|
8 | 8 | package com.facebook.react.views.text;
|
9 | 9 |
|
10 | 10 | import android.content.res.AssetManager;
|
11 |
| -import android.graphics.Paint; |
12 | 11 | import android.graphics.Typeface;
|
13 |
| - |
| 12 | +import android.text.TextUtils; |
14 | 13 | import androidx.annotation.Nullable;
|
15 |
| - |
16 | 14 | import com.facebook.react.bridge.ReadableArray;
|
17 |
| - |
18 | 15 | import java.util.ArrayList;
|
19 | 16 | import java.util.List;
|
20 | 17 |
|
@@ -51,30 +48,37 @@ public static int parseFontStyle(@Nullable String fontStyleString) {
|
51 | 48 | List<String> features = new ArrayList<>();
|
52 | 49 | for (int i = 0; i < fontVariantArray.size(); i++) {
|
53 | 50 | // see https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
|
54 |
| - switch (fontVariantArray.getString(i)) { |
55 |
| - case "small-caps": |
56 |
| - features.add("'smcp'"); |
57 |
| - break; |
58 |
| - case "oldstyle-nums": |
59 |
| - features.add("'onum'"); |
60 |
| - break; |
61 |
| - case "lining-nums": |
62 |
| - features.add("'lnum'"); |
63 |
| - break; |
64 |
| - case "tabular-nums": |
65 |
| - features.add("'tnum'"); |
66 |
| - break; |
67 |
| - case "proportional-nums": |
68 |
| - features.add("'pnum'"); |
69 |
| - break; |
| 51 | + String fontVariant = fontVariantArray.getString(i); |
| 52 | + if (fontVariant != null) { |
| 53 | + switch (fontVariant) { |
| 54 | + case "small-caps": |
| 55 | + features.add("'smcp'"); |
| 56 | + break; |
| 57 | + case "oldstyle-nums": |
| 58 | + features.add("'onum'"); |
| 59 | + break; |
| 60 | + case "lining-nums": |
| 61 | + features.add("'lnum'"); |
| 62 | + break; |
| 63 | + case "tabular-nums": |
| 64 | + features.add("'tnum'"); |
| 65 | + break; |
| 66 | + case "proportional-nums": |
| 67 | + features.add("'pnum'"); |
| 68 | + break; |
| 69 | + } |
70 | 70 | }
|
71 | 71 | }
|
72 | 72 |
|
73 |
| - return String.join(", ", features); |
| 73 | + return TextUtils.join(", ", features); |
74 | 74 | }
|
75 | 75 |
|
76 |
| - public static Typeface applyStyles(@Nullable Typeface typeface, |
77 |
| - int style, int weight, @Nullable String family, AssetManager assetManager) { |
| 76 | + public static Typeface applyStyles( |
| 77 | + @Nullable Typeface typeface, |
| 78 | + int style, |
| 79 | + int weight, |
| 80 | + @Nullable String family, |
| 81 | + AssetManager assetManager) { |
78 | 82 | int oldStyle;
|
79 | 83 | if (typeface == null) {
|
80 | 84 | oldStyle = 0;
|
@@ -114,9 +118,9 @@ public static Typeface applyStyles(@Nullable Typeface typeface,
|
114 | 118 | private static int parseNumericFontWeight(String fontWeightString) {
|
115 | 119 | // This should be much faster than using regex to verify input and Integer.parseInt
|
116 | 120 | return fontWeightString.length() == 3
|
117 |
| - && fontWeightString.endsWith("00") |
118 |
| - && fontWeightString.charAt(0) <= '9' |
119 |
| - && fontWeightString.charAt(0) >= '1' |
| 121 | + && fontWeightString.endsWith("00") |
| 122 | + && fontWeightString.charAt(0) <= '9' |
| 123 | + && fontWeightString.charAt(0) >= '1' |
120 | 124 | ? 100 * (fontWeightString.charAt(0) - '0')
|
121 | 125 | : UNSET;
|
122 | 126 | }
|
|
0 commit comments