pango-renderer.h 11.7 KB
Newer Older
Owen Taylor's avatar
Owen Taylor committed
1 2 3 4
/* Pango
 * pango-renderer.h: Base class for rendering
 *
 * Copyright (C) 2004, Red Hat, Inc.
5
 *
Owen Taylor's avatar
Owen Taylor committed
6 7 8 9 10 11 12
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Matthias Clasen's avatar
Matthias Clasen committed
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Owen Taylor's avatar
Owen Taylor committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef __PANGO_RENDERER_H_
#define __PANGO_RENDERER_H_

#include <pango/pango-layout.h>

G_BEGIN_DECLS

#define PANGO_TYPE_RENDERER            (pango_renderer_get_type())
#define PANGO_RENDERER(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_RENDERER, PangoRenderer))
#define PANGO_IS_RENDERER(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_RENDERER))
#define PANGO_RENDERER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_RENDERER, PangoRendererClass))
#define PANGO_IS_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_RENDERER))
#define PANGO_RENDERER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_RENDERER, PangoRendererClass))

typedef struct _PangoRenderer        PangoRenderer;
typedef struct _PangoRendererClass   PangoRendererClass;
typedef struct _PangoRendererPrivate PangoRendererPrivate;

/**
 * PangoRenderPart:
 * @PANGO_RENDER_PART_FOREGROUND: the text itself
 * @PANGO_RENDER_PART_BACKGROUND: the area behind the text
 * @PANGO_RENDER_PART_UNDERLINE: underlines
 * @PANGO_RENDER_PART_STRIKETHROUGH: strikethrough lines
45
 * @PANGO_RENDER_PART_OVERLINE: overlines
Owen Taylor's avatar
Owen Taylor committed
46
 *
47
 * `PangoRenderPart` defines different items to render for such
Owen Taylor's avatar
Owen Taylor committed
48 49 50 51 52 53 54 55 56 57
 * purposes as setting colors.
 *
 * Since: 1.8
 **/
/* When extending, note N_RENDER_PARTS #define in pango-renderer.c */
typedef enum
{
  PANGO_RENDER_PART_FOREGROUND,
  PANGO_RENDER_PART_BACKGROUND,
  PANGO_RENDER_PART_UNDERLINE,
58 59
  PANGO_RENDER_PART_STRIKETHROUGH,
  PANGO_RENDER_PART_OVERLINE
Owen Taylor's avatar
Owen Taylor committed
60 61 62 63
} PangoRenderPart;

/**
 * PangoRenderer:
64
 * @matrix: (nullable): the current transformation matrix for
65 66
 *   the Renderer; may be %NULL, which should be treated the
 *   same as the identity matrix.
Owen Taylor's avatar
Owen Taylor committed
67
 *
Matthias Clasen's avatar
Matthias Clasen committed
68 69 70 71 72 73
 * `PangoRenderer` is a base class for objects that can render text
 * provided as `PangoGlyphString` or `PangoLayout`.
 *
 * By subclassing `PangoRenderer` and overriding operations such as
 * @draw_glyphs and @draw_rectangle, renderers for particular font
 * backends and destinations can be created.
Owen Taylor's avatar
Owen Taylor committed
74 75
 *
 * Since: 1.8
Matthias Clasen's avatar
Matthias Clasen committed
76
 */
Owen Taylor's avatar
Owen Taylor committed
77 78 79 80 81 82 83 84
struct _PangoRenderer
{
  /*< private >*/
  GObject parent_instance;

  PangoUnderline underline;
  gboolean strikethrough;
  int active_count;
85

Owen Taylor's avatar
Owen Taylor committed
86
  /*< public >*/
Matthias Clasen's avatar
Matthias Clasen committed
87
  PangoMatrix *matrix;          /* May be NULL */
88

Owen Taylor's avatar
Owen Taylor committed
89 90 91 92 93 94
  /*< private >*/
  PangoRendererPrivate *priv;
};

/**
 * PangoRendererClass:
95
 * @draw_glyphs: draws a `PangoGlyphString`
Owen Taylor's avatar
Owen Taylor committed
96 97 98
 * @draw_rectangle: draws a rectangle
 * @draw_error_underline: draws a squiggly line that approximately
 * covers the given rectangle in the style of an underline used to
99
 * indicate a spelling error.
100
 * @draw_shape: draw content for a glyph shaped with `PangoAttrShape`
101 102
 *   @x, @y are the coordinates of the left edge of the baseline,
 *   in user coordinates.
Owen Taylor's avatar
Owen Taylor committed
103 104 105 106 107 108 109
 * @draw_trapezoid: draws a trapezoidal filled area
 * @draw_glyph: draws a single glyph
 * @part_changed: do renderer specific processing when rendering
 *  attributes change
 * @begin: Do renderer-specific initialization before drawing
 * @end: Do renderer-specific cleanup after drawing
 * @prepare_run: updates the renderer for a new run
110
 * @draw_glyph_item: draws a `PangoGlyphItem`
Owen Taylor's avatar
Owen Taylor committed
111
 *
112
 * Class structure for `PangoRenderer`.
Owen Taylor's avatar
Owen Taylor committed
113
 *
Matthias Clasen's avatar
Matthias Clasen committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
 * The following vfuncs take user space coordinates in Pango units
 * and have default implementations:
 * - draw_glyphs
 * - draw_rectangle
 * - draw_error_underline
 * - draw_shape
 * - draw_glyph_item
 *
 * The default draw_shape implementation draws nothing.
 *
 * The following vfuncs take device space coordinates as doubles
 * and must be implemented:
 * - draw_trapezoid
 * - draw_glyph
 *
Owen Taylor's avatar
Owen Taylor committed
129
 * Since: 1.8
Matthias Clasen's avatar
Matthias Clasen committed
130
 */
Owen Taylor's avatar
Owen Taylor committed
131 132 133 134 135 136 137 138
struct _PangoRendererClass
{
  /*< private >*/
  GObjectClass parent_class;

  /* vtable - not signals */
  /*< public >*/

Matthias Clasen's avatar
Matthias Clasen committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
  void (*draw_glyphs)          (PangoRenderer    *renderer,
                                PangoFont        *font,
                                PangoGlyphString *glyphs,
                                int               x,
                                int               y);
  void (*draw_rectangle)       (PangoRenderer    *renderer,
                                PangoRenderPart   part,
                                int               x,
                                int               y,
                                int               width,
                                int               height);
  void (*draw_error_underline) (PangoRenderer    *renderer,
                                int               x,
                                int               y,
                                int               width,
                                int               height);
  void (*draw_shape)           (PangoRenderer    *renderer,
                                PangoAttrShape   *attr,
                                int               x,
                                int               y);
159

Matthias Clasen's avatar
Matthias Clasen committed
160 161 162 163 164 165 166 167 168 169 170 171 172
  void (*draw_trapezoid)       (PangoRenderer    *renderer,
                                PangoRenderPart   part,
                                double            y1_,
                                double            x11,
                                double            x21,
                                double            y2,
                                double            x12,
                                double            x22);
  void (*draw_glyph)           (PangoRenderer    *renderer,
                                PangoFont        *font,
                                PangoGlyph        glyph,
                                double            x,
                                double            y);
Owen Taylor's avatar
Owen Taylor committed
173

Matthias Clasen's avatar
Matthias Clasen committed
174 175
  void (*part_changed)         (PangoRenderer    *renderer,
                                PangoRenderPart   part);
Owen Taylor's avatar
Owen Taylor committed
176

Matthias Clasen's avatar
Matthias Clasen committed
177 178
  void (*begin)                (PangoRenderer    *renderer);
  void (*end)                  (PangoRenderer    *renderer);
Owen Taylor's avatar
Owen Taylor committed
179

Matthias Clasen's avatar
Matthias Clasen committed
180 181
  void (*prepare_run)          (PangoRenderer    *renderer,
                                PangoLayoutRun   *run);
Owen Taylor's avatar
Owen Taylor committed
182

Matthias Clasen's avatar
Matthias Clasen committed
183 184 185 186 187
  void (*draw_glyph_item)      (PangoRenderer    *renderer,
                                const char       *text,
                                PangoGlyphItem   *glyph_item,
                                int               x,
                                int               y);
Behdad Esfahbod's avatar
Behdad Esfahbod committed
188

Owen Taylor's avatar
Owen Taylor committed
189
  /*< private >*/
190

Owen Taylor's avatar
Owen Taylor committed
191
  /* Padding for future expansion */
192
  void (*_pango_reserved2) (void);
Owen Taylor's avatar
Owen Taylor committed
193 194 195 196
  void (*_pango_reserved3) (void);
  void (*_pango_reserved4) (void);
};

197
PANGO_AVAILABLE_IN_1_8
Matthias Clasen's avatar
Matthias Clasen committed
198
GType pango_renderer_get_type            (void) G_GNUC_CONST;
Owen Taylor's avatar
Owen Taylor committed
199

200
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
201
void pango_renderer_draw_layout          (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
202 203 204
                                          PangoLayout      *layout,
                                          int               x,
                                          int               y);
205
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
206
void pango_renderer_draw_layout_line     (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
207 208 209
                                          PangoLayoutLine  *line,
                                          int               x,
                                          int               y);
210
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
211
void pango_renderer_draw_glyphs          (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
212 213 214 215
                                          PangoFont        *font,
                                          PangoGlyphString *glyphs,
                                          int               x,
                                          int               y);
216
PANGO_AVAILABLE_IN_1_22
Behdad Esfahbod's avatar
Behdad Esfahbod committed
217
void pango_renderer_draw_glyph_item      (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
218 219 220 221
                                          const char       *text,
                                          PangoGlyphItem   *glyph_item,
                                          int               x,
                                          int               y);
222
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
223
void pango_renderer_draw_rectangle       (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
224 225 226 227 228
                                          PangoRenderPart   part,
                                          int               x,
                                          int               y,
                                          int               width,
                                          int               height);
229
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
230
void pango_renderer_draw_error_underline (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
231 232 233 234
                                          int               x,
                                          int               y,
                                          int               width,
                                          int               height);
235
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
236
void pango_renderer_draw_trapezoid       (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
237 238 239 240 241 242 243
                                          PangoRenderPart   part,
                                          double            y1_,
                                          double            x11,
                                          double            x21,
                                          double            y2,
                                          double            x12,
                                          double            x22);
244
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
245
void pango_renderer_draw_glyph           (PangoRenderer    *renderer,
Matthias Clasen's avatar
Matthias Clasen committed
246 247 248 249
                                          PangoFont        *font,
                                          PangoGlyph        glyph,
                                          double            x,
                                          double            y);
Owen Taylor's avatar
Owen Taylor committed
250

251
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
252
void pango_renderer_activate             (PangoRenderer    *renderer);
253
PANGO_AVAILABLE_IN_1_8
Owen Taylor's avatar
Owen Taylor committed
254 255
void pango_renderer_deactivate           (PangoRenderer    *renderer);

256
PANGO_AVAILABLE_IN_1_8
Matthias Clasen's avatar
Matthias Clasen committed
257 258
void pango_renderer_part_changed         (PangoRenderer   *renderer,
                                          PangoRenderPart  part);
259

260
PANGO_AVAILABLE_IN_1_8
Matthias Clasen's avatar
Matthias Clasen committed
261 262 263
void        pango_renderer_set_color     (PangoRenderer    *renderer,
                                          PangoRenderPart   part,
                                          const PangoColor *color);
264
PANGO_AVAILABLE_IN_1_8
Matthias Clasen's avatar
Matthias Clasen committed
265 266
PangoColor *pango_renderer_get_color     (PangoRenderer    *renderer,
                                          PangoRenderPart   part);
Owen Taylor's avatar
Owen Taylor committed
267

268
PANGO_AVAILABLE_IN_1_38
Matthias Clasen's avatar
Matthias Clasen committed
269 270 271
void        pango_renderer_set_alpha     (PangoRenderer    *renderer,
                                          PangoRenderPart   part,
                                          guint16           alpha);
272
PANGO_AVAILABLE_IN_1_38
Matthias Clasen's avatar
Matthias Clasen committed
273 274
guint16     pango_renderer_get_alpha     (PangoRenderer    *renderer,
                                          PangoRenderPart   part);
275

276
PANGO_AVAILABLE_IN_1_8
Matthias Clasen's avatar
Matthias Clasen committed
277 278
void               pango_renderer_set_matrix      (PangoRenderer     *renderer,
                                                   const PangoMatrix *matrix);
279
PANGO_AVAILABLE_IN_1_8
Matthias Clasen's avatar
Matthias Clasen committed
280
const PangoMatrix *pango_renderer_get_matrix      (PangoRenderer     *renderer);
Owen Taylor's avatar
Owen Taylor committed
281

282
PANGO_AVAILABLE_IN_1_20
Matthias Clasen's avatar
Matthias Clasen committed
283
PangoLayout       *pango_renderer_get_layout      (PangoRenderer     *renderer);
284
PANGO_AVAILABLE_IN_1_20
Matthias Clasen's avatar
Matthias Clasen committed
285
PangoLayoutLine   *pango_renderer_get_layout_line (PangoRenderer     *renderer);
286

Owen Taylor's avatar
Owen Taylor committed
287 288 289 290
G_END_DECLS

#endif /* __PANGO_RENDERER_H_ */