英文:
Is it possible to export a font as base64 using xslt?
问题
Sure, here is the translation of the text you provided:
我想从 .fo
文件创建一些 HTML 输出,并编写了一些 XSL 模板来获得所需的输出。对于 HTML 元素的样式,每个元素都有一个具有匹配的 CSS 类的 class
属性。
看起来像这样:
.page_2_text_3 {
transform: translate(0pt, 82.96pt);
font-family: ITCFranklinGothicStd-Book;
font-style: normal;
font-weight: 400;
font-variant: normal;
font-size: 10pt;
color: #000000;
}
问题在于字体 ITCFranklinGothicStd-Book
找不到,被其他字体替代了。
是否有办法在模板中将字体导出为 base64,以便我可以像这样在我的 CSS 中添加 @font-face
:
<xsl:template name="fontexport">
<xsl:param name="font"/>
<xsl:param name="fontname"/>
@font-face {
font-family: "<xsl:value-of select="$fontname"/>";
src: url("<xsl:value-of select="$font" mode="base64"/>")<!-- 将 $font 转换为 base64 -->
}
</xsl:template>
当调用带有字体和字体名称作为参数的 call-template
时,应该创建以下输出:
@font-face {
font-family: "ITCFranklinGothicStd-Book";
src: url("data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAB...)
}
是否有可能以某种方式实现这个目标?
英文:
I want to create some html output from .fo
file and I wrote myself some xsl templates to get the desired output.
For the styling of the html
-elements, each element has a class
attribute with the matching css
-class.
That looks like the following:
.page_2_text_3 {
transform: translate(0pt, 82.96pt);
font-family: ITCFranklinGothicStd-Book;
font-style: normal;
font-weight: 400;
font-variant: normal;
font-size: 10pt;
color: #000000;
}
The problem here is that the font ITCFranklinGothicStd-Book
can't be found and is substituted by some other font.
Is there any way to export the font as base64 in a template, so i can add a @font-face
to my css like so:
<xsl:template name="fontexport">
<xsl:param name="font"/>
<xsl:param name="fontname"/>
@font-face {
font-family: "<xsl:value-of select="$fontname"/>";
src: url("<xsl:value-of select="$font" mode="base64"/>")<!-- convert the $font into base64 -->
}
</xsl:template>
this should create the following output when calling call-template
with font and fontname as parameter
@font-face {
font-family: "ITCFranklinGothicStd-Book";
src: url("data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAB...)
}
Is that possible somehow?
答案1
得分: 2
如果您切换到支持EXPath文件模块的XSLT处理器,比如Saxon-PE,那么您可以使用file:read-binary()
来读取字体文件,它会返回一个xs:base64Binary
值,对这个值应用string()
函数会给您Base64表示。
英文:
If you move to an XSLT processor that supports the EXPath file module, such as Saxon-PE, then you can read the font file using file:read-binary()
, which returns an xs:base64Binary
value, and the string()
function applied to this value gives you the Base64 representation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论