Skip to content

Commit fa06b6c

Browse files
feat: arabic font support
1 parent 59c8eb7 commit fa06b6c

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed
Binary file not shown.
Binary file not shown.

scripts/import-fonts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writeFile, readdir, unlink } from "node:fs/promises";
33

44
const fonts = [
55
{ family: "Noto Sans JP", weights: "400;700" },
6+
{ family: "Noto Sans Arabic", weights: "400;700" },
67
{ family: "Permanent Marker", weights: "400" },
78
{ family: "Shippori Antique B1", weights: "400" },
89
];

src/components/docs/card/CardDisplayFront.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ICON_RATIOS } from "@/docs/card/icon-ratios";
99
import { ICON_WHITE_BG } from "@/docs/card/icon-white-bg";
1010
import type { AllIconTypes, CardV1Type } from "@/docs/card";
1111
import type { DocPageView } from "@/components/safeDoc-react/DocView";
12+
import { NotoSansArabic } from "@/components/fonts/NotoSansArabic";
13+
import { TextWithFont } from "@/components/fonts/TextWithFont";
1214

1315
type BigProps = {
1416
kana?: string;
@@ -39,17 +41,17 @@ const Big = ({ kana, text, className, ref }: BigProps) => {
3941
<g ref={ref} className={clsx("big", className)}>
4042
{zoom}
4143
{text && kana ? (
42-
<text ref={refs.kana} className={clsx("big--kana", className)}>
44+
<TextWithFont ref={refs.kana} className={clsx("big--kana", className)}>
4345
{kana}
44-
</text>
46+
</TextWithFont>
4547
) : null}
46-
<text
48+
<TextWithFont
4749
ref={refs.regular}
4850
className={clsx("big--regular", className)}
4951
fontSize="40px"
5052
>
5153
{text}
52-
</text>
54+
</TextWithFont>
5355
</g>
5456
);
5557
};
@@ -208,11 +210,17 @@ export const CardDisplayFront: DocPageView<CardV1Type> = ({
208210
<BusinessCardSvg ref={ref} isCut={!showMargins} background="white">
209211
<style>{`
210212
${NotoSansJP.css}
213+
${NotoSansArabic.css}
211214
/* Style the text */
212215
text {
213216
font-family: "${NotoSansJP.name}", sans-serif;
214217
color: #111111;
215218
}
219+
.arabic {
220+
font-family: "${NotoSansArabic.name}", sans-serif;
221+
baseline-shift: .45em;
222+
line-height: 1.1em;
223+
}
216224
.big--regular {
217225
font-size: 50px;
218226
font-weight: normal;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Font } from "./font";
2+
/**
3+
* Generated from url=https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;700
4+
*
5+
* Generated using -> npm run import:fonts
6+
*/
7+
export const NotoSansArabic = {
8+
name: "Noto Sans Arabic",
9+
css: `
10+
@font-face {
11+
font-family: 'Noto Sans Arabic';
12+
font-style: normal;
13+
font-weight: 400;
14+
font-stretch: normal;
15+
src: url(/fonts/146b2193f4aee343a8da5e2295255b04db547d74339a12be51763b3a0081868d.ttf) format('truetype');
16+
}
17+
@font-face {
18+
font-family: 'Noto Sans Arabic';
19+
font-style: normal;
20+
font-weight: 700;
21+
font-stretch: normal;
22+
src: url(/fonts/195e8d8e1e723630e46c1d19fe7ec118a73e5825baa198737d6a96df8c4063b1.ttf) format('truetype');
23+
}
24+
`,
25+
} satisfies Font;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { clsx } from "clsx";
2+
import type { SVGTextElementAttributes } from "react";
3+
4+
export type TextWithFontProps = Omit<
5+
SVGTextElementAttributes<SVGTextElement>,
6+
"children"
7+
> & {
8+
children: string | undefined;
9+
};
10+
export function TextWithFont({
11+
children: text,
12+
className,
13+
...rest
14+
}: TextWithFontProps) {
15+
return (
16+
<text
17+
className={clsx(className, {
18+
arabic: text ? /[\u0600-\u06FF\u0750-\u077F]/.test(text) : false,
19+
})}
20+
{...rest}
21+
>
22+
{text}
23+
</text>
24+
);
25+
}

0 commit comments

Comments
 (0)