Skip to content

Commit

Permalink
Merge pull request #209 from metanorma/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Intelligent2013 authored Jun 12, 2023
2 parents 163e719 + e608b79 commit 6d37980
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL ?= /bin/bash
endif

#JAR_VERSION := $(shell mvn -q -Dexec.executable="echo" -Dexec.args='$${project.version}' --non-recursive exec:exec -DforceStdout)
JAR_VERSION := 1.72
JAR_VERSION := 1.73
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.72</version>
<version>1.73</version>
<name>Metanorma XML to PDF converter</name>
----

Expand All @@ -111,8 +111,8 @@ Tag the same version in Git:

[source,xml]
----
git tag v1.72
git push origin v1.72
git tag v1.73
git push origin v1.73
----

Then the corresponding GitHub release will be automatically created at:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.72</version>
<version>1.73</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class PDFGenerator {
private boolean isAddMathAsText = false;

private boolean isAddLineNumbers = false;

private boolean isAddCommentaryPageNumbers = false;

private boolean isAddMathAsAttachment = false;

Expand Down Expand Up @@ -406,7 +408,10 @@ private void convertmn2pdf(fontConfig fontcfg, XSLTconverter xsltConverter, File

String add_line_numbers = Util.readValueFromXMLString(xmlFO, "/*[local-name() = 'root']/processing-instruction('add_line_numbers')");
isAddLineNumbers = add_line_numbers.equalsIgnoreCase("true");


String add_commentary_page_numbers = Util.readValueFromXMLString(xmlFO, "//*[@id = '_independent_page_number_commentary']/@id");
isAddCommentaryPageNumbers = !add_commentary_page_numbers.isEmpty();

debugSaveXML(xmlFO, pdf.getAbsolutePath() + ".fo.xml");

fontcfg.setSourceDocumentFontList(sourceXMLDocument.getDocumentFonts());
Expand Down Expand Up @@ -453,8 +458,10 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio
try {

String mime = MimeConstants.MIME_PDF;

if (isAddMathAsText || isAddAnnotations || isAddLineNumbers) {

boolean isPostprocessing = isAddMathAsText || isAddAnnotations || isAddLineNumbers || isAddCommentaryPageNumbers;

if (isPostprocessing) {
if (isAddMathAsText) {
logger.info("Adding Math as text...");
}
Expand All @@ -480,6 +487,16 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio

debugSaveXML(xmlIF, pdf.getAbsolutePath() + ".if.linenumbers.xml");
}

if (isAddCommentaryPageNumbers) {
logger.info("Updating Intermediate Format (adding commentary pages)...");
xmlIF = applyXSLT("add_commentary_page_numbers.xsl", xmlIF, true);

debugXSLFO = xmlIF;

debugSaveXML(xmlIF, pdf.getAbsolutePath() + ".if.commentarypagenumbers.xml");
}


src = new StreamSource(new StringReader(xmlIF));
}
Expand Down Expand Up @@ -516,7 +533,7 @@ private void runFOP (fontConfig fontcfg, Source src, File pdf) throws IOExceptio
out = new FileOutputStream(pdf);
out = new BufferedOutputStream(out);

if (isAddMathAsText || isAddAnnotations || isAddLineNumbers) { // process IF to PDF
if (isPostprocessing) { // process IF to PDF
//Setup target handler
IFDocumentHandler targetHandler = fopFactory.getRendererFactory().createDocumentHandler(
foUserAgent, mime);
Expand Down
28 changes: 28 additions & 0 deletions src/main/resources/add_commentary_page_numbers.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://xmlgraphics.apache.org/fop/intermediate"
xmlns:im="http://xmlgraphics.apache.org/fop/intermediate"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:foi="http://xmlgraphics.apache.org/fop/internal"
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:jeuclid="http://jeuclid.sf.net/ns/ext"
xmlns:java="http://xml.apache.org/xalan/java"
xmlns:math="http://exslt.org/math"
exclude-result-prefixes="im xalan fo fox math java"
version="1.0">

<xsl:output version="1.0" method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="im:text[preceding-sibling::*[1][self::im:id and @name = '_independent_page_number_commentary']]/text()">
<!-- set page number for commentary -->
<xsl:value-of select="count(ancestor::im:page/preceding-sibling::im:page[.//im:viewport[@region-type = 'Footer']/im:id[@name = '_independent_page_number_commentary']]) + 1"/>
</xsl:template>

</xsl:stylesheet>
2 changes: 1 addition & 1 deletion src/main/resources/pdf_fonts_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Relative config URLs are resolved relative to location of this file.
<renderers>
<renderer mime="application/pdf">
<pdf-ua-mode>PDF/UA-1</pdf-ua-mode>
<linearization>true</linearization>
<!-- <linearization>true</linearization> commented: see https://github.com/metanorma/mn2pdf/issues/204 -->
<version>1.7</version>
<filterList>
<!-- provides compression using zlib flate (default is on) -->
Expand Down

0 comments on commit 6d37980

Please sign in to comment.