Hi!
I want to print (in a printer) a GtkTreeview as I see in the screen.
But i can't get the exactly number of characters show in a column. I can get th entire text but not the text showned.
Then I try to fit the text i get in a PangoLayout in a width in pixels, but I cant get pixels, but i can't set the witdh in pixels, only in bytes.
How I cant put the with in a PangoLayout in pixels?.
Maybe this example code explain it better:
Code:
gint print_text(
gchar *Text,
gdouble X,
gdouble Y,
gint W,
GtkPrintContext *context,
cairo_t *cr)
{
PangoLayout *layout;
PangoFontDescription *font;
gint w,h;
layout = gtk_print_context_create_pango_layout(context);
pango_layout_set_text(layout, Text, -1);
font = pango_font_description_from_string("Arial 6");
pango_layout_set_font_description (layout,font);
pango_font_description_free(font);
//pango_layout_get_pixel_size(layout,&w,&h);
//How can I set the W (width) to the layout to limit this width to column width???????
cairo_move_to(cr,X,Y);
pango_cairo_layout_path(cr,layout);
cairo_stroke_preserve(cr);
cairo_fill(cr);
g_object_unref(layout);
return h;
}
static void draw_page (GtkPrintOperation *operation,GtkPrintContext *context,gint page_nr,GtkTreeView *tree)
{
cairo_t *cr;
cr = gtk_print_context_get_cairo_context(context);
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeViewColumn *column;
GtkTreeIter iter;
GValue value = {0};
GString *text;
gint col_num;
gint x,y,w,h;
GdkRectangle rect;
gboolean visible;
texto = g_string_new("");
model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
path = gtk_tree_path_new_first();
while(gtk_tree_model_get_iter(model,&iter,path) == TRUE)
{
x = 0
for(col_num=0;col_num < gtk_tree_model_get_n_columns(model);col_num++)
{
column = gtk_tree_view_get_column(GTK_TREE_VIEW(tree),col_num);
visible = gtk_tree_view_column_get_visible(column);
if(visible1)
{
gtk_tree_model_get_value(modelo,&iterador,col_num,&valor);
switch(G_VALUE_TYPE(&value))
{
case G_TYPE_STRING:
{
if(g_value_get_string(&value) != NULL) g_string_assign(text,g_value_get_string(&value));
} break;
case G_TYPE_INT:
{
g_string_printf(text,"%d",g_value_get_int(&value));
} break;
case G_TYPE_ULONG:
{
g_string_printf(text,"%lu",g_value_get_ulong(&value));
} break;
}
g_value_unset(&value);
gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tree),path,columna,&rect);
h = rect.height;
gtk_tree_view_get_background_area(GTK_TREE_VIEW(tree),NULL,column,&rect);
w = rect.width;
print_text(text->str,x,y,w,context,cr);
x += (w+2);
}
}
y += h;
gtk_tree_path_next(path);
}
gtk_tree_path_free(path);
g_string_free(text,TRUE);
Thanks (i excuse my poor english)