Skip to content

CDrawContext::drawEllipse() broken on linux #333

@Distb

Description

@Distb

CDrawContext::drawEllipse seems to use incorrect scaling on linux, so that the ellipse is typically much smaller than desired.

CairoGrpahicsDeviceContext::drawEllipse() appears to have two issues:

  1. The inverse of the correct scaling factor is passed to cairo_scale
  2. imp->draw is called with scaling still enabled. This means that a stroke width of 1 will be also be scaled by the ellipse size scaling factors (interestingly causing non-uniform line width when rect width is not equal to rect height). See https://cairo.freedesktop.org/cookbook/ellipses/ for why this happens.

The following seems to work for me:

bool CairoGraphicsDeviceContext::drawEllipse (CRect rect, PlatformGraphicsDrawStyle drawStyle) const
{
    impl->doInContext ([&] () {
        CPoint center = rect.getCenter ();
        cairo_matrix_t save_matrix;
        cairo_get_matrix( impl->context, & save_matrix );
        cairo_translate (impl->context, center.x, center.y);
        cairo_scale( impl->context, 0.5 * rect.getWidth(), 0.5 * rect.getHeight() );
        cairo_arc (impl->context, 0, 0, 1, 0, 2 * M_PI);
        cairo_set_matrix( impl->context, & save_matrix );
        impl->draw (drawStyle);
    });
    return true;
}

I'd assume that similar changes are needed for CairoGraphicsDeviceContext::drawArc().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions