[cairo-commit] cairo/src cairo.c,1.30,1.31 cairo.h,1.36,1.37 cairo_ft_font.c,1.12,1.13 cairo_gstate.c,1.35,1.36 cairoint.h,1.45,1.46

Carl Worth commit at pdx.freedesktop.org
Mon Dec 15 18:26:54 PST 2003


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory pdx:/tmp/cvs-serv23908/src

Modified Files:
	cairo.c cairo.h cairo_ft_font.c cairo_gstate.c cairoint.h 
Log Message:

        * src/cairo_gstate.c (_cairo_gstate_text_extents):
        (_cairo_gstate_glyph_extents): Need to divide out the scale factor
        to return user-space extents.
        (_cairo_gstate_glyph_extents): Don't transform glyph locations as
        they're not relevant to extents.

        * src/cairo_ft_font.c (_cairo_ft_font_font_extents): Clean up
        implementation.
        (_cairo_ft_font_glyph_extents): Initial implementation. Thanks to
        John Ellson <ellson at research.att.com> for most of the work on this
        function.
        (_cairo_ft_font_show_text): Clean to use num_glyphs not nglyphs.

        * src/cairo.h:
        * src/cairo.c (cairo_text_extents):
        (cairo_glyph_extents): Re-enable cairo_text/glyph_extents.


Index: cairo.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** cairo.c	11 Dec 2003 19:12:59 -0000	1.30
--- cairo.c	16 Dec 2003 02:26:51 -0000	1.31
***************
*** 708,712 ****
  
  
- /* XXX: NYI
  void
  cairo_text_extents (cairo_t                *cr,
--- 708,711 ----
***************
*** 732,736 ****
  					      extents);
  }
- */
  
  void
--- 731,734 ----

Index: cairo.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** cairo.h	12 Dec 2003 19:44:16 -0000	1.36
--- cairo.h	16 Dec 2003 02:26:51 -0000	1.37
***************
*** 408,414 ****
  cairo_set_font (cairo_t *ct, cairo_font_t *font);
  
- 
- /* XXX: NYI
- 
  extern void __external_linkage
  cairo_text_extents (cairo_t                *ct,
--- 408,411 ----
***************
*** 422,425 ****
--- 419,424 ----
  		     cairo_text_extents_t  *extents);
  
+ /* XXX: NYI
+ 
  extern void __external_linkage
  cairo_text_path  (cairo_t *ct, const unsigned char *utf8);

Index: cairo_ft_font.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_ft_font.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** cairo_ft_font.c	16 Dec 2003 02:02:03 -0000	1.12
--- cairo_ft_font.c	16 Dec 2003 02:26:51 -0000	1.13
***************
*** 355,372 ****
                               cairo_font_extents_t *extents)
  {
      double scale_x, scale_y;
!     cairo_ft_font_t *ft = (cairo_ft_font_t *)font;
!     cairo_status_t status = CAIRO_STATUS_SUCCESS;
  
      _cairo_matrix_compute_scale_factors (&font->matrix, &scale_x, &scale_y);
  
! #define FONT_UNIT_TO_DEV(x) ((double)(x) / (double)(ft->face->units_per_EM))
  
!     extents->ascent = FONT_UNIT_TO_DEV(ft->face->ascender) * scale_y;
!     extents->descent = FONT_UNIT_TO_DEV(ft->face->descender) * scale_y;
!     extents->height = FONT_UNIT_TO_DEV(ft->face->height) * scale_y;
!     extents->max_x_advance = FONT_UNIT_TO_DEV(ft->face->max_advance_width) * scale_x;
!     extents->max_y_advance = FONT_UNIT_TO_DEV(ft->face->max_advance_height) * scale_y;
!     return status;
  }
  
--- 355,372 ----
                               cairo_font_extents_t *extents)
  {
+     FT_Face face;
      double scale_x, scale_y;
!     face = ((cairo_ft_font_t *)font)->face;
!     double upm = face->units_per_EM;
  
      _cairo_matrix_compute_scale_factors (&font->matrix, &scale_x, &scale_y);
  
!     extents->ascent =        face->ascender / upm * scale_y;
!     extents->descent =       face->descender / upm * scale_y;
!     extents->height =        face->height / upm * scale_y;
!     extents->max_x_advance = face->max_advance_width / upm * scale_x;
!     extents->max_y_advance = face->max_advance_height / upm * scale_y;
  
!     return CAIRO_STATUS_SUCCESS;
  }
  
***************
*** 377,394 ****
  			      cairo_text_extents_t *extents)
  {
!     cairo_ft_font_t *ft;
!     cairo_status_t status = CAIRO_STATUS_SUCCESS;
  
!     ft = (cairo_ft_font_t *)font;
  
!     /* FIXME: lift code from xft to do this */
  
!     return status;
  }
  
  static cairo_status_t 
  _cairo_ft_font_text_extents (cairo_font_t        *font,
                               const unsigned char *utf8,
! 			      cairo_text_extents_t *extents)
  {
      cairo_glyph_t *glyphs;
--- 377,454 ----
  			      cairo_text_extents_t *extents)
  {
!     int i;
!     cairo_point_double_t origin;
!     cairo_point_double_t glyph_min, glyph_max;
!     cairo_point_double_t total_min, total_max;
!     FT_Error error;
!     FT_Face face = ((cairo_ft_font_t *)font)->face;
!     FT_GlyphSlot glyph = face->glyph;
!     FT_Glyph_Metrics *metrics = &glyph->metrics;
  
!     if (num_glyphs == 0)
!     {
! 	extents->left_side_bearing = 0.0;
! 	extents->right_side_bearing = 0.0;
! 	extents->ascent = 0.0;
! 	extents->descent = 0.0;
! 	extents->x_advance = 0.0;
! 	extents->y_advance = 0.0;
  
! 	return CAIRO_STATUS_SUCCESS;
!     }
  
!     origin.x = glyphs[0].x;
!     origin.y = glyphs[0].y;
! 
!     _install_font_matrix (&font->matrix, face);
! 
!     for (i = 0; i < num_glyphs; i++)
!     {
! 	error = FT_Load_Glyph (face, glyphs[i].index, FT_LOAD_DEFAULT);
! 	/* XXX: What to do in this error case? */
! 	if (error)
! 	    continue;
! 
! 	/* XXX: Need to add code here to check the font's FcPattern
!            for FC_VERTICAL_LAYOUT and if set get vertBearingX/Y
!            instead. This will require that
!            cairo_ft_font_create_for_ft_face accept an
!            FcPattern. */
! 	glyph_min.x = glyphs[i].x + DOUBLE_FROM_26_6 (metrics->horiBearingX);
! 	glyph_min.y = glyphs[i].y - DOUBLE_FROM_26_6 (metrics->horiBearingY);
! 	glyph_max.x = glyph_min.x + DOUBLE_FROM_26_6 (metrics->width);
! 	glyph_max.y = glyph_min.y + DOUBLE_FROM_26_6 (metrics->height);
!     
! 	if (i==0) {
! 	    total_min = glyph_min;
! 	    total_max = glyph_max;
! 	} else {
! 	    if (glyph_min.x < total_min.x)
! 		total_min.x = glyph_min.x;
! 	    if (glyph_min.y < total_min.y)
! 		total_min.y = glyph_min.y;
! 
! 	    if (glyph_max.x > total_max.x)
! 		total_max.x = glyph_max.x;
! 	    if (glyph_max.y > total_max.y)
! 		total_max.y = glyph_max.y;
! 	}
!     }
! 
!     extents->left_side_bearing  = total_min.x - origin.x;
!     extents->right_side_bearing = total_max.x - origin.x;
!     extents->ascent             = total_min.y - origin.y;
!     extents->descent            = total_max.y - origin.y;
!     extents->x_advance = glyphs[i-1].x + DOUBLE_FROM_26_6 (metrics->horiAdvance) - origin.x;
!     extents->y_advance = glyphs[i-1].y + 0 - origin.y;
! 
!     return CAIRO_STATUS_SUCCESS;
  }
  
+ 
  static cairo_status_t 
  _cairo_ft_font_text_extents (cairo_font_t        *font,
                               const unsigned char *utf8,
! 			     cairo_text_extents_t *extents)
  {
      cairo_glyph_t *glyphs;
***************
*** 516,527 ****
  {
      cairo_glyph_t *glyphs;
!     size_t nglyphs;
      
!     if (_utf8_to_glyphs (font, utf8, x0, y0, &glyphs, &nglyphs))
      {
          cairo_status_t res;
          res = _cairo_ft_font_show_glyphs (font, operator, 
                                            source, surface,
!                                           glyphs, nglyphs);      
          free (glyphs);
          return res;
--- 576,587 ----
  {
      cairo_glyph_t *glyphs;
!     int num_glyphs;
      
!     if (_utf8_to_glyphs (font, utf8, x0, y0, &glyphs, &num_glyphs))
      {
          cairo_status_t res;
          res = _cairo_ft_font_show_glyphs (font, operator, 
                                            source, surface,
!                                           glyphs, num_glyphs);      
          free (glyphs);
          return res;
***************
*** 543,547 ****
      ft = (cairo_ft_font_t *)font;
      
!     /* FIXME: lift code from xft to do this */
      
      return status;
--- 603,607 ----
      ft = (cairo_ft_font_t *)font;
      
!     /* XXX: lift code from xft to do this */
      
      return status;

Index: cairo_gstate.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo_gstate.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** cairo_gstate.c	15 Dec 2003 22:20:56 -0000	1.35
--- cairo_gstate.c	16 Dec 2003 02:26:51 -0000	1.36
***************
*** 1601,1604 ****
--- 1601,1605 ----
  
      cairo_matrix_copy (&gstate->font->matrix, &saved_font_matrix);    
+ 
      return status;
  }
***************
*** 1623,1629 ****
      cairo_matrix_t saved_font_matrix;
      cairo_status_t status;
  
      cairo_matrix_copy (&saved_font_matrix, &gstate->font->matrix);
!     cairo_matrix_multiply (&gstate->font->matrix, &gstate->ctm, &gstate->font->matrix);
  
      status = _cairo_font_text_extents (gstate->font,
--- 1624,1632 ----
      cairo_matrix_t saved_font_matrix;
      cairo_status_t status;
+     double scale_x, scale_y;
  
      cairo_matrix_copy (&saved_font_matrix, &gstate->font->matrix);
!     _cairo_matrix_compute_scale_factors (&gstate->ctm, &scale_x, &scale_y);
!     cairo_matrix_scale (&gstate->font->matrix, scale_x, scale_y);
  
      status = _cairo_font_text_extents (gstate->font,
***************
*** 1631,1634 ****
--- 1634,1645 ----
  
      cairo_matrix_copy (&gstate->font->matrix, &saved_font_matrix);
+ 
+     extents->x_advance /= scale_x;
+     extents->y_advance /= scale_y;
+     extents->left_side_bearing /= scale_x;
+     extents->right_side_bearing /= scale_x;
+     extents->ascent /= scale_y;
+     extents->descent /= scale_y;
+ 
      return status;
  }
***************
*** 1641,1670 ****
  {
      cairo_status_t status;
-     int i;
-     cairo_glyph_t *transformed_glyphs = NULL;
      cairo_matrix_t saved_font_matrix;
! 
!     transformed_glyphs = malloc (num_glyphs * sizeof(cairo_glyph_t));
!     if (transformed_glyphs == NULL)
! 	return CAIRO_STATUS_NO_MEMORY;
!     
!     for (i = 0; i < num_glyphs; ++i)
!     {
! 	transformed_glyphs[i] = glyphs[i];
! 	cairo_matrix_transform_point (&gstate->ctm, 
! 				      &(transformed_glyphs[i].x), 
! 				      &(transformed_glyphs[i].y));
!     }
  
      cairo_matrix_copy (&saved_font_matrix, &gstate->font->matrix);
!     cairo_matrix_multiply (&gstate->font->matrix, &gstate->ctm, &gstate->font->matrix);
  
      status = _cairo_font_glyph_extents (gstate->font,
! 					transformed_glyphs, num_glyphs,
  					extents);
  
      cairo_matrix_copy (&gstate->font->matrix, &saved_font_matrix);
  
!     free (transformed_glyphs);
      return status;
  }
--- 1652,1675 ----
  {
      cairo_status_t status;
      cairo_matrix_t saved_font_matrix;
!     double scale_x, scale_y;
  
      cairo_matrix_copy (&saved_font_matrix, &gstate->font->matrix);
!     _cairo_matrix_compute_scale_factors (&gstate->ctm, &scale_x, &scale_y);
!     cairo_matrix_scale (&gstate->font->matrix, scale_x, scale_y);
  
      status = _cairo_font_glyph_extents (gstate->font,
! 					glyphs, num_glyphs,
  					extents);
  
      cairo_matrix_copy (&gstate->font->matrix, &saved_font_matrix);
  
!     extents->x_advance /= scale_x;
!     extents->y_advance /= scale_y;
!     extents->left_side_bearing /= scale_x;
!     extents->right_side_bearing /= scale_x;
!     extents->ascent /= scale_y;
!     extents->descent /= scale_y;
! 
      return status;
  }
***************
*** 1724,1732 ****
  	cairo_matrix_transform_point (&gstate->ctm, &x, &y);
      }
!     
      status = setup_text_rendering_context(gstate, &user_to_source);
      if (status)
  	return status;
!     
      cairo_matrix_copy (&saved_font_matrix, &gstate->font->matrix);
      cairo_matrix_multiply (&gstate->font->matrix, &gstate->ctm, &gstate->font->matrix);
--- 1729,1737 ----
  	cairo_matrix_transform_point (&gstate->ctm, &x, &y);
      }
! 
      status = setup_text_rendering_context(gstate, &user_to_source);
      if (status)
  	return status;
! 
      cairo_matrix_copy (&saved_font_matrix, &gstate->font->matrix);
      cairo_matrix_multiply (&gstate->font->matrix, &gstate->ctm, &gstate->font->matrix);

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** cairoint.h	15 Dec 2003 22:20:56 -0000	1.45
--- cairoint.h	16 Dec 2003 02:26:51 -0000	1.46
***************
*** 1135,1138 ****
--- 1135,1141 ----
  _cairo_matrix_compute_eigen_values (cairo_matrix_t *matrix, double *lambda1, double *lambda2);
  
+ extern cairo_status_t __internal_linkage
+ _cairo_matrix_compute_scale_factors (cairo_matrix_t *matrix, double *sx, double *sy);
+ 
  /* cairo_traps.c */
  extern void __internal_linkage





More information about the cairo-commit mailing list