GL backend: Fix round corner clip radius

Rendering tests/cases/examples/rectangle_clip.60 shows a border radius
for the clipped area that's not identical with the border radius of the
inner edge of the rectangle stroke.

It appears that the stroke's inner radius is not exactly the difference
of the line (border) width but rather scaled by kappa.
This commit is contained in:
Simon Hausmann 2021-04-26 17:28:47 +02:00
parent 0bb61cc1b3
commit 1ef1e79b93

View file

@ -46,6 +46,8 @@ type CanvasRc = Rc<RefCell<femtovg::Canvas<femtovg::renderer::OpenGl>>>;
pub const DEFAULT_FONT_SIZE: f32 = 12.;
pub const DEFAULT_FONT_WEIGHT: i32 = 400; // CSS normal
const KAPPA90: f32 = 0.5522847493;
#[derive(PartialEq, Eq, Hash, Debug)]
enum ImageCacheKey {
Path(String),
@ -1075,8 +1077,12 @@ impl ItemRenderer for GLItemRenderer {
// adjust_rect_and_border_for_inner_drawing adjusts the rect so that for drawing it
// would be entirely an *inner* border. However for clipping we want the rect that's
// entirely inside, hence the doubling of the width and consequently radius adjustment.
border_width *= self.scale_factor * 2.;
radius *= self.scale_factor * 0.75;
radius -= border_width * KAPPA90;
border_width *= 2.;
// Convert from logical to physical pixels
border_width *= self.scale_factor;
radius *= self.scale_factor;
clip_rect *= self.scale_factor;
adjust_rect_and_border_for_inner_drawing(&mut clip_rect, &mut border_width);