You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2015/07/10 10:14:46 UTC
svn commit: r1690220 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
Author: jahewson
Date: Fri Jul 10 08:14:46 2015
New Revision: 1690220
URL: http://svn.apache.org/r1690220
Log:
PDFBOX-2842: Skip unnecessary call to getNaming()
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java?rev=1690220&r1=1690219&r2=1690220&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java Fri Jul 10 08:14:46 2015
@@ -284,96 +284,83 @@ final class FileSystemFontProvider exten
{
try
{
- // check for 'name' table
- NamingTable nameTable = null;
-
- // ttf could still be null
- if (ttf != null)
+ // read PostScript name, if any
+ if (ttf.getName() != null)
{
- // todo: this is a performance bottleneck, we don't actually need to read this table
- nameTable = ttf.getNaming();
- }
+ int sFamilyClass = -1;
+ int usWeightClass = -1;
+ int ulCodePageRange1 = 0;
+ int ulCodePageRange2 = 0;
+ byte[] panose = null;
+
+ // Apple's AAT fonts don't have an OS/2 table
+ if (ttf.getOS2Windows() != null)
+ {
+ sFamilyClass = ttf.getOS2Windows().getFamilyClass();
+ usWeightClass = ttf.getOS2Windows().getWeightClass();
+ ulCodePageRange1 = (int)ttf.getOS2Windows().getCodePageRange1();
+ ulCodePageRange2 = (int)ttf.getOS2Windows().getCodePageRange2();
+ panose = ttf.getOS2Windows().getPanose();
+ }
- if (nameTable == null)
- {
- LOG.warn("Missing 'name' table in font " + file);
- }
- else
- {
- // read PostScript name, if any
- if (ttf.getName() != null)
+ // ignore bitmap fonts
+ if (ttf.getHeader() == null)
{
- int sFamilyClass = -1;
- int usWeightClass = -1;
- int ulCodePageRange1 = 0;
- int ulCodePageRange2 = 0;
- byte[] panose = null;
-
- // Apple's AAT fonts don't have an OS/2 table
- if (ttf.getOS2Windows() != null)
+ return;
+ }
+ int macStyle = ttf.getHeader().getMacStyle();
+
+ String format;
+ if (ttf instanceof OpenTypeFont && ((OpenTypeFont)ttf).isPostScript())
+ {
+ format = "OTF";
+ CFFFont cff = ((OpenTypeFont)ttf).getCFF().getFont();
+ PDCIDSystemInfo ros = null;
+ if (cff instanceof CFFCIDFont)
{
- sFamilyClass = ttf.getOS2Windows().getFamilyClass();
- usWeightClass = ttf.getOS2Windows().getWeightClass();
- ulCodePageRange1 = (int)ttf.getOS2Windows().getCodePageRange1();
- ulCodePageRange2 = (int)ttf.getOS2Windows().getCodePageRange2();
- panose = ttf.getOS2Windows().getPanose();
+ CFFCIDFont cidFont = (CFFCIDFont)cff;
+ String registry = cidFont.getRegistry();
+ String ordering = cidFont.getOrdering();
+ int supplement = cidFont.getSupplement();
+ ros = new PDCIDSystemInfo(registry, ordering, supplement);
}
-
- // ignore bitmap fonts
- if (ttf.getHeader() == null)
+ fontInfoList.add(new FSFontInfo(file, FontFormat.OTF, ttf.getName(), ros,
+ usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2,
+ macStyle, panose));
+ }
+ else
+ {
+ PDCIDSystemInfo ros = null;
+ if (ttf.getTableMap().containsKey("gcid"))
{
- return;
+ // Apple's AAT fonts have a "gcid" table with CID info
+ byte[] bytes = ttf.getTableBytes(ttf.getTableMap().get("gcid"));
+ String registryName = new String(bytes, 10, 64, Charsets.US_ASCII).trim();
+ String orderName = new String(bytes, 76, 64, Charsets.US_ASCII).trim();
+ int supplementVersion = bytes[140] << 8 & bytes[141];
+ ros = new PDCIDSystemInfo(registryName, orderName, supplementVersion);
}
- int macStyle = ttf.getHeader().getMacStyle();
- String format;
- if (ttf instanceof OpenTypeFont && ((OpenTypeFont)ttf).isPostScript())
- {
- format = "OTF";
- CFFFont cff = ((OpenTypeFont)ttf).getCFF().getFont();
- PDCIDSystemInfo ros = null;
- if (cff instanceof CFFCIDFont)
- {
- CFFCIDFont cidFont = (CFFCIDFont)cff;
- String registry = cidFont.getRegistry();
- String ordering = cidFont.getOrdering();
- int supplement = cidFont.getSupplement();
- ros = new PDCIDSystemInfo(registry, ordering, supplement);
- }
- fontInfoList.add(new FSFontInfo(file, FontFormat.OTF, ttf.getName(), ros,
- usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2,
- macStyle, panose));
- }
- else
- {
- PDCIDSystemInfo ros = null;
- if (ttf.getTableMap().containsKey("gcid"))
- {
- // Apple's AAT fonts have a "gcid" table with CID info
- byte[] bytes = ttf.getTableBytes(ttf.getTableMap().get("gcid"));
- String registryName = new String(bytes, 10, 64, Charsets.US_ASCII).trim();
- String orderName = new String(bytes, 76, 64, Charsets.US_ASCII).trim();
- int supplementVersion = bytes[140] << 8 & bytes[141];
- ros = new PDCIDSystemInfo(registryName, orderName, supplementVersion);
- }
-
- format = "TTF";
- fontInfoList.add(new FSFontInfo(file, FontFormat.TTF, ttf.getName(), ros,
- usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2,
- macStyle, panose));
- }
+ format = "TTF";
+ fontInfoList.add(new FSFontInfo(file, FontFormat.TTF, ttf.getName(), ros,
+ usWeightClass, sFamilyClass, ulCodePageRange1, ulCodePageRange2,
+ macStyle, panose));
+ }
- if (LOG.isTraceEnabled())
+ if (LOG.isTraceEnabled())
+ {
+ NamingTable name = ttf.getNaming();
+ if (name != null)
{
- LOG.trace(format +": '" + ttf.getName() + "' / '" +
- nameTable.getFontFamily() + "' / '" +
- nameTable.getFontSubFamily() + "'");
+ LOG.trace(format +": '" + name.getPostScriptName() + "' / '" +
+ name.getFontFamily() + "' / '" +
+ name.getFontSubFamily() + "'");
}
}
- else
- {
- LOG.warn("Missing 'name' entry for PostScript name in font " + file);
- }
+ }
+ else
+ {
+ LOG.warn("Missing 'name' entry for PostScript name in font " + file);
}
}
catch (IOException e)