Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Apr 30, 2024
1 parent 58f7b0a commit 81d7401
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugin-src/translators/text/custom/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './translateCustomFont';
export * from './translateFontVariantId';
6 changes: 4 additions & 2 deletions plugin-src/translators/text/custom/translateCustomFont.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import slugify from 'slugify';

import { translateFontVariantId } from '@plugin/translators/text/custom';

import { FontId } from '@ui/lib/types/text/textContent';

/**
* @TODO: implement custom font loading for Penpot
*/
export const translateCustomFont = (fontName: FontName): FontId | undefined => {
export const translateCustomFont = (fontName: FontName, fontWeight: number): FontId | undefined => {
// For now display a message in the UI, so the user knows
// that the file is using a custom font not present in Penpot
figma.ui.postMessage({ type: 'FONT_NAME', data: fontName.family });

return {
fontId: slugify(fontName.family.toLowerCase()),
fontVariantId: fontName.style.toLowerCase().replace(/\s/g, '')
fontVariantId: translateFontVariantId(fontName, fontWeight)
};
};
5 changes: 5 additions & 0 deletions plugin-src/translators/text/custom/translateFontVariantId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const translateFontVariantId = (fontName: FontName, fontWeight: number) => {
// check match by style and weight
const italic = fontName.style.toLowerCase().includes('italic') ? 'italic' : 'normal';
return `${italic}-${fontWeight.toString()}`;
};
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateFontId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const translateFontId = (fontName: FontName, fontWeight: number): FontId
return (
translateGoogleFont(fontName, fontWeight) ??
translateLocalFont(fontName, fontWeight) ??
translateCustomFont(fontName)
translateCustomFont(fontName, fontWeight)
);
};

0 comments on commit 81d7401

Please sign in to comment.