2017-08-26 176 views
2

我試圖對齊SVG圖像旁邊的文本插入XSL然後用於創建pdf。將文本垂直對齊xsl中的SVG旁邊的文本

這是我的文本和SVG設置:

<fo:block font-size="14pt" text-align="center" margin-top="2cm"> 
    <fo:instream-foreign-object> 
     <svg:svg width="30" height="30" xml:space="preserve"> 
      <svg:g style="fill:none; stroke:black; stroke-width:1"> 
       <svg:rect x="0" y="0" width="30" height="30"/> 
      </svg:g> 
     </svg:svg> 
    </fo:instream-foreign-object> 

    Mark If Closed 
</fo:block> 

這是輸出:

enter image description here

我想要的文字「標記是否關閉」可垂直於與方形SVG中間。

回答

1

如果廣場的大小是恆定的,你可以玩基線移位。如果SVG高度爲30,字體大小爲14pt,則大約5pt的基線偏移就可以實現。

  <fo:block font-size="14pt" text-align="center" background-color="silver"> 
      <fo:instream-foreign-object> 
       <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="30" height="30" xml:space="preserve"> 
         <svg:g style="fill:none; stroke:black; stroke-width:1"> 
          <svg:rect x="0" y="0" width="30" height="30"/> 
         </svg:g> 
       </svg:svg> 
      </fo:instream-foreign-object><fo:inline background-color="yellow" baseline-shift="5pt">Mark If Closed</fo:inline></fo:block> 

此息率(顏色增加了清晰度):

enter image description here

+0

非常感謝!我無法在網上找到很多信息。這使得伎倆。 – nullwriter

1

讓格式化做出來......

請格式化做數學題(假設line-height(見https://www.w3.org/TR/xsl11/#line-height)是'1.2'):

<fo:block font-size="14pt" text-align="center" margin-top="2pt" 
    background-color="silver"> 
    <fo:instream-foreign-object baseline-shift="-((30pt - 1em * 1.2) div 2)"> 
     <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="30" height="30" xml:space="preserve"> 
    <svg:g style="fill:none; stroke:black; stroke-width:1"> 
     <svg:rect x="0" y="0" width="30" height="30" /> 
    </svg:g> 
</svg:svg> 
    </fo:instream-foreign-object> 
    <fo:inline background-color="yellow">Mark If Closed</fo:inline> 
</fo:block> 

移動箱下降了50%:

<fo:block font-size="14pt" text-align="center" margin-top="2pt" 
    background-color="silver"> 
    <fo:instream-foreign-object baseline-shift="-50%"> 
     <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="30" height="30" xml:space="preserve"> 
      <svg:g style="fill:none; stroke:black; stroke-width:1"> 
       <svg:rect x="0" y="0" width="30" height="30" /> 
      </svg:g> 
     </svg:svg> 
    </fo:instream-foreign-object> 
    <fo:inline background-color="yellow">Mark If Closed</fo:inline> 
</fo:block> 

使用alignment-baselinefo:instream-foreign-object(見https://www.w3.org/TR/xsl11/#alignment-baseline):

<fo:block font-size="14pt" text-align="center" margin-top="2pt" 
    background-color="silver"> 
    <fo:instream-foreign-object alignment-baseline="middle"> 
     <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="30" height="30" xml:space="preserve"> 
    <svg:g style="fill:none; stroke:black; stroke-width:1"> 
     <svg:rect x="0" y="0" width="30" height="30" /> 
    </svg:g> 
</svg:svg> 
    </fo:instream-foreign-object> 
    <fo:inline background-color="yellow">Mark If Closed</fo:inline> 
</fo:block> 

Screenshot from formatting examples

+0

僅供參考,如果發佈人使用他設置爲標籤的FOP,則只有第三個選項有效。你的例子沒有確定地使用FOP。 –