From eaf7b5e88b41ce81528cefd84b01ef4d4b88bd57 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sat, 22 Jul 2017 23:02:37 +0300 Subject: [PATCH] Improve fontSize handling --- .../java/com/horcrux/svg/GlyphContext.java | 31 ++++++++++++++----- lib/extract/extractText.js | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/GlyphContext.java b/android/src/main/java/com/horcrux/svg/GlyphContext.java index 28d9fd07..93122988 100644 --- a/android/src/main/java/com/horcrux/svg/GlyphContext.java +++ b/android/src/main/java/com/horcrux/svg/GlyphContext.java @@ -299,28 +299,43 @@ class GlyphContext { } } + // https://www.w3.org/TR/SVG11/text.html#FontSizeProperty private float getActualFontSize() { + // TODO Should handle an ancestor hierarchy of relative fontSize until default in the root + float fontSizeFromParentContext = mTop > -1 ? + mNodes.get(0).getFontSizeFromParentContext() : DEFAULT_FONT_SIZE; + + // TODO consider relative fontSizes in this glyph context stack as well + // TODO Should parhaps calculate relative size on pushContext for (int index = mTop; index >= 0; index--) { ReadableMap font = mFontContext.get(index); if (mFontContext.get(index).hasKey(FONT_SIZE)) { String string = font.getString(FONT_SIZE); - // https://www.w3.org/TR/SVG11/text.html#FontSizeProperty - return PropHelper.fromRelativeToFloat(string, mHeight, 0, 1, DEFAULT_FONT_SIZE); + return PropHelper.fromRelativeToFloat( + string, + fontSizeFromParentContext, + 0, + 1, + fontSizeFromParentContext + ); } } - if (mTop > -1) { - return mNodes.get(0).getFontSizeFromParentContext(); - } - - return DEFAULT_FONT_SIZE; + return fontSizeFromParentContext; } /** * Get font size from context. * - * ‘font-size’ : | | | | inherit + * ‘font-size’ + * Value: | | | | inherit + * Initial: medium + * Applies to: text content elements + * Inherited: yes, the computed value is inherited + * Percentages: refer to parent element's font size TODO + * Media: visual + * Animatable: yes * * This property refers to the size of the font from baseline to * baseline when multiple lines of text are set solid in a multiline diff --git a/lib/extract/extractText.js b/lib/extract/extractText.js index 9b6db3d3..4530cc84 100644 --- a/lib/extract/extractText.js +++ b/lib/extract/extractText.js @@ -62,7 +62,7 @@ export function extractFont(props) { letterSpacing: props.letterSpacing, fontWeight: props.fontWeight, fontStyle: props.fontStyle, - fontSize: props.fontSize, + fontSize: props.fontSize ? '' + props.fontSize : null, kerning: props.kerning, };