Skip to content

Commit f5a721b

Browse files
authored
fix: Adds support for superscript and subscript on Super pdf exports (#2978) [skip e2e]
1 parent fafd15e commit f5a721b

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/PDFExport

packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/PDFExport/PDFExport.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import {
3333
getFontFamiliesFromLexicalNode,
3434
} from './FontConfig'
3535

36+
const PDF_SUPERSUBSCRIPT_FONT_SIZE = 9
37+
const PDF_HEADING_SUPERSUBSCRIPT_SCALE = 0.75
38+
3639
const styles = StyleSheet.create({
3740
page: {
3841
paddingVertical: 35,
@@ -200,6 +203,8 @@ const getPDFDataNodeFromLexicalNode = (
200203
const isBold = node.hasFormat('bold')
201204
const isItalic = node.hasFormat('italic')
202205
const isHighlight = node.hasFormat('highlight')
206+
const isSuperscript = node.hasFormat('superscript')
207+
const isSubscript = node.hasFormat('subscript')
203208
let fontFamily: FontFamily[] | FontFamily = FALLBACK_FONT_FAMILY
204209

205210
if (isInlineCode && isCodeNodeText) {
@@ -212,6 +217,15 @@ const getPDFDataNodeFromLexicalNode = (
212217
}
213218
}
214219

220+
const baseFontSize = isInlineCode || isCodeNodeText ? 11 : undefined
221+
const headingFontSize = $isHeadingNode(parent) ? getFontSizeForHeading(parent) : undefined
222+
const fontSize =
223+
isSuperscript || isSubscript
224+
? headingFontSize
225+
? Math.max(PDF_SUPERSUBSCRIPT_FONT_SIZE, Math.round(headingFontSize * PDF_HEADING_SUPERSUBSCRIPT_SCALE))
226+
: PDF_SUPERSUBSCRIPT_FONT_SIZE
227+
: baseFontSize
228+
215229
return {
216230
type: 'Text',
217231
children: node.getTextContent(),
@@ -226,8 +240,9 @@ const getPDFDataNodeFromLexicalNode = (
226240
? 'line-through'
227241
: undefined,
228242
backgroundColor: isInlineCode ? '#f1f1f1' : isHighlight ? 'rgb(255,255,0)' : undefined,
229-
fontSize: isInlineCode || isCodeNodeText ? 11 : undefined,
243+
fontSize,
230244
textAlign: $isElementNode(parent) ? getNodeTextAlignment(parent) : 'left',
245+
verticalAlign: isSuperscript ? 'super' : isSubscript ? 'sub' : undefined,
231246
},
232247
}
233248
}

0 commit comments

Comments
 (0)