# Idea for underlining in GD text functions

- Thread: https://externals.io/message/13752
- Original archive: https://news-web.php.net/php.internals/13752
- Started by Tim Toohey on 2004-11-06T06:21:58+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13752 — Tim Toohey — 2004-11-06T06:21:58+00:00

URL: https://externals.io/message/13752#13752

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

---

## #13756 — Ron Korving — 2004-11-06T18:30:59+00:00

URL: https://externals.io/message/13752#13756 · In reply to: #13752

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 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

---

## #13763 — Tim Toohey — 2004-11-07T05:41:29+00:00

URL: https://externals.io/message/13752#13763 · In reply to: #13756

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
