As a bonus, if you accept both suggestions, you don't need to handle
from_index >= len(self.text) as an special case in get_break_index,
and rendering a block of text becomes just:

        gs = GlyphString(text, myfont.get_glyphs(text))
        i = 0
        while i < len(text):
            glTranslatef(0, -linespacing, 0)
            next = gs.get_break_index(i, window.width)
            gs.draw(i, next)
            i = next

On Sep 27, 3:28 pm, Esteban <[EMAIL PROTECTED]> wrote:
> There are a couple things that strike me as counterintuitive in
> font.GlyphString.get_break_index.  I'd like to know your rationale for
> these:
>
>  - If no valid break index is found, the original from_index is
> returned. Why? Wouldn't it be better to return None (easier to tell
> from a valid index) or the length of the text (a sane default if the
> whole text fits the width)?
>
>  - If text[from_index:] actually fits in the given width, I still get
> the index of the beginning of the last word. Why? If it fits, I don't
> want to break it at all. I could check the width beforehand, but
> get_subwidth doesn't handle line breaks. I think the latter could be
> fixed by just changing the last line in the body:
>
>     def get_break_index(self, from_index, width):
>         """<docstring omitted>"""
>         to_index = from_index
>         if from_index >= len(self.text):
>             return from_index
>         if from_index:
>             width += self.cumulative_advance[from_index-1]
>         for i, (c, w) in enumerate(
>                 zip(self.text[from_index:],
>                     self.cumulative_advance[from_index:])):
>             if w > width:
>                 return to_index
>             if c == '\n':
>                 return i + from_index + 1
>             elif c in u'\u0020\u200b':
>                 to_index = i + from_index + 1
>         return to_index
>
> so it returns len(self.text) instead.
>
> Am I missing something?
>
> Esteban.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to