Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
cairo-font.c File Reference
#include "cairoint.h"

Go to the source code of this file.

Classes

struct  _cairo_scaled_font_map

Defines

#define CAIRO_SCALED_FONT_MAX_HOLDOVERS   24
#define FNV_32_PRIME   ((uint32_t)0x01000193)
#define FNV1_32_INIT   ((uint32_t)0x811c9dc5)

Typedefs

typedef struct
_cairo_scaled_font_map 
cairo_scaled_font_map_t

Functions

void _cairo_font_face_init (cairo_font_face_t *font_face, const cairo_font_face_backend_t *backend)
cairo_font_face_t * cairo_font_face_reference (cairo_font_face_t *font_face)
 cairo_font_face_reference: : a #cairo_font_face_t, (may be NULL in which case this function does nothing).
void cairo_font_face_destroy (cairo_font_face_t *font_face)
 cairo_font_face_destroy: : a #cairo_font_face_t
cairo_status_t cairo_font_face_status (cairo_font_face_t *font_face)
 cairo_font_face_status: : a #cairo_font_face_t
voidcairo_font_face_get_user_data (cairo_font_face_t *font_face, const cairo_user_data_key_t *key)
 cairo_font_face_get_user_data: : a #cairo_font_face_t : the address of the cairo_user_data_key_t the user data was attached to
cairo_status_t cairo_font_face_set_user_data (cairo_font_face_t *font_face, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy)
 cairo_font_face_set_user_data: : a #cairo_font_face_t : the address of a cairo_user_data_key_t to attach the user data to : the user data to attach to the font face : a cairo_destroy_func_t which will be called when the font face is destroyed or when new user data is attached using the same key.
static int _cairo_toy_font_face_keys_equal (void *key_a, void *key_b)
 CAIRO_MUTEX_DECLARE (cairo_toy_font_face_hash_table_mutex)
static cairo_hash_table_t * _cairo_toy_font_face_hash_table_lock (void)
static void _cairo_toy_font_face_hash_table_unlock (void)
static void _cairo_toy_font_face_init_key (cairo_toy_font_face_t *key, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight)
 _cairo_toy_font_face_init_key:
static cairo_status_t _cairo_toy_font_face_init (cairo_toy_font_face_t *font_face, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight)
static void _cairo_toy_font_face_fini (cairo_toy_font_face_t *font_face)
cairo_font_face_t * _cairo_toy_font_face_create (const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight)
 _cairo_toy_font_face_create: : a font family name, encoded in UTF-8 : the slant for the font : the weight for the font
static void _cairo_toy_font_face_destroy (void *abstract_face)
static cairo_status_t _cairo_toy_font_face_scaled_font_create (void *abstract_font_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options, cairo_scaled_font_t **scaled_font)
void _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, cairo_status_t status)
 _cairo_scaled_font_set_error: : a scaled_font : a status value indicating an error, (eg.
cairo_status_t cairo_scaled_font_status (cairo_scaled_font_t *scaled_font)
 cairo_scaled_font_status: : a #cairo_scaled_font_t
 CAIRO_MUTEX_DECLARE (cairo_scaled_font_map_mutex)
static int _cairo_scaled_font_keys_equal (void *abstract_key_a, void *abstract_key_b)
static cairo_scaled_font_map_t_cairo_scaled_font_map_lock (void)
static void _cairo_scaled_font_map_unlock (void)
static void _cairo_scaled_font_map_destroy (void)
static uint32_t _hash_bytes_fnv (unsigned char *buffer, int len, uint32_t hval)
static void _cairo_scaled_font_init_key (cairo_scaled_font_t *scaled_font, cairo_font_face_t *font_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options)
void _cairo_scaled_font_init (cairo_scaled_font_t *scaled_font, cairo_font_face_t *font_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options, const cairo_scaled_font_backend_t *backend)
void _cairo_scaled_font_fini (cairo_scaled_font_t *scaled_font)
cairo_scaled_font_t * cairo_scaled_font_create (cairo_font_face_t *font_face, const cairo_matrix_t *font_matrix, const cairo_matrix_t *ctm, const cairo_font_options_t *options)
 cairo_scaled_font_create: : a #cairo_font_face_t : font space to user space transformation matrix for the font.
cairo_scaled_font_t * cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font)
 cairo_scaled_font_reference: : a #cairo_scaled_font_t, (may be NULL in which case this function does nothing)
void cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font)
 cairo_scaled_font_destroy: : a #cairo_scaled_font_t
cairo_status_t _cairo_scaled_font_text_to_glyphs (cairo_scaled_font_t *scaled_font, const char *utf8, cairo_glyph_t **glyphs, int *num_glyphs)
cairo_status_t _cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_text_extents_t *extents)
cairo_status_t _cairo_scaled_font_glyph_bbox (cairo_scaled_font_t *scaled_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_box_t *bbox)
cairo_status_t _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font, cairo_operator_t operator, cairo_pattern_t *pattern, cairo_surface_t *surface, int source_x, int source_y, int dest_x, int dest_y, unsigned int width, unsigned int height, cairo_glyph_t *glyphs, int num_glyphs)
cairo_status_t _cairo_scaled_font_glyph_path (cairo_scaled_font_t *scaled_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_path_fixed_t *path)
cairo_status_t _cairo_scaled_font_get_glyph_cache_key (cairo_scaled_font_t *scaled_font, cairo_glyph_cache_key_t *key)
cairo_status_t _cairo_scaled_font_font_extents (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents)
void _cairo_unscaled_font_init (cairo_unscaled_font_t *unscaled_font, const cairo_unscaled_font_backend_t *backend)
cairo_unscaled_font_t_cairo_unscaled_font_reference (cairo_unscaled_font_t *unscaled_font)
void _cairo_unscaled_font_destroy (cairo_unscaled_font_t *unscaled_font)
void cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents)
 cairo_scaled_font_extents: : a #cairo_scaled_font_t : a cairo_font_extents_t which to store the retrieved extents.
void cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_text_extents_t *extents)
 cairo_font_glyph_extents: : a #cairo_scaled_font_t : an array of glyph IDs with X and Y offsets.
unsigned long _cairo_glyph_cache_hash (void *cache, void *key)
int _cairo_glyph_cache_keys_equal (void *cache, void *k1, void *k2)
static cairo_status_t _image_glyph_cache_create_entry (void *cache, void *key, void **return_value)
static void _image_glyph_cache_destroy_entry (void *cache, void *value)
static void _image_glyph_cache_destroy_cache (void *cache)
 CAIRO_MUTEX_DECLARE (_global_image_glyph_cache_mutex)
void _cairo_lock_global_image_glyph_cache (void)
void _cairo_unlock_global_image_glyph_cache (void)
cairo_cache_t_cairo_get_global_image_glyph_cache (void)
void _cairo_font_reset_static_data (void)

Variables

static const
cairo_font_face_backend_t 
_cairo_toy_font_face_backend
const cairo_font_face_t _cairo_font_face_nil
static cairo_hash_table_t * cairo_toy_font_face_hash_table = NULL
static const cairo_scaled_font_t _cairo_scaled_font_nil
static cairo_scaled_font_map_tcairo_scaled_font_map = NULL
static const cairo_cache_backend_t cairo_image_cache_backend
static cairo_cache_t_global_image_glyph_cache = NULL

Class Documentation

struct _cairo_scaled_font_map

Definition at line 501 of file cairo-font.c.

Collaboration diagram for _cairo_scaled_font_map:
Class Members
cairo_hash_table_t * hash_table
cairo_scaled_font_t * holdovers
int num_holdovers

Define Documentation

Definition at line 499 of file cairo-font.c.

#define FNV1_32_INIT   ((uint32_t)0x811c9dc5)

Definition at line 586 of file cairo-font.c.

#define FNV_32_PRIME   ((uint32_t)0x01000193)

Definition at line 585 of file cairo-font.c.


Typedef Documentation


Function Documentation

void _cairo_font_face_init ( cairo_font_face_t *  font_face,
const cairo_font_face_backend_t *  backend 
)

Definition at line 58 of file cairo-font.c.

{
    font_face->status = CAIRO_STATUS_SUCCESS;
    font_face->ref_count = 1;
    font_face->backend = backend;

    _cairo_user_data_array_init (&font_face->user_data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1279 of file cairo-font.c.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long _cairo_glyph_cache_hash ( void cache,
void key 
)

Definition at line 1162 of file cairo-font.c.

{
    cairo_glyph_cache_key_t *in;
    in = (cairo_glyph_cache_key_t *) key;
    return 
       ((unsigned long) in->unscaled) 
       ^ ((unsigned long) in->scale.xx) 
       ^ ((unsigned long) in->scale.yx) 
       ^ ((unsigned long) in->scale.xy) 
       ^ ((unsigned long) in->scale.yy)
        ^ (in->flags * 1451) /* 1451 is just an abitrary prime */
       ^ in->index;
}
int _cairo_glyph_cache_keys_equal ( void cache,
void k1,
void k2 
)

Definition at line 1177 of file cairo-font.c.

{
    cairo_glyph_cache_key_t *a, *b;
    a = (cairo_glyph_cache_key_t *) k1;
    b = (cairo_glyph_cache_key_t *) k2;
    return (a->index == b->index)
       && (a->unscaled == b->unscaled)
       && (a->flags == b->flags)
       && (a->scale.xx == b->scale.xx)
       && (a->scale.yx == b->scale.yx)
       && (a->scale.xy == b->scale.xy)
       && (a->scale.yy == b->scale.yy);
}

Definition at line 1263 of file cairo-font.c.

Here is the caller graph for this function:

void _cairo_scaled_font_fini ( cairo_scaled_font_t *  scaled_font)

Definition at line 671 of file cairo-font.c.

{
    if (scaled_font->font_face)
       cairo_font_face_destroy (scaled_font->font_face);

    scaled_font->backend->fini (scaled_font);
}

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_font_extents ( cairo_scaled_font_t *  scaled_font,
cairo_font_extents_t extents 
)

Definition at line 973 of file cairo-font.c.

{
    if (scaled_font->status)
       return scaled_font->status;

    return scaled_font->backend->font_extents (scaled_font, extents);
}

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_get_glyph_cache_key ( cairo_scaled_font_t *  scaled_font,
cairo_glyph_cache_key_t key 
)

Definition at line 961 of file cairo-font.c.

{
    if (scaled_font->status)
       return scaled_font->status;

    scaled_font->backend->get_glyph_cache_key (scaled_font, key);

    return CAIRO_STATUS_SUCCESS;
}

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_glyph_bbox ( cairo_scaled_font_t *  scaled_font,
cairo_glyph_t glyphs,
int  num_glyphs,
cairo_box_t bbox 
)

Definition at line 895 of file cairo-font.c.

{
    if (scaled_font->status)
       return scaled_font->status;

    return scaled_font->backend->glyph_bbox (scaled_font, glyphs, num_glyphs, bbox);
}

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_glyph_extents ( cairo_scaled_font_t *  scaled_font,
cairo_glyph_t glyphs,
int  num_glyphs,
cairo_text_extents_t extents 
)

Definition at line 882 of file cairo-font.c.

{
    if (scaled_font->status)
       return scaled_font->status;

    return scaled_font->backend->glyph_extents (scaled_font, glyphs, num_glyphs, extents);
}

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_glyph_path ( cairo_scaled_font_t *  scaled_font,
cairo_glyph_t glyphs,
int  num_glyphs,
cairo_path_fixed_t *  path 
)

Definition at line 949 of file cairo-font.c.

{
    if (scaled_font->status)
       return scaled_font->status;

    return scaled_font->backend->glyph_path (scaled_font, glyphs, num_glyphs, path);
}

Here is the caller graph for this function:

void _cairo_scaled_font_init ( cairo_scaled_font_t *  scaled_font,
cairo_font_face_t *  font_face,
const cairo_matrix_t font_matrix,
const cairo_matrix_t ctm,
const cairo_font_options_t *  options,
const cairo_scaled_font_backend_t *  backend 
)

Definition at line 649 of file cairo-font.c.

{
    scaled_font->ref_count = 1;

    _cairo_scaled_font_init_key (scaled_font, font_face,
                             font_matrix, ctm, options);

    cairo_font_face_reference (font_face);

    cairo_matrix_multiply (&scaled_font->scale,
                        &scaled_font->font_matrix,
                        &scaled_font->ctm);

    scaled_font->backend = backend;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_scaled_font_init_key ( cairo_scaled_font_t *  scaled_font,
cairo_font_face_t *  font_face,
const cairo_matrix_t font_matrix,
const cairo_matrix_t ctm,
const cairo_font_options_t *  options 
) [static]

Definition at line 602 of file cairo-font.c.

{
    uint32_t hash = FNV1_32_INIT;

    scaled_font->status = CAIRO_STATUS_SUCCESS;
    scaled_font->font_face = font_face;
    scaled_font->font_matrix = *font_matrix;
    scaled_font->ctm = *ctm;
    scaled_font->options = *options;

    /* We do a bytewise hash on the font matrices, ignoring the
     * translation values. */
    hash = _hash_bytes_fnv ((unsigned char *)(&scaled_font->font_matrix.xx),
                         sizeof(double) * 4,
                         hash);
    hash = _hash_bytes_fnv ((unsigned char *)(&scaled_font->ctm.xx),
                         sizeof(double) * 4,
                         hash);

    hash ^= (unsigned long) scaled_font->font_face;

    hash ^= cairo_font_options_hash (&scaled_font->options);

    scaled_font->hash_entry.hash = hash;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_bool_t _cairo_scaled_font_keys_equal ( void abstract_key_a,
void abstract_key_b 
) [static]

Definition at line 633 of file cairo-font.c.

{
    cairo_scaled_font_t *key_a = abstract_key_a;
    cairo_scaled_font_t *key_b = abstract_key_b;

    return (key_a->font_face == key_b->font_face &&
           memcmp ((unsigned char *)(&key_a->font_matrix.xx),
                  (unsigned char *)(&key_b->font_matrix.xx),
                  sizeof(double) * 4) == 0 &&
           memcmp ((unsigned char *)(&key_a->ctm.xx),
                  (unsigned char *)(&key_b->ctm.xx),
                  sizeof(double) * 4) == 0 &&
           cairo_font_options_equal (&key_a->options, &key_b->options));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_scaled_font_map_destroy ( void  ) [static]

Definition at line 550 of file cairo-font.c.

{
    int i;
    cairo_scaled_font_map_t *font_map = cairo_scaled_font_map;
    cairo_scaled_font_t *scaled_font;

    if (font_map == NULL)
       return;

    CAIRO_MUTEX_UNLOCK (cairo_scaled_font_map_mutex);

    for (i = 0; i < font_map->num_holdovers; i++) {
       scaled_font = font_map->holdovers[i];
       /* We should only get here through the reset_static_data path
        * and there had better not be any active references at that
        * point. */
       assert (scaled_font->ref_count == 0);
       _cairo_hash_table_remove (font_map->hash_table,
                              &scaled_font->hash_entry);
       _cairo_scaled_font_fini (scaled_font);
       free (scaled_font);
    }

    _cairo_hash_table_destroy (font_map->hash_table);

    free (cairo_scaled_font_map);
    cairo_scaled_font_map = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 515 of file cairo-font.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_scaled_font_map_unlock ( void  ) [static]

Definition at line 544 of file cairo-font.c.

Here is the caller graph for this function:

void _cairo_scaled_font_set_error ( cairo_scaled_font_t *  scaled_font,
cairo_status_t  status 
)

_cairo_scaled_font_set_error: : a scaled_font : a status value indicating an error, (eg.

not CAIRO_STATUS_SUCCESS)

Sets scaled_font->status to and calls _cairo_error;

All assignments of an error status to scaled_font->status should happen through _cairo_scaled_font_set_error() or else _cairo_error() should be called immediately after the assignment.

The purpose of this function is to allow the user to set a breakpoint in _cairo_error() to generate a stack trace for when the user causes cairo to detect an error.

Definition at line 450 of file cairo-font.c.

{
    /* Don't overwrite an existing error. This preserves the first
     * error, which is the most significant. It also avoids attempting
     * to write to read-only data (eg. from a nil scaled_font). */
    if (scaled_font->status == CAIRO_STATUS_SUCCESS)
       scaled_font->status = status;

    _cairo_error (status);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_show_glyphs ( cairo_scaled_font_t *  scaled_font,
cairo_operator_t  operator,
cairo_pattern_t *  pattern,
cairo_surface_t *  surface,
int  source_x,
int  source_y,
int  dest_x,
int  dest_y,
unsigned int  width,
unsigned int  height,
cairo_glyph_t glyphs,
int  num_glyphs 
)

Definition at line 907 of file cairo-font.c.

{
    cairo_status_t status;

    /* These operators aren't interpreted the same way by the backends;
     * they are implemented in terms of other operators in cairo-gstate.c
     */
    assert (operator != CAIRO_OPERATOR_SOURCE && operator != CAIRO_OPERATOR_CLEAR);
    
    if (scaled_font->status)
       return scaled_font->status;

    status = _cairo_surface_show_glyphs (scaled_font, operator, pattern, 
                                    surface,
                                    source_x, source_y,
                                    dest_x, dest_y,
                                    width, height,
                                    glyphs, num_glyphs);
    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
       return status;

    /* Surface display routine either does not exist or failed. */
    return scaled_font->backend->show_glyphs (scaled_font, operator, pattern, 
                                         surface,
                                         source_x, source_y,
                                         dest_x, dest_y,
                                         width, height,
                                         glyphs, num_glyphs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

cairo_status_t _cairo_scaled_font_text_to_glyphs ( cairo_scaled_font_t *  scaled_font,
const char *  utf8,
cairo_glyph_t **  glyphs,
int num_glyphs 
)

Definition at line 870 of file cairo-font.c.

{
    if (scaled_font->status)
       return scaled_font->status;

    return scaled_font->backend->text_to_glyphs (scaled_font, utf8, glyphs, num_glyphs);
}

Here is the caller graph for this function:

cairo_font_face_t* _cairo_toy_font_face_create ( const char *  family,
cairo_font_slant_t  slant,
cairo_font_weight_t  weight 
)

_cairo_toy_font_face_create: : a font family name, encoded in UTF-8 : the slant for the font : the weight for the font

Creates a font face from a triplet of family, slant, and weight. These font faces are used in implementation of the the #cairo_t "toy" font API.

Return value: a newly created #cairo_font_face_t, destroy with cairo_font_face_destroy()

Definition at line 328 of file cairo-font.c.

{
    cairo_status_t status;
    cairo_toy_font_face_t key, *font_face;
    cairo_hash_table_t *hash_table;

    hash_table = _cairo_toy_font_face_hash_table_lock ();
    if (hash_table == NULL)
       goto UNWIND;

    _cairo_toy_font_face_init_key (&key, family, slant, weight);
    
    /* Return existing font_face if it exists in the hash table. */
    if (_cairo_hash_table_lookup (hash_table,
                              &key.base.hash_entry,
                              (cairo_hash_entry_t **) &font_face))
    {
       _cairo_toy_font_face_hash_table_unlock ();
       return cairo_font_face_reference (&font_face->base);
    }

    /* Otherwise create it and insert into hash table. */
    font_face = malloc (sizeof (cairo_toy_font_face_t));
    if (font_face == NULL)
       goto UNWIND_HASH_TABLE_LOCK;

    status = _cairo_toy_font_face_init (font_face, family, slant, weight);
    if (status)
       goto UNWIND_FONT_FACE_MALLOC;

    status = _cairo_hash_table_insert (hash_table, &font_face->base.hash_entry);
    if (status)
       goto UNWIND_FONT_FACE_INIT;

    _cairo_toy_font_face_hash_table_unlock ();

    return &font_face->base;

 UNWIND_FONT_FACE_INIT:
 UNWIND_FONT_FACE_MALLOC:
    free (font_face);
 UNWIND_HASH_TABLE_LOCK:
    _cairo_toy_font_face_hash_table_unlock ();
 UNWIND:
    return (cairo_font_face_t*) &_cairo_font_face_nil;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_toy_font_face_destroy ( void abstract_face) [static]

Definition at line 378 of file cairo-font.c.

{
    cairo_toy_font_face_t *font_face = abstract_face;
    cairo_hash_table_t *hash_table;

    if (font_face == NULL)
       return;

    hash_table = _cairo_toy_font_face_hash_table_lock ();
    /* All created objects must have been mapped in the hash table. */
    assert (hash_table != NULL);

    _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry);
    
    _cairo_toy_font_face_hash_table_unlock ();
    
    _cairo_toy_font_face_fini (font_face);
}

Here is the call graph for this function:

static void _cairo_toy_font_face_fini ( cairo_toy_font_face_t font_face) [static]

Definition at line 294 of file cairo-font.c.

{
    /* We assert here that we own font_face->family before casting
     * away the const qualifer. */
    assert (font_face->owns_family);
    free ((char*) font_face->family);
}

Here is the caller graph for this function:

static cairo_hash_table_t* _cairo_toy_font_face_hash_table_lock ( void  ) [static]

Definition at line 236 of file cairo-font.c.

Here is the caller graph for this function:

static cairo_status_t _cairo_toy_font_face_init ( cairo_toy_font_face_t font_face,
const char *  family,
cairo_font_slant_t  slant,
cairo_font_weight_t  weight 
) [static]

Definition at line 273 of file cairo-font.c.

{
    char *family_copy;

    family_copy = strdup (family);
    if (family_copy == NULL)
       return CAIRO_STATUS_NO_MEMORY;

    _cairo_toy_font_face_init_key (font_face, family_copy,
                                  slant, weight);
    font_face->owns_family = TRUE;

    _cairo_font_face_init (&font_face->base, &_cairo_toy_font_face_backend);

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _cairo_toy_font_face_init_key ( cairo_toy_font_face_t key,
const char *  family,
cairo_font_slant_t  slant,
cairo_font_weight_t  weight 
) [static]

_cairo_toy_font_face_init_key:

Initialize those portions of cairo_toy_font_face_t needed to use it as a hash table key, including the hash code buried away in font_face->base.hash_entry. No memory allocation is performed here so that no fini call is needed. We do this to make it easier to use an automatic cairo_toy_font_face_t variable as a key.

Definition at line 251 of file cairo-font.c.

{
    unsigned long hash;

    key->family = family;
    key->owns_family = FALSE;

    key->slant = slant;
    key->weight = weight;

    /* 1607 and 1451 are just a couple of arbitrary primes. */
    hash = _cairo_hash_string (family);
    hash += ((unsigned long) slant) * 1607;
    hash += ((unsigned long) weight) * 1451;
    
    key->base.hash_entry.hash = hash;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int _cairo_toy_font_face_keys_equal ( void key_a,
void key_b 
) [static]

Definition at line 303 of file cairo-font.c.

{
    cairo_toy_font_face_t *face_a = key_a;
    cairo_toy_font_face_t *face_b = key_b;

    return (strcmp (face_a->family, face_b->family) == 0 &&
           face_a->slant == face_b->slant &&
           face_a->weight == face_b->weight);
}

Here is the caller graph for this function:

static cairo_status_t _cairo_toy_font_face_scaled_font_create ( void abstract_font_face,
const cairo_matrix_t font_matrix,
const cairo_matrix_t ctm,
const cairo_font_options_t *  options,
cairo_scaled_font_t **  scaled_font 
) [static]

Definition at line 398 of file cairo-font.c.

{
    cairo_toy_font_face_t *font_face = abstract_font_face;
    const cairo_scaled_font_backend_t * backend = CAIRO_SCALED_FONT_BACKEND_DEFAULT;

    return backend->create_toy (font_face,
                            font_matrix, ctm, options, scaled_font);
}

Definition at line 1269 of file cairo-font.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1002 of file cairo-font.c.

{    
    if (unscaled_font == NULL)
       return;

    if (--(unscaled_font->ref_count) > 0)
       return;

    unscaled_font->backend->destroy (unscaled_font);

    free (unscaled_font);
}

Here is the caller graph for this function:

void _cairo_unscaled_font_init ( cairo_unscaled_font_t unscaled_font,
const cairo_unscaled_font_backend_t *  backend 
)

Definition at line 983 of file cairo-font.c.

{
    unscaled_font->ref_count = 1;
    unscaled_font->backend = backend;
}

Here is the caller graph for this function:

Definition at line 991 of file cairo-font.c.

{
    if (unscaled_font == NULL)
       return NULL;

    unscaled_font->ref_count++;

    return unscaled_font;
}

Here is the caller graph for this function:

static uint32_t _hash_bytes_fnv ( unsigned char *  buffer,
int  len,
uint32_t  hval 
) [static]

Definition at line 589 of file cairo-font.c.

{
    while (len--) {
       hval *= FNV_32_PRIME;
       hval ^= *buffer++;
    }

    return hval;
}

Here is the caller graph for this function:

static cairo_status_t _image_glyph_cache_create_entry ( void cache,
void key,
void **  return_value 
) [static]

Definition at line 1195 of file cairo-font.c.

{
    cairo_glyph_cache_key_t *k = (cairo_glyph_cache_key_t *) key;
    cairo_image_glyph_cache_entry_t *im;
    cairo_status_t status;

    im = calloc (1, sizeof (cairo_image_glyph_cache_entry_t));
    if (im == NULL)
       return CAIRO_STATUS_NO_MEMORY;

    im->key = *k;    
    status = im->key.unscaled->backend->create_glyph (im->key.unscaled,
                                                im);

    if (status != CAIRO_STATUS_SUCCESS) {
       free (im);
       return status;
    }

    _cairo_unscaled_font_reference (im->key.unscaled);

    im->key.base.memory = 
       sizeof (cairo_image_glyph_cache_entry_t) 
       + (im->image ? 
          sizeof (cairo_image_surface_t) 
          + 28 * sizeof (int) /* rough guess at size of pixman image structure */
          + (im->image->height * im->image->stride) : 0);

    *return_value = im;

    return CAIRO_STATUS_SUCCESS;
}

Here is the call graph for this function:

static void _image_glyph_cache_destroy_cache ( void cache) [static]

Definition at line 1244 of file cairo-font.c.

{
    free (cache);
}
static void _image_glyph_cache_destroy_entry ( void cache,
void value 
) [static]

Definition at line 1232 of file cairo-font.c.

Here is the call graph for this function:

void cairo_font_face_destroy ( cairo_font_face_t *  font_face)

cairo_font_face_destroy: : a #cairo_font_face_t

Decreases the reference count on by one. If the result is zero, then and all associated resources are freed. See cairo_font_face_reference().

Definition at line 106 of file cairo-font.c.

{
    if (font_face == NULL)
       return;

    if (font_face->ref_count == (unsigned int)-1)
       return;

    assert (font_face->ref_count > 0);

    if (--(font_face->ref_count) > 0)
       return;

    font_face->backend->destroy (font_face);

    /* We allow resurrection to deal with some memory management for the
     * FreeType backend where cairo_ft_font_face_t and cairo_ft_unscaled_font_t
     * need to effectively mutually reference each other
     */
    if (font_face->ref_count > 0)
       return;

    _cairo_user_data_array_fini (&font_face->user_data);

    free (font_face);
}

Here is the call graph for this function:

void* cairo_font_face_get_user_data ( cairo_font_face_t *  font_face,
const cairo_user_data_key_t key 
)

cairo_font_face_get_user_data: : a #cairo_font_face_t : the address of the cairo_user_data_key_t the user data was attached to

Return user data previously attached to using the specified key. If no user data has been attached with the given key this function returns NULL.

Return value: the user data previously attached or NULL.

Definition at line 162 of file cairo-font.c.

{
    return _cairo_user_data_array_get_data (&font_face->user_data,
                                       key);
}

Here is the call graph for this function:

cairo_font_face_t* cairo_font_face_reference ( cairo_font_face_t *  font_face)

cairo_font_face_reference: : a #cairo_font_face_t, (may be NULL in which case this function does nothing).

Increases the reference count on by one. This prevents from being destroyed until a matching call to cairo_font_face_destroy() is made.

Return value: the referenced #cairo_font_face_t.

Definition at line 80 of file cairo-font.c.

{
    if (font_face == NULL)
       return NULL;

    if (font_face->ref_count == (unsigned int)-1)
       return font_face;

    /* We would normally assert (font_face->ref_count >0) here but we
     * can't get away with that due to the zombie case as documented
     * in _cairo_ft_font_face_destroy. */

    font_face->ref_count++;

    return font_face;
}
cairo_status_t cairo_font_face_set_user_data ( cairo_font_face_t *  font_face,
const cairo_user_data_key_t key,
void user_data,
cairo_destroy_func_t  destroy 
)

cairo_font_face_set_user_data: : a #cairo_font_face_t : the address of a cairo_user_data_key_t to attach the user data to : the user data to attach to the font face : a cairo_destroy_func_t which will be called when the font face is destroyed or when new user data is attached using the same key.

Attach user data to . To remove user data from a font face, call this function with the key that was used to set it and NULL for .

Return value: CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could not be allocated for the user data.

Definition at line 186 of file cairo-font.c.

{
    if (font_face->ref_count == -1)
       return CAIRO_STATUS_NO_MEMORY;
    
    return _cairo_user_data_array_set_data (&font_face->user_data,
                                       key, user_data, destroy);
}

Here is the call graph for this function:

cairo_status_t cairo_font_face_status ( cairo_font_face_t *  font_face)

cairo_font_face_status: : a #cairo_font_face_t

Checks whether an error has previously occurred for this font face

Return value: CAIRO_STATUS_SUCCESS or another error such as CAIRO_STATUS_NO_MEMORY.

Definition at line 144 of file cairo-font.c.

{
    return font_face->status;
}
cairo_scaled_font_t* cairo_scaled_font_create ( cairo_font_face_t *  font_face,
const cairo_matrix_t font_matrix,
const cairo_matrix_t ctm,
const cairo_font_options_t *  options 
)

cairo_scaled_font_create: : a #cairo_font_face_t : font space to user space transformation matrix for the 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_set_font_matrix(). : user to device transformation matrix with which the font will be used. : options to use when getting metrics for the font and rendering with it.

Creates a #cairo_scaled_font_t object from a font face and matrices that describe the size of the font and the environment in which it will be used.

Return value: a newly created #cairo_scaled_font_t. Destroy with cairo_scaled_font_destroy()

Definition at line 700 of file cairo-font.c.

{
    cairo_status_t status;
    cairo_scaled_font_map_t *font_map;
    cairo_scaled_font_t key, *scaled_font = NULL;

    font_map = _cairo_scaled_font_map_lock ();
    if (font_map == NULL)
       goto UNWIND;
    
    _cairo_scaled_font_init_key (&key, font_face,
                             font_matrix, ctm, options);

    /* Return existing scaled_font if it exists in the hash table. */
    if (_cairo_hash_table_lookup (font_map->hash_table, &key.hash_entry,
                              (cairo_hash_entry_t**) &scaled_font))
    {
       _cairo_scaled_font_map_unlock ();
       return cairo_scaled_font_reference (scaled_font);
    }

    /* Otherwise create it and insert it into the hash table. */
    status = font_face->backend->scaled_font_create (font_face, font_matrix,
                                               ctm, options, &scaled_font);
    if (status)
       goto UNWIND_FONT_MAP_LOCK;

    status = _cairo_hash_table_insert (font_map->hash_table,
                                   &scaled_font->hash_entry);
    if (status)
       goto UNWIND_SCALED_FONT_CREATE;

    _cairo_scaled_font_map_unlock ();

    return scaled_font;

UNWIND_SCALED_FONT_CREATE:
    /* We can't call _cairo_scaled_font_destroy here since it expects
     * that the font has already been successfully inserted into the
     * hash table. */
    _cairo_scaled_font_fini (scaled_font);
    free (scaled_font);
UNWIND_FONT_MAP_LOCK:
    _cairo_scaled_font_map_unlock ();
UNWIND:
    return NULL;
}

Here is the call graph for this function:

void cairo_scaled_font_destroy ( cairo_scaled_font_t *  scaled_font)

cairo_scaled_font_destroy: : a #cairo_scaled_font_t

Decreases the reference count on by one. If the result is zero, then and all associated resources are freed. See cairo_scaled_font_reference().

Definition at line 818 of file cairo-font.c.

{
    cairo_scaled_font_map_t *font_map;

    if (scaled_font == NULL)
       return;

    if (scaled_font->ref_count == (unsigned int)-1)
       return;

    /* cairo_scaled_font_t objects are cached and shared between
     * threads. This works because these objects are immutable. Except
     * that the reference count is mutable, so we have to do locking
     * around any modification of the reference count. */
    font_map = _cairo_scaled_font_map_lock ();
    {
       assert (font_map != NULL);

       assert (scaled_font->ref_count > 0);

       if (--(scaled_font->ref_count) == 0)
       {
           /* Rather than immediately destroying this object, we put it into
            * the font_map->holdovers array in case it will get used again
            * soon. To make room for it, we do actually destroy the
            * least-recently-used holdover.
            */
           if (font_map->num_holdovers == CAIRO_SCALED_FONT_MAX_HOLDOVERS) {
              cairo_scaled_font_t *lru;

              lru = font_map->holdovers[0];
              assert (lru->ref_count == 0);
       
              _cairo_hash_table_remove (font_map->hash_table, &lru->hash_entry);

              _cairo_scaled_font_fini (lru);
              free (lru);
       
              font_map->num_holdovers--;
              memmove (&font_map->holdovers[0],
                      &font_map->holdovers[1],
                      font_map->num_holdovers * sizeof (cairo_scaled_font_t*));
           }

           font_map->holdovers[font_map->num_holdovers] = scaled_font;
           font_map->num_holdovers++;
       }
    }
    _cairo_scaled_font_map_unlock ();
}

Here is the call graph for this function:

void cairo_scaled_font_extents ( cairo_scaled_font_t *  scaled_font,
cairo_font_extents_t extents 
)

cairo_scaled_font_extents: : a #cairo_scaled_font_t : a cairo_font_extents_t which to store the retrieved extents.

Gets the metrics for a #cairo_scaled_font_t.

Definition at line 1025 of file cairo-font.c.

{
    cairo_int_status_t status;
    double  font_scale_x, font_scale_y;
    
    if (scaled_font->status)
       return;

    status = _cairo_scaled_font_font_extents (scaled_font, extents);
    if (status) {
       _cairo_scaled_font_set_error (scaled_font, status);
       return;
    }
    
    _cairo_matrix_compute_scale_factors (&scaled_font->font_matrix,
                                    &font_scale_x, &font_scale_y,
                                    /* XXX */ 1);
    
    /* 
     * The font responded in unscaled units, scale by the font
     * matrix scale factors to get to user space
     */
    
    extents->ascent *= font_scale_y;
    extents->descent *= font_scale_y;
    extents->height *= font_scale_y;
    extents->max_x_advance *= font_scale_x;
    extents->max_y_advance *= font_scale_y;
}

Here is the call graph for this function:

void cairo_scaled_font_glyph_extents ( cairo_scaled_font_t *  scaled_font,
cairo_glyph_t glyphs,
int  num_glyphs,
cairo_text_extents_t extents 
)

cairo_font_glyph_extents: : a #cairo_scaled_font_t : an array of glyph IDs with X and Y offsets.

: the number of glyphs in the array : a cairo_text_extents_t which to store the retrieved extents.

cairo_font_glyph_extents() gets the overall metrics for a string of glyphs. The X and Y offsets in are taken from an origin of 0,0.

Definition at line 1067 of file cairo-font.c.

{
    cairo_status_t status = CAIRO_STATUS_SUCCESS;
    cairo_glyph_t origin_glyph;
    cairo_text_extents_t origin_extents;
    int i;
    double min_x = 0.0, min_y = 0.0, max_x = 0.0, max_y = 0.0;
    double x_pos = 0.0, y_pos = 0.0;
    int set = 0;

    if (scaled_font->status)
       return;

    if (!num_glyphs)
    {
       extents->x_bearing = 0.0;
       extents->y_bearing = 0.0;
       extents->width = 0.0;
       extents->height = 0.0;
       extents->x_advance = 0.0;
       extents->y_advance = 0.0;
       
       return;
    }

    for (i = 0; i < num_glyphs; i++)
    {
       double        x, y;
       double        wm, hm;
       
       origin_glyph = glyphs[i];
       origin_glyph.x = 0.0;
       origin_glyph.y = 0.0;
       status = _cairo_scaled_font_glyph_extents (scaled_font,
                                             &origin_glyph, 1,
                                             &origin_extents);
       
       /*
        * Transform font space metrics into user space metrics
        * by running the corners through the font matrix and
        * expanding the bounding box as necessary
        */
       x = origin_extents.x_bearing;
       y = origin_extents.y_bearing;
       cairo_matrix_transform_point (&scaled_font->font_matrix,
                                  &x, &y);

       for (hm = 0.0; hm <= 1.0; hm += 1.0)
           for (wm = 0.0; wm <= 1.0; wm += 1.0)
           {
              x = origin_extents.x_bearing + origin_extents.width * wm;
              y = origin_extents.y_bearing + origin_extents.height * hm;
              cairo_matrix_transform_point (&scaled_font->font_matrix,
                                         &x, &y);
              x += glyphs[i].x;
              y += glyphs[i].y;
              if (!set)
              {
                  min_x = max_x = x;
                  min_y = max_y = y;
                  set = 1;
              }
              else
              {
                  if (x < min_x) min_x = x;
                  if (x > max_x) max_x = x;
                  if (y < min_y) min_y = y;
                  if (y > max_y) max_y = y;
              }
           }

       x = origin_extents.x_advance;
       y = origin_extents.y_advance;
       cairo_matrix_transform_point (&scaled_font->font_matrix,
                                  &x, &y);
       x_pos = glyphs[i].x + x;
       y_pos = glyphs[i].y + y;
    }

    extents->x_bearing = min_x - glyphs[0].x;
    extents->y_bearing = min_y - glyphs[0].y;
    extents->width = max_x - min_x;
    extents->height = max_y - min_y;
    extents->x_advance = x_pos - glyphs[0].x;
    extents->y_advance = y_pos - glyphs[0].y;
}

Here is the call graph for this function:

cairo_scaled_font_t* cairo_scaled_font_reference ( cairo_scaled_font_t *  scaled_font)

cairo_scaled_font_reference: : a #cairo_scaled_font_t, (may be NULL in which case this function does nothing)

Increases the reference count on by one. This prevents from being destroyed until a matching call to cairo_scaled_font_destroy() is made.

Returns: the referenced #cairo_scaled_font_t

Definition at line 763 of file cairo-font.c.

{
    cairo_scaled_font_map_t *font_map;

    if (scaled_font == NULL)
       return NULL;

    if (scaled_font->ref_count == (unsigned int)-1)
       return scaled_font;

    /* We would normally assert (scaled_font->ref_count > 0) here, but
     * we are using ref_count == 0 as a legitimate case for the
     * holdovers array. See below. */

    /* cairo_scaled_font_t objects are cached and shared between
     * threads. This works because these objects are immutable. Except
     * that the reference count is mutable, so we have to do locking
     * around any modification of the reference count. */
    font_map = _cairo_scaled_font_map_lock ();
    {
       /* If the original reference count is 0, then this font must have
        * been found in font_map->holdovers, (which means this caching is
        * actually working). So now we remove it from the holdovers
        * array. */
       if (scaled_font->ref_count == 0) {
           int i;

           for (i = 0; i < font_map->num_holdovers; i++)
              if (font_map->holdovers[i] == scaled_font)
                  break;
           assert (i < font_map->num_holdovers);

           font_map->num_holdovers--;
           memmove (&font_map->holdovers[i],
                   &font_map->holdovers[i+1],
                   (font_map->num_holdovers - i) * sizeof (cairo_scaled_font_t*));
       }

       scaled_font->ref_count++;

    }
    _cairo_scaled_font_map_unlock ();

    return scaled_font;
}

Here is the call graph for this function:

cairo_status_t cairo_scaled_font_status ( cairo_scaled_font_t *  scaled_font)

cairo_scaled_font_status: : a #cairo_scaled_font_t

Checks whether an error has previously occurred for this scaled_font.

Return value: CAIRO_STATUS_SUCCESS or another error such as CAIRO_STATUS_NO_MEMORY.

Definition at line 473 of file cairo-font.c.

{
    return scaled_font->status;
}

Variable Documentation

const cairo_font_face_t _cairo_font_face_nil
Initial value:

Definition at line 49 of file cairo-font.c.

const cairo_scaled_font_t _cairo_scaled_font_nil [static]
Initial value:
 {
    { 0 },                  
    CAIRO_STATUS_NO_MEMORY, 
    -1,                            
    NULL,                   
    { 1., 0., 0., 1., 0, 0},       
    { 1., 0., 0., 1., 0, 0},       
    { 1., 0., 0., 1., 0, 0},       
    { CAIRO_ANTIALIAS_DEFAULT,     
      CAIRO_SUBPIXEL_ORDER_DEFAULT,
      CAIRO_HINT_STYLE_DEFAULT,
      CAIRO_HINT_METRICS_DEFAULT} ,
    CAIRO_SCALED_FONT_BACKEND_DEFAULT,
}

Definition at line 418 of file cairo-font.c.

static const cairo_font_face_backend_t _cairo_toy_font_face_backend [static]

Definition at line 1260 of file cairo-font.c.

Definition at line 507 of file cairo-font.c.

cairo_hash_table_t* cairo_toy_font_face_hash_table = NULL [static]

Definition at line 212 of file cairo-font.c.