com.itextpdf.layout.element.Paragraph Maven / Gradle / Ivy
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package com.itextpdf.layout.element;
import com.itextpdf.kernel.pdf.tagging.StandardRoles;
import com.itextpdf.kernel.pdf.tagutils.DefaultAccessibilityProperties;
import com.itextpdf.kernel.pdf.tagutils.AccessibilityProperties;
import com.itextpdf.layout.properties.Leading;
import com.itextpdf.layout.properties.ParagraphOrphansControl;
import com.itextpdf.layout.properties.ParagraphWidowsControl;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.layout.renderer.IRenderer;
import com.itextpdf.layout.renderer.ParagraphRenderer;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
/**
* A layout element that represents a self-contained block of textual and
* graphical information.
* It is a {@link BlockElement} which essentially acts as a container for
* {@link ILeafElement leaf elements}.
*/
public class Paragraph extends BlockElement {
protected DefaultAccessibilityProperties tagProperties;
/**
* Creates a Paragraph.
*/
public Paragraph() {
}
/**
* Creates a Paragraph, initialized with a piece of text.
*
* @param text the initial textual content, as a {@link String}
*/
public Paragraph(String text) {
this(new Text(text));
}
/**
* Creates a Paragraph, initialized with a piece of text.
*
* @param text the initial textual content, as a {@link Text}
*/
public Paragraph(Text text) {
add(text);
}
/**
* Adds a piece of text to this {@link Paragraph}.
*
* @param text the content to be added, as a {@link String}
* @return this {@link Paragraph}
*/
public Paragraph add(String text) {
return add(new Text(text));
}
/**
* Adds a {@link ILeafElement element} to this {@link Paragraph}.
*
* @param element the content to be added, any {@link ILeafElement}
* @return this {@link Paragraph}
*/
public Paragraph add(ILeafElement element) {
childElements.add(element);
return this;
}
/**
* Adds an {@link IBlockElement element} to this {@link Paragraph}.
*
* @param element the content to be added, any {@link IBlockElement}
* @return this {@link Paragraph}
*/
public Paragraph add(IBlockElement element) {
childElements.add(element);
return this;
}
/**
* Adds a {@link java.util.List} of layout elements to this {@link Paragraph}.
*
* @param elements the content to be added
* @param any {@link ILeafElement}
* @return this {@link Paragraph}
*/
public Paragraph addAll(java.util.List elements) {
for (ILeafElement element : elements) {
add(element);
}
return this;
}
/**
* Adds an unspecified amount of tabstop elements as properties to this {@link Paragraph}.
*
* @param tabStops the {@link TabStop tabstop(s)} to be added as properties
* @return this {@link Paragraph}
* @see TabStop
*/
public Paragraph addTabStops(TabStop... tabStops) {
addTabStopsAsProperty(Arrays.asList(tabStops));
return this;
}
/**
* Adds a {@link java.util.List} of tabstop elements as properties to this {@link Paragraph}.
*
* @param tabStops the list of {@link TabStop}s to be added as properties
* @return this {@link Paragraph}
* @see TabStop
*/
public Paragraph addTabStops(java.util.List tabStops) {
addTabStopsAsProperty(tabStops);
return this;
}
/**
* Removes a tabstop position from the Paragraph, if it is present in the
* {@link Property#TAB_STOPS} property.
*
* @param tabStopPosition the {@link TabStop} position to be removed.
* @return this Paragraph
* @see TabStop
*/
public Paragraph removeTabStop(float tabStopPosition) {
Map tabStops = this.