93 lines
3.7 KiB
Diff
93 lines
3.7 KiB
Diff
From e12b8487283979ab454a32888a3c37d4d9492480 Mon Sep 17 00:00:00 2001
|
|
From: Ken Sharp <Ken.Sharp@artifex.com>
|
|
Date: Thu, 14 Mar 2024 13:08:38 +0000
|
|
Subject: [PATCH] pdfwrite - more improvements for mesh shadings
|
|
|
|
Bug #707655 "No output visible with pdfwriter"
|
|
|
|
commit 3d6e3acbcda79a0096cd1ad73c7b9b1101a43187 to fix bug #06852
|
|
unfortunately led to this regression. The problem is related to the
|
|
scaling of co-ordinates performed when a mesh shading has vertex
|
|
co-ordinates which are too large for Acrobat 5 (PDF 1.4).
|
|
|
|
Acrobat 5 has a limit of =/-32767 on real numbers, which applies to the
|
|
/Decode array of a mesh shading. Because this is an Acrobat limit, not a
|
|
limit of the PDF specification we would ordinarily ignore it, but the
|
|
PDF/A-1 specification chose to carry the Acrobat limitations into the
|
|
PDF/A spec.
|
|
|
|
This commit fixes the problem by correctly scaling the co-ordinate
|
|
values to the Decode array values when outputting to PDF 1.4 or less,
|
|
even if no actual co-ordinte scaling is required, and modifying the
|
|
/Matrix of the Pattern to scale up the Decode values to the real
|
|
co-ordinates. Crucially we must not scale the Tx and Ty values of the
|
|
CTM.
|
|
---
|
|
devices/vector/gdevpdfv.c | 20 ++++++++++++--------
|
|
1 file changed, 12 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/devices/vector/gdevpdfv.c b/devices/vector/gdevpdfv.c
|
|
index e880acafd..90a02158f 100644
|
|
--- a/devices/vector/gdevpdfv.c
|
|
+++ b/devices/vector/gdevpdfv.c
|
|
@@ -42,8 +42,8 @@ extern const gx_device_color_type_t gx_dc_pattern2;
|
|
*/
|
|
#define ENCODE_VALUE(v, emax, vmin, vmax)\
|
|
( ((v) - (vmin)) * ((double)(emax) / ((vmax) - (vmin))) )
|
|
-#define PDFA_MIN_MESH_COORDINATE (-0x800000 / 256.0)
|
|
-#define PDFA_MAX_MESH_COORDINATE ( 0x7fffff / 256.0)
|
|
+#define PDFA_MIN_MESH_COORDINATE (-0x400000 / 128.0)
|
|
+#define PDFA_MAX_MESH_COORDINATE ( 0x3fffff / 128.0)
|
|
#define PDFA_ENCODE_MESH_COORDINATE(v)\
|
|
ENCODE_VALUE(v, 0xffffff, PDFA_MIN_MESH_COORDINATE, PDFA_MAX_MESH_COORDINATE)
|
|
#define MIN_MESH_COORDINATE (-0x800000 )
|
|
@@ -690,6 +690,7 @@ typedef struct pdf_mesh_data_params_s {
|
|
int num_components;
|
|
bool is_indexed;
|
|
int rescale; /* If the co-ordinates won't fit into crappy Acrobat values, scale them here and in the pattern Matrix */
|
|
+ bool old_pdf;
|
|
const float *Domain; /* iff Function */
|
|
const gs_range_t *ranges;
|
|
} pdf_mesh_data_params_t;
|
|
@@ -713,7 +714,7 @@ put_clamped(byte *p, double v, int num_bytes)
|
|
static inline void
|
|
put_clamped_coord(byte *p, double v, int num_bytes, const pdf_mesh_data_params_t *pmdp)
|
|
{
|
|
- if (pmdp->rescale != 1.0) {
|
|
+ if (pmdp->rescale != 1.0 || pmdp->old_pdf) {
|
|
v = v / pmdp->rescale;
|
|
put_clamped(p, PDFA_ENCODE_MESH_COORDINATE(v), num_bytes);
|
|
} else
|
|
@@ -1027,7 +1028,9 @@ pdf_put_mesh_shading(gx_device_pdf *pdev, cos_stream_t *pscs, const gs_shading_t
|
|
if (z > *rescale)
|
|
*rescale = (int)z;
|
|
data_params.rescale = *rescale;
|
|
- }
|
|
+ data_params.old_pdf = 1;
|
|
+ } else
|
|
+ data_params.old_pdf = 0;
|
|
|
|
switch (ShadingType(psh)) {
|
|
case shading_type_Free_form_Gouraud_triangle: {
|
|
@@ -1183,12 +1186,13 @@ pdf_put_pattern2(gx_device_pdf *pdev, const gs_gstate * pgs, const gx_drawing_co
|
|
yscale = 72.0 / pdev->HWResolution[1];
|
|
}
|
|
|
|
- if (rescale != 1) {
|
|
- xscale *= rescale;
|
|
- yscale *= rescale;
|
|
- }
|
|
smat.xx *= xscale, smat.yx *= xscale, smat.tx *= xscale;
|
|
smat.xy *= yscale, smat.yy *= yscale, smat.ty *= yscale;
|
|
+
|
|
+ if (rescale != 1) {
|
|
+ smat.xx *= rescale, smat.yx *= rescale;
|
|
+ smat.xy *= rescale, smat.yy *= rescale;
|
|
+ }
|
|
}
|
|
|
|
/* Bug #697451, if we emit a PDF with a type 2 Pattern where the
|
|
--
|
|
2.34.1
|
|
|