Skip to content

Commit

Permalink
Merge pull request #9 from nyarla/add-rounded-mplus-font
Browse files Browse the repository at this point in the history
feat(fonts): add Rounded M+ Fonts
  • Loading branch information
nyarla committed Apr 23, 2024
2 parents d1965b3 + 4c4b8e9 commit 939d649
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/fonts/rounded-mplus/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all: unpack

rounded-mplus.7z:
curl -L -o rounded-mplus.7z https://ftp.iij.ad.jp/pub/osdn.jp/users/8/8569/rounded-mplus-20150529.7z

rounded-x-mplus.7z:
curl -L -o rounded-x-mplus.7z https://ftp.iij.ad.jp/pub/osdn.jp/users/8/8570/rounded-x-mplus-20150529.7z

rounded-l-mplus.7z:
curl -L -o rounded-l-mplus.7z https://ftp.iij.ad.jp/pub/osdn.jp/users/8/8568/rounded-l-mplus-20150529.7z

unpack: rounded-mplus.7z rounded-x-mplus.7z rounded-l-mplus.7z
echo A | 7z x rounded-mplus.7z
echo A | 7z x rounded-x-mplus.7z
echo A | 7z x rounded-l-mplus.7z
80 changes: 80 additions & 0 deletions src/fonts/rounded-mplus/font.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { readFile } from "node:fs/promises";

import { FontOptions } from "satori";
import type { FontStyle } from "satori";

type MPlusVariants = 1 | 2;
type MPlusFontFaces = "c" | "p" | "m" | "mn";

type XMPlusWeights = "light" | "regular" | "medium" | "bold" | "heavy" | "bold";
type MPlusWeights = "thin" | XMPlusWeights;

const MPlusWeights = {
thin: 100,
light: 200,
regular: 400,
medium: 500,
bold: 600,
heavy: 700,
bold: 900,
};

export async function RoundedXMPlus(
fontVariant: MPlusVariants = 1,
fontFace: MPlusFontFaces = "c",
fontWeight: XMPlusWeights = "regular",
fontStyle: FontStyle = "normal",
) {
const fn = new URL(
`./rounded-x-mplus-${fontVariant}${fontFace}-${fontWeight}.ttf`,
import.meta.url,
);

const name = `Rounded-X M+ ${fontVariant}${fontFace}`;
const lang = "ja-JP";
const data = await readFile(fn);
const weight = MPlusWeights[fontWeight];
const style = fontStyle;

return { name, lang, data, weight, style };
}

export async function RoundedLMPlus(
fontVariant: MPlusVariants = 1,
fontFace: MPlusFontFaces = "c",
fontWeight: MPlusWeights = "regular",
fontStyle: FontStyle = "normal",
) {
const fn = new URL(
`./rounded-l-mplus-${fontVariant}${fontFace}-${fontWeight}.ttf`,
import.meta.url,
);

const name = `Rounded-L M+ ${fontVariant}${fontFace}`;
const lang = "ja-JP";
const data = await readFile(fn);
const weight = MPlusWeights[fontWeight];
const style = fontStyle;

return { name, lang, data, weight, style };
}

export async function RoundedMPlus(
fontVariant: MPlusVariants = 1,
fontFace: MPlusFontFaces = "c",
fontWeight: MPlusWeights = "regular",
fontStyle: FontStyle = "normal",
) {
const fn = new URL(
`./rounded-mplus-${fontVariant}${fontFace}-${fontWeight}.ttf`,
import.meta.url,
);

const name = `Rounded M+ ${fontVariant}${fontFace}`;
const lang = "ja-JP";
const data = await readFile(fn);
const weight = MPlusWeights[fontWeight];
const style = fontStyle;

return { name, lang, data, weight, style };
}

0 comments on commit 939d649

Please sign in to comment.