GraphicsContextCairoWin.cpp [plain text]
#include "config.h"
#include "GraphicsContext.h"
#include "TransformationMatrix.h"
#include "Path.h"
#include <cairo-win32.h>
#include "GraphicsContextPlatformPrivateCairo.h"
using namespace std;
namespace WebCore {
GraphicsContext::GraphicsContext(HDC dc, bool hasAlpha)
: m_common(createGraphicsContextPrivate())
, m_data(new GraphicsContextPlatformPrivate)
{
if (dc) {
cairo_surface_t* surface = cairo_win32_surface_create(dc);
m_data->cr = cairo_create(surface);
m_data->m_hdc = dc;
} else {
setPaintingDisabled(true);
m_data->cr = 0;
m_data->m_hdc = 0;
}
if (m_data->cr) {
setPlatformFillColor(fillColor());
setPlatformStrokeColor(strokeColor());
}
}
HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
if (dstRect.isEmpty())
return 0;
cairo_surface_t* surface = cairo_get_target(platformContext());
HDC hdc = cairo_win32_surface_get_dc(surface);
SaveDC(hdc);
SetGraphicsMode(hdc, GM_ADVANCED); 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;
}
void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
{
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);
}
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);
}
}