public class Phrase extends ArrayList<Element> implements TextElementArray
Phrase
is a series of Chunk
s.
A Phrase
has a main Font
, but some chunks within the phrase can have a Font
that differs from the main Font
. All the Chunk
s 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 HyphenationEvent |
hyphenation
Null, unless the Phrase has to be hyphenated.
|
protected float |
leading
This is the leading of this phrase.
|
protected float |
multipliedLeading
The text leading that is multiplied by the biggest font size in the line.
|
protected TabSettings |
tabSettings
Predefined tab position and properties(alignment, leader and etc.);
|
modCount
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 and Description |
---|
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 .
|
Modifier and Type | Method and Description |
---|---|
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 Chunk s 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.
|
float |
getMultipliedLeading()
Gets the variable leading
|
TabSettings |
getTabSettings()
Getter for the tab stops settings.
|
float |
getTotalLeading()
Gets the total leading.
|
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 fixedLeading) |
void |
setLeading(float fixedLeading, float multipliedLeading)
Sets the leading fixed and variable.
|
void |
setMultipliedLeading(float multipliedLeading)
Sets the variable leading.
|
void |
setTabSettings(TabSettings tabSettings)
Setter for the tab stops.
|
boolean |
trim() |
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, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
containsAll, equals, hashCode
parallelStream, stream
protected float leading
protected float multipliedLeading
protected Font font
protected HyphenationEvent hyphenation
protected TabSettings tabSettings
public Phrase()
Phrase
without specifying a leading.
public Phrase(Phrase phrase)
Phrase
.
phrase
- the Phrase to copy
public Phrase(float leading)
Phrase
with a certain leading.
leading
- the leading
public Phrase(Chunk chunk)
Phrase
with a certain Chunk
.
chunk
- a Chunk
public Phrase(float leading, Chunk chunk)
Phrase
with a certain Chunk
and a certain leading.
leading
- the leading
chunk
- a Chunk
public Phrase(String string)
Phrase
with a certain String
.
string
- a String
public Phrase(String string, Font font)
Phrase
with a certain String
and a certain Font
.
string
- a String
font
- a Font
public Phrase(float leading, String string)
Phrase
with a certain leading and a certain String
.
leading
- the leading
string
- a String
public boolean process(ElementListener listener)
ElementListener
.
public int type()
public boolean isContent()
Element
isContent
in interface Element
Element.isContent()
public boolean isNestable()
Element
isNestable
in interface Element
Element.isNestable()
public void add(int index, Element element)
Chunk
, an Anchor
or another Phrase
to this Phrase
.
add
in interface List<Element>
add
in class ArrayList<Element>
index
- index at which the specified element is to be inserted
element
- an object of type Chunk
, Anchor
or Phrase
ClassCastException
- when you try to add something that isn't a Chunk
, Anchor
or Phrase
public boolean add(String s)
String
to this Phrase
.
s
- a string
public boolean add(Element element)
Chunk
, Anchor
or another Phrase
to this Phrase
.
add
in interface TextElementArray
add
in interface Collection<Element>
add
in interface List<Element>
add
in class ArrayList<Element>
element
- an object of type Chunk
, Anchor
or Phrase
ClassCastException
- when you try to add something that isn't a Chunk
, Anchor
or Phrase
public boolean addAll(Collection extends Element> collection)
Chunk
s to this Phrase
.
addAll
in interface Collection<Element>
addAll
in interface List<Element>
addAll
in class ArrayList<Element>
collection
- a collection of Chunk
s, Anchor
s and Phrase
s.
true
if the action succeeded, false
if not.
ClassCastException
- when you try to add something that isn't a Chunk
, Anchor
or Phrase
protected boolean addChunk(Chunk chunk)
This method is a hack to solve a problem I had with phrases that were split between chunks in the wrong place.
chunk
- a Chunk to add to the Phrase
protected void addSpecial(Element object)
Element
to the Paragraph
.
object
- the object to add.
public void setLeading(float fixedLeading, float multipliedLeading)
fixedLeading
- the fixed leading
multipliedLeading
- the variable leading
public void setLeading(float fixedLeading)
setLeading(float)
public void setMultipliedLeading(float multipliedLeading)
multipliedLeading
- the variable leading
public void setFont(Font font)
font
- the new font
public float getLeading()
public float getMultipliedLeading()
public float getTotalLeading()
public boolean hasLeading()
public Font getFont()
Chunk
that appears in this Phrase
.
Font
public String getContent()
public boolean isEmpty()
Phrase
contains no or 1 empty Chunk
.
public HyphenationEvent getHyphenation()
public void setHyphenation(HyphenationEvent hyphenation)
hyphenation
- a HyphenationEvent instance
public TabSettings getTabSettings()
public void setTabSettings(TabSettings tabSettings)
tabSettings
- tab settings
public static final Phrase getInstance(String string)
string
-
public static final Phrase getInstance(int leading, String string)
leading
-
string
-
public static final Phrase getInstance(int leading, String string, Font font)
leading
-
string
-
font
-
public boolean trim()
Copyright © 1998–2022. All rights reserved.