-
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.
translated line height & letter spacing; Created new type for text po…
…sitionData
- Loading branch information
Showing
7 changed files
with
73 additions
and
5 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
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
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,12 @@ | ||
export const translateLetterSpacing = ( | ||
segment: Pick<StyledTextSegment, 'letterSpacing' | 'fontSize'> | ||
): number => { | ||
switch (segment.letterSpacing.unit) { | ||
case 'PIXELS': | ||
return segment.letterSpacing.value; | ||
case 'PERCENT': | ||
return (segment.fontSize * segment.letterSpacing.value) / 100; | ||
default: | ||
return 0; | ||
} | ||
}; |
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,13 @@ | ||
export const translateLineHeight = ( | ||
segment: Pick<StyledTextSegment, 'lineHeight' | 'fontSize'> | ||
): number => { | ||
// Penpot reads lineHeight as a multiplier of the font size | ||
switch (segment.lineHeight.unit) { | ||
case 'PIXELS': | ||
return segment.lineHeight.value / segment.fontSize; | ||
case 'PERCENT': | ||
return segment.lineHeight.value / 100; | ||
default: | ||
return 1.2; // This is the most common auto value for line-height | ||
} | ||
}; |
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,18 @@ | ||
import { PositionData } from '@ui/lib/types/text/textAttributes'; | ||
import { TextNode } from '@ui/lib/types/text/textContent'; | ||
|
||
export const translateTextPositionData = (segments: TextNode[]): PositionData[] => { | ||
return segments.map((segment): PositionData => { | ||
return { | ||
fills: segment.fills, | ||
fontFamily: segment.fontFamily, | ||
fontSize: segment.fontSize, | ||
fontStyle: segment.fontStyle, | ||
fontWeight: segment.fontWeight, | ||
rtl: segment.direction === 'rtl', | ||
text: segment.text, | ||
textDecoration: segment.textDecoration, | ||
textTransform: segment.textTransform | ||
}; | ||
}); | ||
}; |
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,9 +1,27 @@ | ||
import { TextContent, TextNode } from './textContent'; | ||
import { Fill } from '../utils/fill'; | ||
import { TextContent } from './textContent'; | ||
|
||
export const TEXT_TYPE: unique symbol = Symbol.for('text'); | ||
|
||
export type TextAttributes = { | ||
type: 'text' | typeof TEXT_TYPE; | ||
content?: TextContent; | ||
positionData: TextNode[]; | ||
positionData: PositionData[]; | ||
}; | ||
|
||
export type PositionData = { | ||
// @TODO: figure out how to manage position and dimension | ||
x?: number; | ||
y?: number; | ||
height?: number; | ||
width?: number; | ||
fills?: Fill[]; | ||
fontFamily?: string; | ||
fontSize?: string; | ||
fontStyle?: string; | ||
fontWeight?: string; | ||
rtl?: boolean; | ||
text?: string; | ||
textDecoration?: string; | ||
textTransform?: string; | ||
}; |