KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > faceless > pdf > PDFStyle


1 // $Id: PDFStyle.java,v 1.6 2003/11/04 17:16:01 mike Exp $
2

3 package org.faceless.pdf;
4
5 import java.util.*;
6 import java.awt.Color JavaDoc;
7 import java.awt.Paint JavaDoc;
8 import java.awt.GradientPaint JavaDoc;
9
10 /**
11  * <p>
12  * A PDFStyle controls the colors, font and many other aspects of the actual
13  * display of elements on a PDF page. It's conceptually similar to a CSS
14  * style used with HTML markup.
15  * </p>
16  * <p>
17  * The idea behind the PDFStyle class is that you create a style and then
18  * apply it to the page. This means you can switch from one style to another
19  * with a single command, and switch back just as easily. It makes defining
20  * a consistant "feel" to your document much easier than it would if you had
21  * to set the font and color separately.
22  * </p>
23  * <b>Example</b>
24  * <pre>
25  * import java.awt.Color;
26  *
27  * // Create a new style "normal": 12pt black Times-Roman, with
28  * // line-spacing of 1.5
29  * PDFStyle normal = new PDFStyle();
30  * normal.setFont(new StandardFont(StandardFont.TIMES), 12);
31  * normal.setFillColor(Color.black);
32  * normal.setTextLineSpacing(1.5);
33  *
34  * // Create a new varient of "normal": 12pt red Times-Italic with
35  * // the same line-spacing
36  * PDFStyle italic = (PDFStyle)normal.clone();
37  * normal.setFont(new StandardFont(StandardFont.TIMESITALIC), 12);
38  * normal.setFillColor(Color.red);
39  *
40  * // Create a style to draw a box around the text in green, with a
41  * // line width of 2 points
42  * PDFStyle boxstyle = new PDFStyle();
43  * boxstyle.setLineColor(Color.green);
44  * boxstyle.setLineWeighting(2);
45  *
46  * // Now use these styles in a document
47  * PDF p = new PDF();
48  * PDFPage page = p.newPage(PDF.PAGESIZE_A4);
49  * page.setStyle(normal);
50  * page.drawText("This is in 12pt black Times Roman", 100, 100);
51  * page.setStyle(italic);
52  * page.drawText("This is in 12pt red Times Italic", 100, 120);
53  *
54  * // Draw a box around them in green
55  * page.setStyle(boxstyle);
56  * page.drawRectangle(90,90, 200, 40);
57  * </pre>
58  *
59  * <p>
60  * This shows several useful aspects of styles:
61  * <ul>
62  * <li>Styles can easily be extended by using the <code>clone()</code> method.</li>
63  * <li>Not all the aspects of a style need to be set.</li>
64  * <li>Styles can be given meaningful names.</li>
65  * </ul>
66  * </p>
67  * @version $Revision: 1.6 $
68  */

69 public class PDFStyle extends PeeredObject implements Cloneable JavaDoc
70 {
71     /**
72      * Set the text alignment for this style to left-aligned
73      */

74     public static final int TEXTALIGN_LEFT = 1;
75
76     /**
77      * Set the text alignment for this style to right-aligned
78      */

79     public static final int TEXTALIGN_RIGHT = 2;
80
81     /**
82      * Set the text alignment for this style to centered
83      */

84     public static final int TEXTALIGN_CENTER = 4;
85
86     /**
87      * Set the text alignment for this style to justified (the default).
88      * Justification is only useful when text is written within a paragraph.
89      * When a single element of text is drawn, the effect is the same as
90      * left-alignment.
91      */

92     public static final int TEXTALIGN_JUSTIFY = 8;
93
94     /**
95      * Set the vertical text alignment for this style to baseline (the default).
96      */

97     public static final int TEXTALIGN_BASELINE = 0;
98
99     /**
100      * Set the vertical text alignment for this style to top
101      */

102     public static final int TEXTALIGN_TOP = 16;
103
104     /**
105      * Set the vertical text alignment for this style to middle
106      */

107     public static final int TEXTALIGN_MIDDLE = 32;
108
109     /**
110      * Set the vertical text alignment for this style to bottom
111      */

112     public static final int TEXTALIGN_BOTTOM = 64;
113
114     /**
115      * Set the end of a line to be squared off at the end. There is no
116      * projection beyond the end of the path. This is the default
117      */

118     public static final int LINECAP_BUTT = 0;
119
120     /**
121      * Set the end of a line to be rounded at the end. Effectively draws a circle with
122      * a diameter of the line width at the end of each line.
123      */

124     public static final int LINECAP_ROUND = 1;
125
126     /**
127      * Set the end of a line to be squared at the end. Effectively extends each line by
128      * half the linewidth.
129      */

130     public static final int LINECAP_SQUARE = 2;
131
132     /**
133      * Sets the join style of two lines so that the lines are extended so they meet at
134      * a point (like a picture frame). For extremely sharp angles, this will automatically
135      * be converted to a LINEJOIN_BEVEL. This is the default.
136      */

137     public static final int LINEJOIN_MITER = 0;
138
139     /**
140      * Sets the join style of two lines so that the lines are rounded, equivalent to
141      * drawing a circle with a diameter of the linewidth where the lines meet.
142      */

143     public static final int LINEJOIN_ROUND = 1;
144
145     /**
146      * Sets the join style of two lines so that the lines are beveled. The two lines
147      * are drawn with LINECAP_BUTT ends, and the notch between the two segments is
148      * filled in with a triangle.
149      */

150     public static final int LINEJOIN_BEVEL = 2;
151
152     /**
153      * Set any text rendered in this style to be filled with the styles
154      * FillColor (the default)
155      */

156     public static final int FONTSTYLE_FILLED = 0;
157
158     /**
159      * Set any text rendered in this style to be drawn as a hollow outline
160      * with the styles LineColor (the default)
161      */

162     public static final int FONTSTYLE_OUTLINE = 1;
163
164     /**
165      * Set any text rendered in this style to be filled with the styles
166      * FillColor, then to be outlined with the styles' LineColor
167      */

168     public static final int FONTSTYLE_FILLEDOUTLINE = 2;
169
170     /**
171      * Set any text rendered in this style to be invisible. This becomes
172      * useful in applications like OCR, where the original scanned image
173      * is displayed on the screen and invisible text written above it,
174      * allowing the text to be cut and pasted.
175      */

176     public static final int FONTSTYLE_INVISIBLE = 3;
177
178     /**
179      * A parameter to {@link #setPaintMethod} to set the paint method to
180      * use the non-zero winding number method to determine which areas are
181      * inside or outside a shape. This is the default.
182      */

183     public static final int PAINTMETHOD_NONZEROWINDING = 0;
184
185     /**
186      * A parameter to {@link #setPaintMethod} to set the paint method to
187      * use the even-odd method to determine which areas are inside or
188      * outside a shape.
189      */

190     public static final int PAINTMETHOD_EVENODD = 1;
191
192
193     final org.faceless.pdf2.PDFStyle style;
194
195     Object JavaDoc getPeer()
196     {
197         return style;
198     }
199
200     PDFStyle(org.faceless.pdf2.PDFStyle style)
201     {
202         this.style=style;
203     }
204
205     /**
206      * A PDFStyle which can be passed in to {@link PDFPage#beginTextLink}
207      * to underline the text links.
208      */

209     public static final PDFStyle LINKSTYLE;
210
211     static {
212         LINKSTYLE = new PDFStyle();
213     LINKSTYLE.setTextUnderline(true);
214     }
215
216     /**
217      * Create a new PDFStyle. The default aspects of this style are:
218      * <ul>
219      * <li>No Font specified, no line color, no fill color. These must be set by the user</li>
220      * <li>Line Weighting of 1 point</li>
221      * <li>Line Dashing set to a solid line</li>
222      * <li>Line Spacing set to a 1</li>
223      * <li>Text Justification ratio of 0.5</li>
224      * <li>Line ends set to {@link #LINECAP_BUTT}</li>
225      * <li>Line joints set to {@link #LINEJOIN_MITER}</li>
226      * <li>Font style set to {@link #FONTSTYLE_FILLED}</li>
227      * <li>Text alignment is locale dependent - for hebrew, arabic, urdu and yiddish, it's {@link #TEXTALIGN_RIGHT}. For japanese, chinese and korean, it's {@link #TEXTALIGN_LEFT} and for everything else it's {@link #TEXTALIGN_JUSTIFY}.</li>
228      * </ul>
229      */

230     public PDFStyle()
231     {
232     style = new org.faceless.pdf2.PDFStyle();
233     }
234
235     /**
236      * Set the text justification ratio for a style. When a line of text
237      * is padded to justify it against two margins, there is always the
238      * the option of extending the space between each character, extending
239      * the space between each word, or a combination of the two. The
240      * "justification ratio" determines how much to apply to each. A ratio
241      * of 0 means "only extend the spaces between words", a ratio of 1
242      * means "only extend the spaces between letters". The default is 0.5.
243      */

244     public void setTextJustificationRatio(float in)
245     {
246     style.setTextJustificationRatio(in);
247     }
248
249     /**
250      * Set whether text rendered with this style is underlined or not.
251      * The exact position and width of the underlining is font specific.
252      * The default is <i>false</i>.
253      * @since 1.1
254      */

255     public void setTextUnderline(boolean on)
256     {
257     style.setTextUnderline(on);
258     }
259
260     /**
261      * Set whether text rendered with this style is struck-out or not.
262      * The default is <i>false</i>.
263      * @since 1.1
264      */

265     public void setTextStrikeOut(boolean on)
266     {
267     style.setTextStrikeOut(on);
268     }
269
270     /**
271      * Set the line cap style. Value can be {@link #LINECAP_BUTT}, {@link #LINECAP_ROUND} or
272      * {@link #LINECAP_SQUARE}
273      * <p>
274      * Changes to this setting midway through a <code>path</code> don't
275      * take effect until it is closed.
276      * </p>
277      */

278     public void setLineCap(int type)
279     {
280     style.setLineCap(type);
281     }
282
283     /**
284      * Set the line join style. Value can be {@link #LINEJOIN_MITER}, {@link #LINEJOIN_ROUND} or
285      * {@link #LINEJOIN_BEVEL}
286      * <p>
287      * Changes to this setting midway through a <code>path</code> don't
288      * take effect until it is closed.
289      * </p>
290      */

291     public void setLineJoin(int type)
292     {
293     style.setLineJoin(type);
294     }
295
296     /**
297      * <p>
298      * Set the line dashing pattern. The first <code>on</code> points of
299      * the line will be drawn, then the next <code>off</code> points of
300      * the line will be skipped. The <code>phase</code> argument defines
301      * how far into this pattern to start.
302      * </p>
303      * <p>
304      * An example would be <code>setLineDash(2,2,0)</code> to draw lines that
305      * have two points on, two points off and so on, starting with two "on"
306      * points. For solid lines, the call should
307      * be <code>setLineDash(0,0,0)</code>
308      * </p>
309      * <p>
310      * Changes to this setting midway through a <code>path</code> don't
311      * take effect until it is closed.
312      * </p>
313      * Since 1.1.5, the parameters are floats rather than ints
314      * @param on how many points of the line to draw
315      * @param off how many points of the line to skip
316      * @param phase how far into the pattern to start
317      */

318     public void setLineDash(float on, float off, float phase)
319     {
320     style.setLineDash(on,off,phase);
321     }
322
323     /**
324      * Set the line weighting, for fonts and geometric shapes drawn as
325      * outlines. The minimum possible value is zero, which indicates to
326      * the PDF renderer to use the thinnest line possible. On high-resolution
327      * devices, this will become nearly invisible. Because of its
328      * device-dependent nature, it's not recommended.
329      * <p>
330      * Changes to this setting midway through a <code>path</code> don't
331      * take effect until it is closed.
332      * </p>
333      *
334      * @param thickness The thickness of the line, in points
335      */

336     public void setLineWeighting(float thickness)
337     {
338     style.setLineWeighting(thickness);
339     }
340
341     /**
342      * <p>
343      * Set the spacing between lines of text. In versions prior to 1.1,
344      * this was a multiplied by the the fonts point size to give the difference
345      * between the baselines of two successive lines of text, and the default
346      * value was 1.2.
347      * </p><p>
348      * Since 1.1, this has been changed to a ratio of the <i>default spacing
349      * between lines for this font</i> (as determined by the
350      * {@link PDFFont#getDefaultLeading} method). This allows individual fonts to set
351      * their preferred line spacing more accurately.
352      * Although the default setting should result in nearly identical results
353      * for most fonts, developers calling this method who are upgrading from
354      * versions 1.0.4 or earlier should divide the value passed in by 1.2 to
355      * meet the new method contract.
356      * </p><p>
357      * The default value is now 1. A value of 1.5 sets line-and-a-half spacing,
358      * a value of 2 gives double spacing, and so on.
359      * </p>
360      * @param factor the spacing between lines
361      */

362     public void setTextLineSpacing(float factor)
363     {
364     style.setTextLineSpacing(factor);
365     }
366
367     /**
368      * Set the text-alignment. Can be one of {@link #TEXTALIGN_LEFT},
369      * {@link #TEXTALIGN_RIGHT}, {@link #TEXTALIGN_CENTER} or {@link #TEXTALIGN_JUSTIFY}.
370      */

371     public void setTextAlign(int align)
372     {
373     style.setTextAlign(align);
374     }
375
376     /**
377      * <p>
378      * Set the text vertical offset - the distance between the standard
379      * baseline and the basline for this style, as a proportion of the
380      * font size. This is mainly used for superscripting or subscripting.
381      * text.
382      * </p><p>
383      * As an example, if you wanted to create a line of text that was 6 points
384      * high and 6 points above the standard baseline, set the font size to
385      * 6 and the TextRise() to 1. (1x6 = 6 points above the baseline).
386      * To place the same text 3 points below the baseline, set the offset to -0.5.
387      * </p>
388      * @since 1.1
389      */

390     public void setTextRise(float offset)
391     {
392     style.setTextRise(offset);
393     }
394
395     /**
396      * <p>
397      * Set the fill color. For text, this is the color of the text.
398      * For geometric shapes, this is paint to fill those shapes with.
399      * To draw only outlines, set it to <code>null</code> (the default).
400      * </p><p>
401      * Prior to release 1.2, this method took a
402      * {@link java.awt.Color} as an argument, but this has been changed to
403      * its superclass, {@link java.awt.Paint}, instead.
404      * Although most of the time the parameter will still be a plain color,
405      * this change allows a {@link java.awt.GradientPaint} to be used
406      * as well.
407      * </p>
408      * @param paint the paint to use, or <code>null</code> if no fill
409      * is required.
410      */

411     public void setFillColor(Paint JavaDoc paint)
412     {
413     if (paint!=null && paint instanceof ColorPattern) {
414         paint = ((ColorPattern)paint).pattern;
415     }
416     style.setFillColor(paint);
417     }
418
419     /**
420      * Set the line color. For text, this is the color of the outline of
421      * the text. For geometric shapes, this is color to draw the outlines
422      * of those shapes. If no outline is required, set it to
423      * <code>null</code> (the default).
424      * @param color The Color to use, or <code>null</code> if no outline
425      * is required.
426      */

427     public void setLineColor(Color JavaDoc color)
428     {
429     style.setLineColor(color);
430     }
431
432     /**
433      * <p>
434      * Set the paint method to either {@link #PAINTMETHOD_EVENODD} or
435      * {@link #PAINTMETHOD_NONZEROWINDING} (the default). The paint method
436      * determines which area of a self-intersecting polygon is filled. If
437      * your polygons aren't self-intersecting, it has no effect.
438      * </p><p>
439      * This setting is very obscure and is really only here for completeness.
440      * For a full discussion of the difference see the <a HREF="http://partners.adobe.com/asn/developer/acrosdk/docs/PDFRef.pdf">PDF Reference manual version 1.3</a>, page 156.
441      * </p>
442      * @since 1.1.5
443      */

444     public void setPaintMethod(int method)
445     {
446     int newmethod = style.PAINTMETHOD_EVENODD;
447     if (method==PAINTMETHOD_NONZEROWINDING) newmethod = style.PAINTMETHOD_NONZEROWINDING;
448     style.setPaintMethod(newmethod);
449     }
450
451     /**
452      * Set the font and font size for the style.
453      * @param font the <code>PDFFont</code> to use
454      * @param size the size of the font, in points
455      */

456     public void setFont(PDFFont font, float size)
457     {
458     style.setFont(font==null ? null : font.font, size);
459     }
460
461     /**
462      * Add a backup font to the current style. Backup fonts are used when
463      * the standard font doesn't have a character defined - for example, creating
464      * a style with the "Times Roman" font and then adding a backup font of
465      * "Symbol" would allow text to be written in both English and Greek without
466      * changing styles. As many backup fonts as are required may be added.
467      * @param font the font to add as a backup for the current style.
468      * @since 1.2
469      */

470     public void addBackupFont(PDFFont font)
471     {
472     style.addBackupFont(font==null ? null : font.font);
473     }
474
475     /**
476      * Get the specified backup font. The argument to this method determines
477      * which backup font to return - zero for the first, one for the second and
478      * so on.
479      * @param i the backup font to return
480      * @return the specified backup font, or <code>null</code> if no backup font
481      * exists at that index.
482      * @since 1.2
483      */

484     public PDFFont getBackupFont(int i)
485     {
486     return (PDFFont)PeeredObject.getPeer(style.getBackupFont(i));
487     }
488
489     /**
490      * Set the font render style. Can be one of {@link #FONTSTYLE_FILLED}
491      * (the default), {@link #FONTSTYLE_OUTLINE},
492      * {@link #FONTSTYLE_FILLEDOUTLINE} or {@link #FONTSTYLE_INVISIBLE}.
493      * @since 1.1
494      */

495     public void setFontStyle(int fontstyle)
496     {
497     int newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_FILLED;
498     if (fontstyle==FONTSTYLE_OUTLINE) newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_OUTLINE;
499     else if (fontstyle==FONTSTYLE_FILLEDOUTLINE) newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_FILLEDOUTLINE;
500     else if (fontstyle==FONTSTYLE_INVISIBLE) newfontstyle=org.faceless.pdf2.PDFStyle.FONTSTYLE_INVISIBLE;
501     style.setFontStyle(newfontstyle);
502     }
503
504     /**
505      * <p>
506      * Set the number of points to indent the first line of any text
507      * drawn in this style. Positive values result in the first line
508      * being indented to the right, negative values in the first line
509      * being indented to the left (this is reversed for RTL scripts)
510      * </p><p>
511      * Note that mixing styles with different text-indent levels on
512      * the first line of text in a paragraph will result in
513      * unpredictable results.
514      * </p>
515      * @since 1.1.21
516      */

517     public void setTextIndent(float indent)
518     {
519     style.setTextIndent(indent);
520     }
521
522     /**
523      * Get the length of the specified string in points, using the
524      * styles font and font size. The line of text must not contain
525      * any newlines. For horizontal fonts, this is equivalent to
526      * <code>getTextRight()-getTextLeft()</code>.
527      * This method takes track-kerning into account.
528      */

529     public float getTextLength(String JavaDoc s)
530     {
531     return style.getTextLength(s);
532     }
533
534     /**
535      * Get the length of the specified string in points, using the
536      * styles font and font size. As for {@link #getTextLength(String)}
537      * but takes a char array, and the text must be {@link PDFFont#ligaturize ligaturized}
538      * first if necessary.
539      * @since 1.2.1
540      */

541     public float getTextLength(char[] c, int off, int len)
542     {
543     return style.getTextLength(c,off,len);
544     }
545
546     /**
547      * Get the left-most X co-ordinate of the specified string in points if it
548      * was rendered at (0,0), using the styles font and font size. The line of
549      * text must not contain any newlines.
550      * This method takes track-kerning into account.
551      */

552     public float getTextLeft(String JavaDoc s)
553     {
554     return style.getTextLeft(s);
555     }
556
557     /**
558      * Get the right-most X co-ordinate of the specified string in points if it
559      * was rendered at (0,0), using the styles font and font size. The line of
560      * text must not contain any newlines.
561      * This method takes track-kerning into account.
562      */

563     public float getTextRight(String JavaDoc s)
564     {
565     return style.getTextRight(s);
566     }
567
568     /**
569      * Get the top-most Y co-ordinate of the specified string in points if it
570      * was rendered at (0,0), using the styles font and font size. The line of
571      * text must not contain any newlines.
572      * This method takes track-kerning into account.
573      */

574     public float getTextTop(String JavaDoc s)
575     {
576     return style.getTextTop(s);
577     }
578
579     /**
580      * Get the bottom-most Y co-ordinate of the specified string in points if it
581      * was rendered at (0,0), using the styles font and font size. The line of
582      * text must not contain any newlines.
583      * This method takes track-kerning into account.
584      */

585     public float getTextBottom(String JavaDoc s)
586     {
587     return style.getTextBottom(s);
588     }
589
590     /**
591      * Get the text leading for this styles in points. The leading is the
592      * distance between the baseline of two successive lines of text, and
593      * is defined as:<BR>
594      * <code>getFontSize() * font.getDefaultLeading() * getLineSpacing()</code>
595      */

596     public float getFontLeading()
597     {
598     return style.getFontLeading();
599     }
600
601     /**
602      * Get the styles line thickness, in points.
603      */

604     public float getLineWeighting()
605     {
606     return style.getLineWeighting();
607     }
608
609     /**
610      * Get the paint method as set by {@link #setPaintMethod}
611      */

612     public int getPaintMethod()
613     {
614     return PAINTMETHOD_EVENODD;
615     }
616
617     /**
618      * Get the spacing between lines of text, as a ratio of default spacing
619      * between lines of this point size - i.e. the value is "1" for single
620      * spaced, "2" for double spaced and so on.
621      */

622     public float getTextLineSpacing()
623     {
624     return style.getTextLineSpacing();
625     }
626
627     /**
628      * Get the styles text justification ratio
629      */

630     public float getTextJustificationRatio()
631     {
632     return 0.5f;
633     }
634
635     /**
636      * Get whether the style has text underlining set
637      */

638     public boolean getTextUnderline()
639     {
640     return false;
641     }
642
643     /**
644      * Get whether the style has text strikeout set
645      */

646     public boolean getTextStrikeOut()
647     {
648     return false;
649     }
650
651     /**
652      * Get the styles' fill color. Since 1.2, this method returns a
653      * {@link java.awt.Paint} instead of its subclass, {@link java.awt.Color}.
654      */

655     public Paint JavaDoc getFillColor()
656     {
657     return style.getFillColor();
658     }
659
660     /**
661      * Get the styles line color
662      */

663     public Color JavaDoc getLineColor()
664     {
665     return (Color JavaDoc)style.getLineColor();
666     }
667
668     /**
669      * Get the styles font
670      */

671     public PDFFont getFont()
672     {
673     return (PDFFont)PeeredObject.getPeer(style.getFont());
674     }
675
676     /**
677      * Get the styles font size in points.
678      */

679     public float getFontSize()
680     {
681     return style.getFontSize();
682     }
683
684     /**
685      * Get the styles line join style.
686      */

687     public int getLineJoin()
688     {
689     return style.getLineJoin();
690     }
691
692     /**
693      * Get the styles line cap style.
694      */

695     public int getLineCap()
696     {
697     return style.getLineCap();
698     }
699
700     /**
701      * Get the styles line dash pattern. The returned array is two elements
702      * long, with element zero being the "on" and element one the "off".
703      * Since 1.1.5, this value is a float (rather than int)
704      */

705     public float[] getLineDashPattern()
706     {
707     float[] f = new float[2];
708     f[0] = style.getLineDashOn();
709     f[1] = style.getLineDashOff();
710     return f;
711     }
712
713     /**
714      * Get the styles line dash phase - how far into the dash pattern the
715      * line should start. Since 1.1.5, this value is a float (rather than int)
716      */

717     public float getLineDashPhase()
718     {
719     return style.getLineDashPhase();
720     }
721
722     /**
723      * Get the styles text alignment
724      */

725     public int getTextAlign()
726     {
727         return 0;
728     }
729
730     /**
731      * Get the font style.
732      */

733     public int getFontStyle()
734     {
735     int newfontstyle=style.getFontStyle();
736     if (newfontstyle==org.faceless.pdf2.PDFStyle.FONTSTYLE_OUTLINE) return FONTSTYLE_OUTLINE;
737     else if (newfontstyle==org.faceless.pdf2.PDFStyle.FONTSTYLE_FILLEDOUTLINE) return FONTSTYLE_FILLEDOUTLINE;
738     else if (newfontstyle==org.faceless.pdf2.PDFStyle.FONTSTYLE_INVISIBLE) return FONTSTYLE_INVISIBLE;
739     return FONTSTYLE_FILLED;
740     }
741
742     /**
743      * Get the text vertical offset for this style
744      */

745     public float getTextRise()
746     {
747     return 0;
748     }
749
750     /**
751      * Get the track kerning value as set by {@link #setTrackKerning}
752      * @since 1.1.14
753      */

754     public float getTrackKern()
755     {
756         return 0;
757     }
758
759     /**
760      * Get the text indent value as set by {@link #setTextIndent}
761      * @since 1.1.21
762      */

763     public float getTextIndent()
764     {
765         return style.getTextIndent();
766     }
767
768     /**
769      * Get a shallow copy of this style.
770      */

771     public Object JavaDoc clone()
772     {
773     return PeeredObject.getPeer(style.clone());
774     }
775     
776     /**
777      * Convenience Method - Get a clone of this style, typecast to PDFStyle
778      */

779     public PDFStyle styleClone()
780     {
781         return (PDFStyle)clone();
782     }
783
784     /**
785      * Return a new style which is the "superscripted" version of
786      * the current style.
787      * @since 1.1
788      */

789     public PDFStyle superscriptClone()
790     {
791     return new PDFStyle(style.superscriptClone());
792     }
793
794     /**
795      * Return a new style which is the "subscripted" version of
796      * the current style.
797      * @since 1.1
798      */

799     public PDFStyle subscriptClone()
800     {
801     return new PDFStyle(style.subscriptClone());
802     }
803
804     /**
805      * <p>
806      * Allows you to explicitly set the kerning between characters for a font.
807      * This method may be called as many times as necessary - between each
808      * character if required - to set the kerning distance between characters
809      * for all future text rendered in this style ("characters" in this context
810      * includes spaces). This "track kerning" is used as well as the standard
811      * "pair-wise" kerning, as returned by {@link PDFSimpleFont#getKerning}.
812      * </p><p>
813      * If text-alignment is set to {@link #TEXTALIGN_JUSTIFY}, kerning (both
814      * track and pairwise) is scaled up or down depending on the justification
815      * required.
816      * </p>
817      * @param millipoints the space to place between each character in millipoints
818      * (thousandths of a point) if this font was rendered one point high. May be
819      * positive, which moves the characters apart, or negative to move them closer
820      * together.
821      * @see PDFSimpleFont#getKerning
822      *
823      * @since 1.1.14
824      */

825     public void setTrackKerning(float millipoints)
826     {
827     style.setTrackKerning(millipoints);
828     }
829
830     /**
831      * Style for {@link #setFormStyle} which draws a solid border
832      * around the field (the default)
833      */

834     public static final int FORMSTYLE_SOLID=0;
835
836     /**
837      * Style for {@link #setFormStyle} which draws an border around the
838      * field so that it looks inset into the page.
839      */

840     public static final int FORMSTYLE_INSET=1;
841
842     /**
843      * Style for {@link #setFormStyle} which draws an border around the
844      * field so that it looks beveled.
845      */

846     public static final int FORMSTYLE_BEVEL=2;
847
848     /**
849      * Style for {@link #setFormStyle} which draws a single line under the
850      * field
851      */

852     public static final int FORMSTYLE_UNDERLINE=3;
853
854     /**
855      * Sets the style of a form fields background to one of {@link #FORMSTYLE_SOLID},
856      * {@link #FORMSTYLE_INSET}, {@link #FORMSTYLE_BEVEL} or
857      * {@link #FORMSTYLE_UNDERLINE}. This method can be applied to the background
858      * style passed into the <code>setStyle</code> method of a {@link FormElement},
859      * but for all other purposes such as setting the style of a page, this setting is
860      * ignored.
861      * @param style the type of background to draw the form field.
862      * @since 1.1.23
863      */

864     public void setFormStyle(int formstyle)
865     {
866     int newstyle=style.FORMSTYLE_SOLID;
867     if (formstyle==FORMSTYLE_SOLID) newstyle=style.FORMSTYLE_SOLID;
868     else if (formstyle==FORMSTYLE_BEVEL) newstyle=style.FORMSTYLE_BEVEL;
869     else if (formstyle==FORMSTYLE_INSET) newstyle=style.FORMSTYLE_INSET;
870     else if (formstyle==FORMSTYLE_UNDERLINE) newstyle=style.FORMSTYLE_UNDERLINE;
871     style.setFormStyle(newstyle);
872     }
873  
874     /**
875      * Returns the form-style of the current style, as set by {@link #setFormStyle}.
876      * @since 1.1.23
877      */

878     public int getFormStyle()
879     {
880     int formstyle = style.getFormStyle();
881     int newstyle=FORMSTYLE_SOLID;
882     if (formstyle==style.FORMSTYLE_SOLID) newstyle=FORMSTYLE_SOLID;
883     else if (formstyle==style.FORMSTYLE_BEVEL) newstyle=FORMSTYLE_BEVEL;
884     else if (formstyle==style.FORMSTYLE_INSET) newstyle=FORMSTYLE_INSET;
885     else if (formstyle==style.FORMSTYLE_UNDERLINE) newstyle=FORMSTYLE_UNDERLINE;
886
887     return newstyle;
888     }
889 }
890
Popular Tags