metanorma / mn2pdf

Metanorma XML to PDF
3 stars 2 forks source link

Add page numbering in Japanese #304

Closed Intelligent2013 closed 2 days ago

Intelligent2013 commented 3 days ago

Source issue: https://github.com/metanorma/metanorma-jis/issues/226

Apache FOP site: https://xmlgraphics.apache.org/fop/2.9/complexscripts.html#source

The feature fox:number-conversion-features doesn't have any effect.

fop-core\src\main\java\org\apache\fop\fo\pagination\AbstractPageSequence.java

    public void startOfNode() throws FOPException {
        this.pageNumberGenerator = new PageNumberGenerator(
                format, groupingSeparator, groupingSize, letterValue,
                numberConversionFeatures, language, country);

fop-core\src\main\java\org\apache\fop\complexscripts\util\NumberConverter.java:

    private SpecialNumberFormatter getSpecialFormatter(int one, int letterValue, String features, String language, String country) {
        if (one == (int) 'I') {
            return new RomanNumeralsFormatter();
        } else if (one == (int) 'i') {
            return new RomanNumeralsFormatter();
        } else if (one == (int) '\u0391') {
            return new IsopsephryNumeralsFormatter();
        } else if (one == (int) '\u03B1') {
            return new IsopsephryNumeralsFormatter();
        } else if (one == (int) '\u05D0') {
            return new GematriaNumeralsFormatter();
        } else if (one == (int) '\u0623') {
            return new ArabicNumeralsFormatter();
        } else if (one == (int) '\u0627') {
            return new ArabicNumeralsFormatter();
        } else if (one == (int) '\u0E01') {
            return new ThaiNumeralsFormatter();
        } else if (one == (int) '\u3042') {
            return new KanaNumeralsFormatter();
        } else if (one == (int) '\u3044') {
            return new KanaNumeralsFormatter();
        } else if (one == (int) '\u30A2') {
            return new KanaNumeralsFormatter();
        } else if (one == (int) '\u30A4') {
            return new KanaNumeralsFormatter();
        } else {
            return null;
        }
    }
Intelligent2013 commented 3 days ago

For some reason, the attribute value doesn't pass into the method

    public void bind(PropertyList pList) throws FOPException {

in the class PageSequence.

In any case, Apache FOP doesn't support Japanese (Chinese) numbers:

    private static int[][] supportedSpecials = {
        { 'I' },                // latin - uppercase roman numerals
        { 'i' },                // latin - lowercase roman numerals
        { '\u0391' },           // greek - uppercase isopsephry numerals
        { '\u03B1' },           // greek - lowercase isopsephry numerals
        { '\u05D0' },           // hebrew - gematria numerals
        { '\u0623' },           // arabic - abjadi numberals
        { '\u0627' },           // arabic - either abjadi or hijai alphabetic sequence
        { '\u0E01' },           // thai - default alphabetic sequence
        { '\u3042' },           // kana - hiragana (gojuon) - default alphabetic sequence
        { '\u3044' },           // kana - hiragana (iroha)
        { '\u30A2' },           // kana - katakana (gojuon) - default alphabetic sequence
        { '\u30A4' },           // kana - katakana (iroha)

So, I have to add it.

Intelligent2013 commented 3 days ago

Proof-of-concept - the two-character page number without line breaks: image

Intelligent2013 commented 2 days ago

Done in mn2pdf v.2.06 (not released yet). To activate the page numbering in Japanese, add to to the element <fo:page-sequence:

<xsl:attribute name="format">&#x4E8C;</xsl:attribute>

New issues: the glyphs don't rotate in ToC (XSL-FO element fo:page-number-citation): image

and in the footer (XSL-FO element fo:page-number): image