0001_No_output_visible_with_pdfwriter.diff 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From e12b8487283979ab454a32888a3c37d4d9492480 Mon Sep 17 00:00:00 2001
  2. From: Ken Sharp <Ken.Sharp@artifex.com>
  3. Date: Thu, 14 Mar 2024 13:08:38 +0000
  4. Subject: [PATCH] pdfwrite - more improvements for mesh shadings
  5. Bug #707655 "No output visible with pdfwriter"
  6. commit 3d6e3acbcda79a0096cd1ad73c7b9b1101a43187 to fix bug #06852
  7. unfortunately led to this regression. The problem is related to the
  8. scaling of co-ordinates performed when a mesh shading has vertex
  9. co-ordinates which are too large for Acrobat 5 (PDF 1.4).
  10. Acrobat 5 has a limit of =/-32767 on real numbers, which applies to the
  11. /Decode array of a mesh shading. Because this is an Acrobat limit, not a
  12. limit of the PDF specification we would ordinarily ignore it, but the
  13. PDF/A-1 specification chose to carry the Acrobat limitations into the
  14. PDF/A spec.
  15. This commit fixes the problem by correctly scaling the co-ordinate
  16. values to the Decode array values when outputting to PDF 1.4 or less,
  17. even if no actual co-ordinte scaling is required, and modifying the
  18. /Matrix of the Pattern to scale up the Decode values to the real
  19. co-ordinates. Crucially we must not scale the Tx and Ty values of the
  20. CTM.
  21. ---
  22. devices/vector/gdevpdfv.c | 20 ++++++++++++--------
  23. 1 file changed, 12 insertions(+), 8 deletions(-)
  24. diff --git a/devices/vector/gdevpdfv.c b/devices/vector/gdevpdfv.c
  25. index e880acafd..90a02158f 100644
  26. --- a/devices/vector/gdevpdfv.c
  27. +++ b/devices/vector/gdevpdfv.c
  28. @@ -42,8 +42,8 @@ extern const gx_device_color_type_t gx_dc_pattern2;
  29. */
  30. #define ENCODE_VALUE(v, emax, vmin, vmax)\
  31. ( ((v) - (vmin)) * ((double)(emax) / ((vmax) - (vmin))) )
  32. -#define PDFA_MIN_MESH_COORDINATE (-0x800000 / 256.0)
  33. -#define PDFA_MAX_MESH_COORDINATE ( 0x7fffff / 256.0)
  34. +#define PDFA_MIN_MESH_COORDINATE (-0x400000 / 128.0)
  35. +#define PDFA_MAX_MESH_COORDINATE ( 0x3fffff / 128.0)
  36. #define PDFA_ENCODE_MESH_COORDINATE(v)\
  37. ENCODE_VALUE(v, 0xffffff, PDFA_MIN_MESH_COORDINATE, PDFA_MAX_MESH_COORDINATE)
  38. #define MIN_MESH_COORDINATE (-0x800000 )
  39. @@ -690,6 +690,7 @@ typedef struct pdf_mesh_data_params_s {
  40. int num_components;
  41. bool is_indexed;
  42. int rescale; /* If the co-ordinates won't fit into crappy Acrobat values, scale them here and in the pattern Matrix */
  43. + bool old_pdf;
  44. const float *Domain; /* iff Function */
  45. const gs_range_t *ranges;
  46. } pdf_mesh_data_params_t;
  47. @@ -713,7 +714,7 @@ put_clamped(byte *p, double v, int num_bytes)
  48. static inline void
  49. put_clamped_coord(byte *p, double v, int num_bytes, const pdf_mesh_data_params_t *pmdp)
  50. {
  51. - if (pmdp->rescale != 1.0) {
  52. + if (pmdp->rescale != 1.0 || pmdp->old_pdf) {
  53. v = v / pmdp->rescale;
  54. put_clamped(p, PDFA_ENCODE_MESH_COORDINATE(v), num_bytes);
  55. } else
  56. @@ -1027,7 +1028,9 @@ pdf_put_mesh_shading(gx_device_pdf *pdev, cos_stream_t *pscs, const gs_shading_t
  57. if (z > *rescale)
  58. *rescale = (int)z;
  59. data_params.rescale = *rescale;
  60. - }
  61. + data_params.old_pdf = 1;
  62. + } else
  63. + data_params.old_pdf = 0;
  64. switch (ShadingType(psh)) {
  65. case shading_type_Free_form_Gouraud_triangle: {
  66. @@ -1183,12 +1186,13 @@ pdf_put_pattern2(gx_device_pdf *pdev, const gs_gstate * pgs, const gx_drawing_co
  67. yscale = 72.0 / pdev->HWResolution[1];
  68. }
  69. - if (rescale != 1) {
  70. - xscale *= rescale;
  71. - yscale *= rescale;
  72. - }
  73. smat.xx *= xscale, smat.yx *= xscale, smat.tx *= xscale;
  74. smat.xy *= yscale, smat.yy *= yscale, smat.ty *= yscale;
  75. +
  76. + if (rescale != 1) {
  77. + smat.xx *= rescale, smat.yx *= rescale;
  78. + smat.xy *= rescale, smat.yy *= rescale;
  79. + }
  80. }
  81. /* Bug #697451, if we emit a PDF with a type 2 Pattern where the
  82. --
  83. 2.34.1