[cairo-commit] 2 commits - src/cairo-ps-surface.c src/cairo-scaled-font-subsets.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Fri Aug 5 08:00:10 PDT 2011


 src/cairo-ps-surface.c          |   41 ++++++++++++++++++++++++++++------------
 src/cairo-scaled-font-subsets.c |   33 ++++++++++++++++++++++++++++----
 2 files changed, 58 insertions(+), 16 deletions(-)

New commits:
commit 8a6d7643f09946b31d14e9bd57276747b025604a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Aug 6 00:24:55 2011 +0930

    subsets: use show_text_glyphs supplied utf8 to determine latin character
    
    PS files printed from PDF do not have a cmap in the subsetted
    fonts. If the unicode mapping has ben supplied by _show_text_glyphs we
    should use this instead of the reverse lookup to determine if the
    glyph is a latin chartacter.

diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 0e9880a..2ac2589 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -606,13 +606,38 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
 	int latin_character;
 
 	status = _cairo_sub_font_glyph_lookup_unicode (sub_font->scaled_font,
-						       scaled_font_glyph_index,
-						       &font_unicode,
-						       &font_utf8,
-						       &font_utf8_len);
+							   scaled_font_glyph_index,
+							   &font_unicode,
+							   &font_utf8,
+							   &font_utf8_len);
 	if (unlikely(status))
 	    return status;
 
+	/* If the supplied utf8 is a valid single character, use it
+	 * instead of the font lookup */
+	if (text_utf8 != NULL && text_utf8_len > 0) {
+	    uint32_t  *ucs4;
+	    int	ucs4_len;
+
+	    status = _cairo_utf8_to_ucs4 (text_utf8, text_utf8_len,
+					  &ucs4, &ucs4_len);
+	    if (status == CAIRO_STATUS_SUCCESS) {
+		if (ucs4_len == 1) {
+		    font_unicode = ucs4[0];
+		    free (font_utf8);
+		    font_utf8 = malloc (text_utf8_len + 1);
+		    if (font_utf8 == NULL) {
+			free (ucs4);
+			return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+		    }
+		    memcpy (font_utf8, text_utf8, text_utf8_len);
+		    font_utf8[font_utf8_len] = 0;
+		    font_utf8_len = text_utf8_len;
+		}
+		free (ucs4);
+	    }
+	}
+
 	/* If glyph is in the winansi encoding and font is not a user
 	 * font, put glyph in the latin subset. If glyph is .notdef
 	 * the latin subset is preferred but only if the latin subset
commit 1a4714b61f194d6b69855cfd48dd1a6aff4efda5
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Aug 6 00:23:14 2011 +0930

    ps: use show_text_glyphs
    
    to ensure that when the PS is converted to PDF the text can be extracted.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index b0c1db8..96f5bcf 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -3846,15 +3846,25 @@ _cairo_ps_surface_fill (void		*abstract_surface,
     return status;
 }
 
+static cairo_bool_t
+_cairo_ps_surface_has_show_text_glyphs	(void			*abstract_surface)
+{
+    return TRUE;
+}
+
 static cairo_int_status_t
-_cairo_ps_surface_show_glyphs (void		     *abstract_surface,
-			       cairo_operator_t	      op,
-			       const cairo_pattern_t *source,
-			       cairo_glyph_t         *glyphs,
-			       int		      num_glyphs,
-			       cairo_scaled_font_t   *scaled_font,
-			       const cairo_clip_t    *clip,
-			       int		     *remaining_glyphs)
+_cairo_ps_surface_show_text_glyphs (void		       *abstract_surface,
+				    cairo_operator_t	        op,
+				    const cairo_pattern_t      *source,
+				    const char                 *utf8,
+				    int                         utf8_len,
+				    cairo_glyph_t	       *glyphs,
+				    int			        num_glyphs,
+				    const cairo_text_cluster_t *clusters,
+				    int                         num_clusters,
+				    cairo_text_cluster_flags_t  cluster_flags,
+				    cairo_scaled_font_t	       *scaled_font,
+				    const cairo_clip_t	       *clip)
 {
     cairo_ps_surface_t *surface = abstract_surface;
     cairo_composite_rectangles_t extents;
@@ -3895,10 +3905,10 @@ _cairo_ps_surface_show_glyphs (void		     *abstract_surface,
 	return status;
 
     return _cairo_pdf_operators_show_text_glyphs (&surface->pdf_operators,
-						  NULL, 0,
+						  utf8, utf8_len,
 						  glyphs, num_glyphs,
-						  NULL, 0,
-						  FALSE,
+						  clusters, num_clusters,
+						  cluster_flags,
 						  scaled_font);
 }
 
@@ -4054,8 +4064,15 @@ static const cairo_surface_backend_t cairo_ps_surface_backend = {
     NULL, /* mask */
     _cairo_ps_surface_stroke,
     _cairo_ps_surface_fill,
-    _cairo_ps_surface_show_glyphs,
+    NULL, /* show_glyphs */
     NULL, /* snapshot */
+
+    NULL, /* is_compatible */
+    NULL, /* fill_stroke */
+    NULL, /* create_solid_pattern_surface */
+    NULL, /* can_repaint_solid_pattern_surface */
+    _cairo_ps_surface_has_show_text_glyphs,
+    _cairo_ps_surface_show_text_glyphs,
 };
 
 static const cairo_paginated_surface_backend_t cairo_ps_surface_paginated_backend = {


More information about the cairo-commit mailing list