From 3fae77951c902a9efb78ab7e8a7578a300d0b799 Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Wed, 24 Jan 2024 23:02:08 +0300 Subject: [PATCH 1/4] code refactoring, #235 --- Makefile | 2 +- README.adoc | 6 +++--- pom.xml | 2 +- .../java/org/metanorma/fop/fontConfig.java | 20 +++++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 3a07d5d..92910be 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README.adoc b/README.adoc index 8badc56..fa5fb01 100644 --- a/README.adoc +++ b/README.adoc @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.: ---- org.metanorma.fop mn2pdf -1.81 +1.82 Metanorma XML to PDF converter ---- @@ -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: diff --git a/pom.xml b/pom.xml index 9f65590..4427602 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.metanorma.fop mn2pdf - 1.81 + 1.82 Metanorma XML to PDF converter jar https://www.metanorma.org diff --git a/src/main/java/org/metanorma/fop/fontConfig.java b/src/main/java/org/metanorma/fop/fontConfig.java index 715ae9d..3fcac0a 100644 --- a/src/main/java/org/metanorma/fop/fontConfig.java +++ b/src/main/java/org/metanorma/fop/fontConfig.java @@ -198,17 +198,21 @@ public void setFontManifest(File fFontManifest) { //for(String fontPath : (List)fontEntry.getValue()) { for(String fontPath : (List)fontNamePathsEntries.get("paths")) { - String fontPath_ = Util.fixFontPath(fontPath); - if (new File(fontPath_).exists()) { + String fontPath__ = Util.fixFontPath(fontPath); + File fontFile = new File(fontPath__); - for (FOPFontTriplet fontVariant: fontVariants) { + if (!fontFile.exists()) { + + String fontPath_ = fontPath__; + + for (FOPFontTriplet fontVariant : fontVariants) { final String fontName = fontVariant.getName(); final String fontWeight = fontVariant.getWeight(); final String fontStyle = fontVariant.getStyle(); - + List fopFontsByNameWeightStyle = fopFonts.stream() .filter(fopFont -> !fopFont.isReadyToUse()) - .filter(fopFont -> fopFont.contains(fontName, fontWeight, fontStyle)) + .filter(fopFont -> fopFont.contains(fontName, fontWeight, fontStyle)) .collect(Collectors.toList()); if (fopFontsByNameWeightStyle.isEmpty()) { // create a new font entry in fopFonts array @@ -217,7 +221,7 @@ public void setFontManifest(File fFontManifest) { 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 fopFontTriplets = new ArrayList<>(); fopFontTriplets.add(fopFontTriplet); @@ -233,7 +237,7 @@ public void setFontManifest(File fFontManifest) { fopFonts.add(newFOPFont); - + // set embed-url path for fonts with simulate-style="true" and similar sub-font fopFonts.stream() .filter(f -> !f.isReadyToUse()) @@ -242,7 +246,7 @@ public void setFontManifest(File fFontManifest) { .forEach(f -> { f.setEmbed_url(fontPath_); }); - + } else { //if there is font in array if (DEBUG) { //System.out.println("Update font entry: " + fontName + " to " + fontPath_); From 1233a7b850cc99da7f2073ac68f8ad0a7ffc9311 Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Wed, 24 Jan 2024 23:06:24 +0300 Subject: [PATCH 2/4] updated for #235 --- .../java/org/metanorma/fop/fontConfig.java | 141 +++++++++--------- 1 file changed, 73 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/metanorma/fop/fontConfig.java b/src/main/java/org/metanorma/fop/fontConfig.java index 3fcac0a..c96cef5 100644 --- a/src/main/java/org/metanorma/fop/fontConfig.java +++ b/src/main/java/org/metanorma/fop/fontConfig.java @@ -198,90 +198,95 @@ public void setFontManifest(File fFontManifest) { //for(String fontPath : (List)fontEntry.getValue()) { for(String fontPath : (List)fontNamePathsEntries.get("paths")) { + if (fontPath.toLowerCase().contains("variablefont") || fontPath.toLowerCase().contains("wght")) { + logger.log(Level.WARNING, "WARNING: font path ''{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()) { - - String fontPath_ = fontPath__; - - for (FOPFontTriplet fontVariant : fontVariants) { - final String fontName = fontVariant.getName(); - final String fontWeight = fontVariant.getWeight(); - final String fontStyle = fontVariant.getStyle(); - - List 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 fopFontTriplets = new ArrayList<>(); - fopFontTriplets.add(fopFontTriplet); + logger.log(Level.WARNING, "WARNING: font path ''{0}'' from the 'fontist' manifest file doesn''t exist!", fontPath); + continue; + } - 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); + String fontPath_ = fontPath__; - fopFonts.add(newFOPFont); + for (FOPFontTriplet fontVariant : fontVariants) { + final String fontName = fontVariant.getName(); + final String fontWeight = fontVariant.getWeight(); + final String fontStyle = fontVariant.getStyle(); + List fopFontsByNameWeightStyle = fopFonts.stream() + .filter(fopFont -> !fopFont.isReadyToUse()) + .filter(fopFont -> fopFont.contains(fontName, fontWeight, fontStyle)) + .collect(Collectors.toList()); - // 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_); - }); + 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); - } 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 fopFontTriplets = new ArrayList<>(); + fopFontTriplets.add(fopFontTriplet); - //List 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)) + 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 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); } } } From c85c78bcb138ffe3fde591bb193dce12b3e46d9d Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Wed, 24 Jan 2024 23:08:06 +0300 Subject: [PATCH 3/4] updated for #235 --- src/main/java/org/metanorma/fop/fontConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/metanorma/fop/fontConfig.java b/src/main/java/org/metanorma/fop/fontConfig.java index c96cef5..2b261a8 100644 --- a/src/main/java/org/metanorma/fop/fontConfig.java +++ b/src/main/java/org/metanorma/fop/fontConfig.java @@ -199,7 +199,7 @@ public void setFontManifest(File fFontManifest) { for(String fontPath : (List)fontNamePathsEntries.get("paths")) { if (fontPath.toLowerCase().contains("variablefont") || fontPath.toLowerCase().contains("wght")) { - logger.log(Level.WARNING, "WARNING: font path ''{0}'' from the 'fontist' manifest file is the 'variable font' and doesn''t supported by Apache FOP!", fontPath); + 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; } From f916bb6957417907abf579ed5f3508b70e5019a4 Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Wed, 24 Jan 2024 23:14:54 +0300 Subject: [PATCH 4/4] ruby updated to 3.1, #235 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2dc468b..ddae3d2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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