Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2021 iText Group NV
Authors: Bruno Lowagie, Paulo Soares, et al.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
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 http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://itextpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using iText.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the iText software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping iText with a closed
source product.
For more information, please contact iText Software Corp. at this
address: [email protected]
*/
package com.itextpdf.layout.renderer;
import com.itextpdf.io.LogMessageConstant;
import com.itextpdf.io.util.MessageFormatUtil;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.layout.LayoutArea;
import com.itextpdf.layout.layout.LayoutContext;
import com.itextpdf.layout.layout.LayoutResult;
import com.itextpdf.layout.layout.LineLayoutContext;
import com.itextpdf.layout.layout.LineLayoutResult;
import com.itextpdf.layout.layout.MinMaxWidthLayoutResult;
import com.itextpdf.layout.margincollapse.MarginsCollapseHandler;
import com.itextpdf.layout.minmaxwidth.MinMaxWidth;
import com.itextpdf.layout.minmaxwidth.MinMaxWidthUtils;
import com.itextpdf.layout.property.BaseDirection;
import com.itextpdf.layout.property.FloatPropertyValue;
import com.itextpdf.layout.property.Leading;
import com.itextpdf.layout.property.OverflowPropertyValue;
import com.itextpdf.layout.property.ParagraphOrphansControl;
import com.itextpdf.layout.property.ParagraphWidowsControl;
import com.itextpdf.layout.property.Property;
import com.itextpdf.layout.property.RenderingMode;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* This class represents the {@link IRenderer renderer} object for a {@link Paragraph}
* object. It will draw the glyphs of the textual content on the {@link DrawContext}.
*/
public class ParagraphRenderer extends BlockRenderer {
@Deprecated
/**
* @deprecated will be removed in 7.2
*/
protected float previousDescent = 0;
protected List lines = null;
/**
* Creates a ParagraphRenderer from its corresponding layout object.
*
* @param modelElement the {@link com.itextpdf.layout.element.Paragraph} which this object should manage
*/
public ParagraphRenderer(Paragraph modelElement) {
super(modelElement);
}
/**
* {@inheritDoc}
*/
@Override
public LayoutResult layout(LayoutContext layoutContext) {
ParagraphOrphansControl orphansControl = this.getProperty(Property.ORPHANS_CONTROL);
ParagraphWidowsControl widowsControl = this.getProperty(Property.WIDOWS_CONTROL);
if (orphansControl != null || widowsControl != null) {
return OrphansWidowsLayoutHelper.orphansWidowsAwareLayout(this, layoutContext, orphansControl, widowsControl);
}
final LayoutResult layoutResult = directLayout(layoutContext);
updateParentLines(this);
updateParentLines((ParagraphRenderer) layoutResult.getSplitRenderer());
return layoutResult;
}
protected LayoutResult directLayout(LayoutContext layoutContext) {
boolean wasHeightClipped = false;
boolean wasParentsHeightClipped = layoutContext.isClippedHeight();
int pageNumber = layoutContext.getArea().getPageNumber();
boolean anythingPlaced = false;
boolean firstLineInBox = true;
LineRenderer currentRenderer = (LineRenderer) new LineRenderer().setParent(this);
Rectangle parentBBox = layoutContext.getArea().getBBox().clone();
MarginsCollapseHandler marginsCollapseHandler = null;
boolean marginsCollapsingEnabled = Boolean.TRUE.equals(getPropertyAsBoolean(Property.COLLAPSING_MARGINS));
if (marginsCollapsingEnabled) {
marginsCollapseHandler = new MarginsCollapseHandler(this, layoutContext.getMarginsCollapseInfo());
}
OverflowPropertyValue overflowX = this.getProperty(Property.OVERFLOW_X);
Boolean nowrapProp = this.getPropertyAsBoolean(Property.NO_SOFT_WRAP_INLINE);
currentRenderer.setProperty(Property.NO_SOFT_WRAP_INLINE, nowrapProp);
boolean notAllKidsAreFloats = false;
List floatRendererAreas = layoutContext.getFloatRendererAreas();
FloatPropertyValue floatPropertyValue = this.getProperty(Property.FLOAT);
float clearHeightCorrection = FloatingHelper.calculateClearHeightCorrection(this, floatRendererAreas, parentBBox);
FloatingHelper.applyClearance(parentBBox, marginsCollapseHandler, clearHeightCorrection, FloatingHelper.isRendererFloating(this));
Float blockWidth = retrieveWidth(parentBBox.getWidth());
if (FloatingHelper.isRendererFloating(this, floatPropertyValue)) {
blockWidth = FloatingHelper.adjustFloatedBlockLayoutBox(this, parentBBox, blockWidth, floatRendererAreas, floatPropertyValue, overflowX);
floatRendererAreas = new ArrayList<>();
}
if (0 == childRenderers.size()) {
anythingPlaced = true;
currentRenderer = null;
}
boolean isPositioned = isPositioned();
Float rotation = this.getPropertyAsFloat(Property.ROTATION_ANGLE);
Float blockMaxHeight = retrieveMaxHeight();
OverflowPropertyValue overflowY = (null == blockMaxHeight || blockMaxHeight > parentBBox.getHeight())
&& !wasParentsHeightClipped
? OverflowPropertyValue.FIT
: this.getProperty(Property.OVERFLOW_Y);
if (rotation != null || isFixedLayout()) {
parentBBox.moveDown(AbstractRenderer.INF - parentBBox.getHeight()).setHeight(AbstractRenderer.INF);
}
if (rotation != null && !FloatingHelper.isRendererFloating(this)) {
blockWidth = RotationUtils.retrieveRotatedLayoutWidth(parentBBox.getWidth(), this);
}
if (marginsCollapsingEnabled) {
marginsCollapseHandler.startMarginsCollapse(parentBBox);
}
Border[] borders = getBorders();
UnitValue[] paddings = getPaddings();
float additionalWidth = applyBordersPaddingsMargins(parentBBox, borders, paddings);
applyWidth(parentBBox, blockWidth, overflowX);
wasHeightClipped = applyMaxHeight(parentBBox, blockMaxHeight, marginsCollapseHandler, false, wasParentsHeightClipped, overflowY);
MinMaxWidth minMaxWidth = new MinMaxWidth(additionalWidth);
AbstractWidthHandler widthHandler = new MaxMaxWidthHandler(minMaxWidth);
List areas;
if (isPositioned) {
areas = Collections.singletonList(parentBBox);
} else {
areas = initElementAreas(new LayoutArea(pageNumber, parentBBox));
}
occupiedArea = new LayoutArea(pageNumber, new Rectangle(parentBBox.getX(), parentBBox.getY() + parentBBox.getHeight(), parentBBox.getWidth(), 0));
shrinkOccupiedAreaForAbsolutePosition();
TargetCounterHandler.addPageByID(this);
int currentAreaPos = 0;
Rectangle layoutBox = areas.get(0).clone();
lines = new ArrayList<>();
for (IRenderer child : childRenderers) {
notAllKidsAreFloats = notAllKidsAreFloats || !FloatingHelper.isRendererFloating(child);
currentRenderer.addChild(child);
}
float lastYLine = layoutBox.getY() + layoutBox.getHeight();
float previousDescent = 0;
float lastLineBottomLeadingIndent = 0;
boolean onlyOverflowedFloatsLeft = false;
List inlineFloatsOverflowedToNextPage = new ArrayList<>();
boolean floatOverflowedToNextPageWithNothing = false;
// rectangles are compared by instances
Set nonChildFloatingRendererAreas = new HashSet<>(floatRendererAreas);
if (marginsCollapsingEnabled && childRenderers.size() > 0) {
// passing null is sufficient to notify that there is a kid, however we don't care about it and it's margins
marginsCollapseHandler.startChildMarginsHandling(null, layoutBox);
}
boolean includeFloatsInOccupiedArea = BlockFormattingContextUtil.isRendererCreateBfc(this);
while (currentRenderer != null) {
currentRenderer.setProperty(Property.TAB_DEFAULT, this.getPropertyAsFloat(Property.TAB_DEFAULT));
currentRenderer.setProperty(Property.TAB_STOPS, this.