GraphicsContextPlatformPrivate();
~GraphicsContextPlatformPrivate();
- cairo_t* context;
+ cairo_t* cr;
Vector<float> layers;
};
}
GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate()
- : context(0)
+ : cr(0)
{
}
GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate()
{
- cairo_destroy(context);
+ cairo_destroy(cr);
}
#if PLATFORM(WIN)
, m_data(new GraphicsContextPlatformPrivate)
{
cairo_surface_t* surface = cairo_win32_surface_create(dc);
- m_data->context = cairo_create(surface);
+ m_data->cr = cairo_create(surface);
}
#endif
-GraphicsContext::GraphicsContext(PlatformGraphicsContext* context)
+GraphicsContext::GraphicsContext(PlatformGraphicsContext* cr)
: m_common(createGraphicsContextPrivate())
, m_data(new GraphicsContextPlatformPrivate)
{
- m_data->context = cairo_reference(context);
+ m_data->cr = cairo_reference(cr);
}
GraphicsContext::~GraphicsContext()
cairo_t* GraphicsContext::platformContext() const
{
- return m_data->context;
+ return m_data->cr;
}
void GraphicsContext::savePlatformState()
{
- cairo_save(m_data->context);
+ cairo_save(m_data->cr);
}
void GraphicsContext::restorePlatformState()
{
- cairo_restore(m_data->context);
+ cairo_restore(m_data->cr);
}
// Draws a filled rectangle with a stroked border.
{
if (paintingDisabled())
return;
-
- cairo_t* context = m_data->context;
- cairo_save(context);
+
+ cairo_t* cr = m_data->cr;
+ cairo_save(cr);
if (fillColor().alpha())
- fillRectSourceOver(context, rect, fillColor());
+ fillRectSourceOver(cr, rect, fillColor());
if (strokeStyle() != NoStroke) {
- setColor(context, strokeColor());
+ setColor(cr, strokeColor());
FloatRect r(rect);
r.inflate(-.5f);
- cairo_rectangle(context, r.x(), r.y(), r.width(), r.height());
- cairo_set_line_width(context, 1.0);
- cairo_stroke(context);
+ cairo_rectangle(cr, r.x(), r.y(), r.width(), r.height());
+ cairo_set_line_width(cr, 1.0);
+ cairo_stroke(cr);
}
- cairo_restore(context);
+ cairo_restore(cr);
}
// FIXME: Now that this is refactored, it should be shared by all contexts.
p2.setX(p2.x() - strokeWidth);
}
}
-
- if (((int)strokeWidth)%2) {
+
+ if (static_cast<int>(strokeWidth) % 2) {
if (p1.x() == p2.x()) {
// We're a vertical line. Adjust our x.
p1.setX(p1.x() + 0.5);
if (style == NoStroke)
return;
- cairo_t* context = m_data->context;
- cairo_save(context);
+ cairo_t* cr = m_data->cr;
+ cairo_save(cr);
float width = strokeThickness();
if (width < 1)
FloatPoint p1 = point1;
FloatPoint p2 = point2;
bool isVerticalLine = (p1.x() == p2.x());
-
+
adjustLineToPixelBoundaries(p1, p2, width, style);
- cairo_set_line_width(context, width);
+ cairo_set_line_width(cr, width);
int patWidth = 0;
switch (style) {
case SolidStroke:
break;
case DottedStroke:
- patWidth = (int)width;
+ patWidth = static_cast<int>(width);
break;
case DashedStroke:
- patWidth = 3*(int)width;
+ patWidth = 3*static_cast<int>(width);
break;
}
- setColor(context, strokeColor());
-
- cairo_set_antialias(context, CAIRO_ANTIALIAS_NONE);
-
+ setColor(cr, strokeColor());
+
+ cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+
if (patWidth) {
// Do a rect fill of our endpoints. This ensures we always have the
// appearance of being a border. We then draw the actual dotted/dashed line.
if (isVerticalLine) {
- fillRectSourceOver(context, FloatRect(p1.x()-width/2, p1.y()-width, width, width), strokeColor());
- fillRectSourceOver(context, FloatRect(p2.x()-width/2, p2.y(), width, width), strokeColor());
+ fillRectSourceOver(cr, FloatRect(p1.x() - width/2, p1.y() - width, width, width), strokeColor());
+ fillRectSourceOver(cr, FloatRect(p2.x() - width/2, p2.y(), width, width), strokeColor());
} else {
- fillRectSourceOver(context, FloatRect(p1.x()-width, p1.y()-width/2, width, width), strokeColor());
- fillRectSourceOver(context, FloatRect(p2.x(), p2.y()-width/2, width, width), strokeColor());
+ fillRectSourceOver(cr, FloatRect(p1.x() - width, p1.y() - width/2, width, width), strokeColor());
+ fillRectSourceOver(cr, FloatRect(p2.x(), p2.y() - width/2, width, width), strokeColor());
}
-
+
// Example: 80 pixels with a width of 30 pixels.
// Remainder is 20. The maximum pixels of line we could paint
// will be 50 pixels.
- int distance = (isVerticalLine ? (point2.y() - point1.y()) : (point2.x() - point1.x())) - 2*(int)width;
+ int distance = (isVerticalLine ? (point2.y() - point1.y()) : (point2.x() - point1.x())) - 2*static_cast<int>(width);
int remainder = distance%patWidth;
int coverage = distance-remainder;
int numSegments = coverage/patWidth;
patternOffset = (patWidth - remainder)/2;
}
}
-
+
double dash = patWidth;
- cairo_set_dash(context, &dash, 1, patternOffset);
+ cairo_set_dash(cr, &dash, 1, patternOffset);
}
- cairo_move_to(context, p1.x(), p1.y());
- cairo_line_to(context, p2.x(), p2.y());
+ cairo_move_to(cr, p1.x(), p1.y());
+ cairo_line_to(cr, p2.x(), p2.y());
- cairo_stroke(context);
- cairo_restore(context);
+ cairo_stroke(cr);
+ cairo_restore(cr);
}
// This method is only used to draw the little circles used in lists.
{
if (paintingDisabled())
return;
-
- cairo_t* context = m_data->context;
- cairo_save(context);
+
+ cairo_t* cr = m_data->cr;
+ cairo_save(cr);
float yRadius = .5 * rect.height();
float xRadius = .5 * rect.width();
- cairo_translate(context, rect.x() + xRadius, rect.y() + yRadius);
- cairo_scale(context, xRadius, yRadius);
- cairo_arc(context, 0., 0., 1., 0., 2 * M_PI);
- cairo_restore(context);
+ cairo_translate(cr, rect.x() + xRadius, rect.y() + yRadius);
+ cairo_scale(cr, xRadius, yRadius);
+ cairo_arc(cr, 0., 0., 1., 0., 2 * M_PI);
+ cairo_restore(cr);
if (fillColor().alpha()) {
- setColor(context, fillColor());
- cairo_fill_preserve(context);
+ setColor(cr, fillColor());
+ cairo_fill_preserve(cr);
}
if (strokeStyle() != NoStroke) {
- setColor(context, strokeColor());
- cairo_set_line_width(context, strokeThickness());
- cairo_stroke(context);
+ setColor(cr, strokeColor());
+ cairo_set_line_width(cr, strokeThickness());
+ cairo_stroke(cr);
}
- cairo_new_path(context);
+ cairo_new_path(cr);
}
// FIXME: This function needs to be adjusted to match the functionality on the Mac side.
{
if (paintingDisabled())
return;
-
+
+ if (strokeStyle() == NoStroke)
+ return;
+
int x = rect.x();
int y = rect.y();
- float w = (float)rect.width();
+ float w = rect.width();
#if 0 // FIXME: unused so far
- float h = (float)rect.height();
+ float h = rect.height();
float scaleFactor = h / w;
float reverseScaleFactor = w / h;
#endif
- cairo_t* context = m_data->context;
- if (strokeStyle() != NoStroke) {
- float r = w / 2;
- float fa = startAngle;
- float falen = fa + angleSpan;
- cairo_arc_negative(context, x + r, y + r, r, -fa * M_PI/180, -falen * M_PI/180);
-
- setColor(context, strokeColor());
- cairo_set_line_width(context, strokeThickness());
- cairo_stroke(context);
- }
+ float r = w / 2;
+ float fa = startAngle;
+ float falen = fa + angleSpan;
+
+ cairo_t* cr = m_data->cr;
+ cairo_save(cr);
+ cairo_arc_negative(cr, x + r, y + r, r, -fa * M_PI/180, -falen * M_PI/180);
+ setColor(cr, strokeColor());
+ cairo_set_line_width(cr, strokeThickness());
+ cairo_stroke(cr);
+ cairo_restore(cr);
}
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
if (npoints <= 1)
return;
- cairo_t* context = m_data->context;
+ cairo_t* cr = m_data->cr;
- cairo_save(context);
- cairo_set_antialias(context, shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
- cairo_move_to(context, points[0].x(), points[0].y());
+ cairo_save(cr);
+ cairo_set_antialias(cr, shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
+ cairo_move_to(cr, points[0].x(), points[0].y());
for (size_t i = 1; i < npoints; i++)
- cairo_line_to(context, points[i].x(), points[i].y());
- cairo_close_path(context);
+ cairo_line_to(cr, points[i].x(), points[i].y());
+ cairo_close_path(cr);
if (fillColor().alpha()) {
- setColor(context, fillColor());
- cairo_set_fill_rule(context, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_fill_preserve(context);
+ setColor(cr, fillColor());
+ cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_fill_preserve(cr);
}
if (strokeStyle() != NoStroke) {
- setColor(context, strokeColor());
- cairo_set_line_width(context, strokeThickness());
- cairo_stroke(context);
+ setColor(cr, strokeColor());
+ cairo_set_line_width(cr, strokeThickness());
+ cairo_stroke(cr);
}
- cairo_new_path(context);
- cairo_restore(context);
+ cairo_new_path(cr);
+ cairo_restore(cr);
}
void GraphicsContext::fillRect(const IntRect& rect, const Color& color)
return;
if (color.alpha())
- fillRectSourceOver(m_data->context, rect, color);
+ fillRectSourceOver(m_data->cr, rect, color);
}
void GraphicsContext::fillRect(const FloatRect& rect, const Color& color)
return;
if (color.alpha())
- fillRectSourceOver(m_data->context, rect, color);
+ fillRectSourceOver(m_data->cr, rect, color);
}
void GraphicsContext::clip(const IntRect& rect)
if (paintingDisabled())
return;
- cairo_t* context = m_data->context;
- cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height());
- cairo_clip(context);
+ cairo_t* cr = m_data->cr;
+ cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
+ cairo_clip(cr);
}
void GraphicsContext::drawFocusRing(const Color& color)
int radius = (focusRingWidth() - 1) / 2;
int offset = radius + focusRingOffset();
-
+
const Vector<IntRect>& rects = focusRingRects();
unsigned rectCount = rects.size();
IntRect finalFocusRect;
focusRect.inflate(offset);
finalFocusRect.unite(focusRect);
}
+
+ cairo_t* cr = m_data->cr;
+ cairo_save(cr);
// FIXME: These rects should be rounded
- cairo_rectangle(m_data->context, finalFocusRect.x(), finalFocusRect.y(), finalFocusRect.width(), finalFocusRect.height());
-
+ cairo_rectangle(cr, finalFocusRect.x(), finalFocusRect.y(), finalFocusRect.width(), finalFocusRect.height());
+
// Force the alpha to 50%. This matches what the Mac does with outline rings.
Color ringColor(color.red(), color.green(), color.blue(), 127);
- setColor(m_data->context, ringColor);
- cairo_stroke(m_data->context);
+ setColor(cr, ringColor);
+ cairo_stroke(cr);
+ cairo_restore(cr);
}
void GraphicsContext::setFocusRingClip(const IntRect&)
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect)
{
FloatRect result;
- double x =frect.x();
+ double x = frect.x();
double y = frect.y();
- cairo_t* context = m_data->context;
- cairo_user_to_device(context,&x,&y);
+ cairo_t* cr = m_data->cr;
+ cairo_user_to_device(cr, &x, &y);
x = round(x);
y = round(y);
- cairo_device_to_user(context,&x,&y);
- result.setX((float)x);
- result.setY((float)y);
+ cairo_device_to_user(cr, &x, &y);
+ result.setX(static_cast<float>(x));
+ result.setY(static_cast<float>(y));
x = frect.width();
y = frect.height();
- cairo_user_to_device_distance(context,&x,&y);
+ cairo_user_to_device_distance(cr, &x, &y);
x = round(x);
y = round(y);
- cairo_device_to_user_distance(context,&x,&y);
- result.setWidth((float)x);
- result.setHeight((float)y);
- return result;
+ cairo_device_to_user_distance(cr, &x, &y);
+ result.setWidth(static_cast<float>(x));
+ result.setHeight(static_cast<float>(y));
+ return result;
}
void GraphicsContext::translate(float x, float y)
{
if (paintingDisabled())
return;
- cairo_t* context = m_data->context;
- cairo_translate(context, x, y);
+
+ cairo_t* cr = m_data->cr;
+ cairo_translate(cr, x, y);
}
IntPoint GraphicsContext::origin()
{
cairo_matrix_t matrix;
- cairo_t* context = m_data->context;
- cairo_get_matrix(context, &matrix);
- return IntPoint((int)matrix.x0, (int)matrix.y0);
+ cairo_t* cr = m_data->cr;
+ cairo_get_matrix(cr, &matrix);
+ return IntPoint(static_cast<int>(matrix.x0), static_cast<int>(matrix.y0));
}
void GraphicsContext::setPlatformFillColor(const Color& col)
{
if (paintingDisabled())
return;
- cairo_set_line_width(m_data->context, strokeThickness);
+
+ cairo_set_line_width(m_data->cr, strokeThickness);
}
void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& strokeStyle)
switch (strokeStyle) {
case NoStroke:
// FIXME: is it the right way to emulate NoStroke?
- cairo_set_line_width(m_data->context, 0);
+ cairo_set_line_width(m_data->cr, 0);
break;
case SolidStroke:
- cairo_set_dash(m_data->context, 0, 0, 0);
+ cairo_set_dash(m_data->cr, 0, 0, 0);
break;
case DottedStroke:
- cairo_set_dash(m_data->context, dotPattern, 2, 0);
+ cairo_set_dash(m_data->cr, dotPattern, 2, 0);
break;
case DashedStroke:
- cairo_set_dash(m_data->context, dashPattern, 2, 0);
+ cairo_set_dash(m_data->cr, dashPattern, 2, 0);
break;
default:
notImplemented();
// FIXME: is it the right thing to do? Also, doesn't work on Win because
// there FontData doesn't have ::setFont()
const FontData *fontData = font.primaryFont();
- fontData->setFont(m_data->context);
+ fontData->setFont(m_data->cr);
#endif
}
if (paintingDisabled())
return;
- cairo_t* cr = m_data->context;
+ cairo_t* cr = m_data->cr;
const cairo_matrix_t* matrix = reinterpret_cast<const cairo_matrix_t*>(&transform);
cairo_transform(cr, matrix);
}
-void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
-{
- notImplemented();
+void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
+{
+ notImplemented();
}
void GraphicsContext::setShadow(IntSize const&, int, Color const&)
if (paintingDisabled())
return;
- cairo_t* context = m_data->context;
- cairo_push_group(context);
+ cairo_t* cr = m_data->cr;
+ cairo_push_group(cr);
m_data->layers.append(opacity);
}
if (paintingDisabled())
return;
- cairo_t* context = m_data->context;
+ cairo_t* cr = m_data->cr;
- cairo_pop_group_to_source(context);
- cairo_paint_with_alpha(context, m_data->layers.last());
+ cairo_pop_group_to_source(cr);
+ cairo_paint_with_alpha(cr, m_data->layers.last());
m_data->layers.removeLast();
}
if (paintingDisabled())
return;
- cairo_t* cr = m_data->context;
+ cairo_t* cr = m_data->cr;
cairo_save(cr);
cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
cairoCap = CAIRO_LINE_CAP_SQUARE;
break;
}
- cairo_set_line_cap(m_data->context, cairoCap);
+ cairo_set_line_cap(m_data->cr, cairoCap);
}
void GraphicsContext::setLineJoin(LineJoin lineJoin)
cairoJoin = CAIRO_LINE_JOIN_BEVEL;
break;
}
- cairo_set_line_join(m_data->context, cairoJoin);
+ cairo_set_line_join(m_data->cr, cairoJoin);
}
void GraphicsContext::setMiterLimit(float miter)
{
if (paintingDisabled())
return;
- cairo_set_miter_limit(m_data->context, miter);
+
+ cairo_set_miter_limit(m_data->cr, miter);
}
void GraphicsContext::setAlpha(float)
{
if (paintingDisabled())
return;
- cairo_set_operator(m_data->context, toCairoOperator(op));
+
+ cairo_set_operator(m_data->cr, toCairoOperator(op));
}
void GraphicsContext::beginPath()
if (paintingDisabled())
return;
- cairo_t* cr = m_data->context;
+ cairo_t* cr = m_data->cr;
cairo_new_path(cr);
}
if (paintingDisabled())
return;
- cairo_t* cr = m_data->context;
+ cairo_t* cr = m_data->cr;
cairo_path_t *p = cairo_copy_path(path.platformPath()->m_cr);
cairo_append_path(cr, p);
cairo_path_destroy(p);
{
if (paintingDisabled())
return;
- cairo_t* cr = m_data->context;
+
+ cairo_t* cr = m_data->cr;
cairo_path_t *p = cairo_copy_path(path.platformPath()->m_cr);
cairo_append_path(cr, p);
cairo_path_destroy(p);
{
if (paintingDisabled())
return;
- cairo_rotate(m_data->context, radians);
+
+ cairo_rotate(m_data->cr, radians);
}
void GraphicsContext::scale(const FloatSize& size)
{
if (paintingDisabled())
return;
- cairo_scale(m_data->context, size.width(), size.height());
+
+ cairo_scale(m_data->cr, size.width(), size.height());
}
void GraphicsContext::clipOut(const IntRect&)