Re: unicode, rendering, and a minor doc typeo patch
- From: martine cs washington edu (Evan Martin)
- To: Owen Taylor <otaylor redhat com>
- Cc: Evan Martin <martine cs washington edu>, gtk-devel-list gnome org
- Subject: Re: unicode, rendering, and a minor doc typeo patch
- Date: Thu, 24 Jan 2002 14:07:47 -0800
On Thu, Jan 24, 2002 at 04:51:32PM -0500, Owen Taylor wrote:
> > It seems the easy (and probably naive and slow) way to render fonts is
> > like this (in the expose event):
> > layout = gtk_widget_create_pango_layout(widget, text);
> > gdk_draw_layout(window,
> > widget->style->fg_gc[widget->state],
> > 10, 10,
> > layout);
> > g_object_unref(G_OBJECT(layout));
> >
> > When I try this with my sample file (sample.u8, displayed in the above
> > screenshot), my text displays correctly, but I get this warning:
> > fb (pid:17955): ** WARNING **: pango_default_break(): the array
> > of PangoLogAttr passed in must have at least N+1 elements, if
> > there are N characters in the text being broken
> >
> > Here's a backtrace (using --g-fatal-warnings):
> > #2 0x4044401e in pango_default_break () from /usr/lib/libpango-0.23.so
> > #3 0x404456b6 in pango_break () from /usr/lib/libpango-0.23.so
> > #4 0x404506ab in pango_layout_get_pixel_size () from /usr/lib/libpango-0.23.so
> > #5 0x404509c9 in pango_layout_get_pixel_size () from /usr/lib/libpango-0.23.so
> > #6 0x40451fa3 in pango_layout_get_iter () from /usr/lib/libpango-0.23.so
> > #7 0x4024400b in gdk_draw_layout_with_colors () from /usr/lib/libgdk-x11-1.3.so.12
> > #8 0x402442a0 in gdk_draw_layout () from /usr/lib/libgdk-x11-1.3.so.12
> > #9 0x080491e0 in expose_event ()
> >
> >
> > Am I going about this the wrong way?
>
> It sounds reasonable. I think there I may have heard about some
> problems with one-character layouts, though I can't reproduce that in
> some quick tests. If you can produce a test case that exhibits the
> problem, I'll take a look.
Actually, this is using a small (45 byte) UTF-8 file.
Attached test case and file.
--
Evan Martin
martine cs washington edu
http://neugierig.org
/* vim: set ts=4 sw=4 : */
#include <gtk/gtk.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
GString*
string_from_file(char *filename) {
int fd;
char buf[1024];
GString *str;
size_t size;
str = g_string_new(NULL);
if ((fd = open(filename, 0)) < 0)
perror("open");
/* a loop is overkill for this test case,
* but this code is more correct. */
do {
size = read(fd, buf, 1024);
if (size < 0)
perror("read");
g_string_append_len(str, buf, size);
} while (size > 0);
close(fd);
return str;
}
gboolean
expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
GdkWindow *window = GTK_LAYOUT(widget)->bin_window;
static GString* text = NULL;
PangoLayout *layout;
if (text == NULL)
text = string_from_file("sample.u8");
gdk_window_clear_area(window,
event->area.x, event->area.y,
event->area.width, event->area.height);
gdk_gc_set_clip_rectangle(widget->style->fg_gc[widget->state],
&event->area);
layout = gtk_widget_create_pango_layout(widget, text->str);
/*
* providing the string length doesn't fix it, either.
layout = pango_layout_new(gtk_widget_get_pango_context(widget));
pango_layout_set_text(layout, text->str, text->len);
*/
gdk_draw_layout(window,
widget->style->fg_gc[widget->state],
10, 10,
layout);
g_object_unref(G_OBJECT(layout));
gdk_gc_set_clip_rectangle(widget->style->fg_gc[widget->state],
NULL);
return TRUE;
}
GtkWidget*
make_contents() {
GtkWidget *layout, *scroll;
PangoFontDescription *font_desc;
layout = gtk_layout_new(NULL, NULL);
font_desc = pango_font_description_from_string("Bitstream Cyberbit 18");
gtk_widget_modify_font(layout, font_desc);
pango_font_description_free(font_desc);
gtk_signal_connect(GTK_OBJECT(layout), "expose-event",
GTK_SIGNAL_FUNC(expose_event), NULL);
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(scroll), layout);
return scroll;
}
int main(int argc, char* argv[]) {
GtkWidget *dlg, *contents;
gtk_init(&argc, &argv);
dlg = gtk_dialog_new_with_buttons("Test Case", NULL, 0,
GTK_STOCK_CLOSE, GTK_STOCK_CLOSE, NULL);
gtk_window_set_default_size(GTK_WINDOW(dlg), 400, 200);
gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
contents = make_contents();
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox),
contents, TRUE, TRUE, 0);
gtk_widget_show_all(contents);
gtk_dialog_run(GTK_DIALOG(dlg));
return 0;
}
テストです。
だいがく / 大学。
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]