mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-03 05:10:13 -05:00
Merge pull request #8 from Runroom/hotfix/missing-fonts
Fix Missing Fonts
This commit is contained in:
commit
77cfd0b800
11 changed files with 53 additions and 49 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import { PenpotFile } from '../ui/penpot';
|
||||||
|
|
||||||
export type NodeData = {
|
export type NodeData = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -42,3 +44,8 @@ export type TextData = Pick<
|
||||||
textAlignVertical: 'CENTER' | 'TOP' | 'BOTTOM';
|
textAlignVertical: 'CENTER' | 'TOP' | 'BOTTOM';
|
||||||
children: TextDataChildren[];
|
children: TextDataChildren[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ExportFile = {
|
||||||
|
penpotFile: PenpotFile;
|
||||||
|
fontNames: Set<FontName>;
|
||||||
|
};
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import { createPenpotItem } from '.';
|
import { createPenpotItem } from '.';
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
import { translateFills } from '../translators';
|
import { translateFills } from '../translators';
|
||||||
|
|
||||||
export const createPenpotBoard = (
|
export const createPenpotBoard = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: NodeData,
|
node: NodeData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
) => {
|
) => {
|
||||||
file.addArtboard({
|
file.penpotFile.addArtboard({
|
||||||
name: node.name,
|
name: node.name,
|
||||||
x: node.x + baseX,
|
x: node.x + baseX,
|
||||||
y: node.y + baseY,
|
y: node.y + baseY,
|
||||||
|
@ -20,5 +19,5 @@ export const createPenpotBoard = (
|
||||||
for (const child of node.children) {
|
for (const child of node.children) {
|
||||||
createPenpotItem(file, child, node.x + baseX, node.y + baseY);
|
createPenpotItem(file, child, node.x + baseX, node.y + baseY);
|
||||||
}
|
}
|
||||||
file.closeArtboard();
|
file.penpotFile.closeArtboard();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
import { translateFills } from '../translators';
|
import { translateFills } from '../translators';
|
||||||
|
|
||||||
export const createPenpotCircle = (
|
export const createPenpotCircle = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: NodeData,
|
node: NodeData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
) => {
|
) => {
|
||||||
file.createCircle({
|
file.penpotFile.createCircle({
|
||||||
name: node.name,
|
name: node.name,
|
||||||
x: node.x + baseX,
|
x: node.x + baseX,
|
||||||
y: node.y + baseY,
|
y: node.y + baseY,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { createPenpotItem } from '.';
|
import { createPenpotItem } from '.';
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { createFile } from '../penpot';
|
import { createFile } from '../penpot';
|
||||||
|
|
||||||
export const createPenpotFile = (node: NodeData) => {
|
export const createPenpotFile = (node: NodeData) => {
|
||||||
const file = createFile(node.name);
|
const exportFile = { penpotFile: createFile(node.name), fontNames: new Set<FontName>() };
|
||||||
for (const page of node.children) {
|
for (const page of node.children) {
|
||||||
createPenpotItem(file, page, 0, 0);
|
createPenpotItem(exportFile as ExportFile, page, 0, 0);
|
||||||
}
|
}
|
||||||
return file;
|
return exportFile;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
import { createPenpotItem } from '.';
|
import { createPenpotItem } from '.';
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
|
|
||||||
export const createPenpotGroup = (
|
export const createPenpotGroup = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: NodeData,
|
node: NodeData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
) => {
|
) => {
|
||||||
file.addGroup({ name: node.name });
|
file.penpotFile.addGroup({ name: node.name });
|
||||||
for (const child of node.children) {
|
for (const child of node.children) {
|
||||||
createPenpotItem(file, child, baseX, baseY);
|
createPenpotItem(file, child, baseX, baseY);
|
||||||
}
|
}
|
||||||
file.closeGroup();
|
file.penpotFile.closeGroup();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
|
|
||||||
export const createPenpotImage = (
|
export const createPenpotImage = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: NodeData,
|
node: NodeData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
) => {
|
) => {
|
||||||
file.createImage({
|
file.penpotFile.createImage({
|
||||||
name: node.name,
|
name: node.name,
|
||||||
x: node.x + baseX,
|
x: node.x + baseX,
|
||||||
y: node.y + baseY,
|
y: node.y + baseY,
|
||||||
|
|
|
@ -7,12 +7,11 @@ import {
|
||||||
createPenpotRectangle,
|
createPenpotRectangle,
|
||||||
createPenpotText
|
createPenpotText
|
||||||
} from '.';
|
} from '.';
|
||||||
import { NodeData, TextData } from '../../common/interfaces';
|
import { ExportFile, NodeData, TextData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
import { calculateAdjustment } from '../utils';
|
import { calculateAdjustment } from '../utils';
|
||||||
|
|
||||||
export const createPenpotItem = (
|
export const createPenpotItem = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: NodeData,
|
node: NodeData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import { createPenpotItem } from '.';
|
import { createPenpotItem } from '.';
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
|
|
||||||
export const createPenpotPage = (file: PenpotFile, node: NodeData) => {
|
export const createPenpotPage = (file: ExportFile, node: NodeData) => {
|
||||||
file.addPage(node.name);
|
file.penpotFile.addPage(node.name);
|
||||||
for (const child of node.children) {
|
for (const child of node.children) {
|
||||||
createPenpotItem(file, child, 0, 0);
|
createPenpotItem(file, child, 0, 0);
|
||||||
}
|
}
|
||||||
file.closePage();
|
file.penpotFile.closePage();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import { NodeData } from '../../common/interfaces';
|
import { ExportFile, NodeData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
import { translateFills } from '../translators';
|
import { translateFills } from '../translators';
|
||||||
|
|
||||||
export const createPenpotRectangle = (
|
export const createPenpotRectangle = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: NodeData,
|
node: NodeData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
) => {
|
) => {
|
||||||
file.createRect({
|
file.penpotFile.createRect({
|
||||||
name: node.name,
|
name: node.name,
|
||||||
x: node.x + baseX,
|
x: node.x + baseX,
|
||||||
y: node.y + baseY,
|
y: node.y + baseY,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import slugify from 'slugify';
|
import slugify from 'slugify';
|
||||||
|
|
||||||
import { TextData } from '../../common/interfaces';
|
import { ExportFile, TextData } from '../../common/interfaces';
|
||||||
import { PenpotFile } from '../penpot';
|
|
||||||
import {
|
import {
|
||||||
translateFills,
|
translateFills,
|
||||||
translateFontStyle,
|
translateFontStyle,
|
||||||
|
@ -10,16 +9,15 @@ import {
|
||||||
translateTextTransform,
|
translateTextTransform,
|
||||||
translateVerticalAlign
|
translateVerticalAlign
|
||||||
} from '../translators';
|
} from '../translators';
|
||||||
import { validateFont } from '../validators';
|
|
||||||
|
|
||||||
export const createPenpotText = (
|
export const createPenpotText = (
|
||||||
file: PenpotFile,
|
file: ExportFile,
|
||||||
node: TextData,
|
node: TextData,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number
|
||||||
) => {
|
) => {
|
||||||
const children = node.children.map(val => {
|
const children = node.children.map(val => {
|
||||||
validateFont(val.fontName);
|
file.fontNames.add(val.fontName);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lineHeight: val.lineHeight,
|
lineHeight: val.lineHeight,
|
||||||
|
@ -38,9 +36,9 @@ export const createPenpotText = (
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
validateFont(node.fontName);
|
file.fontNames.add(node.fontName);
|
||||||
|
|
||||||
file.createText({
|
file.penpotFile.createText({
|
||||||
name: node.name,
|
name: node.name,
|
||||||
x: node.x + baseX,
|
x: node.x + baseX,
|
||||||
y: node.y + baseY,
|
y: node.y + baseY,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
|
import slugify from 'slugify';
|
||||||
|
|
||||||
import { createPenpotFile } from './converters';
|
import { createPenpotFile } from './converters';
|
||||||
import './ui.css';
|
import './ui.css';
|
||||||
|
import { validateFont } from './validators';
|
||||||
|
|
||||||
type PenpotExporterState = {
|
type PenpotExporterState = {
|
||||||
missingFonts: Set<string>;
|
missingFonts: Set<string>;
|
||||||
|
@ -26,14 +28,12 @@ export default class PenpotExporter extends React.Component<unknown, PenpotExpor
|
||||||
componentWillUnmount = () => {
|
componentWillUnmount = () => {
|
||||||
window.removeEventListener('message', this.onMessage);
|
window.removeEventListener('message', this.onMessage);
|
||||||
};
|
};
|
||||||
|
addFontWarning(font: string) {
|
||||||
|
const newMissingFonts = this.state.missingFonts;
|
||||||
|
newMissingFonts.add(font);
|
||||||
|
|
||||||
// TODO: FIX THIS CODE
|
this.setState(() => ({ missingFonts: newMissingFonts }));
|
||||||
// addFontWarning(font: string) {
|
}
|
||||||
// const newMissingFonts = this.state.missingFonts;
|
|
||||||
// newMissingFonts.add(font);
|
|
||||||
//
|
|
||||||
// this.setState(() => ({ missingFonts: newMissingFonts }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
onCreatePenpot = () => {
|
onCreatePenpot = () => {
|
||||||
this.setState(() => ({ exporting: true }));
|
this.setState(() => ({ exporting: true }));
|
||||||
|
@ -48,7 +48,13 @@ export default class PenpotExporter extends React.Component<unknown, PenpotExpor
|
||||||
onMessage = (event: any) => {
|
onMessage = (event: any) => {
|
||||||
if (event.data.pluginMessage.type == 'FIGMAFILE') {
|
if (event.data.pluginMessage.type == 'FIGMAFILE') {
|
||||||
const file = createPenpotFile(event.data.pluginMessage.data);
|
const file = createPenpotFile(event.data.pluginMessage.data);
|
||||||
file.export();
|
// validate file.fontNames
|
||||||
|
file.fontNames.forEach(font => {
|
||||||
|
if (!validateFont(font)) {
|
||||||
|
this.addFontWarning(slugify(font.family.toLowerCase()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
file.penpotFile.export();
|
||||||
this.setState(() => ({ exporting: false }));
|
this.setState(() => ({ exporting: false }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue