org.apache.fop.svg

Class PDFTextUtil


public class PDFTextUtil
extends java.lang.Object

Utility class for generating PDF text objects.

Field Summary

static int
TR_CLIP
PDF text rendering mode: Add text to path for clipping
static int
TR_FILL
PDF text rendering mode: Fill text
static int
TR_FILL_CLIP
PDF text rendering mode: Fill text and add to path for clipping
static int
TR_FILL_STROKE
PDF text rendering mode: Fill, then stroke text
static int
TR_FILL_STROKE_CLIP
PDF text rendering mode: Fill, then stroke text and add to path for clipping
static int
TR_INVISIBLE
PDF text rendering mode: Neither fill nor stroke text (invisible)
static int
TR_STROKE
PDF text rendering mode: Stroke text
static int
TR_STROKE_CLIP
PDF text rendering mode: Stroke text and add to path for clipping

Constructor Summary

PDFTextUtil(PDFGraphics2D g2d)
Main constructor.

Method Summary

void
adjustGlyphTJ(double adjust)
Writes a glyph adjust value to the "TJ-Buffer".
void
beginTextObject()
Called when a new text object should be started.
void
concatMatrixCurrentTransform()
Creates a "cm" command using the current transformation as the matrix.
void
endTextObject()
Called when a text object should be ended.
Font
getCurrentFont()
Returns the current font in use.
void
restoreGraphicsState()
Creates a "Q" command, restoring the entire graphics state to its former value by popping it from the stack.
void
saveGraphicsState()
Creates a "q" command, pushing a copy of the entire graphics state onto the stack.
Font
selectFontForChar(char ch)
Selects a font from the font list suitable to display the given character.
void
setCurrentFont(Font f)
Sets the current font.
void
setFont(Font font)
Sets the current font for the text object.
void
setFonts(Font[] fonts)
Sets the current fonts for the text object.
void
setTextRenderingMode(boolean fill, boolean stroke, boolean addToClip)
Sets the text rendering mode.
void
setTextRenderingMode(int mode)
Sets the text rendering mode.
void
writeTJ()
Writes a "TJ" command, writing out the accumulated buffer with the characters and glyph positioning values.
void
writeTJChar(char ch)
Writes a char to the "TJ-Buffer".
void
writeTextMatrix(AffineTransform localTransform)
Writes a "Tm" command, setting a new text transformation matrix.
void
writeTf(Font f)
Writes a "Tf" command, setting a new current font.

Field Details

TR_CLIP

public static final int TR_CLIP
PDF text rendering mode: Add text to path for clipping
Field Value:
7

TR_FILL

public static final int TR_FILL
PDF text rendering mode: Fill text
Field Value:
0

TR_FILL_CLIP

public static final int TR_FILL_CLIP
PDF text rendering mode: Fill text and add to path for clipping
Field Value:
4

TR_FILL_STROKE

public static final int TR_FILL_STROKE
PDF text rendering mode: Fill, then stroke text
Field Value:
2

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
Field Value:
6

TR_INVISIBLE

public static final int TR_INVISIBLE
PDF text rendering mode: Neither fill nor stroke text (invisible)
Field Value:
3

TR_STROKE

public static final int TR_STROKE
PDF text rendering mode: Stroke text
Field Value:
1

TR_STROKE_CLIP

public static final int TR_STROKE_CLIP
PDF text rendering mode: Stroke text and add to path for clipping
Field Value:
5

Constructor Details

PDFTextUtil

public PDFTextUtil(PDFGraphics2D g2d)
Main constructor.
Parameters:
g2d - the PDFGraphics2D instance to work with

Method Details

adjustGlyphTJ

public void adjustGlyphTJ(double adjust)
Writes a glyph adjust value to the "TJ-Buffer".
Parameters:
adjust - the glyph adjust value in thousands of text unit space.

beginTextObject

public void beginTextObject()
Called when a new text object should be started. Be sure to call setFont() before issuing any text painting commands.

concatMatrixCurrentTransform

public void concatMatrixCurrentTransform()
Creates a "cm" command using the current transformation as the matrix.

endTextObject

public void endTextObject()
Called when a text object should be ended.

getCurrentFont

public Font getCurrentFont()
Returns the current font in use.
Returns:
the current font or null if no font is currently active.

restoreGraphicsState

public void restoreGraphicsState()
Creates a "Q" command, restoring the entire graphics state to its former value by popping it from the stack.

saveGraphicsState

public void saveGraphicsState()
Creates a "q" command, pushing a copy of the entire graphics state onto the stack.

selectFontForChar

public Font selectFontForChar(char ch)
Selects a font from the font list suitable to display the given character.
Parameters:
ch - the character
Returns:
the recommended Font to use

setCurrentFont

public void setCurrentFont(Font f)
Sets the current font.
Parameters:
f - the new font to use

setFont

public void setFont(Font font)
Sets the current font for the text object.
Parameters:
font - the new font

setFonts

public void setFonts(Font[] fonts)
Sets the current fonts for the text object. For every character, the suitable font will be selected.
Parameters:
fonts - the new fonts

setTextRenderingMode

public void setTextRenderingMode(boolean fill,
                                 boolean stroke,
                                 boolean addToClip)
Sets the text rendering mode.
Parameters:
fill - true if the text should be filled
stroke - true if the text should be stroked
addToClip - true if the path should be added for clipping

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_*)

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.

writeTJChar

public void writeTJChar(char ch)
Writes a char to the "TJ-Buffer".
Parameters:
ch - the unmapped character

writeTextMatrix

public void writeTextMatrix(AffineTransform localTransform)
Writes a "Tm" command, setting a new text transformation matrix.
Parameters:
localTransform - the new text transformation matrix

writeTf

public void writeTf(Font f)
Writes a "Tf" command, setting a new current font.
Parameters:
f - the font to select

Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.