Changing fonts on the same line
"spinningwebz2002" <spinningwebz2002-/[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.pdfapi2 |
|---|---|
| Message-ID | <[email protected]> |
I am trying to determine how to do this and maybe one of you can give
me some pointers.
What I want to do is create a justified line of text and be able to
have the font change in that line. For lack of a better example here
is what I would like to do (html markup shown just for the example):
This is the <B>line</B> that is justified.
And have the word line bold.
The brute force way I can envision doing it would be something like
this psuedo code:
For purposes of this example I will only concern myself with the Bold
tag
$linetoprint = "This is the <B>line</B> that is justified."
$f1=$pdf->corefont('Helvetica',-encode=>'latin1');
$f2=$pdf->corefont('Helvetica-Bold',-encode=>'latin1');
while ($linetoprint ne "")
{
$a = substr($linetoprint,0,1); #get next character
if ($a eq "<")
{
# we found a tag
if (substr($linetoprint,1,1) eq "/")
{
# We found the bold close so restore the
regular font
$f1=$pdf->corefont('Helvetica',-
encode=>'latin1');
# Remove the tag from the line
$linetoprint = substr($linetoprint,4);
goto Bypass; #Kludge in this sample
}
# we just assume this tag is B for now so change font
$f2=$pdf->corefont('Helvetica-Bold',-
encode=>'latin1');
$linetoprint = substr($linetoprint,4);
goto Bypass; #Kludge in this sample
}
# here is where I am not sure how to do in PDF::API2
$thisletterwidth = What is the width of the character in $a
using the current font settings?
if ($thisletterwidth + (What is the current print position on
this line?) >= (Farthest right I want to print) )
{
Insert a little spacing into the current line to
justify it?
Start a new line
}
Add $a to the current line
$thislinetoprint = substr($thislinetoprint,1);
Bypass:
}
Bill H