Pango wrapping API



      Hello,
	I have a question about the Pango API and word wrapping.

	Word wrapping is complicated, and can get *very* complicated for
non-western scripts.  There is "wrap-up" line wrapping, "wrap-down" line
wrapping, and "dangling" or "hanging punctuation" wrapping.  For scripts
which do not break words with spaces/whitespace, you need a
dictionary-based lookup of the characters to see where the wrap boundaries
are.

	I was happy to see that a Pango Layout object would take all this
crap off my shoulders, and do the line wrapping for me.  But the only
function I can find to set the wrap-boundary is pango_layout_set_width(),
which takes a 1/1000th of a pixel unit value.

	Therein lies my problem.  I'm working on a text-editing
application which need to wrap at the 76th *character*, not a pixel value.

	There are a couple of reasons I need this: the main target
audience is the ASCII world, who will want files edited with this app to
still look good ("well-wrapped") in vi, emacs, or pico.  Also, I'm
attempting to clone an existing Win32 application which allows the user to
choose between window-wrapping and character-length wrapping.  I don't
want my app to be inferior to the Win32 version just because I'm using
Pango.

	Finally, I can see a need for this feature in email client
applications, where it is common to wrap emails to the 76th character so
that it looks good in an 80-character terminal window (ala Pine).

	Does such a character-length wrapping exist?  If not, could we add
such a function?

	I would suggest just adding two new functions:

void pango_layout_set_width_by_char(PangoLayout *layout, gint char_width);
gint pango_layout_get_width_by_char(PangoLayout *layout);

	...and have the 1/1000th pixel functions (without the _by_char)
take precedence.  That is, character-based wrapping only takes place if
the "width" of the PangoLayout is set to -1 (as in, "no wrapping").  That
would allow us to keep the existing API intact, and require the addition
of a new variable to the PangoLayout structure.

	Alternatively, you could break existing apps by renaming the
set_width/get_width functions, and having some kind of flag or "Wrap Type"
enum in the functions.  Personally, I believe character-based wrapping is
important enough to make the design clean, and would be worth breaking the
existing API if that would make things easiest to use.

	Of course, we could let the responsibility of character wrapping
fall upon the application, but I really believe Pango is the place to put
this for the reasons mentioned at the beginning of this message.

	Comments?  (I'm still new to Pango, but I'd be willing to do the
work and submit a patch if you're willing to wait a couple of weeks for
it)


--Derek





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]