0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-24 08:18:41 -05:00

Merge pull request #16 from ryanbreen/GH-15-text-decoration-and-transforms

🐛 Fix text transform and decoration
This commit is contained in:
Pablo Alba 2023-01-05 09:02:19 +01:00 committed by GitHub
commit ac443b7047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 5 deletions

View file

@ -71,7 +71,7 @@ function traverse(node): NodeData {
} }
if (node.type == "TEXT") { if (node.type == "TEXT") {
const styledTextSegments = node.getStyledTextSegments(["fontName", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "fills"]); const styledTextSegments = node.getStyledTextSegments(["fontName", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "textCase", "textDecoration", "fills"]);
let font = { let font = {
fontName: styledTextSegments[0].fontName, fontName: styledTextSegments[0].fontName,
fontSize: styledTextSegments[0].fontSize.toString(), fontSize: styledTextSegments[0].fontSize.toString(),
@ -80,6 +80,8 @@ function traverse(node): NodeData {
lineHeight: styledTextSegments[0].lineHeight, lineHeight: styledTextSegments[0].lineHeight,
letterSpacing: styledTextSegments[0].letterSpacing, letterSpacing: styledTextSegments[0].letterSpacing,
fills: styledTextSegments[0].fills, fills: styledTextSegments[0].fills,
textCase: styledTextSegments[0].textCase,
textDecoration: styledTextSegments[0].textDecoration,
textAlignHorizontal: node.textAlignHorizontal, textAlignHorizontal: node.textAlignHorizontal,
textAlignVertical: node.textAlignVertical, textAlignVertical: node.textAlignVertical,
children: styledTextSegments children: styledTextSegments

View file

@ -166,7 +166,33 @@ export default class PenpotExporter extends React.Component<PenpotExporterProps,
return style.toLowerCase().replace(/\s/g, "") return style.toLowerCase().replace(/\s/g, "")
} }
getTextDecoration(node){
const textDecoration = node.textDecoration;
if (textDecoration === "STRIKETHROUGH"){
return "line-through";
}
if (textDecoration === "UNDERLINE"){
return "underline";
}
return "none";
}
getTextTransform(node){
const textCase = node.textCase;
if (textCase === "UPPER"){
return "uppercase";
}
if (textCase === "LOWER"){
return "lowercase";
}
if (textCase === "TITLE"){
return "capitalize";
}
return "none";
}
createPenpotText(file, node, baseX, baseY){ createPenpotText(file, node, baseX, baseY){
const children = node.children.map((val) => { const children = node.children.map((val) => {
return { return {
lineHeight: val.lineHeight, lineHeight: val.lineHeight,
@ -176,8 +202,8 @@ export default class PenpotExporter extends React.Component<PenpotExporterProps,
fontSize: val.fontSize.toString(), fontSize: val.fontSize.toString(),
fontWeight: val.fontWeight.toString(), fontWeight: val.fontWeight.toString(),
fontVariantId: this.translateFontStyle(val.fontName.style), fontVariantId: this.translateFontStyle(val.fontName.style),
textDecoration: "none", textDecoration: this.getTextDecoration(val),
textTransform: "none", textTransform: this.getTextTransform(val),
letterSpacing: val.letterSpacing, letterSpacing: val.letterSpacing,
fills: this.translateFills(val.fills, node.width, node.height), fills: this.translateFills(val.fills, node.width, node.height),
fontFamily: val.fontName.family, fontFamily: val.fontName.family,
@ -201,13 +227,13 @@ export default class PenpotExporter extends React.Component<PenpotExporterProps,
lineHeight: node.lineHeight, lineHeight: node.lineHeight,
fontStyle: "normal", fontStyle: "normal",
children: children, children: children,
textTransform: "none", textTransform: this.getTextTransform(node),
textAlign: this.translateHorizontalAlign(node.textAlignHorizontal), textAlign: this.translateHorizontalAlign(node.textAlignHorizontal),
fontId: "gfont-" + slugify(node.fontName.family.toLowerCase()), fontId: "gfont-" + slugify(node.fontName.family.toLowerCase()),
fontSize: node.fontSize.toString(), fontSize: node.fontSize.toString(),
fontWeight: node.fontWeight.toString(), fontWeight: node.fontWeight.toString(),
type: "paragraph", type: "paragraph",
textDecoration: "none", textDecoration: this.getTextDecoration(node),
letterSpacing: node.letterSpacing, letterSpacing: node.letterSpacing,
fills: this.translateFills(node.fills, node.width, node.height), fills: this.translateFills(node.fills, node.width, node.height),
fontFamily: node.fontName.family fontFamily: node.fontName.family