File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -319,6 +319,11 @@ <h3>Per-table breakdown</h3>
319319 < a href ="https://harfbuzz.github.io/integration-freetype.html "> hb-ft</ a >
320320 if you need hinted output at small sizes.</ p >
321321 < div class ="render "> < canvas id ="raster-canvas "> </ canvas > </ div >
322+ < div class ="controls demo-controls ">
323+ < a id ="raster-dl-png " href ="# " download ="text.png ">
324+ Download PNG < span class ="size-tag " id ="raster-png-size "> </ span >
325+ </ a >
326+ </ div >
322327 < p class ="raster-stats " id ="raster-stats "> </ p >
323328 </ section >
324329
Original file line number Diff line number Diff line change 373373 const rasterCanvas = document . getElementById ( "raster-canvas" ) ;
374374 const rasterCtx = rasterCanvas . getContext ( "2d" ) ;
375375 const rasterStats = document . getElementById ( "raster-stats" ) ;
376+ const rasterDl = document . getElementById ( "raster-dl-png" ) ;
377+ const rasterPngSize = document . getElementById ( "raster-png-size" ) ;
378+ let rasterPngUrl = null ;
376379 function renderRaster ( ) {
377380 withText ( ( textPtr ) => {
378381 const wPtr = Module . _malloc ( 4 ) ;
412415 w + " × " + h + " px"
413416 + " (" + ( w / dpr ) . toFixed ( 0 ) + " × " + ( h / dpr ) . toFixed ( 0 ) + " CSS px"
414417 + " · " + dpr + "× DPR)" ;
418+ /* Re-encode the canvas as PNG for the download link.
419+ * toBlob is async; the previous URL is revoked once the
420+ * new one lands so we don't leak. */
421+ rasterCanvas . toBlob ( ( blob ) => {
422+ if ( ! blob ) return ;
423+ if ( rasterPngUrl ) URL . revokeObjectURL ( rasterPngUrl ) ;
424+ rasterPngUrl = URL . createObjectURL ( blob ) ;
425+ rasterDl . href = rasterPngUrl ;
426+ rasterPngSize . textContent = fmtBytes ( blob . size ) ;
427+ } , "image/png" ) ;
415428 } ) ;
416429 }
417430
You can’t perform that action at this time.
0 commit comments