Make sure SVGs are crisp (#4823)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> * Closes https://github.com/emilk/egui/issues/3453 * [x] I have followed the instructions in the PR template I'm fairly new to egui. I read the code, but I didn't follow the approach mentioned in https://github.com/emilk/egui/issues/3453#issuecomment-2208255433. I believe this is an easier way to achieve that, though I'm not certain if it's the best method. <img width="760" alt="image" src="https://github.com/user-attachments/assets/4b3c561f-1c24-446b-9581-a2f4e9858480"> I get really nice svg with this patch. @emilk Can you please take a look? I really need this!
This commit is contained in:
parent
27e648a335
commit
1741f0a51c
|
|
@ -123,6 +123,7 @@ pub type Result<T, E = LoadError> = std::result::Result<T, E>;
|
||||||
/// Given as a hint for image loading requests.
|
/// Given as a hint for image loading requests.
|
||||||
///
|
///
|
||||||
/// Used mostly for rendering SVG:s to a good size.
|
/// Used mostly for rendering SVG:s to a good size.
|
||||||
|
/// The size is measured in texels, with the pixels per point already factored in.
|
||||||
///
|
///
|
||||||
/// All variants will preserve the original aspect ratio.
|
/// All variants will preserve the original aspect ratio.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ impl<'a> Image<'a> {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// May fail if they underlying [`Context::try_load_texture`] call fails.
|
/// May fail if they underlying [`Context::try_load_texture`] call fails.
|
||||||
pub fn load_for_size(&self, ctx: &Context, available_size: Vec2) -> TextureLoadResult {
|
pub fn load_for_size(&self, ctx: &Context, available_size: Vec2) -> TextureLoadResult {
|
||||||
let size_hint = self.size.hint(available_size);
|
let size_hint = self.size.hint(available_size, ctx.pixels_per_point());
|
||||||
self.source(ctx)
|
self.source(ctx)
|
||||||
.clone()
|
.clone()
|
||||||
.load(ctx, self.texture_options, size_hint)
|
.load(ctx, self.texture_options, size_hint)
|
||||||
|
|
@ -431,23 +431,21 @@ impl ImageFit {
|
||||||
|
|
||||||
impl ImageSize {
|
impl ImageSize {
|
||||||
/// Size hint for e.g. rasterizing an svg.
|
/// Size hint for e.g. rasterizing an svg.
|
||||||
pub fn hint(&self, available_size: Vec2) -> SizeHint {
|
pub fn hint(&self, available_size: Vec2, pixels_per_point: f32) -> SizeHint {
|
||||||
let size = match self.fit {
|
let size = match self.fit {
|
||||||
ImageFit::Original { scale } => return SizeHint::Scale(scale.ord()),
|
ImageFit::Original { scale } => return SizeHint::Scale(scale.ord()),
|
||||||
ImageFit::Fraction(fract) => available_size * fract,
|
ImageFit::Fraction(fract) => available_size * fract,
|
||||||
ImageFit::Exact(size) => size,
|
ImageFit::Exact(size) => size,
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = size.min(self.max_size);
|
let size = size.min(self.max_size);
|
||||||
|
let size = size * pixels_per_point;
|
||||||
// TODO(emilk): take pixels_per_point into account here!
|
|
||||||
|
|
||||||
// `inf` on an axis means "any value"
|
// `inf` on an axis means "any value"
|
||||||
match (size.x.is_finite(), size.y.is_finite()) {
|
match (size.x.is_finite(), size.y.is_finite()) {
|
||||||
(true, true) => SizeHint::Size(size.x.round() as u32, size.y.round() as u32),
|
(true, true) => SizeHint::Size(size.x.round() as u32, size.y.round() as u32),
|
||||||
(true, false) => SizeHint::Width(size.x.round() as u32),
|
(true, false) => SizeHint::Width(size.x.round() as u32),
|
||||||
(false, true) => SizeHint::Height(size.y.round() as u32),
|
(false, true) => SizeHint::Height(size.y.round() as u32),
|
||||||
(false, false) => SizeHint::Scale(1.0.ord()),
|
(false, false) => SizeHint::Scale(pixels_per_point.ord()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue