Skip to content

Commit d6f1e2e

Browse files
fix: nsvg rasterize hdpi
#314
1 parent 98c9392 commit d6f1e2e

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/shell/contextmenu/menu_widget.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ void mb_shell::menu_item_normal_widget::render(ui::nanovg_context ctx) {
168168
auto icon_unfold = fmt::format(
169169
R"#(<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 12 12"><path opacity="0.7" fill="{}" d="M4.646 2.146a.5.5 0 0 0 0 .708L7.793 6L4.646 9.146a.5.5 0 1 0 .708.708l3.5-3.5a.5.5 0 0 0 0-.708l-3.5-3.5a.5.5 0 0 0-.708 0"/></svg>)#",
170170
c ? "white" : "black");
171-
auto icon_unfold_img_svg = nsvgParse(icon_unfold.data(), "px", 96);
171+
ui::nanovg_context::NSVGimageRAII icon_unfold_img_svg(
172+
nsvgParse(icon_unfold.data(), "px", 96));
172173
this->icon_unfold_img =
173-
ctx.imageFromSVG(icon_unfold_img_svg, ctx.rt->dpi_scale);
174+
ctx.imageFromSVG(icon_unfold_img_svg.image, ctx.rt->dpi_scale);
174175
}
175176

176177
auto paintY = floor(*y + (*height - icon_width) / 2);
@@ -997,8 +998,9 @@ void mb_shell::menu_item_normal_widget::reload_icon_img(
997998
icon_img = ui::LoadBitmapImage(ctx, (HBITMAP)item.icon_bitmap.value());
998999
else if (item.icon_svg) {
9991000
std::string copy = item.icon_svg.value();
1000-
auto svg = nsvgParse(copy.data(), "px", 96);
1001-
icon_img = ctx.imageFromSVG(svg, ctx.rt->dpi_scale);
1001+
ui::nanovg_context::NSVGimageRAII svg(
1002+
nsvgParse(copy.data(), "px", 96));
1003+
icon_img = ctx.imageFromSVG(svg.image, ctx.rt->dpi_scale);
10021004
} else {
10031005
icon_img = std::nullopt;
10041006
}
@@ -1232,7 +1234,9 @@ void mb_shell::screenside_button_group_widget::button_widget::render(
12321234

12331235
float icon_size = std::min(*width, *height) - 8.f;
12341236
if (!icon) {
1235-
icon = ctx.imageFromSVG(nsvgParse(icon_svg.data(), "px", 96));
1237+
ui::nanovg_context::NSVGimageRAII svg(
1238+
nsvgParse(icon_svg.data(), "px", 96));
1239+
icon = ctx.imageFromSVG(svg.image);
12361240
}
12371241

12381242
if (icon) {

src/shell/script/binding_types_breeze_ui.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ struct image_widget : public ui::widget {
360360
const auto &data = std::get<data_svg>(image_data);
361361
auto svg = data.svg;
362362

363-
image = ctx.imageFromSVG(nsvgParse(svg.data(), "px", 96));
363+
ui::nanovg_context::NSVGimageRAII parsed_svg(
364+
nsvgParse(svg.data(), "px", 96));
365+
image = ctx.imageFromSVG(parsed_svg.image);
364366
}
365367
}
366368

0 commit comments

Comments
 (0)