Esempio n. 1
0
/////////////////////////////////////////////////////////////////////////////
// SurfaceEps
SurfaceEps::SurfaceEps( const std::string &filePath, double widthInPoints, double heightInPoints, bool enableLevel3 )
	: SurfaceBase( (int32_t)widthInPoints, (int32_t)heightInPoints )
{
	mCairoSurface = cairo_ps_surface_create( filePath.c_str(), widthInPoints, heightInPoints ); 
	cairo_ps_surface_set_eps( mCairoSurface, TRUE );
	cairo_ps_surface_restrict_to_level( mCairoSurface, ( enableLevel3 ) ? CAIRO_PS_LEVEL_3 : CAIRO_PS_LEVEL_2 );
}
Esempio n. 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();
}
Esempio n. 3
0
// cairo_public void
// cairo_ps_surface_restrict_to_level (cairo_surface_t    *surface,
//                                     cairo_ps_level_t    level);
static int l_cairo_ps_surface_restrict_to_level(lua_State* L)
{
    cairo_surface_t	*surface = get_cairo_surface_t (L, 1);
    cairo_ps_level_t level = (cairo_ps_level_t)luaL_checkinteger(L, 2);
    cairo_ps_surface_restrict_to_level (surface, level);
    return 0;
}
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);
}
Esempio n. 5
0
static VALUE
cr_ps_surface_restrict_to_level (VALUE self, VALUE level)
{
  cairo_ps_surface_restrict_to_level (_SELF, RVAL2CRPSLEVEL (level));
  cr_surface_check_status (_SELF);
  return Qnil;
}
Esempio n. 6
0
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    cairo_surface_t *surface;

    /* get the error surface */
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);

#if CAIRO_HAS_GL_SURFACE
    cairo_gl_surface_set_size (surface, 0, 0);
    cairo_gl_surface_swapbuffers (surface);
#endif

#if CAIRO_HAS_OS2_SURFACE
    cairo_os2_surface_set_hwnd (surface, 0);
    cairo_os2_surface_set_size (surface, 0, 0);
    cairo_os2_surface_set_manual_window_refresh (surface, FALSE);
#endif

#if CAIRO_HAS_PDF_SURFACE
    cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
    cairo_pdf_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_PS_SURFACE
    cairo_ps_surface_set_eps (surface, FALSE);
    cairo_ps_surface_set_size (surface, 0, 0);
    cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
    cairo_ps_surface_dsc_comment (surface, NULL);
    cairo_ps_surface_dsc_begin_setup (surface);
    cairo_ps_surface_dsc_begin_page_setup (surface);
#endif

#if CAIRO_HAS_XCB_SURFACE
    cairo_xcb_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_XLIB_SURFACE
    cairo_xlib_surface_set_size (surface, 0, 0);
    cairo_xlib_surface_set_drawable (surface, 0, 0, 0);
#endif

    cairo_surface_set_mime_data (surface, NULL, NULL, 0, NULL, 0);
    cairo_surface_set_device_offset (surface, 0, 0);
    cairo_surface_set_fallback_resolution (surface, 0, 0);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 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);
}
Esempio n. 8
0
static cairo_t *
create_cairo(struct objlist *obj, N_VALUE *inst, char *fname, int iw, int ih, int *err)
{
  cairo_surface_t *ps;
  cairo_t *cairo;
  double w, h;
  int format, dpi, r;
  struct gra2cairo_local *local;

#ifdef WINDOWS
  fname = g_locale_from_utf8(fname, -1, NULL, NULL, NULL);
#else  /* WINDOWS */
  fname = g_filename_from_utf8(fname, -1, NULL, NULL, NULL);
#endif	/* WINDOWS */

  if (fname == NULL) {
    *err = CAIRO_STATUS_NO_MEMORY;
    return NULL;
  }

  *err = 0;

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

  w = iw * dpi / 25.4 / 100;
  h = ih * dpi / 25.4 / 100;

  switch (format) {
  case TYPE_PS2:
    ps = cairo_ps_surface_create(fname, w, h);
    cairo_ps_surface_restrict_to_level(ps, CAIRO_PS_LEVEL_2);
    cairo_ps_surface_set_eps(ps, FALSE);
    break;
  case TYPE_PS3:
    ps = cairo_ps_surface_create(fname, w, h);
    cairo_ps_surface_restrict_to_level(ps, CAIRO_PS_LEVEL_3);
    cairo_ps_surface_set_eps(ps, FALSE);
    break;
  case TYPE_EPS2:
    ps = cairo_ps_surface_create(fname, w, h);
    cairo_ps_surface_restrict_to_level(ps, CAIRO_PS_LEVEL_2);
    cairo_ps_surface_set_eps(ps, TRUE);
    break;
  case TYPE_EPS3:
    ps = cairo_ps_surface_create(fname, w, h);
    cairo_ps_surface_restrict_to_level(ps, CAIRO_PS_LEVEL_3);
    cairo_ps_surface_set_eps(ps, TRUE);
    break;
  case TYPE_PDF:
    ps = cairo_pdf_surface_create(fname, w, h);
    break;
  case TYPE_SVG1_1:
    ps = cairo_svg_surface_create(fname, w, h);
    cairo_svg_surface_restrict_to_version(ps, CAIRO_SVG_VERSION_1_1);
    break;
  case TYPE_SVG1_2:
    ps = cairo_svg_surface_create(fname, w, h);
    cairo_svg_surface_restrict_to_version(ps, CAIRO_SVG_VERSION_1_2);
    break;
  case TYPE_PNG:
    ps = cairo_image_surface_create(CAIRO_FORMAT_RGB24, w, h);
    break;
#ifdef CAIRO_HAS_WIN32_SURFACE
  case TYPE_EMF:
    ps = open_emf(dpi, fname);
    if (ps == NULL) {
      g_free(fname);
      return NULL;
    }
    break;
#endif	/* CAIRO_HAS_WIN32_SURFACE */
  default:
    ps = cairo_ps_surface_create(fname, w, h);
  }

  g_free(fname);

  r = cairo_surface_status(ps);
  if (r != CAIRO_STATUS_SUCCESS) {
    *err = r;
    cairo_surface_destroy(ps);
    return NULL;
  }

  cairo = cairo_create(ps);
  /* cairo_create() references target, so you can immediately call cairo_surface_destroy() on it */
  cairo_surface_destroy(ps);

  r = cairo_status(cairo);
  if (r != CAIRO_STATUS_SUCCESS) {
    *err = r;
    cairo_destroy(cairo);
    return NULL;
  }

  switch (format) {
  case TYPE_PNG:
    cairo_set_source_rgb(cairo, 1, 1, 1);
    cairo_paint(cairo);
    cairo_new_path(cairo);
    break;
  }

  return cairo;
}
Esempio n. 9
0
static cairo_test_status_t
test_cairo_ps_surface_restrict_to_level (cairo_surface_t *surface)
{
    cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
    return CAIRO_TEST_SUCCESS;
}
static cairo_surface_t *
_cairo_boilerplate_ps_create_surface (const char		*name,
				      cairo_content_t		 content,
				      cairo_ps_level_t		 level,
				      double			 width,
				      double			 height,
				      double			 max_width,
				      double			 max_height,
				      cairo_boilerplate_mode_t	 mode,
				      int			 id,
				      void		       **closure)
{
    ps_target_closure_t *ptc;
    cairo_surface_t *surface;
    cairo_status_t status;

    /* Sanitize back to a real cairo_content_t value. */
    if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
	content = CAIRO_CONTENT_COLOR_ALPHA;

    *closure = ptc = xmalloc (sizeof (ps_target_closure_t));

    xasprintf (&ptc->filename, "%s.out.ps", name);
    xunlink (ptc->filename);

    ptc->level = level;
    ptc->width = ceil (width);
    ptc->height = ceil (height);

    surface = cairo_ps_surface_create (ptc->filename, width, height);
    if (cairo_surface_status (surface))
	goto CLEANUP_FILENAME;

    cairo_ps_surface_restrict_to_level (surface, level);
    _cairo_boilerplate_ps_surface_set_creation_date (surface, 0);
    cairo_surface_set_fallback_resolution (surface, 72., 72.);

    if (content == CAIRO_CONTENT_COLOR) {
	ptc->target = surface;
	surface = cairo_surface_create_similar (ptc->target,
						CAIRO_CONTENT_COLOR,
						ptc->width, ptc->height);
	if (cairo_surface_status (surface))
	    goto CLEANUP_TARGET;
    } else {
	ptc->target = NULL;
    }

    status = cairo_surface_set_user_data (surface, &ps_closure_key, ptc, NULL);
    if (status == CAIRO_STATUS_SUCCESS)
	return surface;

    cairo_surface_destroy (surface);
    surface = cairo_boilerplate_surface_create_in_error (status);

  CLEANUP_TARGET:
    cairo_surface_destroy (ptc->target);
  CLEANUP_FILENAME:
    free (ptc->filename);
    free (ptc);
    return surface;
}
bool QCairoPaintEngine::begin(QPaintDevice *pd)
{
    if (surface) {
        end();
    }

    const QCairoPaintDevice* cpd=dynamic_cast<const QCairoPaintDevice*>(pd);
    surface = NULL;
    if (cpd) {
        exportText=cpd->getExportText();
        QCairoPaintDevice::CairoFileType ft=cpd->getFileType();
        QSizeF s=cpd->getFileSizeMM();
        //qDebug()<<ft;
        if (ft==QCairoPaintDevice::cftPDF14) {
            //qDebug()<<  "Cairo-PDF1.4";
            surface = cairo_pdf_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_pdf_surface_restrict_to_version(surface, CAIRO_PDF_VERSION_1_4);
        } else if (ft==QCairoPaintDevice::cftPDF15) {
            //Debug()<<  "Cairo-PDF1.5"<<s<<s.width()/25.4*72.0<<s.height()/25.4*72.0;
            surface = cairo_pdf_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_pdf_surface_restrict_to_version(surface, CAIRO_PDF_VERSION_1_5);
        } else if (ft==QCairoPaintDevice::cftPS2) {
           //qDebug()<<  "Cairo-PS2";
            surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2);
        } else if (ft==QCairoPaintDevice::cftPS3) {
           //qDebug()<<  "Cairo-PS3";
            surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2);
        } else if (ft==QCairoPaintDevice::cftEPS2) {
           //qDebug()<<  "Cairo-EPS2";
            surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2);
            cairo_ps_surface_set_eps(surface, 1);
        } else if (ft==QCairoPaintDevice::cftEPS3) {
           //qDebug()<<  "Cairo-EPS3";
            surface = cairo_ps_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_ps_surface_restrict_to_level(surface, CAIRO_PS_LEVEL_2);
            cairo_ps_surface_set_eps(surface, 1);
        } else if (ft==QCairoPaintDevice::cftSVG11) {
           //qDebug()<<  "Cairo-SVG11";
            surface = cairo_svg_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_1);
        } else if (ft==QCairoPaintDevice::cftSVG12) {
           //qDebug()<<  "Cairo-SVG12";
            surface = cairo_svg_surface_create (cpd->getFileName().toLocal8Bit().data(), s.width()/25.4*72.0, s.height()/25.4*72.0);
            cairo_svg_surface_restrict_to_version(surface, CAIRO_SVG_VERSION_1_2);
        }
    }
    if (surface) {
        if (cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS) {
            cr = cairo_create(surface);
            if (cr) {
                if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) {
                    qDebug()<<"QCairoPaintDevice error initializing CAIRO: "<<cairo_status_to_string(cairo_status(cr));
                    end();
                    return false;
                } else {
                    cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
                }
            } else {
                qDebug()<<"QCairoPaintDevice error initializing CAIRO !!!";
                end();
                return false;
            }
        } else {
            qDebug()<<"QCairoPaintDevice error creating surface: "<<cairo_status_to_string(cairo_surface_status(surface));
            end();
            return false;
        }

    } else {
        qDebug()<<"UNKNOWN QCairoPaintDevice type !!!";
        return false;
    }
    return true;
}