When someone writes their name as 𝐀𝐬𝐚𝐝 or 𝒜𝓈𝒶𝒹 in a bio, it looks like a font. It isn't. Instagram, WhatsApp and TikTok only let you send plain text, so the "font" is really a different set of characters that happen to look like styled letters.
I built Wryte, a fancy-text app for Android, around that idea. Here's how the styles actually work, the gaps in Unicode that trip up a naive converter, and how Wryte restyles text inside any other app through Android's text-selection menu.
The trick: Mathematical Alphanumeric Symbols
Unicode has a block called Mathematical Alphanumeric Symbols, starting at U+1D400. It exists so mathematicians can write a bold 𝐀 that means something different from a plain A. For us, it's a full set of bold, italic, script, gothic (fraktur), double-struck, sans-serif and monospace alphabets.
Within each style, A–Z and a–z are laid out in order. So a style is just an offset:
/** Maps A–Z, a–z and optionally 0–9 onto a contiguous block, with per-letter exceptions. */
private fun math(text: String, upper: Int, lower: Int, digits: Int?, holes: Map<Char, Char> = emptyMap()): String {
val sb = StringBuilder()
for (c in text) {
val hole = holes[c]
when {
hole != null -> sb.append(hole)
c in 'A'..'Z' -> sb.appendCodePoint(upper + (c - 'A'))
c in 'a'..'z' -> sb.appendCodePoint(lower + (c - 'a'))
c in '0'..'9' && digits != null -> sb.appendCodePoint(digits + (c - '0'))
else -> sb.append(c)
}
}
return sb.toString()
}
add("bold", "Bold", FontGroup.CLASSIC, true) { math(it, 0x1D400, 0x1D41A, 0x1D7CE) }
Note appendCodePoint, not append(Char). These characters are outside the Basic Multilingual Plane, so each one is two UTF-16 chars (a surrogate pair). That has a visible side effect: code that counts String.length sees your bold name as twice as long as it is, so a character limit can fill up faster with styled text.
The holes
Apply that offset blindly to the italic alphabet and the word "the" comes out with an empty box where the h should be. Some letters in the math block are reserved and empty. The reason is history: a few of these letters were already in Unicode, in the older Letterlike Symbols block, before the math block existed. Italic h was already there as ℎ (U+210E, the Planck constant), so its slot in the new block was left empty rather than encoded twice.
Every style has its own set of holes, so every style carries its own exceptions:
private val ITALIC = mapOf('h' to 'ℎ')
private val SCRIPT = mapOf(
'B' to 'ℬ', 'E' to 'ℰ', 'F' to 'ℱ', 'H' to 'ℋ', 'I' to 'ℐ', 'L' to 'ℒ', 'M' to 'ℳ',
'R' to 'ℛ', 'e' to 'ℯ', 'g' to 'ℊ', 'o' to 'ℴ',
)
private val FRAKTUR = mapOf('C' to 'ℭ', 'H' to 'ℌ', 'I' to 'ℑ', 'R' to 'ℜ', 'Z' to 'ℨ')
private val DOUBLE = mapOf('C' to 'ℂ', 'H' to 'ℍ', 'N' to 'ℕ', 'P' to 'ℙ', 'Q' to 'ℚ', 'R' to 'ℝ', 'Z' to 'ℤ')
If you ever write one of these converters, test every letter of every style, not just "Hello". The holes are exactly the letters a quick test skips.
Not every style comes from the math block. Circled letters (Ⓐ) sit at U+24B6, small caps and similar styles are hand-built tables of lookalike characters, and frames and decorations wrap the result rather than changing it. In total Wryte has 154 fonts and 52 frames.
Styling text inside any app
Copying from one app and pasting into another gets old quickly. Android has a better hook: ACTION_PROCESS_TEXT. Any activity that declares it appears in the menu that pops up over selected text, in every app that uses the standard text views.
<activity android:name=".ProcessTextActivity" android:exported="true" android:theme="@style/Theme.Wryte.Sheet">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
The activity receives the selection in EXTRA_PROCESS_TEXT, and a flag that matters: EXTRA_PROCESS_TEXT_READONLY. If the text is in an editable field, you return the new text as the result and Android puts it in place of the selection. If it's read-only (a message someone sent you, say), there's nowhere to put it back, so Wryte copies it instead.
private fun deliver(text: String, readOnly: Boolean) {
if (readOnly) {
copyToClipboard(this, text)
} else {
setResult(RESULT_OK, Intent().putExtra(Intent.EXTRA_PROCESS_TEXT, text))
}
finish()
}
The styles open in a bottom sheet over the other app, so it feels like part of the menu rather than a jump into a different app.
A caution I'd give anyone using these
Styled text looks great, but these are mathematical symbols, not letters. Screen readers may read them out symbol by symbol or skip them, and search won't match them against the plain word. It's fine for a name or a bio line; I wouldn't write a whole post in it.
Wryte is on Google Play. It has no ads and needs no account, everything is generated on the phone and works offline, and 20 fonts are free. If you know a Unicode block I should mine next, tell me.
Top comments (0)