Class PdfChunk
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfChunk
-
- All Implemented Interfaces:
SplitCharacter
public class PdfChunk extends java.lang.Object implements SplitCharacter
APdfChunkis the PDF translation of aChunk.A
PdfChunkis aPdfStringin a certainPdfFontandColor.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMapattributesMetric attributes.protected BaseFontbaseFontprotected booleanchangeLeadingIndicates if the height and offset of the Image has to be taken into accountprotected java.lang.StringencodingThe encoding.protected PdfFontfontThe font for thisPdfChunk.private static floatITALIC_ANGLEprivate static java.util.HashMapkeysAttributesThe allowed attributes in variableattributes.private static java.util.HashMapkeysNoStrokeThe allowed attributes in variablenoStroke.protected booleannewlineSplittrueif the chunk split was cause by a newline.protected java.util.HashMapnoStrokeNon metric attributes.protected floatoffsetXThe offset in the x direction for the imageprotected floatoffsetYThe offset in the y direction for the imageprivate static char[]singleSpaceprotected SplitCharactersplitCharacterprivate static PdfChunk[]thisChunkprotected java.lang.StringvalueThe value of this object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanchangeLeading()(package private) java.awt.Colorcolor()Returns the color of thisChunk.(package private) PdfFontfont()Returns the font of thisChunk.(package private) java.lang.ObjectgetAttribute(java.lang.String name)Gets an attribute.(package private) floatgetCharWidth(char c)(package private) java.lang.StringgetEncoding()Gets the encoding of this string.(package private) floatgetImageOffsetY()Gets the image offset in the y directionfloatgetTextRise()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 thePdfChunktaking into account the extra character and word spacing.protected intgetWord(java.lang.String text, int start)(package private) booleanisAttribute(java.lang.String name)Checks if the attribute exists.(package private) booleanisExtSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)booleanisNewlineSplit()Checks if thePdfChunksplit was caused by a newline.(package private) 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 aPdfString.(package private) booleanisStroked()Checks if thisPdfChunkneeds some special metrics handling.(package private) intlength()static booleannoPrint(char c)(package private) voidsetValue(java.lang.String value)sets the value.(package private) PdfChunksplit(float width)Splits thisPdfChunkif it's too long for the given width.java.lang.StringtoString()(package private) java.lang.Stringtrim(java.lang.String string)Removes all the ' ' and '-'-characters on the right of aString.floattrimLastSpace()Trims the last space.(package private) PdfChunktruncate(float width)Truncates thisPdfChunkif it's too long for the given width.(package private) floatwidth()Returns the width of thisPdfChunk.
-
-
-
Field Detail
-
singleSpace
private static final char[] singleSpace
-
thisChunk
private static final PdfChunk[] thisChunk
-
ITALIC_ANGLE
private static final float ITALIC_ANGLE
- See Also:
- Constant Field Values
-
keysAttributes
private static final java.util.HashMap keysAttributes
The allowed attributes in variableattributes.
-
keysNoStroke
private static final java.util.HashMap keysNoStroke
The allowed attributes in variablenoStroke.
-
value
protected java.lang.String value
The value of this object.
-
encoding
protected java.lang.String encoding
The encoding.
-
font
protected PdfFont font
The font for thisPdfChunk.
-
baseFont
protected BaseFont baseFont
-
splitCharacter
protected SplitCharacter splitCharacter
-
attributes
protected java.util.HashMap attributes
Metric attributes.This attributes require the mesurement of characters widths when rendering such as underline.
-
noStroke
protected java.util.HashMap noStroke
Non metric attributes.This attributes do not require the mesurement of characters widths when rendering such as Color.
-
newlineSplit
protected boolean newlineSplit
trueif the chunk split was cause by a newline.
-
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
-
changeLeading
protected boolean changeLeading
Indicates if the height and offset of the Image has to be taken into account
-
-
Constructor Detail
-
PdfChunk
PdfChunk(java.lang.String string, PdfChunk other)Constructs aPdfChunk-object.- Parameters:
string- the content of thePdfChunk-objectother- Chunk with the same style you want for the new Chunk
-
-
Method Detail
-
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
protected int getWord(java.lang.String text, int start)
-
split
PdfChunk split(float width)
Splits thisPdfChunkif it's too long for the given width.Returns null if the
PdfChunkwasn't truncated.- Parameters:
width- a given width- Returns:
- the
PdfChunkthat doesn't fit into the width.
-
truncate
PdfChunk truncate(float width)
Truncates thisPdfChunkif it's too long for the given width.Returns null if the
PdfChunkwasn't truncated.- Parameters:
width- a given width- Returns:
- the
PdfChunkthat doesn't fit into the width.
-
font
PdfFont font()
Returns the font of thisChunk.- Returns:
- a
PdfFont
-
color
java.awt.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 thePdfChunksplit was caused by a newline.- Returns:
trueif thePdfChunksplit was caused by a newline.
-
getWidthCorrected
public float getWidthCorrected(float charSpacing, float wordSpacing)Gets the width of thePdfChunktaking 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
java.lang.Object getAttribute(java.lang.String name)
Gets an attribute. The search is made inattributesandnoStroke.- Parameters:
name- the attribute key- Returns:
- the attribute value or null if not found
-
isAttribute
boolean isAttribute(java.lang.String name)
Checks if the attribute exists.- Parameters:
name- the attribute key- Returns:
trueif the attribute exists
-
isStroked
boolean isStroked()
Checks if thisPdfChunkneeds some special metrics handling.- Returns:
trueif thisPdfChunkneeds 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
void setValue(java.lang.String value)
sets the value.- Parameters:
value- content of the Chunk
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.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
java.lang.String getEncoding()
Gets the encoding of this string.- Returns:
- a
String
-
length
int length()
-
isSplitCharacter
public boolean isSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)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:
isSplitCharacterin 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:
trueif the character can be used to split a string,falseotherwise
-
isExtSplitCharacter
boolean isExtSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck)
-
trim
java.lang.String trim(java.lang.String string)
Removes all the ' ' and '-'-characters on the right of aString.- Parameters:
string- theStringthat has to be trimmed.- Returns:
- the trimmed
String
-
changeLeading
public boolean changeLeading()
-
getCharWidth
float getCharWidth(char c)
-
noPrint
public static boolean noPrint(char c)
-
-