-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add Custom Emojis with Unicode Private User Area with a new font #59301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
16be069
24b31a4
9d64927
46fc170
209a1c3
a8abe7a
f80ca12
6784b82
80dc51b
e3f4a27
0aa1640
4b80502
cb0be92
ca49619
e542e3b
0f6ae66
104eab2
ce37b14
4d23b90
9c7cca1
605096e
df03015
d91c534
46507c4
b4f41ec
0aedfa4
9dd2d81
966fff8
6bcc151
8175385
e39dbab
ba38136
18ee1f8
e3e1db2
9c18694
ce472ff
02d4280
f7c73c7
7797419
2f8b8b6
991ab92
11bc7db
13c8f22
d8d82b9
5db9422
1ed61be
aa4273e
b41203f
41d0588
961e93e
f76a4ce
2b28f82
4243911
ff1ccc9
a3e7590
3dacab7
6a9d9c8
2fff160
a7567e3
c58a766
61646d2
5d4f562
db9da50
8788c9e
00382d2
55f7488
ce87f43
5e142be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <font-family xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
| <font app:fontStyle="normal" app:fontWeight="400" app:font="@font/custom_emoji_native_font"/> | ||
| </font-family> |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file was not configured properly, which caused #84449 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |
| ED222ED90E074A5481A854FA /* ExpensifyNeue-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */; }; | ||
| F0C450EA2705020500FD2970 /* colors.json in Resources */ = {isa = PBXBuildFile; fileRef = F0C450E92705020500FD2970 /* colors.json */; }; | ||
| FF941A8D48F849269AB85C9A /* ExpensifyNewKansas-Medium.otf in Resources */ = {isa = PBXBuildFile; fileRef = 44BF435285B94E5B95F90994 /* ExpensifyNewKansas-Medium.otf */; }; | ||
| 59164B2F48344A53975791A9 /* CustomEmojiNativeFont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B42BBCC5FB8E4E40B1A9202C /* CustomEmojiNativeFont.ttf */; }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why .ttf for this font and not .otf like the others?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could not make an otf with nanoemoji.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm did you confirm that .ttf works on native devices?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| /* End PBXBuildFile section */ | ||
|
|
||
| /* Begin PBXContainerItemProxy section */ | ||
|
|
@@ -158,6 +159,7 @@ | |
| F0C450E92705020500FD2970 /* colors.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = colors.json; path = ../colors.json; sourceTree = "<group>"; }; | ||
| F4F8A052A22040339996324B /* ExpensifyNeue-Regular.otf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "ExpensifyNeue-Regular.otf"; path = "../assets/fonts/native/ExpensifyNeue-Regular.otf"; sourceTree = "<group>"; }; | ||
| F8839E9820F4C312BD1C9339 /* Pods-NewExpensify.releasedevelopment.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NewExpensify.releasedevelopment.xcconfig"; path = "Target Support Files/Pods-NewExpensify/Pods-NewExpensify.releasedevelopment.xcconfig"; sourceTree = "<group>"; }; | ||
| B42BBCC5FB8E4E40B1A9202C /* CustomEmojiNativeFont.ttf */ = {isa = PBXFileReference; name = "CustomEmojiNativeFont.ttf"; path = "../assets/fonts/native/CustomEmojiNativeFont.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; }; | ||
| /* End PBXFileReference section */ | ||
|
|
||
| /* Begin PBXFrameworksBuildPhase section */ | ||
|
|
@@ -319,6 +321,7 @@ | |
| 8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */, | ||
| BF6A4C5167244B9FB8E4D4E3 /* ExpensifyNeue-Italic.otf */, | ||
| F4F8A052A22040339996324B /* ExpensifyNeue-Regular.otf */, | ||
| B42BBCC5FB8E4E40B1A9202C /* CustomEmojiNativeFont.ttf */, | ||
| ); | ||
| name = Resources; | ||
| sourceTree = "<group>"; | ||
|
|
@@ -491,6 +494,7 @@ | |
| D27CE6B77196EF3EF450EEAC /* PrivacyInfo.xcprivacy in Resources */, | ||
| 524F95D57E75496EBD14B0AA /* ExpensifyMono-BoldItalic.otf in Resources */, | ||
| 0F749C2B3B8F4562B816DEAB /* BuildFile in Resources */, | ||
| 59164B2F48344A53975791A9 /* CustomEmojiNativeFont.ttf in Resources */, | ||
| ); | ||
| runOnlyForDeploymentPostprocessing = 0; | ||
| }; | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,22 @@ function sanitizeString(str: string): string { | |
| * Check if the string would be empty if all invisible characters were removed. | ||
| */ | ||
| function isEmptyString(value: string): boolean { | ||
| // We implemented a custom emoji on this Unicode Private Use Area (PUA) code point | ||
| // so we should not remove it. | ||
| // Temporarily replace \uE100 with a placeholder | ||
| const PLACEHOLDER = '<<KEEP_E100>>'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is defined twice (here and in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a placeholder and can be anything. I think this is fine here within the function scope. |
||
| let transformed = value.replace(/\uE100/g, PLACEHOLDER); | ||
|
|
||
| // \p{C} matches all 'Other' characters | ||
| // \p{Z} matches all separators (spaces etc.) | ||
| // Source: http://www.unicode.org/reports/tr18/#General_Category_Property | ||
| let transformed = value.replace(CONST.REGEX.INVISIBLE_CHARACTERS_GROUPS, ''); | ||
| transformed = transformed.replace(CONST.REGEX.INVISIBLE_CHARACTERS_GROUPS, ''); | ||
|
|
||
| // Remove other invisible characters that are not in the above unicode categories | ||
| transformed = transformed.replace(CONST.REGEX.OTHER_INVISIBLE_CHARACTERS, ''); | ||
|
|
||
| transformed = transformed.replace(new RegExp(PLACEHOLDER, 'g'), '\uE100'); | ||
|
|
||
| // Check if after removing invisible characters the string is empty | ||
| return transformed === ''; | ||
| } | ||
|
|
@@ -36,6 +44,12 @@ function isEmptyString(value: string): boolean { | |
| function removeInvisibleCharacters(value: string): string { | ||
| let result = value; | ||
|
|
||
| // We implemented a custom emoji on this Unicode Private Use Area (PUA) code point | ||
| // so we should not remove it. | ||
| // Temporarily replace \uE100 with a placeholder | ||
| const PLACEHOLDER = '<<KEEP_E100>>'; | ||
| result = result.replace(/\uE100/g, PLACEHOLDER); | ||
|
|
||
| // Remove spaces: | ||
| // - \u200B: zero-width space | ||
| // - \u2060: word joiner | ||
|
|
@@ -60,6 +74,9 @@ function removeInvisibleCharacters(value: string): string { | |
| // Remove all characters from the 'Separator' (Z) category except for Space Separator (Zs) | ||
| result = result.replace(/[\p{Zl}\p{Zp}]/gu, ''); | ||
|
|
||
| // Restore \uE100 from placeholder | ||
| result = result.replace(new RegExp(PLACEHOLDER, 'g'), '\uE100'); | ||
|
|
||
| // If the result consist of only invisible characters, return an empty string | ||
| if (isEmptyString(result)) { | ||
| return ''; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a .ttf here when all of our other fonts use woff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another font seguiemj.ttf there and AFAIK I have not found any issue with woff/otf/ttf. Nanoemoji gives ttf as default and I found converting it to other fonts unreliable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I have a feeling that Segui is an artifact - is it even being used? I think at one point a contributor added custom emoji files and we reverted those changes because we wanted to rely on system emoji fonts for everything. So I bet we aren't even using that. Either way, can you please try to generate .woff and see what happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but it did not work for Safari.