Package org.apache.fop.pdf
Class PDFTextUtil
- java.lang.Object
-
- org.apache.fop.pdf.PDFTextUtil
-
- Direct Known Subclasses:
PDFTextUtil
public abstract class PDFTextUtil extends java.lang.Object
Utility class for generating PDF text objects. It needs to be subclassed to add writing functionality (seewrite(String)
).
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuffer
bufTJ
private java.lang.String
currentFontName
private double
currentFontSize
private static int
DEC
The number of decimal places.private java.lang.String
endText
private boolean
inTextObject
private java.lang.String
startText
private int
textRenderingMode
static int
TR_CLIP
PDF text rendering mode: Add text to path for clippingstatic int
TR_FILL
PDF text rendering mode: Fill textstatic int
TR_FILL_CLIP
PDF text rendering mode: Fill text and add to path for clippingstatic int
TR_FILL_STROKE
PDF text rendering mode: Fill, then stroke textstatic int
TR_FILL_STROKE_CLIP
PDF text rendering mode: Fill, then stroke text and add to path for clippingstatic int
TR_INVISIBLE
PDF text rendering mode: Neither fill nor stroke text (invisible)static int
TR_STROKE
PDF text rendering mode: Stroke textstatic int
TR_STROKE_CLIP
PDF text rendering mode: Stroke text and add to path for clippingprivate boolean
useCid
private boolean
useMultiByte
-
Constructor Summary
Constructors Constructor Description PDFTextUtil()
Main constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
adjustGlyphTJ(double adjust)
Writes a glyph adjust value to the "TJ-Buffer".void
beginTextObject()
Called when a new text object should be started.private void
checkInTextObject()
void
concatMatrix(java.awt.geom.AffineTransform at)
Creates a "cm" command.void
endTextObject()
Called when a text object should be ended.protected void
initValues()
Resets the state fields.private boolean
isInString()
boolean
isInTextObject()
Indicates whether we are in a text object or not.void
setTextRenderingMode(boolean fill, boolean stroke, boolean addToClip)
Sets the text rendering mode.void
setTextRenderingMode(int mode)
Sets the text rendering mode.void
updateTf(java.lang.String fontName, double fontSize, boolean multiByte, boolean cid)
Updates the current font.protected abstract void
write(java.lang.String code)
Writes PDF code.protected abstract void
write(java.lang.StringBuffer code)
Writes PDF code.private void
writeAffineTransform(java.awt.geom.AffineTransform at, java.lang.StringBuffer sb)
private void
writeChar(int codePoint, java.lang.StringBuffer sb)
private static void
writeChar(int codePoint, java.lang.StringBuffer sb, boolean multibyte, boolean cid)
void
writeTd(double x, double y)
Writes a "Td" command with specified x and y coordinates.void
writeTextMatrix(java.awt.geom.AffineTransform localTransform)
Writes a "Tm" command, setting a new text transformation matrix.void
writeTf(java.lang.String fontName, double fontSize)
Writes a "Tf" command, setting a new current font.void
writeTj(char ch, boolean multibyte, boolean cid)
Writes a "Tj" command with specified character code.void
writeTJ()
Writes a "TJ" command, writing out the accumulated buffer with the characters and glyph positioning values.void
writeTJMappedChar(char ch)
Writes a char to the "TJ-Buffer".void
writeTJMappedCodePoint(int codePoint)
Writes a codepoint to the "TJ-Buffer".
-
-
-
Field Detail
-
DEC
private static final int DEC
The number of decimal places.- See Also:
- Constant Field Values
-
TR_FILL
public static final int TR_FILL
PDF text rendering mode: Fill text- See Also:
- Constant Field Values
-
TR_STROKE
public static final int TR_STROKE
PDF text rendering mode: Stroke text- See Also:
- Constant Field Values
-
TR_FILL_STROKE
public static final int TR_FILL_STROKE
PDF text rendering mode: Fill, then stroke text- See Also:
- Constant Field Values
-
TR_INVISIBLE
public static final int TR_INVISIBLE
PDF text rendering mode: Neither fill nor stroke text (invisible)- See Also:
- Constant Field Values
-
TR_FILL_CLIP
public static final int TR_FILL_CLIP
PDF text rendering mode: Fill text and add to path for clipping- See Also:
- Constant Field Values
-
TR_STROKE_CLIP
public static final int TR_STROKE_CLIP
PDF text rendering mode: Stroke text and add to path for clipping- See Also:
- Constant Field Values
-
TR_FILL_STROKE_CLIP
public static final int TR_FILL_STROKE_CLIP
PDF text rendering mode: Fill, then stroke text and add to path for clipping- See Also:
- Constant Field Values
-
TR_CLIP
public static final int TR_CLIP
PDF text rendering mode: Add text to path for clipping- See Also:
- Constant Field Values
-
inTextObject
private boolean inTextObject
-
startText
private java.lang.String startText
-
endText
private java.lang.String endText
-
useMultiByte
private boolean useMultiByte
-
useCid
private boolean useCid
-
bufTJ
private java.lang.StringBuffer bufTJ
-
textRenderingMode
private int textRenderingMode
-
currentFontName
private java.lang.String currentFontName
-
currentFontSize
private double currentFontSize
-
-
Method Detail
-
write
protected abstract void write(java.lang.String code)
Writes PDF code.- Parameters:
code
- the PDF code to write
-
write
protected abstract void write(java.lang.StringBuffer code)
Writes PDF code.- Parameters:
code
- the PDF code to write
-
writeAffineTransform
private void writeAffineTransform(java.awt.geom.AffineTransform at, java.lang.StringBuffer sb)
-
writeChar
private static void writeChar(int codePoint, java.lang.StringBuffer sb, boolean multibyte, boolean cid)
-
writeChar
private void writeChar(int codePoint, java.lang.StringBuffer sb)
-
checkInTextObject
private void checkInTextObject()
-
isInTextObject
public boolean isInTextObject()
Indicates whether we are in a text object or not.- Returns:
- true if we are in a text object
-
beginTextObject
public void beginTextObject()
Called when a new text object should be started. Be sure to call setFont() before issuing any text painting commands.
-
endTextObject
public void endTextObject()
Called when a text object should be ended.
-
initValues
protected void initValues()
Resets the state fields.
-
concatMatrix
public void concatMatrix(java.awt.geom.AffineTransform at)
Creates a "cm" command.- Parameters:
at
- the transformation matrix
-
writeTf
public void writeTf(java.lang.String fontName, double fontSize)
Writes a "Tf" command, setting a new current font.- Parameters:
fontName
- the name of the font to selectfontSize
- the font size (in points)
-
updateTf
public void updateTf(java.lang.String fontName, double fontSize, boolean multiByte, boolean cid)
Updates the current font. This method only writes a "Tf" if the current font changes.- Parameters:
fontName
- the name of the font to selectfontSize
- the font size (in points)multiByte
- true indicates the font is a multi-byte font, false means single-byte
-
setTextRenderingMode
public void setTextRenderingMode(int mode)
Sets the text rendering mode.- Parameters:
mode
- the rendering mode (value 0 to 7, see PDF Spec, constants: TR_*)
-
setTextRenderingMode
public void setTextRenderingMode(boolean fill, boolean stroke, boolean addToClip)
Sets the text rendering mode.- Parameters:
fill
- true if the text should be filledstroke
- true if the text should be strokedaddToClip
- true if the path should be added for clipping
-
writeTextMatrix
public void writeTextMatrix(java.awt.geom.AffineTransform localTransform)
Writes a "Tm" command, setting a new text transformation matrix.- Parameters:
localTransform
- the new text transformation matrix
-
writeTJMappedChar
public void writeTJMappedChar(char ch)
Writes a char to the "TJ-Buffer".- Parameters:
ch
- the mapped character (code point/character code)
-
writeTJMappedCodePoint
public void writeTJMappedCodePoint(int codePoint)
Writes a codepoint to the "TJ-Buffer".- Parameters:
codePoint
- the mapped character (code point/character code)
-
adjustGlyphTJ
public void adjustGlyphTJ(double adjust)
Writes a glyph adjust value to the "TJ-Buffer".Assumes the following:
- if buffer is currently empty, then this is the start of the array object that encodes the adjustment and character values, and, therfore, a LEFT SQUARE BRACKET '[' must be prepended; and
- otherwise (the buffer is not empty), then the last element written to the buffer was a mapped character, and, therefore, a terminating '>' or ')' followed by a space must be appended to the buffer prior to appending the adjustment value.
- Parameters:
adjust
- the glyph adjust value in thousands of text unit space.
-
writeTJ
public void writeTJ()
Writes a "TJ" command, writing out the accumulated buffer with the characters and glyph positioning values. The buffer is reset afterwards.
-
isInString
private boolean isInString()
-
writeTd
public void writeTd(double x, double y)
Writes a "Td" command with specified x and y coordinates.- Parameters:
x
- coordinatey
- coordinate
-
writeTj
public void writeTj(char ch, boolean multibyte, boolean cid)
Writes a "Tj" command with specified character code.- Parameters:
ch
- character code to write
-
-