/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Adobe Technical Note 5040 details the format of PFB files.
* the file is divided into ascii and binary sections. Each section
* starts with a header
* 0x8001 - start of binary data, is followed by 4 bytes length, then data
* 0x8002 - start of ascii data, is followed by 4 bytes length, then data
* 0x8003 - end of data segment
* The length is organised as LSB->MSB.
*
* Note: I experimented with using a MappedByteBuffer and
* 1. If a global buffer is used rather than one allocated in the calling
* context, then we need to synchronize on all uses of that data, which
* means more code would beed to be synchronized with probable repercussions
* elsewhere.
* 2. It is not clear whether to free the buffer when the file is closed.
* If we have the contents in memory then why keep open files around?
* The mmapped buffer doesn't need it.
* Also regular GC is what frees the buffer. So closing the file and nulling
* out the reference still needs to wait for the buffer to be GC'd to
* reclaim the storage.
* If the contents of the buffer are persistent there's no need
* to worry about synchronization.
* Perhaps could use a WeakReference, and when its referent is gone, and
* need it can just reopen the file.
* Type1 fonts thus don't use up file descriptor references, but can
* use memory footprint in a way that's managed by the host O/S.
* The main "pain" may be the different model means code needs to be written
* without assumptions as to how this is handled by the different subclasses
* of FileFont.
*/
}
public synchronized void dispose() {
}
return null;
}
});
}
}
static {
styleAbbreviationsMapping = new HashMap();
styleNameTokes = new HashSet();
/* These abbreviation rules are taken from Appendix 1 of Adobe Technical Note #5088 */
/* NB: this list is not complete - we did not include abbreviations which contain
several capital letters because current expansion algorithm do not support this.
(namely we have omited MM aka "Multiple Master", OsF aka "Oldstyle figures",
OS aka "Oldstyle", SC aka "Small caps" and DS aka "Display" */
"Meduium", "Nord", "Poster", "Regular", "Super", "Thin",
"Compressed", "Condensed", "Compact", "Extended", "Narrow",
"Inclined", "Italic", "Kursiv", "Oblique", "Upright", "Sloped",
"Semi", "Ultra", "Extra",
"Alternate", "Alternate", "Deutsche Fraktur", "Expert", "Inline", "Ornaments",
"Outline", "Roman", "Rounded", "Script", "Shaded", "Swash", "Titling", "Typewriter"};
"Md", "Nd", "Po", "Rg", "Su", "Th",
"Cm", "Cn", "Ct", "Ex", "Nr",
"Ic", "It", "Ks", "Obl", "Up", "Sl",
"Sm", "Ult", "X",
"A", "Alt", "Dfr", "Exp", "In", "Or",
"Ou", "Rm", "Rd", "Scr", "Sh", "Sw", "Ti", "Typ"};
/* This is only subset of names from nm[] because we want to distinguish things
like "Lucida Sans TypeWriter Bold" and "Lucida Sans Bold".
"Medium", "Nord", "Poster", "Regular", "Super", "Thin",
"Compressed", "Condensed", "Compact", "Extended", "Narrow",
"Inclined", "Italic", "Kursiv", "Oblique", "Upright", "Sloped", "Slanted",
"Semi", "Ultra", "Extra"};
}
}
}
/**
* Constructs a Type1 Font.
* @param platname - Platform identifier of the font. Typically file name.
* @param nativeNames - Native names - typically XLFDs on Unix.
*/
throws FontFormatException {
this(platname, nativeNames, false);
}
/**
* - does basic verification of the file
* - reads the names (full, family).
* - determines the style of the font.
* @throws FontFormatException - if the font can't be opened
* or fails verification, or there's no usable cmap
*/
throws FontFormatException {
super(platname, nativeNames);
checkedNatives = true;
try {
verify();
} catch (Throwable t) {
if (createdCopy) {
}
if (t instanceof FontFormatException) {
throw (FontFormatException)t;
} else {
throw new FontFormatException("Unexpected runtime exception.");
}
}
}
//System.out.println("open T1 " + platName);
try {
try {
} catch (FileNotFoundException ffne) {
}
return null;
}
});
} catch (NullPointerException e) {
throw new FontFormatException(e.toString());
} catch (ClosedChannelException e) {
/* NIO I/O is interruptible, recurse to retry operation.
* Clear interrupts before recursing in case NIO didn't.
*/
return getBuffer();
} catch (IOException e) {
throw new FontFormatException(e.toString());
}
}
return mapBuf;
}
protected void close() {
}
/* called from native code to read file into a direct byte buffer */
try {
raf = (RandomAccessFile)
try {
} catch (FileNotFoundException fnfe) {
}
return null;
}
});
} catch (NullPointerException npe) {
} catch (ClosedChannelException e) {
try {
}
} catch (IOException ioe) {
}
/* NIO I/O is interruptible, recurse to retry operation.
* Clear interrupts before recursing in case NIO didn't.
*/
} catch (IOException e) {
} finally {
try {
} catch (IOException e) {
}
}
}
}
try {
}
} catch (FontFormatException e) {
return null;
}
}
/* Normal usage should not call getBuffer(), as its state
* ie endianness, position etc, are shared. verify() can do
* this as its called only from within the constructor before
* there are other users of this object.
*/
throw new FontFormatException("short file");
}
} else {
}
throw new FontFormatException("Font name not found");
}
setStyle();
}
public int getFileSize() {
if (fileSize == 0) {
try {
getBuffer();
} catch (FontFormatException e) {
}
}
return fileSize;
}
throw new FontFormatException("bad pfa font");
}
// remind - additional verification needed?
}
int pos = 0;
while (true) {
try {
if (segLen <= 0) {
throw new FontFormatException("bad segment length");
}
} else if (segType == 0x8003) {
return;
} else {
throw new FontFormatException("bad pfb file");
}
} catch (BufferUnderflowException bue) {
} catch (Exception e) {
throw new FontFormatException(e.toString());
}
}
}
/* Need to parse the ascii contents of the Type1 font file,
* looking for FullName, FamilyName and FontName.
* If explicit names are not found then extract them from first text line.
* Operating on bytes so can't use Java String utilities, which
* is a large part of why this is a hack.
*
* Also check for mandatory FontType and verify if it is supported.
*/
boolean eof = false;
try {
//Parse font looking for explicit FullName, FamilyName and FontName
// (acording to Type1 spec they are optional)
if (tokenType == PSNAMETOKEN) {
if ("FullName".equals(s)) {
}
} else if ("FamilyName".equals(s)) {
}
} else if ("FontName".equals(s)) {
}
} else if ("FontType".equals(s)) {
/* look for
/FontType id def
*/
}
}
} else {
}
} else if (tokenType == PSEOFTOKEN) {
eof = true;
}
}
} catch (Exception e) {
throw new FontFormatException(e.toString());
}
/* Ignore all fonts besides Type1 (e.g. Type3 fonts) */
throw new FontFormatException("Unsupported font type");
}
// Try to extract font name from the first text line.
// According to Type1 spec first line consist of
// "%!FontType1-SpecVersion: FontName FontVersion"
// or
// "%!PS-AdobeFont-1.0: FontName version"
//skip segment header and "%!"
//NB: assume that first segment is ASCII one
// (is it possible to have valid Type1 font with first binary segment?)
}
}
}
//if we got to the end of file then we did not find at least one of FullName or FamilyName
//Try to deduce missing names from present ones
//NB: At least psName must be already initialized by this moment
if (eof) {
//if we find fullName or familyName then use it as another name too
} else if (familyName != null) {
} else { //fallback - use postscript font name to deduce full and family names
}
}
}
//FamilyName is truncated version of FullName
//Truncated tail must contain only style modifiers
while (end > 0) {
start--;
//as soon as we meet first non style token truncate
// current tail and return
}
}
return name; //should not happen
}
return abbr;
}
}
int pos;
//According to Adobe technical note #5088 psName (aka FontName) has form
// <Family Name><VendorID>-<Weight><Width><Slant><Character Set>
//where spaces are not allowed.
//Conversion: Expand abbreviations in style portion (everything after '-'),
// replace '-' with space and insert missing spaces
if (pos >= 0) {
} else {
}
return res;
}
//According to Adobe technical note #5088 psName (aka FontName) has form
// <Family Name><VendorID>-<Weight><Width><Slant><Character Set>
//where spaces are not allowed.
//Conversion: Truncate style portion (everything after '-')
// and insert missing spaces
}
return expandName(tmp, false);
}
return off;
}
return -1;
}
if (end < 0) {
}
if (start != 0) {
}
if (tryExpandAbbreviations) {
} else {
}
}
}
/* skip lines beginning with "%" and leading white space on a line */
while (b == '%') {
while (true) {
if (b == '\r' || b == '\n') {
break;
}
}
}
while (b <= ' ') {
}
return b;
}
/*
* Token types:
* PSNAMETOKEN - /
* PSSTRINGTOKEN - literal text string
*/
try {
while (true) {
if (b == (byte)'/') { // PS defined name follows.
return PSNAMETOKEN;
} else if (b == (byte)'(') { // PS string follows
return PSSTRINGTOKEN;
} else if ((b == (byte)'\r') || (b == (byte)'\n')) {
} else {
}
}
} catch (BufferUnderflowException e) {
return PSEOFTOKEN;
}
}
/* Read simple token (sequence of non-whitespace characters)
starting from the current position.
Skip leading whitespaces (if any). */
try {
} catch (UnsupportedEncodingException e) {
}
}
try {
} catch (UnsupportedEncodingException e) {
}
}
return psName;
}
}
return scaler;
}
mapper = new Type1GlyphMapper(this);
}
return mapper;
}
public int getNumGlyphs() {
try {
return getScaler().getNumGlyphs();
} catch (FontScalerException e) {
return getNumGlyphs();
}
}
public int getMissingGlyphCode() {
try {
return getScaler().getMissingGlyphCode();
} catch (FontScalerException e) {
return getMissingGlyphCode();
}
}
try {
} catch (FontScalerException e) {
return getGlyphCode(charCode);
}
}
}
}