yWorks / jsPDF

JavaScript PDF generation to work with SVG
MIT License
56 stars 23 forks source link

setLineDashPattern not complaining if second parameter is missing and not compatible with jsPDF #23

Closed bernhardreiter closed 5 years ago

bernhardreiter commented 5 years ago

jsPDF.version = '2.0.2' is not drawing the line patterns for circles as expected, see the comparison with jspdf (latest) is from April (where setLineDashPattern is not yet an alias for setLineDash.)

<script src="./jspdf.debug.js"></script>
<script type="text/javascript">
  var doc = new jsPDF();

  doc.setDrawColor("#0000ff");

  doc.setLineDashPattern([0.3]);
  doc.setFillColor("#fcfacc");
  doc.circle(10, 10, 2, "FD");

  doc.setLineDashPattern([0.3]);
  doc.setFillColor("#fcfacc");
  doc.circle(20, 10, 2, "FD");

  doc.setLineDashPattern([0]);
  doc.setFillColor("#ffffff");
  doc.circle(30, 10, 2, "FD");

  doc.save('Test.pdf');
</script>
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
<script type="text/javascript">
  var doc = new jsPDF();

  doc.setDrawColor("#0000ff");

  doc.setLineDash([0.3]);
  doc.setFillColor("#fcfacc");
  doc.circle(10, 10, 2, "FD");

  doc.setLineDash([1]);
  doc.setFillColor("#fcfacc");
  doc.circle(20, 10, 2, "FD");

  doc.setLineDash([0]);
  doc.setFillColor("#ffffff");
  doc.circle(30, 10, 2, "FD");

  doc.save('Test.pdf');
</script>

jspdf-yworks.pdf jspdf-201904.pdf

bernhardreiter commented 5 years ago

In addition jspdf-yworks.pdf does not open in a libpoppler based PDF viewer, while jspdf-201904.pdf does, though does not show the last circle.

bernhardreiter commented 5 years ago

Analysis shows: this is because of the missing phase value in the output.

bernhardreiter commented 5 years ago

The alternative of making parameter dash optional would be to to check if it is there and throw an error message. I prefer making it optional, because it makes the calling code shorter and more readable in a common use case.

HackbrettXXX commented 5 years ago

I agree: making dash optional is better.