gpt4 book ai didi

javascript - base64图像中的嵌入字体

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:15 24 4
gpt4 key购买 nike

我给了一个带有一些自定义字体的 svg(通过 css 的字体嵌入)在浏览器中它工作正常,但如果我尝试从 SVG 制作 base64 编码图像,字体将无法识别。

enter image description here

这是我的代码:

CSS

    svg,text, textPath{
font-family: 'MyFont';
}

@font-face
{
font-family: MyFont;
src: src: url(data:application/x-font-ttf;base64,AAEAAAAQA...);
}

JS 我正在使用 RaphaelJS

//set the text's font
t.attr({"font-family": "MyFont"})

//make the snapshot
var source = new Image();
$("body").append(source);
$('body').click(function(){

// record start time
var startTime = new Date();

var svg = $('#paper').html();

var mySrc = 'data:image/svg+xml;base64,'+Base64.encode(svg);

//source.src = base64Path + "?" + mySrc.slice(5);
source.src = mySrc;

var endTime = new Date();

console.log(endTime - startTime);


});

最佳答案

您必须将样式表嵌入 SVG 本身,或从外部引用它。如果 SVG 自行呈现,则不会应用通用页面样式表。

查看 the reference on SVG styling获取更多信息。

关于javascript - base64图像中的嵌入字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19453526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com