diff options
author | Owen Taylor <otaylor@redhat.com> | 2005-04-07 13:29:32 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@redhat.com> | 2005-04-07 13:29:32 +0000 |
commit | ac6f15e2450e4e08d833355e626df0358d81c2ec (patch) | |
tree | 60139fcd0fc144d11a34223cf0734460faf60cf0 | |
parent | 62212867d4228d5834ea16858a8569765977bdd9 (diff) |
src/cairo.[ch] src/cairoint.h src/cairo-gstate.c docs/public/cairo-sections.txt: cairo_select_font() => cairo_select_font_face() cairo_scale_font() => cairo_set_font_size() cairo_transform_font() => cairo_set_font_matrix() Add cairo_get_font_matrix(). Make cairo_set_font_face() not reset the font matrix. Default the font matrix to SCALE(10). Document cairo_select_font_face().
test/text-cache-crash.c (draw) test/text-rotate.c (draw): Use cairo_set_font_size().
src/cairo-font.c src/cairo.h: Fix up some parameter names for docs.
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | doc/public/cairo-sections.txt | 10 | ||||
-rw-r--r-- | doc/public/tmpl/cairo-font.sgml | 12 | ||||
-rw-r--r-- | doc/public/tmpl/cairo.sgml | 18 | ||||
-rw-r--r-- | src/cairo-font.c | 8 | ||||
-rw-r--r-- | src/cairo-gstate.c | 50 | ||||
-rw-r--r-- | src/cairo.c | 73 | ||||
-rw-r--r-- | src/cairo.h | 32 | ||||
-rw-r--r-- | src/cairoint.h | 30 | ||||
-rw-r--r-- | test/coverage.c | 2 | ||||
-rw-r--r-- | test/text-cache-crash.c | 6 | ||||
-rw-r--r-- | test/text-rotate.c | 2 |
12 files changed, 163 insertions, 97 deletions
@@ -1,5 +1,22 @@ 2005-04-07 Owen Taylor <otaylor@redhat.com> + * src/cairo.[ch] src/cairoint.h src/cairo-gstate.c + docs/public/cairo-sections.txt: + cairo_select_font() => cairo_select_font_face() + cairo_scale_font() => cairo_set_font_size() + cairo_transform_font() => cairo_set_font_matrix() + Add cairo_get_font_matrix(). Make cairo_set_font_face() + not reset the font matrix. Default the font matrix + to SCALE(10). Document cairo_select_font_face(). + + * test/coverage.c (draw) test/text-cache-crash.c (draw) + test/text-rotate.c (draw): Use cairo_set_font_size(). + + * src/cairo-font.c src/cairo.h: Fix up some parameter + names for docs. + +2005-04-07 Owen Taylor <otaylor@redhat.com> + * src/cairo-win32-font.c: Fix various compilation errors. 2005-04-07 Carl Worth <cworth@cworth.org> diff --git a/doc/public/cairo-sections.txt b/doc/public/cairo-sections.txt index 0b7c9398..94ba4f8a 100644 --- a/doc/public/cairo-sections.txt +++ b/doc/public/cairo-sections.txt @@ -215,9 +215,10 @@ cairo_clip cairo_glyph_t cairo_font_slant_t cairo_font_weight_t -cairo_select_font -cairo_scale_font -cairo_transform_font +cairo_select_font_face +cairo_set_font_size +cairo_set_font_matrix +cairo_get_font_matrix cairo_show_text cairo_show_glyphs cairo_get_font_face @@ -275,6 +276,9 @@ cairo_current_path cairo_current_path_flat cairo_current_font cairo_current_font_extents +cairo_scale_font +cairo_select_font +cairo_transform_font cairo_get_font_extents cairo_get_status cairo_get_status_string diff --git a/doc/public/tmpl/cairo-font.sgml b/doc/public/tmpl/cairo-font.sgml index 1c87ae34..cdf0ed28 100644 --- a/doc/public/tmpl/cairo-font.sgml +++ b/doc/public/tmpl/cairo-font.sgml @@ -61,6 +61,8 @@ Font Handling </para> +@scaled_font: +<!-- # Unused Parameters # --> @font: @@ -69,6 +71,8 @@ Font Handling </para> +@scaled_font: +<!-- # Unused Parameters # --> @font: @@ -88,9 +92,11 @@ Font Handling </para> -@font: +@scaled_font: @extents: @Returns: +<!-- # Unused Parameters # --> +@font: <!-- ##### STRUCT cairo_text_extents_t ##### --> @@ -110,9 +116,11 @@ Font Handling </para> -@font: +@scaled_font: @glyphs: @num_glyphs: @extents: +<!-- # Unused Parameters # --> +@font: diff --git a/doc/public/tmpl/cairo.sgml b/doc/public/tmpl/cairo.sgml index 016ae5d3..6fb842ae 100644 --- a/doc/public/tmpl/cairo.sgml +++ b/doc/public/tmpl/cairo.sgml @@ -621,7 +621,7 @@ Drawing contexts. @CAIRO_FONT_WEIGHT_NORMAL: @CAIRO_FONT_WEIGHT_BOLD: -<!-- ##### FUNCTION cairo_select_font ##### --> +<!-- ##### FUNCTION cairo_select_font_face ##### --> <para> </para> @@ -632,16 +632,16 @@ Drawing contexts. @weight: -<!-- ##### FUNCTION cairo_scale_font ##### --> +<!-- ##### FUNCTION cairo_set_font_size ##### --> <para> </para> @cr: -@scale: +@size: -<!-- ##### FUNCTION cairo_transform_font ##### --> +<!-- ##### FUNCTION cairo_set_font_matrix ##### --> <para> </para> @@ -650,6 +650,16 @@ Drawing contexts. @matrix: +<!-- ##### FUNCTION cairo_get_font_matrix ##### --> +<para> + +</para> + +@cr: +@matrix: +@Returns: + + <!-- ##### FUNCTION cairo_show_text ##### --> <para> diff --git a/src/cairo-font.c b/src/cairo-font.c index fc658a8f..d1743b13 100644 --- a/src/cairo-font.c +++ b/src/cairo-font.c @@ -636,7 +636,7 @@ static const cairo_cache_backend_t _cairo_inner_font_cache_backend = { * font. In the simplest case of a N point font, this matrix is * just a scale by N, but it can also be used to shear the font * or stretch it unequally along the two axes. See - * cairo_transform_font(). + * cairo_set_font_matrix(). * @ctm: user to device transformation matrix with which the font will * be used. * @@ -821,7 +821,7 @@ cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font) /** * cairo_scaled_font_destroy: - * @font: a #cairo_scaled_font_t + * @scaled_font: a #cairo_scaled_font_t * * Decreases the reference count on @font by one. If the result * is zero, then @font and all associated resources are freed. @@ -856,7 +856,7 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font) /** * cairo_scaled_font_extents: - * @font: a #cairo_scaled_font_t + * @scaled_font: a #cairo_scaled_font_t * @extents: a #cairo_font_extents_t which to store the retrieved extents. * * Gets the metrics for a #cairo_scaled_font_t. @@ -896,7 +896,7 @@ cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, /** * cairo_font_glyph_extents: - * @font: a #cairo_scaled_font_t + * @scaled_font: a #cairo_scaled_font_t * @glyphs: an array of glyph IDs with X and Y offsets. * @num_glyphs: the number of glyphs in the @glyphs array * @extents: a #cairo_text_extents_t which to store the retrieved extents. diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c index a8abb93d..d35f643c 100644 --- a/src/cairo-gstate.c +++ b/src/cairo-gstate.c @@ -97,6 +97,10 @@ _cairo_gstate_init (cairo_gstate_t *gstate) gstate->scaled_font = NULL; gstate->font_face = NULL; + cairo_matrix_init_scale (&gstate->font_matrix, + CAIRO_GSTATE_DEFAULT_FONT_SIZE, + CAIRO_GSTATE_DEFAULT_FONT_SIZE); + gstate->surface = NULL; gstate->clip.region = NULL; @@ -2118,10 +2122,10 @@ _cairo_gstate_unset_font (cairo_gstate_t *gstate) } cairo_status_t -_cairo_gstate_select_font (cairo_gstate_t *gstate, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) +_cairo_gstate_select_font_face (cairo_gstate_t *gstate, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) { cairo_font_face_t *font_face; @@ -2136,32 +2140,32 @@ _cairo_gstate_select_font (cairo_gstate_t *gstate, } cairo_status_t -_cairo_gstate_scale_font (cairo_gstate_t *gstate, - double scale) +_cairo_gstate_set_font_size (cairo_gstate_t *gstate, + double size) { _cairo_gstate_unset_font (gstate); - cairo_matrix_scale (&gstate->font_matrix, scale, scale); + cairo_matrix_init_scale (&gstate->font_matrix, size, size); return CAIRO_STATUS_SUCCESS; } cairo_status_t -_cairo_gstate_transform_font (cairo_gstate_t *gstate, - cairo_matrix_t *matrix) +_cairo_gstate_set_font_matrix (cairo_gstate_t *gstate, + cairo_matrix_t *matrix) { - cairo_matrix_t tmp; - double a, b, c, d, tx, ty; - _cairo_gstate_unset_font (gstate); - cairo_matrix_get_affine (matrix, &a, &b, &c, &d, &tx, &ty); - cairo_matrix_init (&tmp, a, b, c, d, 0, 0); - cairo_matrix_multiply (&gstate->font_matrix, &gstate->font_matrix, &tmp); + gstate->font_matrix = *matrix; return CAIRO_STATUS_SUCCESS; } +cairo_matrix_t +_cairo_gstate_get_font_matrix (cairo_gstate_t *gstate) +{ + return gstate->font_matrix; +} cairo_status_t _cairo_gstate_get_font_face (cairo_gstate_t *gstate, @@ -2178,22 +2182,6 @@ _cairo_gstate_get_font_face (cairo_gstate_t *gstate, return CAIRO_STATUS_SUCCESS; } -void -_cairo_gstate_set_font_transform (cairo_gstate_t *gstate, - cairo_matrix_t *matrix) -{ - _cairo_gstate_unset_font (gstate); - - cairo_matrix_copy (&gstate->font_matrix, matrix); -} - -void -_cairo_gstate_get_font_transform (cairo_gstate_t *gstate, - cairo_matrix_t *matrix) -{ - cairo_matrix_copy (matrix, &gstate->font_matrix); -} - /* * Like everything else in this file, fonts involve Too Many Coordinate Spaces; * it is easy to get confused about what's going on. diff --git a/src/cairo.c b/src/cairo.c index 631d646f..f59a6276 100644 --- a/src/cairo.c +++ b/src/cairo.c @@ -1516,17 +1516,32 @@ cairo_reset_clip (cairo_t *cr) } DEPRECATE (cairo_init_clip, cairo_reset_clip); +/** + * cairo_select_font_face: + * @cr: a #cairo_t + * @family: a font family name, encoded in UTF-8 + * @slant: the slant for the font + * @weight: the weight for the font + * + * Selects a family and style of font from a simplified description as + * a family name, slant and weight. This function is meant to be used + * only for applications with simple font needs: Cairo doesn't provide + * for operations such as listing all available fonts on the system, + * and it is expected that most applications will need to use a more + * comprehensive font handling and text layout library in addition to + * Cairo. + **/ void -cairo_select_font (cairo_t *cr, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight) +cairo_select_font_face (cairo_t *cr, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight) { CAIRO_CHECK_SANITY (cr); if (cr->status) return; - cr->status = _cairo_gstate_select_font (cr->gstate, family, slant, weight); + cr->status = _cairo_gstate_select_font_face (cr->gstate, family, slant, weight); CAIRO_CHECK_SANITY (cr); } @@ -1599,46 +1614,64 @@ cairo_set_font_face (cairo_t *cr, } /** - * cairo_scale_font: + * cairo_set_font_size: * @cr: a #cairo_t - * @scale: a scale factor + * @size: the new font size, in user space units * - * Scale the current font by the factor @scale. This function is - * designed to work well with cairo_select_font(), and will usually be - * called immediately afterwards to set the desired font size. + * Sets the current font matrix to a scale by a factor of @size, replacing + * any font matrix previously set with cairo_set_font_size() or + * cairo_set_font_matrix(). This results in a font size of @size user space + * units. (More precisely, this matrix will result in the font's + * em-square being a @size by @size square in user space.) **/ void -cairo_scale_font (cairo_t *cr, double scale) +cairo_set_font_size (cairo_t *cr, double size) { CAIRO_CHECK_SANITY (cr); if (cr->status) return; - cr->status = _cairo_gstate_scale_font (cr->gstate, scale); + cr->status = _cairo_gstate_set_font_size (cr->gstate, size); CAIRO_CHECK_SANITY (cr); } /** - * cairo_transform_font: + * cairo_set_font_matrix * @cr: a #cairo_t * @matrix: a #cairo_matrix_t describing a transform to be applied to * the current font. - * - * Transform the current font according to @matrix. The transformation - * is applied in addition to any previous transformations applied by - * either cairo_transform_font() or cairo_scale_font(). * - * This function is designed to work well with cairo_select_font(). + * Sets the current font matrix to @matrix. The font matrix gives a + * transformation from the design space of the font (in this space, + * the em-square is 1 unit by 1 unit) to user space. Normally, a + * simple scale is used (see cairo_set_font_size()), but a more + * complex font matrix can be used to shear the font + * or stretch it unequally along the two axes **/ void -cairo_transform_font (cairo_t *cr, cairo_matrix_t *matrix) +cairo_set_font_matrix (cairo_t *cr, cairo_matrix_t *matrix) { CAIRO_CHECK_SANITY (cr); if (cr->status) return; - cr->status = _cairo_gstate_transform_font (cr->gstate, matrix); + cr->status = _cairo_gstate_set_font_matrix (cr->gstate, matrix); + CAIRO_CHECK_SANITY (cr); +} + +/** + * cairo_get_font_matrix + * @cr: a #cairo_t + * + * Gets the current font matrix. See cairo_set_font_matrix() + * + * Return value: the current font matrix + **/ +cairo_matrix_t +cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix) +{ CAIRO_CHECK_SANITY (cr); + return _cairo_gstate_get_font_matrix (cr->gstate); } /** diff --git a/src/cairo.h b/src/cairo.h index c28a8c0b..e0040e13 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -566,16 +566,20 @@ typedef enum cairo_font_weight { font object inside the the cairo_t. */ void -cairo_select_font (cairo_t *cr, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight); +cairo_select_font_face (cairo_t *cr, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight); void -cairo_scale_font (cairo_t *cr, double scale); +cairo_set_font_size (cairo_t *cr, double size); void -cairo_transform_font (cairo_t *cr, cairo_matrix_t *matrix); +cairo_set_font_matrix (cairo_t *cr, + cairo_matrix_t *matrix); + +cairo_matrix_t +cairo_get_font_matrix (cairo_t *cr, cairo_matrix_t *matrix); void cairo_show_text (cairo_t *cr, const char *utf8); @@ -627,17 +631,17 @@ cairo_scaled_font_create (cairo_font_face_t *font_face, cairo_matrix_t *ctm); void -cairo_scaled_font_reference (cairo_scaled_font_t *font); +cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font); void -cairo_scaled_font_destroy (cairo_scaled_font_t *font); +cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font); cairo_status_t -cairo_scaled_font_extents (cairo_scaled_font_t *font, +cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents); void -cairo_scaled_font_glyph_extents (cairo_scaled_font_t *font, +cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_text_extents_t *extents); @@ -1108,6 +1112,9 @@ typedef cairo_status_t (*cairo_write_func_t) (void *closure, #define cairo_get_status cairo_get_status_DEPRECATED_BY_cairo_status #define cairo_get_status_string cairo_get_status_string_DEPRECATED_BY_cairo_status_string #define cairo_concat_matrix cairo_concat_matrix_DEPRECATED_BY_cairo_transform +#define cairo_scale_font cairo_scale_font_DEPRECATED_BY_cairo_set_font_size +#define cairo_select_font cairo_select_font_face_DEPRECATED_BY_cairo_select_font_face +#define cairo_transform_font cairo_transform_font_DEPRECATED_BY_cairo_set_font_matrix #define cairo_transform_point cairo_transform_point_DEPRECATED_BY_cairo_user_to_device #define cairo_transform_distance cairo_transform_distance_DEPRECATED_BY_cairo_user_to_device_distance #define cairo_inverse_transform_point cairo_inverse_transform_point_DEPRECATED_BY_cairo_device_to_user @@ -1124,7 +1131,6 @@ typedef cairo_status_t (*cairo_write_func_t) (void *closure, #define cairo_current_path_flat cairo_get_path_flat #define cairo_current_font cairo_get_font #define cairo_current_font_extents cairo_font_extents -#define cairo_get_font_extents cairo_font_extents #define cairo_current_operator cairo_get_operator #define cairo_current_rgb_color cairo_get_rgb_color #define cairo_current_alpha cairo_get_alpha @@ -1136,6 +1142,7 @@ typedef cairo_status_t (*cairo_write_func_t) (void *closure, #define cairo_current_line_join cairo_get_line_join #define cairo_current_miter_limit cairo_get_miter_limit #define cairo_current_target_surface cairo_get_target_surface +#define cairo_get_font_extents cairo_font_extents #define cairo_get_status cairo_status #define cairo_get_status_string cairo_status_string #define cairo_concat_matrix cairo_transform @@ -1144,7 +1151,10 @@ typedef cairo_status_t (*cairo_write_func_t) (void *closure, #define cairo_inverse_transform_point cairo_device_to_user #define cairo_inverse_transform_distance cairo_device_to_user_distance #define cairo_init_clip cairo_reset_clip +#define cairo_scale_font cairo_set_font_size +#define cairo_select_font cairo_select_font_face #define cairo_surface_create_for_image cairo_image_surface_create_for_data +#define cairo_transform_font cairo_set_font_matrix #define cairo_default_matrix cairo_identity_matrix #define cairo_matrix_set_affine cairo_matrix_init #define cairo_matrix_set_identity cairo_matrix_init_identity diff --git a/src/cairoint.h b/src/cairoint.h index 51d10309..3625acba 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -818,6 +818,7 @@ typedef struct _cairo_traps { #define CAIRO_GSTATE_LINE_CAP_DEFAULT CAIRO_LINE_CAP_BUTT #define CAIRO_GSTATE_LINE_JOIN_DEFAULT CAIRO_LINE_JOIN_MITER #define CAIRO_GSTATE_MITER_LIMIT_DEFAULT 10.0 +#define CAIRO_GSTATE_DEFAULT_FONT_SIZE 10.0 /* Need a name distinct from the cairo_clip function */ typedef struct _cairo_clip_rec { @@ -1111,34 +1112,29 @@ _cairo_gstate_show_surface (cairo_gstate_t *gstate, int height); cairo_private cairo_status_t -_cairo_gstate_select_font (cairo_gstate_t *gstate, - const char *family, - cairo_font_slant_t slant, - cairo_font_weight_t weight); +_cairo_gstate_select_font_face (cairo_gstate_t *gstate, + const char *family, + cairo_font_slant_t slant, + cairo_font_weight_t weight); cairo_private cairo_status_t -_cairo_gstate_scale_font (cairo_gstate_t *gstate, - double scale); +_cairo_gstate_set_font_size (cairo_gstate_t *gstate, + double size); +cairo_matrix_t +_cairo_gstate_get_font_matrix (cairo_gstate_t *gstate); + cairo_private cairo_status_t -_cairo_gstate_transform_font (cairo_gstate_t *gstate, - cairo_matrix_t *matrix); +_cairo_gstate_set_font_matrix (cairo_gstate_t *gstate, + cairo_matrix_t *matrix); cairo_private cairo_status_t _cairo_gstate_get_font_face (cairo_gstate_t *gstate, cairo_font_face_t **font_face); -cairo_private void -_cairo_gstate_set_font_transform (cairo_gstate_t *gstate, - cairo_matrix_t *matrix); - -cairo_private void -_cairo_gstate_get_font_transform (cairo_gstate_t *gstate, - cairo_matrix_t *matrix); - cairo_private cairo_status_t _cairo_gstate_get_font_extents (cairo_gstate_t *gstate, - cairo_font_extents_t *extents); + cairo_font_extents_t *extents); cairo_private cairo_status_t _cairo_gstate_set_font_face (cairo_gstate_t *gstate, diff --git a/test/coverage.c b/test/coverage.c index 1928e221..b60f5f5a 100644 --- a/test/coverage.c +++ b/test/coverage.c @@ -140,7 +140,7 @@ draw (cairo_t *cr, int width, int height) cairo_select_font (cr, fontname, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_scale_font (cr, fontsize); + cairo_set_font_size (cr, fontsize); for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) { for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) { diff --git a/test/text-cache-crash.c b/test/text-cache-crash.c index 68348cf6..188852e5 100644 --- a/test/text-cache-crash.c +++ b/test/text-cache-crash.c @@ -74,10 +74,10 @@ draw (cairo_t *cr, int width, int height) { /* Once there was a bug that choked when selecting the same font twice. */ cairo_select_font(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_scale_font(cr, 40.0); + cairo_set_font_size(cr, 40.0); cairo_select_font(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_scale_font(cr, 40.0); + cairo_set_font_size(cr, 40.0); cairo_move_to(cr, 10, 50); cairo_show_text(cr, "hello"); @@ -102,7 +102,7 @@ Aborted But in the meantime, I need "make check" not to destory work, so I'm commenting this test out for now. - cairo_scale_font (cr, 500); + cairo_set_font_size (cr, 500); cairo_show_text (cr, "hello"); */ diff --git a/test/text-rotate.c b/test/text-rotate.c index f7c28775..13b2d99d 100644 --- a/test/text-rotate.c +++ b/test/text-rotate.c @@ -81,7 +81,7 @@ draw (cairo_t *cr, int width, int height) cairo_select_font (cr, "Bitstream Vera Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_scale_font (cr, TEXT_SIZE); + cairo_set_font_size (cr, TEXT_SIZE); cairo_set_rgb_color (cr, 0,0,0); |