-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moved validate font logic * google fonts working * fixes * minor improvements * fix linter * fixes * Changeset * refactor * refactor * move files around --------- Co-authored-by: Jordi Sala Morales <[email protected]>
- Loading branch information
1 parent
881ccab
commit 8021da2
Showing
24 changed files
with
27,113 additions
and
1,581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": minor | ||
--- | ||
|
||
Add support for Google Fonts |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { transformFills } from '@plugin/transformers/partials'; | ||
import { | ||
translateFills, | ||
translateHorizontalAlign, | ||
translateVerticalAlign | ||
} from '@plugin/translators'; | ||
import { | ||
translateFontId, | ||
translateFontStyle, | ||
translateFontVariantId, | ||
translateGrowType, | ||
translateLetterSpacing, | ||
translateLineHeight, | ||
translateTextDecoration, | ||
translateTextTransform | ||
} from '@plugin/translators/text'; | ||
|
||
import { TextStyle } from '@ui/lib/types/text/textContent'; | ||
import { TextShape } from '@ui/lib/types/text/textShape'; | ||
|
||
export const transformText = (node: TextNode): Partial<TextShape> => { | ||
const styledTextSegments = node.getStyledTextSegments([ | ||
'fontName', | ||
'fontSize', | ||
'fontWeight', | ||
'lineHeight', | ||
'letterSpacing', | ||
'textCase', | ||
'textDecoration', | ||
'fills' | ||
]); | ||
|
||
return { | ||
content: { | ||
type: 'root', | ||
verticalAlign: translateVerticalAlign(node.textAlignVertical), | ||
children: [ | ||
{ | ||
type: 'paragraph-set', | ||
children: [ | ||
{ | ||
type: 'paragraph', | ||
children: styledTextSegments.map(segment => ({ | ||
fills: translateFills(segment.fills, node.width, node.height), | ||
text: segment.characters, | ||
...transformTextStyle(node, segment) | ||
})), | ||
...(styledTextSegments.length ? transformTextStyle(node, styledTextSegments[0]) : {}), | ||
...transformFills(node) | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
growType: translateGrowType(node) | ||
}; | ||
}; | ||
|
||
const transformTextStyle = ( | ||
node: TextNode, | ||
segment: Pick< | ||
StyledTextSegment, | ||
| 'characters' | ||
| 'start' | ||
| 'end' | ||
| 'fontName' | ||
| 'fontSize' | ||
| 'fontWeight' | ||
| 'lineHeight' | ||
| 'letterSpacing' | ||
| 'textCase' | ||
| 'textDecoration' | ||
| 'fills' | ||
> | ||
): Partial<TextStyle> => { | ||
return { | ||
fontFamily: segment.fontName.family, | ||
fontId: translateFontId(segment.fontName), | ||
fontVariantId: translateFontVariantId(segment.fontName, segment.fontWeight), | ||
fontSize: segment.fontSize.toString(), | ||
fontStyle: translateFontStyle(segment.fontName.style), | ||
fontWeight: segment.fontWeight.toString(), | ||
textAlign: translateHorizontalAlign(node.textAlignHorizontal), | ||
textDecoration: translateTextDecoration(segment), | ||
textTransform: translateTextTransform(segment), | ||
letterSpacing: translateLetterSpacing(segment), | ||
lineHeight: translateLineHeight(segment) | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
export * from './translateBlendMode'; | ||
export * from './translateShadowEffects'; | ||
export * from './translateFills'; | ||
export * from './translateFontStyle'; | ||
export * from './translateFontVariantId'; | ||
export * from './translateGrowType'; | ||
export * from './translateHorizontalAlign'; | ||
export * from './translateLetterSpacing'; | ||
export * from './translateLineHeight'; | ||
export * from './translateStrokes'; | ||
export * from './translateStyledTextSegments'; | ||
export * from './translateTextDecoration'; | ||
export * from './translateTextTransform'; | ||
export * from './translateVectorPaths'; | ||
export * from './translateVerticalAlign'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from './translateFontIds'; | ||
export * from './translateFontStyle'; | ||
export * from './translateGrowType'; | ||
export * from './translateLetterSpacing'; | ||
export * from './translateLineHeight'; | ||
export * from './translateTextDecoration'; | ||
export * from './translateTextTransform'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import slugify from 'slugify'; | ||
|
||
import { items as gfonts } from '@plugin/gfonts.json'; | ||
|
||
export const translateFontId = (fontName: FontName): string => { | ||
if (isGfont(fontName)) { | ||
return `gfont-${slugify(fontName.family.toLowerCase())}`; | ||
} | ||
|
||
// @TODO: check if source sans pro | ||
|
||
// always send font name if not gfont or source sans pro | ||
figma.ui.postMessage({ type: 'FONT_NAME', data: fontName.family }); | ||
|
||
// @TODO: custom font | ||
return slugify(fontName.family.toLowerCase()); | ||
}; | ||
|
||
export const translateFontVariantId = (fontName: FontName, fontWeight: number) => { | ||
const variantId = translateGfontVariantId(fontName, fontWeight); | ||
if (variantId !== undefined) { | ||
return variantId; | ||
} | ||
|
||
// @TODO: Custom font | ||
// @TODO: Source Sans pro | ||
return fontName.style.toLowerCase().replace(/\s/g, ''); | ||
}; | ||
|
||
const findGoogleFont = (fontName: FontName) => { | ||
return gfonts.find(font => font.family === fontName.family); | ||
}; | ||
|
||
const isGfont = (fontName: FontName): boolean => { | ||
return findGoogleFont(fontName) !== undefined; | ||
}; | ||
|
||
const translateGfontVariantId = (fontName: FontName, fontWeight: number): string | undefined => { | ||
const gfont = findGoogleFont(fontName); | ||
|
||
if (gfont === undefined) { | ||
return; | ||
} | ||
|
||
// check match directly by style | ||
const variant = gfont.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 = gfont.variants.find( | ||
variant => variant === `${fontWeight.toString()}${italic}` | ||
); | ||
|
||
if (variantWithWeight !== undefined) { | ||
return variantWithWeight; | ||
} | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from './applyMatrixToPoint'; | ||
export * from './calculateAdjustment'; | ||
export * from './calculateLinearGradient'; | ||
export * from './detectMimeType'; | ||
export * from './matrixInvert'; | ||
export * from './rgbToHex'; | ||
export * from './calculateAdjustment'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.