@@ -188,14 +188,12 @@ export function writeHtml({
188
188
const scale = 1 ;
189
189
const angle = 0 ;
190
190
191
- // HTML exports currently only use raw fonts, as the fonts are retrieved from a CDN.
192
- const fontI = FontCont . getWordFont ( wordObj ) ;
193
- fontsUsed . add ( fontI ) ;
194
-
195
191
const {
196
192
charSpacing, leftSideBearing, rightSideBearing, fontSize, charArr, advanceArr, kerningArr, font,
197
193
} = calcWordMetrics ( wordObj ) ;
198
194
195
+ fontsUsed . add ( font ) ;
196
+
199
197
const wordStr = charArr . join ( '' ) ;
200
198
201
199
const charSpacingHTML = charSpacing * scale ;
@@ -204,9 +202,9 @@ export function writeHtml({
204
202
205
203
const fontSizeHTML = fontSize * scale ;
206
204
207
- const metrics = calcFontMetrics ( fontI , fontSizeHTML ) ;
205
+ const metrics = calcFontMetrics ( font , fontSizeHTML ) ;
208
206
209
- const fontSizeHTMLSmallCaps = fontSize * scale * fontI . smallCapsMult ;
207
+ const fontSizeHTMLSmallCaps = fontSize * scale * font . smallCapsMult ;
210
208
211
209
if ( metrics . fontBoundingBoxAscent > activeLine . maxFontBoundingBoxAscentLine ) {
212
210
activeLine . maxFontBoundingBoxAscentLine = metrics . fontBoundingBoxAscent ;
@@ -218,7 +216,7 @@ export function writeHtml({
218
216
let styleStr = '' ;
219
217
220
218
styleStr += `font-size:${ fontSizeHTML } px;` ;
221
- styleStr += `font-family:${ fontI . fontFaceName } ;` ;
219
+ styleStr += `font-family:${ font . fontFaceName } ;` ;
222
220
223
221
if ( Math . abs ( angle ?? 0 ) > 0.05 ) {
224
222
styleStr += `transform-origin:left ${ y1 - topHTML } px;` ;
@@ -265,8 +263,8 @@ export function writeHtml({
265
263
266
264
styleStr += `letter-spacing:${ formatNum ( charSpacingHTML ) } px;` ;
267
265
268
- styleStr += `font-weight:${ fontI . fontFaceWeight } ;` ;
269
- styleStr += `font-style:${ fontI . fontFaceStyle } ;` ;
266
+ styleStr += `font-weight:${ font . fontFaceWeight } ;` ;
267
+ styleStr += `font-style:${ font . fontFaceStyle } ;` ;
270
268
271
269
// Line height must match the height of the font bounding box for the font metrics to be accurate.
272
270
styleStr += `line-height:${ metrics . fontBoundingBoxAscent + metrics . fontBoundingBoxDescent } px;` ;
@@ -284,10 +282,9 @@ export function writeHtml({
284
282
}
285
283
286
284
if ( i > 0 ) {
287
- let styleStrSpace = `font-family:${ fontI . fontFaceName } ;` ;
288
- styleStrSpace += `font-style:${ fontI . fontFaceStyle } ;` ;
289
- const spaceAdvance = fontI . opentype . charToGlyph ( ' ' ) . advanceWidth || fontI . opentype . unitsPerEm * 0.35 ;
290
- const spaceAdvancePx = ( spaceAdvance / fontI . opentype . unitsPerEm ) ;
285
+ let styleStrSpace = '' ;
286
+ const spaceAdvance = font . opentype . charToGlyph ( ' ' ) . advanceWidth || font . opentype . unitsPerEm * 0.35 ;
287
+ const spaceAdvancePx = ( spaceAdvance / font . opentype . unitsPerEm ) ;
291
288
const fontSizeHTMLSpace = leftPad / spaceAdvancePx ;
292
289
if ( fontSizeHTMLSpace > fontSizeHTML * 3 ) {
293
290
styleStrSpace += `font-size:${ fontSizeHTML } px;` ;
@@ -301,6 +298,10 @@ export function writeHtml({
301
298
styleStrSpace += `word-spacing:${ formatNum ( leftPadFinal ) } px;` ;
302
299
}
303
300
301
+ styleStrSpace += `font-family:${ font . fontFaceName } ;` ;
302
+ styleStrSpace += `font-style:${ font . fontFaceStyle } ;` ;
303
+ styleStrSpace += `font-weight:${ font . fontFaceWeight } ;` ;
304
+
304
305
if ( underlinePrev ) {
305
306
styleStrSpace += `color:${ fill } ;` ;
306
307
styleStrSpace += `opacity:${ opacity } ;` ;
@@ -362,9 +363,16 @@ export function writeHtml({
362
363
styleStr += ' }\n' ;
363
364
364
365
for ( const fontI of fontsUsed ) {
365
- const cdnPath = 'https://cdn.jsdelivr.net/npm/[email protected] /fonts/all/' ;
366
- let styleTitleCase = fontI . style . charAt ( 0 ) . toUpperCase ( ) + fontI . style . slice ( 1 ) . toLowerCase ( ) ;
367
- if ( styleTitleCase === 'Normal' ) styleTitleCase = 'Regular' ;
366
+ const cdnPath = 'https://cdn.jsdelivr.net/npm/[email protected] /fonts/all/' ;
367
+ let styleTitleCase = 'Regular' ;
368
+ if ( fontI . style === 'italic' ) {
369
+ styleTitleCase = 'Italic' ;
370
+ } else if ( fontI . style === 'bold' ) {
371
+ styleTitleCase = 'Bold' ;
372
+ } else if ( fontI . style === 'boldItalic' ) {
373
+ styleTitleCase = 'BoldItalic' ;
374
+ }
375
+
368
376
const fontName = `${ fontI . family } -${ styleTitleCase } .woff` ;
369
377
const fontPath = cdnPath + fontName ;
370
378
0 commit comments