|
| 1 | +Myra uses [FontStashSharp](https://github.com/FontStashSharp/FontStashSharp) for the text rendering. |
| 2 | + |
| 3 | +Sample code for setting font: |
| 4 | +```c# |
| 5 | +byte[] ttfData = File.ReadAllBytes("DroidSans.ttf"); |
| 6 | + |
| 7 | +// Ordinary DynamicSpriteFont |
| 8 | +FontSystem ordinaryFontSystem = new FontSystem(); |
| 9 | +ordinaryFontSystem.AddFont(ttfData); |
| 10 | +_label1.Font = ordinaryFontSystem.GetFont(32); |
| 11 | + |
| 12 | +// Stroked DynamicSpriteFont |
| 13 | +FontSystemSettings strokedSettings = new FontSystemSettings |
| 14 | +{ |
| 15 | + Effect = FontSystemEffect.Stroked, |
| 16 | + EffectAmount = 1 |
| 17 | +}; |
| 18 | +FontSystem strokedFontSystem = new FontSystem(strokedSettings); |
| 19 | +strokedFontSystem.AddFont(ttfData); |
| 20 | +_label2.Font = strokedFontSystem.GetFont(24); |
| 21 | + |
| 22 | +// Blurry DynamicSpriteFont |
| 23 | +FontSystemSettings blurrySettings = new FontSystemSettings |
| 24 | +{ |
| 25 | + Effect = FontSystemEffect.Blurry, |
| 26 | + EffectAmount = 1 |
| 27 | +}; |
| 28 | +FontSystem blurryFontSystem = new FontSystem(blurrySettings); |
| 29 | +blurryFontSystem.AddFont(ttfData); |
| 30 | +_label3.Font = blurryFontSystem.GetFont(48); |
| 31 | + |
| 32 | +// StaticSpriteFont in AngelCode BMFont Format(https://www.angelcode.com/products/bmfont/) |
| 33 | +string fntData = File.ReadAllText("comicSans48.fnt"); |
| 34 | +_label4.Font = StaticSpriteFont.FromBMFont(fntData, atlasFileName => File.OpenRead(atlasFileName), GraphicsDevice); |
| 35 | +``` |
| 36 | + |
| 37 | +It is equivalent to the following MML: |
| 38 | +```xml |
| 39 | +<Project> |
| 40 | + <Project.ExportOptions /> |
| 41 | + <Panel Background="#4BD961FF"> |
| 42 | + <VerticalStackPanel HorizontalAlignment="Center" VerticalAlignment="Center" > |
| 43 | + <Label Text="Hello, World!" Font="DroidSans.ttf:32" /> |
| 44 | + <Label Text="Hello, World!" Font="DroidSans.ttf:Stroked:1:24" /> |
| 45 | + <Label Text="Hello, World!" Font="DroidSans.ttf:Blurry:2:48" /> |
| 46 | + <Label Text="Hello, World!" Font="comicSans48.fnt" /> |
| 47 | + </VerticalStackPanel> |
| 48 | + </Panel> |
| 49 | +</Project> |
| 50 | +``` |
| 51 | + |
| 52 | +Which would result to the following: |
| 53 | + |
| 54 | + |
0 commit comments