Skip to content

Commit

Permalink
Fix OS-292: Support UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaister committed Jul 28, 2016
1 parent 005a866 commit a6791c5
Show file tree
Hide file tree
Showing 21 changed files with 316 additions and 132 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ dependencies {
compile group: 'mrj', name: 'MRJ141Stubs', version:'0'
compile group: 'net.sf.squirrel-sql.thirdparty-non-maven', name: 'skinlf', version:'6.7'
compile group: 'org.apache.xmlgraphics', name: 'fop', version:'2.1'
compile group: 'org.apache.pdfbox', name: 'pdfbox', version:'1.8.9'
compile group: 'jep', name: 'jep', version:'2.4.1'
compile group: 'org.freemarker', name: 'freemarker', version:'2.3.23'
compile group: 'org.jdom', name: 'jdom', version:'1.1.3'
Expand Down
80 changes: 63 additions & 17 deletions code/src/java/pcgen/util/fop/FopTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopConfParser;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.events.Event;
import org.apache.fop.events.EventFormatter;
import org.apache.fop.events.EventListener;
import org.apache.fop.events.model.EventSeverity;
import org.apache.fop.render.Renderer;

import pcgen.cdom.base.Constants;
Expand All @@ -64,33 +69,35 @@ public class FopTask implements Runnable

private static FopFactory createFopFactory()
{
FopConfParser parser;
FopFactoryBuilder builder;

// Allow optional customization with configuration file
String configPath = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fop.xconf";
Logging.log(Logging.INFO, "Checking for config file at " + configPath);
Logging.log(Logging.INFO, "FoPTask checking for config file at " + configPath);
File userConfigFile = new File(configPath);
try
if (userConfigFile.exists())
{
if (userConfigFile.exists())
Logging.log(Logging.INFO, "FoPTask using config file " + configPath);
try
{
Logging.log(Logging.INFO, "FoPTask using config file " + configPath);
builder = new FopFactoryBuilder(userConfigFile.toURI());
parser = new FopConfParser(userConfigFile);
}
else
catch (Exception e)
{
Logging.log(Logging.INFO, "FoPTask using default config");
builder = new FopFactoryBuilder(new File(".").toURI());
}
builder.setStrictFOValidation(false);
return builder.build();
Logging.errorPrint("FoPTask encountered a problem with FOP configuration "
+ configPath + ": ", e);
return null;
}
builder = parser.getFopFactoryBuilder();
}
catch (Exception e)
else
{
Logging.errorPrint("Problem with FOP configuration "
+ configPath + ": ", e);
return null;
}
Logging.log(Logging.INFO, "FoPTask using default config");
builder = new FopFactoryBuilder(new File(".").toURI());
builder.setStrictFOValidation(false);
}
return builder.build();
}

private final StreamSource inputSource;
Expand Down Expand Up @@ -180,6 +187,8 @@ public void run()
userAgent.setProducer("PC Gen Character Generator");
userAgent.setAuthor(System.getProperty("user.name"));
userAgent.setCreationDate(new Date());

userAgent.getEventBroadcaster().addEventListener(new FOPEventListener());

String mimeType;
if (renderer != null)
Expand Down Expand Up @@ -296,5 +305,42 @@ private String getLocation(SourceLocator locator)
}

}


public static class FOPEventListener implements EventListener
{
/**
* @{inheritdoc}
*/
@Override
public void processEvent(Event event)
{
String msg = "[FOP] " + EventFormatter.format(event);

// filter out some erroneous FOP warnings about not finding internal fonts
// this is an ancient, but still unfixed FOP bug
// see https://issues.apache.org/jira/browse/FOP-1667
if (msg.contains("not found") && (msg.contains("Symbol,normal") || msg.contains("ZapfDingbats,normal")))
{
return;
}

EventSeverity severity = event.getSeverity();
if (severity == EventSeverity.INFO)
{
Logging.log(Logging.INFO, msg);
}
else if (severity == EventSeverity.WARN)
{
Logging.log(Logging.WARNING, msg);
}
else if (severity == EventSeverity.ERROR || severity == EventSeverity.FATAL)
{
Logging.log(Logging.ERROR, msg);
}
else
{
assert false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<!--> <xsl:if test="string-length(translate(normalize-space(concat(description,bio)), ' ', '')) &gt; 0"> -->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="8pt">
<fo:block font-size="14pt" break-before="page" span="all">
Expand Down Expand Up @@ -239,6 +240,7 @@
<!-- BEGIN CHARACTER NOTES Pages -->
<xsl:if test="count(.//note) &gt; 0">
<fo:page-sequence master-reference="Portrait 2 Column">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="8pt">
<fo:block font-size="14pt" font-weight="bold" space-after.optimum="2mm" break-before="page" span="all">
Expand Down Expand Up @@ -269,6 +271,7 @@
<!-- BEGIN Armor table -->
<xsl:if test="count(campaign_history) &gt; 0">
<fo:page-sequence master-reference="Portrait">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="attrib">
<xsl:with-param name="attribute" select="'ac'"/>
</xsl:call-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<xsl:if test="count(.//spell) &gt; 0">
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="8pt">
<xsl:apply-templates select="spells_innate/racial_innate"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</fo:layout-master-set>

<fo:page-sequence master-reference="Portrait">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select=".//spell" mode="spell.card">
<xsl:sort select="name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</fo:layout-master-set>

<fo:page-sequence master-reference="Portrait">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select=".//spell" mode="spell.card">
<xsl:sort select="name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</fo:layout-master-set>

<fo:page-sequence master-reference="Landscape">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select=".//spell" mode="spell.card">
<xsl:sort select="name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</fo:layout-master-set>

<fo:page-sequence master-reference="Landscape">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select=".//spell" mode="spell.card.block">
<xsl:sort select="name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
====================================
====================================-->
<xsl:template name="page.footer.content">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:table table-layout="fixed">
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of select="0.25 * $pagePrintableWidth" />mm</xsl:attribute>
Expand All @@ -219,7 +220,7 @@
<fo:block font-size="12pt">Player: <fo:inline font-weight="bold"><xsl:value-of select="/character/basics/playername"/></fo:inline></fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" wrap-option="no-wrap" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
<fo:block text-align="center" font-size="12pt">PCGen Character Template by Frugal, based on work by ROG, Arcady, Barak, Dimrill, Dekker &amp; Andrew Maitland (LegacyKing).</fo:block>
<fo:block text-align="center" font-size="12pt">PCGen Character Template by Andrew Maitland (LegacyKing) and Stefan Radermacher (Zaister), based on work by Frugal, ROG, Arcady, Barak, Dimrill, &amp; Dekker.</fo:block>
<fo:block text-align="center" font-size="12pt">Created using <fo:basic-link external-destination="http://pcgen.org/" show-destination="true" color="blue" text-decoration="underline">PCGen</fo:basic-link> <xsl:value-of select="/character/export/version"/> on <xsl:value-of select="/character/export/date"/><xsl:text> at </xsl:text><xsl:value-of select="/character/export/time"/></fo:block>
</fo:table-cell>
<fo:table-cell text-align="end" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
Expand Down Expand Up @@ -251,6 +252,7 @@
-->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<!-- CHARACTER BODY STARTS HERE !!! -->
<fo:flow flow-name="body" font-size="12pt">
Expand Down Expand Up @@ -335,6 +337,7 @@
-->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait 2 Column</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="12pt">
<fo:block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
====================================
====================================-->
<xsl:template name="page.footer.content">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:table table-layout="fixed" width="100%">
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of select="0.25 * $pagePrintableWidth" />mm</xsl:attribute>
Expand All @@ -239,7 +240,7 @@
<fo:block font-size="5pt">Player: <fo:inline font-weight="bold"><xsl:value-of select="/character/basics/playername"/></fo:inline></fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" wrap-option="no-wrap" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Frugal, based on work by ROG, Arcady, Barak, Dimrill, Dekker &amp; Andrew Maitland (LegacyKing).</fo:block>
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Andrew Maitland (LegacyKing) and Stefan Radermacher (Zaister), based on work by Frugal, ROG, Arcady, Barak, Dimrill, &amp; Dekker.</fo:block>
<fo:block text-align="center" font-size="5pt">Created using <fo:basic-link external-destination="http://pcgen.org/" color="blue" text-decoration="underline">PCGen</fo:basic-link> v<xsl:value-of select="/character/export/version"/> on <xsl:value-of select="/character/export/date"/><xsl:text> at </xsl:text><xsl:value-of select="/character/export/time"/></fo:block>
</fo:table-cell>
<fo:table-cell text-align="end" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
Expand Down Expand Up @@ -271,6 +272,7 @@
-->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<!-- CHARACTER BODY STARTS HERE !!! -->
<fo:flow flow-name="body" font-size="8pt">
Expand Down Expand Up @@ -359,6 +361,7 @@
<fo:page-sequence>

<xsl:attribute name="master-reference">Portrait 2 Column</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="8pt">
<fo:block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
====================================
====================================-->
<xsl:template name="page.footer.content">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:table table-layout="fixed">
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of select="0.25 * $pagePrintableWidth" />mm</xsl:attribute>
Expand All @@ -239,7 +240,7 @@
<fo:block font-size="5pt">Player: <fo:inline font-weight="bold"><xsl:value-of select="/character/basics/playername"/></fo:inline></fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" wrap-option="no-wrap" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Frugal, based on work by ROG, Arcady, Barak, Dimrill, Dekker &amp; Andrew Maitland (LegacyKing).</fo:block>
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Andrew Maitland (LegacyKing) and Stefan Radermacher (Zaister), based on work by Frugal, ROG, Arcady, Barak, Dimrill, &amp; Dekker.</fo:block>
<fo:block text-align="center" font-size="5pt">Created using <fo:basic-link external-destination="http://pcgen.org/" color="blue" text-decoration="underline">PCGen</fo:basic-link> v<xsl:value-of select="/character/export/version"/> on <xsl:value-of select="/character/export/date"/><xsl:text> at </xsl:text><xsl:value-of select="/character/export/time"/></fo:block>
</fo:table-cell>
<fo:table-cell text-align="end" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
Expand Down Expand Up @@ -271,6 +272,7 @@
-->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<!-- CHARACTER BODY STARTS HERE !!! -->
<fo:flow flow-name="body" font-size="8pt">
Expand Down Expand Up @@ -359,6 +361,7 @@
<fo:page-sequence>

<xsl:attribute name="master-reference">Portrait 2 Column</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="8pt">
<fo:block>
Expand Down
5 changes: 4 additions & 1 deletion outputsheets/d20/fantasy/pdf/fantasy_master_no_header.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
====================================
====================================-->
<xsl:template name="page.footer.content">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:table table-layout="fixed">
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of select="0.25 * $pagePrintableWidth" />mm</xsl:attribute>
Expand All @@ -239,7 +240,7 @@
<fo:block font-size="5pt">Player: <fo:inline font-weight="bold"><xsl:value-of select="/character/basics/playername"/></fo:inline></fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" wrap-option="no-wrap" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Frugal, based on work by ROG, Arcady, Barak, Dimrill, Dekker &amp; Andrew Maitland (LegacyKing).</fo:block>
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Andrew Maitland (LegacyKing) and Stefan Radermacher (Zaister), based on work by Frugal, ROG, Arcady, Barak, Dimrill, &amp; Dekker.</fo:block>
<fo:block text-align="center" font-size="5pt">Created using <fo:basic-link external-destination="http://pcgen.org/" color="blue" text-decoration="underline">PCGen</fo:basic-link> v<xsl:value-of select="/character/export/version"/> on <xsl:value-of select="/character/export/date"/><xsl:text> at </xsl:text><xsl:value-of select="/character/export/time"/></fo:block>
</fo:table-cell>
<fo:table-cell text-align="end" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
Expand Down Expand Up @@ -271,6 +272,7 @@
-->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<!-- CHARACTER BODY STARTS HERE !!! -->
<fo:flow flow-name="body" font-size="8pt">
Expand Down Expand Up @@ -357,6 +359,7 @@
<fo:page-sequence>

<xsl:attribute name="master-reference">Portrait 2 Column</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<fo:flow flow-name="body" font-size="8pt">
<fo:block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
====================================
====================================-->
<xsl:template name="page.footer.content">
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<fo:table table-layout="fixed">
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of select="0.25 * $pagePrintableWidth" />mm</xsl:attribute>
Expand All @@ -239,7 +240,7 @@
<fo:block font-size="5pt">Player: <fo:inline font-weight="bold"><xsl:value-of select="/character/basics/playername"/></fo:inline></fo:block>
</fo:table-cell>
<fo:table-cell text-align="center" wrap-option="no-wrap" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Frugal, based on work by ROG, Arcady, Barak, Dimrill, Dekker &amp; Andrew Maitland (LegacyKing).</fo:block>
<fo:block text-align="center" font-size="5pt">PCGen Character Template by Andrew Maitland (LegacyKing) and Stefan Radermacher (Zaister), based on work by Frugal, ROG, Arcady, Barak, Dimrill, &amp; Dekker.</fo:block>
<fo:block text-align="center" font-size="5pt">Created using <fo:basic-link external-destination="http://pcgen.org/" color="blue" text-decoration="underline">PCGen</fo:basic-link> v<xsl:value-of select="/character/export/version"/> on <xsl:value-of select="/character/export/date"/><xsl:text> at </xsl:text><xsl:value-of select="/character/export/time"/></fo:block>
</fo:table-cell>
<fo:table-cell text-align="end" border-top-color="black" border-top-style="solid" border-top-width="0.1pt" background-color="transparent" padding-top="2pt">
Expand Down Expand Up @@ -269,6 +270,7 @@
-->
<fo:page-sequence>
<xsl:attribute name="master-reference">Portrait</xsl:attribute>
<xsl:attribute name="font-family">NotoSans</xsl:attribute>
<xsl:call-template name="page.footer"/>
<!-- CHARACTER BODY STARTS HERE !!! -->
<fo:flow flow-name="body" font-size="8pt">
Expand Down
Loading

0 comments on commit a6791c5

Please sign in to comment.