Back to index

lightning-sunbird  0.9+nobinonly
cairo-font-options.c
Go to the documentation of this file.
00001 /* cairo - a vector graphics library with display and print output
00002  *
00003  * Copyright © 2005 Red Hat Inc.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it either under the terms of the GNU Lesser General Public
00007  * License version 2.1 as published by the Free Software Foundation
00008  * (the "LGPL") or, at your option, under the terms of the Mozilla
00009  * Public License Version 1.1 (the "MPL"). If you do not alter this
00010  * notice, a recipient may use your version of this file under either
00011  * the MPL or the LGPL.
00012  *
00013  * You should have received a copy of the LGPL along with this library
00014  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00016  * You should have received a copy of the MPL along with this library
00017  * in the file COPYING-MPL-1.1
00018  *
00019  * The contents of this file are subject to the Mozilla Public License
00020  * Version 1.1 (the "License"); you may not use this file except in
00021  * compliance with the License. You may obtain a copy of the License at
00022  * http://www.mozilla.org/MPL/
00023  *
00024  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
00025  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
00026  * the specific language governing rights and limitations.
00027  *
00028  * The Original Code is the cairo graphics library.
00029  *
00030  * The Initial Developer of the Original Code is University of Southern
00031  * California.
00032  *
00033  * Contributor(s):
00034  *      Owen Taylor <otaylor@redhat.com>
00035  */
00036 
00037 #include "cairoint.h"
00038 
00039 static const cairo_font_options_t cairo_font_options_nil = {
00040     CAIRO_ANTIALIAS_DEFAULT,
00041     CAIRO_SUBPIXEL_ORDER_DEFAULT,
00042     CAIRO_HINT_STYLE_DEFAULT,
00043     CAIRO_HINT_METRICS_DEFAULT
00044 };
00045 
00052 void
00053 _cairo_font_options_init_default (cairo_font_options_t *options)
00054 {
00055     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00056        return;
00057   
00058     options->antialias = CAIRO_ANTIALIAS_DEFAULT;
00059     options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
00060     options->hint_style = CAIRO_HINT_STYLE_DEFAULT;
00061     options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT;
00062 }
00063 
00076 cairo_font_options_t *
00077 cairo_font_options_create (void)
00078 {
00079     cairo_font_options_t *options = malloc (sizeof (cairo_font_options_t));
00080 
00081     if (!options)
00082        return (cairo_font_options_t *)&cairo_font_options_nil;
00083 
00084     _cairo_font_options_init_default (options);
00085 
00086     return options;
00087 }
00088 
00102 cairo_font_options_t *
00103 cairo_font_options_copy (const cairo_font_options_t *original)
00104 {
00105     cairo_font_options_t *options = malloc (sizeof (cairo_font_options_t));
00106 
00107     if (!options)
00108        return (cairo_font_options_t *)&cairo_font_options_nil;
00109 
00110     *options = *original;
00111 
00112     return options;
00113 }
00114 
00122 void 
00123 cairo_font_options_destroy (cairo_font_options_t *options)
00124 {
00125     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00126        return;
00127 
00128     free (options);
00129 }
00130 
00140 cairo_status_t
00141 cairo_font_options_status (cairo_font_options_t *options)
00142 {
00143     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00144        return CAIRO_STATUS_NO_MEMORY;
00145     else
00146        return CAIRO_STATUS_SUCCESS;
00147 }      
00148 
00159 void
00160 cairo_font_options_merge (cairo_font_options_t       *options,
00161                        const cairo_font_options_t *other)
00162 {
00163     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00164        return;
00165 
00166     if (other->antialias != CAIRO_ANTIALIAS_DEFAULT)
00167        options->antialias = other->antialias;
00168     if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
00169        options->subpixel_order = other->subpixel_order;
00170     if (other->hint_style != CAIRO_HINT_STYLE_DEFAULT)
00171        options->hint_style = other->hint_style;
00172     if (other->hint_metrics != CAIRO_HINT_METRICS_DEFAULT)
00173        options->hint_metrics = other->hint_metrics;
00174 }
00175 
00185 cairo_bool_t
00186 cairo_font_options_equal (const cairo_font_options_t *options,
00187                        const cairo_font_options_t *other)
00188 {
00189     return (options->antialias == other->antialias &&
00190            options->subpixel_order == other->subpixel_order &&
00191            options->hint_style == other->hint_style &&
00192            options->hint_metrics == other->hint_metrics);
00193 }
00194 
00207 unsigned long
00208 cairo_font_options_hash (const cairo_font_options_t *options)
00209 {
00210     return ((options->antialias) |
00211            (options->subpixel_order << 4) |
00212            (options->hint_style << 8) | 
00213            (options->hint_metrics << 16));
00214 }
00215 
00224 void
00225 cairo_font_options_set_antialias (cairo_font_options_t *options,
00226                               cairo_antialias_t     antialias)
00227 {
00228     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00229        return;
00230     
00231     options->antialias = antialias;
00232 }
00233 
00242 cairo_antialias_t
00243 cairo_font_options_get_antialias (const cairo_font_options_t *options)
00244 {
00245     return options->antialias;
00246 }
00247 
00259 void
00260 cairo_font_options_set_subpixel_order (cairo_font_options_t   *options,
00261                                    cairo_subpixel_order_t  subpixel_order)
00262 {
00263     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00264        return;
00265     
00266     options->subpixel_order = subpixel_order;
00267 }
00268 
00278 cairo_subpixel_order_t
00279 cairo_font_options_get_subpixel_order (const cairo_font_options_t *options)
00280 {
00281     return options->subpixel_order;
00282 }
00283 
00294 void
00295 cairo_font_options_set_hint_style (cairo_font_options_t *options,
00296                                cairo_hint_style_t    hint_style)
00297 {
00298     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00299        return;
00300     
00301     options->hint_style = hint_style;
00302 }
00303 
00313 cairo_hint_style_t
00314 cairo_font_options_get_hint_style (const cairo_font_options_t *options)
00315 {
00316     return options->hint_style;
00317 }
00318 
00329 void
00330 cairo_font_options_set_hint_metrics (cairo_font_options_t *options,
00331                                  cairo_hint_metrics_t  hint_metrics)
00332 {
00333     if (options == (cairo_font_options_t *)&cairo_font_options_nil)
00334        return;
00335 
00336     options->hint_metrics = hint_metrics;
00337 }
00338 
00348 cairo_hint_metrics_t
00349 cairo_font_options_get_hint_metrics (const cairo_font_options_t *options)
00350 {
00351     return options->hint_metrics;
00352 }