com.itextpdf.text
Class Phrase

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Element>
              extended by com.itextpdf.text.Phrase
All Implemented Interfaces:
Element, TextElementArray, Serializable, Cloneable, Iterable<Element>, Collection<Element>, List<Element>, RandomAccess
Direct Known Subclasses:
Anchor, Paragraph

public class Phrase
extends ArrayList<Element>
implements TextElementArray

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:
Element, Chunk, Paragraph, Anchor, Serialized Form

Field Summary
protected  Font font
          This is the font of this phrase.
protected  HyphenationEvent hyphenation
          Null, unless the Phrase has to be hyphenated.
protected  float leading
          This is the leading of this phrase.
protected  TabSettings tabSettings
          Predefined tab position and properties(alignment, leader and etc.);
 
Fields inherited from class java.util.AbstractList
modCount
 
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, 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
Phrase()
          Constructs a Phrase without specifying a leading.
Phrase(Chunk chunk)
          Constructs a Phrase with a certain Chunk.
Phrase(float leading)
          Constructs a Phrase with a certain leading.
Phrase(float leading, Chunk chunk)
          Constructs a Phrase with a certain Chunk and a certain leading.
Phrase(float leading, String string)
          Constructs a Phrase with a certain leading and a certain String.
Phrase(float leading, String string, Font font)
          Constructs a Phrase with a certain leading, a certain String and a certain Font.
Phrase(Phrase phrase)
          Copy constructor for Phrase.
Phrase(String string)
          Constructs a Phrase with a certain String.
Phrase(String string, Font font)
          Constructs a Phrase with a certain String and a certain Font.
 
Method Summary
 boolean add(Element element)
          Adds a Chunk, Anchor or another Phrase to this Phrase.
 void add(int index, Element element)
          Adds a Chunk, an Anchor or another Phrase to this Phrase.
 boolean add(String s)
          Adds a String to this Phrase.
 boolean addAll(Collection<? extends Element> collection)
          Adds a collection of Chunks to this Phrase.
protected  boolean addChunk(Chunk chunk)
          Adds a Chunk.
protected  void addSpecial(Element object)
          Adds an Element to the Paragraph.
 List<Chunk> getChunks()
          Gets all the chunks in this element.
 String getContent()
          Returns the content as a String object.
 Font getFont()
          Gets the font of the first Chunk that appears in this Phrase.
 HyphenationEvent getHyphenation()
          Getter for the hyphenation settings.
static Phrase getInstance(int leading, String string)
          Gets a special kind of Phrase that changes some characters into corresponding symbols.
static Phrase getInstance(int leading, String string, Font font)
          Gets a special kind of Phrase that changes some characters into corresponding symbols.
static Phrase getInstance(String string)
          Gets a special kind of Phrase that changes some characters into corresponding symbols.
 float getLeading()
          Gets the leading of this phrase.
 TabSettings getTabSettings()
          Getter for the tab stops settings.
 float getTotalLeading()
           
 boolean hasLeading()
          Checks you if the leading of this phrase is defined.
 boolean isContent()
          Checks if this element is a content object.
 boolean isEmpty()
          Checks is this Phrase contains no or 1 empty Chunk.
 boolean isNestable()
          Checks if this element is nestable.
 boolean process(ElementListener listener)
          Processes the element by adding it (or the different parts) to an ElementListener.
 void setFont(Font font)
          Sets the main font of this phrase.
 void setHyphenation(HyphenationEvent hyphenation)
          Setter for the hyphenation.
 void setLeading(float leading)
          Sets the leading of this phrase.
 void setTabSettings(TabSettings tabSettings)
          Setter for the tab stops.
 boolean trim()
           
 int type()
          Gets the type of the text element.
 
Methods inherited from class java.util.ArrayList
addAll, clear, clone, contains, ensureCapacity, get, indexOf, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.itextpdf.text.Element
toString
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

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

tabSettings

protected TabSettings tabSettings
Predefined tab position and properties(alignment, leader and etc.);

Since:
5.4.1
Constructor Detail

Phrase

public Phrase()
Constructs a Phrase without specifying a leading.


Phrase

public Phrase(Phrase phrase)
Copy constructor for Phrase.

Parameters:
phrase - the Phrase to copy

Phrase

public Phrase(float leading)
Constructs a Phrase with a certain leading.

Parameters:
leading - the leading

Phrase

public Phrase(Chunk chunk)
Constructs a Phrase with a certain Chunk.

Parameters:
chunk - a Chunk

Phrase

public Phrase(float leading,
              Chunk chunk)
Constructs a Phrase with a certain Chunk and a certain leading.

Parameters:
leading - the leading
chunk - a Chunk

Phrase

public Phrase(String string)
Constructs a Phrase with a certain String.

Parameters:
string - a String

Phrase

public Phrase(String string,
              Font font)
Constructs a Phrase with a certain String and a certain Font.

Parameters:
string - a String
font - a Font

Phrase

public Phrase(float leading,
              String string)
Constructs a Phrase with a certain leading and a certain String.

Parameters:
leading - the leading
string - a String

Phrase

public Phrase(float leading,
              String string,
              Font font)
Constructs a Phrase with a certain leading, a certain String and a certain Font.

Parameters:
leading - the leading
string - a String
font - a Font
Method Detail

process

public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to an ElementListener.

Specified by:
process in interface Element
Parameters:
listener - an ElementListener
Returns:
true if the element was processed successfully

type

public int type()
Gets the type of the text element.

Specified by:
type in interface Element
Returns:
a type

getChunks

public List<Chunk> getChunks()
Gets all the chunks in this element.

Specified by:
getChunks in interface Element
Returns:
an ArrayList

isContent

public boolean isContent()
Description copied from interface: Element
Checks if this element is a content object. If not, it's a metadata object.

Specified by:
isContent in interface Element
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: Element
Checks if this element is nestable.

Specified by:
isNestable in interface Element
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,
                Element element)
Adds a Chunk, an Anchor or another Phrase to this Phrase.

Specified by:
add in interface List<Element>
Overrides:
add in class ArrayList<Element>
Parameters:
index - index at which the specified element is to be inserted
element - an object of type Chunk, Anchor or Phrase
Throws:
ClassCastException - when you try to add something that isn't a Chunk, Anchor or Phrase
Since:
5.0.1 (signature changed to use Element)

add

public boolean add(String s)
Adds a String to this Phrase.

Parameters:
s - a string
Returns:
a boolean
Since:
5.0.1

add

public boolean add(Element element)
Adds a Chunk, Anchor or another Phrase to this Phrase.

Specified by:
add in interface TextElementArray
Specified by:
add in interface Collection<Element>
Specified by:
add in interface List<Element>
Overrides:
add in class ArrayList<Element>
Parameters:
element - an object of type Chunk, Anchor or Phrase
Returns:
a boolean
Throws:
ClassCastException - when you try to add something that isn't a Chunk, Anchor or Phrase
Since:
5.0.1 (signature changed to use Element)

addAll

public boolean addAll(Collection<? extends Element> collection)
Adds a collection of Chunks to this Phrase.

Specified by:
addAll in interface Collection<Element>
Specified by:
addAll in interface List<Element>
Overrides:
addAll in class ArrayList<Element>
Parameters:
collection - a collection of Chunks, Anchors and Phrases.
Returns:
true if the action succeeded, false if not.
Throws:
ClassCastException - when you try to add something that isn't a Chunk, Anchor or Phrase

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(Element object)
Adds an Element to the Paragraph.

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

getTotalLeading

public float getTotalLeading()

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 first Chunk that appears in this Phrase.

Returns:
a Font

getContent

public 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.

Returns:
the content

isEmpty

public boolean isEmpty()
Checks is this Phrase contains no or 1 empty Chunk.

Specified by:
isEmpty in interface Collection<Element>
Specified by:
isEmpty in interface List<Element>
Overrides:
isEmpty in class ArrayList<Element>
Returns:
false if the Phrase contains 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

getTabSettings

public TabSettings getTabSettings()
Getter for the tab stops settings.

Returns:
a HyphenationEvent
Since:
5.4.1

setTabSettings

public void setTabSettings(TabSettings tabSettings)
Setter for the tab stops.

Parameters:
tabSettings - tab settings
Since:
5.4.1

getInstance

public static final Phrase getInstance(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,
                                       String string)
Gets a special kind of Phrase that changes some characters into corresponding symbols.

Parameters:
leading -
string -
Returns:
a newly constructed Phrase

getInstance

public static final Phrase getInstance(int leading,
                                       String string,
                                       Font font)
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()


Copyright © 2013. All Rights Reserved.