Re: Re: issue with line break option PANGO_WRAP_CHAR



Title: Samsung Enterprise Portal mySingle

Hello Behdad,

 

Thanks for your inputs.

 

I have fixed the issue by adding the a few lines of code (additional code, colored in blue) in the process_item() function of pango_layout.c

I have tested this in English only and it works fine.

 

Issue

When space is encountered at the end of the current line and it cannot be accommodated there,

the word breaks at the previous glyph.

This is because break_num_chars does not count the current glyph (i.e. space)

 

Proposed Solution

In case of above scenario, increase the value of break_num_chars by 1.

And also take into account the break_width.

 

Modification in code

 

    retry_break:

      /* See how much of the item we can stuff in the line. */
      width = 0;
      for (num_chars = 0; num_chars < item->num_chars; num_chars++)
 {
   if (width > state->remaining_width && break_num_chars < item->num_chars)
     break;

   /* If there are no previous runs we have to take care to grab at least one char. */
   if (can_break_at (layout, state->start_offset + num_chars, retrying_with_char_breaks) &&
       (num_chars > 0 || line->runs))
     {
       break_num_chars = num_chars;
       break_width = width;
     }
   else
   {

    if( (layout->log_attrs[state->start_offset + num_chars].is_white) &&
      (layout->wrap == PANGO_WRAP_CHAR || layout->wrap == PANGO_WRAP_WORD_CHAR) )
    {
     break_num_chars = num_chars + 1;
     break_width = width + state->log_widths[state->log_widths_offset + num_chars];
    }
   }

   width += state->log_widths[state->log_widths_offset + num_chars];
 }

 

------

 

Do you think that this would work fine in other languages also ?

 

Thanks and regards,

Parth Kanungo

 

------- Original Message -------

Sender : Behdad Esfahbod<behdad behdad org>

Date : Sep 09, 2013 21:44 (GMT+05:30)

Title : Re: issue with line break option PANGO_WRAP_CHAR

 

On 13-09-06 08:22 AM, Parth Kanungo wrote:
> Hello,
>
> I am facing an issue with a line break option - PANGO_WRAP_CHAR.
>
> You can see the output (image.bmp)
>
> for my code (main.cpp)
>
> It is clear that "i" can be rendered on the first line after "Th".
>
> However, it is coming on the second line. This is wrong.
>
> Is this a known bug?

There's many things going on here:

1. Unicode line breaking algorithm prohibits breaking before a space.  As such
we try to fit the space after i in the same line.  Normally, after we break
line, we zero the width of the final space on the line (see
pango-layout.c:zero_line_final_space).  We try to account for that when
deciding where to break, but it's possible that we are messing things up,

2. When WRAP_CHAR, we still never break before a space, while sometimes that's
the right thing to do no matter what Unicode says.

In short, that piece of code needs some long overdue love, but I don't know
anyone with the time and expertise to look into it right now.

behdad

>
> I further debugged and found that
>
> 1. can_break_at() gives false for space character.
>
> 2. break_width contains the width of "Th" only, when it should contain the
> width of "The"
>
>  
>
> But, I am not sure how to fix this.
>
> Moreover, this problem aggravates if we introduce multiple spaces between 2 words.
>
>  
>
> Any pointers in this direction would be helpful.
>
>  
>
> Thanks and regards,
> Parth Kanungo
>
>
>
> _______________________________________________
> gtk-i18n-list mailing list
> gtk-i18n-list gnome org
> https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
>

--
behdad
http://behdad.org/

 



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