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-2024 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.forms.form.renderer;
import com.itextpdf.forms.fields.AbstractPdfFormField;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.forms.form.element.IFormField;
import com.itextpdf.forms.util.BorderStyleUtil;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
import com.itextpdf.layout.layout.LayoutArea;
import com.itextpdf.layout.layout.LayoutContext;
import com.itextpdf.layout.layout.LayoutResult;
import com.itextpdf.layout.properties.Background;
import com.itextpdf.layout.properties.BoxSizingPropertyValue;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.TextAlignment;
import com.itextpdf.layout.properties.TransparentColor;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.layout.renderer.IRenderer;
import com.itextpdf.layout.renderer.LineRenderer;
import com.itextpdf.layout.renderer.ParagraphRenderer;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract {@link AbstractFormFieldRenderer} for form fields with text content.
*/
public abstract class AbstractTextFieldRenderer extends AbstractFormFieldRenderer {
/**
* The font to be used for the text.
*/
protected PdfFont font;
/**
* Creates a new {@link AbstractTextFieldRenderer} instance.
*
* @param modelElement the model element
*/
AbstractTextFieldRenderer(IFormField modelElement) {
super(modelElement);
}
/**
* Creates a paragraph renderer.
*
* @param defaultValue the default value
* @return the renderer
*/
IRenderer createParagraphRenderer(String defaultValue) {
if (defaultValue.isEmpty()) {
defaultValue = "\u00a0";
}
Text text = new Text(defaultValue);
FormFieldValueNonTrimmingTextRenderer nextRenderer = new FormFieldValueNonTrimmingTextRenderer(text);
text.setNextRenderer(nextRenderer);
return new Paragraph(text).setMargin(0).createRendererSubTree();
}
/**
* Applies the default field properties.
*
* @param inputField the input field
*/
void applyDefaultFieldProperties(PdfFormField inputField) {
inputField.getWidgets().get(0).setHighlightMode(PdfAnnotation.HIGHLIGHT_NONE);
TransparentColor color = getPropertyAsTransparentColor(Property.FONT_COLOR);
if (color != null) {
inputField.setColor(color.getColor());
}
inputField.setJustification(this.getProperty(Property.TEXT_ALIGNMENT));
BorderStyleUtil.applyBorderProperty(this, inputField.getFirstFormAnnotation());
Background background = this.getProperty(Property.BACKGROUND);
if (background != null) {
inputField.getFirstFormAnnotation().setBackgroundColor(background.getColor());
}
}
float getHeightRowsBased(List lines, Rectangle bBox, int rows) {
float averageLineHeight = bBox.getHeight() / lines.size();
return averageLineHeight * rows;
}
/**
* Updates the font.
*
* @param renderer the renderer
*/
void updatePdfFont(ParagraphRenderer renderer) {
Object retrievedFont;
if (renderer != null) {
List lines = renderer.getLines();
if (lines != null) {
for (LineRenderer line : lines) {
for (IRenderer child : line.getChildRenderers()) {
retrievedFont = child.