diff options
| author | Ray <[email protected]> | 2016-11-13 23:53:28 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2016-11-13 23:53:28 +0100 |
| commit | 38df2cad253251c9fc531c2e9a3a28308aaeb718 (patch) | |
| tree | 52c15db2e90907476e090ed5aa16bc555df7e8ec /src/text.c | |
| parent | 42452378925e3b1d407a33084cd8cf0495632ee8 (diff) | |
| download | raylib-38df2cad253251c9fc531c2e9a3a28308aaeb718.tar.gz raylib-38df2cad253251c9fc531c2e9a3a28308aaeb718.zip | |
Improved text measurement
Still not working correctly, font offsets are not considered
correctly...
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 9 |
1 files changed, 3 insertions, 6 deletions
@@ -444,14 +444,14 @@ int MeasureText(const char *text, int fontSize) if (fontSize < defaultFontSize) fontSize = defaultFontSize; int spacing = fontSize/defaultFontSize; - vec = MeasureTextEx(GetDefaultFont(), text, fontSize, spacing); + vec = MeasureTextEx(GetDefaultFont(), text, (float)fontSize, spacing); } return (int)vec.x; } // Measure string size for SpriteFont -Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int spacing) +Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, float fontSize, int spacing) { int len = strlen(text); int tempLen = 0; // Used to count longer text line num chars @@ -461,7 +461,7 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int int tempTextWidth = 0; // Used to count longer text line width int textHeight = spriteFont.size; - float scaleFactor; + float scaleFactor = fontSize/spriteFont.size; for (int i = 0; i < len; i++) { @@ -487,9 +487,6 @@ Vector2 MeasureTextEx(SpriteFont spriteFont, const char *text, int fontSize, int if (tempTextWidth < textWidth) tempTextWidth = textWidth; - if (fontSize <= spriteFont.size) scaleFactor = 1.0f; - else scaleFactor = (float)fontSize/spriteFont.size; - Vector2 vec; vec.x = (float)tempTextWidth*scaleFactor + (tempLen - 1)*spacing; // Adds chars spacing to measure vec.y = (float)textHeight*scaleFactor; |
