Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Pen Thickness is not taking into account when calculating bounding boxes/clip rectangles. #5249

Closed
nitroxis opened this issue Jan 2, 2021 · 11 comments · Fixed by #8260
Closed
Labels
help-wanted A contribution from the community would be most welcome.

Comments

@nitroxis
Copy link

nitroxis commented Jan 2, 2021

When drawing e.g. an ellipse into an image with just the outline, it will always get cut off at the edges because the bounding box appears to only consider the "fill" area, not the whole outline.

A simple repro:

<Image Width="500" Height="500" Stretch="None">
	<Image.Source>
		<DrawingImage>
			<GeometryDrawing>
				<GeometryDrawing.Pen>
					<Pen Brush="#000000" Thickness="10"></Pen>
				</GeometryDrawing.Pen>
				<EllipseGeometry RadiusX="100" RadiusY="100"></EllipseGeometry>
			</GeometryDrawing>
		</DrawingImage>
	</Image.Source>
</Image>

This currently looks like this:
20210102123750

If this is intentional behavior, what is the proper way to make this look like a normal circle?

@kekekeks
Copy link
Member

kekekeks commented Jan 2, 2021

Probably a bug somewhere here

public Rect GetRenderBounds(IPen pen)

@Gillibald
Copy link
Contributor

cf15520

@nitroxis
Copy link
Author

nitroxis commented Jan 5, 2021

I checked the method you mentioned but the bounds look correct there:
20210105053531

This is for the above example geometry, which is correctly calculated at 200x200 for the fill + 10 for the stroke. The bug might be somewhere else?

@nitroxis
Copy link
Author

nitroxis commented Jan 5, 2021

Okay I've investigated this a bit more. Seems like the first calls to GetRenderBounds from here

return Geometry?.GetRenderBounds(s_boundsPen) ?? Rect.Empty;

supply a pen with Thickness 0. Later, when the method is called from here:
: base(geometry.GetRenderBounds(pen), transform)

the pen is correct. I think the Pen property is not fully initialized when layouting or UpdateScene is called for the first time or something?

@nitroxis
Copy link
Author

nitroxis commented Jan 5, 2021

Ah no, s_boundsPen is simply an immutable Pen with Thickness always 0. I guess this is the problem then, it should probably use the real pen?

@kekekeks
Copy link
Member

kekekeks commented Jan 5, 2021

@grokys

@Gillibald
Copy link
Contributor

Gillibald commented Jan 5, 2021

GetRenderBounds should not require a Pen to work properly. Instead, the API should be changed to take a thickness.

@joneuhauser
Copy link

I also mentioned this bug here: #4913

@Tenjim
Copy link

Tenjim commented May 9, 2022

I notice that bug is also related to : #8080

@maxkatz6 maxkatz6 added the help-wanted A contribution from the community would be most welcome. label May 24, 2022
@Whiletru3
Copy link
Contributor

Hello, this bug is annoying as all the icons are cropped in the interface, is there any plan to fix this ?

Thanks

@Whiletru3
Copy link
Contributor

In GeometryDrawing.cs, the GetBounds should be changed from this

public override Rect GetBounds()
        {
            return Geometry?.GetRenderBounds(s_boundsPen) ?? Rect.Empty;
        }

image

to this (to take the Pen of GeometryDrawing if exist

public override Rect GetBounds()
        {
            IPen pen = Pen ?? s_boundsPen;
            return Geometry?.GetRenderBounds(pen) ?? Rect.Empty;
        }

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants