[gq-commit] gq/src dt_text.c,1.13,1.14 dt_text.h,1.6,1.7
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-13 07:25:10
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv14958 Modified Files: dt_text.c dt_text.h Log Message: * Implemented proper line-sizing, the previous algorithm was completly broken, as it did not have any connection to what actually happened on screen. Index: dt_text.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/dt_text.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dt_text.c 12 Oct 2003 16:52:57 -0000 1.13 --- dt_text.c 13 Oct 2003 07:25:00 -0000 1.14 *************** *** 147,225 **** } - static void dt_text_set_data(struct formfill *form, GByteArray *data, - GtkWidget *widget) - { - GtkWidget *text = gtk_bin_get_child(GTK_BIN(widget)); - GtkTextBuffer *b = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); - if (data) { - GtkTextIter start; - int y, height, x; - - gtk_text_buffer_set_text(b, (gchar*) data->data, data->len); - gtk_text_buffer_get_iter_at_offset(b, - &start, 0); - - gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(text), - &start, - &y, - &height); - - gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(text), - GTK_TEXT_WINDOW_WIDGET, - 0, height, - &x, &height); - height += gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(text)); - /* go through great lenghts to calculate the line height */ - { - - /* - Pango is expecting the size on "points divided by PANGO_SCALE". And for pango - the resolution for converting from points (a 1/72 inch) to pixels is the - fontconfig dpi (usually 96 these days, I guess). - - So, to convert from your pixels to points at fontconfig dpi you should do: - - pango_size = font_size_pix * PANGO_SCALE * 72 / fontconfig_dpi; - - If your fontconfig dpi is 75, the last 72 / fontconfig_dpi will be almost 1, - so you were getting an almost right resolt with this resolution. With a dpi - of 91, the factor is 0.79. And so on. - - I think that there is a GtkSetting or something to get the fontconfig dpi, but - I'm not sure. You can also get it using directly the fontconfig API. - - - */ - - /* - font_size_pix = pango_size * fontconfig_dpi / 72 / PANGO_SCALE ! */ ! ! double d = 1.0; ! int w, h; ! PangoContext *ctx = ! gtk_widget_get_pango_context(GTK_WIDGET(text)); ! GdkScreen *screen = gdk_screen_get_default(); ! int scr_h = gdk_screen_get_height(screen); ! int scr_hmm = gdk_screen_get_height_mm(screen); ! PangoLayout *lay = pango_layout_new(ctx); ! d = (scr_h / ((double) scr_hmm / 25.4)) / (72.0 * PANGO_SCALE); ! pango_layout_set_text(lay, "X", 1); ! pango_layout_get_size(lay, &w, &h); ! height = (int) ((double) h * d); ! g_object_unref(lay); ! } ! gtk_widget_set_size_request(GTK_WIDGET(text), 100, 5 * height); ! } } --- 147,192 ---- } ! static void realize_text(GtkWidget *text, gpointer user_data) ! { ! /* go through great lenghts to calculate the line height */ ! ! int height; ! PangoContext *ctx = gtk_widget_get_pango_context(GTK_WIDGET(text)); ! PangoLayout *lay = pango_layout_new(ctx); ! PangoRectangle rect; ! pango_layout_set_single_paragraph_mode(lay, FALSE); ! ! pango_layout_set_text(lay, "X\nX", 3); /* two lines */ ! pango_layout_get_pixel_extents(lay, &rect, NULL); ! height = rect.height; ! pango_layout_set_text(lay, "X", 1); /* one line */ ! pango_layout_get_pixel_extents(lay, &rect, NULL); ! height -= rect.height; /* difference is height of one line ... */ ! ! g_object_unref(lay); ! ! gtk_widget_set_size_request(GTK_WIDGET(text), 100, ! DEFAULT_LINES * height); ! } ! static void dt_text_set_data(struct formfill *form, GByteArray *data, ! GtkWidget *widget) ! { ! GtkWidget *text = gtk_bin_get_child(GTK_BIN(widget)); ! GtkTextBuffer *b = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); ! if (data) { ! gtk_text_buffer_set_text(b, (gchar*) data->data, data->len); ! gtk_signal_connect(GTK_OBJECT(text), "realize", ! (GtkSignalFunc) realize_text, NULL); ! } } Index: dt_text.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/dt_text.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dt_text.h 30 Sep 2003 17:20:25 -0000 1.6 --- dt_text.h 13 Oct 2003 07:25:01 -0000 1.7 *************** *** 42,44 **** --- 42,46 ---- gpointer funcdata); + #define DEFAULT_LINES 5 + #endif |