How to restore spacing in <codeblock> when using <fo:bidi-override> with DITA OT and FOP

136 Views Asked by At

For our PDF user guides, we use <codeblock> for code and XML samples and type spaces for indenting. These turn out fine in left-to-right languages, and the spaces indent the text as expected. But in Arabic, the spaces are stripped out when the text is aligned against the right (start) side in the PDF. Also, the closing bracket of the last line is misplaced.

Here is the <codeblock> as appears in our source DITA file:

<codeblock>&lt;ExpressAccess&gt;
                  &lt;Class&gt;ExpressAccess&lt;/Class&gt;
                  &lt;Version&gt;1&lt;/Version&gt;
                  &lt;Members&gt;
                              &lt;DisableAllAdmin&gt;0&lt;/DisableAllAdmin&gt;
                  &lt;/Members&gt;
     &lt;/ExpressAccess&gt;</codeblock> 

And this is the XSLT we use to render it:

<fo:block xsl:use-attribute-sets="pre">            
  <xsl:call-template name="commonattributes"/>
  <xsl:call-template name="setFrame"/>
  <xsl:call-template name="setScale"/>
  <xsl:call-template name="setExpanse"/>
            
  <fo:bidi-override direction="ltr" unicode-bidi="bidi-override">
    <xsl:apply-templates/>
  </fo:bidi-override>
</fo:block>

Here is the output in a left-to-right language:

Text is properly indented by spaces

But in Arabic, the output looks like this:

Spaces are stripped out and the final bracket is misplaced.

Here is the resulting FO code for both cases:

<fo:block background-color="#D9D9D6" font-size="9pt" line-height="106%" linefeed-treatment="preserve" space-after="0.6em" space-before="0.6em" text-align="start" white-space-collapse="false" white-space-treatment="preserve" wrap-option="wrap" line-height-shift-adjustment="disregard-shifts" font-family="Courier New"><fo:bidi-override direction="ltr" unicode-bidi="bidi-override">&lt;ExpressAccess&gt;
                  &lt;Class&gt;ExpressAccess&lt;/Class&gt;
                  &lt;Version&gt;1&lt;/Version&gt;
                  &lt;Members&gt;
                              &lt;DisableAllAdmin&gt;0&lt;/DisableAllAdmin&gt;
                  &lt;/Members&gt;
     &lt;/ExpressAccess&gt;</fo:bidi-override></fo:block>

This was generated with DITA OT 3.6.1 with the accompanying FOP 2.5. Any help is appreciated. Thank you.

UPDATE: I gave the fix Kevin Brown provided a try. When I added text-align="left" to the block, the codeblock was aligned to the left with the spaces and indents preserved. But the last line still had the problem with the misplaced closing bracket (< </ExpressAccess). When I added text-align-last="left", it shoved the whole code back to the right and removed the space. (Setting text-align-last to "preserve" didn't break the code, but didn't fix misplaced closing bracket.) If I type any character after that closing bracket, it is formed correctly. Any suggestions?

1

There are 1 best solutions below

0
Kevin Brown On

I believe you have text-align and text-align-last set at a higher level which is causing the code block to be right aligned. I did this:

            <fo:flow flow-name="xsl-region-body" direction="rtl" font-family="Arial" text-align="right" text-align-last="right">
            <fo:block>سيقوم أخصائي التخدير (طبيب مؤهل في التخدير) بإجراء التخدير فوق الجافية لك. وفي العادة، يُعاون أخصائي التخدير طبيب ممارس من فريق الرعاية الصحية ومؤهل بشكل خاص.</fo:block>                 
            <fo:block background-color="#D9D9D6" font-size="9pt" line-height="106%" linefeed-treatment="preserve" space-after="0.6em" space-before="0.6em" text-align="left" text-align-last="left" white-space-collapse="false" white-space-treatment="preserve" wrap-option="wrap" line-height-shift-adjustment="disregard-shifts" font-family="Courier New">
                <fo:bidi-override direction="ltr" unicode-bidi="bidi-override">
&lt;ExpressAccess&gt;
     &lt;Class&gt;ExpressAccess&lt;/Class&gt;
     &lt;Version&gt;1&lt;/Version&gt;
     &lt;Members&gt;
          &lt;DisableAllAdmin&gt;0&lt;/DisableAllAdmin&gt;
     &lt;/Members&gt;
&lt;/ExpressAccess&gt;
                </fo:bidi-override>
            </fo:block>
        </fo:flow>

Which yields this result:

enter image description here