Skip to content

Commit

Permalink
Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
rds1983 committed Jan 4, 2020
1 parent ac3457c commit 8a965c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions samples/SpriteFontPlus.Samples.DynamicSpriteFont/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ protected override void Draw(GameTime gameTime)
DrawString("Příliš žluťoučký kůň úpěl ďábelské kódy, R: В чащах юга жил-был цитрус? Да, но фальшивый экземпляр! ёъ.", 120);

_font.Size = 28;
DrawString("kilómetros y frío, añoraba, P: vôo à noite, F: Les naïfs ægithales hâtifs pondant à Noël où", 150);
DrawString("kilómetros y frío, añoraba,\nP: vôo à noite, F: Les naïfs ægithales\nhâtifs pondant à Noël où", 150);

_font.FontId = _fontIdJapanese;
_font.Size = 30;
DrawString("いろはにほへど", 180);
DrawString("いろはにほへど", 250);

_font.FontId = _fontIdEmojis;
_font.Size = 32;
DrawString("🙌📦👏🔥👍😻😂🎉💻😍🚀😁🙈🇧🇪👩😉🍻🎶🏆👀👉👶💕😎😱🌌🌻🍺🏀👇👯💁💝💩😃😅🙏🚄🇫🌧🌾🍀🍁🍓🍕🎾🏈", 220, Color.Gold);
DrawString("🙌📦👏🔥👍😻😂🎉💻😍🚀😁🙈🇧🇪👩😉🍻🎶🏆👀👉👶💕😎😱🌌🌻🍺🏀👇👯💁💝💩😃😅🙏🚄🇫🌧🌾🍀🍁🍓🍕🎾🏈", 280, Color.Gold);

_font.FontId = _font.DefaultFontId;
_font.Size = 26;
Expand Down
25 changes: 23 additions & 2 deletions src/SpriteFontPlus/FontStashSharp/FontSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpriteFontPlus;
using StbTrueTypeSharp;
using static StbTrueTypeSharp.StbTrueType;

namespace FontStashSharp
Expand Down Expand Up @@ -110,6 +109,9 @@ public float DrawText(SpriteBatch batch, float x, float y, StringSegment str, fl
{
if (str.IsNullOrEmpty) return 0.0f;

float ascenter, descenter, lineHeight;
VertMetrics(out ascenter, out descenter, out lineHeight);

FontGlyph glyph = null;
var q = new FontGlyphSquad();
var prevGlyphIndex = -1;
Expand Down Expand Up @@ -148,6 +150,14 @@ public float DrawText(SpriteBatch batch, float x, float y, StringSegment str, fl
for (int i = 0; i < str.Length; i += char.IsSurrogatePair(str.String, i + str.Location) ? 2 : 1)
{
var codepoint = char.ConvertToUtf32(str.String, i + str.Location);

if (codepoint == '\n')
{
originX = 0.0f;
originY += lineHeight;
continue;
}

glyph = GetGlyph(font, codepoint, isize, iblur, true);
if (glyph != null)
{
Expand Down Expand Up @@ -184,6 +194,9 @@ public float DrawText(SpriteBatch batch, float x, float y, StringSegment str, fl

public float TextBounds(float x, float y, StringSegment str, ref Bounds bounds)
{
float ascenter, descenter, lineHeight;
VertMetrics(out ascenter, out descenter, out lineHeight);

var q = new FontGlyphSquad();
FontGlyph glyph = null;
var prevGlyphIndex = -1;
Expand All @@ -210,6 +223,14 @@ public float TextBounds(float x, float y, StringSegment str, ref Bounds bounds)
for (int i = 0; i < str.Length; i += char.IsSurrogatePair(str.String, i + str.Location) ? 2 : 1)
{
var codepoint = char.ConvertToUtf32(str.String, i + str.Location);

if (codepoint == '\n')
{
x = startx;
y += lineHeight;
continue;
}

glyph = GetGlyph(font, codepoint, isize, iblur, false);
if (glyph != null)
{
Expand Down Expand Up @@ -359,7 +380,7 @@ private FontGlyph GetGlyph(Font font, int codepoint, int isize, int iblur, bool
g = font._font.fons__tt_getGlyphIndex(codepoint);
if (g == 0)
{
throw new Exception(string.Format("Could not find glyph for codepoint {0}", codepoint));
return null;
}

scale = font._font.fons__tt_getPixelHeightScale(size);
Expand Down

0 comments on commit 8a965c2

Please sign in to comment.