From d7d50676db5d7f44ce27852f468f86604b5f1d01 Mon Sep 17 00:00:00 2001 From: Richard Lescak Date: Thu, 16 Mar 2023 09:39:13 +0100 Subject: [PATCH] fix bbox device calculating bounding box incorrectly Resolves: rhbz#2176327 --- ghostscript-9.27-fix-bbox.patch | 63 +++++++++++++++++++++++++++++++++ ghostscript.spec | 7 +++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 ghostscript-9.27-fix-bbox.patch diff --git a/ghostscript-9.27-fix-bbox.patch b/ghostscript-9.27-fix-bbox.patch new file mode 100644 index 0000000..fdb7f3a --- /dev/null +++ b/ghostscript-9.27-fix-bbox.patch @@ -0,0 +1,63 @@ +diff -Napur ghostscript-9.27.old/base/fapi_ft.c ghostscript-9.27.new/base/fapi_ft.c +--- ghostscript-9.27.old/base/fapi_ft.c 2019-04-04 00:43:14.000000000 -0700 ++++ ghostscript-9.27.new/base/fapi_ft.c 2023-03-07 16:41:56.217995052 -0800 +@@ -974,13 +974,19 @@ make_rotation(FT_Matrix * a_transform, c + */ + static void + transform_decompose(FT_Matrix * a_transform, FT_UInt * xresp, FT_UInt * yresp, +- FT_Fixed * a_x_scale, FT_Fixed * a_y_scale) ++ FT_Fixed * a_x_scale, FT_Fixed * a_y_scale, int units_per_EM) + { + double scalex, scaley, fact = 1.0; + double factx = 1.0, facty = 1.0; + FT_Matrix ftscale_mat; + FT_UInt xres; + FT_UInt yres; ++ /* We have to account for units_per_EM as we fiddle with the scaling ++ * in order to avoid underflow (mostly in the TTF hinting code), but ++ * we also want to clamp to a lower value (512, admittedly arrived at ++ * via experimentation) in order to preserve the fidelity of the outlines. ++ */ ++ double upe = units_per_EM > 512 ? (float)units_per_EM : 512.0; + + scalex = hypot((double)a_transform->xx, (double)a_transform->xy); + scaley = hypot((double)a_transform->yx, (double)a_transform->yy); +@@ -1067,10 +1073,25 @@ transform_decompose(FT_Matrix * a_transf + scalex *= fact; + } + +- ftscale_mat.xx = (FT_Fixed) (65536.0 / scalex); +- ftscale_mat.xy = (FT_Fixed) 0; +- ftscale_mat.yx = (FT_Fixed) 0; +- ftscale_mat.yy = (FT_Fixed) (65536.0 / scaley); ++ /* see above */ ++ fact = 1.0; ++ while (scaley * yres > (double)upe * 72.0 && (xres > 0 && yres > 0) ++ && (scalex > 0.0 && scaley > 0.0)) { ++ if (scaley < yres) { ++ xres >>= 1; ++ yres >>= 1; ++ fact *= 2.0; ++ } ++ else { ++ scalex /= 1.25; ++ scaley /= 1.25; ++ } ++ } ++ ++ ftscale_mat.xx = (FT_Fixed) ((65536.0 / scalex) * fact); ++ ftscale_mat.xy = 0; ++ ftscale_mat.yx = 0; ++ ftscale_mat.yy = (FT_Fixed) ((65536.0 / scaley) * fact); + + FT_Matrix_Multiply(a_transform, &ftscale_mat); + memcpy(a_transform, &ftscale_mat, sizeof(FT_Matrix)); +@@ -1315,7 +1336,7 @@ gs_fapi_ft_get_scaled_font(gs_fapi_serve + * transform. + */ + transform_decompose(&face->ft_transform, &face->horz_res, +- &face->vert_res, &face->width, &face->height); ++ &face->vert_res, &face->width, &face->height, face->ft_face->units_per_EM); + + ft_error = FT_Set_Char_Size(face->ft_face, face->width, face->height, + face->horz_res, face->vert_res); diff --git a/ghostscript.spec b/ghostscript.spec index d670979..2aea2b6 100644 --- a/ghostscript.spec +++ b/ghostscript.spec @@ -37,7 +37,7 @@ Name: ghostscript Summary: Interpreter for PostScript language & PDF Version: 9.27 -Release: 6%{?dist} +Release: 7%{?dist} License: AGPLv3+ @@ -107,6 +107,7 @@ Patch014: ghostscript-cve-2020-16301.patch Patch015: ghostscript-9.27-fix-use-of-HWMargins.patch Patch016: ghostscript-9.27-Deal-with-different-VM-modes-during-CIDFont-loading.patch Patch017: ghostscript-9.27-ESC-Page-driver-does-not-set-page-size-correctly.patch +Patch018: ghostscript-9.27-fix-bbox.patch # Downstream patches -- these should be always included when doing rebase: @@ -447,6 +448,10 @@ done # ============================================================================= %changelog +* Wed Mar 15 2023 Richard Lescak - 9.27-7 +- fix bbox device calculating bounding box incorrectly +- Resolves: rhbz#2176327 + * Thu Feb 02 2023 Richard Lescak - 9.27-6 - set the page size for A4 correctly in ESC/Page driver - Resolves: rhbz#2164603