static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { DocInfo *dinfo = user_data; PangoFontDescription *desc; if (dinfo == NULL) return; gtk_widget_show(main_widgets.progressbar); /* init dinfo fields */ /* setup printing scintilla object */ dinfo->sci = editor_create_widget(dinfo->doc->editor); scintilla_send_message(dinfo->sci, SCI_SETDOCPOINTER, 0, scintilla_send_message(dinfo->doc->editor->sci, SCI_GETDOCPOINTER, 0, 0)); highlighting_set_styles(dinfo->sci, dinfo->doc->file_type); sci_set_line_numbers(dinfo->sci, printing_prefs.print_line_numbers, 0); scintilla_send_message(dinfo->sci, SCI_SETVIEWWS, SCWS_INVISIBLE, 0); scintilla_send_message(dinfo->sci, SCI_SETVIEWEOL, FALSE, 0); scintilla_send_message(dinfo->sci, SCI_SETEDGEMODE, EDGE_NONE, 0); scintilla_send_message(dinfo->sci, SCI_SETPRINTMAGNIFICATION, (uptr_t) -2, 0); /* WTF? */ scintilla_send_message(dinfo->sci, SCI_SETPRINTCOLOURMODE, SC_PRINT_COLOURONWHITE, 0); dinfo->pages = g_array_new(FALSE, FALSE, sizeof(gint)); dinfo->print_time = time(NULL); /* create a PangoLayout to be commonly used in add_page_header() and draw_page() */ desc = pango_font_description_from_string(interface_prefs.editor_font); dinfo->layout = setup_pango_layout(context, desc); pango_font_description_free(desc); get_text_dimensions(dinfo->layout, "|XMfjgq_" /* reasonably representative character set */, NULL, &dinfo->line_height); get_text_dimensions(dinfo->layout, "99999 " /* Scintilla resets the margin to the width of "99999" when printing */, &dinfo->margin_width, NULL); /* setup dinfo->fr */ setup_range(dinfo, context); }
static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data) { DocInfo *dinfo = user_data; PangoFontDescription *desc; gint i; gint style_max; if (dinfo == NULL) return; gtk_widget_show(main_widgets.progressbar); desc = pango_font_description_from_string(interface_prefs.editor_font); /* init dinfo fields */ dinfo->lines = sci_get_line_count(dinfo->doc->editor->sci); dinfo->lines_per_page = 0; dinfo->cur_line = 0; dinfo->cur_pos = 0; dinfo->long_line = FALSE; dinfo->print_time = time(NULL); dinfo->max_line_number_margin = get_line_numbers_arity(dinfo->lines) + 1; /* increase font width by 1 (looks better) */ dinfo->font_width = get_font_width(context, desc) + 1; /* create a PangoLayout to be commonly used in get_page_count and draw_page */ dinfo->layout = setup_pango_layout(context, desc); /* this is necessary because of possible line breaks on the printed page and then * lines_per_page differs from document line count */ dinfo->n_pages = get_page_count(context, dinfo); /* read all styles from Scintilla */ style_max = pow(2, scintilla_send_message(dinfo->doc->editor->sci, SCI_GETSTYLEBITS, 0, 0)); /* if the lexer uses only the first 32 styles(style bits = 5), * we need to add the pre-defined styles */ if (style_max == 32) style_max = STYLE_LASTPREDEFINED; for (i = 0; i < style_max; i++) { dinfo->styles[i][FORE] = ROTATE_RGB(scintilla_send_message( dinfo->doc->editor->sci, SCI_STYLEGETFORE, i, 0)); if (i == STYLE_LINENUMBER) { /* ignore background colour for line number margin to avoid trouble with wrapped lines */ dinfo->styles[STYLE_LINENUMBER][BACK] = ROTATE_RGB(scintilla_send_message( dinfo->doc->editor->sci, SCI_STYLEGETBACK, STYLE_DEFAULT, 0)); } else { dinfo->styles[i][BACK] = ROTATE_RGB(scintilla_send_message( dinfo->doc->editor->sci, SCI_STYLEGETBACK, i, 0)); } /* use white background color unless foreground is white to save ink */ if (dinfo->styles[i][FORE] != 0xffffff) dinfo->styles[i][BACK] = 0xffffff; dinfo->styles[i][BOLD] = scintilla_send_message(dinfo->doc->editor->sci, SCI_STYLEGETBOLD, i, 0); dinfo->styles[i][ITALIC] = scintilla_send_message(dinfo->doc->editor->sci, SCI_STYLEGETITALIC, i, 0); } if (dinfo->n_pages >= 0) gtk_print_operation_set_n_pages(operation, dinfo->n_pages); pango_font_description_free(desc); }