[cairo-commit] 2 commits - src/cairo-pdf-surface.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Feb 21 15:49:07 UTC 2021

 src/cairo-pdf-surface.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

New commits:
commit f4e43b6822ec73f2fd8046859315e5d2a5709bf5
Merge: 79b539fab a3b69a021
Author: Heiko Lewin <hlewin at gmx.de>
Date:   Sun Feb 21 15:49:06 2021 +0000

    Merge branch 'pdf-font-names' into 'master'
    pdf font subset: Generate valid font names
    Closes #449
    See merge request cairo/cairo!125

commit a3b69a0215fdface0fd5730872a4b3242d979dca
Author: Uli Schlachter <psychon at znc.in>
Date:   Tue Feb 9 16:54:35 2021 +0100

    pdf font subset: Generate valid font names
    A hash value is encoded in base 26 with upper case letters for font
    Commit ed984146 replaced "numerator = abs (hash);" with "numerator =
    hash;" in this code, because hash has type uint32_t and the compiler
    warned about taking the absolute value of an unsigned value.  However,
    abs() is actually defined to take an int argument. Thus, there was some
    implicit cast.
    Since numerator has type long, i.e. is signed, it is now actually
    possible to get an overflow in the implicit cast and then have a
    negative number. The following code is not prepared for this and
    produces non-letters when encoding the hash.
    This commit fixes that problem by not using ldiv() and instead using /
    and % to directly compute the needed values. This gets rid of the need
    to convert to type long. Since now everything works with uint32_t, there
    is no more chance for negative numbers messing things up.
    Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/449
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 6da460878..52c49b6d2 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -5310,18 +5310,14 @@ _create_font_subset_tag (cairo_scaled_font_subset_t	*font_subset,
     uint32_t hash;
     int i;
-    long numerator;
-    ldiv_t d;
     hash = _hash_data ((unsigned char *) font_name, strlen(font_name), 0);
     hash = _hash_data ((unsigned char *) (font_subset->glyphs),
 		       font_subset->num_glyphs * sizeof(unsigned long), hash);
-    numerator = hash;
     for (i = 0; i < 6; i++) {
-	d = ldiv (numerator, 26);
-	numerator = d.quot;
-        tag[i] = 'A' + d.rem;
+	tag[i] = 'A' + (hash % 26);
+	hash /= 26;
     tag[i] = 0;

More information about the cairo-commit mailing list