|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.PDFFont
org.faceless.pdf2.OpenTypeFont
public final class OpenTypeFont
A subclass of PDFFont
that represents an OpenType font.
OpenType fonts are a superset of TrueType fonts, but also include
fonts where the glyphs are defined using Adobes "Compact Font" format
(which are supported since version 2.3 of the library).
OpenType fonts can be stored by reference only (the font is not embedded into the file), or can be embedded using either one or two bytes per glyph. One byte is only really suitable when the font is using a subset of the ASCII character set - eg. western european characters only. If the font is going to be used to display non-roman characters, two bytes should be used.
Constructor Summary | |
---|---|
OpenTypeFont(InputStream in,
int bytesperglyph)
Create a new OpenTypeFont from the specified InputStream. |
|
OpenTypeFont(OpenTypeFont font)
Create a new OpenTypeFont that is a copy of the specified OpenTypeFont. |
Method Summary | |
---|---|
float |
getAscender()
Get the Ascender for the font (the maximum height above the baseline the font extends), as a proportion of the point size. |
String[] |
getAvailableFeatures()
Return the list of available features for this font. |
float |
getDefaultLeading()
Get the default leading for this font - the preferred distance between two successive baselines of text. |
float |
getDescender()
Get the Descender for the font (the maximum height below the baseline the font extends), as a proportion of the point size. |
String |
getEmbeddingRestrictions()
Returns null if the font can be embedded without any restrictions, or
a non-null String if the font has embedding restrictions. |
boolean |
getFeature(String feature)
Returns whether the specified feature is currently set |
float |
getStrikeoutPosition()
Get the strikeout position, as a proportion of the font size. |
float |
getStrikeoutThickness()
Get the strikeout thickness, as a proportion of the font size. |
float |
getSubscriptPosition()
Get the recommended position of a sub-script version of this font, as a proportion of the sub-scripted font size. |
float |
getSubscriptSize()
Get the recommended size of a super/sub script version of this font, as a proportion of the normal font size. |
float |
getSuperscriptPosition()
Get the recommended position of a super-script version of this font, as a proportion of the sub-scripted font size. |
float |
getUnderlinePosition()
Get the underline position, as a proportion of the font size. |
float |
getUnderlineThickness()
Get the underline thickness, as a proportion of the font size. |
float |
getXHeight()
Get the X-Height of the font - normally the height of a lower-case 'x' character |
boolean |
isMonospace()
Return true if every character has the same width (like Courier), false if every character is potentially a different width (like Times-Roman) |
void |
setEmbed(boolean embed)
Whether to embed the font in the PDF. |
void |
setFeature(String feature,
boolean on)
Set or clear an optional feature on a font. |
void |
setSubset(boolean subset)
Whether to "subset" the font by removing unused glyph definitions from the font when it's embedded in the file. |
String |
toString()
|
Methods inherited from class org.faceless.pdf2.PDFFont |
---|
getBaseName, getBottom, getCharWidth, getCharWidth, getKerning, getKerning, getLeft, getRight, getTop, isDefined, isDefined, isHorizontal, ligaturize, ligaturize, requote, requote, versionBold, versionItalic, versionNonBold, versionNonItalic, versionRegular |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public OpenTypeFont(OpenTypeFont font)
font
- the OpenTypeFont to copy.public OpenTypeFont(InputStream in, int bytesperglyph) throws IOException
in
- the InputStream to read the font from.bytesperglyph
- the number of bytes to use for each glyph. Must
be 1 or 2. Thanks to compression there is surprisingly little difference
in terms of size in the resulting file, so if in doubt, use 2.
IOException
Method Detail |
---|
public void setSubset(boolean subset)
subset
- whether to subset the font (the default is true)public void setEmbed(boolean embed)
embed
- whether to embed the font (the default is true)public String getEmbeddingRestrictions()
null
if the font can be embedded without any restrictions, or
a non-null String if the font has embedding restrictions. Note the library will not
prevent you from using a font with embedding restrictions unless you
have set the OutputProfile.Feature.FontEmbeddingRestrictions
feature - it's your responsibility to ensure you have the right to embed
the font. The content of the String is undefined but is intended to detail the
restriction type.
public float getDefaultLeading()
PDFFont
Get 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 the PDFStyle
class for more
information.
getDefaultLeading
in class PDFFont
public float getDescender()
PDFFont
getDescender
in class PDFFont
public float getAscender()
PDFFont
getAscender
in class PDFFont
public float getUnderlinePosition()
PDFFont
getDescender()
method, the returned value is almost
always negative, indicating below the baseline.
getUnderlinePosition
in class PDFFont
public float getUnderlineThickness()
PDFFont
getUnderlineThickness
in class PDFFont
public float getStrikeoutPosition()
PDFFont
getStrikeoutPosition
in class PDFFont
public float getStrikeoutThickness()
PDFFont
getStrikeoutThickness
in class PDFFont
public float getSuperscriptPosition()
PDFFont
Get 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.
getSuperscriptPosition
in class PDFFont
public float getSubscriptPosition()
PDFFont
Get 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.
getSubscriptPosition
in class PDFFont
public float getSubscriptSize()
PDFFont
Get 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.
getSubscriptSize
in class PDFFont
public float getXHeight()
PDFFont
getXHeight
in class PDFFont
public boolean isMonospace()
PDFFont
isMonospace
in class PDFFont
public void setFeature(String feature, boolean on)
Set or clear an optional feature on a font. Some OpenType fonts have GPOS and GSUB tables which can be used to modify the glyphs that are displayed. This is required to display some languages correctly.
To enable this type of glyph shaping, the font must be created using
a 2-byte encoding and the "opentype" feature must first be set.
This will cause the default set of OpenType features to be used for
layout. The full list of features available in the font can be
seen by calling the getAvailableFeatures()
method (go
here
for their explanations), and individual
features may then be turned on or off as required. Features that are
required for correct layout (the case for Indic and Arabic scripts)
will be selected by default when the "opentype" feature is set.
By default, OpenType layout is not used, as it is considerably slower.
When it is used the PDFFont.ligaturize(char[], int, int, java.util.Locale)
method becomes a no-op,
as ligatures will be applied using these tables. The langauge of the
Locale can affect which operations are run, so this should be used
with care.
Lastly the "correctleading" feature can be set to use the correct
calculation for getDefaultLeading()
rather than the one originally
used in the PDF Library. For many fonts the two calculations will give
similar, often identical results, but for some fonts it won't so we can't
change this calculation by default without forcing a re-layout of many
existing documents. However we recommend setting this feature for all
new documents. The initial value of this feature can be set to true
by setting the OpenTypeCorrectLeading
property
setFeature
in class PDFFont
feature
- the feature nameon
- whether to set or clear the featurePDFFont.requote
,
PDFFont.getAvailableFeatures()
public boolean getFeature(String feature)
PDFFont
getFeature
in class PDFFont
feature
- the feature namepublic String[] getAvailableFeatures()
PDFFont
getAvailableFeatures
in class PDFFont
PDFFont.setFeature(java.lang.String, boolean)
PDFFont.setFeature(java.lang.String, boolean)
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |