Re: How to set background color for a pango layout being printed ?



Unfortunately, this does not work. All I get is a page that is completely
empty (white).

My requirements are not to paint entire background of a page in one color,
but to paint the background of the single text layout in that color.
Each page has more than one text layout being drawn with the different properties
(color, bgcolor, font, bold, italic, ...).

Yesterday I've found some code (see below) that should work but it doesn't work all the time.

On Ubuntu 7.04 (PDF backend), background color works fine, text underlining
woks, but the text is underlined with gray color!, strikethrough does not work at all!

On Windows (GTK+ 2.10.11 from http://gladewin32.sourceforge.net/),
when using print preview operation (.emf image format) everything seems to work,
but I get strange drawing artefacts in the picture.
Individual text layouts are drawn with gray lines either on the left and right layout bounds or on the
top and bottom bounds!! Some layouts are even completely squared in gray.
You can see the sample for Windows print preview at: http://notecase.sourceforge.net/temp/printing.jpg

Even more strange, when I print the same test page on the actual printer (Windows), there are no gray lines and everything works except the strikethrough (there is no strike line).


My new code is this:

//create layout
layout = gtk_print_context_create_pango_layout (context);
pango_layout_set_text (layout, text, -1);

//set required layout attributes
PangoAttrList *layout_attr = pango_attr_list_new ();

PangoAttribute *attr1 = pango_attr_background_new(bkgcolor.red,
bkgcolor.green, bkgcolor.blue);
pango_attr_list_insert (layout_attr, attr1);

if(bStrike){
   PangoAttribute *attr2 = pango_attr_strikethrough_new (TRUE);
   pango_attr_list_insert (layout_attr, attr2);
}

if(bUnderline){
   PangoAttribute *attr3 =
pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
   pango_attr_list_insert (layout_attr, attr3);
}
pango_layout_set_attributes(layout, layout_attr);
pango_layout_context_changed(layout);

//set fg color
cairo_set_source_rgb (cr, color.red, color.green, color.blue);

cairo_move_to (cr, nPosX,  nPosY);
pango_cairo_show_layout (cr, layout);


Does anyone knows what is the problem with this ? Is this a GTK bug ?
Is it the code problem ?

Regards,
 Miroslav


----- Original Message ----- From: "Behdad Esfahbod" <behdad behdad org>
To: "Miroslav Rajcic" <rajcic sokrates hr>
Cc: <gtk-app-devel-list gnome org>
Sent: Tuesday, October 16, 2007 5:58 PM
Subject: Re: How to set background color for a pango layout being printed ?


On Tue, 2007-10-16 at 12:13 +0200, Miroslav Rajcic wrote:

layout = gtk_print_context_create_pango_layout (context);
pango_layout_set_text (layout, text, -1);

cairo_set_source_rgb (cr, bgcolor.red, bgcolor.green, bgcolor.blue);
cairo_paint (cr);

//set fg color
cairo_set_source_rgb (cr, color.red, color.green, color.blue);

//HOW to set bkg color for the layout?

cairo_move_to (cr, nPosX,  nPosY);
pango_cairo_show_layout (cr, layout);
--
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
Temporary Safety, deserve neither Liberty nor Safety."
       -- Benjamin Franklin, 1759




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]