Skip to content

Commit

Permalink
using default fonts for render fonts from svg, #177
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Jul 15, 2023
1 parent 324f234 commit 4aa9860
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/main/java/org/metanorma/fop/fontConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class fontConfig {

static final String ENV_FONT_PATH = "MN_PDF_FONT_PATH";
static final String WARNING_FONT = "WARNING: Font file '%s' (font name '%s', font style '%s', font weight '%s') doesn't exist. Replaced by '%s'.";
static final String WARNING_FONT_NO_FILE = "WARNING: Font '%s' (font name '%s', font style '%s', font weight '%s') doesn't exist. Replaced by '%s'.";
private final String CONFIG_NAME = "pdf_fonts_config.xml";
private final String CONFIG_NAME_UPDATED = CONFIG_NAME + ".out";

Expand All @@ -92,6 +93,8 @@ class fontConfig {

private static List<String> registeredFonts = new ArrayList<>();

//private String mainFont = "";

private boolean isReady = false;

//private final List<String> defaultFontList = new DefaultFonts().getDefaultFonts();
Expand Down Expand Up @@ -439,9 +442,9 @@ public void setSourceDocumentFontList(List<String> sourceDocumentFontList) {

this.sourceDocumentFontList = sourceDocumentFontList;

if (!sourceDocumentFontList.isEmpty()) {
/*if (!sourceDocumentFontList.isEmpty()) {
this.mainFont = sourceDocumentFontList.get(0);
}
}*/

isReady = false;

Expand All @@ -450,7 +453,37 @@ public void setSourceDocumentFontList(List<String> sourceDocumentFontList) {
.filter(fopFont -> !fopFont.getFont_triplet().isEmpty())
.filter(fopFont -> fopFont.getName().equals(sourceDocumentFont))
.forEach(fopFont -> fopFont.setIsUsing(true));


// if font isn't exist in FOP fonts config, then add it
if (fopFonts.stream()
.filter(fopFont -> fopFont.getName().equals(sourceDocumentFont))
.count() == 0) {

String fontWeight = "normal";
String fontStyle = "normal";
if (sourceDocumentFont.contains("Bold")) {
fontWeight="bold";
}
if (sourceDocumentFont.contains("Italic")) {
fontStyle="italic";
}
List<FOPFontTriplet> fopFontTriplets = new ArrayList<>();
fopFontTriplets.add(new FOPFontTriplet(sourceDocumentFont, fontWeight, fontStyle));
if (fontWeight.equals("normal") && fontStyle.equals("normal")) {
// add 3 fonts: bold, italic and bold+italic
fopFontTriplets.add(new FOPFontTriplet(sourceDocumentFont, "bold", "normal"));
fopFontTriplets.add(new FOPFontTriplet(sourceDocumentFont, "normal", "italic"));
fopFontTriplets.add(new FOPFontTriplet(sourceDocumentFont, "bold", "italic"));
}
for (FOPFontTriplet fopFontTriplet: fopFontTriplets) {
FOPFont fopFont = new FOPFont();
fopFont.setEmbed_url("filenotfound_" + sourceDocumentFont + ".ttf");
fopFont.setIsUsing(true);
fopFont.setFont_triplet(Arrays.asList(fopFontTriplet));
fopFonts.add(fopFont);
}
}

/* for (FOPFont fopFont: fopFonts) {
if(!fopFont.getFont_triplet().isEmpty() &&
fopFont.getFont_triplet().get(0).getName().equals(sourceDocumentFont)) {
Expand Down Expand Up @@ -640,7 +673,11 @@ private void setFontsPaths() throws IOException, URISyntaxException {

//printMessage(msg + " (font style '" + fontstyle + "', font weight '" + fontweight + "') doesn't exist. Replaced by '" + font_replacementpath + "'.");
//printMessage(String.format(WARNING_FONT, embed_url, fopFontTriplet.getStyle(), fopFontTriplet.getWeight(), font_replacementpath));
fopFont.setMessage(String.format(WARNING_FONT, embed_url, fopFontTriplet.getName(), fopFontTriplet.getStyle(), fopFontTriplet.getWeight(), font_replacementpath));
if (embed_url.contains("filenotfound_")) {
fopFont.setMessage(String.format(WARNING_FONT_NO_FILE, fopFontTriplet.getName(), fopFontTriplet.getName(), fopFontTriplet.getStyle(), fopFontTriplet.getWeight(), font_replacementpath));
} else {
fopFont.setMessage(String.format(WARNING_FONT, embed_url, fopFontTriplet.getName(), fopFontTriplet.getStyle(), fopFontTriplet.getWeight(), font_replacementpath));
}

/*try{
font_replacementpath = new File(font_replacementpath).toURI().toURL().toString();
Expand Down

0 comments on commit 4aa9860

Please sign in to comment.