expo-font 13.1.1 → 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.
- package/CHANGELOG.md +10 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/font/FontUtilsModule.kt +71 -0
- package/android/src/main/java/expo/modules/font/FontUtilsRecords.kt +16 -0
- package/build/ExpoFontLoader.web.d.ts.map +1 -1
- package/build/ExpoFontLoader.web.js +4 -1
- package/build/ExpoFontLoader.web.js.map +1 -1
- package/build/ExpoFontUtils.d.ts +3 -0
- package/build/ExpoFontUtils.d.ts.map +1 -0
- package/build/ExpoFontUtils.js +3 -0
- package/build/ExpoFontUtils.js.map +1 -0
- package/build/ExpoFontUtils.web.d.ts +8 -0
- package/build/ExpoFontUtils.web.d.ts.map +1 -0
- package/build/ExpoFontUtils.web.js +8 -0
- package/build/ExpoFontUtils.web.js.map +1 -0
- package/build/FontUtils.d.ts +11 -0
- package/build/FontUtils.d.ts.map +1 -0
- package/build/FontUtils.js +17 -0
- package/build/FontUtils.js.map +1 -0
- package/build/FontUtils.types.d.ts +18 -0
- package/build/FontUtils.types.d.ts.map +1 -0
- package/build/FontUtils.types.js +2 -0
- package/build/FontUtils.types.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/expo-module.config.json +3 -3
- package/ios/FontExceptions.swift +12 -0
- package/ios/FontUtilsModule.swift +48 -0
- package/ios/FontUtilsRecords.swift +10 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0-sources.jar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/{13.1.1/expo.modules.font-13.1.1.module → 13.2.0/expo.modules.font-13.2.0.module} +22 -22
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.module.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/{13.1.1/expo.modules.font-13.1.1.pom → 13.2.0/expo.modules.font-13.2.0.pom} +1 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.md5 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.sha1 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.sha256 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.sha512 +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml +4 -4
- package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.md5 +1 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.sha1 +1 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.sha256 +1 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/maven-metadata.xml.sha512 +1 -1
- package/package.json +4 -3
- package/src/ExpoFontLoader.web.ts +4 -1
- package/src/ExpoFontUtils.ts +3 -0
- package/src/ExpoFontUtils.web.ts +11 -0
- package/src/FontUtils.ts +22 -0
- package/src/FontUtils.types.ts +17 -0
- package/src/index.ts +1 -0
- package/src/ts-declarations/react-native-assets.d.ts +1 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1-sources.jar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1-sources.jar.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1-sources.jar.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1-sources.jar.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1-sources.jar.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar +0 -0
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.module.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.module.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.module.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.module.sha512 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.pom.md5 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.pom.sha1 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.pom.sha256 +0 -1
- package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.pom.sha512 +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,16 @@
|
|
|
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
|
+
|
|
19
|
+
## 13.1.2 — 2025-04-14
|
|
20
|
+
|
|
21
|
+
_This version does not introduce any user-facing changes._
|
|
22
|
+
|
|
13
23
|
## 13.1.1 — 2025-04-09
|
|
14
24
|
|
|
15
25
|
_This version does not introduce any user-facing changes._
|
package/android/build.gradle
CHANGED
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoFontLoader.web.d.ts","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;;sBAiF/B,OAAO,CAAC,IAAI,CAAC;gCASH,MAAM,YAAY,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;0BAS/D,MAAM,EAAE;;sBAqBZ,MAAM,EAAE;6BAQD,MAAM,aAAY,iBAAiB,GAAQ,OAAO;8BAUjD,MAAM,YAAY,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;;AA1D1E,
|
|
1
|
+
{"version":3,"file":"ExpoFontLoader.web.d.ts","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;;sBAiF/B,OAAO,CAAC,IAAI,CAAC;gCASH,MAAM,YAAY,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;0BAS/D,MAAM,EAAE;;sBAqBZ,MAAM,EAAE;6BAQD,MAAM,aAAY,iBAAiB,GAAQ,OAAO;8BAUjD,MAAM,YAAY,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;;AA1D1E,wBA8FE;AAeF,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,CAIzF"}
|
|
@@ -131,7 +131,10 @@ export default {
|
|
|
131
131
|
if (!isFontLoadingListenerSupported()) {
|
|
132
132
|
return Promise.resolve();
|
|
133
133
|
}
|
|
134
|
-
return new FontObserver(fontFamilyName, {
|
|
134
|
+
return new FontObserver(fontFamilyName, {
|
|
135
|
+
// @ts-expect-error: TODO(@kitten): Typings indicate that the polyfill may not support this?
|
|
136
|
+
display: resource.display,
|
|
137
|
+
}).load(null, 6000);
|
|
135
138
|
},
|
|
136
139
|
};
|
|
137
140
|
const ID = 'expo-generated-fonts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoFontLoader.web.js","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,YAAY,MAAM,k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C,OAAO;YACnE,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,OAAO,GAAG,SAAS;YAC/C,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACpD,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,8BAA8B;IACrC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;IACvC,2EAA2E;IAC3E,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,gCAAgC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5E,iGAAiG;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,oBAAoB;IACpB,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,UAAU;IACV,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChD,OAAO,CAAC,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;AAC/D,CAAC","sourcesContent":["import { CodedError, Platform } from 'expo-modules-core';\nimport FontObserver from 'fontfaceobserver';\n\nimport { UnloadFontOptions } from './Font';\nimport { FontDisplay, FontResource } from './Font.types';\n\nfunction getFontFaceStyleSheet(): CSSStyleSheet | null {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const styleSheet = getStyleElement();\n return styleSheet.sheet ? (styleSheet.sheet as CSSStyleSheet) : null;\n}\n\ntype RuleItem = { rule: CSSFontFaceRule; index: number };\n\nfunction getFontFaceRules(): RuleItem[] {\n const sheet = getFontFaceStyleSheet();\n if (sheet) {\n // @ts-ignore: rule iterator\n const rules = [...sheet.cssRules];\n\n const items: RuleItem[] = [];\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i];\n if (rule instanceof CSSFontFaceRule) {\n items.push({ rule, index: i });\n }\n }\n return items;\n }\n return [];\n}\n\nfunction getFontFaceRulesMatchingResource(\n fontFamilyName: string,\n options?: UnloadFontOptions\n): RuleItem[] {\n const rules = getFontFaceRules();\n return rules.filter(({ rule }) => {\n return (\n rule.style.fontFamily === fontFamilyName &&\n (options && options.display ? options.display === (rule.style as any).fontDisplay : true)\n );\n });\n}\n\nconst serverContext: Set<{ name: string; css: string; resourceId: string }> = new Set();\n\nfunction getHeadElements(): {\n $$type: string;\n rel?: string;\n href?: string;\n as?: string;\n crossorigin?: string;\n children?: string;\n id?: string;\n type?: string;\n}[] {\n const entries = [...serverContext.entries()];\n if (!entries.length) {\n return [];\n }\n const css = entries.map(([{ css }]) => css).join('\\n');\n const links = entries.map(([{ resourceId }]) => resourceId);\n // TODO: Maybe return nothing if no fonts were loaded.\n return [\n {\n $$type: 'style',\n children: css,\n id: ID,\n type: 'text/css',\n },\n ...links.map((resourceId) => ({\n $$type: 'link',\n rel: 'preload',\n href: resourceId,\n as: 'font',\n crossorigin: '',\n })),\n ];\n}\n\nexport default {\n async unloadAllAsync(): Promise<void> {\n if (!Platform.isDOMAvailable) return;\n\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n document.removeChild(element);\n }\n },\n\n async unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void> {\n const sheet = getFontFaceStyleSheet();\n if (!sheet) return;\n const items = getFontFaceRulesMatchingResource(fontFamilyName, options);\n for (const item of items) {\n sheet.deleteRule(item.index);\n }\n },\n\n getServerResources(): string[] {\n const elements = getHeadElements();\n\n return elements\n .map((element) => {\n switch (element.$$type) {\n case 'style':\n return `<style id=\"${element.id}\" type=\"${element.type}\">${element.children}</style>`;\n case 'link':\n return `<link rel=\"${element.rel}\" href=\"${element.href}\" as=\"${element.as}\" crossorigin=\"${element.crossorigin}\" />`;\n default:\n return '';\n }\n })\n .filter(Boolean);\n },\n\n resetServerContext() {\n serverContext.clear();\n },\n\n getLoadedFonts(): string[] {\n if (typeof window === 'undefined') {\n return [...serverContext.values()].map(({ name }) => name);\n }\n const rules = getFontFaceRules();\n return rules.map(({ rule }) => rule.style.fontFamily);\n },\n\n isLoaded(fontFamilyName: string, resource: UnloadFontOptions = {}): boolean {\n if (typeof window === 'undefined') {\n return !![...serverContext.values()].find((asset) => {\n return asset.name === fontFamilyName;\n });\n }\n return getFontFaceRulesMatchingResource(fontFamilyName, resource)?.length > 0;\n },\n\n // NOTE(EvanBacon): No async keyword! This cannot return a promise in Node environments.\n loadAsync(fontFamilyName: string, resource: FontResource): Promise<void> {\n if (typeof window === 'undefined') {\n serverContext.add({\n name: fontFamilyName,\n css: _createWebFontTemplate(fontFamilyName, resource),\n // @ts-expect-error: typeof string\n resourceId: resource.uri!,\n });\n return Promise.resolve();\n }\n\n const canInjectStyle = document.head && typeof document.head.appendChild === 'function';\n if (!canInjectStyle) {\n throw new CodedError(\n 'ERR_WEB_ENVIRONMENT',\n `The browser's \\`document.head\\` element doesn't support injecting fonts.`\n );\n }\n\n const style = getStyleElement();\n document.head!.appendChild(style);\n\n const res = getFontFaceRulesMatchingResource(fontFamilyName, resource);\n if (!res.length) {\n _createWebStyle(fontFamilyName, resource);\n }\n\n if (!isFontLoadingListenerSupported()) {\n return Promise.resolve();\n }\n\n return new FontObserver(fontFamilyName, { display: resource.display }).load(null, 6000);\n },\n};\n\nconst ID = 'expo-generated-fonts';\n\nfunction getStyleElement(): HTMLStyleElement {\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n return element;\n }\n const styleElement = document.createElement('style');\n styleElement.id = ID;\n styleElement.type = 'text/css';\n return styleElement;\n}\n\nexport function _createWebFontTemplate(fontFamily: string, resource: FontResource): string {\n return `@font-face{font-family:${fontFamily};src:url(${resource.uri});font-display:${\n resource.display || FontDisplay.AUTO\n }}`;\n}\n\nfunction _createWebStyle(fontFamily: string, resource: FontResource): HTMLStyleElement {\n const fontStyle = _createWebFontTemplate(fontFamily, resource);\n\n const styleElement = getStyleElement();\n // @ts-ignore: TypeScript does not define HTMLStyleElement::styleSheet. This is just for IE and\n // possibly can be removed if it's unnecessary on IE 11.\n if (styleElement.styleSheet) {\n const styleElementIE = styleElement as any;\n styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText\n ? styleElementIE.styleSheet.cssText + fontStyle\n : fontStyle;\n } else {\n const textNode = document.createTextNode(fontStyle);\n styleElement.appendChild(textNode);\n }\n return styleElement;\n}\n\nfunction isFontLoadingListenerSupported(): boolean {\n const { userAgent } = window.navigator;\n // WebKit is broken https://github.com/bramstein/fontfaceobserver/issues/95\n const isIOS = !!userAgent.match(/iPad|iPhone/i);\n const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n // Edge is broken https://github.com/bramstein/fontfaceobserver/issues/109#issuecomment-333356795\n const isEdge = userAgent.includes('Edge');\n // Internet Explorer\n const isIE = userAgent.includes('Trident');\n // Firefox\n const isFirefox = userAgent.includes('Firefox');\n return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoFontLoader.web.js","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAgB,MAAM,cAAc,CAAC;AAEzD,SAAS,qBAAqB;IAC5B,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC;IACrC,OAAO,UAAU,CAAC,KAAK,C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CAAC,CAAC;IACrC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,8BAA8B;IACrC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;IACvC,2EAA2E;IAC3E,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,gCAAgC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5E,iGAAiG;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,oBAAoB;IACpB,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,UAAU;IACV,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChD,OAAO,CAAC,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;AAC/D,CAAC","sourcesContent":["import { CodedError, Platform } from 'expo-modules-core';\nimport FontObserver from 'fontfaceobserver';\n\nimport { UnloadFontOptions } from './Font';\nimport { FontDisplay, FontResource } from './Font.types';\n\nfunction getFontFaceStyleSheet(): CSSStyleSheet | null {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const styleSheet = getStyleElement();\n return styleSheet.sheet ? (styleSheet.sheet as CSSStyleSheet) : null;\n}\n\ntype RuleItem = { rule: CSSFontFaceRule; index: number };\n\nfunction getFontFaceRules(): RuleItem[] {\n const sheet = getFontFaceStyleSheet();\n if (sheet) {\n // @ts-ignore: rule iterator\n const rules = [...sheet.cssRules];\n\n const items: RuleItem[] = [];\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i];\n if (rule instanceof CSSFontFaceRule) {\n items.push({ rule, index: i });\n }\n }\n return items;\n }\n return [];\n}\n\nfunction getFontFaceRulesMatchingResource(\n fontFamilyName: string,\n options?: UnloadFontOptions\n): RuleItem[] {\n const rules = getFontFaceRules();\n return rules.filter(({ rule }) => {\n return (\n rule.style.fontFamily === fontFamilyName &&\n (options && options.display ? options.display === (rule.style as any).fontDisplay : true)\n );\n });\n}\n\nconst serverContext: Set<{ name: string; css: string; resourceId: string }> = new Set();\n\nfunction getHeadElements(): {\n $$type: string;\n rel?: string;\n href?: string;\n as?: string;\n crossorigin?: string;\n children?: string;\n id?: string;\n type?: string;\n}[] {\n const entries = [...serverContext.entries()];\n if (!entries.length) {\n return [];\n }\n const css = entries.map(([{ css }]) => css).join('\\n');\n const links = entries.map(([{ resourceId }]) => resourceId);\n // TODO: Maybe return nothing if no fonts were loaded.\n return [\n {\n $$type: 'style',\n children: css,\n id: ID,\n type: 'text/css',\n },\n ...links.map((resourceId) => ({\n $$type: 'link',\n rel: 'preload',\n href: resourceId,\n as: 'font',\n crossorigin: '',\n })),\n ];\n}\n\nexport default {\n async unloadAllAsync(): Promise<void> {\n if (!Platform.isDOMAvailable) return;\n\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n document.removeChild(element);\n }\n },\n\n async unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void> {\n const sheet = getFontFaceStyleSheet();\n if (!sheet) return;\n const items = getFontFaceRulesMatchingResource(fontFamilyName, options);\n for (const item of items) {\n sheet.deleteRule(item.index);\n }\n },\n\n getServerResources(): string[] {\n const elements = getHeadElements();\n\n return elements\n .map((element) => {\n switch (element.$$type) {\n case 'style':\n return `<style id=\"${element.id}\" type=\"${element.type}\">${element.children}</style>`;\n case 'link':\n return `<link rel=\"${element.rel}\" href=\"${element.href}\" as=\"${element.as}\" crossorigin=\"${element.crossorigin}\" />`;\n default:\n return '';\n }\n })\n .filter(Boolean);\n },\n\n resetServerContext() {\n serverContext.clear();\n },\n\n getLoadedFonts(): string[] {\n if (typeof window === 'undefined') {\n return [...serverContext.values()].map(({ name }) => name);\n }\n const rules = getFontFaceRules();\n return rules.map(({ rule }) => rule.style.fontFamily);\n },\n\n isLoaded(fontFamilyName: string, resource: UnloadFontOptions = {}): boolean {\n if (typeof window === 'undefined') {\n return !![...serverContext.values()].find((asset) => {\n return asset.name === fontFamilyName;\n });\n }\n return getFontFaceRulesMatchingResource(fontFamilyName, resource)?.length > 0;\n },\n\n // NOTE(EvanBacon): No async keyword! This cannot return a promise in Node environments.\n loadAsync(fontFamilyName: string, resource: FontResource): Promise<void> {\n if (typeof window === 'undefined') {\n serverContext.add({\n name: fontFamilyName,\n css: _createWebFontTemplate(fontFamilyName, resource),\n // @ts-expect-error: typeof string\n resourceId: resource.uri!,\n });\n return Promise.resolve();\n }\n\n const canInjectStyle = document.head && typeof document.head.appendChild === 'function';\n if (!canInjectStyle) {\n throw new CodedError(\n 'ERR_WEB_ENVIRONMENT',\n `The browser's \\`document.head\\` element doesn't support injecting fonts.`\n );\n }\n\n const style = getStyleElement();\n document.head!.appendChild(style);\n\n const res = getFontFaceRulesMatchingResource(fontFamilyName, resource);\n if (!res.length) {\n _createWebStyle(fontFamilyName, resource);\n }\n\n if (!isFontLoadingListenerSupported()) {\n return Promise.resolve();\n }\n\n return new FontObserver(fontFamilyName, {\n // @ts-expect-error: TODO(@kitten): Typings indicate that the polyfill may not support this?\n display: resource.display,\n }).load(null, 6000);\n },\n};\n\nconst ID = 'expo-generated-fonts';\n\nfunction getStyleElement(): HTMLStyleElement {\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n return element;\n }\n const styleElement = document.createElement('style');\n styleElement.id = ID;\n styleElement.type = 'text/css';\n return styleElement;\n}\n\nexport function _createWebFontTemplate(fontFamily: string, resource: FontResource): string {\n return `@font-face{font-family:${fontFamily};src:url(${resource.uri});font-display:${\n resource.display || FontDisplay.AUTO\n }}`;\n}\n\nfunction _createWebStyle(fontFamily: string, resource: FontResource): HTMLStyleElement {\n const fontStyle = _createWebFontTemplate(fontFamily, resource);\n\n const styleElement = getStyleElement();\n // @ts-ignore: TypeScript does not define HTMLStyleElement::styleSheet. This is just for IE and\n // possibly can be removed if it's unnecessary on IE 11.\n if (styleElement.styleSheet) {\n const styleElementIE = styleElement as any;\n styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText\n ? styleElementIE.styleSheet.cssText + fontStyle\n : fontStyle;\n } else {\n const textNode = document.createTextNode(fontStyle);\n styleElement.appendChild(textNode);\n }\n return styleElement;\n}\n\nfunction isFontLoadingListenerSupported(): boolean {\n const { userAgent } = window.navigator;\n // WebKit is broken https://github.com/bramstein/fontfaceobserver/issues/95\n const isIOS = !!userAgent.match(/iPad|iPhone/i);\n const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n // Edge is broken https://github.com/bramstein/fontfaceobserver/issues/109#issuecomment-333356795\n const isEdge = userAgent.includes('Edge');\n // Internet Explorer\n const isIE = userAgent.includes('Trident');\n // Firefox\n const isFirefox = userAgent.includes('Firefox');\n return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoFontUtils.d.ts","sourceRoot":"","sources":["../src/ExpoFontUtils.ts"],"names":[],"mappings":";AAEA,wBAAoD"}
|
|
@@ -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 @@
|
|
|
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
package/build/index.d.ts.map
CHANGED
|
@@ -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
package/build/index.js.map
CHANGED
|
@@ -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"]}
|
package/expo-module.config.json
CHANGED
|
@@ -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.
|
|
11
|
+
"version": "13.2.0",
|
|
12
12
|
"repository": "local-maven-repo"
|
|
13
13
|
}
|
|
14
14
|
}
|
package/ios/FontExceptions.swift
CHANGED
|
@@ -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
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
85fa250981be0d9c2cfe380914137d32
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
58f3bf67ec556651368352816436127f20c27a0c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c029366141433ab312f41026590eb119ef648137f3b6cebeb416531fc0b4cccc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
04d8003327d266d74c7c2123206ff0c008db185c4fe9ce8518e6c47af1ed8d3118db35e094ceb19451c622318ac15e9fa9eaea609d7fae69cedec95e1656c20a
|
package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar
ADDED
|
Binary file
|
package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.aar.md5
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c4a5fbec91ef91f550b4a16b8011c1da
|
|
@@ -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.
|
|
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.
|
|
28
|
-
"url": "expo.modules.font-13.
|
|
29
|
-
"size":
|
|
30
|
-
"sha512": "
|
|
31
|
-
"sha256": "
|
|
32
|
-
"sha1": "
|
|
33
|
-
"md5": "
|
|
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.
|
|
61
|
-
"url": "expo.modules.font-13.
|
|
62
|
-
"size":
|
|
63
|
-
"sha512": "
|
|
64
|
-
"sha256": "
|
|
65
|
-
"sha1": "
|
|
66
|
-
"md5": "
|
|
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.
|
|
81
|
-
"url": "expo.modules.font-13.
|
|
82
|
-
"size":
|
|
83
|
-
"sha512": "
|
|
84
|
-
"sha256": "
|
|
85
|
-
"sha1": "
|
|
86
|
-
"md5": "
|
|
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
|
+
3ed9c4b78f534a9c991aaff9f6cc6d87
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
62b47993ad2d49f4a1d27724477bf94f3eba5617
|
|
@@ -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.
|
|
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>
|
package/local-maven-repo/host/exp/exponent/expo.modules.font/13.2.0/expo.modules.font-13.2.0.pom.md5
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c85f3479e15480f11e951ed36637eb06
|
|
@@ -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.
|
|
7
|
-
<release>13.
|
|
6
|
+
<latest>13.2.0</latest>
|
|
7
|
+
<release>13.2.0</release>
|
|
8
8
|
<versions>
|
|
9
|
-
<version>13.
|
|
9
|
+
<version>13.2.0</version>
|
|
10
10
|
</versions>
|
|
11
|
-
<lastUpdated>
|
|
11
|
+
<lastUpdated>20250421213308</lastUpdated>
|
|
12
12
|
</versioning>
|
|
13
13
|
</metadata>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
03e013cfd9238f8e9bd83c76751baa30
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
71d5799b8f1517ce9c837dd1105a3c1bf4b12842
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
9be03f2203a7220638e78d74824e54553443db59a5f71a8f0c5a1c60f6ab59b0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
9a1c6d59d8c1637d2c8e9c069de5549f9fdc760b8a8d0e8462692e71ed57117c9aede5de1cffd52489da29e3af1b6509472e5bf344b26e10d43e7ca50608604b
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-font",
|
|
3
|
-
"version": "13.
|
|
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",
|
|
@@ -49,11 +49,12 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/react-native": "^13.1.0",
|
|
52
|
-
"
|
|
52
|
+
"@types/fontfaceobserver": "^2.1.3",
|
|
53
|
+
"expo-module-scripts": "^4.1.2"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"expo": "*",
|
|
56
57
|
"react": "*"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f1394f21ff2719a9a3037d7511db170704e5c492"
|
|
59
60
|
}
|
|
@@ -171,7 +171,10 @@ export default {
|
|
|
171
171
|
return Promise.resolve();
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
return new FontObserver(fontFamilyName, {
|
|
174
|
+
return new FontObserver(fontFamilyName, {
|
|
175
|
+
// @ts-expect-error: TODO(@kitten): Typings indicate that the polyfill may not support this?
|
|
176
|
+
display: resource.display,
|
|
177
|
+
}).load(null, 6000);
|
|
175
178
|
},
|
|
176
179
|
};
|
|
177
180
|
|
|
@@ -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');
|
package/src/FontUtils.ts
ADDED
|
@@ -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference path="../../../expo-asset/src/ts-declarations/react-native-assets.d.ts" />
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
584be3c85f2cea79a438cb3029de44b1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
82b8aba4d9525e564f2cbc4299b3623fe5304232
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
857820932e52dbe80e0f58011d164e892ed37213dd74c3dc30fe70739d0f94fa
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
922d17ab9404230df7a55676e7c308ad010b49278562a12051eb7f8f518683f2020eabb96ae0ee79b908dd49572830eea6d9cf7c579ef5db7be04ef2c864a093
|
package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar
DELETED
|
Binary file
|
package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.aar.md5
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
28ac3500cafc491337446819fbff1ed9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ac0cf41e2f0905c4d87505fa1bfa5c4bb9ebb0a9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
df73df860315a2f01896ec47d5ed6740b9b3f7339d47d0418360859f05fe1088
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
6b0d739ff6720adf9bcefcfde410dd8b4c1cd8783abf788d42b429a51caed98dcce305b30ab4ec82dabc0379b46f344ca0581ed1b281b09e1c568319e2563bc5
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
d2c56d884805bb0877d6644e0683ffb1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
c19a3a9d984ac22cdb1d0a4ae536ce1b648ea9c5
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
46723b5fb554fad114adeec00e3b5bc2cc896d1b016294f74c49fd6ff0be2e7d
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a93a222d6299ccda24ffa9075021cfc5a912c07764e1af8dc5070a65dfb90fe919d60d0fe7d7ff03feb85fe5e4d87dcfe1d28c6a0ceeef088cfbd36a93354ba5
|
package/local-maven-repo/host/exp/exponent/expo.modules.font/13.1.1/expo.modules.font-13.1.1.pom.md5
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
af804e697156e05a82680291d5dd3e90
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dfb73d9881eb258749f74826e800594c6040e29a
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
61ae2886c0122423a516cf8d8fda69ce601776f0761dee4e15efddc436dfde85
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ccc71a66e8c82cfd297c79af7d611e978dc1de1f7176cdc4afa1b6667d613ff7ab6a07fc0605063084b17a68edc3d57ecce11d63fa166725333473355b53ab86
|