gfxPSSurface::gfxPSSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints)
    : mStream(aStream), mXDPI(-1), mYDPI(-1), mSize(aSizeInPoints)
{
    cairo_surface_t* ps_surface = cairo_ps_surface_create_for_stream(write_func, (void*)mStream, mSize.width, mSize.height);
    cairo_ps_surface_restrict_to_level(ps_surface, CAIRO_PS_LEVEL_2);
    Init(ps_surface);
}
예제 #2
0
/* static */ already_AddRefed<PrintTargetPS>
PrintTargetPS::CreateOrNull(nsIOutputStream *aStream,
                            IntSize aSizeInPoints,
                            PageOrientation aOrientation)
{
  // The PS output does not specify the page size so to print landscape we need
  // to rotate the drawing 90 degrees and print on portrait paper.  If printing
  // landscape, swap the width/height supplied to cairo to select a portrait
  // print area.  Our consumers are responsible for checking
  // RotateForLandscape() and applying a rotation transform if true.
  if (aOrientation == LANDSCAPE) {
    Swap(aSizeInPoints.width, aSizeInPoints.height);
  }

  cairo_surface_t* surface =
    cairo_ps_surface_create_for_stream(write_func, (void*)aStream,
                                       aSizeInPoints.width,
                                       aSizeInPoints.height);
  if (cairo_surface_status(surface)) {
    return nullptr;
  }
  cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2);

  // The new object takes ownership of our surface reference.
  RefPtr<PrintTargetPS> target = new PrintTargetPS(surface, aSizeInPoints,
                                                   aStream, aOrientation);
  return target.forget();
}
예제 #3
0
static cairo_surface_t *
_ps_surface_create (void *closure,
		    cairo_content_t content,
		    double width, double height)
{
    return cairo_ps_surface_create_for_stream (NULL, NULL, width, height);
}
예제 #4
0
static PyObject *
ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    double width_in_points, height_in_points;
    PyObject *file, *writer;

    if (!PyArg_ParseTuple(args, "Odd:PSSurface.__new__",
			  &file, &width_in_points, &height_in_points))
	return NULL;

    if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
	/* string (filename) argument */
	return PycairoSurface_FromSurface (
                  cairo_ps_surface_create (PyString_AsString(file),
                                     width_in_points, height_in_points),
	       NULL);

    }
    /* else: file or file-like object argument */
    writer = PyObject_GetAttrString (file, "write");
    if (writer == NULL || !PyCallable_Check (writer)) {
	Py_XDECREF(writer);
	PyErr_SetString(PyExc_TypeError,
"PSSurface argument 1 must be a filename (str), file object, or an object "
"that has a \"write\" method (like StringIO)");
	return NULL;
    }
    Py_DECREF(writer);

    return PycairoSurface_FromSurface (
	       cairo_ps_surface_create_for_stream (_write_func, file,
                   width_in_points, height_in_points),
	       file);
}
예제 #5
0
void gt_graphics_cairo_initialize(GtGraphics *gg, GtGraphicsOutType type,
                                  unsigned int width, unsigned int height)
{
  GtGraphicsCairo *g = gt_graphics_cairo_cast(gg);
  g->outbuf = gt_str_new();
  switch (type)
  {
    case GT_GRAPHICS_PDF:
#ifdef CAIRO_HAS_PDF_SURFACE
      g->surf = cairo_pdf_surface_create_for_stream(str_write_func,
                                                    g->outbuf,
                                                    width,
                                                    height);
      break;
#endif
    case GT_GRAPHICS_PS:
#ifdef CAIRO_HAS_PS_SURFACE
      g->surf = cairo_ps_surface_create_for_stream(str_write_func,
                                                   g->outbuf,
                                                   width,
                                                   height);
      break;
#endif
    case GT_GRAPHICS_SVG:
#ifdef CAIRO_HAS_SVG_SURFACE
      g->surf = cairo_svg_surface_create_for_stream(str_write_func,
                                                    g->outbuf,
                                                    width,
                                                    height);
      break;
#endif
    case GT_GRAPHICS_PNG:
    default:
      g->surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
      break;
  }
  gt_assert(g->surf && cairo_surface_status(g->surf) == CAIRO_STATUS_SUCCESS);
  g->cr = cairo_create(g->surf);
  gt_assert(cairo_status(g->cr) == CAIRO_STATUS_SUCCESS);
  /* set background default to transparent */
  g->bg_color.red = g->bg_color.green  = 0.0;
  g->bg_color.blue = g->bg_color.alpha = 0.0;
  g->width = width;
  g->height = height;
  g->margin_x = g->margin_y = 20;
  cairo_set_line_join(g->cr, CAIRO_LINE_JOIN_ROUND);
  cairo_set_line_cap(g->cr, CAIRO_LINE_CAP_ROUND);
  cairo_select_font_face(g->cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL,
                         CAIRO_FONT_WEIGHT_NORMAL);
  g->type = type;
}
예제 #6
0
파일: ml_cairo_ps.c 프로젝트: DMClambo/pfff
static value
_ml_cairo_ps_surface_create_for_stream (value f, value w, value h, cairo_bool_t unsafe)
{
  CAMLparam3(f, w, h);
  value *c;
  cairo_surface_t *surf;

  c = ml_cairo_make_closure (f);
  surf = cairo_ps_surface_create_for_stream (unsafe ? ml_cairo_unsafe_write_func : ml_cairo_write_func,
					     c, Double_val (w), Double_val (h));

  ml_cairo_surface_set_stream_data (surf, c);

  CAMLreturn (Val_cairo_surface_t (surf));
}
예제 #7
0
gfxPSSurface::gfxPSSurface(nsIOutputStream *aStream, const gfxSize& aSizeInPoints, PageOrientation aOrientation)
    : mStream(aStream), mXDPI(-1), mYDPI(-1), mOrientation(aOrientation)
{
    mSize = mozilla::gfx::IntSize(aSizeInPoints.width, aSizeInPoints.height);

    // The PS output does not specify the page size so to print
    // landscape we need to rotate the drawing 90 degrees and print on
    // portrait paper. If printing landscape, swap the width/height
    // supplied to cairo to select a portrait print area. gfxContext
    // will perform the rotation when GetRotateForLandscape() is TRUE.
    mozilla::gfx::IntSize cairoSize;
    if (mOrientation == PORTRAIT) {
        cairoSize = mSize;
    } else {
        cairoSize = mozilla::gfx::IntSize(mSize.height, mSize.width);
    }
    cairo_surface_t* ps_surface = cairo_ps_surface_create_for_stream(write_func, (void*)mStream, cairoSize.width, cairoSize.height);
    cairo_ps_surface_restrict_to_level(ps_surface, CAIRO_PS_LEVEL_2);
    Init(ps_surface);
}
예제 #8
0
static void cairogen_begin_page(GVJ_t * job)
{
    cairo_t *cr = (cairo_t *) job->context;
    cairo_surface_t *surface;
    cairo_status_t status;

    if (cr == NULL) {
        switch (job->render.id) {
        case FORMAT_PS:
#ifdef CAIRO_HAS_PS_SURFACE
	    surface = cairo_ps_surface_create_for_stream (writer,
			job, job->width, job->height);
#endif
	    break;
        case FORMAT_PDF:
#ifdef CAIRO_HAS_PDF_SURFACE
	    surface = cairo_pdf_surface_create_for_stream (writer,
			job, job->width, job->height);
#endif
	    break;
        case FORMAT_SVG:
#ifdef CAIRO_HAS_SVG_SURFACE
	    surface = cairo_svg_surface_create_for_stream (writer,
			job, job->width, job->height);
#endif
	    break;
        case FORMAT_CAIRO:
        case FORMAT_PNG:
        default:
	    if (job->width >= CAIRO_XMAX || job->height >= CAIRO_YMAX) {
		double scale = MIN((double)CAIRO_XMAX / job->width,
			(double)CAIRO_YMAX / job->height);
		job->width *= scale;
		job->height *= scale;
		job->scale.x *= scale;
		job->scale.y *= scale;
                fprintf(stderr,
                        "%s: graph is too large for cairo-renderer bitmaps. Scaling by %g to fit\n", 
                        job->common->cmdname, scale);
	    }
	    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
			job->width, job->height);
            if (job->common->verbose)
                fprintf(stderr,
                        "%s: allocating a %dK cairo image surface (%d x %d pixels)\n",
                        job->common->cmdname,
			ROUND(job->width * job->height * 4 / 1024.),
			job->width, job->height);
	    break;
        }
	status = cairo_surface_status(surface);
        if (status != CAIRO_STATUS_SUCCESS)  {
		fprintf(stderr, "%s: failure to create cairo surface: %s\n",
			job->common->cmdname,
			cairo_status_to_string(status));
		cairo_surface_destroy (surface);
		return;
	}
        cr = cairo_create(surface);
        cairo_surface_destroy (surface);
        job->context = (void *) cr;
    }

    cairo_scale(cr, job->scale.x, job->scale.y);
    cairo_rotate(cr, -job->rotation * M_PI / 180.);
    cairo_translate(cr, job->translation.x, -job->translation.y);

    cairo_rectangle(cr, job->clip.LL.x, - job->clip.LL.y,
	    job->clip.UR.x - job->clip.LL.x, - (job->clip.UR.y - job->clip.LL.y));
    cairo_clip(cr);
    /* cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); */
}