Skip to content

Commit

Permalink
Merge pull request #236 from metanorma/issue/235
Browse files Browse the repository at this point in the history
Issue/235
  • Loading branch information
Intelligent2013 authored Jan 24, 2024
2 parents cb19302 + f916bb6 commit d470533
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.1

- if: matrix.os == 'ubuntu-latest'
run: sudo gem install fontist
Expand Down
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.81
JAR_VERSION := 1.82
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.81</version>
<version>1.82</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.81
git push origin v1.81
git tag v1.82
git push origin v1.82
----

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.81</version>
<version>1.82</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
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

0 comments on commit d470533

Please sign in to comment.