Amin Elhag
10/16/2025, 5:28 AMMoe
10/16/2025, 7:02 AMAmin Elhag
10/16/2025, 7:28 AMfun injectArabicFontSupport() {
// Preconnect for performance
val preconnect = document.createElement("link").apply {
setAttribute("rel", "preconnect")
setAttribute("href", "<https://fonts.googleapis.com>")
}
val preconnectStatic = document.createElement("link").apply {
setAttribute("rel", "preconnect")
setAttribute("href", "<https://fonts.gstatic.com>")
setAttribute("crossorigin", "")
}
// Load font stylesheet
val fontLink = document.createElement("link").apply {
setAttribute("rel", "stylesheet")
setAttribute("href",
"<https://fonts.googleapis.com/css2>?" +
"family=Noto+Sans+Arabic:wght@400;500;600;700&" +
"family=Roboto:wght@400;500;700&" +
"display=swap"
)
}
document.head?.apply {
appendChild(preconnect)
appendChild(preconnectStatic)
appendChild(fontLink)
}
// CRITICAL: Force browser text rendering with proper shaping
val style = document.createElement("style").apply {
textContent = """
/* Global font family */
* {
font-family: 'Noto Sans Arabic', 'Roboto', -apple-system,
BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
}
/* CRITICAL: Force proper text rendering and shaping */
body, div, span, p, h1, h2, h3, h4, h5, h6,
input, button, textarea, select, label, option {
/* Enable text shaping */
text-rendering: optimizeLegibility !important;
-webkit-font-feature-settings: 'liga', 'kern' !important;
font-feature-settings: 'liga', 'kern' !important;
/* Force subpixel antialiasing */
-webkit-font-smoothing: subpixel-antialiased !important;
-moz-osx-font-smoothing: auto !important;
/* Ensure proper Unicode bidirectional text */
unicode-bidi: embed !important;
}
/* Force Skia canvas to use proper text rendering */
canvas {
text-rendering: optimizeLegibility !important;
}
/* RTL support for Arabic */
[dir="rtl"], [dir="rtl"] * {
direction: rtl !important;
text-align: right !important;
unicode-bidi: embed !important;
}
/* Specific targeting for Compose canvas elements */
[style*="position: absolute"] {
text-rendering: optimizeLegibility !important;
}
""".trimIndent()
}
document.head?.appendChild(style)
// Add a script to monitor and fix any dynamically created elements
val script = document.createElement("script").apply {
textContent = """
(function() {
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) {
node.style.textRendering = 'optimizeLegibility';
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})();
""".trimIndent()
}
document.head?.appendChild(script)
console.log("ā
Arabic font support injected with text shaping")
}Artem Kobzar
10/16/2025, 10:41 AMAmin Elhag
10/16/2025, 2:42 PMArtem Kobzar
10/16/2025, 2:45 PMOleksandr Karpovich [JB]
10/16/2025, 2:47 PM