1
24 package net.sf.jasperreports.export.pdf.classic;
25
26 import com.lowagie.text.DocumentException;
27 import com.lowagie.text.Phrase;
28 import com.lowagie.text.pdf.ColumnText;
29 import com.lowagie.text.pdf.PdfWriter;
30
31 import net.sf.jasperreports.engine.JRRuntimeException;
32 import net.sf.jasperreports.export.pdf.PdfChunk;
33 import net.sf.jasperreports.export.pdf.PdfPhrase;
34 import net.sf.jasperreports.export.pdf.PdfTextAlignment;
35 import net.sf.jasperreports.export.pdf.TextDirection;
36
37
41 public class ClassicPhrase implements PdfPhrase
42 {
43
44 private ClassicPdfProducer pdfProducer;
45 private Phrase phrase;
46
47 public ClassicPhrase(ClassicPdfProducer pdfProducer, Phrase phrase)
48 {
49 this.pdfProducer = pdfProducer;
50 this.phrase = phrase;
51 }
52
53 @Override
54 public void add(PdfChunk chunk)
55 {
56 phrase.add(((ClassicChunk) chunk).getChunk());
57 }
58
59 @Override
60 public float go(float llx, float lly, float urx, float ury,
61 float fixedLeading, float multipliedLeading,
62 PdfTextAlignment alignment, TextDirection runDirection)
63 {
64 ColumnText colText = new ColumnText(pdfProducer.getPdfContentByte());
65 colText.setSimpleColumn(phrase,
66 llx, lly, urx, ury,
67 fixedLeading,
68 ClassicPdfUtils.toITextAlignment(alignment));
69 if (multipliedLeading != 0f)
70 {
71 colText.setLeading(fixedLeading, multipliedLeading);
72 }
73 colText.setRunDirection(toITextRunDirection(runDirection));
74 try
75 {
76 colText.go();
77 }
78 catch (DocumentException e)
79 {
80 throw new JRRuntimeException(e);
81 }
82 return colText.getYLine();
83 }
84
85 protected static int toITextRunDirection(TextDirection direction)
86 {
87 int iTextDirection;
88 switch (direction)
89 {
90 case DEFAULT:
91 iTextDirection = PdfWriter.RUN_DIRECTION_DEFAULT;
92 break;
93 case LTR:
94 iTextDirection = PdfWriter.RUN_DIRECTION_LTR;
95 break;
96 case RTL:
97 iTextDirection = PdfWriter.RUN_DIRECTION_RTL;
98 break;
99 default:
100 throw new JRRuntimeException("Unknown text direction " + direction);
101 }
102 return iTextDirection;
103 }
104
105 }
106