emf.c: truncate multiplication to 3 decimal places (ticket #242)

This commit is contained in:
gitlost 2021-08-27 18:07:05 +01:00
parent b568201574
commit bb6bb1e5ee

View File

@ -45,6 +45,9 @@
#include "common.h" #include "common.h"
#include "emf.h" #include "emf.h"
/* Multiply truncating to 3 decimal places (avoids rounding differences on various platforms) */
#define mul3dpf(m, arg) (roundf(m * arg * 1000.0) / 1000.0f)
static int count_rectangles(struct zint_symbol *symbol) { static int count_rectangles(struct zint_symbol *symbol) {
int rectangles = 0; int rectangles = 0;
struct zint_vector_rect *rect; struct zint_vector_rect *rect;
@ -468,7 +471,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
causes various different rendering issues for LibreOffice Draw and Inkscape, so using following hack */ causes various different rendering issues for LibreOffice Draw and Inkscape, so using following hack */
if (previous_diameter != circ->diameter + circ->width) { /* Drawing MaxiCode bullseye using overlayed discs */ if (previous_diameter != circ->diameter + circ->width) { /* Drawing MaxiCode bullseye using overlayed discs */
previous_diameter = circ->diameter + circ->width; previous_diameter = circ->diameter + circ->width;
radius = (float) (0.5 * previous_diameter); radius = mul3dpf(0.5, previous_diameter);
} }
circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE
circle[this_circle].size = 24; circle[this_circle].size = 24;
@ -507,9 +510,9 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
if (previous_diameter != hex->diameter) { if (previous_diameter != hex->diameter) {
previous_diameter = hex->diameter; previous_diameter = hex->diameter;
radius = (float) (0.5 * previous_diameter); radius = mul3dpf(0.5, previous_diameter);
half_radius = (float) (0.25 * previous_diameter); half_radius = mul3dpf(0.25, previous_diameter);
half_sqrt3_radius = (float) (0.43301270189221932338 * previous_diameter); half_sqrt3_radius = mul3dpf(0.43301270189221932338, previous_diameter);
} }
/* Note rotation done via world transform */ /* Note rotation done via world transform */