HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
    // FIXME:  We aren't really doing anything with the 'mayCreateBitmap' flag.  This needs
    // to be addressed.
    if (dstRect.isEmpty())
       return 0;

    // This is probably wrong, and definitely out of date.  Pulled from old SVN
    cairo_surface_t* surface = cairo_get_target(platformContext());
    HDC hdc = cairo_win32_surface_get_dc(surface);   
    SaveDC(hdc);

    // FIXME: We need to make sure a clip is really set on the HDC.
    // Call SetWorldTransform to honor the current Cairo transform.
    SetGraphicsMode(hdc, GM_ADVANCED); // We need this call for themes to honor world transforms.
    cairo_matrix_t mat;
    cairo_get_matrix(platformContext(), &mat);
    XFORM xform;
    xform.eM11 = mat.xx;
    xform.eM12 = mat.xy;
    xform.eM21 = mat.yx;
    xform.eM22 = mat.yy;
    xform.eDx = mat.x0;
    xform.eDy = mat.y0;
    ::SetWorldTransform(hdc, &xform);

    return hdc;
}
gfxWindowsSurface::gfxWindowsSurface(HDC dc, const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) :
    mOwnsDC(false), mForPrinting(false), mWnd(nullptr)
{
    mozilla::gfx::IntSize size(realSize);
    if (!CheckSurfaceSize(size))
        MakeInvalid(size);

    cairo_format_t cformat = gfxImageFormatToCairoFormat(imageFormat);
    cairo_surface_t *surf =
        cairo_win32_surface_create_with_ddb(dc, cformat,
                                            size.width, size.height);

    Init(surf);

    if (mSurfaceValid) {
        // DDBs will generally only use 3 bytes per pixel when RGB24
        int bytesPerPixel = ((imageFormat == gfxImageFormat::RGB24) ? 3 : 4);
        RecordMemoryUsed(size.width * size.height * bytesPerPixel + sizeof(gfxWindowsSurface));
    }

    if (CairoStatus() == 0)
        mDC = cairo_win32_surface_get_dc(CairoSurface());
    else
        mDC = nullptr;
}
Beispiel #3
0
GdkWindow *clg_gdk_cairo_surface_get_window (cairo_surface_t *surface)
{
  /* If 'surface_info_key' had been public we would have had a
     portable way to find the GdkWindow of a Cairo surface. */
  
#ifdef GDK_WINDOWING_X11
  g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB);
  
  Display* display = cairo_xlib_surface_get_display (surface);
  if (display) {
    Drawable window = cairo_xlib_surface_get_drawable (surface);
    if (window)
      return gdk_window_lookup_for_display (window, display);
  }

  return NULL;
#elif defined (G_OS_WIN32)
  HDC hdc = (HDC)cairo_win32_surface_get_dc (surface);
  if (hdc)
    return gdk_window_lookup ((GdkNativeWindow)hdc);
  else
    return NULL;
#else
  return NULL;
#endif
}
void PlatformBinding::TakeScreenshotImpl(const std::string& targetFile)
{
    // Ensure filename ends in .bmp.
    // TODO: This seems broken.
    std::string screenshotFile = targetFile;
    if (screenshotFile.rfind(".") == std::string::npos)
        screenshotFile.append(".png");

    HWND desktop = GetDesktopWindow();
    RECT desktopRect;
    GetWindowRect(desktop, &desktopRect);

    int width = desktopRect.right;
    int height = desktopRect.bottom;

    cairo_surface_t* surface = cairo_win32_surface_create_with_dib(CAIRO_FORMAT_RGB24, width, height);
    cairo_surface_flush(surface);

    HDC hdc = cairo_win32_surface_get_dc(surface);
    BitBlt(hdc, 0, 0, width, height, GetDC(0), 0, 0, SRCCOPY);

    std::string filename(::UTF8ToSystem(screenshotFile));
    cairo_status_t result = cairo_surface_write_to_png(surface, filename.c_str());

    cairo_surface_destroy(surface);

    if (result != CAIRO_STATUS_SUCCESS)
        throw ValueException::FromString("Could not save screenshot.");
}
Beispiel #5
0
void GraphicsContextPlatformPrivate::syncContext(cairo_t* cr)
{
    if (!cr)
       return;

    cairo_surface_t* surface = cairo_get_target(cr);
    m_hdc = cairo_win32_surface_get_dc(surface);   

    SetGraphicsMode(m_hdc, GM_ADVANCED); // We need this call for themes to honor world transforms.
}
static VALUE
cr_win32_surface_get_hdc (VALUE self)
{
  HDC hdc;

  hdc = cairo_win32_surface_get_dc (_SELF);
  if (!hdc)
    return Qnil;
  else
    return PTR2NUM (hdc);
}
gfxWindowsSurface::gfxWindowsSurface(cairo_surface_t *csurf) :
    mOwnsDC(false), mWnd(nullptr)
{
    if (cairo_surface_status(csurf) == 0)
        mDC = cairo_win32_surface_get_dc(csurf);
    else
        mDC = nullptr;

    MOZ_ASSERT(cairo_surface_get_type(csurf) != CAIRO_SURFACE_TYPE_WIN32_PRINTING);

    Init(csurf, true);
}
void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
    // FIXME:  We aren't really doing anything with the 'mayCreateBitmap' flag.  This needs
    // to be addressed.
    if (dstRect.isEmpty())
       return;

    cairo_surface_t* surface = cairo_get_target(platformContext());
    HDC hdc2 = cairo_win32_surface_get_dc(surface);
    RestoreDC(hdc2, -1);
    cairo_surface_mark_dirty(surface);
}
gfxWindowsSurface::gfxWindowsSurface(cairo_surface_t *csurf) :
    mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mWnd(nsnull)
{
    if (cairo_surface_status(csurf) == 0)
        mDC = cairo_win32_surface_get_dc(csurf);
    else
        mDC = nsnull;

    if (cairo_surface_get_type(csurf) == CAIRO_SURFACE_TYPE_WIN32_PRINTING)
        mForPrinting = PR_TRUE;

    Init(csurf, PR_TRUE);
}
gfxWindowsSurface::gfxWindowsSurface(HDC dc, const gfxIntSize& size, gfxImageFormat imageFormat) :
    mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mWnd(nsnull)
{
    if (!CheckSurfaceSize(size))
        return;

    cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, (cairo_format_t)imageFormat,
                                                                size.width, size.height);
    Init(surf);

    if (CairoStatus() == 0)
        mDC = cairo_win32_surface_get_dc(CairoSurface());
    else
        mDC = nsnull;
}
void GraphicsContextPlatformPrivate::concatCTM(const TransformationMatrix& transform)
{
    cairo_surface_t* surface = cairo_get_target(cr);
    HDC hdc = cairo_win32_surface_get_dc(surface);   
    SaveDC(hdc);

    const cairo_matrix_t* matrix = reinterpret_cast<const cairo_matrix_t*>(&transform);

    XFORM xform;
    xform.eM11 = matrix->xx;
    xform.eM12 = matrix->xy;
    xform.eM21 = matrix->yx;
    xform.eM22 = matrix->yy;
    xform.eDx = matrix->x0;
    xform.eDy = matrix->y0;

    ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY);
}
Beispiel #12
0
gfxWindowsSurface::gfxWindowsSurface(const gfxIntSize& realSize, gfxImageFormat imageFormat) :
    mOwnsDC(false), mForPrinting(false), mWnd(nullptr)
{
    gfxIntSize size(realSize);
    if (!CheckSurfaceSize(size))
        MakeInvalid(size);

    cairo_surface_t *surf = cairo_win32_surface_create_with_dib((cairo_format_t)(int)imageFormat,
                                                                size.width, size.height);

    Init(surf);

    if (CairoStatus() == CAIRO_STATUS_SUCCESS) {
        mDC = cairo_win32_surface_get_dc(CairoSurface());
        RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface));
    } else {
        mDC = nullptr;
    }
}
gfxWindowsSurface::gfxWindowsSurface(const mozilla::gfx::IntSize& realSize, gfxImageFormat imageFormat) :
    mOwnsDC(false), mWnd(nullptr)
{
    mozilla::gfx::IntSize size(realSize);
    if (!mozilla::gfx::Factory::CheckSurfaceSize(size))
        MakeInvalid(size);

    cairo_format_t cformat = GfxFormatToCairoFormat(imageFormat);
    cairo_surface_t *surf =
        cairo_win32_surface_create_with_dib(cformat, size.width, size.height);

    Init(surf);

    if (CairoStatus() == CAIRO_STATUS_SUCCESS) {
        mDC = cairo_win32_surface_get_dc(CairoSurface());
        RecordMemoryUsed(size.width * size.height * 4 + sizeof(gfxWindowsSurface));
    } else {
        mDC = nullptr;
    }
}
Beispiel #14
0
gfxWindowsSurface::gfxWindowsSurface(HDC dc, const gfxIntSize& size, gfxImageFormat imageFormat) :
    mOwnsDC(PR_FALSE), mForPrinting(PR_FALSE), mWnd(nsnull)
{
    if (!CheckSurfaceSize(size))
        return;

    cairo_surface_t *surf = cairo_win32_surface_create_with_ddb(dc, (cairo_format_t)imageFormat,
                                                                size.width, size.height);

    Init(surf);

    // DDBs will generally only use 3 bytes per pixel when RGB24
    int bytesPerPixel = ((imageFormat == gfxASurface::ImageFormatRGB24) ? 3 : 4);
    RecordMemoryUsed(size.width * size.height * bytesPerPixel + sizeof(gfxWindowsSurface));

    if (CairoStatus() == 0)
        mDC = cairo_win32_surface_get_dc(CairoSurface());
    else
        mDC = nsnull;
}
Beispiel #15
0
static int
close_emf(cairo_surface_t *surface)
{
  HDC hdc;
  HENHMETAFILE emf;
  int r;

  hdc = cairo_win32_surface_get_dc(surface);
  cairo_surface_flush(surface);
  cairo_surface_copy_page(surface);
  cairo_surface_finish(surface);

  r = 1;

  EndPage(hdc);
  emf = CloseEnhMetaFile(hdc);
  if (emf == NULL) {
    return 1;
  }
  DeleteEnhMetaFile(emf);
  /* DeleteDC() is called in the cairo library */
  return r;
}
HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
    if (dstRect.isEmpty())
        return 0;

    if(!m_data->hdc_refcount++)
    {
        m_data->hdc_surface = cairo_win32_surface_create_with_dib(CAIRO_FORMAT_RGB24, dstRect.width(), dstRect.height());

        // see http://cairographics.org/FAQ/#paint_from_a_surface
        cairo_surface_t* source = cairo_get_target( m_data->cr );
        cairo_t *cr = cairo_create ( m_data->hdc_surface );
        cairo_set_source_surface (cr, source, -dstRect.x(), -dstRect.y() );
        cairo_paint(cr);
        cairo_destroy(cr);

        m_data->m_hdc = cairo_win32_surface_get_dc(m_data->hdc_surface);

        SaveDC(m_data->m_hdc);
    }

    HDC hdc = m_data->m_hdc;
    return hdc;
}
Beispiel #17
0
HDC
gfxWindowsSurface::GetDC()
{
    return cairo_win32_surface_get_dc (CairoSurface());
}
Beispiel #18
0
static void
draw_page (GtkPrintOperation */*operation*/,
           GtkPrintContext   *context,
           gint               /*page_nr*/,
           gpointer           user_data)
{
    struct workaround_gtkmm *junk = (struct workaround_gtkmm*)user_data;
    //printf("%s %d\n",__FUNCTION__, page_nr);

    if (junk->_tab->as_bitmap()) {
        // Render as exported PNG
        gdouble width = sp_document_width(junk->_doc);
        gdouble height = sp_document_height(junk->_doc);
        gdouble dpi = junk->_tab->bitmap_dpi();
        std::string tmp_png;
        std::string tmp_base = "inkscape-print-png-XXXXXX";

        int tmp_fd;
        if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) {
            close(tmp_fd);

            guint32 bgcolor = 0x00000000;
            Inkscape::XML::Node *nv = sp_repr_lookup_name (junk->_doc->rroot, "sodipodi:namedview");
            if (nv && nv->attribute("pagecolor"))
                bgcolor = sp_svg_read_color(nv->attribute("pagecolor"), 0xffffff00);
            if (nv && nv->attribute("inkscape:pageopacity"))
                bgcolor |= SP_COLOR_F_TO_U(sp_repr_get_double_attribute (nv, "inkscape:pageopacity", 1.0));

            sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
                width, height,
                (unsigned long)(width * dpi / PX_PER_IN),
                (unsigned long)(height * dpi / PX_PER_IN),
                dpi, dpi, bgcolor, NULL, NULL, true, NULL);

            // This doesn't seem to work:
            //context->set_cairo_context ( Cairo::Context::create (Cairo::ImageSurface::create_from_png (tmp_png) ), dpi, dpi );
            //
            // so we'll use a surface pattern blat instead...
            //
            // but the C++ interface isn't implemented in cairomm:
            //context->get_cairo_context ()->set_source_surface(Cairo::ImageSurface::create_from_png (tmp_png) );
            //
            // so do it in C:
            {
                Cairo::RefPtr<Cairo::ImageSurface> png = Cairo::ImageSurface::create_from_png (tmp_png);
                cairo_t *cr = gtk_print_context_get_cairo_context (context);
		cairo_matrix_t m;
		cairo_get_matrix(cr, &m);
		cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi);
                // FIXME: why is the origin offset??
                cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0);
		cairo_paint(cr);
		cairo_set_matrix(cr, &m);
            }

            // Clean up
            unlink (tmp_png.c_str());
        }
        else {
            g_warning(_("Could not open temporary PNG for bitmap printing"));
        }
    }
    else {
        // Render as vectors
        Inkscape::Extension::Internal::CairoRenderer renderer;
        Inkscape::Extension::Internal::CairoRenderContext *ctx = renderer.createContext();

        // ctx->setPSLevel(CAIRO_PS_LEVEL_3);
        ctx->setTextToPath(false);
        ctx->setFilterToBitmap(true);
        ctx->setBitmapResolution(72);

        cairo_t *cr = gtk_print_context_get_cairo_context (context);
        cairo_surface_t *surface = cairo_get_target(cr);


/**
	Call cairo_win32_printing_surface directly as a workaround until GTK uses this call.
	When GTK uses cairo_win32_printing_surface this automatically reverts.
*/
#ifdef WIN32
        if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_WIN32) {
        HDC dc = cairo_win32_surface_get_dc (surface);
        surface = _cairo_win32_printing_surface_create (dc);
        }
#endif

        bool ret = ctx->setSurfaceTarget (surface, true);        if (ret) {
            ret = renderer.setupDocument (ctx, junk->_doc, TRUE, NULL);
            if (ret) {
                renderer.renderItem(ctx, junk->_base);
                ret = ctx->finish();
            }
            else {
                g_warning(_("Could not set up Document"));
            }
        }
        else {
            g_warning(_("Failed to set CairoRenderContext"));
        }

        // Clean up
        renderer.destroyContext(ctx);
    }

}