Skip to content

fix(android/text-base): remove extra font padding for custom fonts gl… #10771

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ahmedsalman74
Copy link

@ahmedsalman74 ahmedsalman74 commented Jul 26, 2025

Apply setIncludeFontPadding(false) in TextBase.initNativeView for all Android text-based views. This fixes the issue where custom and icon fonts appeared taller than expected due to Android's default font padding. The fix is global and backward compatible, so no manual workaround is needed in app code.\n\nCloses #

PR Checklist

Fixes/Implements/Closes #10769 .

…obally

Apply setIncludeFontPadding(false) in TextBase.initNativeView for all Android text-based views.
This fixes the issue where custom and icon fonts appeared taller than expected due to Android's
default font padding. The fix is global and backward compatible, so no manual workaround is
needed in app code.\n\nCloses #<issue-number-if-applicable>

// Fix for custom font over-height issue on Android
// Disable font padding to prevent extra spacing around text
nativeView.setIncludeFontPadding(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious @CatchABus do you see any issue with this fix?

@CatchABus
Copy link
Contributor

CatchABus commented Jul 26, 2025

@ahmedsalman74 Could you post screenshots of the problem from both platforms?
Over-height sounds like it's much larger than it should but it would be good to have a grasp of the situation.

According to android docs, this method:

Set whether the TextView includes extra top and bottom padding to make room for accents that go above the normal ascent and descent. The default is true.

The extra padding for accents might be necessary and there's also a possibility that the widget itself has a native padding that's not removed using padding: 0.

@mohammadrafigh
Copy link

mohammadrafigh commented Jul 27, 2025

@CatchABus Here is what I get with this font icon: https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@3.34.1/dist/fonts/tabler-icons-300.ttf

Screenshot From 2025-07-27 13-48-29

I tried different fonts in the hello world project and some of them were rendered correctly and some not. In the screenshot the height for "font 1" is terrible and for "font 3" is slightly more than normal. It might be due to the wrong metrics set for this specific font? I'm not a font expert, I wonder why the height is correct on the web for all of these fonts but not on Android. If the problem is related only to this specific font and not others; then a generic fix might not be needed in the nativescript core? or we may need a property in styles or somewhere to enable or disable it per use case?

@NathanWalker NathanWalker added this to the 9.0 milestone Jul 30, 2025
@NathanWalker
Copy link
Contributor

Thank you for this @ahmedsalman74 we'll discuss what may be best in this case to include any adjustments for 9.0.
If you end up finding other examples feel free to include. It might be good to see how iOS handles that same font with a screenshot when get chance (against browser as well may help give full picture).

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.

Custom fonts have a weird height
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy