@@ -157,6 +157,8 @@ export function writeHtml({
157
157
newLine = true ;
158
158
}
159
159
160
+ let underlinePrev = false ;
161
+
160
162
for ( let i = 0 ; i < lineObj . words . length ; i ++ ) {
161
163
const wordObj = lineObj . words [ i ] ;
162
164
if ( ! wordObj ) continue ;
@@ -262,7 +264,6 @@ export function writeHtml({
262
264
263
265
styleStr += `font-weight:${ fontI . fontFaceWeight } ;` ;
264
266
styleStr += `font-style:${ fontI . fontFaceStyle } ;` ;
265
- styleStr += `padding-left:${ leftPad } px;` ;
266
267
267
268
// Line height must match the height of the font bounding box for the font metrics to be accurate.
268
269
styleStr += `line-height:${ metrics . fontBoundingBoxAscent + metrics . fontBoundingBoxDescent } px;` ;
@@ -272,7 +273,42 @@ export function writeHtml({
272
273
styleStr += `vertical-align:${ supOffset } px;` ;
273
274
}
274
275
275
- activeLine . bodyWordsStr += ` <span class="scribe-word" id="${ wordObj . id } " style="${ styleStr } ">${ innerHTML } </span>\n` ;
276
+ if ( wordObj . style . underline ) {
277
+ styleStr += 'text-decoration:underline;' ;
278
+ styleStr += `text-decoration-color:${ fill } ;` ;
279
+ styleStr += `text-decoration-thickness:${ Math . ceil ( fontSizeHTML / 12 ) } px;` ;
280
+ styleStr += `text-underline-offset:${ Math . ceil ( fontSizeHTML / 12 ) + Math . ceil ( fontSizeHTML / 24 ) } px;` ;
281
+ }
282
+
283
+ if ( i > 0 ) {
284
+ let styleStrSpace = `font-family:${ fontI . fontFaceName } ;` ;
285
+ const spaceAdvancePx = ( fontI . opentype . charToGlyph ( ' ' ) . advanceWidth / fontI . opentype . unitsPerEm ) ;
286
+ const fontSizeHTMLSpace = leftPad / spaceAdvancePx ;
287
+ if ( fontSizeHTMLSpace > fontSizeHTML * 3 ) {
288
+ styleStrSpace += `font-size:${ fontSizeHTML } px;` ;
289
+
290
+ const leftPadFinal = leftPad - spaceAdvancePx * fontSizeHTML ;
291
+
292
+ styleStrSpace += `padding-left:${ leftPadFinal } px;` ;
293
+ } else {
294
+ styleStrSpace += `font-size:${ fontSizeHTML } px;` ;
295
+ const leftPadFinal = leftPad - spaceAdvancePx * fontSizeHTML ;
296
+ styleStrSpace += `word-spacing:${ leftPadFinal } px;` ;
297
+ }
298
+
299
+ if ( underlinePrev ) {
300
+ styleStrSpace += 'text-decoration:underline;' ;
301
+ styleStrSpace += `text-decoration-color:${ fill } ;` ;
302
+ styleStrSpace += `text-decoration-thickness:${ Math . ceil ( fontSizeHTML / 12 ) } px;` ;
303
+ styleStrSpace += `text-underline-offset:${ Math . ceil ( fontSizeHTML / 12 ) + Math . ceil ( fontSizeHTML / 24 ) } px;` ;
304
+ }
305
+
306
+ activeLine . bodyWordsStr += `<span class="scribe-space" style=${ styleStrSpace } > </span>` ;
307
+ }
308
+
309
+ activeLine . bodyWordsStr += `<span class="scribe-word" id="${ wordObj . id } " style="${ styleStr } ">${ innerHTML } </span>` ;
310
+
311
+ underlinePrev = wordObj . style . underline ;
276
312
277
313
wordObjPrev = wordObj ;
278
314
rightSideBearingPrev = rightSideBearing ;
@@ -299,7 +335,6 @@ export function writeHtml({
299
335
styleStr += ' }\n' ;
300
336
301
337
styleStr += ' .scribe-line {\n' ;
302
- styleStr += ' font-size:0px;\n' ;
303
338
styleStr += ' position:absolute;\n' ;
304
339
styleStr += ' white-space:nowrap;\n' ;
305
340
styleStr += ' }\n' ;
@@ -325,7 +360,7 @@ export function writeHtml({
325
360
326
361
const metaStr = '<meta charset="UTF-8">\n' ;
327
362
328
- const htmlStr = `<html>\n<head>\n${ metaStr } ${ styleStr } </head>\n${ bodyStr } </html>` ;
363
+ const htmlStr = `<!doctype html>\n< html>\n<head>\n${ metaStr } ${ styleStr } </head>\n${ bodyStr } </html>` ;
329
364
330
365
FontCont . state . enableOpt = enableOptSaved ;
331
366
0 commit comments