Skip to content

Commit 6e2ad75

Browse files
authored
fix: add custom fonts to example (#197)
* fix: add custom fonts to example * docs: add collaborator
1 parent 83d9856 commit 6e2ad75

File tree

13 files changed

+71
-16
lines changed

13 files changed

+71
-16
lines changed

README.MD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[![CI](https://github.com/JimmyDaddy/react-native-image-marker/actions/workflows/ci.yml/badge.svg)](https://github.com/JimmyDaddy/react-native-image-marker/actions/workflows/ci.yml)
1616
![platform-iOS](https://img.shields.io/badge/iOS-black?logo=Apple&style=for-the-badge) ![platform-Android](https://img.shields.io/badge/Android-black?logo=Android&style=for-the-badge)
1717
<br/>
18-
18+
1919
</div>
2020

2121
---
@@ -761,6 +761,7 @@ pod 'RNImageMarker', :path => '../node_modules/react-native-image-marker'
761761
[@gaoxiaosong](https://github.com/gaoxiaosong)
762762
[@onka13](https://github.com/onka13)
763763
[@OrangeFlavoredColdCoffee](https://github.com/OrangeFlavoredColdCoffee)
764+
[@Dendi](https://github.com/vioku)
764765

765766
## Examples
766767

android/src/main/java/com/jimmydaddy/imagemarker/base/TextOptions.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ data class TextOptions(val options: ReadableMap) {
5757
style.shadowLayerStyle!!.color
5858
)
5959
}
60-
try {
61-
//设置字体失败时使用默认字体
62-
textPaint.typeface = ReactFontManager.getInstance()
63-
.getTypeface(style.fontName!!, Typeface.NORMAL, context.assets)
64-
} catch (e: Exception) {
65-
textPaint.typeface = Typeface.DEFAULT
60+
61+
var typefaceFamily = Typeface.DEFAULT
62+
if (style.fontName != null) {
63+
typefaceFamily = try {
64+
//设置字体失败时使用默认字体
65+
ReactFontManager.getInstance()
66+
.getTypeface(style.fontName!!, Typeface.NORMAL, context.assets)
67+
} catch (e: Exception) {
68+
Log.e(Constants.IMAGE_MARKER_TAG, "Could not get typeface: " + e.message)
69+
Typeface.DEFAULT
70+
}
6671
}
6772
val textSize = TypedValue.applyDimension(
6873
TypedValue.COMPLEX_UNIT_SP,
@@ -75,13 +80,13 @@ data class TextOptions(val options: ReadableMap) {
7580
textPaint.color = Color.parseColor(Utils.transRGBColor(style.color))
7681
textPaint.isUnderlineText = style.underline
7782
textPaint.textSkewX = style.skewX!!
78-
var typeface = Typeface.create(ReactFontManager.getInstance() .getTypeface(style.fontName!!, Typeface.NORMAL, context.assets), Typeface.NORMAL)
83+
var typeface = Typeface.create(typefaceFamily, Typeface.NORMAL)
7984
if (style.italic && style.bold) {
80-
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC)
85+
typeface = Typeface.create(typefaceFamily, Typeface.BOLD_ITALIC)
8186
} else if (style.italic) {
82-
typeface = Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)
87+
typeface = Typeface.create(typefaceFamily, Typeface.ITALIC)
8388
} else if (style.bold) {
84-
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
89+
typeface = Typeface.create(typefaceFamily, Typeface.BOLD)
8590
}
8691
textPaint.isStrikeThruText = style.strikeThrough
8792
textPaint.typeface = typeface
Binary file not shown.
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"migIndex": 1,
3+
"data": [
4+
{
5+
"path": "assets/fonts/MaShanZheng-Regular.ttf",
6+
"sha1": "1376fdd48ab29afd9599101e8991b773f12177e5"
7+
},
8+
{
9+
"path": "assets/fonts/RubikBurned-Regular.ttf",
10+
"sha1": "546eccbc5a368bd10e6a4fe9570208428c16a036"
11+
}
12+
]
13+
}
5.58 MB
Binary file not shown.
591 KB
Binary file not shown.

example/ios/ImageMarkerExample.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1414
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
1515
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
16+
93F7B1DDABE441E6B6212F21 /* MaShanZheng-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 50CB977CE5BF44179F12CFF5 /* MaShanZheng-Regular.ttf */; };
1617
A119E9E12B162437000C0527 /* ImageMarkerExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A119E9E02B162437000C0527 /* ImageMarkerExampleUITests.swift */; };
1718
A119E9E32B162437000C0527 /* ImageMarkerExampleUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A119E9E22B162437000C0527 /* ImageMarkerExampleUITestsLaunchTests.swift */; };
19+
F95A8E69C66343EEB9A8D9DC /* RubikBurned-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E3DA1B9696844B35AAE670BD /* RubikBurned-Regular.ttf */; };
1820
/* End PBXBuildFile section */
1921

2022
/* Begin PBXContainerItemProxy section */
@@ -36,6 +38,7 @@
3638
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ImageMarkerExample/main.m; sourceTree = "<group>"; };
3739
15E0FEF5E88EB5BA856E015A /* Pods-ImageMarkerExample-ImageMarkerExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageMarkerExample-ImageMarkerExampleUITests.release.xcconfig"; path = "Target Support Files/Pods-ImageMarkerExample-ImageMarkerExampleUITests/Pods-ImageMarkerExample-ImageMarkerExampleUITests.release.xcconfig"; sourceTree = "<group>"; };
3840
3B4392A12AC88292D35C810B /* Pods-ImageMarkerExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageMarkerExample.debug.xcconfig"; path = "Target Support Files/Pods-ImageMarkerExample/Pods-ImageMarkerExample.debug.xcconfig"; sourceTree = "<group>"; };
41+
50CB977CE5BF44179F12CFF5 /* MaShanZheng-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "MaShanZheng-Regular.ttf"; path = "../assets/fonts/MaShanZheng-Regular.ttf"; sourceTree = "<group>"; };
3942
5709B34CF0A7D63546082F79 /* Pods-ImageMarkerExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageMarkerExample.release.xcconfig"; path = "Target Support Files/Pods-ImageMarkerExample/Pods-ImageMarkerExample.release.xcconfig"; sourceTree = "<group>"; };
4043
5DCACB8F33CDC322A6C60F78 /* libPods-ImageMarkerExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ImageMarkerExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4144
6F2EF2314753552DE3ED8A96 /* libPods-ImageMarkerExample-ImageMarkerExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ImageMarkerExample-ImageMarkerExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -44,6 +47,7 @@
4447
A119E9DE2B162437000C0527 /* ImageMarkerExampleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ImageMarkerExampleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4548
A119E9E02B162437000C0527 /* ImageMarkerExampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageMarkerExampleUITests.swift; sourceTree = "<group>"; };
4649
A119E9E22B162437000C0527 /* ImageMarkerExampleUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageMarkerExampleUITestsLaunchTests.swift; sourceTree = "<group>"; };
50+
E3DA1B9696844B35AAE670BD /* RubikBurned-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "RubikBurned-Regular.ttf"; path = "../assets/fonts/RubikBurned-Regular.ttf"; sourceTree = "<group>"; };
4751
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
4852
/* End PBXFileReference section */
4953

@@ -106,6 +110,7 @@
106110
83CBBA001A601CBA00E9B192 /* Products */,
107111
2D16E6871FA4F8E400B85C8A /* Frameworks */,
108112
BBD78D7AC51CEA395F1C20DB /* Pods */,
113+
A12431AF27494A9D92C20CF1 /* Resources */,
109114
);
110115
indentWidth = 2;
111116
sourceTree = "<group>";
@@ -130,6 +135,16 @@
130135
path = ImageMarkerExampleUITests;
131136
sourceTree = "<group>";
132137
};
138+
A12431AF27494A9D92C20CF1 /* Resources */ = {
139+
isa = PBXGroup;
140+
children = (
141+
E3DA1B9696844B35AAE670BD /* RubikBurned-Regular.ttf */,
142+
50CB977CE5BF44179F12CFF5 /* MaShanZheng-Regular.ttf */,
143+
);
144+
name = Resources;
145+
path = "";
146+
sourceTree = "<group>";
147+
};
133148
BBD78D7AC51CEA395F1C20DB /* Pods */ = {
134149
isa = PBXGroup;
135150
children = (
@@ -230,6 +245,8 @@
230245
files = (
231246
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
232247
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
248+
F95A8E69C66343EEB9A8D9DC /* RubikBurned-Regular.ttf in Resources */,
249+
93F7B1DDABE441E6B6212F21 /* MaShanZheng-Regular.ttf in Resources */,
233250
);
234251
runOnlyForDeploymentPostprocessing = 0;
235252
};

example/ios/ImageMarkerExample/Info.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<string></string>
3838
<key>NSPhotoLibraryUsageDescription</key>
3939
<string>want to use</string>
40+
<key>UIAppFonts</key>
41+
<array>
42+
<string>RubikBurned-Regular.ttf</string>
43+
<string>MaShanZheng-Regular.ttf</string>
44+
</array>
4045
<key>UILaunchStoryboardName</key>
4146
<string>LaunchScreen</string>
4247
<key>UIRequiredDeviceCapabilities</key>

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ PODS:
946946
- React-debug
947947
- react-native-blob-util (0.19.6):
948948
- React-Core
949-
- react-native-image-marker (1.2.1):
949+
- react-native-image-marker (1.2.2):
950950
- React-Core
951951
- react-native-image-picker (5.7.0):
952952
- React-Core
@@ -1360,7 +1360,7 @@ SPEC CHECKSUMS:
13601360
React-logger: e0c1e918d9588a9f39c9bc62d9d6bfe9ca238d9d
13611361
React-Mapbuffer: 9731a0a63ebaf8976014623c4d637744d7353a7c
13621362
react-native-blob-util: d8fa1a7f726867907a8e43163fdd8b441d4489ea
1363-
react-native-image-marker: c2352e04b9c5322c47154bd54430182889f4ebd3
1363+
react-native-image-marker: 5c211bedcc2c74c68775e63d58b6e76b6e4c7bee
13641364
react-native-image-picker: 3269f75c251cdcd61ab51b911dd30d6fff8c6169
13651365
React-nativeconfig: 37aecd26d64b79327c3f10e43b2e9a6c425e0a60
13661366
React-NativeModulesApple: 9ca6d2eaa1dd5606588262195b46d0774bdec83a

example/ios/link-assets-manifest.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"migIndex": 1,
3+
"data": [
4+
{
5+
"path": "assets/fonts/MaShanZheng-Regular.ttf",
6+
"sha1": "1376fdd48ab29afd9599101e8991b773f12177e5"
7+
},
8+
{
9+
"path": "assets/fonts/RubikBurned-Regular.ttf",
10+
"sha1": "546eccbc5a368bd10e6a4fe9570208428c16a036"
11+
}
12+
]
13+
}

example/react-native.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports = {
77
root: path.join(__dirname, '..'),
88
},
99
},
10+
assets: ['./assets/fonts'],
1011
};

example/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function useViewModel() {
485485
},
486486
style: {
487487
color: '#FF0000AA',
488-
fontName: 'Arial',
488+
fontName: 'MaShanZheng-Regular',
489489
fontSize,
490490
underline,
491491
bold,
@@ -520,7 +520,7 @@ function useViewModel() {
520520
},
521521
style: {
522522
color: '#FF00AA9F',
523-
fontName: 'NotoSansSC-Regular',
523+
fontName: 'RubikBurned-Regular',
524524
fontSize,
525525
underline,
526526
bold,
@@ -1146,7 +1146,7 @@ function App() {
11461146
/>
11471147
</RowSplit>
11481148
{/* <RowSplit>
1149-
1149+
11501150
</RowSplit> */}
11511151
<TouchableOpacity
11521152
style={[s.btn, { height: 40 }]}

0 commit comments

Comments
 (0)