Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to avoid java.net.URISyntaxException under Windows to load fonts #519

Open
wants to merge 1 commit into
base: VERSION_11_4_8
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,15 @@ public PhysicalFont extract(String fontNameAsInTablePart, String fontFileName, S
// Save the result
setF(new File(getTmpFontDir(), filenamePrefix + "-"+fontFileName +".ttf"));
getF().deleteOnExit();
String path = null;

java.io.FileOutputStream fos = null;
try {
path = getF().getCanonicalPath();
fos = new java.io.FileOutputStream(getF());
fos.write(fontData);
log.debug("wrote: " + fontData.length);
fos.close();
} catch (IOException e) {
log.error("Problem with " + path);
log.error("Problem with " + this.getF());
log.error(e.getMessage(), e);
}

Expand All @@ -160,15 +158,15 @@ public PhysicalFont extract(String fontNameAsInTablePart, String fontFileName, S
if (log.isDebugEnabled()) {
CustomFont customFont = null;
try {
log.debug("Loading from: " + path);
log.debug("Loading from: " + this.getF());
String subFontName = null; // TODO set this if its a TTC
boolean embedded = true;
boolean useKerning = true;
boolean useAdvanced = false;
boolean simulateStyle = false;
boolean embedAsType1 = false;

FontUris fontUris = new FontUris(new URI("file:" + path.replace(" ", "%20")), null);
FontUris fontUris = new FontUris(this.getF().toURI(), null);

customFont = FontLoader.loadFont(fontUris,
subFontName, embedded, EmbeddingMode.AUTO, EncodingMode.AUTO,
Expand All @@ -190,20 +188,12 @@ public PhysicalFont extract(String fontNameAsInTablePart, String fontFileName, S
}

// Get this font as a PhysicalFont object; do NOT add it to physical fonts (since those are available to all documents)
try {
List<PhysicalFont> fonts = PhysicalFonts.getPhysicalFont(fontNameAsInTablePart,
new URI("file:" + path.replace(" ", "%20")));
return (fonts == null || fonts.isEmpty()) ? null : fonts.iterator().next();
List<PhysicalFont> fonts = PhysicalFonts.getPhysicalFont(fontNameAsInTablePart, this.getF().toURI());
return (fonts == null || fonts.isEmpty()) ? null : fonts.iterator().next();

// This needs to be done before populateFontMappings,
// otherwise this font will be ignored, and references
// to it mapped to some substitute font!

} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
// This needs to be done before populateFontMappings,
// otherwise this font will be ignored, and references
// to it mapped to some substitute font!

}

Expand Down