0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-10 09:00:08 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/translateStyledTextSegments.ts
Jordi Sala Morales 881ccabe86
Added text basic properties (#61)
* fixes in text nodes

* fix comment

* allow design.penpot.app

* wip

* wip

* add position data

* wip agaaain

* added translate growtype

* use a random url just to get a 404 on gfonts call

* leave the config, just in case someone wants to try it

* translated line height & letter spacing; Created new type for text positionData

* text strokes

* several fixes

* compiled penpot lib with fix

* updated penpot lib

* fix lint

* remove proxy

* correctly translate font style

* fix grow type to reflect vertical trim

* Fix font segments

* remove comment

* changeset

---------

Co-authored-by: Alex Sánchez <sion333@gmail.com>
2024-04-29 10:17:08 +02:00

32 lines
833 B
TypeScript

import { transformTextStyle } from '@plugin/transformers/partials';
import { translateFills } from '@plugin/translators/translateFills';
import { TextNode as PenpotTextNode } from '@ui/lib/types/text/textContent';
export const translateStyledTextSegments = (
node: TextNode,
segments: Pick<
StyledTextSegment,
| 'characters'
| 'start'
| 'end'
| 'fontName'
| 'fontSize'
| 'fontWeight'
| 'lineHeight'
| 'letterSpacing'
| 'textCase'
| 'textDecoration'
| 'fills'
>[]
): PenpotTextNode[] => {
return segments.map(segment => {
figma.ui.postMessage({ type: 'FONT_NAME', data: segment.fontName.family });
return {
fills: translateFills(segment.fills, node.width, node.height),
text: segment.characters,
...transformTextStyle(node, segment)
};
});
};