com.lowagie.text.pdf

Class PdfChunk

public class PdfChunk extends Object implements SplitCharacter

A PdfChunk is the PDF translation of a Chunk.

A PdfChunk is a PdfString in a certain PdfFont and Color.

See Also: PdfString Chunk Font

Field Summary
protected HashMapattributes
Metric attributes.
protected BaseFontbaseFont
protected booleanchangeLeading
Indicates if the height and offset of the Image has to be taken into account
protected Stringencoding
The encoding.
protected PdfFontfont
The font for this PdfChunk.
protected Imageimage
The image in this PdfChunk, if it has one
static floatITALIC_ANGLE
static HashMapkeysAttributes
The allowed attributes in variable attributes.
static HashMapkeysNoStroke
The allowed attributes in variable noStroke.
protected booleannewlineSplit
true if the chunk split was cause by a newline.
protected HashMapnoStroke
Non metric attributes.
protected floatoffsetX
The offset in the x direction for the image
protected floatoffsetY
The offset in the y direction for the image
static char[]singleSpace
protected SplitCharactersplitCharacter
static PdfChunk[]thisChunk
protected Stringvalue
The value of this object.
Constructor Summary
PdfChunk(String string, PdfChunk other)
Constructs a PdfChunk-object.
PdfChunk(Chunk chunk, PdfAction action)
Constructs a PdfChunk-object.
Method Summary
booleanchangeLeading()
Colorcolor()
Returns the color of this Chunk.
PdfFontfont()
Returns the font of this Chunk.
ObjectgetAttribute(String name)
Gets an attribute.
floatgetCharWidth(char c)
StringgetEncoding()
Gets the encoding of this string.
ImagegetImage()
Gets the image in the PdfChunk.
floatgetImageOffsetX()
Gets the image offset in the x direction
floatgetImageOffsetY()
Gets the image offset in the y direction
floatgetTextRise()
Gets the text displacement relatiev to the baseline.
chargetUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID.
floatgetWidthCorrected(float charSpacing, float wordSpacing)
Gets the width of the PdfChunk taking into account the extra character and word spacing.
protected intgetWord(String text, int start)
booleanisAttribute(String name)
Checks if the attribute exists.
booleanisExtSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)
booleanisImage()
Checks if there is an image in the PdfChunk.
booleanisNewlineSplit()
Checks if the PdfChunk split was caused by a newline.
booleanisSpecialEncoding()
Tells you if this string is in Chinese, Japanese, Korean or Identity-H.
booleanisSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)
Checks if a character can be used to split a PdfString.
booleanisStroked()
Checks if this PdfChunk needs some special metrics handling.
intlength()
static booleannoPrint(char c)
voidsetImageOffsetX(float offsetX)
Sets the image offset in the x direction
voidsetImageOffsetY(float offsetY)
Sets the image offset in the y direction
voidsetValue(String value)
sets the value.
PdfChunksplit(float width)
Splits this PdfChunk if it's too long for the given width.
StringtoString()
Stringtrim(String string)
Removes all the ' ' and '-'-characters on the right of a String.
floattrimFirstSpace()
floattrimLastSpace()
Trims the last space.
PdfChunktruncate(float width)
Truncates this PdfChunk if it's too long for the given width.
floatwidth()
Returns the width of this PdfChunk.

Field Detail

attributes

protected HashMap attributes
Metric attributes.

This attributes require the mesurement of characters widths when rendering such as underline.

baseFont

protected BaseFont baseFont

changeLeading

protected boolean changeLeading
Indicates if the height and offset of the Image has to be taken into account

encoding

protected String encoding
The encoding.

font

protected PdfFont font
The font for this PdfChunk.

image

protected Image image
The image in this PdfChunk, if it has one

ITALIC_ANGLE

private static final float ITALIC_ANGLE

keysAttributes

private static final HashMap keysAttributes
The allowed attributes in variable attributes.

keysNoStroke

private static final HashMap keysNoStroke
The allowed attributes in variable noStroke.

newlineSplit

protected boolean newlineSplit
true if the chunk split was cause by a newline.

noStroke

protected HashMap noStroke
Non metric attributes.

This attributes do not require the mesurement of characters widths when rendering such as Color.

offsetX

protected float offsetX
The offset in the x direction for the image

offsetY

protected float offsetY
The offset in the y direction for the image

singleSpace

private static final char[] singleSpace

splitCharacter

protected SplitCharacter splitCharacter

thisChunk

private static final PdfChunk[] thisChunk

value

protected String value
The value of this object.

Constructor Detail

PdfChunk

PdfChunk(String string, PdfChunk other)
Constructs a PdfChunk-object.

Parameters: string the content of the PdfChunk-object other Chunk with the same style you want for the new Chunk

PdfChunk

PdfChunk(Chunk chunk, PdfAction action)
Constructs a PdfChunk-object.

Parameters: chunk the original Chunk-object action the PdfAction if the Chunk comes from an Anchor

Method Detail

changeLeading

public boolean changeLeading()

color

Color color()
Returns the color of this Chunk.

Returns: a Color

font

PdfFont font()
Returns the font of this Chunk.

Returns: a PdfFont

getAttribute

Object getAttribute(String name)
Gets an attribute. The search is made in attributes and noStroke.

Parameters: name the attribute key

Returns: the attribute value or null if not found

getCharWidth

float getCharWidth(char c)

getEncoding

String getEncoding()
Gets the encoding of this string.

Returns: a String

getImage

Image getImage()
Gets the image in the PdfChunk.

Returns: the image or null

getImageOffsetX

float getImageOffsetX()
Gets the image offset in the x direction

Returns: the image offset in the x direction

getImageOffsetY

float getImageOffsetY()
Gets the image offset in the y direction

Returns: Gets the image offset in the y direction

getTextRise

public float getTextRise()
Gets the text displacement relatiev to the baseline.

Returns: a displacement in points

getUnicodeEquivalent

public char getUnicodeEquivalent(char c)
Gets the Unicode equivalent to a CID. The (inexistent) CID is translated as '\n'. It has only meaning with CJK fonts with Identity encoding.

Parameters: c the CID code

Returns: the Unicode equivalent

getWidthCorrected

public float getWidthCorrected(float charSpacing, float wordSpacing)
Gets the width of the PdfChunk taking into account the extra character and word spacing.

Parameters: charSpacing the extra character spacing wordSpacing the extra word spacing

Returns: the calculated width

getWord

protected int getWord(String text, int start)

isAttribute

boolean isAttribute(String name)
Checks if the attribute exists.

Parameters: name the attribute key

Returns: true if the attribute exists

isExtSplitCharacter

boolean isExtSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)

isImage

boolean isImage()
Checks if there is an image in the PdfChunk.

Returns: true if an image is present

isNewlineSplit

public boolean isNewlineSplit()
Checks if the PdfChunk split was caused by a newline.

Returns: true if the PdfChunk split was caused by a newline.

isSpecialEncoding

boolean isSpecialEncoding()
Tells you if this string is in Chinese, Japanese, Korean or Identity-H.

Returns: true if the Chunk has a special encoding

isSplitCharacter

public boolean isSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)
Checks if a character can be used to split a PdfString.

for the moment every character less than or equal to SPACE and the character '-' are 'splitCharacters'.

Parameters: start start position in the array current current position in the array end end position in the array cc the character array that has to be checked ck chunk array

Returns: true if the character can be used to split a string, false otherwise

isStroked

boolean isStroked()
Checks if this PdfChunk needs some special metrics handling.

Returns: true if this PdfChunk needs some special metrics handling.

length

int length()

noPrint

public static boolean noPrint(char c)

setImageOffsetX

void setImageOffsetX(float offsetX)
Sets the image offset in the x direction

Parameters: offsetX the image offset in the x direction

setImageOffsetY

void setImageOffsetY(float offsetY)
Sets the image offset in the y direction

Parameters: offsetY the image offset in the y direction

setValue

void setValue(String value)
sets the value.

Parameters: value content of the Chunk

split

PdfChunk split(float width)
Splits this PdfChunk if it's too long for the given width.

Returns null if the PdfChunk wasn't truncated.

Parameters: width a given width

Returns: the PdfChunk that doesn't fit into the width.

toString

public String toString()

See Also: java.lang.Object#toString()

trim

String trim(String string)
Removes all the ' ' and '-'-characters on the right of a String.

Parameters: string the String that has to be trimmed.

Returns: the trimmed String

trimFirstSpace

public float trimFirstSpace()

trimLastSpace

public float trimLastSpace()
Trims the last space.

Returns: the width of the space trimmed, otherwise 0

truncate

PdfChunk truncate(float width)
Truncates this PdfChunk if it's too long for the given width.

Returns null if the PdfChunk wasn't truncated.

Parameters: width a given width

Returns: the PdfChunk that doesn't fit into the width.

width

float width()
Returns the width of this PdfChunk.

Returns: a width