PangoLayout wrap + drawing
- From: z2274394 student unsw edu au
- To: gtk-app-devel-list gnome org
- Subject: PangoLayout wrap + drawing
- Date: Tue, 17 Feb 2004 04:58:59 +1100
Dear All,
I have a pangoLayout which is 'wrap' enabled, align = center. and when i call
gdk_draw_layout, it paints the layout but not according to the x position
specified by gdk_draw_layout. this can be understandable when the pangolayout is
multiline and hence aligned centerly, but this happens for one line also (wrap =
enabled, but smaller than wrapping width), and i fail to see why there is a
difference in x position between painting an unwrap-layout and painting a
wrap-singleLine-layout.
this is illustrated in the test program below:
attempts to draws 3 times,
1st time at (0,0) - wrap, (fail)
2nd time at middle (fail)
3rd time = unwrapped line.
The question is. What am i missing in the code or doing things wrong
so that i can correctly pinpoint the x value interested in drawing. (ie just
like how it is done in a unwrapped-pangolayout)
Thanks alot for any comments in advance
Gangas
********* ATTACH TEST PROGRAM *******
#include <gtk/gtk.h>
gboolean exposeCB(GtkWidget *wid, GdkEventExpose *event, gpointer data)
{
PangoLayout *layout;
gint plotWidth = wid->allocation.width;
gint w; gint h;
layout = gtk_widget_create_pango_layout(wid, "ashdaiosuh diausdh iasudhias uh
uias hda hsd asdluiahsd sd sd sdasdsadas ");
pango_layout_set_font_description(layout,
pango_font_description_from_string("sans 10"));
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_set_width(layout, 1000 * plotWidth);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
pango_layout_get_pixel_size(layout, &w, &h);
// 1st drawing at (0,0) - wrap
gdk_draw_layout(wid->window, gdk_gc_new(wid->window), 0, 0, layout);
// 2nd drawing - attempt to position dead middle - wrap
gdk_draw_layout(wid->window, gdk_gc_new(wid->window), plotWidth / 2 - w/2, 50,
layout);
gdk_draw_line(wid->window, gdk_gc_new(wid->window),
plotWidth / 2, 75, plotWidth, 75);
// 3rd drawing at (0,0) - not wrap
pango_layout_set_width(layout, -1);
gdk_draw_layout(wid->window, gdk_gc_new(wid->window), 0, 100, layout);
return FALSE;
}
int main(int argc, char **argv) {
GtkWidget *plotWindow;
GtkWidget *drawingArea;
gtk_init(&argc, &argv);
plotWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
drawingArea = gtk_drawing_area_new();
gtk_widget_set_size_request(drawingArea, 700, 400);
g_signal_connect(G_OBJECT(drawingArea), "expose_event",
G_CALLBACK(exposeCB), NULL);
gtk_container_add(GTK_CONTAINER(plotWindow), drawingArea);
gtk_widget_show_all(plotWindow);
gtk_main();
return 0;
}
********** END TEST PROGRAM **********
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]