On Wed, Jul 26, 2006 at 09:50:21AM +0200, Richard Boaz wrote: > 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; Unless the fraction comes out as an integer, how are the spaces supposed to pad the string to the exact width? > 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. Hardly. Stop living in ASCII world, hey we are talking about Chinese. First of all, %c breaks the string into bytes, so the only thing you get from this is a Pango warning about invalid UTF-8. So let's say you broke the string into characters. How they map to glyphs? No one knows (well, Pango knows, but I'm not sure how to get this from it). So let's say you somehow managed to break the string to parts corresponding to glyphs. And you want to insert spaces and render? Wrong. Characters can look differently when they are surrounded spaces and whey they are surrounded by other characters. If your app is single-language and you know how to deal with the previous two issues for that language, well, you can use the method I outlined in the previous mail. But for international text you have no chance without the support of Pango or other international text handling library (not talking about the possibility that such spreading makes no sense for a particular script). > no? ja? No. Yeti -- Anonyms eat their boogers. _______________________________________________ gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list