Re: Windows printing problem

2010-08-22 Thread James
On Fri, 2010-08-20 at 15:55 +1000, James wrote:
 Hi,
 
 I've refined the code a bit.
 
 This I can print to PDF using pdfFactory Pro, and it is displayed in the
 pdfFactory Pro preview window properly, but Windows always errors out on
 the actual printing.
 
 Printing direct to the printer (HP laserjet) also causes windows to
 report an error trying to print.
 
 (The printer works fine for every other app on Windows and Ubuntu).
 
 Draw page code below.

snip

Ok, I think I found the reason the darn thing wont print under windows.
It seems that because I have about 1 lines drawn in cairo onto the
print surface, the printer chucks a fit.  Now I draw to a separate cairo
surface and copy to the print context, which generates somewhat fuzzy
lines, but at least works.

Is there something I can do to improve the fuzzy lines?

James.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Windows printing problem

2010-08-19 Thread James
Hi,

I have an app that prints 2 pages with an image in one corner of the
page, and some plotted data in the middle, the rest is text.

The page is oriented in landscape.

On Ubuntu the printing works fine.

On Windows XP I can get the text only to work.

Printing the image creates blank pages.

Printing the plotted data causes printing errors.

I'm using gtk+-bundle_2.18.7-20100213_win32

Any clues?

Code below.

Regards,
James.

pb = gdk_pixbuf_new_from_file(./Logo.jpg, gerror);
if(!pb) {
eprintf(error message: %s\n, gerror-message);
return;
}

int pb_width = gdk_pixbuf_get_width (pb);
int pb_height = gdk_pixbuf_get_height (pb);

//set to 1 makes the whole page blank on Win32, Linux fine.
#if 0
cairo_surface_t *image = cairo_image_surface_create_for_data(
gdk_pixbuf_get_pixels(pb),
CAIRO_FORMAT_RGB24,
pb_width,
pb_height,
gdk_pixbuf_get_rowstride(pb));

do {
int rowstride, n_channels, x, y;
guchar *pixels, *p, tmp;

pixels = gdk_pixbuf_get_pixels (pb);
rowstride = gdk_pixbuf_get_rowstride(pb);
n_channels = gdk_pixbuf_get_n_channels (pb);

for (y = 0; y  pb_height; y++) {
for (x = 0; x  pb_width; x++) {
p = pixels + y * rowstride + x *
n_channels;
tmp = p[0];
p[0] = p[2];
p[2] = tmp;
}
}
} while (0);

cairo_save (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface(cr, image, 0, 0);
cairo_paint (cr);

cairo_restore (cr);


cairo_surface_destroy(image);
#endif



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Windows printing problem

2010-08-19 Thread James
Hi,

I've refined the code a bit.

This I can print to PDF using pdfFactory Pro, and it is displayed in the
pdfFactory Pro preview window properly, but Windows always errors out on
the actual printing.

Printing direct to the printer (HP laserjet) also causes windows to
report an error trying to print.

(The printer works fine for every other app on Windows and Ubuntu).

Draw page code below.

Regards,
James.

static void draw_page (GtkPrintOperation *operation,
GtkPrintContext   *context,
gint   page_nr,
gpointer   user_data)
{
g_print(Draw page %d\n, page_nr);


int i;
char text[256];
int len;
PangoLayout *layout;
PangoFontDescription *desc;
GError *gerror = NULL;
GdkPixbuf *pb;

cairo_t *cr;
gdouble width, height;

cr = gtk_print_context_get_cairo_context (context);
width = gtk_print_context_get_width (context);
height = gtk_print_context_get_height (context);

pb = gdk_pixbuf_new_from_file(./Logo.jpg, gerror);
if(!pb) {
eprintf(error message: %s\n, gerror-message);
return;
}

int pb_width = gdk_pixbuf_get_width (pb);
int pb_height = gdk_pixbuf_get_height (pb);

cairo_operator_t op = cairo_get_operator(cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
gdk_cairo_set_source_pixbuf(cr, pb, 0.0, 0.0);
cairo_paint (cr);
cairo_set_operator(cr, op);

cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

layout = gtk_print_context_create_pango_layout (context);
desc = pango_font_description_from_string (sans 14);
pango_layout_set_font_description (layout, desc);

sprintf(text, Title details);

cairo_move_to(cr, pb_width+10, 0);
pango_layout_set_text (layout, text, -1);
pango_cairo_update_layout (cr, layout);
pango_cairo_show_layout (cr, layout);

pango_layout_set_text (layout, text, -1);

pango_font_description_free (desc);
g_object_unref (layout);

for (i = 0; i  6; i++) {
layout = gtk_print_context_create_pango_layout (context);

len = 0;
len += sprintf(text[len], Stuff\n);
len += sprintf(text[len], More stuff\n);

pango_layout_set_text (layout, text, -1);

desc = pango_font_description_from_string (sans 9);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_cairo_update_layout (cr, layout);

cairo_move_to(cr, (5 - i) * (width - GAP_X_AXIS) / 6, height - 
80);
pango_cairo_show_layout (cr, layout);

g_object_unref (layout);
}

cairo_translate(cr, 0, pb_height);

if (page_nr == 0) {
#if 1
//Various text and line drawing 
//with pango and cairo functions.
#endif
} else if (page_nr == 1) {
#if 1
//Various text and line drawing 
//with pango and cairo functions.
#endif
}
}


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list