利用window.font属性改变其surface.font
Code: Select all
class Form1 : Window
{
text = "Fonts";
background = activeBorder;
...
font = { "Comic Sans MS", 10, bold = true };
...
void OnRedraw(Surface surface)
{
...
surface.WriteText( 50, 20, str, strlen(str));
...
方法2
定义资源
Code: Select all
FontResource fontRes{ faceName = "Comic Sans MS", size = 8.25f ,bold = true,italic = true,underline = true ,window=this};
surface.TextFont(fontRes.font);
surface.WriteText( 50, 20, str, strlen(str));
方法3
通过显示系统Display,手动管理
Code: Select all
Font fonts ;
...
bool OnLoadGraphics(void)
{
fonts = displaySystem.LoadFont("Comic Sans MS", 10, 0);//*方法3*/
return true;
}
void OnUnloadGraphics(void)
{
displaySystem.UnloadFont(fonts);//*方法3*/
}
...
surface.TextFont(fonts);
surface.WriteText( 50, 20, str, strlen(str));
...
Code: Select all
import "ecere"
static char * verse1 = "Not marble, nor the gilded monuments";
static char * verse2 = "Of princes, shall outlive this powerful rhyme;";
static char * verse3 = "But you shall shine more bright in these contents";
static char * verse4 = "Than unswept stone, besmear'd with sluttish time.";
static char * verse5 = "When wasteful war shall statues overturn,";
static char * verse6 = "And broils root out the work of masonry,";
static char * verse7 = "Nor Mars his sword, nor war's quick fire shall burn";
static char * verse8 = "The living record of your memory.";
static char * verse9 = "'Gainst death, and all oblivious enmity";
static char * verse10 = "Shall you pace forth; your praise shall still find room ";
static char * verse11 = "Even in the eyes of all posterity";
static char * verse12 = "That wear this world out to the ending doom.";
static char * verse13 = "So, till the judgment that yourself arise,";
static char * verse14 = "You live in this, and dwell in lovers' eyes.";
class Form1 : Window
{
text = "Fonts";
background = activeBorder;
borderStyle = sizable;
hasMaximize = true;
hasMinimize = true;
hasClose = true;
size = { 464, 336 };
anchor = { horz = -27, vert = -60 };
//font = { "Comic Sans MS", 10, bold = true };//方法1
//FontResource fontRes{ faceName = "Comic Sans MS", size = 8.25f ,bold = true,italic = true,underline = true,window=this};//*方法2*/
Font fonts ;
void OnRedraw(Surface surface)
{
surface.TextFont(fonts);
//surface.TextFont(fontRes.font);
surface.WriteText( 50, 20, verse1, strlen(verse1));
surface.WriteText( 50, 40, verse2, strlen(verse2));
surface.WriteText( 50, 60, verse3, strlen(verse3));
surface.WriteText( 50, 80, verse4, strlen(verse4));
surface.WriteText( 50, 100, verse5, strlen(verse5));
surface.WriteText( 50, 120, verse6, strlen(verse6));
surface.WriteText( 50, 140, verse7, strlen(verse7));
surface.WriteText( 50, 160, verse8, strlen(verse8));
surface.WriteText( 50, 180, verse9, strlen(verse9));
surface.WriteText( 50, 200, verse10, strlen(verse10));
surface.WriteText( 50, 220, verse11, strlen(verse11));
surface.WriteText( 50, 240, verse12, strlen(verse12));
surface.WriteText( 50, 260, verse13, strlen(verse13));
surface.WriteText( 50, 280, verse14, strlen(verse14));
}
bool OnLoadGraphics(void)
{
fonts = displaySystem.LoadFont("Comic Sans MS", 10, 0);//*方法3*/
return true;
}
void OnUnloadGraphics(void)
{
displaySystem.UnloadFont(fonts);//*方法3*/
}
}
Form1 form1 {};