0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-19 05:52:34 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/text/local/translateLocalFont.ts

25 lines
768 B
TypeScript
Raw Normal View History

import { LocalFont, translateFontVariantId } from '@plugin/translators/text/local';
2024-05-06 08:06:14 +02:00
import { FontId } from '@ui/lib/types/shapes/textShape';
import { items as localFonts } from './localFonts.json';
export const translateLocalFont = (fontName: FontName, fontWeight: number): FontId | undefined => {
const localFont = getLocalFont(fontName);
if (localFont === undefined) return;
return {
fontId: localFont.id,
fontVariantId: translateFontVariantId(localFont, fontName, fontWeight)
};
};
export const isLocalFont = (fontName: FontName): boolean => {
return getLocalFont(fontName) !== undefined;
};
const getLocalFont = (fontName: FontName): LocalFont | undefined => {
return localFonts.find(localFont => localFont.name === fontName.family);
};