Skip to content

PDF renderer rounds coordinates to two decimal places #5801

@mrd0ll4r

Description

@mrd0ll4r

Description

When using PDF as the renderer, coordinates (at least for bezier curves, didn't test anything else) are rounded to two decimal places.

Expected Behavior

I didn't expect any rounding to happen. The PDF specification does not impose a limit on the precision of real numbers (see section 7.3.3 of the Adobe spec).

Current Behavior

Coordinates are rounded to two places after the decimal dot.

Steps to Reproduce

Using this program:

import processing.pdf.*;

void setup() {
  size(400, 400, PDF, "test.pdf");
}

void draw() {
  background(250);
  noFill();
  stroke(0);

  //a few marker lines so we find our way around the PDF later
  line(100, 101, 300, 101);
  line(100, 102, 300, 102);
  line(100, 103, 300, 103);
  line(100, 104, 300, 104);
  line(100, 105, 300, 105);

  beginShape();
  vertex(100, 100);
  // Test rounding behaviour.
  // Note that we use X coordinates to observe what's happening, because PDF coordinate spaces is flipped along the X-axis in comparison to Processing's.
  bezierVertex(
    150.1234, 100, 
    120.127, 210, // observe rounding behaviour
    223.123, 323); 
  endShape();

  // more marker lines
  line(100, 101, 300, 101);
  line(100, 102, 300, 102);
  line(100, 103, 300, 103);
  line(100, 104, 300, 104);
  line(100, 105, 300, 105);

  exit();
}

will produce a PDF file test.pdf. We can decompress the file using mutool, specifically the mutool clean command (https://mupdf.com/docs/manual-mutool-clean.html):

mutool clean -dif test.pdf decompressed.pdf

The resulting PDF file, without all the preamble and trailer stuff, looks like this:

100 299 m
300 299 l
S
100 298 m
300 298 l
S
100 297 m
300 297 l
S
100 296 m
300 296 l
S
100 295 m
300 295 l
S
100 300 m
150.12 300 120.13 190 223.12 77 c
S
100 299 m
300 299 l
S
100 298 m
300 298 l
S
100 297 m
300 297 l
S
100 296 m
300 296 l
S
100 295 m
300 295 l
S

We can see that the coordinates of the bezier curve are rounded.

Of course, I see that this is not the biggest of issues, some precision is still there. For my use case, I could scale everything up by some factor, then rasterize the PDF at a lower resolution, and probably get the same result. But this behavior still came as a surprise to me.

Your Environment

  • Processing version: 3.5.3
  • Operating System and OS version: Debian 9

Possible Causes / Solutions

Does iText enforce this? Can we configure it? Are there hints for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions