Beispiel #1
0
static VALUE
rg_get_default_bottom_margin(VALUE self, VALUE unit)
{
    return rb_float_new(gtk_paper_size_get_default_bottom_margin(_SELF(self),
                                                                 RVAL2UNIT(unit)));
}
Beispiel #2
0
/* Calculates a page layout.  If page is NULL, uses the first page
 * (this is convenient for single-page rendering).  The required size
 * of the page is returned in extents, and the cairo transformation
 * matrix needed to fit the drawing into the page is returned in mtx.
 * Takes into account all of the margin/orientation/paper settings,
 * and the size of the drawing itself. */
static void
export_layout_page (PAGE *page, cairo_rectangle_t *extents, cairo_matrix_t *mtx)
{
  cairo_rectangle_t drawable;
  int wx_min, wy_min, wx_max, wy_max, w_width, w_height;
  gboolean landscape = FALSE;
  gdouble m[4]; /* Calculated margins */
  gdouble s; /* Calculated scale */
  gdouble slack[2]; /* Calculated alignment slack */

  if (page == NULL) {
    const GList *pages = geda_list_get_glist (toplevel->pages);
    g_assert (pages != NULL && pages->data != NULL);
    page = (PAGE *) pages->data;
  }

  /* Set the margins. If none were provided by the user, get them
   * from the paper size (if a paper size is being used) or just use a
   * sensible default. */
  if (settings.margins[0] >= 0) {
    memcpy (m, settings.margins, 4*sizeof(gdouble));
  } else if (settings.paper != NULL) {
    m[0] = gtk_paper_size_get_default_top_margin (settings.paper, GTK_UNIT_POINTS);
    m[1] = gtk_paper_size_get_default_left_margin (settings.paper, GTK_UNIT_POINTS);
    m[2] = gtk_paper_size_get_default_bottom_margin (settings.paper, GTK_UNIT_POINTS);
    m[3] = gtk_paper_size_get_default_right_margin (settings.paper, GTK_UNIT_POINTS);
  } else {
    m[0] = DEFAULT_MARGIN;
    m[1] = DEFAULT_MARGIN;
    m[2] = DEFAULT_MARGIN;
    m[3] = DEFAULT_MARGIN;
  }

  /* Now calculate extents of objects within page */
  world_get_object_glist_bounds (toplevel, s_page_objects (page),
                                 &wx_min, &wy_min, &wx_max, &wy_max);
  w_width = wx_max - wx_min;
  w_height = wy_max - wy_min;

  /* If a size was specified, use it.  Otherwise, use paper size, if
   * provided.  Fall back to just using the size of the drawing. */
  extents->x = extents->y = 0;
  if (settings.size[0] >= 0) {
    /* get extents from size */

    extents->width = settings.size[0];
    extents->height = settings.size[1];

  } else if (settings.paper != NULL) {
    /* get extents from paper */

    gdouble p_width, p_height;

    /* Select orientation */
    switch (settings.layout) {
    case ORIENTATION_LANDSCAPE:
      landscape = TRUE;
      break;
    case ORIENTATION_PORTRAIT:
      landscape = FALSE;
      break;
    case ORIENTATION_AUTO:
    default:
      landscape = (w_width > w_height);
      break;
    }

    p_width = gtk_paper_size_get_width (settings.paper, GTK_UNIT_POINTS);
    p_height = gtk_paper_size_get_height (settings.paper, GTK_UNIT_POINTS);

    if (landscape) {
      extents->width = p_height;
      extents->height = p_width;
    } else {
      extents->width = p_width;
      extents->height = p_height;
    }
  } else {
    /* get extents from drawing */

    extents->width = w_width * settings.scale; /* in points */
    extents->height = w_height * settings.scale; /* in points */

    /* If the extents were obtained from the drawing, grow the extents
     * rather than shrinking the drawable area.  This ensures that the
     * overall aspect ratio of the image remains correct. */
    extents->width += m[1] + m[3];
    extents->height += m[0] + m[2];
  }

  drawable.x = m[1];
  drawable.y = m[0];

  drawable.width = extents->width - m[1] - m[3];
  drawable.height = extents->height - m[0] - m[2];

  /* Calculate optimum scale */
  s = fmin (drawable.width / w_width, drawable.height / w_height);

  /* Calculate alignment slack */
  slack[0] = fmin (1, fmax (0, settings.align[0])) * (drawable.width - w_width * s);
  slack[1] = fmin (1, fmax (0, settings.align[1])) * (drawable.height - w_height * s);

  /* Finally, create and set a cairo transformation matrix that
   * centres the drawing into the drawable area. */
  cairo_matrix_init (mtx, s, 0, 0, -s,
                     - wx_min * s + drawable.x + slack[0],
                     (wy_min + w_height) * s + drawable.y + slack[1]);
}
Beispiel #3
0
static void papersize(PdfPrintContext *ppc)
{
//GList *list, *item;
const gchar *name;
GtkPaperSize *ps;

	DB( g_print("[papersize]\n") );
	
	name = gtk_paper_size_get_default();

	DB( g_print("- def paper is %s\n", name) );
	
	ps = gtk_paper_size_new(name);



  /*GtkPageSetup *new_page_setup;

  if (settings == NULL)
    settings = gtk_print_settings_new ();

  new_page_setup = gtk_print_run_page_setup_dialog (NULL,
                                                    page_setup, settings);

  if (page_setup)
    g_object_unref (page_setup);

  page_setup = new_page_setup;
*/

//#if MYDEBUG == 1
	gdouble w, h, mt, mb, ml, mr;
	w = gtk_paper_size_get_width(ps, GTK_UNIT_MM);
	h = gtk_paper_size_get_height(ps, GTK_UNIT_MM);
	mt = gtk_paper_size_get_default_top_margin(ps, GTK_UNIT_MM);
	mr = gtk_paper_size_get_default_right_margin(ps, GTK_UNIT_MM);
	mb = gtk_paper_size_get_default_bottom_margin(ps, GTK_UNIT_MM);
	ml = gtk_paper_size_get_default_left_margin(ps, GTK_UNIT_MM);
	
	DB( g_print("- name: %s\n", gtk_paper_size_get_display_name(ps)) );
	DB( g_print("- w: %f (%f)\n- h: %f (%f)\n", w, w/PANGO_SCALE, h, h/PANGO_SCALE) );
	DB( g_print("- margin: %f %f %f %f\n", mt, mr, mb, ml) );

	ppc->w = w * 2.83;
	ppc->h = h * 2.83;
	ppc->mt = mt * 2.83;
	ppc->mr = mr * 2.83;
	ppc->mb = mb * 2.83;
	ppc->ml = ml * 2.83;

//#endif

	gtk_paper_size_free(ps);

	/* list all paper size */
	/*
	list = gtk_paper_size_get_paper_sizes (FALSE);
	item = g_list_first(list);
	while(item != NULL)
	{
		ps = item->data;
		if(ps != NULL)
		{
			g_print("- name: %s\n", gtk_paper_size_get_display_name(ps));
			gtk_paper_size_free(ps);
		}
		item = g_list_next(item);
	}
	g_list_free (list);
	*/
}