metanorma / metanorma-jis

Metanorma for JIS
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

PDF: Add new vertical layout #226

Open Intelligent2013 opened 1 month ago

Intelligent2013 commented 1 month ago

In continue of https://github.com/metanorma/mn-native-pdf/issues/713.

As titled, based on the new JIS layout JIS_Template_traditional_blue_v2_traditional.pdf.

To do (draft list):

Known issues:

ronaldtse commented 1 month ago

Here's an updated file for reference:

use font NotoSansJP-Thin, NotoSerifJP-ExtraLight and Source Sans in the XSLT

I've used "Noto Serif JP" "Medium" to replace the Italic text, so we don't need Source Sans.

put cover page image into the back cover page

It's a mirrored front-back image of the front cover page. If possible allow using a separate front/back cover page.

Thanks!

Intelligent2013 commented 1 month ago

add new parameters :presentation-metadata-color-cover-page-background-1:, :presentation-metadata-color-cover-page-background-2: for vertical stripes (with opacity) on the cover page

The parameter :presentation-metadata-color-cover-page-background-1: for image

The parameter :presentation-metadata-color-cover-page-background-2: for image

Also we need two parameters for opacities:

Intelligent2013 commented 1 month ago

The footer contains the last on page clause title. First depth clause:

image

Intelligent2013 commented 1 month ago

@ronaldtse there are question about numbers in header/footer:

Examples:

Intelligent2013 commented 1 month ago

@ronaldtse could you check the fonts which are used on the cover page in the source Adobe Illustrator file. Adobe Acrobat shows Noto Serif Extra Light for all texts: image

but the rendered fonts looks so: image

I've tried to use Noto Serif JP Medium, but it looks different than in the source PDF(generated from AI): image

Also, Adobe Acrobat in the document properties shows 7 fonts Noto Serif Extra Light: image

Thanks.

ronaldtse commented 1 month ago

@Intelligent2013 I think this is because I’m using Noto Sans JP “Variable” that can realize all weights. It’s not Extra Light.

Intelligent2013 commented 1 month ago

Actually the fonts Noto Serif JP Medium, Noto Serif JP Bold and Noto Serif Black are using on the cover page text.

Intelligent2013 commented 4 weeks ago

Bad things found. Update in https://github.com/chunlinyao/fop has very limited vertical layout support! It doesn't support glyph rotation in the blocks inside fo:block-container and fo:table. From right to left: block, block-container, table. image The glyphs didn't rotated in 2 and 3 blue boxes.

XSL-FO:

<fo:block border="1pt solid blue" language="JA">
                「天の人を生ずるは億兆皆同一轍にて、之に附与するに動かす可からざるの通義を以てす。即ち其通義とは人の自から生命を保し自由を求め幸福を祈るの類にて、他より之を如何ともす可らざるものなり。」
                ――『アメリカ独立宣言』
            </fo:block>
<fo:block-container>
    <fo:block border="1pt solid blue" language="JA">
                「天の人を生ずるは億兆皆同一轍にて、之に附与するに動かす可からざるの通義を以てす。即ち其通義とは人の自から生命を保し自由を求め幸福を祈るの類にて、他より之を如何ともす可らざるものなり。」
                ――『アメリカ独立宣言』
            </fo:block>
</fo:block-container>
<fo:table width="100%" table-layout="fixed">
    <fo:table-body>
        <fo:table-row>
            <fo:table-cell>
                <fo:block border="1pt solid blue" language="JA">
                                                「天の人を生ずるは億兆皆同一轍にて、之に附与するに動かす可からざるの通義を以てす。即ち其通義とは人の自から生命を保し自由を求め幸福を祈るの類にて、他より之を如何ともす可らざるものなり。」
                                                ――『アメリカ独立宣言』
                                        </fo:block>
            </fo:table-cell>
        </fo:table-row>
    </fo:table-body>
</fo:table>
Intelligent2013 commented 4 weeks ago

Another issue in the vertical layout - 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

Intelligent2013 commented 4 weeks ago

@ronaldtse question about last page (not back page).

Is this a fixed text or it should be read from XML? It's user defined section or hard-coded boilerplate in metanorma gem?

image

Intelligent2013 commented 4 weeks ago

The error occurs on the full document:

Rendered page fontist/fontist#1.
Rendered page fontist/fontist#2.
Index: 2, Size: 2
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
        at java.util.ArrayList.rangeCheck(ArrayList.java:659)
        at java.util.ArrayList.get(ArrayList.java:435)
        at org.apache.fop.render.intermediate.IFStructureTreeBuilder.replayEventsForPageSequence(IFStructureTreeBuilder.java:192)
        at org.apache.fop.render.intermediate.IFSerializer.startPageSequence(IFSerializer.java:278)
        at org.apache.fop.render.intermediate.IFRenderer.startPageSequence(IFRenderer.java:526)
        at org.apache.fop.area.RenderPagesModel.checkPreparedPages(RenderPagesModel.java:172)
        at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:146)
        at org.apache.fop.layoutmgr.AbstractPageSequenceLayoutManager.finishPage(AbstractPageSequenceLayoutManager.java:316)
        at org.apache.fop.layoutmgr.PageSequenceLayoutManager.finishPage(PageSequenceLayoutManager.java:243)
        at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:147)
        at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:267)
        at org.apache.fop.fo.DelegatingFOEventHandler.endPageSequence(DelegatingFOEventHandler.java:114)
        at org.apache.fop.accessibility.fo.FO2StructureTreeConverter.endPageSequence(FO2StructureTreeConverter.java:184)
        at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:140)
        at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:390)
        at org.apache.fop.fo.FOTreeBuilder$3.run(FOTreeBuilder.java:207)
        at org.apache.fop.fo.FOTreeBuilder$3.run(FOTreeBuilder.java:204)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:203)
        at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1149)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:610)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1784)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2969)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:113)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:507)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:867)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:796)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1216)
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:519)
        at org.metanorma.fop.PDFGenerator.generateFOPIntermediateFormat(PDFGenerator.java:860)
        at org.metanorma.fop.PDFGenerator.runFOP(PDFGenerator.java:564)
        at org.metanorma.fop.PDFGenerator.convertmn2pdf(PDFGenerator.java:512)
        at org.metanorma.fop.PDFGenerator.process(PDFGenerator.java:326)
        at org.metanorma.fop.mn2pdf.main(mn2pdf.java:350)
Intelligent2013 commented 4 weeks ago

The error occurs due the block with mathml:

<UnitsML xmlns="https://schema.unitsml.org/unitsml/1.0">
            <UnitSet>
...
<math xmlns="http://www.w3.org/1998/Math/MathML">
    <mi mathvariant="normal">µF</mi>
</math>

mn2pdf can't process it, because the element math isn't in the text. I'll omit it in the preprocess phase.

Intelligent2013 commented 4 weeks ago

No, without Unitsml there is the error...

Intelligent2013 commented 4 weeks ago

The issue in fop-core\src\main\java\org\apache\fop\render\intermediate\IFStructureTreeBuilder.java

    public void replayEventsForPageSequence(ContentHandler handler,
            int pageSequenceIndex) throws SAXException {
            pageSequenceEventRecorders.get(pageSequenceIndex).replay(handler);
    }

The value pageSequenceIndex is great than pageSequenceEventRecorders size.

Intelligent2013 commented 4 weeks ago

I've applied very rough workaround solution:

        try {
            pageSequenceEventRecorders.get(pageSequenceIndex).replay(handler);
        } catch (IndexOutOfBoundsException ex) {
            System.out.println("Error on pageSequenceIndex=" + pageSequenceIndex);
            pageSequenceEventRecorders.get(pageSequenceEventRecorders.size() - 1).replay(handler);
        }

and PDF generated.

@ronaldtse here is first PDF for JIZ Z 8301: document_vertical.presentation.zip

The PDF doesn't contain the clause numbers in Japanese, because still I'm not able to generate XML on my machine.

Known issues:

Vertical layout introduced in https://github.com/chunlinyao/fop is non-production feature, and time consuming to finding workaround solution.

opoudjis commented 3 weeks ago

Removing support for Noto Fonts in JIS until Fontist is made to support them: https://github.com/fontist/formulas/issues/206

Intelligent2013 commented 3 weeks ago

Issue java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 occurs due the attribute role="artifact" in

<fo:static-content flow-name="left-region" role="artifact">
...
<fo:retrieve-marker retrieve-class-name="section_title"

fo:retrieve-marker and role="artifact" in one element occurs this error. Looks like it's a bug in Apache FOP. I'll add the ticket on Apache tracker.

ronaldtse commented 2 weeks ago

This is the latest example from @Intelligent2013 20241106 vertical jis example.pdf

Metanorma issues:

What is to be done in FOP:

Intelligent2013 commented 1 week ago

Metanorma issues:

  • clause numbers in Japanese

@opoudjis does the current version of metanorma-jis support the clause numbers in Japanese?

opoudjis commented 1 week ago

Yes, with :presentation-metadata-autonumbering-style: japanese

https://github.com/metanorma/metanorma.org/pull/832/commits/b905b8722205b74d5335444806dcd06e6ce1152d

Intelligent2013 commented 1 week ago

@opoudjis thanks!

Intelligent2013 commented 1 week ago

This is the latest PDF with clause numbers in Japanese: 20241110.vertical.jis.example.pdf

Intelligent2013 commented 1 week ago
  • rotation of text in examples
  • vertical line overflow for English

Fixed.

  • image/figure rotation

I've added the rotation for the image, but now the image breaks the page:

image

I'll try to find the workaround solution.

The latest PDF: 20241111.vertical.jis.example.pdf

Intelligent2013 commented 1 week ago

For the image rotation need:

Note: fox:transform="rotate(90)" (https://xmlgraphics.apache.org/fop/2.10/extensions.html#transform) is working for fo:block-container with position="absolute" only.

Intelligent2013 commented 1 week ago
  • image/figure rotation

    the image breaks the page:

The issue with page breaks fixed, but there are two issues with:

I'll need to fix it.

Latest PDF: 20241113.vertical.jis.example.pdf

Intelligent2013 commented 2 days ago

Image scaling issue in the vertical layout fixed.

Next issue - each reference sub-section starts in a new page: image

Intelligent2013 commented 2 days ago

Next issue - each reference sub-section starts in a new page:

Fixed.

Intelligent2013 commented 2 days ago

Latest PDF: 20241120.vertical.jis.example.pdf

Next issues: