DynaPDF Manual - Page 825

Previous Page 824   Index   Next Page 826

Function Reference
Page 825 of 839
Text formatting
WriteFText() can be used to output simple formatted text such as right aligned or justified text, but it
is also possible to use certain format tags to create a list or other specific formattings. It is also
possible to use a callback function to create multi-column text or other more complex formattings.
First, we want to see how the text alignment can be changed inside a text block. WriteFText()
supports 4 format tags which can be used to do this, we call these tags alignment tags.
Alignment tags
An alignment tag changes the text alignment in a text block. The base alignment that is used by the
function was already defined by the parameter Align. The base alignment can also be changed inside
the text by inserting an alignment tag. The following tags are available:
\le# // Left aligned text
\re# // Right aligned text
\ce# // Centred text
\ju# // Justified text
Like all format tags, an alignment tag begins with a backslash (character code 92) and ends with a
numbersign (character code 35).
It is not possible to use multiple alignments in one text line. When an alignment tag is found the
current line is closed and the cursor moves to the next line and continues with the new alignment.
Example:
char fText[] = "Left aligned text, this is left aligned text, this is "
"left aligned text...\\ju#\\FC[255]This is justified text, this is "
"justified text, this is justified text, this is justified text, this "
"is justified text, this is justified text, this is justified text, "
"this is justified text...\\re#\\FC[165536]This is right aligned text, "
"this is right aligned text, this is right aligned text..."
"\\le#\\FC[233512]Back to left aligned text, we go back to left "
"aligned text...";
pdfSetTextRect(pdf, 50, 50, 150, -1);
pdfWriteFText(pdf, taLeft, fText);
double height = pdfGetPageHeight(pdf) - pdfGetLastTextPosY(pdf) - 50;
pdfRectangle(pdf, 50, 50, 150, height, fmStroke);
Note that the above string is a literal string defined in C/C++. Because the backslash is an escape
character in C/C++ it must be added twice. "\\le#" is resolved to "\le#". The latter string is what the
compiler passes to WriteFText(). The same string read from a file requires no escaping with
additional backslashes!
 

Previous topic: WriteFText, Output rectangle

Next topic: Command tags