pango_layout_get_pixel_size fails after multiple iterations



Greetings fellow GTK hackers!

  I'm having an issue with pango_layout_get_pixel_size that I was hoping
someone could shed some light on:

  I have a drawable widget which I draw several things to including
several strings of text. The size of the items are calculated
dynamically, and thus the text must be also.
  Here's some pseudo code to give you an idea of what I'm trying to do:

function find_size(PangoLayout *pl, int maxHeight, int maxWidth){
  PangoAttribute *pa;
  PangoAttrList *pal;
  int height = 0;
  int width = 0;
  int trySize = 8;
  pal = pango_layout_get_attributes(pl);
  if(!pal){
    pal = pango_attr_list_new();
    pango_layout_set_attributes(pl,pal);
    pango_attr_list_unref(pal);
  }
  while(1){
    pa = pango_attr_size_new(trySize * PANGO_SCALE);
    pango_attr_list_change(pal,pa);
    pango_layout_set_attributes(pl,pal);
    pango_layout_get_pixel_size(pl, &width, &height);
    printf("Checking TrySize +10 %i, Height %i, Width %i, MaxHeight %i,
MaxWidth %i\n",trySize,height,width,maxHeight, maxWidth);
    if(height > maxHeight || width > maxWidth){ break; }
    trySize += 10;
  }
}

  Again, this is pseudo code, not the whole code.
  This works all well and good for a while, yet after running for a
while the width and height don't update even though trySize (font size)
is increasing by 10 every time, which of course causes an infinite loop.

  The output looks strange: (not real numbers)
Checking TrySize +10 8, Height 17, Width 142, MaxHeight 43, MaxWidth 541
Checking TrySize +10 18, Height 17, Width 142, MaxHeight 43, MaxWidth
541
Checking TrySize +10 28, Height 17, Width 142, MaxHeight 43, MaxWidth
541

  I'm sure you get the idea. The font size increases by 10 every time,
yet the width and height returned by pango_layout_get_pixel_size does
not change..?!

  Did I miss something?
  Any help or ideas would be greatly appreciated!

Thanks so much!

j

-- 
"A people who mean to be their own governors must arm themselves with
the power knowledge gives. A popular government without popular
information or the means of acquiring it, is but a prologue to a farce
or a tradgedy, or perhaps both." - James Madison




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