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 java.text.AttributedCharacterIterator;
27 import java.text.AttributedString;
28
29 import net.sf.jasperreports.engine.JRPrintText;
30 import net.sf.jasperreports.engine.JasperReportsContext;
31 import net.sf.jasperreports.engine.type.RunDirectionEnum;
32 import net.sf.jasperreports.engine.util.JRStyledText;
33 import net.sf.jasperreports.export.pdf.PdfPhrase;
34 import net.sf.jasperreports.export.pdf.PdfProducer;
35 import net.sf.jasperreports.export.pdf.PdfTextAlignment;
36 import net.sf.jasperreports.export.pdf.TextDirection;
37
38
39 /**
40  * @author Teodor Danciu (teodord@users.sourceforge.net)
41  */

42 public class SimplePdfTextRenderer extends AbstractPdfTextRenderer
43 {
44     private float yLine = 0;
45     
46     /**
47      * @deprecated Replaced by {@link #SimplePdfTextRenderer(JasperReportsContext, booleanbooleanboolean)}.
48      */

49     public SimplePdfTextRenderer(
50         JasperReportsContext jasperReportsContext, 
51         boolean ignoreMissingFont
52         )
53     {
54         this(jasperReportsContext, ignoreMissingFont, truefalse);
55     }
56     
57     
58     /**
59      * 
60      */

61     public SimplePdfTextRenderer(
62         JasperReportsContext jasperReportsContext, 
63         boolean ignoreMissingFont,
64         boolean defaultIndentFirstLine,
65         boolean defaultJustifyLastLine
66         )
67     {
68         super(
69             jasperReportsContext, 
70             ignoreMissingFont,
71             defaultIndentFirstLine,
72             defaultJustifyLastLine
73             );
74     }
75
76     
77     @Override
78     public void initialize(
79         JRPdfExporter pdfExporter, 
80         PdfProducer pdfProducer,
81         JRPrintText text, 
82         JRStyledText styledText, 
83         int offsetX,
84         int offsetY
85         )
86     {
87         super.initialize(
88             pdfExporter, 
89             pdfProducer,
90             text, 
91             styledText, 
92             offsetX,
93             offsetY
94             );
95         
96         yLine = 
97             pdfExporter.getCurrentPageFormat().getPageHeight()
98                 - y
99                 - topPadding
100                 - verticalAlignOffset
101                 - text.getLeadingOffset();
102     }
103
104     
105     @Override
106     public void render()
107     {
108         super.render();
109     }
110
111     
112     @Override
113     protected void renderParagraph(
114         AttributedCharacterIterator allParagraphs,
115         int paragraphStart,
116         String paragraphText
117         )
118     {
119         AttributedString paragraph = null;
120         
121         if (paragraphText == null)
122         {
123             paragraphText = " ";
124             paragraph = 
125                 new AttributedString(
126                     paragraphText,
127                     new AttributedString(
128                         allParagraphs, 
129                         paragraphStart, 
130                         paragraphStart + paragraphText.length()
131                         ).getIterator().getAttributes()
132                     );
133         }
134         else
135         {
136             paragraph = 
137                 new AttributedString(
138                     allParagraphs, 
139                     paragraphStart, 
140                     paragraphStart + paragraphText.length()
141                     );
142         }
143         
144         PdfPhrase phrase = pdfProducer.createPhrase();
145         pdfExporter.getPhrase(paragraph, paragraphText, text, phrase);
146         yLine = phrase.go(
147             x + leftPadding,
148             yLine,
149             x + width - rightPadding,
150             pdfExporter.getCurrentPageFormat().getPageHeight()
151                 - y
152                 - height
153                 + bottomPadding,
154             0,//text.getLineSpacingFactor(),// * text.getFont().getSize(),
155             text.getLineSpacingFactor(),
156             horizontalAlignment == PdfTextAlignment.JUSTIFIED && (isLastParagraph && justifyLastLine) 
157                 ? PdfTextAlignment.JUSTIFIED_ALL : horizontalAlignment,
158             text.getRunDirectionValue() == RunDirectionEnum.LTR
159                 ? TextDirection.LTR : TextDirection.RTL
160             );
161     }
162
163
164     @Override
165     protected AttributedString getAttributedString()
166     {
167         return styledText.getAttributedString();
168     }
169
170
171     @Override
172     public void draw()
173     {
174         //nothing to do
175     }
176
177
178     @Override
179     public boolean addActualText()
180     {
181         return false;
182     }
183 }
184