Skip to content

Commit 6e99152

Browse files
committed
refactor(#194): added web-safe Tahoma font
1 parent 0ca87ed commit 6e99152

File tree

13 files changed

+45
-16
lines changed

13 files changed

+45
-16
lines changed

lib/@dsvgui/components/article/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const Article: React.FC<IArticle> = ({ articles }) => {
8686
<Text
8787
x={0}
8888
y={20 + title.length + index * 13}
89-
option={{ size: 12, weight: 400 }}
89+
option={{ size: 12, weight: 500 }}
9090
>
9191
{line}
9292
</Text>

lib/@dsvgui/components/calendar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const Calendar: React.FC<ICalendar> = ({
149149
key={monthString}
150150
x={x > 0 ? x : 0}
151151
y={166}
152-
option={{ size: 12, weight: 400 }}
152+
option={{ size: 12, weight: 500 }}
153153
>
154154
{monthString}
155155
</Text>

lib/@dsvgui/components/fallback/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const Fallback: React.FC<IFallback> = ({ title, message }) => {
1313

1414
const subtitle = wrapText(
1515
message,
16-
{ maxLineWidth: width - 60, fontSize: 14, fontWeight: 400 },
16+
{ maxLineWidth: width - 60, fontSize: 14, fontWeight: 500 },
1717
(line, index) => (
18-
<Text x={67} y={index * 16 + 40} option={{ size: 14, weight: 400 }}>
18+
<Text x={67} y={index * 16 + 40} option={{ size: 14, weight: 500 }}>
1919
{line}
2020
</Text>
2121
)

lib/@dsvgui/components/flock/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const Flock: React.FC<IFlock> = ({
4040
const subtitleWidth = subtitle
4141
? getTextWidth(subtitle.trim(), {
4242
fontSize: subtitleFontSize,
43-
fontWeight: 400,
43+
fontWeight: 500,
4444
})
4545
: 0;
4646

lib/@dsvgui/components/line/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const Line: React.FC<ILine> = ({ items }) => {
128128
key={index}
129129
x={(textWidth) => i * xGap - textWidth / 2}
130130
y={0}
131-
option={{ size: 8, weight: 300 }}
131+
option={{ size: 8, weight: 500 }}
132132
>
133133
{periodLabel}
134134
</Text>

lib/@dsvgui/components/metrics/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const Metrics: React.FC<IMetrics> = ({ data, icon: Icon }) => {
4242
});
4343
const wValue = getTextWidth(item.value.toString(), {
4444
fontSize: 22,
45-
fontWeight: 800,
45+
fontWeight: 700,
4646
});
4747
const wText = Math.max(wValue, wTitle);
4848

@@ -55,7 +55,7 @@ export const Metrics: React.FC<IMetrics> = ({ data, icon: Icon }) => {
5555
<Text x={xText} y={10} option="subtitle">
5656
{item.title}
5757
</Text>
58-
<Text x={xText} y={33.51} option={{ size: 22, weight: 800 }}>
58+
<Text x={xText} y={33.51} option={{ size: 22, weight: 700 }}>
5959
{item.value.toString()}
6060
</Text>
6161
{index !== 0 && (

lib/@dsvgui/document/branding.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type IBranding = {
77

88
export const Branding: React.FC<IBranding> = ({ x, y }) => {
99
return (
10-
<Text x={x} y={y} option={{ size: 8, weight: 400 }}>
10+
<Text x={x} y={y} option={{ size: 8, weight: 500 }}>
1111
readme.rocks
1212
</Text>
1313
);

lib/@dsvgui/document/fonts/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import * as Manrope from "./manrope";
44
import * as OpenSans from "./opensans";
5+
import * as Tahoma from "./tahoma";
56

6-
const fonts = { Manrope, OpenSans };
7+
const fonts = { Manrope, OpenSans, Tahoma };
78

89
export type FontFamily = keyof typeof fonts;
9-
export const defaultFont: FontFamily = "Manrope";
10+
export const defaultFont: FontFamily = "Tahoma";
1011

1112
export default fonts;
Binary file not shown.
Binary file not shown.

lib/@dsvgui/document/fonts/tahoma/index.ts

+4
Large diffs are not rendered by default.

lib/@dsvgui/document/style.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const Style: React.FC = () => {
22
return (
33
<defs>
44
<style>{`
5+
.websafe{ font-family: Tahoma, Verdana, sans-serif }
56
.text{ fill: #32373e;}
67
.text.subtitle{ fill: #5c5c5c; }
78

lib/@dsvgui/document/text.tsx

+28-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type IText = {
1313
y: number;
1414
option: IFontType | IFontOptions;
1515
children: string | number | undefined;
16+
as?: "path" | "text";
1617
};
1718

1819
const onHandFonts = {
@@ -26,7 +27,13 @@ const onHandFonts = {
2627
},
2728
};
2829

29-
export const Text: React.FC<IText> = ({ x, y, option, children }) => {
30+
export const Text: React.FC<IText> = ({
31+
x,
32+
y,
33+
option,
34+
children,
35+
as = "text",
36+
}) => {
3037
if (!children) return <></>;
3138
const defaultFontFamily = defaultFont;
3239

@@ -40,10 +47,26 @@ export const Text: React.FC<IText> = ({ x, y, option, children }) => {
4047
if (typeof x === "function")
4148
x = x(openTypeFont.getAdvanceWidth(children.toString(), font.size));
4249

43-
const path = openTypeFont.getPath(children.toString(), x, y, font.size);
44-
const pathSVG = path.toPathData(1);
45-
4650
const classNames = ["text"];
4751
if (typeof option === "string") classNames.push(option);
48-
return <path className={classNames.join(" ")} d={pathSVG} />;
52+
53+
if (as === "path") {
54+
const path = openTypeFont.getPath(children.toString(), x, y, font.size);
55+
const pathSVG = path.toPathData(1);
56+
57+
return <path className={classNames.join(" ")} d={pathSVG} />;
58+
} else {
59+
classNames.push("websafe");
60+
return (
61+
<text
62+
x={x}
63+
y={y}
64+
className={classNames.join(" ")}
65+
fontSize={font.size}
66+
fontWeight={font.weight}
67+
>
68+
<tspan>{children}</tspan>
69+
</text>
70+
);
71+
}
4972
};

0 commit comments

Comments
 (0)