Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
PFDocument, PFPage, PFPrintObject, and all the measurement classes. In Part 5 I will focus my explanations on what I call the support classes of the print
framework. I will start with the PFParagraph class.The PFParagraph class is essential to the print framework. It provides all the basic functions needed to render text. By using PFParagraph, you will be able to render text with the following alignments: left, right, center, and fully justified. In addition, the
class enables you to set the text color and the font size. PFParagraph also supports two text input methods. You can use either the standard String class, or if you need a more elaborate way of inputting text, you can use an AttributedString.
PFParagraph also provides all the previously explained functions of the PFPrintObject. Although PFParagraph does not provide direct support for margins, you can use the implementation provided by the PFPrintObject. You will find PFParagraph's code in Listing 1.
Listing 1: PFParagraph As most of PFParagraph is pretty straightforward, I will focus only on its rendering methods. The rendering process starts in the print method located
at line 179 in Listing 1. First, the method sets the text color and the text font. Then, depending on the horizontal alignment,
the method calls the proper text renderer. When finished with the rendering process, the print method calls the printChilds() method to render any child object that it may contain.
There are four private methods available to render text: renderLeftJustfied(), renderRightJustified(), renderCenterJustified(), and renderFullyJustified(). The renderLeftJustified() method (line 387) uses nearly the same code as that presented in Part 2, Listing 4.
Line 325 shows how renderCenterJustified() differs from renderLeftJustified(). To calculate the object's center, divide the width of the object by two. Then divide the width of the string -- which the
layout.getAdvance() method obtains -- by two. Next, subtract the object's center from the string's center to obtain the position where the string
will be rendered.
The renderRightJustified() method resembles renderLeftJustified() except that you subtract the string's width from the object's width (i.e., you compute the same math without the divisions).
Graphics framework for advanced 2D compositions