Package com.itextpdf.text
Class Phrase
- All Implemented Interfaces:
Element,TextElementArray,Serializable,Cloneable,Iterable<Element>,Collection<Element>,List<Element>,RandomAccess,SequencedCollection<Element>
- Direct Known Subclasses:
Anchor,NoNewLineParagraph,Paragraph
A
Phrase is a series of Chunks.
A Phrase has a main Font, but some chunks
within the phrase can have a Font that differs from the
main Font. All the Chunks in a Phrase
have the same leading.
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FontThis is the font of this phrase.protected HyphenationEventNull, unless the Phrase has to be hyphenated.protected floatThis is the leading of this phrase.protected floatThe text leading that is multiplied by the biggest font size in the line.private static final longprotected TabSettingsPredefined tab position and properties(alignment, leader and etc.);Fields inherited from class java.util.AbstractList
modCountFields 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, BODY, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, DIV, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LANGUAGE, LIST, LISTITEM, MARKED, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK -
Constructor Summary
ConstructorsModifierConstructorDescriptionPhrase()Constructs aPhrasewithout specifying a leading.privatePhrase(boolean dummy) Constructs a Phrase that can be used in the static getInstance() method.Phrase(float leading) Constructs aPhrasewith a certain leading.Constructs aPhrasewith a certainChunkand a certain leading.Constructs aPhrasewith a certain leading and a certainString.Constructs aPhrasewith a certain leading, a certainStringand a certainFont.Constructs aPhrasewith a certainChunk.Copy constructor forPhrase.Constructs aPhrasewith a certainString.Constructs aPhrasewith a certainStringand a certainFont. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds aChunk, anAnchoror anotherPhraseto thisPhrase.booleanAdds aChunk,Anchoror anotherPhraseto thisPhrase.booleanAdds aStringto thisPhrase.booleanaddAll(Collection<? extends Element> collection) Adds a collection ofChunks to thisPhrase.protected booleanAdds a Chunk.protected voidaddSpecial(Element object) Adds anElementto theParagraph.Gets all the chunks in this element.Returns the content as a String object.getFont()Gets the font of the firstChunkthat appears in thisPhrase.Getter for the hyphenation settings.static final PhrasegetInstance(int leading, String string) Gets a special kind of Phrase that changes some characters into corresponding symbols.static final PhrasegetInstance(int leading, String string, Font font) Gets a special kind of Phrase that changes some characters into corresponding symbols.static final PhrasegetInstance(String string) Gets a special kind of Phrase that changes some characters into corresponding symbols.floatGets the leading of this phrase.floatGets the variable leadingGetter for the tab stops settings.floatGets the total leading.booleanChecks you if the leading of this phrase is defined.booleanChecks if this element is a content object.booleanisEmpty()Checks is thisPhrasecontains no or 1 emptyChunk.booleanChecks if this element is nestable.booleanprocess(ElementListener listener) Processes the element by adding it (or the different parts) to anElementListener.voidSets the main font of this phrase.voidsetHyphenation(HyphenationEvent hyphenation) Setter for the hyphenation.voidsetLeading(float fixedLeading) voidsetLeading(float fixedLeading, float multipliedLeading) Sets the leading fixed and variable.voidsetMultipliedLeading(float multipliedLeading) Sets the variable leading.voidsetTabSettings(TabSettings tabSettings) Setter for the tab stops.booleantrim()inttype()Gets the type of the text element.Methods inherited from class java.util.ArrayList
addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
leading
protected float leadingThis is the leading of this phrase. -
multipliedLeading
protected float multipliedLeadingThe text leading that is multiplied by the biggest font size in the line. -
font
This is the font of this phrase. -
hyphenation
Null, unless the Phrase has to be hyphenated.- Since:
- 2.1.2
-
tabSettings
Predefined tab position and properties(alignment, leader and etc.);- Since:
- 5.4.1
-
-
Constructor Details
-
Phrase
public Phrase()Constructs aPhrasewithout specifying a leading. -
Phrase
Copy constructor forPhrase.- Parameters:
phrase- the Phrase to copy
-
Phrase
public Phrase(float leading) Constructs aPhrasewith a certain leading.- Parameters:
leading- the leading
-
Phrase
Constructs aPhrasewith a certainChunk.- Parameters:
chunk- aChunk
-
Phrase
Constructs aPhrasewith a certainChunkand a certain leading.- Parameters:
leading- the leadingchunk- aChunk
-
Phrase
Constructs aPhrasewith a certainString.- Parameters:
string- aString
-
Phrase
Constructs aPhrasewith a certainStringand a certainFont.- Parameters:
string- aStringfont- aFont
-
Phrase
Constructs aPhrasewith a certain leading and a certainString.- Parameters:
leading- the leadingstring- aString
-
Phrase
Constructs aPhrasewith a certain leading, a certainStringand a certainFont.- Parameters:
leading- the leadingstring- aStringfont- aFont
-
Phrase
private Phrase(boolean dummy) Constructs a Phrase that can be used in the static getInstance() method.- Parameters:
dummy- a dummy parameter
-
-
Method Details
-
process
Processes the element by adding it (or the different parts) to anElementListener. -
type
public int type()Gets the type of the text element. -
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. -
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:
-
add
Adds aChunk, anAnchoror anotherPhraseto thisPhrase.- Specified by:
addin interfaceList<Element>- Overrides:
addin classArrayList<Element>- Parameters:
index- index at which the specified element is to be insertedelement- an object of typeChunk,AnchororPhrase- Throws:
ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase- Since:
- 5.0.1 (signature changed to use Element)
-
add
Adds aStringto thisPhrase.- Parameters:
s- a string- Returns:
- a boolean
- Since:
- 5.0.1
-
add
Adds aChunk,Anchoror anotherPhraseto thisPhrase.- Specified by:
addin interfaceCollection<Element>- Specified by:
addin interfaceList<Element>- Specified by:
addin interfaceTextElementArray- Overrides:
addin classArrayList<Element>- Parameters:
element- an object of typeChunk,AnchororPhrase- Returns:
- a boolean
- Throws:
ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase- Since:
- 5.0.1 (signature changed to use Element)
-
addAll
Adds a collection ofChunks to thisPhrase.- Specified by:
addAllin interfaceCollection<Element>- Specified by:
addAllin interfaceList<Element>- Overrides:
addAllin classArrayList<Element>- Parameters:
collection- a collection ofChunks,Anchors andPhrases.- Returns:
trueif the action succeeded,falseif not.- Throws:
ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase
-
addChunk
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
Adds anElementto theParagraph.- Parameters:
object- the object to add.
-
setLeading
public void setLeading(float fixedLeading, float multipliedLeading) Sets the leading fixed and variable. The resultant leading will be- If Phrase is added to the ColumnText: fixedLeading+multipliedLeading*maxFontSize, where maxFontSize is the size of the biggest font in the line;
- If Phrase is added to the PdfDocument: fixedLeading+multipliedLeading*phraseFontSize, where phraseFontSize is the size of the font applied to the current phrase.
- Parameters:
fixedLeading- the fixed leadingmultipliedLeading- the variable leading
-
setLeading
public void setLeading(float fixedLeading) - See Also:
-
setMultipliedLeading
public void setMultipliedLeading(float multipliedLeading) Sets the variable leading. The resultant leading will be- If Phrase is added to the ColumnText: fixedLeading+multipliedLeading*maxFontSize, where maxFontSize is the size of the biggest font in the line;
- If Phrase is added to the PdfDocument: fixedLeading+multipliedLeading*phraseFontSize, where phraseFontSize is the size of the font applied to the current phrase.
- Parameters:
multipliedLeading- the variable leading
-
setFont
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
-
getMultipliedLeading
public float getMultipliedLeading()Gets the variable leading- Returns:
- the leading
-
getTotalLeading
public float getTotalLeading()Gets the total leading. This method is based on the assumption that the font of the Paragraph is the font of all the elements that make part of the paragraph. This isn't necessarily true.- Returns:
- the total leading (fixed and multiplied)
-
hasLeading
public boolean hasLeading()Checks you if the leading of this phrase is defined.- Returns:
- true if the leading is defined
-
getFont
Gets the font of the firstChunkthat appears in thisPhrase.- Returns:
- a
Font
-
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.- Returns:
- the content
-
isEmpty
public boolean isEmpty()Checks is thisPhrasecontains no or 1 emptyChunk. -
getHyphenation
Getter for the hyphenation settings.- Returns:
- a HyphenationEvent
- Since:
- 2.1.2
-
setHyphenation
Setter for the hyphenation.- Parameters:
hyphenation- a HyphenationEvent instance- Since:
- 2.1.2
-
getTabSettings
Getter for the tab stops settings.- Returns:
- a HyphenationEvent
- Since:
- 5.4.1
-
setTabSettings
Setter for the tab stops.- Parameters:
tabSettings- tab settings- Since:
- 5.4.1
-
getInstance
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
string-- Returns:
- a newly constructed Phrase
-
getInstance
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading-string-- Returns:
- a newly constructed Phrase
-
getInstance
Gets a special kind of Phrase that changes some characters into corresponding symbols.- Parameters:
leading-string-font-- Returns:
- a newly constructed Phrase
-
trim
public boolean trim()
-