Skip to content

Commit

Permalink
Merge branch 'main' into update_fop_2_9
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 authored Mar 27, 2024
2 parents 28397e3 + 4295027 commit 27f67bb
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 77 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,13 @@ private void convertmn2pdf(fontConfig fontcfg, XSLTconverter xsltConverter, File
basepath = xsltParams.getProperty("baseassetpath") + File.separator;
}
additionalXSLTparams.setProperty("basepath", basepath);


File fInputXML = new File(inputXMLFilePath);
String fInputXMLParent = fInputXML.getAbsoluteFile().getParent() + File.separator;

additionalXSLTparams.setProperty("inputxml_basepath", fInputXMLParent);
additionalXSLTparams.setProperty("inputxml_filename", fInputXML.getName());

xsltConverter.setParams(additionalXSLTparams);

setTablesWidths(fontcfg, xsltConverter, pdf);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/metanorma/fop/SourceXMLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public List<String> getDocumentFonts() {
attrText = attrText.substring(0, attrText.indexOf(";"));
}
for (String fname: attrText.split(",")) {
fname = fname.trim().replace("'","");
fname = fname.trim().replace("'","")
.replace("\"","");
if (!documentFontList.contains(fname)) {
documentFontList.add(fname);
}
Expand Down
155 changes: 82 additions & 73 deletions src/main/java/org/metanorma/fop/fontConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,86 +198,95 @@ public void setFontManifest(File fFontManifest) {
//for(String fontPath : (List<String>)fontEntry.getValue()) {
for(String fontPath : (List<String>)fontNamePathsEntries.get("paths")) {

String fontPath_ = Util.fixFontPath(fontPath);
if (new File(fontPath_).exists()) {

for (FOPFontTriplet fontVariant: fontVariants) {
final String fontName = fontVariant.getName();
final String fontWeight = fontVariant.getWeight();
final String fontStyle = fontVariant.getStyle();

List<FOPFont> fopFontsByNameWeightStyle = fopFonts.stream()
.filter(fopFont -> !fopFont.isReadyToUse())
.filter(fopFont -> fopFont.contains(fontName, fontWeight, fontStyle))
.collect(Collectors.toList());

if (fopFontsByNameWeightStyle.isEmpty()) { // create a new font entry in fopFonts array
if (DEBUG) {
//System.out.println("Create a new font entry: " + fontPath_ + " (" + fontName + " " + fontWeight + " " + fontStyle + ")");
fontManifestLog.append("Create a new font entry: " + fontPath_ + " (" + fontName + ", font-weight='" + fontWeight + "', font-style='" + fontStyle + "')").append("\n");
}
FOPFontTriplet fopFontTriplet = new FOPFontTriplet(fontName, fontWeight, fontStyle);

List<FOPFontTriplet> fopFontTriplets = new ArrayList<>();
fopFontTriplets.add(fopFontTriplet);

FOPFont newFOPFont = new FOPFont();
newFOPFont.setEmbed_url(fontPath_);
if (fontPath_.toLowerCase().endsWith(".ttc")) {
//newFOPFont.setSub_font(fontName);
newFOPFont.setSub_font(fontFullName);
}
newFOPFont.setReadyToUse(true);
newFOPFont.setSource("manifest");
newFOPFont.setFont_triplet(fopFontTriplets);

fopFonts.add(newFOPFont);


// set embed-url path for fonts with simulate-style="true" and similar sub-font
fopFonts.stream()
.filter(f -> !f.isReadyToUse())
.filter(f -> f.getSimulate_style() != null && f.getSimulate_style().equals("true"))
.filter(f -> f.getSub_font() != null && fontFullName.toLowerCase().equals(f.getSub_font().toLowerCase()))
.forEach(f -> {
f.setEmbed_url(fontPath_);
});

} else { //if there is font in array
if (DEBUG) {
//System.out.println("Update font entry: " + fontName + " to " + fontPath_);
fontManifestLog.append("Update font entry: " + fontName + " to " + fontPath_).append("\n");
}
fopFontsByNameWeightStyle.stream()
.forEach(f -> {
f.setEmbed_url(fontPath_);
f.setReadyToUse(true);
f.setSource("manifest");
});

// change sub-font for ttc fonts
if (fontPath_.toLowerCase().endsWith(".ttc")) {
fopFontsByNameWeightStyle.stream()
//.filter(f -> !fontPath_.toLowerCase().contains(f.getEmbed_url().toLowerCase())) // in case if file names in embed-url and in manifest file are different
//.forEach(f -> f.setSub_font(fontName));
.forEach(f -> f.setSub_font(fontFullName));
}
if (fontPath.toLowerCase().contains("variablefont") || fontPath.toLowerCase().contains("wght")) {
logger.log(Level.WARNING, "WARNING: font ''{0}'' from the 'fontist' manifest file is the 'variable font' and doesn''t supported by Apache FOP!", fontPath);
continue;
}

String fontPath__ = Util.fixFontPath(fontPath);
File fontFile = new File(fontPath__);

if (!fontFile.exists()) {
logger.log(Level.WARNING, "WARNING: font path ''{0}'' from the 'fontist' manifest file doesn''t exist!", fontPath);
continue;
}

//List<FOPFont> fopFontsWithSimulateStyleByName
// set embed-url path for fonts with simulate-style="true" and similar font filename
fopFonts.stream()
.filter(f -> !f.isReadyToUse())
.filter(f -> f.getSimulate_style() != null && f.getSimulate_style().equals("true"))
.filter(f -> fontPath_.toLowerCase().contains(f.getEmbed_url().toLowerCase()))
.filter(f -> f.contains(fontName))
String fontPath_ = fontPath__;

for (FOPFontTriplet fontVariant : fontVariants) {
final String fontName = fontVariant.getName();
final String fontWeight = fontVariant.getWeight();
final String fontStyle = fontVariant.getStyle();

List<FOPFont> fopFontsByNameWeightStyle = fopFonts.stream()
.filter(fopFont -> !fopFont.isReadyToUse())
.filter(fopFont -> fopFont.contains(fontName, fontWeight, fontStyle))
.collect(Collectors.toList());

if (fopFontsByNameWeightStyle.isEmpty()) { // create a new font entry in fopFonts array
if (DEBUG) {
//System.out.println("Create a new font entry: " + fontPath_ + " (" + fontName + " " + fontWeight + " " + fontStyle + ")");
fontManifestLog.append("Create a new font entry: " + fontPath_ + " (" + fontName + ", font-weight='" + fontWeight + "', font-style='" + fontStyle + "')").append("\n");
}
FOPFontTriplet fopFontTriplet = new FOPFontTriplet(fontName, fontWeight, fontStyle);

List<FOPFontTriplet> fopFontTriplets = new ArrayList<>();
fopFontTriplets.add(fopFontTriplet);

FOPFont newFOPFont = new FOPFont();
newFOPFont.setEmbed_url(fontPath_);
if (fontPath_.toLowerCase().endsWith(".ttc")) {
//newFOPFont.setSub_font(fontName);
newFOPFont.setSub_font(fontFullName);
}
newFOPFont.setReadyToUse(true);
newFOPFont.setSource("manifest");
newFOPFont.setFont_triplet(fopFontTriplets);

fopFonts.add(newFOPFont);


// set embed-url path for fonts with simulate-style="true" and similar sub-font
fopFonts.stream()
.filter(f -> !f.isReadyToUse())
.filter(f -> f.getSimulate_style() != null && f.getSimulate_style().equals("true"))
.filter(f -> f.getSub_font() != null && fontFullName.toLowerCase().equals(f.getSub_font().toLowerCase()))
.forEach(f -> {
f.setEmbed_url(fontPath_);
});

} else { //if there is font in array
if (DEBUG) {
//System.out.println("Update font entry: " + fontName + " to " + fontPath_);
fontManifestLog.append("Update font entry: " + fontName + " to " + fontPath_).append("\n");
}
fopFontsByNameWeightStyle.stream()
.forEach(f -> {
f.setEmbed_url(fontPath_);
f.setReadyToUse(true);
f.setSource("manifest");
});

// change sub-font for ttc fonts
if (fontPath_.toLowerCase().endsWith(".ttc")) {
fopFontsByNameWeightStyle.stream()
//.filter(f -> !fontPath_.toLowerCase().contains(f.getEmbed_url().toLowerCase())) // in case if file names in embed-url and in manifest file are different
//.forEach(f -> f.setSub_font(fontName));
.forEach(f -> f.setSub_font(fontFullName));
}

//List<FOPFont> fopFontsWithSimulateStyleByName
// set embed-url path for fonts with simulate-style="true" and similar font filename
fopFonts.stream()
.filter(f -> !f.isReadyToUse())
.filter(f -> f.getSimulate_style() != null && f.getSimulate_style().equals("true"))
.filter(f -> fontPath_.toLowerCase().contains(f.getEmbed_url().toLowerCase()))
.filter(f -> f.contains(fontName))
.forEach(f -> {
f.setEmbed_url(fontPath_);
f.setReadyToUse(true);
});
}
} else {
logger.log(Level.WARNING, "WARNING: font path ''{0}'' from the 'fontist' manifest file doesn''t exist!", fontPath);
}
}
}
Expand Down
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 @@ -209,7 +209,7 @@ Relative config URLs are resolved relative to location of this file.
<font kerning="yes" embed-url="SourceSansPro-Light.ttf"> <!-- mn_default="true" -->
<font-triplet name="Source Sans Pro" style="normal" weight="300"/>
</font>
<font kerning="yes" embed-url="SourceSansPro-LightIt.ttf" mn_default="true"> <!-- mn_default="true" -->
<font kerning="yes" embed-url="SourceSansPro-LightIt.ttf"> <!-- mn_default="true" -->
<font-triplet name="Source Sans Pro" style="italic" weight="300"/>
</font>

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/table_if.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</xsl:variable>


<xsl:variable name="table_id" select="concat($table_if_prefix, $id, '_')"/>
<xsl:variable name="table_id" select="concat($table_if_prefix, $id, '@')"/>

<xsl:variable name="cells_">
<!-- <xsl:for-each select="//if:id[starts-with(@name, $table_id)][1]"> --> <!-- select only first in 'g', no need select 'id' ends with '_end' -->
Expand Down

0 comments on commit 27f67bb

Please sign in to comment.