mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-12-01 10:03:33 +01:00
151 lines
6.6 KiB
Diff
151 lines
6.6 KiB
Diff
diff --git a/android/src/main/java/com/horcrux/svg/MarkerView.java b/android/src/main/java/com/horcrux/svg/MarkerView.java
|
|
index 8c796236f9f4b58717ac3fbab65e33d11ba032f2..d886e13d2cd1390a396716ecf4a379205e6a8aeb 100644
|
|
--- a/android/src/main/java/com/horcrux/svg/MarkerView.java
|
|
+++ b/android/src/main/java/com/horcrux/svg/MarkerView.java
|
|
@@ -114,6 +114,17 @@ class MarkerView extends GroupView {
|
|
}
|
|
}
|
|
|
|
+ private static double parseOrientAngle(String orient) {
|
|
+ if (orient == null) {
|
|
+ return 0;
|
|
+ }
|
|
+ try {
|
|
+ return Double.parseDouble(orient);
|
|
+ } catch (NumberFormatException e) {
|
|
+ return 0;
|
|
+ }
|
|
+ }
|
|
+
|
|
void renderMarker(
|
|
Canvas canvas, Paint paint, float opacity, RNSVGMarkerPosition position, float strokeWidth) {
|
|
int count = saveAndSetupCanvas(canvas, mCTM);
|
|
@@ -122,8 +133,15 @@ class MarkerView extends GroupView {
|
|
Point origin = position.origin;
|
|
markerTransform.setTranslate((float) origin.x, (float) origin.y);
|
|
|
|
- double markerAngle = "auto".equals(mOrient) ? -1 : Double.parseDouble(mOrient);
|
|
- float degrees = 180 + (float) (markerAngle == -1 ? position.angle : markerAngle);
|
|
+ double markerAngle = position.angle;
|
|
+ if ("auto-start-reverse".equals(mOrient)) {
|
|
+ if (position.type == RNSVGMarkerType.kStartMarker) {
|
|
+ markerAngle += 180;
|
|
+ }
|
|
+ } else if (!"auto".equals(mOrient)) {
|
|
+ markerAngle = parseOrientAngle(mOrient);
|
|
+ }
|
|
+ float degrees = 180 + (float) markerAngle;
|
|
markerTransform.preRotate(degrees);
|
|
|
|
boolean useStrokeWidth = "strokeWidth".equals(mMarkerUnits);
|
|
diff --git a/android/src/main/java/com/horcrux/svg/TSpanView.java b/android/src/main/java/com/horcrux/svg/TSpanView.java
|
|
index b6e0a3892eb5416b1badf447d4f8c4e4baef828c..4660fb4b7b49ec44e78fb413a543dd5f9f93ed6a 100644
|
|
--- a/android/src/main/java/com/horcrux/svg/TSpanView.java
|
|
+++ b/android/src/main/java/com/horcrux/svg/TSpanView.java
|
|
@@ -21,6 +21,7 @@ import static com.horcrux.svg.TextProperties.TextPathMidLine;
|
|
import static com.horcrux.svg.TextProperties.TextPathSide;
|
|
|
|
import android.annotation.SuppressLint;
|
|
+import android.annotation.TargetApi;
|
|
import android.content.res.AssetManager;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Matrix;
|
|
@@ -290,6 +291,33 @@ class TSpanView extends TextView {
|
|
static final String additionalLigatures = "'hlig', 'cala', ";
|
|
static final String fontWeightTag = "'wght' ";
|
|
|
|
+ static String fontVariationSettings(int weight, String extra) {
|
|
+ String weightAxis = fontWeightTag + weight;
|
|
+ return extra == null || extra.trim().isEmpty() ? weightAxis : weightAxis + ", " + extra;
|
|
+ }
|
|
+
|
|
+ // Android throws IllegalArgumentException on settings it cannot parse, which would crash the
|
|
+ // draw; fall back to the weight axis alone.
|
|
+ @TargetApi(Build.VERSION_CODES.O)
|
|
+ private static void setPaintFontVariationSettings(Paint paint, FontData font) {
|
|
+ try {
|
|
+ paint.setFontVariationSettings(
|
|
+ fontVariationSettings(font.absoluteFontWeight, font.fontVariationSettings));
|
|
+ } catch (IllegalArgumentException e) {
|
|
+ paint.setFontVariationSettings(fontWeightTag + font.absoluteFontWeight);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @TargetApi(Build.VERSION_CODES.O)
|
|
+ private static void setBuilderFontVariationSettings(
|
|
+ Typeface.Builder builder, int weight, String extra) {
|
|
+ try {
|
|
+ builder.setFontVariationSettings(fontVariationSettings(weight, extra));
|
|
+ } catch (IllegalArgumentException e) {
|
|
+ builder.setFontVariationSettings(fontWeightTag + weight);
|
|
+ }
|
|
+ }
|
|
+
|
|
private void applySpacingAndFeatures(Paint paint, FontData font) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
double letterSpacing = font.letterSpacing;
|
|
@@ -307,8 +335,7 @@ class TSpanView extends TextView {
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
- paint.setFontVariationSettings(
|
|
- fontWeightTag + font.absoluteFontWeight + font.fontVariationSettings);
|
|
+ setPaintFontVariationSettings(paint, font);
|
|
}
|
|
}
|
|
}
|
|
@@ -487,8 +514,7 @@ class TSpanView extends TextView {
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
- paint.setFontVariationSettings(
|
|
- fontWeightTag + font.absoluteFontWeight + font.fontVariationSettings);
|
|
+ setPaintFontVariationSettings(paint, font);
|
|
}
|
|
}
|
|
// OpenType.js font data
|
|
@@ -1147,13 +1173,13 @@ class TSpanView extends TextView {
|
|
String ttfpath = FONTS + fontFamily + TTF;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
Typeface.Builder builder = new Typeface.Builder(assets, otfpath);
|
|
- builder.setFontVariationSettings("'wght' " + weight + font.fontVariationSettings);
|
|
+ setBuilderFontVariationSettings(builder, weight, font.fontVariationSettings);
|
|
builder.setWeight(weight);
|
|
builder.setItalic(isItalic);
|
|
typeface = builder.build();
|
|
if (typeface == null) {
|
|
builder = new Typeface.Builder(assets, ttfpath);
|
|
- builder.setFontVariationSettings("'wght' " + weight + font.fontVariationSettings);
|
|
+ setBuilderFontVariationSettings(builder, weight, font.fontVariationSettings);
|
|
builder.setWeight(weight);
|
|
builder.setItalic(isItalic);
|
|
typeface = builder.build();
|
|
diff --git a/apple/Text/RNSVGGlyphContext.mm b/apple/Text/RNSVGGlyphContext.mm
|
|
--- a/apple/Text/RNSVGGlyphContext.mm
|
|
+++ b/apple/Text/RNSVGGlyphContext.mm
|
|
@@ -117,13 +117,24 @@
|
|
NSString *fontFamily = topFont_->fontFamily;
|
|
NSString *fontStyle = RNSVGFontStyleStrings[topFont_->fontStyle];
|
|
NSString *fontWeight = RNSVGFontWeightStrings[topFont_->fontWeight];
|
|
+ // Fabric text maps the CSS generic ui-monospace to SF Mono; the legacy RCTFont does not know it.
|
|
+ BOOL systemMonospaced = [fontFamily isEqualToString:@"ui-monospace"];
|
|
UIFont *font = [RCTFont updateFont:nil
|
|
- withFamily:[fontFamily isEqualToString:@""] ? nil : fontFamily
|
|
+ withFamily:systemMonospaced ? @"System" : ([fontFamily isEqualToString:@""] ? nil : fontFamily)
|
|
size:@(isnan(size) ? 0 : size)
|
|
weight:fontWeight
|
|
style:fontStyle
|
|
variant:nil
|
|
scaleMultiplier:1.0];
|
|
+#if !TARGET_OS_OSX
|
|
+ if (systemMonospaced) {
|
|
+ UIFontDescriptor *descriptor =
|
|
+ [font.fontDescriptor fontDescriptorWithDesign:UIFontDescriptorSystemDesignMonospaced];
|
|
+ if (descriptor) {
|
|
+ font = [UIFont fontWithDescriptor:descriptor size:font.pointSize];
|
|
+ }
|
|
+ }
|
|
+#endif
|
|
CTFontRef ref = (__bridge CTFontRef)font;
|
|
|
|
double weight = topFont_->absoluteFontWeight;
|