Package org.verapdf.pd.font
Class PDFont
- java.lang.Object
-
- org.verapdf.pd.PDObject
-
- org.verapdf.pd.PDResource
-
- org.verapdf.pd.font.PDFont
-
- Direct Known Subclasses:
PDCIDFont
,PDSimpleFont
public abstract class PDFont extends PDResource
This is PD representation of font.- Author:
- Sergey Shemyakov
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
boundingBox
protected COSDictionary
dictionary
protected Encoding
encoding
protected PDFontDescriptor
fontDescriptor
protected FontProgram
fontProgram
protected boolean
isFontParsed
protected PDCMap
toUnicodeCMap
-
Constructor Summary
Constructors Constructor Description PDFont(COSDictionary dictionary)
Constructor from COSDictionary.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
cMapToUnicode(int code)
Gets toUnicode value just from toUnicode cMap.Double
getAscent()
double[]
getBoundingBox()
Double
getDefaultWidth()
Double
getDescent()
COSDictionary
getDictionary()
Map<Integer,String>
getDifferences()
static Map<Integer,String>
getDifferencesFromCosEncoding(COSObject e)
COSObject
getEncoding()
Encoding
getEncodingMapping()
Long
getFirstChar()
PDFontDescriptor
getFontDescriptor()
abstract FontProgram
getFontProgram()
Double
getFontWeight()
Long
getLastChar()
String
getName()
String
getNameWithoutSubset()
ASAtom
getProgramSubtype()
ASAtom
getSubtype()
String
getType()
Double
getWidth(int code)
Gets width for glyph with given code in this font.abstract float
getWidthFromProgram(int code)
Gets width of given code from font program.COSObject
getWidths()
abstract boolean
glyphIsPresent(int code)
Checks if glyph for given code is present in this font.protected boolean
isSubset()
boolean
isSuccessfullyParsed()
boolean
isSymbolic()
int
readCode(InputStream stream)
Method reads next character code from stream according to font data.void
setSuccessfullyParsed(boolean successfullyParsed)
Sets flag indicating successful parsing of embedded font program.String
toUnicode(int code)
Gets Unicode string for given character code.-
Methods inherited from class org.verapdf.pd.PDResource
isInherited, setInherited
-
Methods inherited from class org.verapdf.pd.PDObject
clear, empty, getBooleanKey, getIntegerKey, getKey, getNameKey, getObject, getRealKey, getStringKey, knownKey, removeKey, setBooleanKey, setIntegerKey, setKey, setNameKey, setObject, setObject, setStringKey, updateFromObject, updateToObject
-
-
-
-
Field Detail
-
dictionary
protected COSDictionary dictionary
-
fontDescriptor
protected PDFontDescriptor fontDescriptor
-
toUnicodeCMap
protected PDCMap toUnicodeCMap
-
isFontParsed
protected boolean isFontParsed
-
fontProgram
protected FontProgram fontProgram
-
encoding
protected Encoding encoding
-
boundingBox
protected double[] boundingBox
-
-
Constructor Detail
-
PDFont
public PDFont(COSDictionary dictionary)
Constructor from COSDictionary.- Parameters:
dictionary
- is font dictionary.
-
-
Method Detail
-
getDictionary
public COSDictionary getDictionary()
- Returns:
- font COSDictionary.
-
getFontDescriptor
public PDFontDescriptor getFontDescriptor()
- Returns:
- font descriptor COSDictionary.
-
getType
public String getType()
- Returns:
- font type (Type entry).
-
getSubtype
public ASAtom getSubtype()
- Returns:
- font subtype (Subtype entry).
-
isSymbolic
public boolean isSymbolic()
- Returns:
- true if the font flags in the font descriptor dictionary mark indicate that the font is symbolic (the entry /Flags has bit 3 set to 1 and bit 6 set to 0). descriptor is null.
-
getEncodingMapping
public Encoding getEncodingMapping()
- Returns:
- encoding mapping object for this font.
-
getFontWeight
public Double getFontWeight()
-
getName
public String getName()
- Returns:
- name of the font as specified in BaseFont key of font dictionary.
-
getNameWithoutSubset
public String getNameWithoutSubset()
- Returns:
- name of the font without subset as specified in BaseFont key of font dictionary.
-
getBoundingBox
public double[] getBoundingBox()
-
getEncoding
public COSObject getEncoding()
- Returns:
- encoding of the font as specified in Encoding key of font dictionary.
-
getDifferences
public Map<Integer,String> getDifferences()
- Returns:
- map of differences as given in Differences key in Encoding of this font.
-
getDifferencesFromCosEncoding
public static Map<Integer,String> getDifferencesFromCosEncoding(COSObject e)
- Returns:
- map of differences as given in Differences key in Encoding.
-
getWidths
public COSObject getWidths()
- Returns:
- widths of the font as specified in Widths key of font dictionary.
-
getFirstChar
public Long getFirstChar()
- Returns:
- first char in the font as specified in FirstChar key of font dictionary.
-
getLastChar
public Long getLastChar()
- Returns:
- last char in the font as specified in LastChar key of font dictionary.
-
readCode
public int readCode(InputStream stream) throws IOException
Method reads next character code from stream according to font data. It can contain from 1 to 4 bytes.- Parameters:
stream
- is stream with raw data.- Returns:
- next character code read.
- Throws:
IOException
- if reading fails.
-
getFontProgram
public abstract FontProgram getFontProgram()
- Returns:
- embedded font program fo this PDFont.
-
getWidthFromProgram
public abstract float getWidthFromProgram(int code)
Gets width of given code from font program.- Parameters:
code
- is code of character in strings to display.- Returns:
- width of glyph for this code.
-
glyphIsPresent
public abstract boolean glyphIsPresent(int code)
Checks if glyph for given code is present in this font.- Parameters:
code
- is code for glyph in this font.- Returns:
- true if glyph is present.
-
toUnicode
public String toUnicode(int code)
Gets Unicode string for given character code. This method returns null in case when no toUnicode mapping for this character was found, so some inherited classes need to call this method, check return value on null and then implement their special logic.- Parameters:
code
- is code for character.- Returns:
- Unicode string
-
cMapToUnicode
public String cMapToUnicode(int code)
Gets toUnicode value just from toUnicode cMap.- Parameters:
code
- is character code.- Returns:
- Unicode value as specified in toUnicode cMap.
-
getProgramSubtype
public ASAtom getProgramSubtype()
- Returns:
- value of Subtype key in embedded font program stream or null if no value available.
-
getWidth
public Double getWidth(int code)
Gets width for glyph with given code in this font.- Parameters:
code
- is code of glyph.- Returns:
- width for glyph with given code as specified in Widths array.
-
getDefaultWidth
public Double getDefaultWidth()
- Returns:
- default width for this font as specified in font descriptor.
-
isSuccessfullyParsed
public boolean isSuccessfullyParsed()
- Returns:
- true if font program for this font has been successfully parsed.
-
setSuccessfullyParsed
public void setSuccessfullyParsed(boolean successfullyParsed)
Sets flag indicating successful parsing of embedded font program.
-
isSubset
protected boolean isSubset()
-
getAscent
public Double getAscent()
-
getDescent
public Double getDescent()
-
-