XSL:FO Fill fo:block with fo:leader

时间:2016-07-07 07:47:19

标签: xml xslt xsl-fo

我想用import java.util.*; import java.math.*; import java.text.*; public class CorrectChange { public static void main(String[] args) { Scanner input = new Scanner(System.in); BigDecimal AmtDue; BigDecimal AmtPaid; NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); //User enters the amount that the customer owes System.out.println("Enter the amount below that is due to be paid."); System.out.print("$"); AmtDue = input.nextBigDecimal(); //Converts user's input into the currency format AmtDue = AmtDue.setScale(2, BigDecimal.ROUND_HALF_UP); double dAmtDue = AmtDue.doubleValue(); String eAmtDue = n.format(dAmtDue); //User enters the amount that the customer paid System.out.println("Enter the amount below that has been paid."); System.out.print("$"); AmtPaid = input.nextBigDecimal(); //Converts user's input into the currency format AmtPaid = AmtPaid.setScale(2, BigDecimal.ROUND_HALF_UP); double dAmtPaid = AmtPaid.doubleValue(); String eAmtPaid = n.format(dAmtPaid); //Checks to see if the amount paid is more than the amount owed if (AmtDue.compareTo(AmtPaid)> 0){ double dBal = AmtDue.subtract(AmtPaid).doubleValue(); String eBal = n.format(dBal); System.out.println("You still owe: " + eBal.toString()); } //Checks to see if the amount owed is more than the amount paid if (AmtDue.compareTo(AmtPaid)< 0){ int cBal = (AmtPaid.compareTo(AmtDue)*100); double dBal = AmtPaid.subtract(AmtDue).doubleValue(); String eBal = n.format(dBal); int DolBills = (int) (dBal / 1); dBal = dBal % 1; int quarters = (int) (dBal / 25); dBal = dBal % 25; int dimes = (int) (cBal / 10); cBal = cBal % 10; int nickles = (int) (cBal / 5); cBal = cBal % 5; //pennies = (int) (dBal / 100); //dBal = dBal % 100; System.out.println("You owe a balance of " + eAmtDue.toString() + ". Since you paid the amount of " + eAmtPaid.toString() + " your change is " + eBal.toString()); System.out.println("Your change amount is as follows:\n" + "\t" + DolBills + " $1 dollar bills \n" + "\t" + quarters + " quarters \n" + "\t" + dimes + " dimes \n" + "\t" + nickles + " nickels \n"); "\t" + numPennies + " pennies"; } //Checks to see if the amount paid is equal to the amount owed if (AmtDue.compareTo(AmtPaid)== 0){ System.out.println("Your balance has been paid. Thank you for your business."); } } 填充我的块,然后用可变文本(长度)填充其余部分。

问题是如果文本的内容需要更多的空间,那么实际的列就有一个包含一个点线和一个文本行的换行符。

我使用的是Antenna House和XSLT 2.0。

现在输出示例:

1: | ................Text Text |
2: |...........................|
   |The Text is to long for the|

正确输出

|... This is some Text |
|    of the text....   |

XSLT代码:

<fo:leader leader-length.minium="1in"/ >

我希望这能使正确的输出清晰。

|.... 10,15,2010| Five dots minimum 
|______2105,1| (_ blank), output align right)

1 个答案:

答案 0 :(得分:2)

断线正在发生(AFAICT),因为AH Formatter无法适应最小领导者加上一行上的文本,然后当它分成两行时,领导者扩展到最佳长度4in。 / p>

要解决:

  1. axf:text-align-first="justify"添加到fo:block

    text-align-lasthttps://www.w3.org/TR/xsl11/#text-align-last)适用于(最后)块区域的最后一个行区域子项,即使它也是(仅)的第一个行区域块的区域。 axf:text-align-firsthttps://www.antennahouse.com/product/ahf63/ahf-ext.html#axf.text-align-first)的优先级高于text-align-last,因此axf:text-align-first="justify"证明了单行数据块的合理性。

  2. 删除leader-length.minimum

    现在,展开默认fo:leader值的leader-length以填充可用空间。

  3. (可选)将axf:leader-expansion="force"添加到fo:block

    axf:leader-expansionhttps://www.antennahouse.com/product/ahf63/ahf-ext.html#axf.leader-expansion)更有助于推动领导者扩张。

  4. 示例:

    <fo:block-container width="2in" border="thin solid black">
        <fo:block text-align="justify" text-align-last="right" axf:text-align-first="justify">
            <fo:leader leader-pattern="dots"/>This is text</fo:block>
        <fo:block text-align="justify" text-align-last="right" axf:text-align-first="justify">
            <fo:leader leader-pattern="dots"/>This is some of the text</fo:block>
        <fo:block text-align="justify" text-align-last="right" axf:text-align-first="justify">
            <fo:leader leader-pattern="dots"/>This is some of the text plus a bit more</fo:block>
        <fo:block text-align="justify" text-align-last="right" axf:text-align-first="justify">
            <fo:leader leader-pattern="dots"/>This is some of the text plus a whole lot more</fo:block>
    </fo:block-container>
    

    Screenshot of sample formatted.