Fix T103061: GPencil export to SVG wrong line thickness

When the line was very thin the precision of the thickness
calculation was not precise enough.

The algorithm has been improved. This affects SVG and PDF.
This commit is contained in:
Antonio Vazquez 2022-12-13 11:39:13 +01:00
parent e8c7866608
commit 85a743e08b
Notes: blender-bot 2023-02-14 08:42:53 +01:00
Referenced by issue #103061, GPencil: SVG exporter generates wrong stroke thickness
Referenced by issue #102967, 3.4: Potential candidates for corrective releases
2 changed files with 10 additions and 4 deletions

View File

@ -177,7 +177,8 @@ void GpencilExporterPDF::export_gpencil_layers()
/* Apply layer thickness change. */
gps_duplicate->thickness += gpl->line_change;
/* Apply object scale to thickness. */
gps_duplicate->thickness *= mat4_to_scale(ob->object_to_world);
const float scalef = mat4_to_scale(ob->object_to_world);
gps_duplicate->thickness = ceilf((float)gps_duplicate->thickness * scalef);
CLAMP_MIN(gps_duplicate->thickness, 1.0f);
/* Fill. */
if ((is_fill) && (params_.flag & GP_EXPORT_FILL)) {
@ -236,7 +237,9 @@ void GpencilExporterPDF::export_stroke_to_polyline(bGPDlayer *gpl,
if (is_stroke && !do_fill) {
HPDF_Page_SetLineJoin(page_, HPDF_ROUND_JOIN);
HPDF_Page_SetLineWidth(page_, MAX2((radius * 2.0f) - gpl->line_change, 1.0f));
const float width = MAX2(
MAX2(gps->thickness + gpl->line_change, (radius * 2.0f) + gpl->line_change), 1.0f);
HPDF_Page_SetLineWidth(page_, width);
}
/* Loop all points. */

View File

@ -198,7 +198,8 @@ void GpencilExporterSVG::export_gpencil_layers()
/* Apply layer thickness change. */
gps_duplicate->thickness += gpl->line_change;
/* Apply object scale to thickness. */
gps_duplicate->thickness *= mat4_to_scale(ob->object_to_world);
const float scalef = mat4_to_scale(ob->object_to_world);
gps_duplicate->thickness = ceilf((float)gps_duplicate->thickness * scalef);
CLAMP_MIN(gps_duplicate->thickness, 1.0f);
const bool is_normalized = ((params_.flag & GP_EXPORT_NORM_THICKNESS) != 0) ||
@ -308,7 +309,9 @@ void GpencilExporterSVG::export_stroke_to_polyline(bGPDlayer *gpl,
color_string_set(gpl, gps, node_gps, do_fill);
if (is_stroke && !do_fill) {
node_gps.append_attribute("stroke-width").set_value((radius * 2.0f) - gpl->line_change);
const float width = MAX2(
MAX2(gps->thickness + gpl->line_change, (radius * 2.0f) + gpl->line_change), 1.0f);
node_gps.append_attribute("stroke-width").set_value(width);
}
std::string txt;