Package com.independentsoft.office.pdf
Class EmbeddedFont
java.lang.Object
com.independentsoft.office.pdf.EmbeddedFont
A TrueType font embedded in a PDF file as a Type0/CIDFontType2 font with
Identity-H encoding. Tracks the glyphs used by the document and produces the
PDF font objects including a ToUnicode CMap for text extraction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intNumber of PDF objects produced bybuildObjects(int, boolean). -
Method Summary
Modifier and TypeMethodDescriptionbyte[][]buildObjects(int firstObjectId, boolean compress)Builds the five PDF objects of this font.Encodes text as a hexadecimal string of glyph ids for use with Identity-H encoding, registering each glyph as used:<00410042>.doublegetCharWidth(char c, double fontSize)Measures a single character width in points.getFont()Gets the underlying TrueType font.Gets the resource name used in page content streams, for example "EF1".doublegetStringWidth(String text, double fontSize)Measures text width in points.
-
Field Details
-
OBJECT_COUNT
public static final int OBJECT_COUNTNumber of PDF objects produced bybuildObjects(int, boolean).- See Also:
- Constant Field Values
-
-
Method Details
-
getResourceName
Gets the resource name used in page content streams, for example "EF1".- Returns:
- the resource name
-
getFont
Gets the underlying TrueType font.- Returns:
- the font
-
encode
Encodes text as a hexadecimal string of glyph ids for use with Identity-H encoding, registering each glyph as used:<00410042>.- Parameters:
text- the text- Returns:
- the hexadecimal string without the enclosing angle brackets
-
getStringWidth
Measures text width in points.- Parameters:
text- the textfontSize- the font size in points- Returns:
- the width in points
-
getCharWidth
public double getCharWidth(char c, double fontSize)Measures a single character width in points.- Parameters:
c- the characterfontSize- the font size in points- Returns:
- the width in points
-
buildObjects
Builds the five PDF objects of this font. The objects use consecutive ids starting at firstObjectId in this order: Type0 font, CIDFontType2 font, font descriptor, FontFile2 stream, ToUnicode stream.- Parameters:
firstObjectId- the id of the first objectcompress- whether to Flate-compress the font file and the ToUnicode stream- Returns:
- one complete "N 0 obj ... endobj" byte array per object
- Throws:
IOException- Signals that an I/O exception has occurred.
-