Skip to content

Commit

Permalink
feat(fonts): add support for thai text
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsaldan committed Dec 19, 2024
1 parent 3af3854 commit c508249
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/constants/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ export const notoSansTA = localFont({
unicode: ["\u0B80-\u0BFF"],
});

export const notoSansTH = localFont({
src: "../fonts/NotoSansTH-VF.woff2",
variable: "--font-noto-sans-th",
preload: false,
display: "swap",
fallback: ["system-ui", "sans-serif"],
unicode: ["\u0E00-\u0E7F"],
});

export function detectTextScript(text) {
if (!text) return "latin";

Expand All @@ -134,6 +143,7 @@ export function detectTextScript(text) {
bengali: /[\u0980-\u09FF]/,
traditionalChinese: /[\u4E00-\u9FFF]/,
tamil: /[\u0B80-\u0BFF]/,
thai: /[\u0E00-\u0E7F]/,
};

for (const [script, regex] of Object.entries(scripts)) {
Expand Down Expand Up @@ -176,6 +186,7 @@ export const fontFamilyForScript = {
hebrew: `var(--font-noto-sans-he), var(--font-inter)`,
bengali: `var(--font-noto-sans-bn), var(--font-inter)`,
tamil: `var(--font-noto-sans-ta), var(--font-inter)`,
thai: `var(--font-noto-sans-th), var(--font-inter)`,
};

export function useDynamicFont(text) {
Expand Down
Binary file added src/fonts/NotoSansTH-VF.woff2
Binary file not shown.
3 changes: 2 additions & 1 deletion src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
notoSansHE,
notoSansBN,
notoSansTA,
notoSansTH,
} from "../constants/fonts";

const initialAuthState = () => {
Expand Down Expand Up @@ -117,7 +118,7 @@ export default function App({ Component, pageProps }) {
const [networkStatus, setNetworkStatus] = useState({ isConnected: false });
const inactivityTimeoutRef = useRef(null);
const lastActivityTimeRef = useRef(Date.now());
const mainFontClasses = `${inter.variable} ${notoSansSC.variable} ${notoSansTC.variable} ${notoSerifJP.variable} ${notoSansKR.variable} ${notoNaskhAR.variable} ${notoSansDV.variable} ${notoSansHE.variable} ${notoSansBN.variable} ${notoSansTA.variable}`;
const mainFontClasses = `${inter.variable} ${notoSansSC.variable} ${notoSansTC.variable} ${notoSerifJP.variable} ${notoSansKR.variable} ${notoNaskhAR.variable} ${notoSansDV.variable} ${notoSansHE.variable} ${notoSansBN.variable} ${notoSansTA.variable} ${notoSansTH.variable}`;

useEffect(() => {
const checkInitialConnectivity = async () => {
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
"var(--font-noto-sans-he)",
"var(--font-noto-sans-bn)",
"var(--font-noto-sans-ta)",
"var(--font-noto-sans-th)",
],
},
letterSpacing: {
Expand Down

0 comments on commit c508249

Please sign in to comment.