0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-23 07:48:41 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/text/font/gfonts/translateFontVariantId.ts

21 lines
651 B
TypeScript
Raw Normal View History

import { GoogleFont } from './googleFont';
export const translateFontVariantId = (
googleFont: GoogleFont,
fontName: FontName,
fontWeight: number
) => {
// check match directly by style
const variant = googleFont.variants?.find(variant => variant === fontName.style.toLowerCase());
if (variant !== undefined) return variant;
// check match by style and weight
const italic = fontName.style.toLowerCase().includes('italic') ? 'italic' : '';
const variantWithWeight = googleFont.variants?.find(
variant => variant === `${fontWeight.toString()}${italic}`
);
if (variantWithWeight !== undefined) return variantWithWeight;
};