mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 14:05:09 +00:00
Initial support for OpenType.js font data/tables/metrics.
This commit is contained in:
@@ -15,6 +15,7 @@ class FontData {
|
||||
private static final double DEFAULT_LETTER_SPACING = 0d;
|
||||
|
||||
private static final String KERNING = "kerning";
|
||||
private static final String FONT_DATA = "fontData";
|
||||
private static final String TEXT_ANCHOR = "textAnchor";
|
||||
private static final String WORD_SPACING = "wordSpacing";
|
||||
private static final String LETTER_SPACING = "letterSpacing";
|
||||
@@ -22,9 +23,9 @@ class FontData {
|
||||
private static final String FONT_VARIANT_LIGATURES = "fontVariantLigatures";
|
||||
|
||||
final double fontSize;
|
||||
|
||||
final String fontFamily;
|
||||
final FontStyle fontStyle;
|
||||
final ReadableMap fontData;
|
||||
final FontWeight fontWeight;
|
||||
final FontVariantLigatures fontVariantLigatures;
|
||||
|
||||
@@ -40,6 +41,7 @@ class FontData {
|
||||
static final FontData Defaults = new FontData();
|
||||
|
||||
private FontData() {
|
||||
fontData = null;
|
||||
fontFamily = "";
|
||||
fontStyle = FontStyle.normal;
|
||||
fontWeight = FontWeight.Normal;
|
||||
@@ -81,6 +83,8 @@ class FontData {
|
||||
fontSize = parentFontSize;
|
||||
}
|
||||
|
||||
fontData = font.hasKey(FONT_DATA) ? font.getMap(FONT_DATA) : parent.fontData;
|
||||
|
||||
fontFamily = font.hasKey(FONT_FAMILY) ? font.getString(FONT_FAMILY) : parent.fontFamily;
|
||||
fontStyle = font.hasKey(FONT_STYLE) ? FontStyle.valueOf(font.getString(FONT_STYLE)) : parent.fontStyle;
|
||||
fontWeight = font.hasKey(FONT_WEIGHT) ? FontWeight.getEnum(font.getString(FONT_WEIGHT)) : parent.fontWeight;
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.graphics.RectF;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.v4.graphics.PaintCompat;
|
||||
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
|
||||
@@ -346,6 +347,9 @@ class TSpanShadowNode extends TextShadowNode {
|
||||
https://svgwg.org/svg2-draft/text.html#FontsGlyphs
|
||||
*/
|
||||
|
||||
// OpenType.js font data
|
||||
ReadableMap fontData = font.fontData;
|
||||
|
||||
/*
|
||||
Name Value Initial value Animatable
|
||||
textLength <length> | <percentage> | <number> See below yes
|
||||
|
||||
@@ -31,7 +31,8 @@ function fontDiffer(a, b) {
|
||||
a.letterSpacing !== b.letterSpacing ||
|
||||
a.wordSpacing !== b.wordSpacing ||
|
||||
a.kerning !== b.kerning ||
|
||||
a.fontVariantLigatures !== b.fontVariantLigatures
|
||||
a.fontVariantLigatures !== b.fontVariantLigatures ||
|
||||
a.fontData !== b.fontData
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ function parseFontString(font) {
|
||||
|
||||
export function extractFont(props) {
|
||||
const {
|
||||
fontData,
|
||||
fontStyle,
|
||||
fontVariant,
|
||||
fontWeight,
|
||||
@@ -66,6 +67,7 @@ export function extractFont(props) {
|
||||
fontSize = fontSize ? '' + fontSize : null;
|
||||
|
||||
const ownedFont = _.pickBy({
|
||||
fontData,
|
||||
fontStyle,
|
||||
fontVariant,
|
||||
fontWeight,
|
||||
|
||||
@@ -268,6 +268,7 @@ const textSpecificProps = {
|
||||
verticalAlign,
|
||||
lengthAdjust,
|
||||
textLength,
|
||||
fontData: PropTypes.object,
|
||||
};
|
||||
|
||||
// https://svgwg.org/svg2-draft/text.html#TSpanAttributes
|
||||
|
||||
Reference in New Issue
Block a user