Пример #1
1
static void
draw_page (GtkPrintOperation *operation,
		   GtkPrintContext   *context,
		   gint               page_nr,
		   gpointer           user_data)
{
    ViewerCbInfo *info = (ViewerCbInfo *) user_data;

	cairo_t *cr;
	gdouble page_width, page_height;
  
	cr = gtk_print_context_get_cairo_context (context);
	page_width = gtk_print_context_get_width (context);
	page_height = gtk_print_context_get_height (context);

	{
		RsvgHandle *handle;
		RsvgDimensionData svg_dimensions;
		struct RsvgSizeCallbackData size_data;

		/* should not fail */
		handle = rsvg_handle_new_from_data(info->svg_bytes->data, info->svg_bytes->len, NULL);
		rsvg_handle_set_base_uri (handle, info->base_uri);
		rsvg_handle_set_dpi_x_y (handle, gtk_print_context_get_dpi_x(context), 
								 gtk_print_context_get_dpi_y(context));
		rsvg_handle_get_dimensions(handle, &svg_dimensions);

        if (svg_dimensions.width > page_width || svg_dimensions.height > page_height) {
            /* scale down the image to the page's size, while preserving the aspect ratio */

            if ((double) svg_dimensions.height * (double) page_width > (double) svg_dimensions.width * (double) page_height) {
                svg_dimensions.width = 0.5 + (double) svg_dimensions.width *(double) page_height / (double) svg_dimensions.height;
                svg_dimensions.height = page_height;
            } else {
                svg_dimensions.height = 0.5 + (double) svg_dimensions.height *(double) page_width / (double) svg_dimensions.width;
                svg_dimensions.width = page_width;
            }
        }

		size_data.type = RSVG_SIZE_WH;
		size_data.width = svg_dimensions.width;
		size_data.height = svg_dimensions.height;
		size_data.keep_aspect_ratio = FALSE;
		rsvg_handle_set_size_callback (handle, _rsvg_size_callback, &size_data, NULL);

		rsvg_handle_render_cairo(handle, cr);

		g_object_unref (handle);
	}
}
Пример #2
0
JNIEXPORT jlong JNICALL
Java_org_gnome_gtk_GtkPrintContext_gtk_1print_1context_1get_1cairo_1context
(
	JNIEnv* env,
	jclass cls,
	jlong _self
)
{
	cairo_t* result;
	jlong _result;
	GtkPrintContext* self;

	// convert parameter self
	self = (GtkPrintContext*) _self;

	// call function
	result = gtk_print_context_get_cairo_context(self);

	// cleanup parameter self

	// translate return value to JNI type
	_result = (jlong) result;

	// and finally
	return _result;
}
Пример #3
0
static void _draw_page_number (GtkPrintContext *context, gint page_nr, GwPageInfo *page, GwPrintData *data)
{
    //Declarations
    PangoLayout *layout;
    char *text;
    PangoFontDescription *desc;
    int width;
    int height;
    cairo_t *cr;
    gdouble drawable_width;

    //Initializations
    text = g_strdup_printf (gettext("Page %d/%d"), page_nr + 1, g_list_length (data->pages));
    layout = gtk_print_context_create_pango_layout (context);
    desc = pango_font_description_from_string ("sans 8");
    cr = gtk_print_context_get_cairo_context (context);
    drawable_width = gtk_print_context_get_width (context);

    //Draw
    if (text != NULL && layout != NULL && desc != NULL)
    {
      pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
      pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
      pango_layout_set_font_description (layout, desc);
      pango_layout_set_markup (layout, text, -1);
      pango_layout_get_size (layout, &width, &height);
      cairo_move_to (cr, (int) drawable_width - PANGO_PIXELS (width), 0);
      pango_cairo_show_layout (cr, layout);
    }

    //Cleanup
    if (text != NULL) g_free (text);
    if (layout != NULL) g_object_unref (layout);
    if (desc != NULL) pango_font_description_free (desc);
}
Пример #4
0
static void
print_job_begin_print(GtkPrintOperation *operation,
		      GtkPrintContext   *context,
		      gpointer           user_data)
{
	PlannerPrintJob *job;
	PlannerPrintJobPriv *priv;
	GList *l;
	PlannerView *view;
	int n_pages = 0;

	job = (PlannerPrintJob *)user_data;
	priv = job->priv;

	job->cr = gtk_print_context_get_cairo_context (context);
	job->pc = context;

	priv->paper_height = gtk_print_context_get_height (context);
	priv->paper_width = gtk_print_context_get_width (context);

	print_job_update_size (job);

	planner_print_job_set_font_regular (job);
	job->x_pad = planner_print_job_get_extents (job, "#") / 2;

	for (l = priv->views; l; l = l->next) {
		view = l->data;
		planner_view_print_init (view, job);

		n_pages += planner_view_print_get_n_pages (view);
	}
	gtk_print_operation_set_n_pages (operation, (n_pages > 0) ? n_pages : 1);
}
Пример #5
0
static void
cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext*
                   context, gint page_number, zathura_t* zathura)
{
  if (context == NULL || zathura == NULL || zathura->document == NULL ||
      zathura->ui.session == NULL || zathura->ui.statusbar.file == NULL) {
    gtk_print_operation_cancel(print_operation);
    return;
  }

  /* Update statusbar. */
  char* tmp = g_strdup_printf(_("Printing page %d ..."), page_number);
  girara_statusbar_item_set_text(zathura->ui.session,
                                 zathura->ui.statusbar.file, tmp);
  g_free(tmp);

  /* Get the page and cairo handle.  */
  cairo_t* cairo       = gtk_print_context_get_cairo_context(context);
  zathura_page_t* page = zathura_document_get_page(zathura->document, page_number);
  if (cairo == NULL || page == NULL) {
    gtk_print_operation_cancel(print_operation);
    return;
  }

  girara_debug("printing page %d ...", page_number);
  if (draw_page_cairo(cairo, zathura, page) == true) {
    return;
  }

  girara_debug("printing page %d (fallback) ...", page_number);
  if (draw_page_image(cairo, context, zathura, page) == false) {
    gtk_print_operation_cancel(print_operation);
  }
}
Пример #6
0
static void
begin_print (GtkPrintOperation *operation,
             GtkPrintContext   *context,
             PrintData         *print_data)
{
  DiaCairoRenderer *cairo_renderer;
  g_return_if_fail (print_data->renderer != NULL);
  cairo_renderer = DIA_CAIRO_RENDERER (print_data->renderer);
  g_return_if_fail (cairo_renderer->cr == NULL);

  /* the renderer wants it's own reference */
#if 0 /* no alpha with printers */
  cairo_renderer->with_alpha = TRUE;
#endif
  cairo_renderer->cr = cairo_reference (gtk_print_context_get_cairo_context (context));
  cairo_renderer->dia = print_data->data;
#if 0 /* needs some text size scaling ... */
  cairo_renderer->layout = gtk_print_context_create_pango_layout (context);
#endif

  /* scaling - as usual I don't get it, or do I? */
  cairo_renderer->scale = (
      gtk_page_setup_get_paper_width (gtk_print_context_get_page_setup (context), GTK_UNIT_MM) 
      - gtk_page_setup_get_left_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
      - gtk_page_setup_get_right_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
      ) / print_data->data->paper.width;
  cairo_renderer->skip_show_page = TRUE;
}
Пример #7
0
static void _draw_page_title (GtkPrintContext *context, GwPageInfo *page, GwPrintData *data) {
    //Declarations
    PangoLayout *layout;
    char *text;
    PangoFontDescription *desc;
    int width;
    int height;
    gint index;
    cairo_t *cr;
    LwSearch *search;

    //Initializations
    index = gw_searchwindow_get_current_tab_index (data->window);
    search = gw_searchwindow_get_searchitem_by_index (data->window, index);
    text = gw_searchwindow_get_title_by_searchitem (data->window, search);
    layout = gtk_print_context_create_pango_layout (context);
    desc = pango_font_description_from_string ("sans 8");
    cr = gtk_print_context_get_cairo_context (context);

    //Draw
    if (text != NULL && layout != NULL && desc != NULL)
    {
      cairo_move_to (cr, 0, 0);
      pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
      pango_layout_set_font_description (layout, desc);
      pango_layout_set_markup (layout, text, -1);
      pango_layout_get_size (layout, &width, &height);
      pango_cairo_show_layout (cr, layout);
    }

    //Cleanup
    if (text != NULL) g_free (text);
    if (layout != NULL) g_object_unref (layout);
    if (desc != NULL) pango_font_description_free (desc);
}
Пример #8
0
static void
draw_page_text (GtkPrintOperation * op, GtkPrintContext * cnt, gint page, gpointer data)
{
  cairo_t *cr;
  PangoLayout *layout;
  gint i, line;

  cr = gtk_print_context_get_cairo_context (cnt);

  /* create header */
  if (options.print_data.headers)
    draw_header (cnt, page + 1, npages);

  /* add text */
  layout = gtk_print_context_create_pango_layout (cnt);
  pango_layout_set_font_description (layout, fdesc);

  cairo_move_to (cr, 0, HEADER_HEIGHT + HEADER_GAP);

  line = page * nlines;
  for (i = 0; i < nlines; i++)
    {
      if (text[line + i] == NULL)
        break;
      pango_layout_set_text (layout, text[line + i], -1);
      pango_cairo_show_layout (cr, layout);
      cairo_rel_move_to (cr, 0, FONTSIZE);
    }

  g_object_unref (layout);
}
Пример #9
0
static void
e_contact_output (GtkPrintContext *context,
                  PangoFontDescription *font,
                  gdouble x,
                  gdouble y,
                  gdouble width,
                  const gchar *text)
{
	PangoLayout *layout;
	gdouble indent;
	cairo_t *cr;

	layout = gtk_print_context_create_pango_layout (context);

	if (width == -1 || get_font_width (context, font, text) <= width)
		indent = .0;
	else
		indent = get_font_width (context, font, "     ");

	pango_layout_set_font_description (layout, font);
	pango_layout_set_text (layout, text, -1);
	pango_layout_set_width (layout, pango_units_from_double (width));
	pango_layout_set_indent (layout, pango_units_from_double (indent));
	pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);

	cr = gtk_print_context_get_cairo_context (context);

	cairo_save (cr);
	cairo_move_to (cr, x, y);
	pango_cairo_show_layout (cr, layout);
	cairo_restore (cr);

	g_object_unref (layout);
}
Пример #10
0
static void setup_range(DocInfo *dinfo, GtkPrintContext *ctx)
{
	dinfo->fr.hdc = dinfo->fr.hdcTarget = gtk_print_context_get_cairo_context(ctx);

	dinfo->fr.rcPage.left   = 0;
	dinfo->fr.rcPage.top    = 0;
	dinfo->fr.rcPage.right  = gtk_print_context_get_width(ctx);
	dinfo->fr.rcPage.bottom = gtk_print_context_get_height(ctx);

	dinfo->fr.rc.left   = dinfo->fr.rcPage.left;
	dinfo->fr.rc.top    = dinfo->fr.rcPage.top;
	dinfo->fr.rc.right  = dinfo->fr.rcPage.right;
	dinfo->fr.rc.bottom = dinfo->fr.rcPage.bottom;
#if GTK_CHECK_VERSION(2, 20, 0)
	{
		gdouble m_top, m_left, m_right, m_bottom;
		if (gtk_print_context_get_hard_margins(ctx, &m_top, &m_bottom, &m_left, &m_right))
		{
			dinfo->fr.rc.left   += m_left;
			dinfo->fr.rc.top    += m_top;
			dinfo->fr.rc.right  -= m_right;
			dinfo->fr.rc.bottom -= m_bottom;
		}
	}
#endif
	if (printing_prefs.print_page_header)
		dinfo->fr.rc.top += dinfo->line_height * 3; /* header height */
	if (printing_prefs.print_page_numbers)
		dinfo->fr.rc.bottom -= dinfo->line_height * 1; /* footer height */

	dinfo->fr.chrg.cpMin = 0;
	dinfo->fr.chrg.cpMax = sci_get_length(dinfo->sci);
}
Пример #11
0
static void
draw_page (GtkPrintOperation *operation,
	   GtkPrintContext *context,
	   int page_nr,
	   PrintData *print_data)
{
  cairo_t *cr;
  GList *pagebreak;
  int start, end, i;
  PangoLayoutIter *iter;
  double start_pos;

  if (page_nr == 0)
    start = 0;
  else
    {
      pagebreak = g_list_nth (print_data->page_breaks, page_nr - 1);
      start = GPOINTER_TO_INT (pagebreak->data);
    }

  pagebreak = g_list_nth (print_data->page_breaks, page_nr);
  if (pagebreak == NULL)
    end = pango_layout_get_line_count (print_data->layout);
  else
    end = GPOINTER_TO_INT (pagebreak->data);
    
  cr = gtk_print_context_get_cairo_context (context);

  cairo_set_source_rgb (cr, 0, 0, 0);
  
  i = 0;
  start_pos = 0;
  iter = pango_layout_get_iter (print_data->layout);
  do
    {
      PangoRectangle   logical_rect;
      PangoLayoutLine *line;
      int              baseline;

      if (i >= start)
	{
	  line = pango_layout_iter_get_line (iter);

	  pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
	  baseline = pango_layout_iter_get_baseline (iter);
	  
	  if (i == start)
	    start_pos = logical_rect.y / 1024.0;
	  
	  cairo_move_to (cr, logical_rect.x / 1024.0, baseline / 1024.0 - start_pos);
	  
	  pango_cairo_show_layout_line  (cr, line);
	}
      i++;
    }
  while (i < end &&
	 pango_layout_iter_next_line (iter));

  pango_layout_iter_free (iter);
}
Пример #12
0
static void
unix_end_page (GtkPrintOperation *op,
	       GtkPrintContext   *print_context)
{
  cairo_t *cr;

  cr = gtk_print_context_get_cairo_context (print_context);
  cairo_show_page (cr);
}
static gint
gp_draw_rect (GtkPrintContext *context, double x, double y, double width, double height)
{
	cairo_t *cr;
	cr = gtk_print_context_get_cairo_context (context);
	cairo_move_to (cr, x, y);
	cairo_rectangle (cr, x, y, x + width, y + height);
	cairo_fill (cr);
}
Пример #14
0
static void
e_contact_print_letter_heading (EContactPrintContext *ctxt,
                                gchar *letter)
{
	PangoLayout *layout;
	PangoFontDescription *desc;
	PangoFontMetrics *metrics;
	gint width, height;
	cairo_t *cr;

	desc = ctxt->letter_heading_font;

	layout = gtk_print_context_create_pango_layout (ctxt->context);

	/* Make the rectangle thrice the average character width.
	 * XXX Works well for English, what about other locales? */
	metrics = pango_context_get_metrics (
		pango_layout_get_context (layout),
		desc, pango_language_get_default ());
	width = pango_font_metrics_get_approximate_char_width (metrics) * 3;
	pango_font_metrics_unref (metrics);

	pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
	pango_layout_set_font_description (layout, desc);
	pango_layout_set_text (layout, letter, -1);
	pango_layout_set_width (layout, width);
	pango_layout_get_size (layout, NULL, &height);

	if (ctxt->page_nr == -1 || ctxt->pages != ctxt->page_nr) {
		/* only calculating number of pages
		 * or on page we do not want to print */
		ctxt->y += pango_units_to_double (height);

		return;
	}

	/* Draw white text centered in a black rectangle. */
	cr = gtk_print_context_get_cairo_context (ctxt->context);

	cairo_save (cr);
	cairo_set_source_rgb (cr, .0, .0, .0);
	cairo_rectangle (
		cr, ctxt->x, ctxt->y,
		pango_units_to_double (width),
		pango_units_to_double (height));
	cairo_fill (cr);
	cairo_restore (cr);

	cairo_save (cr);
	cairo_move_to (cr, ctxt->x, ctxt->y);
	cairo_set_source_rgb (cr, 1., 1., 1.);
	pango_cairo_show_layout (cr, layout);
	cairo_restore (cr);

	ctxt->y += pango_units_to_double (height);
}
Пример #15
0
static void
draw_page (GtkPrintOperation *operation,
	   GtkPrintContext *context,
	   int page_nr)
{
  cairo_t *cr;
  PangoLayout *layout;
  PangoFontDescription *desc;
  
  cr = gtk_print_context_get_cairo_context (context);

  /* Draw a red rectangle, as wide as the paper (inside the margins) */
  cairo_set_source_rgb (cr, 1.0, 0, 0);
  cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
  
  cairo_fill (cr);

  /* Draw some lines */
  cairo_move_to (cr, 20, 10);
  cairo_line_to (cr, 40, 20);
  cairo_arc (cr, 60, 60, 20, 0, G_PI);
  cairo_line_to (cr, 80, 20);
  
  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 5);
  cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
  cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
  
  cairo_stroke (cr);

  /* Draw some text */
  
  layout = gtk_print_context_create_pango_layout (context);
  pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
  desc = pango_font_description_from_string ("sans 28");
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  cairo_move_to (cr, 30, 20);
  pango_cairo_layout_path (cr, layout);

  /* Font Outline */
  cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
  cairo_set_line_width (cr, 0.5);
  cairo_stroke_preserve (cr);

  /* Font Fill */
  cairo_set_source_rgb (cr, 0, 0.0, 1.0);
  cairo_fill (cr);

  g_object_unref (layout);
}
Пример #16
0
static void
portal_end_page (GtkPrintOperation *op,
                 GtkPrintContext   *print_context)
{
  cairo_t *cr;

  cr = gtk_print_context_get_cairo_context (print_context);

  if ((op->priv->manual_number_up < 2) ||
      ((op->priv->page_position + 1) % op->priv->manual_number_up == 0) ||
      (op->priv->page_position == op->priv->nr_of_pages_to_print - 1))
    cairo_show_page (cr);
}
Пример #17
0
static void draw_page(GtkPrintOperation *operation,
			GtkPrintContext *context,
			gint page_nr,
			gpointer user_data)
{
	cairo_t *cr;
	PangoLayout *layout;
	double w, h;
	struct graphics_context gc = { .printer = 1 };

	cr = gtk_print_context_get_cairo_context(context);
	gc.cr = cr;

	layout=gtk_print_context_create_pango_layout(context);

	w = gtk_print_context_get_width(context);
	h = gtk_print_context_get_height(context);

	/* Do the profile on the top half of the page.. */
	plot(&gc, w, h/2, current_dive);

	pango_cairo_show_layout(cr,layout);
	g_object_unref(layout);
}

static void begin_print(GtkPrintOperation *operation, gpointer user_data)
{
}

static GtkPrintSettings *settings = NULL;

void do_print(void)
{
	GtkPrintOperation *print;
	GtkPrintOperationResult res;

	print = gtk_print_operation_new();
	if (settings != NULL)
		gtk_print_operation_set_print_settings(print, settings);
	gtk_print_operation_set_n_pages(print, 1);
	g_signal_connect(print, "begin_print", G_CALLBACK(begin_print), NULL);
	g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), NULL);
	res = gtk_print_operation_run(print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
					 GTK_WINDOW(main_window), NULL);
	if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
		if (settings != NULL)
			g_object_unref(settings);
		settings = g_object_ref(gtk_print_operation_get_print_settings(print));
	}
	g_object_unref(print);
}
Пример #18
0
static void _draw_page_results (GtkPrintContext *context, GwPageInfo *page, GwPrintData *data)
{
    //Declarations
    GtkTextView *view;
    GtkTextBuffer *buffer;
    PangoLayout *layout;
    char *text;
    PangoFontDescription *desc;
    int width;
    int height;
    gdouble drawable_width, drawable_height;
    cairo_t *cr;
    gint line_start;
    gint line_end;

    //Initializations
    view = gw_searchwindow_get_current_textview (data->window);
    buffer = gtk_text_view_get_buffer (view);
    text = gtk_text_buffer_get_text (buffer, &(page->start), &(page->end), FALSE);
    layout = gtk_print_context_create_pango_layout (context);
    desc = pango_font_description_from_string ("sans 10");
    drawable_width = gtk_print_context_get_width (context);
    drawable_height = gtk_print_context_get_height (context);
    cr = gtk_print_context_get_cairo_context (context);
    line_start = 0;
    line_end = 0;

    //Draw
    if (text != NULL)
    {
      cairo_move_to (cr, 5, 10);
      pango_layout_set_font_description (layout, desc);
      pango_layout_set_markup (layout, text, -1);
      pango_layout_set_width (layout, drawable_width * PANGO_SCALE);
      pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
      pango_layout_set_height (layout, drawable_height * PANGO_SCALE);
      pango_layout_get_size (layout, &width, &height);
      pango_cairo_show_layout (cr, layout);
      
      //Adjust the end GtkTextIter to the cutoff in the visible cairo context
      line_start = gtk_text_iter_get_line (&page->start);
      line_end = line_start + pango_layout_get_line_count (layout) - 1;
      gtk_text_buffer_get_iter_at_line (buffer, &(page->end), line_end);
    }

    //Cleanup
    if (text != NULL) g_free (text);
    if (layout != NULL) g_object_unref (layout);
    if (desc != NULL) pango_font_description_free (desc);
}
Пример #19
0
static void
draw_header (GtkPrintContext * cnt, gint pn, gint pc)
{
  cairo_t *cr;
  PangoFontDescription *desc;
  PangoLayout *layout;
  gint pw, tw, th;
  gchar *page;

  cr = gtk_print_context_get_cairo_context (cnt);
  pw = gtk_print_context_get_width (cnt);

  layout = gtk_print_context_create_pango_layout (cnt);

  desc = pango_font_description_from_string (HEADER_FONT);
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  pango_layout_set_text (layout, options.common_data.uri, -1);
  pango_layout_get_pixel_size (layout, &tw, &th);
  if (tw > pw)
    {
      pango_layout_set_width (layout, pw);
      pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_START);
      pango_layout_get_pixel_size (layout, &tw, &th);
    }

  cairo_move_to (cr, (pw - tw) / 2, (HEADER_HEIGHT - th) / 2);
  pango_cairo_show_layout (cr, layout);

  page = g_strdup_printf ("%d/%d", pn, pc);
  pango_layout_set_text (layout, page, -1);
  g_free (page);

  pango_layout_set_width (layout, -1);
  pango_layout_get_pixel_size (layout, &tw, &th);
  cairo_move_to (cr, pw - tw - 4, (HEADER_HEIGHT - th) / 2);
  pango_cairo_show_layout (cr, layout);

  g_object_unref (layout);

  cairo_move_to (cr, 0.0, HEADER_HEIGHT);
  cairo_line_to (cr, pw, HEADER_HEIGHT);

  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 1);
  cairo_stroke (cr);
}
Пример #20
0
void XAP_UnixDialog_Print::BeginPrint(GtkPrintContext   *context)
{
    // Note: Help landscape printing survive, don't do anything on the cairo
    // context in this function.  Any transformations etc. shall take place in
    // PrintPage, because GtkPrint may do some transformations itself (which
    // will come out differently if we scale here).
	cairo_t* cr = gtk_print_context_get_cairo_context (context);
	//
	// The cairo context is automatically unref'd at the end of the print
	// so we need to reference it to allow it to be deleted by the PrintGraphics
	// class
	cairo_reference(cr);
	gtk_print_operation_set_n_pages (m_pPO,m_iNumberPages);
	AP_FrameData *pFrameData = static_cast<AP_FrameData *>(m_pFrame->getFrameData());

	xxx_UT_DEBUGMSG(("Initial Cairo Context %x \n",cr));
	m_pPrintGraphics = (GR_Graphics *) new GR_CairoPrintGraphics(cr, gr_PRINTRES);

	double ScreenRes = m_pView->getGraphics()->getDeviceResolution();
	static_cast<GR_CairoPrintGraphics *>(m_pPrintGraphics)
        ->setResolutionRatio(gr_PRINTRES/ScreenRes);

	if(m_pView->getViewMode() == VIEW_PRINT )
	{
			m_pPrintLayout = m_pDL;
			m_pPrintView = m_pView;
			m_pPrintLayout->setQuickPrint(m_pPrintGraphics);
			m_bDidQuickPrint = true;
			if(pFrameData->m_bShowPara)
			{
				m_pPrintView->setShowPara(false);
				m_bShowParagraphs = true;
			}
			else
				m_bShowParagraphs = false;
	}
	else
	{
			m_pPrintLayout = new FL_DocLayout(m_pView->getDocument(),m_pPrintGraphics);
			m_pPrintView = new FV_View(XAP_App::getApp(),0,m_pPrintLayout);
			m_pPrintView->getLayout()->fillLayouts();
			m_pPrintView->getLayout()->formatAll();
			m_pPrintView->getLayout()->recalculateTOCFields();
			m_bDidQuickPrint = false;
	}
	m_pPrintGraphics->startPrint();
}
Пример #21
0
static void
print_draw_crop_marks (GtkPrintContext *context,
                       gdouble          x,
                       gdouble          y,
                       gdouble          w,
                       gdouble          h)
{
  cairo_t *cr  = gtk_print_context_get_cairo_context (context);
  gdouble  len = MIN (gtk_print_context_get_width (context),
                      gtk_print_context_get_height (context)) / 20.0;

  /*  upper left  */

  cairo_move_to (cr, x - len,     y);
  cairo_line_to (cr, x - len / 5, y);

  cairo_move_to (cr, x, y - len);
  cairo_line_to (cr, x, y - len / 5);

  /*  upper right  */

  cairo_move_to (cr, x + w + len / 5, y);
  cairo_line_to (cr, x + w + len,     y);

  cairo_move_to (cr, x + w, y - len);
  cairo_line_to (cr, x + w, y - len / 5);

  /*  lower left  */

  cairo_move_to (cr, x - len,     y + h);
  cairo_line_to (cr, x - len / 5, y + h);

  cairo_move_to (cr, x, y + h + len);
  cairo_line_to (cr, x, y + h + len / 5);

  /*  lower right  */

  cairo_move_to (cr, x + w + len / 5, y + h);
  cairo_line_to (cr, x + w + len,     y + h);

  cairo_move_to (cr, x + w, y + h + len);
  cairo_line_to (cr, x + w, y + h + len / 5);

  cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
  cairo_set_line_width (cr, 2);
  cairo_stroke (cr);
}
Пример #22
0
/* contact_page_draw_footer inserts the
 * page number at the end of each page
 * while printing*/
void
contact_page_draw_footer (GtkPrintOperation *operation,
                          GtkPrintContext *context,
                          gint page_nr)
{
	PangoFontDescription *desc;
	PangoLayout *layout;
	gdouble x, y, page_height, page_width, page_margin;
	/*gint n_pages;*/
	gchar *text;
	cairo_t *cr;
	GtkPageSetup *setup;

	/*Uncomment next if it is successful to get total number if pages in list view
	 * g_object_get (operation, "n-pages", &n_pages, NULL)*/
	text = g_strdup_printf (_("Page %d"), page_nr + 1);

	setup = gtk_print_context_get_page_setup ( context);
	page_height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS);
	page_width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS);
	page_margin = gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_POINTS);

	desc = pango_font_description_from_string ("Sans Regular 8");
	layout = gtk_print_context_create_pango_layout (context);
	pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
	pango_layout_set_font_description (layout, desc);
	pango_layout_set_text (layout, text, -1);
	pango_layout_set_width (layout, -1);

	x = page_width / 2.0 - page_margin;
	y = page_height - page_margin / 2.0;

	cr = gtk_print_context_get_cairo_context (context);

	cairo_save (cr);
	cairo_set_source_rgb (cr, .0, .0, .0);
	cairo_move_to (cr, x, y);
	pango_cairo_show_layout (cr, layout);
	cairo_restore (cr);

	g_object_unref (layout);
	pango_font_description_free (desc);

	g_free (text);
}
Пример #23
0
static void
biorhythm_print_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data)
{
	cairo_t *cr;
	gdouble p_width, p_height;
	GtkPageSetup *page_setup;
	BiorhythmChart *chart;

	chart = (BiorhythmChart *) user_data;

	page_setup = gtk_print_context_get_page_setup (context);
	p_width =  gtk_page_setup_get_page_width (page_setup, GTK_UNIT_POINTS);
	p_height = gtk_page_setup_get_page_height (page_setup, GTK_UNIT_POINTS);

	cr = gtk_print_context_get_cairo_context (context);

  	biorhythm_chart_draw_cairo (chart, cr, p_height, p_width);
}
Пример #24
0
static int
create_cairo(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv)
{
  cairo_t *cairo;
  int dpi, id, r;
  struct gra2cairo_local *local;
  GtkPrintContext *gpc;

  gpc = GTK_PRINT_CONTEXT(argv[2]);

  if (gpc == NULL) {
    error(obj, CAIRO_STATUS_NULL_POINTER + 100);
    return 1;
  }

  cairo = gtk_print_context_get_cairo_context(gpc);

  r = cairo_status(cairo);
  if (r != CAIRO_STATUS_SUCCESS) {
    error(obj, r + 100);
    return 1;
  }

  _getobj(obj, "id", inst, &id);

  dpi = gtk_print_context_get_dpi_x(gpc);
  if (putobj(obj, "dpix", id, &dpi) < 0) {
    error(obj, ERRFIELD);
    return 1;
  }

  dpi = gtk_print_context_get_dpi_y(gpc);
  if (putobj(obj, "dpiy", id, &dpi) < 0) {
    error(obj, ERRFIELD);
    return 1;
  }

  _getobj(obj, "_local", inst, &local);

  local->cairo = cairo;

  return 0;
}
Пример #25
0
static void cb_draw_page(GtkPrintOperation *op,
		GtkPrintContext *ctx, gint page_nr, gpointer data)
{
	cairo_t *cr;
	PangoLayoutLine *line;
	gint n_line, i, j = 0;
	
	PangoLayout *layout_lh, *layout_rh;
	gchar *page_text;
	gint layout_width;
	
	cr = gtk_print_context_get_cairo_context(ctx);
	
	layout_lh = gtk_print_context_create_pango_layout(ctx);
	pango_layout_set_font_description(layout_lh, font_desc);
	pango_layout_set_text(layout_lh, page_title, -1);
	cairo_move_to(cr, 0, - 72 / 25.4 * 10);
	pango_cairo_show_layout(cr, layout_lh);
	
	page_text = g_strdup_printf("%d / %d", page_nr + 1, n_pages);
	layout_rh = gtk_print_context_create_pango_layout(ctx);
	pango_layout_set_font_description(layout_rh, font_desc);
	pango_layout_set_text(layout_rh, page_text, -1);
//	pango_layout_set_alignment(layout_rh, PANGO_ALIGN_RIGHT);
	pango_layout_get_size(layout_rh, &layout_width, NULL);
	cairo_move_to(cr,
		page_width - layout_width / PANGO_SCALE, - 72 / 25.4 * 10);
	pango_cairo_show_layout(cr, layout_rh);
	g_free(page_text);
	
	if (line_count > lines_per_page * (page_nr + 1))
		n_line = lines_per_page * (page_nr + 1);
	else
		n_line = line_count;
	
	for (i = lines_per_page * page_nr; i < n_line; i++) {
		line = pango_layout_get_line(layout, i);
		cairo_move_to(cr, 0, text_height * (j + 1));
		pango_cairo_show_layout_line(cr, line);
		j++;
	}	
}
Пример #26
0
gboolean
print_draw_page (GtkPrintContext *context,
                 PrintData       *data,
                 GError         **error)
{
  cairo_t         *cr = gtk_print_context_get_cairo_context (context);
  cairo_surface_t *surface;
  gint             width;
  gint             height;
  gdouble          scale_x;
  gdouble          scale_y;

  surface = print_surface_from_drawable (data->drawable_id, error);

  if (surface)
    {
      width  = cairo_image_surface_get_width (surface);
      height = cairo_image_surface_get_height (surface);

      scale_x = gtk_print_context_get_dpi_x (context) / data->xres;
      scale_y = gtk_print_context_get_dpi_y (context) / data->yres;

      cairo_translate (cr, data->offset_x, data->offset_y);

      if (data->draw_crop_marks)
        print_draw_crop_marks (context,
                               0, 0, width * scale_x, height * scale_y);

      cairo_scale (cr, scale_x, scale_y);
      cairo_rectangle (cr, 0, 0, width, height);
      cairo_set_source_surface (cr, surface, 0, 0);
      cairo_fill (cr);

      cairo_surface_destroy (surface);

      return TRUE;
    }
  else
    {
      return FALSE;
    }
}
Пример #27
0
static void
ecc_print (ECellView *ecell_view, GtkPrintContext *context,
	    int model_col, int view_col, int row,
	    double width, double height)
{
	cairo_t *cr = gtk_print_context_get_cairo_context (context);
	const int value = GPOINTER_TO_INT (
			  e_table_model_value_at (ecell_view->e_table_model, model_col, row));
	cairo_save (cr);

	if ( value == 1) {

		cairo_set_line_width (cr, 2);
		cairo_move_to (cr, 3, 11);
		cairo_line_to (cr, 7, 14);
		cairo_line_to (cr, 11, 5);
		cairo_stroke (cr);
	}
	cairo_restore (cr);
}
Пример #28
0
gdouble
planner_print_job_get_extents (PlannerPrintJob *job, char *text)
{
	PangoLayout *layout = gtk_print_context_create_pango_layout (job->pc);
	PlannerPrintJobPriv *priv;
	PangoRectangle ink;

	priv = job->priv;

	pango_layout_set_font_description (layout, priv->current_font);
	pango_layout_set_text (layout, text, -1);

        pango_cairo_update_layout (gtk_print_context_get_cairo_context(job->pc), layout);
	pango_layout_context_changed (layout);

	pango_layout_get_extents (layout, &ink, NULL);

	g_object_unref (layout);

	return ((gdouble)ink.width / PANGO_SCALE);
}
Пример #29
0
static void
draw_page_image (GtkPrintOperation * op, GtkPrintContext * cnt, gint page, gpointer data)
{
  cairo_t *cr;
  GdkPixbuf *pb, *spb;
  guint iw, ih;
  gdouble pw, ph;
  gdouble factor;

  cr = gtk_print_context_get_cairo_context (cnt);

  pw = gtk_print_context_get_width (cnt);
  ph = gtk_print_context_get_height (cnt);
  if (options.print_data.headers)
    ph -= HEADER_HEIGHT + HEADER_GAP;

  /* create header */
  if (options.print_data.headers)
    draw_header (cnt, 1, 1);

  /* scale image to page size */
  pb = gdk_pixbuf_new_from_file (options.common_data.uri, NULL);
  iw = gdk_pixbuf_get_width (pb);
  ih = gdk_pixbuf_get_height (pb);

  if (pw < iw || ph < ih)
    {
      factor = MIN (pw / iw, ph / ih);
      factor = (factor > 1.0) ? 1.0 : factor;
      spb = gdk_pixbuf_scale_simple (pb, iw * factor, ih * factor, GDK_INTERP_HYPER);
    }
  else
    spb = g_object_ref (pb);
  g_object_unref (pb);

  /* add image to surface */
  gdk_cairo_set_source_pixbuf (cr, spb, 0.0, HEADER_HEIGHT + HEADER_GAP);
  cairo_paint (cr);
  g_object_unref (spb);
}
Пример #30
0
static void
_draw_footer(GtkHTML * html, GtkPrintOperation * operation,
	     GtkPrintContext * context,
	     gint page_nr, PangoRectangle * rec, EDITOR * e)
{
	PangoFontDescription *desc;
	PangoLayout *layout;
	gdouble x, y;
	gint n_pages;
	gchar *text;
	cairo_t *cr;

	g_object_get(operation, "n-pages", &n_pages, NULL);
	text = g_strdup_printf(_("Page %d of %d"), page_nr + 1, n_pages);

	desc = pango_font_description_from_string("Sans Regular 10");
	layout = gtk_print_context_create_pango_layout(context);
	pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
	pango_layout_set_font_description(layout, desc);
	pango_layout_set_text(layout, text, -1);
	pango_layout_set_width(layout, rec->width);

	x = pango_units_to_double(rec->x);
	y = pango_units_to_double(rec->y);

	cr = gtk_print_context_get_cairo_context(context);

	cairo_save(cr);
	cairo_set_source_rgb(cr, .0, .0, .0);
	cairo_move_to(cr, x, y);
	pango_cairo_show_layout(cr, layout);
	cairo_restore(cr);

	g_object_unref(layout);
	pango_font_description_free(desc);

	g_free(text);
}