@@ -214,6 +214,8 @@ for (const glyphId of argGlyphList.glyphIds)
214214 }
215215}
216216
217+ const lineMetrics = font . getHorizontalLineMetrics ( )
218+
217219// Render glyphs.
218220for ( const glyph of resolvedGlyphList )
219221{
@@ -314,6 +316,8 @@ for (const glyph of resolvedGlyphList)
314316 height : geometry . yMax - geometry . yMin ,
315317 xOrigin : 0 ,
316318 yOrigin : 0 ,
319+ metricsY1 : lineMetrics . lineTop ,
320+ metricsY2 : lineMetrics . lineBottom ,
317321 xAdvance : geometry . advance ,
318322 emToPixels : null ,
319323 }
@@ -340,12 +344,41 @@ for (const glyph of resolvedGlyphList)
340344 if ( argDataMode != "json" )
341345 json . contours = geometry . contours
342346
343- if ( argDataMode != "xml-sprsheet" )
344- {
345- const jsonStr = JSON . stringify ( json , null , 4 )
346- fs . writeFileSync ( outputDataFilename + ".json" , jsonStr )
347+ if ( argDataMode === "json-sprsheet" )
348+ {
349+ const filenameWithoutFolder = path . basename ( outputDataFilename + ".png" )
350+ const json =
351+ `{
352+ sprites:
353+ [
354+ {
355+ id: "${ mainUnicodeCodepoint . toString ( 16 ) } ",
356+ src: "${ filenameWithoutFolder } ",
357+ x: 0,
358+ y: 0,
359+ w: ${ metrics . width } ,
360+ h: ${ metrics . height } ,
361+ trim_x: 0,
362+ trim_y: 0,
363+ trim_w: 0,
364+ trim_h: 0,
365+ properties:
366+ [
367+ unicode: ${ mainUnicodeCodepoint } ,
368+ xPivot: ${ Math . floor ( metrics . xOrigin ) } ,
369+ yPivot: ${ Math . floor ( metrics . yOrigin ) } ,
370+ advance: ${ Math . floor ( metrics . xAdvance ) } ,
371+ ascender: ${ Math . floor ( lineMetrics . lineTop * metrics . emToPixels ) } ,
372+ descender: ${ Math . floor ( lineMetrics . lineBottom * metrics . emToPixels ) } ,
373+ lineGap: ${ Math . floor ( lineMetrics . lineGap * metrics . emToPixels ) }
374+ ]
347375 }
348- else
376+ ]
377+ }`
378+
379+ fs . writeFileSync ( outputDataFilename + ".json" , json )
380+ }
381+ else if ( argDataMode === "xml-sprsheet" )
349382 {
350383 const filenameWithoutFolder = path . basename ( outputDataFilename + ".png" )
351384 const xml =
@@ -358,5 +391,10 @@ for (const glyph of resolvedGlyphList)
358391
359392 fs . writeFileSync ( outputDataFilename + ".sprsheet" , xml )
360393 }
394+ else
395+ {
396+ const jsonStr = JSON . stringify ( json , null , 4 )
397+ fs . writeFileSync ( outputDataFilename + ".json" , jsonStr )
398+ }
361399 }
362400}
0 commit comments