1 /*
2  * Cogl
3  *
4  * A Low Level GPU Graphics and Utilities API
5  *
6  * Copyright (C) 2008 OpenedHand
7  * Copyright (C) 2012 Intel Corporation.
8  *
9  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use, copy,
13  * modify, merge, publish, distribute, sublicense, and/or sell copies
14  * of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * Authors:
30  *   Neil Roberts <neil@linux.intel.com>
31  *   Robert Bragg <robert@linux.intel.com>
32  *   Matthew Allum  <mallum@openedhand.com>
33  */
34 
35 #ifndef __COGL_PANGO_H__
36 #define __COGL_PANGO_H__
37 
38 #include <glib-object.h>
39 #include <pango/pango.h>
40 #include <pango/pangocairo.h>
41 
42 /* XXX: Currently this header may be included both as an internal
43  * header (within the cogl-pango implementation) and as a public
44  * header.
45  *
46  * Since <cogl/cogl.h> should not be included for internal use we
47  * determine the current context and switch between including cogl.h
48  * or specific internal cogl headers here...
49  */
50 #ifndef COGL_COMPILATION
51 #include <cogl/cogl.h>
52 #else
53 #include "cogl/cogl-context.h"
54 #include "cogl/cogl-macros.h"
55 #endif
56 
57 G_BEGIN_DECLS
58 
59 /* It's too difficult to actually subclass the pango cairo font
60  * map. Instead we just make a fake set of macros that actually just
61  * directly use the original type
62  */
63 #define COGL_PANGO_TYPE_FONT_MAP        PANGO_TYPE_CAIRO_FONT_MAP
64 #define COGL_PANGO_FONT_MAP(obj)        (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_PANGO_TYPE_FONT_MAP, CoglPangoFontMap))
65 #define COGL_PANGO_IS_FONT_MAP(obj)     (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_PANGO_TYPE_FONT_MAP))
66 
67 typedef PangoCairoFontMap CoglPangoFontMap;
68 
69 /**
70  * cogl_pango_font_map_new:
71  *
72  * Creates a new font map.
73  *
74  * Return value: (transfer full): the newly created #PangoFontMap
75  *
76  * Since: 1.14
77  */
78 COGL_EXPORT PangoFontMap *
79 cogl_pango_font_map_new (void);
80 
81 /**
82  * cogl_pango_font_map_create_context:
83  * @font_map: a #CoglPangoFontMap
84  *
85  * Create a #PangoContext for the given @font_map.
86  *
87  * Returns: (transfer full): the newly created context: free with g_object_unref().
88  */
89 COGL_EXPORT PangoContext *
90 cogl_pango_font_map_create_context (CoglPangoFontMap *font_map);
91 
92 /**
93  * cogl_pango_font_map_set_resolution:
94  * @font_map: a #CoglPangoFontMap
95  * @dpi: The resolution in "dots per inch". (Physical inches aren't
96  *       actually involved; the terminology is conventional.)
97  *
98  * Sets the resolution for the @font_map. This is a scale factor
99  * between points specified in a #PangoFontDescription and Cogl units.
100  * The default value is %96, meaning that a 10 point font will be 13
101  * units high. (10 * 96. / 72. = 13.3).
102  *
103  * Since: 1.14
104  */
105 COGL_EXPORT void
106 cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
107                                     double dpi);
108 
109 /**
110  * cogl_pango_font_map_clear_glyph_cache:
111  * @font_map: a #CoglPangoFontMap
112  *
113  * Clears the glyph cache for @font_map.
114  *
115  * Since: 1.0
116  */
117 COGL_EXPORT void
118 cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *font_map);
119 
120 /**
121  * cogl_pango_ensure_glyph_cache_for_layout:
122  * @layout: A #PangoLayout
123  *
124  * This updates any internal glyph cache textures as necessary to be
125  * able to render the given @layout.
126  *
127  * This api should be used to avoid mid-scene modifications of
128  * glyph-cache textures which can lead to undefined rendering results.
129  *
130  * Since: 1.0
131  */
132 COGL_EXPORT void
133 cogl_pango_ensure_glyph_cache_for_layout (PangoLayout *layout);
134 
135 /**
136  * cogl_pango_font_map_set_use_mipmapping:
137  * @font_map: a #CoglPangoFontMap
138  * @value: %TRUE to enable the use of mipmapping
139  *
140  * Sets whether the renderer for the passed font map should use
141  * mipmapping when rendering a #PangoLayout.
142  *
143  * Since: 1.0
144  */
145 COGL_EXPORT void
146 cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *font_map,
147                                         gboolean value);
148 
149 /**
150  * cogl_pango_font_map_get_use_mipmapping:
151  * @font_map: a #CoglPangoFontMap
152  *
153  * Retrieves whether the #CoglPangoRenderer used by @font_map will use
154  * mipmapping when rendering the glyphs.
155  *
156  * Return value: %TRUE if mipmapping is used, %FALSE otherwise.
157  *
158  * Since: 1.0
159  */
160 COGL_EXPORT gboolean
161 cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *font_map);
162 
163 /**
164  * cogl_pango_font_map_get_renderer:
165  * @font_map: a #CoglPangoFontMap
166  *
167  * Retrieves the #CoglPangoRenderer for the passed @font_map.
168  *
169  * Return value: (transfer none): a #PangoRenderer
170  *
171  * Since: 1.0
172  */
173 COGL_EXPORT PangoRenderer *
174 cogl_pango_font_map_get_renderer (CoglPangoFontMap *font_map);
175 
176 /**
177  * cogl_pango_show_layout: (skip)
178  * @framebuffer: A #CoglFramebuffer to draw too.
179  * @layout: a #PangoLayout
180  * @x: X coordinate to render the layout at
181  * @y: Y coordinate to render the layout at
182  * @color: color to use when rendering the layout
183  *
184  * Draws a solidly coloured @layout on the given @framebuffer at (@x,
185  * @y) within the @framebuffer<!-- -->'s current model-view coordinate
186  * space.
187  *
188  * Since: 1.14
189  */
190 COGL_EXPORT void
191 cogl_pango_show_layout (CoglFramebuffer *framebuffer,
192                         PangoLayout *layout,
193                         float x,
194                         float y,
195                         const CoglColor *color);
196 
197 /**
198  * cogl_pango_show_layout_line: (skip)
199  * @framebuffer: A #CoglFramebuffer to draw too.
200  * @line: a #PangoLayoutLine
201  * @x: X coordinate to render the line at
202  * @y: Y coordinate to render the line at
203  * @color: color to use when rendering the line
204  *
205  * Draws a solidly coloured @line on the given @framebuffer at (@x,
206  * @y) within the @framebuffer<!-- -->'s current model-view coordinate
207  * space.
208  *
209  * Since: 1.14
210  */
211 COGL_EXPORT void
212 cogl_pango_show_layout_line (CoglFramebuffer *framebuffer,
213                              PangoLayoutLine *line,
214                              float x,
215                              float y,
216                              const CoglColor *color);
217 
218 
219 #define COGL_PANGO_TYPE_RENDERER                (cogl_pango_renderer_get_type ())
220 #define COGL_PANGO_RENDERER(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_PANGO_TYPE_RENDERER, CoglPangoRenderer))
221 #define COGL_PANGO_RENDERER_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_PANGO_TYPE_RENDERER, CoglPangoRendererClass))
222 #define COGL_PANGO_IS_RENDERER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_PANGO_TYPE_RENDERER))
223 #define COGL_PANGO_IS_RENDERER_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass),  COGL_PANGO_TYPE_RENDERER))
224 #define COGL_PANGO_RENDERER_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_PANGO_TYPE_RENDERER, CoglPangoRendererClass))
225 
226 /* opaque types */
227 typedef struct _CoglPangoRenderer      CoglPangoRenderer;
228 typedef struct _CoglPangoRendererClass CoglPangoRendererClass;
229 
230 COGL_EXPORT GType cogl_pango_renderer_get_type (void) G_GNUC_CONST;
231 
232 G_END_DECLS
233 
234 #endif /* __COGL_PANGO_H__ */
235