[Text][Android][iOS?][RC] text decorations ignoring font position metrics
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- kotlin, objective-c
- Área
- mobile-dev
Línea de trabajo
Comienza con la aplicación obligatoria rn-reproducer-font-rendering y compara la colocación de las decoraciones en Android e iOS con las capturas de pantalla esperadas. Lee el commit 87184c8fbac1 y sigue las rutas nativas de decoración de texto, incluido el tratamiento de las métricas de Android y CoreText descrito en el issue. Se considera terminado cuando se haya verificado que la colocación de subrayados y tachados utiliza métricas de fuente apropiadas o fallbacks documentados en ambas plataformas, y que el reproducer renderiza correctamente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
https://github.com/react/react-native/commit/87184c8fbac1 implemented textDecorationStyle feature parity between iOS and Android (before RC missing in Android as noop). cc @quantizor
The position and sizing of the lines (underlines, strike through), though, are not based on the open type tables of the used font, instead different heuristics are used (mid of x size fo strike through, baseline + 1 for underline)
This leads to a wrong final result, where underlines is always touching the baseline, and strike-through may be oddly positioned.
The problem is more visible in custom fonts that intentionally define larger offsets for the underline (e.g. to avoid crossing descenders), or use a curated position for strike through (e.g. avoiding overlapping with currency symbol mid lines). Those are just some examples, but in general the expectation is to respect the values embedded in the font.
On iOS there is a similar issue: while "solid" and "double" underlines respect values that CoreText reads from the font, the position of "wavy", "dashed", "dotted", instead is using the same hardcoded heuristic now introduced on Android.
(I couldn't directly verify the issues on iOS, but inferred from similar code. Would be worth also verifying how the strike through position is determined there)
I'm not familiar with the native code, but I think both the current state as well as the one in the RC have issues, with underlines on Android now always touching the glyphs just being the most visible one.
LLM suggested possible fixes involving reading the correct metric when they are available, while falling back to heuristics when not available.
drawSpannedDecoration(start, end, canvas, layout, color, style) {
paint,
baseline,
thickness,
->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
baseline + paint.underlinePosition + thickness / 2f
} else {
baseline + thickness + 1f
}
}
CTFontRef ctFont = (__bridge CTFontRef)font;
CGFloat fontThickness = CTFontGetUnderlineThickness(ctFont);
CGFloat thickness = fontThickness > 0
? fontThickness
: MAX(font.pointSize / 12.0f, 1.5f);
CGFloat topOffset = -CTFontGetUnderlinePosition(ctFont);
CGFloat y = baseline + topOffset + thickness / 2.0f;
I haven't directly verified these suggestions and I also think a wider assessment may be needed:
- are there other metrics being ignored and replaced with custom heuristics?
- Is any of those changes compatible with the recent introduction of variable fonts support? (https://github.com/react-native-community/discussions-and-proposals/issues/829#issuecomment-5246274271) cc @Abbondanzo
- when heuristics are used as fallback, are they in sync with web browsers implementation?
- should font metrics be respected by default, or via a style property like on web (e.g.
text-underline-position: from-font) - probably more things I'm missing needing some text rendering experts' eyes
Steps to reproduce
run the reproducer and check the actual and expected rendering (as in screenshot)
can also be compared with older RN version where underline was correctly rendered with a large offset: https://snack.expo.dev/@axyzxp/underline-rendering?platform=android
React Native Version
0.87.0-rc.4
Affected Platforms
Runtime - Android, Runtime - iOS
Output of npx @react-native-community/cli info
❯ npx @react-native-community/cli info
info Fetching system and libraries information...
System:
OS: Linux 7.0 Ubuntu 26.04 LTS 26.04 LTS (Resolute Raccoon)
CPU: (16) x64 AMD Ryzen 7 PRO 4750U with Radeon Graphics
Memory: 13.25 GB / 30.57 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 26.7.0
path: /home/axyz/.local/share/mise/installs/node/latest/bin/node
Yarn: Not Found
npm:
version: 11.19.0
path: /home/axyz/.local/share/mise/installs/node/latest/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java:
version: 21.0.7
path: /home/axyz/app/android-studio/jbr/bin/javac
Ruby:
version: 3.3.8
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
wanted: 20.2.0
react:
installed: 19.2.3
wanted: 19.2.3
react-native:
installed: 0.87.0-rc.4
wanted: 0.87.0-rc.4
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: Not found
newArchEnabled: false
Stacktrace or Logs
there is no crash, it is a visual defect.
MANDATORY Reproducer
https://github.com/axyz/rn-reproducer-font-rendering
Screenshots and Videos
- Lenguaje dominante
- C++
- Estrellas
- 127k
- Forks
- 25.3k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de react/react-native
-
Needs: Author Feedback Needs: Repro
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
react/react-native#58621 · 1 comentario ·
-
Needs: Author Feedback Needs: Repro
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
react/react-native#58610 · 1 comentario ·
-
Needs: Triage :mag:
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
react/react-native#58565 · 1 comentario · 2 reacciones ·
-
Needs: Author Feedback Needs: Repro
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
react/react-native#58555 · 5 comentarios · 2 reacciones ·
-
Needs: Attention Needs: Repro
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
react/react-native#58526 · 2 comentarios ·
Todos los issues de react/react-native
Issues similares
-
ai_reviewed
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ydb-platform/ydb#53869 · 3 comentarios ·
-
bug cert blocker needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
project-chip/connectedhomeip#74373 ·
-
[request] tracy/0.14.1 Abiertoupstream update
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
vllm-project/vllm-ascend#17329 ·