http://shahdza.blog.51cto.com/2410787/1560612
1
2
3
4
5
6
7
8
9
10
| // static Label* createWithSystemFont( const std::string& text, //字符串內容 const std::string& font, //字體(字體名稱、或字體文件) float fontSize, //字號 const Size& dimensions = Size::ZERO, //label的尺寸大小,默認不設置尺寸 TextHAlignment hAlignment = TextHAlignment::LEFT, //水平對齊方式,默認左對齊::LEFT TextVAlignment vAlignment = TextVAlignment::TOP //垂直對齊方式,默認頂部 ::TOP ); // |
1
2
3
4
| // //使用系統的字體名稱 "Arial" 來創建 Label* lb1 = Label::createWithSystemFont( "123abc" , "Arial" , 24); // |
1
2
3
4
5
6
7
8
9
10
| // static Label* createWithTTF( const std::string& text, const std::string& fontFile, //必須為字體文件(如"*.ttf") float fontSize, const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT, TextVAlignment vAlignment = TextVAlignment::TOP ); // |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| // typedef struct _ttfConfig { std::string fontFilePath; //字體文件路徑,如 "fonts/Arial.ttf" int fontSize; //字體大小,默認"12" GlyphCollection glyphs; //使用的字符集,默認"DYNAMIC" const char *customGlyphs; bool distanceFieldEnabled; //是否讓字體緊湊,默認false int outlineSize; //字體輪廓大小,默認"0" //構造函數 _ttfConfig( const char * filePath = "" , int size = 12, const GlyphCollection& glyphCollection = GlyphCollection::DYNAMIC, const char *customGlyphCollection = nullptr, bool useDistanceField = false , int outline = 0 ); }TTFConfig; // |
1
2
3
4
5
6
7
8
| // static Label* createWithTTF( const TTFConfig& ttfConfig, //TTFConfig配置 const std::string& text, //字符串內容 TextHAlignment alignment = TextHAlignment::LEFT, int maxLineWidth = 0 //最大文本行寬,0表示不設置。可用於自動換行只用 ); // |
1
2
3
4
5
6
7
8
9
10
11
12
| // TTFConfig ttfConfig; ttfConfig.fontFilePath = "fonts/Marker Felt.ttf" ; //必須配置 ttfConfig.fontSize = 12; ttfConfig.distanceFieldEnabled = false ; ttfConfig.outlineSize = 0; ttfConfig.glyphs = GlyphCollection::DYNAMIC; ttfConfig.customGlyphs = nullptr; //使用TTFConfig配置,來創建TTF Label* lb3 = Label::createWithTTF(ttfConfig, "123abc" ); // |
沒有留言:
張貼留言