1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

24 package net.sf.jasperreports.engine.export;
25
26 import net.sf.jasperreports.engine.JRPrintText;
27 import net.sf.jasperreports.engine.JasperReportsContext;
28 import net.sf.jasperreports.engine.type.RunDirectionEnum;
29 import net.sf.jasperreports.engine.util.JRStyledText;
30 import net.sf.jasperreports.export.pdf.PdfProducer;
31 import net.sf.jasperreports.export.pdf.PdfTextAlignment;
32
33
34 /**
35  * @author Teodor Danciu (teodord@users.sourceforge.net)
36  */

37 public abstract class AbstractPdfTextRenderer extends AbstractTextRenderer
38 {
39     /**
40      * 
41      */

42     protected JRPdfExporter pdfExporter;
43     protected PdfProducer pdfProducer;
44     protected PdfTextAlignment horizontalAlignment;
45     protected float leftOffsetFactor;
46     protected float rightOffsetFactor;
47
48     
49     /**
50      * @deprecated Replaced by {@link #AbstractPdfTextRenderer(JasperReportsContext, booleanbooleanboolean)}.
51      */

52     public AbstractPdfTextRenderer(
53         JasperReportsContext jasperReportsContext, 
54         boolean ignoreMissingFont
55         )
56     {
57         this(jasperReportsContext, ignoreMissingFont, truefalse);
58     }
59     
60     
61     /**
62      * 
63      */

64     public AbstractPdfTextRenderer(
65         JasperReportsContext jasperReportsContext, 
66         boolean ignoreMissingFont,
67         boolean defaultIndentFirstLine,
68         boolean defaultJustifyLastLine
69         )
70     {
71         super(
72             jasperReportsContext, 
73             false
74             ignoreMissingFont, 
75             defaultIndentFirstLine, 
76             defaultJustifyLastLine
77             );
78     }
79     
80     
81     /**
82      * 
83      */

84     public void initialize(
85         JRPdfExporter pdfExporter, 
86         PdfProducer pdfProducer,
87         JRPrintText text, 
88         JRStyledText styledText, 
89         int offsetX,
90         int offsetY
91         )
92     {
93         this.pdfExporter = pdfExporter;
94         this.pdfProducer = pdfProducer;
95         
96         horizontalAlignment = PdfTextAlignment.LEFT;
97         leftOffsetFactor = 0f;
98         rightOffsetFactor = 0f;
99         
100         //FIXMETAB 0.2f was a fair approximation
101         switch (text.getHorizontalTextAlign())
102         {
103             case JUSTIFIED :
104             {
105                 horizontalAlignment = PdfTextAlignment.JUSTIFIED;
106                 leftOffsetFactor = 0f;
107                 rightOffsetFactor = 0f;
108                 break;
109             }
110             case RIGHT :
111             {
112                 if (text.getRunDirectionValue() == RunDirectionEnum.LTR)
113                 {
114                     horizontalAlignment = PdfTextAlignment.RIGHT;
115                 }
116                 else
117                 {
118                     horizontalAlignment =  PdfTextAlignment.LEFT;
119                 }
120                 leftOffsetFactor = -0.2f;
121                 rightOffsetFactor = 0f;
122                 break;
123             }
124             case CENTER :
125             {
126                 horizontalAlignment = PdfTextAlignment.CENTER;
127                 leftOffsetFactor = -0.1f;
128                 rightOffsetFactor = 0.1f;
129                 break;
130             }
131             case LEFT :
132             default :
133             {
134                 if (text.getRunDirectionValue() == RunDirectionEnum.LTR)
135                 {
136                     horizontalAlignment = PdfTextAlignment.LEFT;
137                 }
138                 else
139                 {
140                     horizontalAlignment = PdfTextAlignment.RIGHT;
141                 }
142                 leftOffsetFactor = 0f;
143                 rightOffsetFactor = 0.2f;
144                 break;
145             }
146         }
147
148         super.initialize(text, styledText, offsetX, offsetY);
149     }
150     
151     public abstract boolean addActualText();
152 }
153