- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList
-
- com.itextpdf.text.Phrase
-
- All Implemented Interfaces:
Element,TextElementArray,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable,java.util.Collection,java.util.List,java.util.RandomAccess
public class Phrase extends java.util.ArrayList implements TextElementArray
APhraseis a series ofChunks.A
Phrasehas a mainFont, but some chunks within the phrase can have aFontthat differs from the mainFont. All theChunks in aPhrasehave the sameleading.Example:
// When no parameters are passed, the default leading = 16 Phrase phrase0 = new Phrase(); Phrase phrase1 = new Phrase("this is a phrase"); // In this example the leading is passed as a parameter Phrase phrase2 = new Phrase(16, "this is a phrase with leading 16"); // When a Font is passed (explicitly or embedded in a chunk), the default leading = 1.5 * size of the font Phrase phrase3 = new Phrase("this is a phrase with a red, normal font Courier, size 12", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, new Color(255, 0, 0))); Phrase phrase4 = new Phrase(new Chunk("this is a phrase")); Phrase phrase5 = new Phrase(18, new Chunk("this is a phrase", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));- See Also:
Element,Chunk,Paragraph,Anchor, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected FontfontThis is the font of this phrase.protected HyphenationEventhyphenationNull, unless the Phrase has to be hyphenated.protected floatleadingThis is the leading of this phrase.-
Fields inherited from interface com.itextpdf.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE, YMARK
-
-
Constructor Summary
Constructors Constructor Description Phrase()Constructs aPhrasewithout specifying a leading.Phrase(float leading)Constructs aPhrasewith a certain leading.Phrase(float leading, Chunk chunk)Constructs aPhrasewith a certainChunkand a certain leading.Phrase(float leading, java.lang.String string)Constructs aPhrasewith a certain leading and a certainString.Phrase(float leading, java.lang.String string, Font font)Constructs aPhrasewith a certain leading, a certainStringand a certainFont.Phrase(Chunk chunk)Constructs aPhrasewith a certainChunk.Phrase(Phrase phrase)Copy constructor forPhrase.Phrase(java.lang.String string)Constructs aPhrasewith a certainString.Phrase(java.lang.String string, Font font)Constructs aPhrasewith a certainStringand a certainFont.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, java.lang.Object o)Adds aChunk, anAnchoror anotherPhraseto thisPhrase.booleanadd(java.lang.Object o)Adds aChunk,Anchoror anotherPhraseto thisPhrase.booleanaddAll(java.util.Collection collection)Adds a collection ofChunks to thisPhrase.protected booleanaddChunk(Chunk chunk)Adds a Chunk.protected voidaddSpecial(java.lang.Object object)Adds aObjectto theParagraph.java.util.ArrayListgetChunks()Gets all the chunks in this element.java.lang.StringgetContent()Returns the content as a String object.FontgetFont()Gets the font of the firstChunkthat appears in thisPhrase.HyphenationEventgetHyphenation()Getter for the hyphenation settings.static PhrasegetInstance(int leading, java.lang.String string)Gets a special kind of Phrase that changes some characters into corresponding symbols.static PhrasegetInstance(int leading, java.lang.String string, Font font)Gets a special kind of Phrase that changes some characters into corresponding symbols.static PhrasegetInstance(java.lang.String string)Gets a special kind of Phrase that changes some characters into corresponding symbols.floatgetLeading()Gets the leading of this phrase.booleanhasLeading()Checks you if the leading of this phrase is defined.booleanisContent()Checks if this element is a content object.booleanisEmpty()Checks is thisPhrasecontains no or 1 emptyChunk.booleanisNestable()Checks if this element is nestable.booleanprocess(ElementListener listener)Processes the element by adding it (or the different parts) to anElementListener.voidsetFont(Font font)Sets the main font of this phrase.voidsetHyphenation(HyphenationEvent hyphenation)Setter for the hyphenation.voidsetLeading(float leading)Sets the leading of this phrase.inttype()Gets the type of the text element.-
Methods inherited from class java.util.ArrayList
addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Field Detail
-
leading
protected float leading
This is the leading of this phrase.
-
font
protected Font font
This is the font of this phrase.
-
hyphenation
protected HyphenationEvent hyphenation
Null, unless the Phrase has to be hyphenated.- Since:
- 2.1.2
-
-
Constructor Detail
-
Phrase
public Phrase()
Constructs aPhrasewithout specifying a leading.
-
Phrase
public Phrase(Phrase phrase)
Copy constructor forPhrase.
-
Phrase
public Phrase(float leading)
Constructs aPhrasewith a certain leading.- Parameters:
leading- the leading
-
Phrase
public Phrase(Chunk chunk)
Constructs aPhrasewith a certainChunk.- Parameters:
chunk- aChunk
-
Phrase
public Phrase(float leading, Chunk chunk)Constructs aPhrasewith a certainChunkand a certain leading.- Parameters:
leading- the leadingchunk- aChunk
-
Phrase
public Phrase(java.lang.String string)
Constructs aPhrasewith a certainString.- Parameters:
string- aString
-
Phrase
public Phrase(java.lang.String string, Font font)Constructs aPhrasewith a certainStringand a certainFont.- Parameters:
string- aStringfont- aFont
-
Phrase
public Phrase(float leading, java.lang.String string)Constructs aPhrasewith a certain leading and a certainString.- Parameters:
leading- the leadingstring- aString
-
Phrase
public Phrase(float leading, java.lang.String string, Font font)Constructs aPhrasewith a certain leading, a certainStringand a certainFont.- Parameters:
leading- the leadingstring- aStringfont- aFont
-
-
Method Detail
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener.
-
type
public int type()
Gets the type of the text element.
-
getChunks
public java.util.ArrayList getChunks()
Gets all the chunks in this element.
-
isContent
public boolean isContent()
Description copied from interface:ElementChecks if this element is a content object. If not, it's a metadata object.- Specified by:
isContentin interfaceElement- Returns:
- true if this is a 'content' element; false if this is a 'metadata' element
- Since:
- iText 2.0.8
- See Also:
Element.isContent()
-
isNestable
public boolean isNestable()
Description copied from interface:ElementChecks if this element is nestable.- Specified by:
isNestablein interfaceElement- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
Element.isNestable()
-
add
public void add(int index, java.lang.Object o)Adds aChunk, anAnchoror anotherPhraseto thisPhrase.- Specified by:
addin interfacejava.util.List- Overrides:
addin classjava.util.ArrayList- Parameters:
index- index at which the specified element is to be insertedo- an object of typeChunk,AnchororPhrase- Throws:
java.lang.ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase
-
add
public boolean add(java.lang.Object o)
Adds aChunk,Anchoror anotherPhraseto thisPhrase.- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.List- Specified by:
addin interfaceTextElementArray- Overrides:
addin classjava.util.ArrayList- Parameters:
o- an object of typeChunk,AnchororPhrase- Returns:
- a boolean
- Throws:
java.lang.ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase
-
addAll
public boolean addAll(java.util.Collection collection)
Adds a collection ofChunks to thisPhrase.- Specified by:
addAllin interfacejava.util.Collection- Specified by:
addAllin interfacejava.util.List- Overrides:
addAllin classjava.util.ArrayList- Parameters:
collection- a collection ofChunks,Anchors andPhrases.- Returns:
trueif the action succeeded,falseif not.- Throws:
java.lang.ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase
-
addChunk
protected boolean addChunk(Chunk chunk)
Adds a Chunk.This method is a hack to solve a problem I had with phrases that were split between chunks in the wrong place.
- Parameters:
chunk- a Chunk to add to the Phrase- Returns:
- true if adding the Chunk succeeded
-
addSpecial
protected void addSpecial(java.lang.Object object)
Adds aObjectto theParagraph.- Parameters:
object- the object to add.
-
setLeading
public void setLeading(float leading)
Sets the leading of this phrase.- Parameters:
leading- the new leading
-
setFont
public void setFont(Font font)
Sets the main font of this phrase.- Parameters:
font- the new font
-
getLeading
public float getLeading()
Gets the leading of this phrase.- Returns:
- the linespacing
-
hasLeading
public boolean hasLeading()
Checks you if the leading of this phrase is defined.- Returns:
- true if the leading is defined
-
getFont
public Font getFont()
Gets the font of the firstChunkthat appears in thisPhrase.- Returns:
- a
Font
-
getContent
public java.lang.String getContent()
Returns the content as a String object. This method differs from toString because toString will return an ArrayList with the toString value of the Chunks in this Phrase.
-
isEmpty
public boolean isEmpty()
Checks is thisPhrasecontains no or 1 emptyChunk.- Specified by:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.List- Overrides:
isEmptyin classjava.util.ArrayList- Returns:
falseif thePhrasecontains more than one or more non-emptyChunks.
-
getHyphenation
public HyphenationEvent getHyphenation()
Getter for the hyphenation settings.- Returns:
- a HyphenationEvent
- Since:
- 2.1.2
-
setHyphenation
public void setHyphenation(HyphenationEvent hyphenation)
Setter for the hyphenation.- Parameters:
hyphenation- a HyphenationEvent instance- Since:
- 2.1.2
-
getInstance
public static final Phrase getInstance(java.lang.String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
string-- Returns:
- a newly constructed Phrase
-
getInstance
public static final Phrase getInstance(int leading, java.lang.String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading-string-- Returns:
- a newly constructed Phrase
-
-