-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PERFORMANCE] Improve FileSystemFontProvider.scanFonts() performance …
…by adding 'only headers' mode to TTF parser: * only read tables needed for FSFontInfo ('name', 'head', 'OS/2', 'CFF ', 'gcid') * 'CFF ' and 'head' table parsers finish as soon as it has all needed headers
- Loading branch information
Showing
9 changed files
with
500 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
fontbox/src/main/java/org/apache/fontbox/ttf/FontHeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.fontbox.ttf; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* To improve performance of {@code FileSystemFontProvider.scanFonts(...)}, | ||
* this class is used both as a marker (to skip unused data) and as a storage for collected data. | ||
* <p> | ||
* Tables it needs:<ul> | ||
* <li>NamingTable.TAG | ||
* <li>HeaderTable.TAG | ||
* <li>OS2WindowsMetricsTable.TAG | ||
* <li>CFFTable.TAG (for OTF) | ||
* <li>"gcid" (for non-OTF) | ||
* </ul> | ||
* | ||
* @author Mykola Bohdiuk | ||
*/ | ||
public final class FontHeaders | ||
{ | ||
static final int BYTES_GCID = 142; | ||
|
||
private IOException exception; | ||
private String name; | ||
private Integer headerMacStyle; | ||
private OS2WindowsMetricsTable os2Windows; | ||
private String fontFamily; | ||
private String fontSubFamily; | ||
private byte[] nonOtfGcid142; | ||
// | ||
private boolean isOTFAndPostScript; | ||
private String otfRegistry; | ||
private String otfOrdering; | ||
private int otfSupplement; | ||
|
||
public IOException getException() | ||
{ | ||
return exception; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
/** | ||
* null == no HeaderTable, {@code ttf.getHeader().getMacStyle()} | ||
*/ | ||
public Integer getHeaderMacStyle() | ||
{ | ||
return headerMacStyle; | ||
} | ||
|
||
public OS2WindowsMetricsTable getOS2Windows() | ||
{ | ||
return os2Windows; | ||
} | ||
|
||
// only when LOGGER(FileSystemFontProvider).isTraceEnabled() tracing: FontFamily, FontSubfamily | ||
public String getFontFamily() | ||
{ | ||
return fontFamily; | ||
} | ||
|
||
public String getFontSubFamily() | ||
{ | ||
return fontSubFamily; | ||
} | ||
|
||
public boolean isOpenTypePostScript() | ||
{ | ||
return isOTFAndPostScript; | ||
} | ||
|
||
public byte[] getNonOtfTableGCID142() | ||
{ | ||
return nonOtfGcid142; | ||
} | ||
|
||
public String getOtfRegistry() | ||
{ | ||
return otfRegistry; | ||
} | ||
|
||
public String getOtfOrdering() | ||
{ | ||
return otfOrdering; | ||
} | ||
|
||
public int getOtfSupplement() | ||
{ | ||
return otfSupplement; | ||
} | ||
|
||
void setException(IOException exception) | ||
{ | ||
this.exception = exception; | ||
} | ||
|
||
void setName(String name) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
void setHeaderMacStyle(Integer headerMacStyle) | ||
{ | ||
this.headerMacStyle = headerMacStyle; | ||
} | ||
|
||
void setOs2Windows(OS2WindowsMetricsTable os2Windows) | ||
{ | ||
this.os2Windows = os2Windows; | ||
} | ||
|
||
void setFontFamily(String fontFamily, String fontSubFamily) | ||
{ | ||
this.fontFamily = fontFamily; | ||
this.fontSubFamily = fontSubFamily; | ||
} | ||
|
||
void setNonOtfGcid142(byte[] nonOtfGcid142) | ||
{ | ||
this.nonOtfGcid142 = nonOtfGcid142; | ||
} | ||
|
||
void setIsOTFAndPostScript(boolean isOTFAndPostScript) | ||
{ | ||
this.isOTFAndPostScript = isOTFAndPostScript; | ||
} | ||
|
||
// public because CFFParser is in a different package | ||
public void setOtfROS(String otfRegistry, String otfOrdering, int otfSupplement) | ||
{ | ||
this.otfRegistry = otfRegistry; | ||
this.otfOrdering = otfOrdering; | ||
this.otfSupplement = otfSupplement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.