Skip to content

Commit 6801085

Browse files
committed
pdfrenderer: Fix ClipBaseline and optimize code
The division was made with integers, giving a wrong result. * Avoid division and use pure integer operations. * Add missing "static" attribute. Signed-off-by: Stefan Weil <[email protected]>
1 parent a414443 commit 6801085

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/api/pdfrenderer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,16 @@ void AffineMatrix(int writing_direction,
293293
// these viewers. I chose this threshold large enough to absorb noise,
294294
// but small enough that lines probably won't cross each other if the
295295
// whole page is tilted at almost exactly the clipping threshold.
296-
void ClipBaseline(int ppi, int x1, int y1, int x2, int y2,
297-
int *line_x1, int *line_y1,
298-
int *line_x2, int *line_y2) {
296+
static void ClipBaseline(int ppi, int x1, int y1, int x2, int y2,
297+
int *line_x1, int *line_y1,
298+
int *line_x2, int *line_y2) {
299299
*line_x1 = x1;
300300
*line_y1 = y1;
301301
*line_x2 = x2;
302302
*line_y2 = y2;
303-
double rise = abs(y2 - y1) * 72 / ppi;
304-
double run = abs(x2 - x1) * 72 / ppi;
305-
if (rise < 2.0 && 2.0 < run)
303+
int rise = abs(y2 - y1) * 72;
304+
int run = abs(x2 - x1) * 72;
305+
if (rise < 2 * ppi && 2 * ppi < run)
306306
*line_y1 = *line_y2 = (y1 + y2) / 2;
307307
}
308308

0 commit comments

Comments
 (0)