Skip to content

Commit

Permalink
Fix wrong size returned by FontMetrics.stringWidth(String s) on devic…
Browse files Browse the repository at this point in the history
…es that use skia when loading font ending with name ending with .ttf (#50)

Font.getFont("Fonts/Roboto-Bold.ttf", false, size) leads FontMetrics.stringWidth(String s) to returns almost double of the size of the font. The reason this is happening is because on the vm side it already adds .ttf the end of the name of the font making the vm look for Fonts/Roboto-Bold.ttf.ttf instead of the originally passed argument. To solve this, I check if name of the font already come with .ttf before concatenating .ttf to the of the name.
  • Loading branch information
ItaloYeltsin authored Jun 12, 2020
1 parent b89a35e commit 38a2142
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions TotalCrossVM/src/nm/ui/font_Font.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ TC_API void tufF_fontCreate(NMParams p) // totalcross/ui/font/Font native void f
} else {
xstrcpy(nameTTF, name);
}
xstrcat(nameTTF, ".ttf");

int len = xstrlen(nameTTF);
// if it doesn't end with .ttf
if(!(nameTTF[len-4] == '.' && nameTTF[len-3] == 't' && nameTTF[len-2] == 't' && nameTTF[len-1] == 'f')) {
xstrcat(nameTTF, ".ttf");
}
int32 fontIdx = skia_getTypefaceIndex(nameTTF);
if (fontIdx == -1) {
if ((file = tczGetFile(nameTTF, false)) != null) {
Expand Down

0 comments on commit 38a2142

Please sign in to comment.