[cairo-commit] 2 commits - src/cairo-pdf-surface.c src/cairo-scaled-font-subsets.c src/cairo-truetype-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun Jul 17 12:08:24 UTC 2016


 src/cairo-pdf-surface.c         |   32 +++++++++++++++++++-------------
 src/cairo-scaled-font-subsets.c |    6 +++++-
 src/cairo-truetype-subset.c     |   21 +++++++++++++++------
 3 files changed, 39 insertions(+), 20 deletions(-)

New commits:
commit 8a921e6c3ee1cbd7353cd28c23802cfef3e48224
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Jul 17 21:33:12 2016 +0930

    truetype: reverse cmap search should end when 0xffff- 0xffff range reached

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index f47b966..afd396e 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -1309,11 +1309,14 @@ _cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font,
 
     /* search for glyph in segments with rangeOffset=0 */
     for (i = 0; i < num_segments; i++) {
+	uint16_t start = be16_to_cpu (start_code[i]);
+	uint16_t end = be16_to_cpu (end_code[i]);
+
+	if (start == 0xffff && end == 0xffff)
+	    break;
+
 	c = index - be16_to_cpu (delta[i]);
-	if (range_offset[i] == 0 &&
-	    c >= be16_to_cpu (start_code[i]) &&
-	    c <= be16_to_cpu (end_code[i]))
-	{
+	if (range_offset[i] == 0 && c >= start && c <= end) {
 	    *ucs4 = c;
 	    goto found;
 	}
@@ -1321,9 +1324,15 @@ _cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font,
 
     /* search for glyph in segments with rangeOffset=1 */
     for (i = 0; i < num_segments; i++) {
+	uint16_t start = be16_to_cpu (start_code[i]);
+	uint16_t end = be16_to_cpu (end_code[i]);
+
+	if (start == 0xffff && end == 0xffff)
+	    break;
+
 	if (range_offset[i] != 0) {
 	    uint16_t *glyph_ids = &range_offset[i] + be16_to_cpu (range_offset[i])/2;
-	    int range_size = be16_to_cpu (end_code[i]) - be16_to_cpu (start_code[i]) + 1;
+	    int range_size = end - start + 1;
 	    uint16_t g_id_be = cpu_to_be16 (index);
 	    int j;
 
@@ -1333,7 +1342,7 @@ _cairo_truetype_reverse_cmap (cairo_scaled_font_t *scaled_font,
 
 		for (j = 0; j < range_size; j++) {
 		    if (glyph_ids[j] == g_id_be) {
-			*ucs4 = be16_to_cpu (start_code[i]) + j;
+			*ucs4 = start + j;
 			goto found;
 		    }
 		}
commit 16a8c13b6acad62c8844bf641c1296a9f4aac09d
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Jul 17 21:19:37 2016 +0930

    pdf: Don't fail subsetting if unable to convert utf8 to utf16
    
    If the unicode came from the font, don't fail if utf8_to_utf16 fails.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 51a9514..436bff0 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -4833,8 +4833,12 @@ _cairo_pdf_surface_emit_unicode_for_glyph (cairo_pdf_surface_t	*surface,
 
     if (utf8 && *utf8) {
 	status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len);
-	if (unlikely (status))
+	if (unlikely (status == CAIRO_INT_STATUS_INVALID_STRING)) {
+	    utf16 = NULL;
+	    utf16_len = 0;
+	} else if (unlikely (status)) {
 	    return status;
+	}
     }
 
     _cairo_output_stream_printf (surface->output, "<");
@@ -5110,13 +5114,14 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 	char *pdf_str;
 
 	status = _utf8_to_pdf_string (subset->family_name_utf8, &pdf_str);
-	if (unlikely (status))
+	if (likely (status == CAIRO_INT_STATUS_SUCCESS)) {
+	    _cairo_output_stream_printf (surface->output,
+					 "   /FontFamily %s\n",
+					 pdf_str);
+	    free (pdf_str);
+	} else if (status != CAIRO_INT_STATUS_INVALID_STRING) {
 	    return status;
-
-	_cairo_output_stream_printf (surface->output,
-				     "   /FontFamily %s\n",
-				     pdf_str);
-	free (pdf_str);
+	}
     }
 
     _cairo_output_stream_printf (surface->output,
@@ -5555,13 +5560,14 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 	char *pdf_str;
 
 	status = _utf8_to_pdf_string (subset.family_name_utf8, &pdf_str);
-	if (unlikely (status))
+	if (likely (status == CAIRO_INT_STATUS_SUCCESS)) {
+	    _cairo_output_stream_printf (surface->output,
+					 "   /FontFamily %s\n",
+					 pdf_str);
+	    free (pdf_str);
+	} else if (status != CAIRO_INT_STATUS_INVALID_STRING) {
 	    return status;
-
-	_cairo_output_stream_printf (surface->output,
-				     "   /FontFamily %s\n",
-				     pdf_str);
-	free (pdf_str);
+	}
     }
 
     _cairo_output_stream_printf (surface->output,
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 74bfb9e..bf05fbd 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -1281,8 +1281,12 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	utf16_len = 0;
 	if (utf8 && *utf8) {
 	    status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &utf16_len);
-	    if (unlikely (status))
+	    if (status == CAIRO_STATUS_INVALID_STRING) {
+		utf16 = NULL;
+		utf16_len = 0;
+	    } else if (unlikely (status)) {
 		goto CLEANUP_HASH;
+	    }
 	}
 
 	if (utf16_len == 1) {


More information about the cairo-commit mailing list