Skip to content

Commit

Permalink
fix: italic font style (#34)
Browse files Browse the repository at this point in the history
* fix: italic font style

* chore: changesets

* nit: prettify

Co-authored-by: jxom  <[email protected]>

---------

Co-authored-by: jxom <[email protected]>
  • Loading branch information
dalechyn and jxom authored Apr 8, 2024
1 parent 1bc7a22 commit c7eaccc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-pigs-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hono-og": patch
---

Fixed incorrect italic font style resolution.
18 changes: 17 additions & 1 deletion src/utils/loadGoogleFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,31 @@ export type LoadGoogleFontParameters = {
family: string;
weight?: number;
text?: string;
style?: "normal" | "italic";
};

export async function loadGoogleFont({
family,
weight,
text,
style = "normal",
}: LoadGoogleFontParameters): Promise<ArrayBuffer> {
let fontOptions: string | undefined;

if (style === "italic") {
// If weight is specified, we need to expliticly set the weight to have `1:` fallback
if (weight) fontOptions = `ital,wght@1,${weight}`;
// If no weight is specified, just append `ital:1` to get italic font.
else fontOptions = "ital@1";
} else {
// If no weight is specified, `fontOptions` should stay empty
// If weight is specified, append weight parameter
if (weight) fontOptions = `wght@${weight}`;
}
const params: Record<string, string> = {
family: `${encodeURIComponent(family)}${weight ? `:wght@${weight}` : ""}`,
family: `${encodeURIComponent(family)}${
fontOptions ? `:${fontOptions}` : ""
}`,
};
if (text) params.text = text;
else params.subset = "latin";
Expand Down

0 comments on commit c7eaccc

Please sign in to comment.