1 /* Copyright (C) 2005 The cairomm Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA.
17  */
18 
19 #ifndef __CAIROMM_FONTOPTIONS_H
20 #define __CAIROMM_FONTOPTIONS_H
21 
22 #include <cairomm/enums.h>
23 #include <string>
24 //#include <cairo.h>
25 #ifdef CAIRO_HAS_FT_FONT
26 #include <cairo-ft.h>
27 #endif // CAIRO_HAS_FT_FONT
28 
29 namespace Cairo
30 {
31 
32 /**
33  * The font options specify how fonts should be rendered.  Most of the
34  * time the font options implied by a surface are just right and do not
35  * need any changes, but for pixel-based targets tweaking font options
36  * may result in superior output on a particular display.
37  */
38 class FontOptions
39 {
40 public:
41   FontOptions();
42   explicit FontOptions(cairo_font_options_t* cobject, bool take_ownership = false);
43   FontOptions(const FontOptions& src);
44 
45   virtual ~FontOptions();
46 
47   FontOptions& operator=(const FontOptions& src);
48 
49   bool operator ==(const FontOptions& src) const;
50   //bool operator !=(const FontOptions& src) const;
51 
52   /**
53    * Merges non-default options from @a other into this, replacing existing
54    * values. This operation can be thought of as somewhat similar to compositing
55    * @a other onto this with the operation of OPERATION_OVER.
56    *
57    * @param other another FontOptions
58    **/
59   void merge(const FontOptions& other);
60 
61   /**
62    * Compute a hash for the font options object; this value will be useful when
63    * storing an object containing a FontOptions in a hash table.
64    *
65    * @return the hash value for the font options object.  The return value can
66    * be cast to a 32-bit type if a 32-bit hash value is needed.
67    **/
68   unsigned long hash() const;
69 
70   /**
71    * Sets the antialiasing mode for the font options object. This
72    * specifies the type of antialiasing to do when rendering text.
73    *
74    * @param antialias the new antialiasing mode.
75    **/
76   void set_antialias(Antialias antialias);
77 
78   /**
79    * Gets the antialiasing mode for the font options object.
80    *
81    * @return the antialiasing mode
82    **/
83   Antialias get_antialias() const;
84 
85   /**
86    * Sets the subpixel order for the font options object. The subpixel order
87    * specifies the order of color elements within each pixel on the display
88    * device when rendering with an antialiasing mode of
89    * Cairo::ANTIALIAS_SUBPIXEL. See the documentation for SubpixelOrder for
90    * full details.
91    *
92    * @param subpixel_order the new subpixel order.
93    **/
94   void set_subpixel_order(SubpixelOrder subpixel_order);
95 
96   /**
97    * Gets the subpixel order for the font options object.  See the documentation
98    * for SubpixelOrder for full details.
99    *
100    * @return the subpixel order for the font options object.
101    **/
102   SubpixelOrder get_subpixel_order() const;
103 
104   /**
105    * Sets the hint style for font outlines for the font options object.  This
106    * controls whether to fit font outlines to the pixel grid, and if so, whether
107    * to optimize for fidelity or contrast.  See the documentation for
108    * HintStyle for full details.
109    *
110    * @param hint_style the new hint style.
111    **/
112   void set_hint_style(HintStyle hint_style);
113 
114   /**
115    * Gets the hint style for font outlines for the font options object.
116    * See the documentation for HintStyle for full details.
117    *
118    * @return the hint style for the font options object.
119    **/
120   HintStyle get_hint_style() const;
121 
122   /**
123    * Sets the metrics hinting mode for the font options object. This
124    * controls whether metrics are quantized to integer values in
125    * device units.
126    * See the documentation for HintMetrics for full details.
127    *
128    * @param hint_metrics the new metrics hinting mode.
129    **/
130   void set_hint_metrics(HintMetrics hint_metrics);
131 
132   /**
133    * Gets the metrics hinting mode for the font options object.  See the
134    * documentation for HintMetrics for full details.
135    *
136    * Return value: the metrics hinting mode for the font options object.
137    **/
138   HintMetrics get_hint_metrics() const;
139 
140 #ifdef CAIRO_HAS_FT_FONT
141 #ifdef CAIRO_HAS_FC_FONT
142   /** Add options to a FcPattern based on a cairo_font_options_t font options
143    * object. Options that are already in the pattern, are not overridden, so you
144    * should call this function after calling FcConfigSubstitute() (the user's
145    * settings should override options based on the surface type), but before
146    * calling FcDefaultSubstitute().
147    *
148    * @param pattern an existing FcPattern.
149    *
150    * @since 1.8
151    */
152   void substitute(FcPattern* pattern);
153 #endif // CAIRO_HAS_FC_FONT
154 #endif // CAIRO_HAS_FT_FONT
155 
156   typedef cairo_font_options_t cobject;
cobj()157   inline cobject* cobj() { return m_cobject; }
cobj()158   inline const cobject* cobj() const { return m_cobject; }
159 
160   #ifndef DOXYGEN_IGNORE_THIS
161   ///For use only by the cairomm implementation.
get_status()162   inline ErrorStatus get_status() const
163   { return cairo_font_options_status(const_cast<cairo_font_options_t*>(cobj())); }
164   #endif //DOXYGEN_IGNORE_THIS
165 
166 protected:
167 
168   cobject* m_cobject;
169 };
170 
171 } // namespace Cairo
172 
173 #endif //__CAIROMM_FONTOPTIONS_H
174 
175 // vim: ts=2 sw=2 et
176