I've had a need to draw underlines in text created with the GD image
functions, specifically ImagePSText(). As far as I could tell there's no
way to do this (apart from using ImageLine()
, which would be difficult to
really get right). [I'm happy to hear suggestions if I've missed the
obvious :-)]
An added complication of what I wanted to achieve was to underline only part
of the string being drawn, while maintaining kerning between characters.
The system I've come up with is to embed "control sequences" into the string
that is passed to ImagePSText(). A control sequence contains commands which
change various characteristics of the output, for instance, toggle
underlining. I'm currently using the escape character (chr(27)) to indicate
the start of a control sequence, and a semi-colon to end the sequence.
For example:
$str="Some text with an " . chr(27) . "u;underlined" . chr(27) . "u; word";
I've attached a patch for gd.c which does what I'm talking about.
I wondering whether people think this is a good way to go, and if so if I
should commit this code? If it's not a good idea, any suggestions for
drawing underlines?
Thanks,
Tim
Shouldn't you better discuss this with the gd people over at boutell.com?
Ron
"Tim Toohey" ttoohey@toowards.com wrote in message
news:20041106062158.78783.qmail@pb1.pair.com...
I've had a need to draw underlines in text created with the GD image
functions, specifically ImagePSText(). As far as I could tell there's no
way to do this (apart from usingImageLine()
, which would be difficult to
really get right). [I'm happy to hear suggestions if I've missed the
obvious :-)]An added complication of what I wanted to achieve was to underline only
part
of the string being drawn, while maintaining kerning between characters.The system I've come up with is to embed "control sequences" into the
string
that is passed to ImagePSText(). A control sequence contains commands
which
change various characteristics of the output, for instance, toggle
underlining. I'm currently using the escape character (chr(27)) to
indicate
the start of a control sequence, and a semi-colon to end the sequence.For example:
$str="Some text with an " . chr(27) . "u;underlined" . chr(27) . "u;
word";I've attached a patch for gd.c which does what I'm talking about.
I wondering whether people think this is a good way to go, and if so if I
should commit this code? If it's not a good idea, any suggestions for
drawing underlines?Thanks,
Tim
Ron Korving wrote:
Shouldn't you better discuss this with the gd people over at boutell.com?
Ron
Yes, perhaps I should. I take it that your point is that this kind of
feature belongs in the underlying library rather than in PHP. PHP's gd
extension is a wrapper around the libgd library to make it usable to PHP
scripts, rather than a place to extend the features of libgd.
Alas for the ImagePSText() function I don't think the gd people will be much
help as it uses the t1lib library. While I might have some chance at
getting the gd people's ear, I'm not sure I'll have much luck with t1lib
(is there an active open development of t1lib?)
So, given the above, and at the risk of being off-topic now, is the general
approach I'm proposing, embedded control character sequences, a reasonable
way to achieve the goal (underlining). Another approach that I had
considered was a kind of HTML rendering mode, which really is simply
another way of have embedded instructions in the string. This, to me, seems
beyond the scope of a low-level graphics library like gd (or t1lib).
Perhaps what is needed is a new library that sits between PHP and gd/t1lib
to do these kind of higher-level text rendering jobs? Maybe that already
exists and I just haven't come across it.
Thanks,
Tim