expo-font 13.1.2 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/expo/modules/font/FontUtilsModule.kt +71 -0
  4. package/android/src/main/java/expo/modules/font/FontUtilsRecords.kt +16 -0
  5. package/build/ExpoFontUtils.d.ts +3 -0
  6. package/build/ExpoFontUtils.d.ts.map +1 -0
  7. package/build/ExpoFontUtils.js +3 -0
  8. package/build/ExpoFontUtils.js.map +1 -0
  9. package/build/ExpoFontUtils.web.d.ts +8 -0
  10. package/build/ExpoFontUtils.web.d.ts.map +1 -0
  11. package/build/ExpoFontUtils.web.js +8 -0
  12. package/build/ExpoFontUtils.web.js.map +1 -0
  13. package/build/FontUtils.d.ts +11 -0
  14. package/build/FontUtils.d.ts.map +1 -0
  15. package/build/FontUtils.js +17 -0
  16. package/build/FontUtils.js.map +1 -0
  17. package/build/FontUtils.types.d.ts +18 -0
  18. package/build/FontUtils.types.d.ts.map +1 -0
  19. package/build/FontUtils.types.js +2 -0
  20. package/build/FontUtils.types.js.map +1 -0
  21. package/build/index.d.ts +1 -0
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +1 -0
  24. package/build/index.js.map +1 -1
  25. package/expo-module.config.json +3 -3
  26. package/ios/FontExceptions.swift +12 -0
  27. package/ios/FontUtilsModule.swift +48 -0
  28. package/ios/FontUtilsRecords.swift +10 -0
  29. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar +0 -0
  30. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.md5 +1 -0
  31. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.sha1 +1 -0
  32. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.sha256 +1 -0
  33. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.sha512 +1 -0
  34. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar +0 -0
  35. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.md5 +1 -0
  36. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.sha1 +1 -0
  37. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.sha256 +1 -0
  38. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.sha512 +1 -0
  39. package/local-maven-repo/host/exp/exponent/expo.modules.font/{13.1.2/expo.modules.font-13.1.2.module → 13.2.0/expo.modules.font-13.2.0.module} +22 -22
  40. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.md5 +1 -0
  41. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.sha1 +1 -0
  42. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.sha256 +1 -0
  43. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.sha512 +1 -0
  44. package/local-maven-repo/host/exp/exponent/expo.modules.font/{13.1.2/expo.modules.font-13.1.2.pom → 13.2.0/expo.modules.font-13.2.0.pom} +1 -1
  45. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.md5 +1 -0
  46. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.sha1 +1 -0
  47. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.sha256 +1 -0
  48. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.sha512 +1 -0
  49. package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml +4 -4
  50. package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.md5 +1 -1
  51. package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.sha1 +1 -1
  52. package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.sha256 +1 -1
  53. package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.sha512 +1 -1
  54. package/package.json +2 -2
  55. package/src/ExpoFontUtils.ts +3 -0
  56. package/src/ExpoFontUtils.web.ts +11 -0
  57. package/src/FontUtils.ts +22 -0
  58. package/src/FontUtils.types.ts +17 -0
  59. package/src/index.ts +1 -0
  60. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2-sources.jar +0 -0
  61. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2-sources.jar.md5 +0 -1
  62. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2-sources.jar.sha1 +0 -1
  63. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2-sources.jar.sha256 +0 -1
  64. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2-sources.jar.sha512 +0 -1
  65. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.aar +0 -0
  66. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.aar.md5 +0 -1
  67. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.aar.sha1 +0 -1
  68. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.aar.sha256 +0 -1
  69. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.aar.sha512 +0 -1
  70. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.module.md5 +0 -1
  71. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.module.sha1 +0 -1
  72. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.module.sha256 +0 -1
  73. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.module.sha512 +0 -1
  74. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.pom.md5 +0 -1
  75. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.pom.sha1 +0 -1
  76. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.pom.sha256 +0 -1
  77. package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.2/expo.modules.font-13.1.2.pom.sha512 +0 -1
package/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 13.2.0 — 2025-04-21
14
+
15
+ ### 🎉 New features
16
+
17
+ - Render to image ([#36185](https://github.com/expo/expo/pull/36185) by [@jakex7](https://github.com/jakex7))
18
+
13
19
  ## 13.1.2 — 2025-04-14
14
20
 
15
21
  _This version does not introduce any user-facing changes._
@@ -4,13 +4,13 @@ plugins {
4
4
  }
5
5
 
6
6
  group = 'host.exp.exponent'
7
- version = '13.1.2'
7
+ version = '13.2.0'
8
8
 
9
9
  android {
10
10
  namespace "expo.modules.font"
11
11
  defaultConfig {
12
12
  versionCode 29
13
- versionName "13.1.2"
13
+ versionName "13.2.0"
14
14
  }
15
15
  }
16
16
 
@@ -0,0 +1,71 @@
1
+ // Copyright 2015-present 650 Industries. All rights reserved.
2
+
3
+ package expo.modules.font
4
+
5
+ import android.content.Context
6
+ import android.graphics.Bitmap
7
+ import android.graphics.Canvas
8
+ import android.graphics.Paint
9
+ import android.graphics.Rect
10
+ import android.graphics.Typeface
11
+ import android.net.Uri
12
+ import com.facebook.react.common.assets.ReactFontManager
13
+ import expo.modules.kotlin.Promise
14
+ import expo.modules.kotlin.exception.CodedException
15
+ import expo.modules.kotlin.exception.Exceptions
16
+ import expo.modules.kotlin.modules.Module
17
+ import expo.modules.kotlin.modules.ModuleDefinition
18
+ import java.io.File
19
+ import java.io.FileOutputStream
20
+ import java.io.IOException
21
+ import java.util.UUID
22
+ import kotlin.math.abs
23
+
24
+ private class SaveImageException(uri: String, cause: Throwable? = null) :
25
+ CodedException("Could not save image to '$uri'", cause)
26
+
27
+ open class FontUtilsModule : Module() {
28
+ private val context: Context
29
+ get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
30
+
31
+ override fun definition() = ModuleDefinition {
32
+ Name("ExpoFontUtils")
33
+
34
+ AsyncFunction("renderToImageAsync") { glyphs: String, options: RenderToImageOptions, promise: Promise ->
35
+ val typeface = ReactFontManager.getInstance().getTypeface(options.fontFamily, Typeface.NORMAL, context.assets)
36
+
37
+ val paint = Paint().apply {
38
+ this.typeface = typeface
39
+ this.color = options.color
40
+ this.textSize = options.size
41
+ this.isAntiAlias = true
42
+ }
43
+
44
+ val bounds = Rect().also {
45
+ paint.getTextBounds(glyphs, 0, glyphs.length, it)
46
+ }
47
+
48
+ val bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888)
49
+ val canvas = Canvas(bitmap)
50
+
51
+ val x = abs(bounds.left).toFloat()
52
+ val y = bounds.height().toFloat() / 2 - ((paint.fontMetrics.ascent + paint.fontMetrics.descent) / 2)
53
+
54
+ canvas.drawText(glyphs, x, y, paint)
55
+
56
+ val output = File(context.cacheDir, "${UUID.randomUUID()}.png")
57
+ if (!output.exists()) {
58
+ output.createNewFile()
59
+ }
60
+
61
+ try {
62
+ FileOutputStream(output).use { out ->
63
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
64
+ promise.resolve(Uri.fromFile(output))
65
+ }
66
+ } catch (e: IOException) {
67
+ promise.reject(SaveImageException(output.absolutePath, e))
68
+ }
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,16 @@
1
+ package expo.modules.font
2
+
3
+ import android.graphics.Color
4
+ import expo.modules.kotlin.records.Field
5
+ import expo.modules.kotlin.records.Record
6
+
7
+ data class RenderToImageOptions(
8
+ @Field
9
+ val fontFamily: String = "",
10
+
11
+ @Field
12
+ val size: Float = 24f,
13
+
14
+ @Field
15
+ val color: Int = Color.BLACK
16
+ ) : Record
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=ExpoFontUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoFontUtils.d.ts","sourceRoot":"","sources":["../src/ExpoFontUtils.ts"],"names":[],"mappings":";AAEA,wBAAoD"}
@@ -0,0 +1,3 @@
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoFontUtils');
3
+ //# sourceMappingURL=ExpoFontUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoFontUtils.js","sourceRoot":"","sources":["../src/ExpoFontUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,eAAe,mBAAmB,CAAC,eAAe,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\n\nexport default requireNativeModule('ExpoFontUtils');\n"]}
@@ -0,0 +1,8 @@
1
+ import { NativeModule } from 'expo-modules-core';
2
+ import { RenderToImageOptions } from './FontUtils.types';
3
+ declare class ExpoFontUtils extends NativeModule {
4
+ renderToImageAsync(glyphs: string, options?: RenderToImageOptions): Promise<string>;
5
+ }
6
+ declare const _default: typeof ExpoFontUtils;
7
+ export default _default;
8
+ //# sourceMappingURL=ExpoFontUtils.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoFontUtils.web.d.ts","sourceRoot":"","sources":["../src/ExpoFontUtils.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0C,MAAM,mBAAmB,CAAC;AAEzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,cAAM,aAAc,SAAQ,YAAY;IAChC,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;CAG1F;;AAED,wBAAiE"}
@@ -0,0 +1,8 @@
1
+ import { NativeModule, registerWebModule, UnavailabilityError } from 'expo-modules-core';
2
+ class ExpoFontUtils extends NativeModule {
3
+ async renderToImageAsync(glyphs, options) {
4
+ throw new UnavailabilityError('expo-font', 'renderToImageAsync');
5
+ }
6
+ }
7
+ export default registerWebModule(ExpoFontUtils, 'ExpoFontUtils');
8
+ //# sourceMappingURL=ExpoFontUtils.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoFontUtils.web.js","sourceRoot":"","sources":["../src/ExpoFontUtils.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAIzF,MAAM,aAAc,SAAQ,YAAY;IACtC,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,OAA8B;QACrE,MAAM,IAAI,mBAAmB,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;IACnE,CAAC;CACF;AAED,eAAe,iBAAiB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { NativeModule, registerWebModule, UnavailabilityError } from 'expo-modules-core';\n\nimport { RenderToImageOptions } from './FontUtils.types';\n\nclass ExpoFontUtils extends NativeModule {\n async renderToImageAsync(glyphs: string, options?: RenderToImageOptions): Promise<string> {\n throw new UnavailabilityError('expo-font', 'renderToImageAsync');\n }\n}\n\nexport default registerWebModule(ExpoFontUtils, 'ExpoFontUtils');\n"]}
@@ -0,0 +1,11 @@
1
+ import { RenderToImageOptions } from './FontUtils.types';
2
+ /**
3
+ * Creates an image with provided text.
4
+ * @param glyphs Text to be exported.
5
+ * @param options RenderToImageOptions.
6
+ * @return Promise which fulfils with uri to image.
7
+ * @platform android
8
+ * @platform ios
9
+ */
10
+ export declare function renderToImageAsync(glyphs: string, options?: RenderToImageOptions): Promise<string>;
11
+ //# sourceMappingURL=FontUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontUtils.d.ts","sourceRoot":"","sources":["../src/FontUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,MAAM,CAAC,CAKjB"}
@@ -0,0 +1,17 @@
1
+ import { processColor } from 'react-native';
2
+ import ExpoFontUtils from './ExpoFontUtils';
3
+ /**
4
+ * Creates an image with provided text.
5
+ * @param glyphs Text to be exported.
6
+ * @param options RenderToImageOptions.
7
+ * @return Promise which fulfils with uri to image.
8
+ * @platform android
9
+ * @platform ios
10
+ */
11
+ export async function renderToImageAsync(glyphs, options) {
12
+ return await ExpoFontUtils.renderToImageAsync(glyphs, {
13
+ ...options,
14
+ color: options?.color ? processColor(options.color) : undefined,
15
+ });
16
+ }
17
+ //# sourceMappingURL=FontUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontUtils.js","sourceRoot":"","sources":["../src/FontUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAG5C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAc,EACd,OAA8B;IAE9B,OAAO,MAAM,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE;QACpD,GAAG,OAAO;QACV,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;KAChE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { processColor } from 'react-native';\n\nimport ExpoFontUtils from './ExpoFontUtils';\nimport { RenderToImageOptions } from './FontUtils.types';\n\n/**\n * Creates an image with provided text.\n * @param glyphs Text to be exported.\n * @param options RenderToImageOptions.\n * @return Promise which fulfils with uri to image.\n * @platform android\n * @platform ios\n */\nexport async function renderToImageAsync(\n glyphs: string,\n options?: RenderToImageOptions\n): Promise<string> {\n return await ExpoFontUtils.renderToImageAsync(glyphs, {\n ...options,\n color: options?.color ? processColor(options.color) : undefined,\n });\n}\n"]}
@@ -0,0 +1,18 @@
1
+ export interface RenderToImageOptions {
2
+ /**
3
+ * Font family name.
4
+ * @default system default
5
+ */
6
+ fontFamily?: string;
7
+ /**
8
+ * Size of the font.
9
+ * @default 24
10
+ */
11
+ size?: number;
12
+ /**
13
+ * Font color
14
+ * @default 'black'
15
+ */
16
+ color?: string;
17
+ }
18
+ //# sourceMappingURL=FontUtils.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontUtils.types.d.ts","sourceRoot":"","sources":["../src/FontUtils.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=FontUtils.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FontUtils.types.js","sourceRoot":"","sources":["../src/FontUtils.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface RenderToImageOptions {\n /**\n * Font family name.\n * @default system default\n */\n fontFamily?: string;\n /**\n * Size of the font.\n * @default 24\n */\n size?: number;\n /**\n * Font color\n * @default 'black'\n */\n color?: string;\n}\n"]}
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Font';
2
+ export * from './FontUtils';
2
3
  export { useFonts } from './FontHooks';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
package/build/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Font';
2
+ export * from './FontUtils';
2
3
  export { useFonts } from './FontHooks';
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export * from './Font';\nexport { useFonts } from './FontHooks';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export * from './Font';\nexport * from './FontUtils';\nexport { useFonts } from './FontHooks';\n"]}
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "platforms": ["apple", "android", "web"],
3
3
  "apple": {
4
- "modules": ["FontLoaderModule"]
4
+ "modules": ["FontLoaderModule", "FontUtilsModule"]
5
5
  },
6
6
  "android": {
7
- "modules": ["expo.modules.font.FontLoaderModule"],
7
+ "modules": ["expo.modules.font.FontLoaderModule", "expo.modules.font.FontUtilsModule"],
8
8
  "publication": {
9
9
  "groupId": "host.exp.exponent",
10
10
  "artifactId": "expo.modules.font",
11
- "version": "13.1.2",
11
+ "version": "13.2.0",
12
12
  "repository": "local-maven-repo"
13
13
  }
14
14
  }
@@ -36,3 +36,15 @@ internal final class UnregisteringFontFailedException: GenericException<CFError>
36
36
  "Unregistering font failed with message: '\(param.localizedDescription)'"
37
37
  }
38
38
  }
39
+
40
+ internal final class CreateImageException: Exception {
41
+ override var reason: String {
42
+ "Could not create image"
43
+ }
44
+ }
45
+
46
+ internal final class SaveImageException: GenericException<String> {
47
+ override var reason: String {
48
+ "Could not save image to '\(param)'"
49
+ }
50
+ }
@@ -0,0 +1,48 @@
1
+ // Copyright 2025-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+
5
+ public final class FontUtilsModule: Module {
6
+ public func definition() -> ModuleDefinition {
7
+ Name("ExpoFontUtils")
8
+
9
+ #if !os(macOS)
10
+ AsyncFunction("renderToImageAsync") { (glyphs: String, options: RenderToImageOptions, promise: Promise) throws in
11
+ let font: UIFont
12
+ if let fontName = UIFont.fontNames(forFamilyName: options.fontFamily).first,
13
+ let uiFont = UIFont(name: fontName, size: options.size) {
14
+ font = uiFont
15
+ } else {
16
+ font = UIFont.systemFont(ofSize: options.size)
17
+ }
18
+
19
+ let attributedString = NSAttributedString(
20
+ string: glyphs,
21
+ attributes: [
22
+ .font: font,
23
+ .foregroundColor: UIColor(options.color)
24
+ ]
25
+ )
26
+
27
+ let renderer = UIGraphicsImageRenderer(size: attributedString.size())
28
+ let image = renderer.image { _ in
29
+ attributedString.draw(at: .zero)
30
+ }
31
+
32
+ guard let data = image.pngData() else {
33
+ promise.reject(CreateImageException())
34
+ return
35
+ }
36
+
37
+ let outputURL = URL(fileURLWithPath: "\(NSTemporaryDirectory())\(UUID().uuidString).png")
38
+
39
+ do {
40
+ try data.write(to: outputURL, options: .atomic)
41
+ promise.resolve(outputURL.absoluteString)
42
+ } catch {
43
+ promise.reject(SaveImageException(outputURL.absoluteString))
44
+ }
45
+ }
46
+ #endif
47
+ }
48
+ }
@@ -0,0 +1,10 @@
1
+ // Copyright 2025-present 650 Industries. All rights reserved.
2
+
3
+ import SwiftUI
4
+ import ExpoModulesCore
5
+
6
+ struct RenderToImageOptions: Record {
7
+ @Field var fontFamily: String = ""
8
+ @Field var size: CGFloat = 24
9
+ @Field var color: Color = .black
10
+ }
@@ -0,0 +1 @@
1
+ c029366141433ab312f41026590eb119ef648137f3b6cebeb416531fc0b4cccc
@@ -0,0 +1 @@
1
+ 04d8003327d266d74c7c2123206ff0c008db185c4fe9ce8518e6c47af1ed8d3118db35e094ceb19451c622318ac15e9fa9eaea609d7fae69cedec95e1656c20a
@@ -0,0 +1 @@
1
+ 8a3e0658bef6d46ddbdfaf891baba11daaadbfc8
@@ -0,0 +1 @@
1
+ 02e3e22b8a6570b0a9ae2d3fff74bcb898a90480d271d162ef76c2c6415fd763
@@ -0,0 +1 @@
1
+ 23e09b1c63cedb2c4e2063a509bdd0ecb91c8815cb946ef3707fba50b7ca2f4ac3c20d825847a1885cec0fd3c29dbd153d730acc552a33e5c031928551c707ab
@@ -3,7 +3,7 @@
3
3
  "component": {
4
4
  "group": "host.exp.exponent",
5
5
  "module": "expo.modules.font",
6
- "version": "13.1.2",
6
+ "version": "13.2.0",
7
7
  "attributes": {
8
8
  "org.gradle.status": "release"
9
9
  }
@@ -24,13 +24,13 @@
24
24
  },
25
25
  "files": [
26
26
  {
27
- "name": "expo.modules.font-13.1.2.aar",
28
- "url": "expo.modules.font-13.1.2.aar",
29
- "size": 13045,
30
- "sha512": "6b0d739ff6720adf9bcefcfde410dd8b4c1cd8783abf788d42b429a51caed98dcce305b30ab4ec82dabc0379b46f344ca0581ed1b281b09e1c568319e2563bc5",
31
- "sha256": "df73df860315a2f01896ec47d5ed6740b9b3f7339d47d0418360859f05fe1088",
32
- "sha1": "ac0cf41e2f0905c4d87505fa1bfa5c4bb9ebb0a9",
33
- "md5": "28ac3500cafc491337446819fbff1ed9"
27
+ "name": "expo.modules.font-13.2.0.aar",
28
+ "url": "expo.modules.font-13.2.0.aar",
29
+ "size": 23940,
30
+ "sha512": "23e09b1c63cedb2c4e2063a509bdd0ecb91c8815cb946ef3707fba50b7ca2f4ac3c20d825847a1885cec0fd3c29dbd153d730acc552a33e5c031928551c707ab",
31
+ "sha256": "02e3e22b8a6570b0a9ae2d3fff74bcb898a90480d271d162ef76c2c6415fd763",
32
+ "sha1": "8a3e0658bef6d46ddbdfaf891baba11daaadbfc8",
33
+ "md5": "c4a5fbec91ef91f550b4a16b8011c1da"
34
34
  }
35
35
  ]
36
36
  },
@@ -57,13 +57,13 @@
57
57
  ],
58
58
  "files": [
59
59
  {
60
- "name": "expo.modules.font-13.1.2.aar",
61
- "url": "expo.modules.font-13.1.2.aar",
62
- "size": 13045,
63
- "sha512": "6b0d739ff6720adf9bcefcfde410dd8b4c1cd8783abf788d42b429a51caed98dcce305b30ab4ec82dabc0379b46f344ca0581ed1b281b09e1c568319e2563bc5",
64
- "sha256": "df73df860315a2f01896ec47d5ed6740b9b3f7339d47d0418360859f05fe1088",
65
- "sha1": "ac0cf41e2f0905c4d87505fa1bfa5c4bb9ebb0a9",
66
- "md5": "28ac3500cafc491337446819fbff1ed9"
60
+ "name": "expo.modules.font-13.2.0.aar",
61
+ "url": "expo.modules.font-13.2.0.aar",
62
+ "size": 23940,
63
+ "sha512": "23e09b1c63cedb2c4e2063a509bdd0ecb91c8815cb946ef3707fba50b7ca2f4ac3c20d825847a1885cec0fd3c29dbd153d730acc552a33e5c031928551c707ab",
64
+ "sha256": "02e3e22b8a6570b0a9ae2d3fff74bcb898a90480d271d162ef76c2c6415fd763",
65
+ "sha1": "8a3e0658bef6d46ddbdfaf891baba11daaadbfc8",
66
+ "md5": "c4a5fbec91ef91f550b4a16b8011c1da"
67
67
  }
68
68
  ]
69
69
  },
@@ -77,13 +77,13 @@
77
77
  },
78
78
  "files": [
79
79
  {
80
- "name": "expo.modules.font-13.1.2-sources.jar",
81
- "url": "expo.modules.font-13.1.2-sources.jar",
82
- "size": 2181,
83
- "sha512": "922d17ab9404230df7a55676e7c308ad010b49278562a12051eb7f8f518683f2020eabb96ae0ee79b908dd49572830eea6d9cf7c579ef5db7be04ef2c864a093",
84
- "sha256": "857820932e52dbe80e0f58011d164e892ed37213dd74c3dc30fe70739d0f94fa",
85
- "sha1": "82b8aba4d9525e564f2cbc4299b3623fe5304232",
86
- "md5": "584be3c85f2cea79a438cb3029de44b1"
80
+ "name": "expo.modules.font-13.2.0-sources.jar",
81
+ "url": "expo.modules.font-13.2.0-sources.jar",
82
+ "size": 3643,
83
+ "sha512": "04d8003327d266d74c7c2123206ff0c008db185c4fe9ce8518e6c47af1ed8d3118db35e094ceb19451c622318ac15e9fa9eaea609d7fae69cedec95e1656c20a",
84
+ "sha256": "c029366141433ab312f41026590eb119ef648137f3b6cebeb416531fc0b4cccc",
85
+ "sha1": "58f3bf67ec556651368352816436127f20c27a0c",
86
+ "md5": "85fa250981be0d9c2cfe380914137d32"
87
87
  }
88
88
  ]
89
89
  }
@@ -0,0 +1 @@
1
+ 32487e83f3483cd8f9494f9595ee19c1680d8641d9565832dd5ef6edf6285336
@@ -0,0 +1 @@
1
+ 6919cb414a23fc083a174a869e3701e577eaed75907051f81dc69d67465437a805fb88268810becee817b68fe933d1ec87cf28b87cc6d1c31915b497954956d8
@@ -9,7 +9,7 @@
9
9
  <modelVersion>4.0.0</modelVersion>
10
10
  <groupId>host.exp.exponent</groupId>
11
11
  <artifactId>expo.modules.font</artifactId>
12
- <version>13.1.2</version>
12
+ <version>13.2.0</version>
13
13
  <packaging>aar</packaging>
14
14
  <name>expo.modules.font</name>
15
15
  <url>https://github.com/expo/expo</url>
@@ -0,0 +1 @@
1
+ 22d6632a3c482e6a9d87335cc784380ddb84c413
@@ -0,0 +1 @@
1
+ 2329a4ecf3f9a2f1ac66221df5bfda3e42217dc3c699129253159dabd39ba9a8
@@ -0,0 +1 @@
1
+ eb22c4fa3fd2c30dbe8f58c226f0d9820b04940182ad553cec0e78bb4324d2bac4a6cdc89198a0d9bb3e58b24c7d6600aa028855da52ca34eb5b935c34ac1289
@@ -3,11 +3,11 @@
3
3
  <groupId>host.exp.exponent</groupId>
4
4
  <artifactId>expo.modules.font</artifactId>
5
5
  <versioning>
6
- <latest>13.1.2</latest>
7
- <release>13.1.2</release>
6
+ <latest>13.2.0</latest>
7
+ <release>13.2.0</release>
8
8
  <versions>
9
- <version>13.1.2</version>
9
+ <version>13.2.0</version>
10
10
  </versions>
11
- <lastUpdated>20250414185044</lastUpdated>
11
+ <lastUpdated>20250421213308</lastUpdated>
12
12
  </versioning>
13
13
  </metadata>
@@ -1 +1 @@
1
- 4e2e920f1ff6bd97ce42b6680f150cf7
1
+ 03e013cfd9238f8e9bd83c76751baa30
@@ -1 +1 @@
1
- b1ca3a37fa0bbeb0dba6cb727a969b76374e3dfa
1
+ 71d5799b8f1517ce9c837dd1105a3c1bf4b12842
@@ -1 +1 @@
1
- bc5200a7182b884bc3256ad990eb9b007438b47c0a30ce56877d2b0d7367bcd7
1
+ 9be03f2203a7220638e78d74824e54553443db59a5f71a8f0c5a1c60f6ab59b0
@@ -1 +1 @@
1
- 8198b84598395cc5e9c8c312f9f212f79a4a9fa25d15e3ee333648f3102f96a8a6af99b2371e03efc2709c7a272d486fc067b3110180dae1969ccd33c32fe90f
1
+ 9a1c6d59d8c1637d2c8e9c069de5549f9fdc760b8a8d0e8462692e71ed57117c9aede5de1cffd52489da29e3af1b6509472e5bf344b26e10d43e7ca50608604b
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-font",
3
- "version": "13.1.2",
3
+ "version": "13.2.0",
4
4
  "description": "Load fonts at runtime and use them in React Native components.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -56,5 +56,5 @@
56
56
  "expo": "*",
57
57
  "react": "*"
58
58
  },
59
- "gitHead": "cb9fdd93f76f28e2ace4f66080b2386d87239553"
59
+ "gitHead": "f1394f21ff2719a9a3037d7511db170704e5c492"
60
60
  }
@@ -0,0 +1,3 @@
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+
3
+ export default requireNativeModule('ExpoFontUtils');
@@ -0,0 +1,11 @@
1
+ import { NativeModule, registerWebModule, UnavailabilityError } from 'expo-modules-core';
2
+
3
+ import { RenderToImageOptions } from './FontUtils.types';
4
+
5
+ class ExpoFontUtils extends NativeModule {
6
+ async renderToImageAsync(glyphs: string, options?: RenderToImageOptions): Promise<string> {
7
+ throw new UnavailabilityError('expo-font', 'renderToImageAsync');
8
+ }
9
+ }
10
+
11
+ export default registerWebModule(ExpoFontUtils, 'ExpoFontUtils');
@@ -0,0 +1,22 @@
1
+ import { processColor } from 'react-native';
2
+
3
+ import ExpoFontUtils from './ExpoFontUtils';
4
+ import { RenderToImageOptions } from './FontUtils.types';
5
+
6
+ /**
7
+ * Creates an image with provided text.
8
+ * @param glyphs Text to be exported.
9
+ * @param options RenderToImageOptions.
10
+ * @return Promise which fulfils with uri to image.
11
+ * @platform android
12
+ * @platform ios
13
+ */
14
+ export async function renderToImageAsync(
15
+ glyphs: string,
16
+ options?: RenderToImageOptions
17
+ ): Promise<string> {
18
+ return await ExpoFontUtils.renderToImageAsync(glyphs, {
19
+ ...options,
20
+ color: options?.color ? processColor(options.color) : undefined,
21
+ });
22
+ }
@@ -0,0 +1,17 @@
1
+ export interface RenderToImageOptions {
2
+ /**
3
+ * Font family name.
4
+ * @default system default
5
+ */
6
+ fontFamily?: string;
7
+ /**
8
+ * Size of the font.
9
+ * @default 24
10
+ */
11
+ size?: number;
12
+ /**
13
+ * Font color
14
+ * @default 'black'
15
+ */
16
+ color?: string;
17
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './Font';
2
+ export * from './FontUtils';
2
3
  export { useFonts } from './FontHooks';
@@ -1 +0,0 @@
1
- 857820932e52dbe80e0f58011d164e892ed37213dd74c3dc30fe70739d0f94fa
@@ -1 +0,0 @@
1
- 922d17ab9404230df7a55676e7c308ad010b49278562a12051eb7f8f518683f2020eabb96ae0ee79b908dd49572830eea6d9cf7c579ef5db7be04ef2c864a093
@@ -1 +0,0 @@
1
- ac0cf41e2f0905c4d87505fa1bfa5c4bb9ebb0a9
@@ -1 +0,0 @@
1
- df73df860315a2f01896ec47d5ed6740b9b3f7339d47d0418360859f05fe1088
@@ -1 +0,0 @@
1
- 6b0d739ff6720adf9bcefcfde410dd8b4c1cd8783abf788d42b429a51caed98dcce305b30ab4ec82dabc0379b46f344ca0581ed1b281b09e1c568319e2563bc5
@@ -1 +0,0 @@
1
- 82cca00facc751d187c9172bc37447953432e815
@@ -1 +0,0 @@
1
- 2e3c04d1a2830af88f48fdc9ee254e872dab8334ae145f669c3bd71d54c51958
@@ -1 +0,0 @@
1
- f4734385080954f5052b9761b3dfa084720148bda7284839cc9ef96d4c0a88563f31e9e7020f522f6264614ceaa99d7c6de81c503d92a592e3717701ba42faef
@@ -1 +0,0 @@
1
- 570f076031db97d373b9a27841b7cd5ea93184ed
@@ -1 +0,0 @@
1
- e0df9fe6fb59b1ced301f6d336250c7cc1ef616853303db73e1a9a57c880e883
@@ -1 +0,0 @@
1
- b2f055d1febbbd8d4d1c1109424dd1d7458046f3b1d4fd9ca7d371929e74f4e9fe51b51d193e30b44d5bc1a7ac3be0a7af5781135b5cbeffa513df8a7241b385