Class PdfChunk
java.lang.Object
com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfChunk
- All Implemented Interfaces:
SplitCharacter
A
PdfChunk
is the PDF translation of a Chunk
.
A PdfChunk
is a PdfString
in a certain
PdfFont
and Color
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMap
Metric attributes.protected BaseFont
protected boolean
Indicates if the height and offset of the Image has to be taken into accountprotected String
The encoding.protected PdfFont
The font for thisPdfChunk
.private static final float
private static final HashMap
The allowed attributes in variableattributes
.private static final HashMap
The allowed attributes in variablenoStroke
.protected boolean
true
if the chunk split was cause by a newline.protected HashMap
Non metric attributes.protected float
The offset in the x direction for the imageprotected float
The offset in the y direction for the imageprivate static final char[]
protected SplitCharacter
private static final PdfChunk[]
protected String
The value of this object. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
(package private) Color
color()
Returns the color of thisChunk
.(package private) PdfFont
font()
Returns the font of thisChunk
.(package private) Object
getAttribute
(String name) Gets an attribute.(package private) float
getCharWidth
(char c) (package private) String
Gets the encoding of this string.(package private) float
Gets the image offset in the y directionfloat
Gets the text displacement relatiev to the baseline.char
getUnicodeEquivalent
(char c) Gets the Unicode equivalent to a CID.float
getWidthCorrected
(float charSpacing, float wordSpacing) Gets the width of thePdfChunk
taking into account the extra character and word spacing.protected int
(package private) boolean
isAttribute
(String name) Checks if the attribute exists.(package private) boolean
isExtSplitCharacter
(int start, int current, int end, char[] cc, PdfChunk[] ck) boolean
Checks if thePdfChunk
split was caused by a newline.(package private) boolean
Tells you if this string is in Chinese, Japanese, Korean or Identity-H.boolean
isSplitCharacter
(int start, int current, int end, char[] cc, PdfChunk[] ck) Checks if a character can be used to split aPdfString
.(package private) boolean
Checks if thisPdfChunk
needs some special metrics handling.(package private) int
length()
static boolean
noPrint
(char c) (package private) void
sets the value.(package private) PdfChunk
split
(float width) Splits thisPdfChunk
if it's too long for the given width.toString()
(package private) String
Removes all the ' ' and '-'-characters on the right of aString
.float
Trims the last space.(package private) PdfChunk
truncate
(float width) Truncates thisPdfChunk
if it's too long for the given width.(package private) float
width()
Returns the width of thisPdfChunk
.
-
Field Details
-
singleSpace
private static final char[] singleSpace -
thisChunk
-
ITALIC_ANGLE
private static final float ITALIC_ANGLE- See Also:
-
keysAttributes
The allowed attributes in variableattributes
. -
keysNoStroke
The allowed attributes in variablenoStroke
. -
value
The value of this object. -
encoding
The encoding. -
font
The font for thisPdfChunk
. -
baseFont
-
splitCharacter
-
attributes
Metric attributes.This attributes require the mesurement of characters widths when rendering such as underline.
-
noStroke
Non metric attributes.This attributes do not require the mesurement of characters widths when rendering such as Color.
-
newlineSplit
protected boolean newlineSplittrue
if the chunk split was cause by a newline. -
offsetX
protected float offsetXThe offset in the x direction for the image -
offsetY
protected float offsetYThe offset in the y direction for the image -
changeLeading
protected boolean changeLeadingIndicates if the height and offset of the Image has to be taken into account
-
-
Constructor Details
-
PdfChunk
Constructs aPdfChunk
-object.- Parameters:
string
- the content of thePdfChunk
-objectother
- Chunk with the same style you want for the new Chunk
-
PdfChunk
Constructs aPdfChunk
-object.- Parameters:
chunk
- the originalChunk
-objectaction
- thePdfAction
if theChunk
comes from anAnchor
-
-
Method Details
-
getUnicodeEquivalent
public char getUnicodeEquivalent(char c) Gets the Unicode equivalent to a CID. The (inexistent) CIDis translated as '\n'. It has only meaning with CJK fonts with Identity encoding. - Parameters:
c
- the CID code- Returns:
- the Unicode equivalent
-
getWord
-
split
Splits thisPdfChunk
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.
-
truncate
Truncates thisPdfChunk
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.
-
font
PdfFont font()Returns the font of thisChunk
.- Returns:
- a
PdfFont
-
color
Color color()Returns the color of thisChunk
.- Returns:
- a
Color
-
width
float width()Returns the width of thisPdfChunk
.- Returns:
- a width
-
isNewlineSplit
public boolean isNewlineSplit()Checks if thePdfChunk
split was caused by a newline.- Returns:
true
if thePdfChunk
split was caused by a newline.
-
getWidthCorrected
public float getWidthCorrected(float charSpacing, float wordSpacing) Gets the width of thePdfChunk
taking into account the extra character and word spacing.- Parameters:
charSpacing
- the extra character spacingwordSpacing
- the extra word spacing- Returns:
- the calculated width
-
getTextRise
public float getTextRise()Gets the text displacement relatiev to the baseline.- Returns:
- a displacement in points
-
trimLastSpace
public float trimLastSpace()Trims the last space.- Returns:
- the width of the space trimmed, otherwise 0
-
getAttribute
Gets an attribute. The search is made inattributes
andnoStroke
.- Parameters:
name
- the attribute key- Returns:
- the attribute value or null if not found
-
isAttribute
Checks if the attribute exists.- Parameters:
name
- the attribute key- Returns:
true
if the attribute exists
-
isStroked
boolean isStroked()Checks if thisPdfChunk
needs some special metrics handling.- Returns:
true
if thisPdfChunk
needs some special metrics handling.
-
getImageOffsetY
float getImageOffsetY()Gets the image offset in the y direction- Returns:
- Gets the image offset in the y direction
-
setValue
sets the value.- Parameters:
value
- content of the Chunk
-
toString
-
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
-
getEncoding
String getEncoding()Gets the encoding of this string.- Returns:
- a
String
-
length
int length() -
isSplitCharacter
Checks if a character can be used to split aPdfString
.for the moment every character less than or equal to SPACE and the character '-' are 'splitCharacters'.
- Specified by:
isSplitCharacter
in interfaceSplitCharacter
- Parameters:
start
- start position in the arraycurrent
- current position in the arrayend
- end position in the arraycc
- the character array that has to be checkedck
- chunk array- Returns:
true
if the character can be used to split a string,false
otherwise
-
isExtSplitCharacter
-
trim
Removes all the ' ' and '-'-characters on the right of aString
.- Parameters:
string
- theString
that has to be trimmed.
- Returns:
- the trimmed
String
-
changeLeading
public boolean changeLeading() -
getCharWidth
float getCharWidth(char c) -
noPrint
public static boolean noPrint(char c)
-