Java tutorial
/* * JasperReports - Free Java Reporting Library. * Copyright (C) 2001 - 2013 Jaspersoft Corporation. All rights reserved. * http://www.jaspersoft.com * * Unless you have purchased a commercial license agreement from Jaspersoft, * the following license terms apply: * * This program is part of JasperReports. * * JasperReports is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JasperReports 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with JasperReports. If not, see <http://www.gnu.org/licenses/>. */ package net.sf.jasperreports.engine.export; import net.sf.jasperreports.engine.DefaultJasperReportsContext; import net.sf.jasperreports.engine.JRPrintText; import net.sf.jasperreports.engine.JasperReportsContext; import net.sf.jasperreports.engine.type.RunDirectionEnum; import com.lowagie.text.Element; import com.lowagie.text.pdf.PdfContentByte; /** * @author Teodor Danciu (teodord@users.sourceforge.net) * @version $Id: AbstractPdfTextRenderer.java 5878 2013-01-07 20:23:13Z teodord $ */ public abstract class AbstractPdfTextRenderer extends AbstractTextRenderer { /** * */ protected JRPdfExporter pdfExporter; protected PdfContentByte pdfContentByte; protected int horizontalAlignment; protected float leftOffsetFactor; protected float rightOffsetFactor; /** * @deprecated Replaced by {@link #AbstractPdfTextRenderer(JasperReportsContext, boolean)}. */ public AbstractPdfTextRenderer(boolean ignoreMissingFont) { this(DefaultJasperReportsContext.getInstance(), ignoreMissingFont); } /** * */ public AbstractPdfTextRenderer(JasperReportsContext jasperReportsContext, boolean ignoreMissingFont) { super(jasperReportsContext, false, ignoreMissingFont); } /** * */ public void initialize(JRPdfExporter pdfExporter, PdfContentByte pdfContentByte, JRPrintText text, int offsetX, int offsetY) { this.pdfExporter = pdfExporter; this.pdfContentByte = pdfContentByte; horizontalAlignment = Element.ALIGN_LEFT; leftOffsetFactor = 0f; rightOffsetFactor = 0f; //FIXMETAB 0.2f was a fair approximation switch (text.getHorizontalAlignmentValue()) { case JUSTIFIED: { horizontalAlignment = Element.ALIGN_JUSTIFIED_ALL; leftOffsetFactor = 0f; rightOffsetFactor = 0f; break; } case RIGHT: { if (text.getRunDirectionValue() == RunDirectionEnum.LTR) { horizontalAlignment = Element.ALIGN_RIGHT; } else { horizontalAlignment = Element.ALIGN_LEFT; } leftOffsetFactor = -0.2f; rightOffsetFactor = 0f; break; } case CENTER: { horizontalAlignment = Element.ALIGN_CENTER; leftOffsetFactor = -0.1f; rightOffsetFactor = 0.1f; break; } case LEFT: default: { if (text.getRunDirectionValue() == RunDirectionEnum.LTR) { horizontalAlignment = Element.ALIGN_LEFT; } else { horizontalAlignment = Element.ALIGN_RIGHT; } leftOffsetFactor = 0f; rightOffsetFactor = 0.2f; break; } } super.initialize(text, offsetX, offsetY); } }