Class Phrase
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
java.util.ArrayList
com.gitlab.pdftk_java.com.lowagie.text.Phrase
- All Implemented Interfaces:
Element, MarkupAttributes, TextElementArray, Serializable, Cloneable, Iterable, Collection, List, RandomAccess, SequencedCollection
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 (explicitely 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 floatThis is the leading of this phrase.protected PropertiesContains extra markupAttributesprivate static final longFields inherited from class AbstractList
modCountFields inherited from interface 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, GRAPHIC, HEADER, IMGRAW, IMGTEMPLATE, JPEG, KEYWORDS, LIST, LISTITEM, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE -
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.Constructs aPhrasewith a certainString.Constructs aPhrasewith a certainStringand a certainFont.Phrase(Properties attributes) Returns aPhrasethat has been constructed taking in account the value of some attributes. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds aChunk, anAnchoror anotherPhraseto thisPhrase.booleanAdds aChunk,Anchoror anotherPhraseto thisPhrase.booleanaddAll(Collection collection) Adds a collection ofChunks to thisPhrase.private booleanAdds a Chunk.protected voidaddSpecial(Object object) Adds aObjectto theParagraph.font()Gets the font of the firstChunkthat appears in thisPhrase.Gets all the chunks in this element.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.getMarkupAttribute(String name) Returns the value of the specified attribute.Returns aSetofStringattribute names for theMarkupAttributesimplementor.Return aProperties-object containing all the markupAttributes.booleanisEmpty()Checks is thisPhrasecontains no or 1 emptyChunk.static booleanChecks if a given tag corresponds with this object.floatleading()Gets the leading of this phrase.booleanChecks you if the leading of this phrase is defined.booleanprocess(ElementListener listener) Processes the element by adding it (or the different parts) to anElementListener.voidsetLeading(float leading) Sets the leading of this phrase.voidsetMarkupAttribute(String name, String value) Sets the specified attribute.voidsetMarkupAttributes(Properties markupAttributes) Sets the markupAttributes.inttype()Gets the type of the text element.Methods inherited from class 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 AbstractCollection
containsAll, toStringMethods inherited from interface Collection
parallelStream, stream, toArrayMethods inherited from interface List
containsAll, reversed
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
leading
protected float leadingThis is the leading of this phrase. -
font
This is the font of this phrase. -
markupAttributes
Contains extra markupAttributes
-
-
Constructor Details
-
Phrase
private Phrase(boolean dummy) Constructs a Phrase that can be used in the static getInstance() method.- Parameters:
dummy- a dummy parameter
-
Phrase
public Phrase()Constructs aPhrasewithout specifying a leading. -
Phrase
public Phrase(float leading) Constructs aPhrasewith a certain leading.- Parameters:
leading- the leading
-
Phrase
-
Phrase
Constructs aPhrasewith a certainChunkand a certain leading.- Parameters:
leading- the leadingchunk- aChunk
-
Phrase
Constructs aPhrasewith a certainString.- Parameters:
string- aString
-
Phrase
-
Phrase
Constructs aPhrasewith a certain leading and a certainString.- Parameters:
leading- the leadingstring- aString
-
Phrase
-
Phrase
Returns aPhrasethat has been constructed taking in account the value of some attributes.- Parameters:
attributes- Some attributes
-
-
Method Details
-
getInstance
-
getInstance
-
getInstance
-
process
Processes the element by adding it (or the different parts) to anElementListener. -
type
-
getChunks
-
add
Adds aChunk, anAnchoror anotherPhraseto thisPhrase.- Specified by:
addin interfaceList- Overrides:
addin classArrayList- Parameters:
index- index at which the specified element is to be insertedo- an object of typeChunk,AnchororPhrase- Throws:
ClassCastException- when you try to add something that isn't aChunk,AnchororPhrase
-
add
Adds aChunk,Anchoror anotherPhraseto thisPhrase.- Specified by:
addin interfaceCollection- Specified by:
addin interfaceList- Specified by:
addin interfaceTextElementArray- Overrides:
addin classArrayList- Parameters:
o- an object of typeChunk,AnchororPhrase- Returns:
- a boolean
- 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
-
addAll
Adds a collection ofChunks to thisPhrase.- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceList- Overrides:
addAllin classArrayList- 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
-
addSpecial
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
-
isEmpty
-
leadingDefined
public boolean leadingDefined()Checks you if the leading of this phrase is defined.- Returns:
- true if the leading is defined
-
leading
public float leading()Gets the leading of this phrase.- Returns:
- the linespacing
-
font
-
isTag
Checks if a given tag corresponds with this object.- Parameters:
tag- the given tag- Returns:
- true if the tag corresponds
-
setMarkupAttribute
Description copied from interface:MarkupAttributesSets the specified attribute.- Specified by:
setMarkupAttributein interfaceMarkupAttributes- Parameters:
name-Stringattribute name.value-Stringattribute value.- See Also:
-
setMarkupAttributes
Description copied from interface:MarkupAttributesSets the markupAttributes.- Specified by:
setMarkupAttributesin interfaceMarkupAttributes- Parameters:
markupAttributes- aProperties-object containing markupattributes- See Also:
-
getMarkupAttribute
Description copied from interface:MarkupAttributesReturns the value of the specified attribute.- Specified by:
getMarkupAttributein interfaceMarkupAttributes- Parameters:
name-Stringattribute name.- Returns:
String.- See Also:
-
getMarkupAttributeNames
Description copied from interface:MarkupAttributesReturns aSetofStringattribute names for theMarkupAttributesimplementor.- Specified by:
getMarkupAttributeNamesin interfaceMarkupAttributes- Returns:
Set.- See Also:
-
getMarkupAttributes
Description copied from interface:MarkupAttributesReturn aProperties-object containing all the markupAttributes.- Specified by:
getMarkupAttributesin interfaceMarkupAttributes- Returns:
Properties- See Also:
-