2016-04-23 11 views
0

AH Formatterで生成されたPDFで、文字列の長さが14文字の後で強制的に改行したい。だから、これは改行のいかなる試みもせずに私のXSLコードです:文字列の長さの後に強制改行

<xsl:attribute-set name="big" use-attribute-sets="bold"> 
    <xsl:attribute name="font-size">38pt</xsl:attribute> 
    <xsl:attribute name="line-height">28.84pt</xsl:attribute> 
    <xsl:attribute name="text-align">center</xsl:attribute> 
    <xsl:attribute name="letter-spacing">1mm</xsl:attribute> 
</xsl:attribute-set> 

<xsl:attribute-set name="small" use-attribute-sets="bold"> 
    <xsl:attribute name="font-size">27pt</xsl:attribute> 
    <xsl:attribute name="line-height">27pt</xsl:attribute> 
    <xsl:attribute name="text-align">center</xsl:attribute> 
    <xsl:attribute name="letter-spacing">1mm</xsl:attribute> 
</xsl:attribute-set> 

<xsl:choose> 
    <xsl:when test="string-length($count_cover)>=14"> 
     <fo:block xsl:use-attribute-sets="small"> 
     <xsl:apply-templates/> 
     </fo:block> 
    </xsl:when> 
    <xsl:otherwise>   
     <fo:block xsl:use-attribute-sets="big"> 
     <xsl:apply-templates/> 
     </fo:block> 
    </xsl:otherwise> 
</xsl:choose> 

は、それはXSL-FOで改行を強制することは可能ですか?

答えて

1

タイトルを文字列に変換できる場合は、改行として<fo:block/>を挿入できます。

<xsl:variable name="cover_title" as="xs:string" select="'Very Long Cover Title! Very Long Cover Title! Very Long Cover Title! '"/> 
<xsl:variable name="count_cover" as="xs:integer" select="string-length($cover_title)"/> 
<xsl:variable name="lf_position" as="xs:integer" select="14"/> 

<xsl:template match="/"> 
    <xsl:choose> 
     <xsl:when test="$count_cover gt $lf_position"> 
      <fo:block xsl:use-attribute-sets="small"> 
       <xsl:analyze-string select="$cover_title" regex=".{{1}}"> 
        <xsl:matching-substring> 
         <xsl:value-of select="."/> 
         <xsl:if test="position() eq $lf_position"> 
          <fo:block/> 
         </xsl:if> 
        </xsl:matching-substring> 
        <xsl:non-matching-substring/> 
       </xsl:analyze-string> 
      </fo:block> 
     </xsl:when> 
     <xsl:otherwise> 
      <fo:block xsl:use-attribute-sets="big"> 
       <xsl:value-of select="$cover_title"/> 
      </fo:block> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

結果:

<fo:block font-weight="bold" font-size="27pt" line-height="27pt" text-align="center" letter-spacing="1mm">Very Long Cove<fo:block/>r Title! Very Long Cover Title! Very Long Cover Title! </fo:block> 

しかし、この方法では、単語の境界とハイフネーションのコントロールを無視します。ブックカバータイトルを作成する場合は、fo:block-containerを使用してAH Formatter拡張機能を導入する方がよいでしょう。

  1. 表紙の固定位置とサイズでタイトルにfo:block-containerを使用します。
  2. 設定するプロパティ@オーバーフロー= @axfと「凝縮」:オーバーフローコンデンス=」フォントサイズを」FOインサイド https://www.antennahouse.com/product/ahf60/docs/ahf-ext.html#axf.overflow-condense
  3. :ブロック・コンテナ、場所FO:タイトルの内容を保存するブロック
  4. AHフォーマッタは自動的にコンテンツの量に応じてフォント・サイズを調整するので、あなたが希望する結果を得ることができる。

[例]

<fo:block-container position="absolute" top="..." left="..." width="..." height="..." overflow="condense" axf:overflow-condense="font-size" font-size="27pt" text-align="center"> 
    <fo:block> 
     <fo:inline>Very Long Cover Title! Very Long Cover Title! Very Long Cover Title!</fo:inline> 
    </fo:block> 
</fo:block-container> 
0

FOで改行を強制することはできませんが、文字列を別々のFOブロックに分割できます。

<xsl:choose> 
    <xsl:when test="string-length($count_cover) &gt;= 14"> 
    <fo:block><xsl:value-of select="substring($count_cover, 1, 13)"/></fo:block> 
    <fo:block><xsl:value-of select="substring($count_cover, 14)"/></fo:block> 
    </when> 
    <xsl:otherwise> 
    <fo:block> 
     <xsl:value-of select="$count_cover"/> 
    </fo:block> 
    </xsl:otherwise> 
</xsl:choose> 
1
  1. ハイフネーションを有効にすると、固定数の文字を分割するよりも良い結果が得られます(部品番号などではなく)。

  2. linefeed-treatment="preserve"を使用し、fo:blockの代わりに&#xA;を挿入すると、この回答はInserting a line break in a PDF generated from XSL FO using <xsl:value-of>となります。あなたはどちら<xsl:value-of select="replace(., '(.{14})', '$1&#xA;')" />

  3. で行うことができますが、代わりに、すべての14文字の後、&#x200B;、ゼロ幅スペースを挿入し、ゼロ幅スペース上のAH Formatterのブレークをさせることができます。

    <xsl:template match="text()"> <xsl:value-of select="replace(replace(., '(\P{Zs}{14})', '$1&#x200B;'), '&#x200B;(\p{Zs})', '$1')" /> </xsl:template>

    インナーreplace()は14文字の空白文字の後に文字を挿入し、1530文字が空白文字の場合はreplace()の外側に修正します。

    比例幅のフォントを使用している場合は、14文字(14桁の一定幅のライニング番号を除く)のシーケンスの幅が他の幅よりも多かれ少なかれであるため、より多くの文字の間に&#x200B; AH Formatterが破損する前にその行を埋めるために最善を尽くすことができます。

  4. axf:word-break="break-all"を使用すると、単語内でも改行を有効にすることができます。 https://www.antennahouse.com/product/ahf63/ahf-ext.html#axf.word-break
関連する問題