Fix emboss gizmo font preview of style not rendering properly (#14612)

This commit is contained in:
yw4z
2026-08-09 08:24:04 +03:00
committed by GitHub
parent 9421e7fa9b
commit 6fb18f2d66

View File

@@ -46,23 +46,25 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
bounding_box.merge(BoundingBox(shape.contour.points)); bounding_box.merge(BoundingBox(shape.contour.points));
for (ExPolygon &shape : shapes) shape.translate(-bounding_box.min); for (ExPolygon &shape : shapes) shape.translate(-bounding_box.min);
// calculate conversion from FontPoint to screen pixels by size of font if (bounding_box.size().x() < 1 || bounding_box.size().y() < 1)
double scale = get_text_shape_scale(item.prop, *item.font.font_file) * m_input.ppm; continue; // or however the font job's degenerate-box case is handled
scales[index] = scale;
//double scale = font_prop.size_in_mm * SCALING_FACTOR; // Normalize to fit max_size, exactly like CreateFontImageJob does against m_input.size.
BoundingBoxf bb2(bounding_box.min.cast<double>(), // Fit by height (matches row height), then clamp width if needed.
bounding_box.max.cast<double>()); constexpr float preview_padding_px = 2.f; // margin for AA sampling, tune to your AA kernel radius
double scale = m_input.max_size.y() / (double) bounding_box.size().y();
BoundingBoxf bb2(bounding_box.min.cast<double>(), bounding_box.max.cast<double>());
bb2.scale(scale); bb2.scale(scale);
image.tex_size.x = std::ceil(bb2.max.x() - bb2.min.x());
image.tex_size.y = std::ceil(bb2.max.y() - bb2.min.y());
// crop image width // crop width only if the (now height-normalized) text is too wide
image.tex_size.x = std::ceil(bb2.max.x() - bb2.min.x()) + 2 * preview_padding_px;
image.tex_size.y = std::ceil(bb2.max.y() - bb2.min.y()) + 2 * preview_padding_px;
if (image.tex_size.x > m_input.max_size.x()) if (image.tex_size.x > m_input.max_size.x())
image.tex_size.x = m_input.max_size.x(); image.tex_size.x = m_input.max_size.x();
// crop image height
if (image.tex_size.y > m_input.max_size.y()) scales[index] = scale;
image.tex_size.y = m_input.max_size.y();
} }
// arrange bounding boxes // arrange bounding boxes