[gs-commits] ghostpdl branch, pdfi, updated. jbig2dec-0.14-2116-g7711ff4
[email protected] (Nancy Durgin)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
The ghostpdl branch, pdfi has been updated
via 7711ff49445ead2fa875ded8fa6bee30e369ad71 (commit)
from f6ba9de1bfc18b1c437711d23a5f7e974727f524 (commit)
----------------------------------------------------------------------
commit 7711ff49445ead2fa875ded8fa6bee30e369ad71
Author: Nancy Durgin <[email protected]>
Date: Thu Aug 22 12:55:51 2019 -0700
Some fixes to SMask
These are from looking at the PS code and Bug694455.pdf.
1) Allow the case where the SMask dict doesn't contain a /Type
(this will fix a few samples with the /Type missing from SMask)
2) Need to transform the BBox by the Matrix for setting up transparency.
NOTE: right now Bug694455.pdf not rendering correctly, still.
diff --git a/pdf/pdf_array.c b/pdf/pdf_array.c
index 3c67c8b..7ed2d6b 100644
--- a/pdf/pdf_array.c
+++ b/pdf/pdf_array.c
@@ -329,3 +329,39 @@ int pdfi_array_to_gs_matrix(pdf_context *ctx, pdf_array *array, gs_matrix *mat)
errorExit:
return code;
}
+
+/* Transform a BBox by a matrix (from zmatrix.c/zbbox_transform())*/
+void
+pdfi_bbox_transform(pdf_context *ctx, gs_rect *bbox, gs_matrix *matrix)
+{
+ gs_point aa, az, za, zz;
+ double temp;
+
+ gs_point_transform(bbox->p.x, bbox->p.y, matrix, &aa);
+ gs_point_transform(bbox->p.x, bbox->q.y, matrix, &az);
+ gs_point_transform(bbox->q.x, bbox->p.y, matrix, &za);
+ gs_point_transform(bbox->q.x, bbox->q.y, matrix, &zz);
+
+ if ( aa.x > az.x)
+ temp = aa.x, aa.x = az.x, az.x = temp;
+ if ( za.x > zz.x)
+ temp = za.x, za.x = zz.x, zz.x = temp;
+ if ( za.x < aa.x)
+ aa.x = za.x; /* min */
+ if ( az.x > zz.x)
+ zz.x = az.x; /* max */
+
+ if ( aa.y > az.y)
+ temp = aa.y, aa.y = az.y, az.y = temp;
+ if ( za.y > zz.y)
+ temp = za.y, za.y = zz.y, zz.y = temp;
+ if ( za.y < aa.y)
+ aa.y = za.y; /* min */
+ if ( az.y > zz.y)
+ zz.y = az.y; /* max */
+
+ bbox->p.x = aa.x;
+ bbox->p.y = aa.y;
+ bbox->q.x = zz.x;
+ bbox->q.y = zz.y;
+}
diff --git a/pdf/pdf_array.h b/pdf/pdf_array.h
index c53dd0a..e0a3227 100644
--- a/pdf/pdf_array.h
+++ b/pdf/pdf_array.h
@@ -36,5 +36,6 @@ bool pdfi_array_known(pdf_context *ctx, pdf_array *a, pdf_obj *, int *index);
void pdfi_normalize_rect(pdf_context *ctx, gs_rect *rect);
int pdfi_array_to_gs_rect(pdf_context *ctx, pdf_array *array, gs_rect *rect);
int pdfi_array_to_gs_matrix(pdf_context *ctx, pdf_array *array, gs_matrix *matrix);
+void pdfi_bbox_transform(pdf_context *ctx, gs_rect *bbox, gs_matrix *matrix);
#endif
diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c
index 61f9a36..54b9aa3 100644
--- a/pdf/pdf_image.c
+++ b/pdf/pdf_image.c
@@ -1507,7 +1507,9 @@ int pdfi_Do(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
* of the graphics state, if its a Form XObject. So gsave/grestore round it
* to prevent unexpected changes.
*/
+ // pdfi_gsave(ctx);
code = pdfi_do_image_or_form(ctx, stream_dict, page_dict, (pdf_dict *)o);
+ // pdfi_grestore(ctx);
if (code < 0)
goto exit;
diff --git a/pdf/pdf_trans.c b/pdf/pdf_trans.c
index 5c5dd3d..4d3421d 100644
--- a/pdf/pdf_trans.c
+++ b/pdf/pdf_trans.c
@@ -30,21 +30,21 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs)
{
int code;
pdf_dict *SMask = igs->SMask;
- // gs_color_space *gray_cs = gs_cspace_new_DeviceGray(ctx->memory);
gs_color_space *pcs = NULL;
- gs_rect bbox = { { 0, 0} , { 1, 1} };
+ gs_rect bbox;
gs_transparency_mask_params_t params;
pdf_array *BBox = NULL;
+ pdf_array *Matrix = NULL;
pdf_array *a = NULL;
pdf_dict *G_dict = NULL;
pdf_dict *Group = NULL;
pdf_name *n = NULL;
pdf_obj *CS = NULL;
double f;
- gs_matrix save_matrix, GroupMat;
+ gs_matrix save_matrix, GroupMat, group_Matrix;
code = pdfi_dict_knownget_type(ctx, SMask, "Type", PDF_NAME, (pdf_obj **)&n);
- if (code > 0 && pdfi_name_is(n, "Mask")) {
+ if (code == 0 || (code > 0 && pdfi_name_is(n, "Mask"))) {
code = pdfi_dict_knownget_type(ctx, SMask, "G", PDF_DICT, (pdf_obj **)&G_dict);
if (code > 0) {
code = pdfi_dict_knownget_type(ctx, G_dict, "Matte", PDF_ARRAY, (pdf_obj **)&a);
@@ -66,11 +66,9 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs)
code = pdfi_dict_knownget_type(ctx, G_dict, "BBox", PDF_ARRAY, (pdf_obj **)&BBox);
if (code < 0)
goto exit;
- if (code > 0) {
- code = pdfi_array_to_gs_rect(ctx, BBox, &bbox);
- if (code < 0)
- goto exit;
- }
+ code = pdfi_array_to_gs_rect(ctx, BBox, &bbox);
+ if (code < 0)
+ goto exit;
gs_trans_mask_params_init(¶ms, TRANSPARENCY_MASK_Luminosity);
params.replacing = true;
@@ -83,6 +81,16 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs)
gs_currentmatrix(igs->GroupGState, &GroupMat);
gs_setmatrix(ctx->pgs, &GroupMat);
+ code = pdfi_dict_knownget_type(ctx, G_dict, "Matrix", PDF_ARRAY, (pdf_obj **)&Matrix);
+ if (code < 0)
+ goto exit;
+ code = pdfi_array_to_gs_matrix(ctx, Matrix, &group_Matrix);
+ if (code < 0)
+ goto exit;
+
+ /* Transform the BBox by the Matrix */
+ pdfi_bbox_transform(ctx, &bbox, &group_Matrix);
+
/* CS is in the dict "Group" inside the dict "G" */
/* TODO: Not sure if this is a required thing or just one possibility */
code = pdfi_dict_knownget_type(ctx, G_dict, "Group", PDF_DICT, (pdf_obj **)&Group);
@@ -134,6 +142,7 @@ static int pdfi_trans_set_mask(pdf_context *ctx, pdfi_int_gstate *igs)
pdfi_countdown(G_dict);
pdfi_countdown(a);
pdfi_countdown(BBox);
+ pdfi_countdown(Matrix);
pdfi_countdown(CS);
return code;
}
Summary of changes:
pdf/pdf_array.c | 36 ++++++++++++++++++++++++++++++++++++
pdf/pdf_array.h | 1 +
pdf/pdf_image.c | 2 ++
pdf/pdf_trans.c | 27 ++++++++++++++++++---------
4 files changed, 57 insertions(+), 9 deletions(-)