Ejemplo n.º 1
0
static VALUE
cr_win32_printing_surface_initialize (VALUE self, VALUE hdc)
{
  cairo_surface_t *surface = NULL;

  surface = cairo_win32_printing_surface_create (NUM2PTR (hdc));
  cr_surface_check_status (surface);
  DATA_PTR (self) = surface;
  if (rb_block_given_p ())
    yield_and_finish (self);
  return Qnil;
}
Ejemplo n.º 2
0
static int new_Win32PrintingSurface (lua_State *L)
{
    HDC hdc;
    cairo_surface_t *cs;
    lua_remove(L, 1); // remove cairo.Win32PrintingSurface

    //{"create",                                   l_cairo_win32_printing_surface_create},
    hdc = (HDC) check_lightuserdata(L, 1);
    cs = cairo_win32_printing_surface_create(hdc);

    return new_Surface(L, LUACAIRO ".Win32PrintingSurface.mt", cs, CAIRO_SURFACE_TYPE_WIN32_PRINTING, 1);
}
gfxWindowsSurface::gfxWindowsSurface(HDC dc, PRUint32 flags) :
    mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mDC(dc), mWnd(nsnull)
{
    if (flags & FLAG_TAKE_DC)
        mOwnsDC = PR_TRUE;

    if (flags & FLAG_FOR_PRINTING) {
        Init(cairo_win32_printing_surface_create(mDC));
        mForPrinting = PR_TRUE;
    } else {
        Init(cairo_win32_surface_create(mDC));
    }
}
Ejemplo n.º 4
0
gfxWindowsSurface::gfxWindowsSurface(HDC dc, uint32_t flags) :
    mOwnsDC(false), mForPrinting(false), mDC(dc), mWnd(nullptr)
{
    if (flags & FLAG_TAKE_DC)
        mOwnsDC = true;

#ifdef NS_PRINTING
    if (flags & FLAG_FOR_PRINTING) {
        Init(cairo_win32_printing_surface_create(mDC));
        mForPrinting = true;
    } else
#endif
    InitWithDC(flags);
}
Ejemplo n.º 5
0
gfxWindowsSurface::gfxWindowsSurface(HDC dc, uint32_t flags) :
    mOwnsDC(false), mForPrinting(false), mDC(dc), mWnd(nullptr)
{
    if (flags & FLAG_TAKE_DC)
        mOwnsDC = true;

#ifdef NS_PRINTING
    if (flags & FLAG_FOR_PRINTING) {
        Init(cairo_win32_printing_surface_create(mDC));
        mForPrinting = true;
        if (!mSurfaceValid) {
            gfxCriticalError(gfxCriticalError::DefaultOptions(false)) << "Invalid printing surface";
        }
    } else
#endif
    InitWithDC(flags);
}
Ejemplo n.º 6
0
static cairo_surface_t *
_cairo_win32_printing_surface_create (HDC hdc)
{
    int x, y, x_dpi, y_dpi, x_off, y_off, depth;
    XFORM xform;
    cairo_surface_t *surface;

    x = GetDeviceCaps (hdc, HORZRES);
    y = GetDeviceCaps (hdc, VERTRES);

    x_dpi = GetDeviceCaps (hdc, LOGPIXELSX);
    y_dpi = GetDeviceCaps (hdc, LOGPIXELSY);

    x_off = GetDeviceCaps (hdc, PHYSICALOFFSETX);
    y_off = GetDeviceCaps (hdc, PHYSICALOFFSETY);

    depth = GetDeviceCaps(hdc, BITSPIXEL);

    SetGraphicsMode (hdc, GM_ADVANCED);
    xform.eM11 = x_dpi/72.0;
    xform.eM12 = 0;
    xform.eM21 = 0;
    xform.eM22 = y_dpi/72.0;
    xform.eDx = -x_off;
    xform.eDy = -y_off;
    SetWorldTransform (hdc, &xform);

    surface = cairo_win32_printing_surface_create (hdc);
    
    /**
		Read fallback dpi from device capabilities. Was a workaround for a bug patched
		in cairo 1.5.14. Without this, fallback defaults to 300dpi, which is quite acceptable.
		Going higher can cause spool size and memory problems.
	*/
    // cairo_surface_set_fallback_resolution (surface, x_dpi, y_dpi);

    return surface;
}
Ejemplo n.º 7
0
static cairo_surface_t *
open_emf(int dpi, const char *fname)
{
  HDC hdc;
  cairo_surface_t *surface;
  XFORM xform = {1, 0, 0, 1, 0, 0};
  int disp_dpi;

  hdc = CreateEnhMetaFile(NULL, fname, NULL, NULL);
  if (hdc == NULL) {
    return NULL;
  }

  SetGraphicsMode(hdc, GM_ADVANCED);
  disp_dpi = GetDeviceCaps(hdc, LOGPIXELSX);
  xform.eM11 = xform.eM22 = 1.0 * disp_dpi / dpi;
  SetWorldTransform(hdc, &xform);

  surface = cairo_win32_printing_surface_create(hdc);
  StartPage(hdc);

  return surface;
}
static cairo_surface_t *
_cairo_boilerplate_win32_printing_create_surface (const char		    *name,
						  cairo_content_t	     content,
						  double		     width,
						  double		     height,
						  double		     max_width,
						  double		     max_height,
						  cairo_boilerplate_mode_t   mode,
						  void			   **closure)
{
    win32_target_closure_t *ptc;
    cairo_surface_t *surface;
    DOCINFO di;

    if (content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED)
	content = CAIRO_CONTENT_COLOR_ALPHA;

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

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

    memset (&di, 0, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
    di.lpszDocName = ptc->filename;
    di.lpszOutput = ptc->filename;

    ptc->width = width;
    ptc->height = height;

    create_printer_dc (ptc);
    if (ptc->dc == NULL) {
	printf("\nFailed to create printer\n");
	free (ptc->filename);
	free (ptc);
	return NULL;
    }
    StartDoc (ptc->dc, &di);
    StartPage (ptc->dc);
    surface = cairo_win32_printing_surface_create (ptc->dc);
    if (cairo_surface_status (surface)) {
	free (ptc->filename);
	free (ptc);
	return NULL;
    }
    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,
						width, height);
    } else {
	ptc->target = NULL;
    }

    if (cairo_surface_set_user_data (surface,
				     &win32_closure_key,
				     ptc,
				     NULL) != CAIRO_STATUS_SUCCESS) {
	cairo_surface_destroy (surface);
	if (ptc->target != NULL)
	    cairo_surface_destroy (ptc->target);
	free (ptc->filename);
	free (ptc);
	return NULL;
    }

    return surface;
}
Ejemplo n.º 9
0
imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorObj* bg)
{
  imageObj *image = NULL;
  cairo_renderer *r=NULL;
  if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) {
    msSetError(MS_MISCERR,
               "Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()");
    return image;
  }
  if (width > 0 && height > 0) {
    image = (imageObj *) calloc(1, sizeof(imageObj));
    r = (cairo_renderer*)calloc(1,sizeof(cairo_renderer));
    if(!strcasecmp(format->driver,"cairo/pdf")) {
      r->outputStream = (bufferObj*)malloc(sizeof(bufferObj));
      msBufferInit(r->outputStream);
      r->surface = cairo_pdf_surface_create_for_stream(
                     _stream_write_fn,
                     r->outputStream,
                     width,height);
    } else if(!strcasecmp(format->driver,"cairo/svg")) {
      r->outputStream = (bufferObj*)malloc(sizeof(bufferObj));
      msBufferInit(r->outputStream);
      r->surface = cairo_svg_surface_create_for_stream(
                     _stream_write_fn,
                     r->outputStream,
                     width,height);
    } else if(!strcasecmp(format->driver,"cairo/winGDI") && format->device) {
#if CAIRO_HAS_WIN32_SURFACE
      r->outputStream = NULL;
      r->surface = cairo_win32_surface_create(format->device);
#else
      msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.",
                 "msImageCreateCairo()");
#endif
    } else if(!strcasecmp(format->driver,"cairo/winGDIPrint") && format->device) {
#if CAIRO_HAS_WIN32_SURFACE
      r->outputStream = NULL;
      r->surface = cairo_win32_printing_surface_create(format->device);
#else
      msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.",
                 "msImageCreateCairo()");
#endif
    } else {
      r->outputStream = NULL;
      r->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
    }
    r->cr = cairo_create(r->surface);
    if(format->transparent || !bg || !MS_VALID_COLOR(*bg)) {
      r->use_alpha = 1;
      cairo_set_source_rgba (r->cr, 0,0,0,0);
    } else {
      r->use_alpha = 0;
      msCairoSetSourceColor(r->cr,bg);
    }
    cairo_save (r->cr);
    cairo_set_operator (r->cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (r->cr);
    cairo_restore (r->cr);

    cairo_set_line_cap (r->cr,CAIRO_LINE_CAP_ROUND);
    cairo_set_line_join(r->cr,CAIRO_LINE_JOIN_ROUND);
    image->img.plugin = (void*)r;
  } else {
    msSetError(MS_RENDERERERR, "Cannot create cairo image of size %dx%d.",
               "msImageCreateCairo()", width, height);
  }
  return image;
}