Re: Question about gtk_label_set_justify()



i would achieve this thus:

// calculate the total space required to render the string (string here contains no spaces): string_width_in_pixels = string_width(string_to_render); // string_width() function is implementation specific

// leaving us with how much white space is required to be inserted:
total_white_space_in_pixels = label_widget_width_in_pixels - string_width_in_pixels;

// compute the pixels for a space (' '):
space_pixels = string_width(" ");

// total white space required between each character
space_fill_in_pixels = total_white_space_in_pixels / (total_characters_in_display_string - 1)

spaces_required = space_fill_in_pixels / space_pixels;

and now we have enough information to make our string by hand, one character at a time, evenly distributing the displayed characters:

for(i=0;i<strlen(string_to_render);i++)
{
  sprintf(output_str, "%s%c\0", output_str, string_to_render[i]);
  for(j=0;j<spaces_required;j++)
  {
    sprintf(output_str, "%s%c\0", output_str, ' ');
  }
}

et voila, our evenly spaced output string. (though in practice i would write the above using glib string functions and not implement it strictly as i have written here.)

no?  ja?

richard


On Jul 26, 2006, at 9:00 AM, David Nečas (Yeti) wrote:

On Wed, Jul 26, 2006 at 07:09:40AM +0200, Richard Boaz wrote:
so far, all discussion of this problem has related to whether or not a
solution resides wholly withing gtk/pango/cairo/whatever.

it would seem to me that the fact that gtk/pango/cairo/whatever does not provide a built-in solution for chinese style justification only means
that the solution must be found elsewhere.

namely, before rendering the label string, provide your own function that creates the string exactly as you would want it to be displayed, simply using spaces to fill out the string accordingly, and then provide this new
string to render the label.

whynot?

How do you achieve an exact width just by adding spaces?

If the program is Chinese-only and gives up the possibility
to be ever internationalized right away, well, one can
create a Pango layout, measure all the glyphs in the label,
calculate the space to put between them and then render the
glyphs one by one to the calculated positions -- this all
encapsulated in a new widget, something like MyChineseSpreadLabel.
Of course this assumes there is an easy way to tell how
a string is broken to glyphs for Chinese.

Yeti


--
Anonyms eat their boogers.
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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