Upload tizen 2.0 beta source
[external/pango1.0.git] / pango / pango-attributes.h
1 /* Pango
2  * pango-attributes.h: Attributed text
3  *
4  * Copyright (C) 2000 Red Hat Software
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __PANGO_ATTRIBUTES_H__
23 #define __PANGO_ATTRIBUTES_H__
24
25 #include <pango/pango-font.h>
26 #include <glib-object.h>
27
28 G_BEGIN_DECLS
29
30 /* PangoColor */
31
32 typedef struct _PangoColor PangoColor;
33
34 struct _PangoColor
35 {
36   guint16 red;
37   guint16 green;
38   guint16 blue;
39 };
40
41 #define PANGO_TYPE_COLOR pango_color_get_type ()
42 GType       pango_color_get_type (void) G_GNUC_CONST;
43
44 PangoColor *pango_color_copy     (const PangoColor *src);
45 void        pango_color_free     (PangoColor       *color);
46 gboolean    pango_color_parse    (PangoColor       *color,
47                                   const char       *spec);
48 gchar      *pango_color_to_string(const PangoColor *color);
49
50
51 /* Attributes */
52
53 typedef struct _PangoAttribute    PangoAttribute;
54 typedef struct _PangoAttrClass    PangoAttrClass;
55
56 typedef struct _PangoAttrString   PangoAttrString;
57 typedef struct _PangoAttrLanguage PangoAttrLanguage;
58 typedef struct _PangoAttrInt      PangoAttrInt;
59 typedef struct _PangoAttrSize     PangoAttrSize;
60 typedef struct _PangoAttrFloat    PangoAttrFloat;
61 typedef struct _PangoAttrColor    PangoAttrColor;
62 typedef struct _PangoAttrFontDesc PangoAttrFontDesc;
63 typedef struct _PangoAttrShape    PangoAttrShape;
64
65 #define PANGO_TYPE_ATTR_LIST pango_attr_list_get_type ()
66 typedef struct _PangoAttrList     PangoAttrList;
67 typedef struct _PangoAttrIterator PangoAttrIterator;
68
69 typedef enum
70 {
71   PANGO_ATTR_INVALID,           /* 0 is an invalid attribute type */
72   PANGO_ATTR_LANGUAGE,          /* PangoAttrLanguage */
73   PANGO_ATTR_FAMILY,            /* PangoAttrString */
74   PANGO_ATTR_STYLE,             /* PangoAttrInt */
75   PANGO_ATTR_WEIGHT,            /* PangoAttrInt */
76   PANGO_ATTR_VARIANT,           /* PangoAttrInt */
77   PANGO_ATTR_STRETCH,           /* PangoAttrInt */
78   PANGO_ATTR_SIZE,              /* PangoAttrSize */
79   PANGO_ATTR_FONT_DESC,         /* PangoAttrFontDesc */
80   PANGO_ATTR_FOREGROUND,        /* PangoAttrColor */
81   PANGO_ATTR_BACKGROUND,        /* PangoAttrColor */
82   PANGO_ATTR_UNDERLINE,         /* PangoAttrInt */
83   PANGO_ATTR_STRIKETHROUGH,     /* PangoAttrInt */
84   PANGO_ATTR_RISE,              /* PangoAttrInt */
85   PANGO_ATTR_SHAPE,             /* PangoAttrShape */
86   PANGO_ATTR_SCALE,             /* PangoAttrFloat */
87   PANGO_ATTR_FALLBACK,          /* PangoAttrInt */
88   PANGO_ATTR_LETTER_SPACING,    /* PangoAttrInt */
89   PANGO_ATTR_UNDERLINE_COLOR,   /* PangoAttrColor */
90   PANGO_ATTR_STRIKETHROUGH_COLOR,/* PangoAttrColor */
91   PANGO_ATTR_ABSOLUTE_SIZE,     /* PangoAttrSize */
92   PANGO_ATTR_GRAVITY,           /* PangoAttrInt */
93   PANGO_ATTR_GRAVITY_HINT       /* PangoAttrInt */
94 } PangoAttrType;
95
96 typedef enum {
97   PANGO_UNDERLINE_NONE,
98   PANGO_UNDERLINE_SINGLE,
99   PANGO_UNDERLINE_DOUBLE,
100   PANGO_UNDERLINE_LOW,
101   PANGO_UNDERLINE_ERROR
102 } PangoUnderline;
103
104 #define PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING    0
105 #define PANGO_ATTR_INDEX_TO_TEXT_END            G_MAXUINT
106
107 struct _PangoAttribute
108 {
109   const PangoAttrClass *klass;
110   guint start_index;    /* in bytes */
111   guint end_index;      /* in bytes. The character at this index is not included */
112 };
113
114 typedef gboolean (*PangoAttrFilterFunc) (PangoAttribute *attribute,
115                                          gpointer        data);
116
117 typedef gpointer (*PangoAttrDataCopyFunc) (gconstpointer data);
118
119 struct _PangoAttrClass
120 {
121   /*< public >*/
122   PangoAttrType type;
123   PangoAttribute * (*copy) (const PangoAttribute *attr);
124   void             (*destroy) (PangoAttribute *attr);
125   gboolean         (*equal) (const PangoAttribute *attr1, const PangoAttribute *attr2);
126 };
127
128 struct _PangoAttrString
129 {
130   PangoAttribute attr;
131   char *value;
132 };
133
134 struct _PangoAttrLanguage
135 {
136   PangoAttribute attr;
137   PangoLanguage *value;
138 };
139
140 struct _PangoAttrInt
141 {
142   PangoAttribute attr;
143   int value;
144 };
145
146 struct _PangoAttrFloat
147 {
148   PangoAttribute attr;
149   double value;
150 };
151
152 struct _PangoAttrColor
153 {
154   PangoAttribute attr;
155   PangoColor color;
156 };
157
158 struct _PangoAttrSize
159 {
160   PangoAttribute attr;
161   int size;
162   guint absolute : 1;
163 };
164
165 struct _PangoAttrShape
166 {
167   PangoAttribute attr;
168   PangoRectangle ink_rect;
169   PangoRectangle logical_rect;
170
171   gpointer              data;
172   PangoAttrDataCopyFunc copy_func;
173   GDestroyNotify        destroy_func;
174 };
175
176 struct _PangoAttrFontDesc
177 {
178   PangoAttribute attr;
179   PangoFontDescription *desc;
180 };
181
182 PangoAttrType         pango_attr_type_register (const gchar        *name);
183 G_CONST_RETURN char * pango_attr_type_get_name (PangoAttrType       type) G_GNUC_CONST;
184
185 void             pango_attribute_init        (PangoAttribute       *attr,
186                                               const PangoAttrClass *klass);
187 PangoAttribute * pango_attribute_copy        (const PangoAttribute *attr);
188 void             pango_attribute_destroy     (PangoAttribute       *attr);
189 gboolean         pango_attribute_equal       (const PangoAttribute *attr1,
190                                               const PangoAttribute *attr2) G_GNUC_PURE;
191
192 PangoAttribute *pango_attr_language_new      (PangoLanguage              *language);
193 PangoAttribute *pango_attr_family_new        (const char                 *family);
194 PangoAttribute *pango_attr_foreground_new    (guint16                     red,
195                                               guint16                     green,
196                                               guint16                     blue);
197 PangoAttribute *pango_attr_background_new    (guint16                     red,
198                                               guint16                     green,
199                                               guint16                     blue);
200 PangoAttribute *pango_attr_size_new          (int                         size);
201 PangoAttribute *pango_attr_size_new_absolute (int                         size);
202 PangoAttribute *pango_attr_style_new         (PangoStyle                  style);
203 PangoAttribute *pango_attr_weight_new        (PangoWeight                 weight);
204 PangoAttribute *pango_attr_variant_new       (PangoVariant                variant);
205 PangoAttribute *pango_attr_stretch_new       (PangoStretch                stretch);
206 PangoAttribute *pango_attr_font_desc_new     (const PangoFontDescription *desc);
207
208 PangoAttribute *pango_attr_underline_new           (PangoUnderline underline);
209 PangoAttribute *pango_attr_underline_color_new     (guint16        red,
210                                                     guint16        green,
211                                                     guint16        blue);
212 PangoAttribute *pango_attr_strikethrough_new       (gboolean       strikethrough);
213 PangoAttribute *pango_attr_strikethrough_color_new (guint16        red,
214                                                     guint16        green,
215                                                     guint16        blue);
216
217 PangoAttribute *pango_attr_rise_new          (int                         rise);
218 PangoAttribute *pango_attr_scale_new         (double                      scale_factor);
219 PangoAttribute *pango_attr_fallback_new      (gboolean                    enable_fallback);
220 PangoAttribute *pango_attr_letter_spacing_new (int                        letter_spacing);
221
222 PangoAttribute *pango_attr_shape_new           (const PangoRectangle       *ink_rect,
223                                                 const PangoRectangle       *logical_rect);
224 PangoAttribute *pango_attr_shape_new_with_data (const PangoRectangle       *ink_rect,
225                                                 const PangoRectangle       *logical_rect,
226                                                 gpointer                    data,
227                                                 PangoAttrDataCopyFunc       copy_func,
228                                                 GDestroyNotify              destroy_func);
229
230 PangoAttribute *pango_attr_gravity_new      (PangoGravity     gravity);
231 PangoAttribute *pango_attr_gravity_hint_new (PangoGravityHint hint);
232
233 GType              pango_attr_list_get_type      (void) G_GNUC_CONST;
234 PangoAttrList *    pango_attr_list_new           (void);
235 PangoAttrList *    pango_attr_list_ref           (PangoAttrList  *list);
236 void               pango_attr_list_unref         (PangoAttrList  *list);
237 PangoAttrList *    pango_attr_list_copy          (PangoAttrList  *list);
238 void               pango_attr_list_insert        (PangoAttrList  *list,
239                                                   PangoAttribute *attr);
240 void               pango_attr_list_insert_before (PangoAttrList  *list,
241                                                   PangoAttribute *attr);
242 void               pango_attr_list_change        (PangoAttrList  *list,
243                                                   PangoAttribute *attr);
244 void               pango_attr_list_splice        (PangoAttrList  *list,
245                                                   PangoAttrList  *other,
246                                                   gint            pos,
247                                                   gint            len);
248
249 PangoAttrList *pango_attr_list_filter (PangoAttrList       *list,
250                                        PangoAttrFilterFunc  func,
251                                        gpointer             data);
252
253 PangoAttrIterator *pango_attr_list_get_iterator  (PangoAttrList  *list);
254
255 void               pango_attr_iterator_range    (PangoAttrIterator     *iterator,
256                                                  gint                  *start,
257                                                  gint                  *end);
258 gboolean           pango_attr_iterator_next     (PangoAttrIterator     *iterator);
259 PangoAttrIterator *pango_attr_iterator_copy     (PangoAttrIterator     *iterator);
260 void               pango_attr_iterator_destroy  (PangoAttrIterator     *iterator);
261 PangoAttribute *   pango_attr_iterator_get      (PangoAttrIterator     *iterator,
262                                                  PangoAttrType          type);
263 void               pango_attr_iterator_get_font (PangoAttrIterator     *iterator,
264                                                  PangoFontDescription  *desc,
265                                                  PangoLanguage        **language,
266                                                  GSList               **extra_attrs);
267 GSList *          pango_attr_iterator_get_attrs (PangoAttrIterator     *iterator);
268
269
270 gboolean pango_parse_markup (const char                 *markup_text,
271                              int                         length,
272                              gunichar                    accel_marker,
273                              PangoAttrList             **attr_list,
274                              char                      **text,
275                              gunichar                   *accel_char,
276                              GError                    **error);
277
278 G_END_DECLS
279
280 #endif /* __PANGO_ATTRIBUTES_H__ */