这是我的FOP:
<fo:block background-color="blue">
<fo:instream-foreign-object background-color="yellow" content-width="0.8cm" content-height="0.3cm" scaling="non-uniform" vertical-align="middle">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" viewBox="0 0 200 100">
<g>
<path d="m 0 0 l 200 0 l -50 100 l -150 0 z"/>
<text x="140" y="80"
style="font-family: Times New Roman;
font-size: 80px;
text-align:end;
text-anchor:end;
fill: white;">12</text>
</g>
</svg>
</fo:instream-foreign-object>
</fo:block>
使用appache FOP版本2进行渲染:
为什么SVG没有填充父块?
答案 0 :(得分:1)
content-width="0.8cm" content-height="0.3cm" scaling="non-uniform"
迫使图像宽0.8厘米,高0.3厘米。
如果要填充宽度,请将其更改为content-width="scale-to-fit" width="100%"
:
<fo:block background-color="blue" font-size="0">
<fo:instream-foreign-object background-color="yellow" content-width="scale-to-fit" width="100%">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" viewBox="0 0 200 100">
<g>
<path d="m 0 0 l 200 0 l -50 100 l -150 0 z"/>
<text x="140" y="80"
style="font-family: Times New Roman;
font-size: 80px;
text-align:end;
text-anchor:end;
fill: white;">12</text>
</g>
</svg>
</fo:instream-foreign-object>
</fo:block>