emacs-devel
[Top][All Lists]
Advanced

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

Re: HTML-Info design


From: Yuri Khan
Subject: Re: HTML-Info design
Date: Tue, 30 Dec 2014 00:13:18 +0700

On Mon, Dec 29, 2014 at 10:32 PM, Lars Ingebrigtsen <address@hidden> wrote:
> Eli Zaretskii <address@hidden> writes:
>
>> Fortunately, such a capability already exists, I think: see the
>> function 'font-get-glyphs'.  Does it solve your problem?  If not, what
>> API would you like to have?
>
> I've just looked at the doc string of that function briefly, and I'm not
> sure how I would use that to do filling.  I need to know the width a
> text will take in the buffer, so that I know when to break the line and
> start a new one.  Is it now possible to write a function like
> `pixel-region-width' that would say how much space the text will occupy?

Naively, one might keep track of the remaining part of the paragraph
being filled (initially the whole paragraph) and the remaining width
in the current line (initially the whole column width).

1: Ask for glyphs for the remaining part of paragraph.
2: Find the last possible line breaking point such that the sum of
glyph widths up to it is less than or equal to the remaining width.
3: Revalidate it by asking for glyphs for this part of paragraph. (In
complex scripts, breaking the line might switch to a different
presentation form.) If the sum of glyph widths is now greater than the
remaining width, backtrack to the preceding possible line breaking
point if it exists.
4: Layout the line, update the remaining part of paragraph, reset the
remaining width of line, and repeat from step 1 if the remaining part
of paragraph is not empty.

(This intentionally omits almost all complexities related to RTL
languages, and assumes that “font-get-glyphs” is smart enough to
return context-sensitive widths in complex scripts and to handle
combining diacritics. It also assumes the existence of a predicate
that tells if it a line break is possible after a certain position in
a string. For many Western languages, that returns t after whitespace
characters except for the non-breaking space. For CJK languages, it
involves some context-specific logic. The German language might demand
hyphenation logic roughly at the same time.)

(Also, the Pango text rendering library implements this and probably much more.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]