Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CDrawContext::drawEllipse() broken on linux #333

Open
Distb opened this issue Oct 16, 2024 · 0 comments
Open

CDrawContext::drawEllipse() broken on linux #333

Distb opened this issue Oct 16, 2024 · 0 comments

Comments

@Distb
Copy link

Distb commented Oct 16, 2024

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().

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant