public class Phrase extends ArrayList implements TextElementArray
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)));
Element,
Chunk,
Paragraph,
Anchor,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected Font |
font
This is the font of this phrase.
|
protected float |
leading
This is the leading of this phrase.
|
modCountALIGN_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 and Description |
|---|
Phrase()
Constructs a
Phrase without specifying a leading. |
Phrase(Chunk chunk)
Constructs a
Phrase with a certain Chunk. |
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. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
Object o)
Adds a
Chunk, an Anchor or another Phrase
to this Phrase. |
boolean |
add(Object o)
Adds a
Chunk, Anchor or another Phrase
to this Phrase. |
boolean |
addAll(Collection collection)
Adds a collection of
Chunks
to this Phrase. |
protected void |
addSpecial(Object object)
Adds a
Object to the Paragraph. |
ArrayList |
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.
|
float |
getLeading()
Gets the leading of this phrase.
|
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.
|
int |
type()
Gets the type of the text element.
|
addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeequals, hashCodecontainsAll, toStringfinalize, getClass, notify, notifyAll, toString, wait, wait, waitcontainsAll, equals, hashCodeparallelStream, streamprotected float leading
protected Font font
public Phrase()
Phrase without specifying a leading.public Phrase(Chunk chunk)
Phrase with a certain Chunk.chunk - a Chunkpublic Phrase(String string)
Phrase with a certain String.string - a Stringpublic boolean process(ElementListener listener)
ElementListener.public int type()
public ArrayList getChunks()
public boolean isContent()
ElementisContent in interface ElementElement.isContent()public boolean isNestable()
ElementisNestable in interface ElementElement.isNestable()public void add(int index,
Object o)
Chunk, an Anchor or another Phrase
to this Phrase.add in interface Listadd in class ArrayListindex - index at which the specified element is to be insertedo - an object of type Chunk, Anchor or PhraseClassCastException - when you try to add something that isn't a Chunk, Anchor or Phrasepublic boolean add(Object o)
Chunk, Anchor or another Phrase
to this Phrase.add in interface TextElementArrayadd in interface Collectionadd in interface Listadd in class ArrayListo - an object of type Chunk, Anchor or PhraseClassCastException - when you try to add something that isn't a Chunk, Anchor or Phrasepublic boolean addAll(Collection collection)
Chunks
to this Phrase.addAll in interface CollectionaddAll in interface ListaddAll in class ArrayListcollection - a collection of Chunks, Anchors and Phrases.true if the action succeeded, false if not.ClassCastException - when you try to add something that isn't a Chunk, Anchor or Phraseprotected void addSpecial(Object object)
Object to the Paragraph.object - the object to add.public void setLeading(float leading)
leading - the new leadingpublic void setFont(Font font)
font - the new fontpublic float getLeading()
public Font getFont()
Chunk that appears in this Phrase.Fontpublic String getContent()
public boolean isEmpty()
Phrase contains no or 1 empty Chunk.public HyphenationEvent getHyphenation()
public void setHyphenation(HyphenationEvent hyphenation)
hyphenation - a HyphenationEvent instanceCopyright © 2021. All rights reserved.