static void move_pen_to_nextpage(void) { gnome_print_showpage(gpx); gnome_print_context_close(gpx); g_object_unref(gpx); gpx = gnome_print_job_get_context(job); gnome_print_beginpage(gpx, NULL); gnome_print_setfont(gpx, font); page_y = page_height - margin_top - line_height; gnome_print_moveto(gpx, page_x, page_y); }
static int gnome_print_multipage_beginpage (GnomePrintContext *pc, const guchar *name) { GnomePrintMultipage *mp; gint ret; mp = GNOME_PRINT_MULTIPAGE (pc); /* We count on ::showpage advancing subpage */ if (mp->subpage == mp->affines) { /* Have to start new global page */ ret = gnome_print_beginpage (mp->subpc, name); g_return_val_if_fail (ret == GNOME_PRINT_OK, ret); } /* Start new local page gsave and current affine matrix */ ret = gnome_print_gsave (mp->subpc); g_return_val_if_fail (ret == GNOME_PRINT_OK, ret); return ret; }
static gint gpm_render (GnomePrintContext *dest, const guchar *data, gint pos, gint len, gboolean pageops) { const guchar *end; data = data + pos; end = data + len; while (data < end){ gint32 opcode, i; guchar *cval; gint32 ival; gdouble dval; ArtBpath *bpath; data = decode_int (data, &opcode); switch ((GnomeMetaType) opcode) { case GNOME_META_BEGINPAGE: data = gpm_decode_string (data, &cval); if (pageops) gnome_print_beginpage (dest, cval); g_free (cval); break; case GNOME_META_SHOWPAGE: if (pageops) gnome_print_showpage (dest); break; case GNOME_META_GSAVE: gnome_print_gsave (dest); break; case GNOME_META_GRESTORE: gnome_print_grestore (dest); break; case GNOME_META_CLIP: data = gpm_decode_bpath (data, &bpath); data = decode_int (data, &ival); gnome_print_clip_bpath_rule (dest, bpath, ival); g_free (bpath); break; case GNOME_META_FILL: data = gpm_decode_bpath (data, &bpath); data = decode_int (data, &ival); gnome_print_fill_bpath_rule (dest, bpath, ival); g_free (bpath); break; case GNOME_META_STROKE: data = gpm_decode_bpath (data, &bpath); gnome_print_stroke_bpath (dest, bpath); g_free (bpath); break; case GNOME_META_IMAGE: { gdouble affine[6]; gint32 width, height, channels; guchar *buf; data = decode_double (data, &affine[0]); data = decode_double (data, &affine[1]); data = decode_double (data, &affine[2]); data = decode_double (data, &affine[3]); data = decode_double (data, &affine[4]); data = decode_double (data, &affine[5]); data = decode_int (data, &height); data = decode_int (data, &width); data = decode_int (data, &channels); buf = g_new (guchar, height * width * channels); memcpy (buf, data, height * width * channels); data += height * width * channels; gnome_print_image_transform (dest, affine, buf, width, height, channels * width, channels); g_free (buf); break; } case GNOME_META_GLYPHLIST: { GnomeGlyphList *gl; gdouble affine[6]; gint32 len, code, ival, i; gdouble dval; data = decode_double (data, &affine[0]); data = decode_double (data, &affine[1]); data = decode_double (data, &affine[2]); data = decode_double (data, &affine[3]); data = decode_double (data, &affine[4]); data = decode_double (data, &affine[5]); gl = gnome_glyphlist_new (); data = decode_int (data, &len); if (len > 0) { gl->glyphs = g_new (int, len); gl->g_length = len; gl->g_size = len; for (i = 0; i < len; i++) { data = decode_int (data, &ival); gl->glyphs[i] = ival; } } data = decode_int (data, &len); if (len > 0) { gl->rules = g_new (GGLRule, len); gl->r_length = len; gl->r_size = len; for (i = 0; i < len; i++) { data = decode_int (data, &code); gl->rules[i].code = code; switch (code) { case GGL_POSITION: case GGL_ADVANCE: case GGL_COLOR: data = decode_int (data, &ival); gl->rules[i].value.ival = ival; break; case GGL_MOVETOX: case GGL_MOVETOY: case GGL_RMOVETOX: case GGL_RMOVETOY: case GGL_LETTERSPACE: case GGL_KERNING: data = decode_double (data, &dval); gl->rules[i].value.dval = dval; break; case GGL_FONT: { GnomeFont *font; guchar *name; data = decode_double (data, &dval); data = gpm_decode_string (data, &name); font = gnome_font_find (name, dval); if (font == NULL) g_warning ("Cannot find font: %s\n", name); g_free (name); gl->rules[i].value.font = font; break; } default: break; } } } gnome_print_glyphlist_transform (dest, affine, gl); gnome_glyphlist_unref (gl); break; } break; case GNOME_META_COLOR: { gdouble r, g, b, a; data = decode_double (data, &r); data = decode_double (data, &g); data = decode_double (data, &b); gnome_print_setrgbcolor (dest, r, g, b); data = decode_double (data, &a); gnome_print_setopacity (dest, a); break; } case GNOME_META_LINE: data = decode_double (data, &dval); gnome_print_setlinewidth (dest, dval); data = decode_double (data, &dval); gnome_print_setmiterlimit (dest, dval); data = decode_int (data, &ival); gnome_print_setlinejoin (dest, ival); data = decode_int (data, &ival); gnome_print_setlinecap (dest, ival); break; case GNOME_META_DASH: { int n; double *values, offset; data = decode_int (data, &n); values = g_new (double, n); for (i = 0; i < n; i++) { data = decode_double (data, &values [i]); } data = decode_double (data, &offset); gnome_print_setdash (dest, n, values, offset); g_free (values); break; } default: g_warning ("Serious print meta data corruption %d", opcode); break; } }
void DrawPrint( GnomePrintContext *gpc ) { int bl_width = 32; int bl_height = 32; int seq_size = 32; int the_width = RUNG_WIDTH*bl_width; int the_height = RUNG_HEIGHT*bl_height; int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language; GdkPixmap *pixmap_for_print; #ifdef SEQUENTIAL_SUPPORT if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL ) { the_width = SEQ_PAGE_WIDTH*seq_size; the_height = SEQ_PAGE_HEIGHT*seq_size; } #endif pixmap_for_print = gdk_pixmap_new( drawing_area->window/*drawable*/, the_width, the_height, -1/*depth*/ ); if ( pixmap_for_print ) { char TheEnd = FALSE; char NewPage = TRUE; int SizePageOffset = 800; int ScanRung = InfosGene->FirstRung; int PageNumber = 1; do { char Buffer[ LGT_LABEL+LGT_COMMENT+20 ]; GdkPixbuf *pixbuf_for_print; if ( NewPage==TRUE ) { gnome_print_beginpage( gpc, (guchar *)"1" ); NewPage = FALSE; SizePageOffset = 800; sprintf(Buffer, "ClassicLadder" RELEASE_VER_STRING ". Section:%s - Page:%d", SectionArray[ InfosGene->CurrentSection ].Name, PageNumber ); gnome_print_moveto( gpc, 50, 20 ); gnome_print_show( gpc, (guchar *)Buffer ); } gdk_draw_rectangle (pixmap_for_print, drawing_area->style->white_gc, TRUE, 0, 0, the_width, the_height); if ( iCurrentLanguage==SECTION_IN_LADDER ) DrawRung( pixmap_for_print, &RungArray[ ScanRung ], 0/*PosiY*/, bl_width, bl_height, DRAW_FOR_PRINT ); #ifdef SEQUENTIAL_SUPPORT if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL ) { DrawSequentialPage( pixmap_for_print, SectionArray[ InfosGene->CurrentSection ].SequentialPage, DRAW_FOR_PRINT ); TheEnd = TRUE; } #endif pixbuf_for_print = gdk_pixbuf_get_from_drawable( NULL /*GdkPixbuf *dest*/, pixmap_for_print, NULL /*cmap*/, 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/, the_width, the_height); if ( pixbuf_for_print ) { guchar *raw_image; gint rowstride; if ( iCurrentLanguage==SECTION_IN_LADDER ) { char BuffFormat[10] = "%s (%s)"; if ( RungArray[ ScanRung ].Comment[0]=='\0' ) strcpy( BuffFormat, "%s %s" ); sprintf( Buffer, BuffFormat, RungArray[ ScanRung ].Label, RungArray[ ScanRung ].Comment ); gnome_print_moveto( gpc, 50, SizePageOffset ); SizePageOffset = SizePageOffset-20; gnome_print_show( gpc, (guchar *)Buffer ); } raw_image = gdk_pixbuf_get_pixels( pixbuf_for_print ); rowstride = gdk_pixbuf_get_rowstride( pixbuf_for_print ); gnome_print_gsave( gpc ); gnome_print_translate( gpc, 20, SizePageOffset-the_height+15 ); gnome_print_scale( gpc, the_width, the_height ); gnome_print_rgbimage( gpc, raw_image, the_width, the_height, rowstride); gnome_print_grestore( gpc ); SizePageOffset = SizePageOffset-the_height-20; gdk_pixbuf_unref( pixbuf_for_print ); if ( iCurrentLanguage==SECTION_IN_LADDER ) { if ( ScanRung!=InfosGene->LastRung ) ScanRung = RungArray[ ScanRung ].NextRung; else TheEnd = TRUE; } if ( SizePageOffset<200 || TheEnd ) { NewPage = TRUE; PageNumber++; gnome_print_showpage ( gpc ); } } else { printf( "Failed to create pixbuf_for_print\n" ); } } while( !TheEnd ); gdk_pixmap_unref( pixmap_for_print ); } else { printf( "Failed to create pixmap_for_print\n" ); } }
static GnomePrintJob *create_job(GnomePrintConfig *gpc) { GnomeFontFace *font_face; PangoFontDescription *font_desc; GtkTextIter start, end; gchar *text, *p; /* Get contents of TextBuffer */ GtkTextBuffer *buffer = pub->mw->buffer; gtk_text_buffer_get_bounds(buffer, &start, &end); text = g_strchomp(gtk_text_buffer_get_text(buffer, &start, &end, FALSE)); /* Initialize job */ job = gnome_print_job_new(gpc); gnome_print_job_get_page_size_from_config(gpc, &page_width, &page_height); gnome_print_config_get_length(gpc, (guchar *)GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &margin_left, NULL); gnome_print_config_get_length(gpc, (guchar *)GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT, &margin_right, NULL); gnome_print_config_get_length(gpc, (guchar *)GNOME_PRINT_KEY_PAGE_MARGIN_TOP, &margin_top, NULL); gnome_print_config_get_length(gpc, (guchar *)GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &margin_bottom, NULL); /* g_print("margin_left = %f\n", margin_left); g_print("margin_right = %f\n", margin_right); g_print("margin_top = %f\n", margin_top); g_print("margin_bottom = %f\n", margin_bottom); margin_top = margin_left; margin_bottom = margin_left; */ /* Initialize font */ font_desc = gtk_widget_get_style(pub->mw->view)->font_desc; font_face = gnome_font_face_find_closest_from_pango_description(font_desc); font = gnome_font_face_get_font_default(font_face, FONT_SIZE); // pango_font_description_get_size(font_desc) / PANGO_SCALE); // g_print("PANGO_SCALE = %d\n", PANGO_SCALE); // g_print("font_size = %d\n", pango_font_description_get_size(font_desc)); line_height = gnome_font_get_size(font); tab_width = gnome_font_face_get_glyph_width(font_face, gnome_font_face_lookup_default(font_face, g_utf8_get_char(" "))) / 1000 * FONT_SIZE * get_current_tab_width(); DV( g_print("tab_width = %f\n", tab_width)); /* Draw texts to canvas */ gpx = gnome_print_job_get_context(job); gnome_print_beginpage(gpx, NULL); gnome_print_setfont(gpx, font); page_x = margin_left; // TODO RTL page_y = page_height - margin_top - line_height; gnome_print_moveto(gpx, page_x, page_y); gl = gnome_glyphlist_from_text_dumb(font, 0x000000ff, 0, 0, (guchar *)""); gl_width = 0; p = text; while (*p != '\0') { gunichar ch = g_utf8_get_char(p); gint glyph = gnome_font_lookup_default(font, ch); if (!glyph) { if (ch == '\n') { print_glyph_list(page_x + gl_width > page_width - margin_right); move_pen_to_newline(); DV( g_print("LF\n")); } else if (ch == '\t') { print_glyph_list(page_x + gl_width > page_width - margin_right); /* page_x = page_x + tab_width - ((page_x - margin_left) % tab_width); */ gdouble tmp_x = margin_left; do { tmp_x += tab_width; } while (tmp_x < page_x + 0.000001); // FIXME DV( g_print("HT ")); DV( g_print("%f -> %f\n", page_x, tmp_x)); page_x = tmp_x; gnome_print_moveto(gpx, page_x, page_y); /* } else if (ch == '\f') { DV( g_print("FF\n")); print_glyph_list(page_x + gl_width > page_width - margin_right); move_pen_to_nextpage(); */ } else { GnomeFont *tmp_font = find_proper_font(ch); GnomeFontFace *tmp_face = gnome_font_get_face(tmp_font); gdouble g_width; glyph = gnome_font_lookup_default(tmp_font, ch); g_width = gnome_font_face_get_glyph_width(tmp_face, glyph) / 1000 * FONT_SIZE; if (page_x + gl_width + g_width > page_width - margin_right) { if (g_unichar_iswide(ch)) { print_glyph_list(FALSE); move_pen_to_newline(); } else print_glyph_list(TRUE); } gnome_glyphlist_font(gl, tmp_font); gnome_glyphlist_glyph(gl, glyph); gnome_glyphlist_font(gl, font); gl_width += g_width; DV( g_print("** ")); } } else { // if (ch == ' ') { if (g_unichar_isspace(ch)) { DV( g_print("SP ")); DV( g_print("\n")); print_glyph_list(page_x + gl_width > page_width - margin_right); page_x += gnome_font_face_get_glyph_width(font_face, glyph) / 1000 * FONT_SIZE; gnome_print_moveto(gpx, page_x, page_y); } else { gdouble g_width = gnome_font_face_get_glyph_width(font_face, glyph) / 1000 * FONT_SIZE; if (page_x + gl_width + g_width > page_width - margin_right) { if (g_unichar_iswide(ch)) { print_glyph_list(FALSE); move_pen_to_newline(); } else print_glyph_list(TRUE); } gnome_glyphlist_glyph(gl, glyph); gl_width += g_width; DV( g_print("%02X ", glyph)); DV( g_print("%f (%f)\n", gl_width, gnome_font_get_glyph_width(font, glyph))); } } p = g_utf8_next_char(p); } print_glyph_list(page_x + gl_width > page_width - margin_right); DV( g_print("\n[EOT]\n")); gnome_print_showpage(gpx); gnome_print_context_close(gpx); g_object_unref(gpx); gnome_glyphlist_unref(gl); gnome_font_unref(font); gnome_font_face_unref(font_face); gnome_print_job_close(job); return job; }