javascript - Font is not applied on image -



javascript - Font is not applied on image -

i trying convert svg png using d3.js , html5. when image displayed, custom font applied on it, when save image png, font not applied on image. below code

css

@font-face { font-family: "calligraffitti"; font-style: normal; font-weight: 400; src: local("calligraffitti"), local("calligraffitti-regular"), url("http://fonts.gstatic.com/s/calligraffitti/v7/vlvn2y-z65rvu1r7lwdvykizaudcntpcwupsair0ie8.woff") format("woff"); }

js

$('.savepng').click(function() { savesvgaspng(document.getelementbyid("treet"), "tree2.png", 3); out.savesvgaspng = function(el, name, scalefactor) { out.svgasdatauri(el, scalefactor, function(uri) { var image = new image(); image.src = uri; image.onload = function() { var canvas = document.createelement('canvas'); canvas.width = image.width; canvas.height = image.height; var context = canvas.getcontext('2d'); context.drawimage(image, 0, 0); var = document.createelement('a'); a.download = name; a.id = "download_link"; a.href = canvas.todataurl('image/png'); document.body.appendchild(a); a.click(); } }); }

in file did set css posted? if in html, or referenced html file, out of luck, because css not apply across document boundaries. not impact separate svg file.

in theory set css in svg file. work except fact loading svg <img> (image()). due security restrictions in browser, svgs loaded <img> must self-contained. cannot reference external objects (such font files).

the solution embed css in svg file and utilize datauri reference font.

<defs> <style type="text/css"><![cdata[ @font-face { font-family: "calligraffitti"; font-style: normal; font-weight: 400; src: local("calligraffitti"), local("calligraffitti-regular"), url("data:application/font-woff;base64,...font.file.encoded.as.base64...") format("woff"); } ]]></style> </defs>

i believe should work.

javascript html css svg d3.js

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -