Class Type3Font
- java.lang.Object
-
- org.faceless.pdf2.PDFFont
-
- org.faceless.pdf2.Type3Font
-
- All Implemented Interfaces:
Cloneable
public class Type3Font extends PDFFont
A Type3 font is an artificial font made up of shapes drawn directly to the PDF, rather than stored in a font file embedded in the PDF. These are useful when a few custom shapes have to be added to the PDF as glyphs - perhaps extracted from an existing font, or created freehand - and in particular this approach can be used with the
PDFStyle.addBackupFont(org.faceless.pdf2.PDFFont)method to plug gaps in an existing font's coverage.Here's an example showing how to use a glyph from an existing
Font. (be aware there is rarely any benefit to cloning an entire font as shown here, and that copyright issues may arise when doing so; it's purely for example):Type3Font font = new Type3Font("MyFont"); String glyphs = "Hello World"; FontRenderContext frc = new FontRenderContext(null, true, true); for (int i=0;i<glyphs.length();i++) { char c = glyphs.charAt(i); if (!font.isDefined(c)) { font.addGlyph(c, f.createGlyphVector(frc, Character.toString(c))); } }and here's how to create a completely custom glyphType3Font font = new Type3Font("MyFont"); GeneralPath p = new GeneralPath(); p.moveTo(0, 600); p.lineTo(600, 300); p.lineTo(0, 0); p.closePath(); font.add('▶', 600, p); // U+25B6, right pointing triangleType3 fonts may contain any number of individual glyphs, but only 255 can be referenced in a PDF from a single instance of this font. The vast majority of methods inherited from
PDFFontthat return font metrics values (eggetAscender()return 0 or default values as these concepts aren't applicable to Type3 fonts.As of 2.23.4, the full range of codepoints outside the BMP can be addressed.
- Since:
- 2.21
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddGlyph(int c, int advance, Shape shape)Add a glyph to the font.intaddGlyph(int c, GlyphVector gv)Add a glyph to the fontfloatgetAscender()Get the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size.floatgetCapHeight()Get the Cap-Height of the font - normally the height of an upper-case 'O' characterfloatgetDefaultLeading()Get the default leading for this font - the preferred distance between two successive baselines of text.BitSetgetDefinedCodepoints()Return read-only BitSet containing all the Unicode codepoints defined in this fontfloatgetDescender()Get the Descender for the font (the maximum height below the baseline the font extends), as a proportion of the point size.intgetSize()Return the maximum entry in this font, from 0 (for empty) to 255.floatgetStrikeoutPosition()Get the strikeout position, as a proportion of the font size.floatgetStrikeoutThickness()Get the strikeout thickness, as a proportion of the font size.floatgetSubscriptPosition()Get the recommended position of a sub-script version of this font, as a proportion of the sub-scripted font size.floatgetSubscriptSize()Get the recommended size of a super/sub script version of this font, as a proportion of the normal font size.floatgetSuperscriptPosition()Get the recommended position of a super-script version of this font, as a proportion of the sub-scripted font size.floatgetUnderlinePosition()Get the underline position, as a proportion of the font size.floatgetUnderlineThickness()Get the underline thickness, as a proportion of the font size.floatgetXHeight()Get the X-Height of the font - normally the height of a lower-case 'x' character.booleanisBold()Return true if the font is boldbooleanisDefined(int codepoint)Return true if the specified Unicode character is defined in the font.booleanisEmbedded()Type3 Fonts are always embeddedbooleanisItalic()Return true if the font is italicbooleanisMonospace()Return true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman)booleanisSerif()Return true if the font is serifStringtoString()-
Methods inherited from class org.faceless.pdf2.PDFFont
clone, getAvailableFeatures, getBaseName, getBottom, getCharWidth, getCharWidth, getFeature, getKerning, getKerning, getLeft, getMetaData, getRight, getTop, getXMP, hasFeature, isDefined, isHorizontal, isSubset, setFeature, setFeature, setMetaData, versionBold, versionItalic, versionNonBold, versionNonItalic, versionRegular
-
-
-
-
Constructor Detail
-
Type3Font
public Type3Font(Type3Font font)
Create a new Type3 Font that is a copy of the existing Type3 font. This constructor should be used to clone the font if it is being shared across threads.- Parameters:
font- the original font
-
Type3Font
public Type3Font(String name)
Create a new Type3 Font with the specified name- Parameters:
name- the font name
-
-
Method Detail
-
addGlyph
public int addGlyph(int c, GlyphVector gv)Add a glyph to the font- Parameters:
c- the Unicode Codepoint this glyph maps togv- the GlyphVector - this should be created from an existingFontwith a size of 1, and represent a single character- Returns:
- the index of the new glyph - the maximum allowed value is 255
- Throws:
IllegalStateException- if the font already has 255 entries
-
addGlyph
public int addGlyph(int c, int advance, Shape shape)Add a glyph to the font.- Parameters:
c- the Unicode Codepoint this glyph maps toadvance- the advance, which should be a number between 0 (no advance) and 1000 (for a square glyph)shape- the glyph outline. This should be in PDF glyph units, which means that (0,0) is the left edge of the baseline, positive Y values are above the baseline, and the glyph is in a box of 1000 x 1000.- Returns:
- the index of the new glyph - the maximum allowed value is 255
- Throws:
IllegalStateException- if the font already has 255 entries
-
isEmbedded
public boolean isEmbedded()
Type3 Fonts are always embedded- Overrides:
isEmbeddedin classPDFFont
-
getSize
public int getSize()
Return the maximum entry in this font, from 0 (for empty) to 255.- Since:
- 2.23.4
-
isItalic
public boolean isItalic()
Description copied from class:PDFFontReturn true if the font is italic
-
isBold
public boolean isBold()
Description copied from class:PDFFontReturn true if the font is bold
-
isSerif
public boolean isSerif()
Description copied from class:PDFFontReturn true if the font is serif
-
isMonospace
public boolean isMonospace()
Description copied from class:PDFFontReturn true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman)- Specified by:
isMonospacein classPDFFont
-
getAscender
public float getAscender()
Description copied from class:PDFFontGet the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size. The exact source of of this value is undefined except for OpenTypeFonts, where it comes from the "hhea.ascender" value normally, or the from "OS2.sTypoAscender" flag if the USE_TYPO_METRICS flag is set.- Specified by:
getAscenderin classPDFFont
-
getDescender
public float getDescender()
Description copied from class:PDFFontGet the Descender for the font (the maximum height below the baseline the font extends), as a proportion of the point size. The returned value is usually negative. The exact source of this value is undefined except for OpenTypeFonts, where it comes from the "hhea.descender" value normally, or the from "OS2.sTypoDescender" flag if the USE_TYPO_METRICS flag is set.- Specified by:
getDescenderin classPDFFont
-
getXHeight
public float getXHeight()
Description copied from class:PDFFontGet the X-Height of the font - normally the height of a lower-case 'x' character.- Specified by:
getXHeightin classPDFFont
-
getCapHeight
public float getCapHeight()
Description copied from class:PDFFontGet the Cap-Height of the font - normally the height of an upper-case 'O' character- Specified by:
getCapHeightin classPDFFont
-
getDefaultLeading
public float getDefaultLeading()
Description copied from class:PDFFontGet the default leading for this font - the preferred distance between two successive baselines of text. Values are a ratio of the font size, and are typically between 1 and 1.3
Note that the values of the different spacing-between-lines methods have changed - in versions 1.0.4 and earlier this routine normally returned 1 and the spacing was set by the
PDFStyle.setTextLineSpacing(float)method. Since 1.1, the values for these two methods are effectively reversed. See the relevant method comments in thePDFStyleclass for more information.- Specified by:
getDefaultLeadingin classPDFFont
-
getUnderlineThickness
public float getUnderlineThickness()
Description copied from class:PDFFontGet the underline thickness, as a proportion of the font size.- Specified by:
getUnderlineThicknessin classPDFFont
-
getUnderlinePosition
public float getUnderlinePosition()
Description copied from class:PDFFontGet the underline position, as a proportion of the font size. Like thegetDescender()method, the returned value is almost always negative, indicating below the baseline. The distance is from the baseline to the center of the underline.- Specified by:
getUnderlinePositionin classPDFFont
-
getStrikeoutThickness
public float getStrikeoutThickness()
Description copied from class:PDFFontGet the strikeout thickness, as a proportion of the font size.- Specified by:
getStrikeoutThicknessin classPDFFont
-
getStrikeoutPosition
public float getStrikeoutPosition()
Description copied from class:PDFFontGet the strikeout position, as a proportion of the font size. The value is the distance from the baseline to the center of the strikeout, and shuold be positive.- Specified by:
getStrikeoutPositionin classPDFFont
-
getSuperscriptPosition
public float getSuperscriptPosition()
Description copied from class:PDFFontGet the recommended position of a super-script version of this font, as a proportion of the sub-scripted font size. Value is always positive.
For some fonts (like CJK or barcode fonts) where there is no concept of super or subscript, this value is entirely arbitrary.
- Specified by:
getSuperscriptPositionin classPDFFont
-
getSubscriptPosition
public float getSubscriptPosition()
Description copied from class:PDFFontGet the recommended position of a sub-script version of this font, as a proportion of the sub-scripted font size. Value is almost always zero or negative.
For some fonts (like CJK or barcode fonts) where there is no concept of super or subscript, this value is entirely arbitrary.
- Specified by:
getSubscriptPositionin classPDFFont
-
getSubscriptSize
public float getSubscriptSize()
Description copied from class:PDFFontGet the recommended size of a super/sub script version of this font, as a proportion of the normal font size. Typical value is around 0.6.
For some fonts (like CJK or barcode fonts) where there is no concept of super or subscript, this value is entirely arbitrary.
- Specified by:
getSubscriptSizein classPDFFont
-
getDefinedCodepoints
public BitSet getDefinedCodepoints()
Description copied from class:PDFFontReturn read-only BitSet containing all the Unicode codepoints defined in this font- Specified by:
getDefinedCodepointsin classPDFFont
-
isDefined
public boolean isDefined(int codepoint)
Description copied from class:PDFFontReturn true if the specified Unicode character is defined in the font. This method is identical toPDFFont.isDefined(char)but takes anint, to cater for the new Unicode 4.0 codepoints added in Java 1.5.
-
toString
public String toString()
-
-