mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 06:07:41 +00:00
Simplify scaling logic
This commit is contained in:
@@ -188,15 +188,15 @@ class GlyphContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void putD(String key, WritableMap map, ReadableMap font, ReadableMap parent, double fontSize) {
|
private void putD(String key, WritableMap map, ReadableMap font, ReadableMap parent) {
|
||||||
if (font.hasKey(key)) {
|
if (font.hasKey(key)) {
|
||||||
String string = font.getString(key);
|
String string = font.getString(key);
|
||||||
double value = PropHelper.fromRelative(
|
double value = PropHelper.fromRelative(
|
||||||
string,
|
string,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
1,
|
mScale,
|
||||||
fontSize
|
mFontSize
|
||||||
);
|
);
|
||||||
map.putDouble(key, value);
|
map.putDouble(key, value);
|
||||||
} else if (parent.hasKey(key)) {
|
} else if (parent.hasKey(key)) {
|
||||||
@@ -244,13 +244,13 @@ class GlyphContext {
|
|||||||
|
|
||||||
// https://www.w3.org/TR/SVG11/text.html#SpacingProperties
|
// https://www.w3.org/TR/SVG11/text.html#SpacingProperties
|
||||||
// https://drafts.csswg.org/css-text-3/#spacing
|
// https://drafts.csswg.org/css-text-3/#spacing
|
||||||
// calculated values for units in: kerning, letter-spacing and word-spacing
|
// calculated values for units in: kerning, word-spacing, and, letter-spacing
|
||||||
|
|
||||||
putD(KERNING, map, font, parent, mFontSize);
|
putD(KERNING, map, font, parent);
|
||||||
|
|
||||||
putD(WORD_SPACING, map, font, parent, mFontSize);
|
putD(WORD_SPACING, map, font, parent);
|
||||||
|
|
||||||
putD(LETTER_SPACING, map, font, parent, mFontSize);
|
putD(LETTER_SPACING, map, font, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushContext(GroupShadowNode node, @Nullable ReadableMap font) {
|
void pushContext(GroupShadowNode node, @Nullable ReadableMap font) {
|
||||||
@@ -465,8 +465,8 @@ class GlyphContext {
|
|||||||
if (nextIndex < mDXs.length) {
|
if (nextIndex < mDXs.length) {
|
||||||
mDXIndex = nextIndex;
|
mDXIndex = nextIndex;
|
||||||
String string = mDXs[nextIndex];
|
String string = mDXs[nextIndex];
|
||||||
double val = PropHelper.fromRelative(string, mWidth, 0, 1, mFontSize);
|
double val = PropHelper.fromRelative(string, mWidth, 0, mScale, mFontSize);
|
||||||
mDX += val * mScale;
|
mDX += val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mDX;
|
return mDX;
|
||||||
@@ -479,8 +479,8 @@ class GlyphContext {
|
|||||||
if (nextIndex < mDYs.length) {
|
if (nextIndex < mDYs.length) {
|
||||||
mDYIndex = nextIndex;
|
mDYIndex = nextIndex;
|
||||||
String string = mDYs[nextIndex];
|
String string = mDYs[nextIndex];
|
||||||
double val = PropHelper.fromRelative(string, mHeight, 0, 1, mFontSize);
|
double val = PropHelper.fromRelative(string, mHeight, 0, mScale, mFontSize);
|
||||||
mDY += val * mScale;
|
mDY += val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mDY;
|
return mDY;
|
||||||
|
|||||||
@@ -181,15 +181,15 @@ class TSpanShadowNode extends TextShadowNode {
|
|||||||
* */
|
* */
|
||||||
|
|
||||||
final boolean hasKerning = font.hasKey(PROP_KERNING);
|
final boolean hasKerning = font.hasKey(PROP_KERNING);
|
||||||
double kerning = hasKerning ? font.getDouble(PROP_KERNING) * mScale : DEFAULT_KERNING;
|
double kerning = hasKerning ? font.getDouble(PROP_KERNING) : DEFAULT_KERNING;
|
||||||
final boolean autoKerning = !hasKerning;
|
final boolean autoKerning = !hasKerning;
|
||||||
|
|
||||||
final double wordSpacing = font.hasKey(PROP_WORD_SPACING) ?
|
final double wordSpacing = font.hasKey(PROP_WORD_SPACING) ?
|
||||||
font.getDouble(PROP_WORD_SPACING) * mScale
|
font.getDouble(PROP_WORD_SPACING)
|
||||||
: DEFAULT_WORD_SPACING;
|
: DEFAULT_WORD_SPACING;
|
||||||
|
|
||||||
final double letterSpacing = font.hasKey(PROP_LETTER_SPACING) ?
|
final double letterSpacing = font.hasKey(PROP_LETTER_SPACING) ?
|
||||||
font.getDouble(PROP_LETTER_SPACING) * mScale
|
font.getDouble(PROP_LETTER_SPACING)
|
||||||
: DEFAULT_LETTER_SPACING;
|
: DEFAULT_LETTER_SPACING;
|
||||||
|
|
||||||
for (int index = 0; index < length; index++) {
|
for (int index = 0; index < length; index++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user