Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong FontMetrics.stringWidth(String s) on devices that use skia #50

Merged
merged 1 commit into from Jun 12, 2020

Conversation

ItaloYeltsin
Copy link
Contributor

@ItaloYeltsin ItaloYeltsin commented Jun 12, 2020

Description:

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 comes with .ttf before concatenating .ttf to the of the name.

Motivation and Context:

Wrong Label width because when using Font.getFont("Fonts/Roboto-Bold.ttf", false, size) instead of Font.getFont("Fonts/Roboto-Bold", false, size) without .ttf.

Benefited Devices:

  • Device: devices that has as OS iOS, Android and Linux/Linux_arm
  • OS: iOS, Android, Linux and Linux_arm

How Has This Been Tested?

  • I took different ttf files and loaded them in a Test project. Then, for each font file I've made a Label and painted its background with to see the real space that Label was taking. After the fix, the was taking exactly the same size of the text drawn.

Tested Devices:

  • Device: Raspberry PI 4
  • OS: Raspberry PI OS

@ItaloYeltsin ItaloYeltsin requested a review from acmlira Jun 12, 2020
…es that use skia when loading font ending with name ending with .ttf

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.
Copy link
Contributor

@acmlira acmlira left a comment

I think it's a sufficient solution :)

@ItaloYeltsin ItaloYeltsin merged commit 38a2142 into develop Jun 12, 2020
@ItaloYeltsin ItaloYeltsin deleted the bugfix/font-stringwidth branch Jun 12, 2020
flsobral pushed a commit that referenced this issue Jul 16, 2020
…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.
flsobral pushed a commit that referenced this issue Jul 24, 2020
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants