1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module pango.c.attributes;
7 
8 import pango.c.font;
9 import pango.c.types;
10 import pango.c.gravity;
11 
12 import glib;
13 import gobject;
14 
15 import std.bitmanip;
16 
17 
18 extern (C):
19 
20 /* PangoColor */
21 /**
22  * PangoColor:
23  * @red: value of red component
24  * @green: value of green component
25  * @blue: value of blue component
26  *
27  * The #PangoColor structure is used to
28  * represent a color in an uncalibrated RGB color-space.
29  */
30 struct PangoColor
31 {
32   guint16 red;
33   guint16 green;
34   guint16 blue;
35 }
36 
37 pure GType       pango_color_get_type ();
38 
39 PangoColor *pango_color_copy     (const(PangoColor) *src);
40 void        pango_color_free     (PangoColor       *color);
41 gboolean    pango_color_parse    (PangoColor       *color,
42 				  const(char)       *spec);
43 gchar      *pango_color_to_string(const(PangoColor) *color);
44 
45 
46 
47 /**
48  * PangoAttrIterator:
49  *
50  * The #PangoAttrIterator structure is used to represent an
51  * iterator through a #PangoAttrList. A new iterator is created
52  * with pango_attr_list_get_iterator(). Once the iterator
53  * is created, it can be advanced through the style changes
54  * in the text using pango_attr_iterator_next(). At each
55  * style change, the range of the current style segment and the
56  * attributes currently in effect can be queried.
57  */
58 /**
59  * PangoAttrList:
60  *
61  * The #PangoAttrList structure represents a list of attributes
62  * that apply to a section of text. The attributes are, in general,
63  * allowed to overlap in an arbitrary fashion, however, if the
64  * attributes are manipulated only through pango_attr_list_change(),
65  * the overlap between properties will meet stricter criteria.
66  *
67  * Since the #PangoAttrList structure is stored as a linear list,
68  * it is not suitable for storing attributes for large amounts
69  * of text. In general, you should not use a single #PangoAttrList
70  * for more than one paragraph of text.
71  */
72 struct PangoAttrList;
73 struct PangoAttrIterator;
74 
75 /**
76  * PangoAttrType:
77  * @PANGO_ATTR_INVALID: does not happen
78  * @PANGO_ATTR_LANGUAGE: language (#PangoAttrLanguage)
79  * @PANGO_ATTR_FAMILY: font family name list (#PangoAttrString)
80  * @PANGO_ATTR_STYLE: font slant style (#PangoAttrInt)
81  * @PANGO_ATTR_WEIGHT: font weight (#PangoAttrInt)
82  * @PANGO_ATTR_VARIANT: font variant (normal or small caps) (#PangoAttrInt)
83  * @PANGO_ATTR_STRETCH: font stretch (#PangoAttrInt)
84  * @PANGO_ATTR_SIZE: font size in points scaled by %PANGO_SCALE (#PangoAttrInt)
85  * @PANGO_ATTR_FONT_DESC: font description (#PangoAttrFontDesc)
86  * @PANGO_ATTR_FOREGROUND: foreground color (#PangoAttrColor)
87  * @PANGO_ATTR_BACKGROUND: background color (#PangoAttrColor)
88  * @PANGO_ATTR_UNDERLINE: whether the text has an underline (#PangoAttrInt)
89  * @PANGO_ATTR_STRIKETHROUGH: whether the text is struck-through (#PangoAttrInt)
90  * @PANGO_ATTR_RISE: baseline displacement (#PangoAttrInt)
91  * @PANGO_ATTR_SHAPE: shape (#PangoAttrShape)
92  * @PANGO_ATTR_SCALE: font size scale factor (#PangoAttrFloat)
93  * @PANGO_ATTR_FALLBACK: whether fallback is enabled (#PangoAttrInt)
94  * @PANGO_ATTR_LETTER_SPACING: letter spacing (#PangoAttrInt)
95  * @PANGO_ATTR_UNDERLINE_COLOR: underline color (#PangoAttrColor)
96  * @PANGO_ATTR_STRIKETHROUGH_COLOR: strikethrough color (#PangoAttrColor)
97  * @PANGO_ATTR_ABSOLUTE_SIZE: font size in pixels scaled by %PANGO_SCALE (#PangoAttrInt)
98  * @PANGO_ATTR_GRAVITY: base text gravity (#PangoAttrInt)
99  * @PANGO_ATTR_GRAVITY_HINT: gravity hint (#PangoAttrInt)
100  *
101  * The #PangoAttrType
102  * distinguishes between different types of attributes. Along with the
103  * predefined values, it is possible to allocate additional values
104  * for custom attributes using pango_attr_type_register(). The predefined
105  * values are given below. The type of structure used to store the
106  * attribute is listed in parentheses after the description.
107  */
108 enum PangoAttrType
109 {
110   PANGO_ATTR_INVALID,           /* 0 is an invalid attribute type */
111   PANGO_ATTR_LANGUAGE,		/* PangoAttrLanguage */
112   PANGO_ATTR_FAMILY,		/* PangoAttrString */
113   PANGO_ATTR_STYLE,		/* PangoAttrInt */
114   PANGO_ATTR_WEIGHT,		/* PangoAttrInt */
115   PANGO_ATTR_VARIANT,		/* PangoAttrInt */
116   PANGO_ATTR_STRETCH,		/* PangoAttrInt */
117   PANGO_ATTR_SIZE,		/* PangoAttrSize */
118   PANGO_ATTR_FONT_DESC,		/* PangoAttrFontDesc */
119   PANGO_ATTR_FOREGROUND,	/* PangoAttrColor */
120   PANGO_ATTR_BACKGROUND,	/* PangoAttrColor */
121   PANGO_ATTR_UNDERLINE,		/* PangoAttrInt */
122   PANGO_ATTR_STRIKETHROUGH,	/* PangoAttrInt */
123   PANGO_ATTR_RISE,		/* PangoAttrInt */
124   PANGO_ATTR_SHAPE,		/* PangoAttrShape */
125   PANGO_ATTR_SCALE,             /* PangoAttrFloat */
126   PANGO_ATTR_FALLBACK,          /* PangoAttrInt */
127   PANGO_ATTR_LETTER_SPACING,    /* PangoAttrInt */
128   PANGO_ATTR_UNDERLINE_COLOR,	/* PangoAttrColor */
129   PANGO_ATTR_STRIKETHROUGH_COLOR,/* PangoAttrColor */
130   PANGO_ATTR_ABSOLUTE_SIZE,	/* PangoAttrSize */
131   PANGO_ATTR_GRAVITY,		/* PangoAttrInt */
132   PANGO_ATTR_GRAVITY_HINT	/* PangoAttrInt */
133 }
134 
135 /**
136  * PangoUnderline:
137  * @PANGO_UNDERLINE_NONE: no underline should be drawn
138  * @PANGO_UNDERLINE_SINGLE: a single underline should be drawn
139  * @PANGO_UNDERLINE_DOUBLE: a double underline should be drawn
140  * @PANGO_UNDERLINE_LOW: a single underline should be drawn at a position
141  * beneath the ink extents of the text being
142  * underlined. This should be used only for underlining
143  * single characters, such as for keyboard
144  * accelerators. %PANGO_UNDERLINE_SINGLE should
145  * be used for extended portions of text.
146  * @PANGO_UNDERLINE_ERROR: a wavy underline should be drawn below.
147  * This underline is typically used to indicate
148  * an error such as a possilble mispelling; in some
149  * cases a contrasting color may automatically
150  * be used. This type of underlining is available since Pango 1.4.
151  *
152  * The #PangoUnderline enumeration is used to specify
153  * whether text should be underlined, and if so, the type
154  * of underlining.
155  */
156 enum PangoUnderline {
157   PANGO_UNDERLINE_NONE,
158   PANGO_UNDERLINE_SINGLE,
159   PANGO_UNDERLINE_DOUBLE,
160   PANGO_UNDERLINE_LOW,
161   PANGO_UNDERLINE_ERROR
162 }
163 
164 /**
165  * PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING:
166  *
167  * This value can be used to set the start_index member of a #PangoAttribute
168  * such that the attribute covers from the beginning of the text.
169  *
170  * Since: 1.24
171  */
172 /**
173  * PANGO_ATTR_INDEX_TO_TEXT_END:
174  *
175  * This value can be used to set the end_index member of a #PangoAttribute
176  * such that the attribute covers to the end of the text.
177  *
178  * Since: 1.24
179  */
180 enum PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING = 0;
181 enum PANGO_ATTR_INDEX_TO_TEXT_END = G_MAXUINT;
182 
183 /**
184  * PangoAttribute:
185  * @klass: the class structure holding information about the type of the attribute
186  * @start_index: the start index of the range (in bytes).
187  * @end_index: end index of the range (in bytes). The character at this index
188  * is not included in the range.
189  *
190  * The #PangoAttribute structure represents the common portions of all
191  * attributes. Particular types of attributes include this structure
192  * as their initial portion. The common portion of the attribute holds
193  * the range to which the value in the type-specific part of the attribute
194  * applies and should be initialized using pango_attribute_init().
195  * By default an attribute will have an all-inclusive range of [0,%G_MAXUINT].
196  */
197 struct PangoAttribute
198 {
199   const(PangoAttrClass) *klass;
200   guint start_index;	/* in bytes */
201   guint end_index;	/* in bytes. The character at this index is not included */
202 }
203 
204 /**
205  * PangoAttrFilterFunc:
206  * @attribute: a Pango attribute
207  * @user_data: user data passed to the function
208  *
209  * Type of a function filtering a list of attributes.
210  *
211  * Return value: %TRUE if the attribute should be selected for
212  * filtering, %FALSE otherwise.
213  **/
214 alias PangoAttrFilterFunc = gboolean function (PangoAttribute *attribute,
215 					 gpointer        user_data);
216 
217 /**
218  * PangoAttrDataCopyFunc:
219  * @user_data: user data to copy
220  *
221  * Type of a function that can duplicate user data for an attribute.
222  *
223  * Return value: new copy of @user_data.
224  **/
225 alias PangoAttrDataCopyFunc = gpointer function (gconstpointer user_data);
226 
227 /**
228  * PangoAttrClass:
229  * @type: the type ID for this attribute
230  * @copy: function to duplicate an attribute of this type (see pango_attribute_copy())
231  * @destroy: function to free an attribute of this type (see pango_attribute_destroy())
232  * @equal: function to check two attributes of this type for equality (see pango_attribute_equal())
233  *
234  * The #PangoAttrClass structure stores the type and operations for
235  * a particular type of attribute. The functions in this structure should
236  * not be called directly. Instead, one should use the wrapper functions
237  * provided for #PangoAttribute.
238  */
239 struct PangoAttrClass
240 {
241   /*< public >*/
242   PangoAttrType type;
243   PangoAttribute * function (const(PangoAttribute) *attr) copy;
244   void             function (PangoAttribute *attr) destroy;
245   gboolean         function (const(PangoAttribute) *attr1, const(PangoAttribute) *attr2) equal;
246 }
247 
248 /**
249  * PangoAttrString:
250  * @attr: the common portion of the attribute
251  * @value: the string which is the value of the attribute
252  *
253  * The #PangoAttrString structure is used to represent attributes with
254  * a string value.
255  */
256 struct PangoAttrString
257 {
258   PangoAttribute attr;
259   char *value;
260 }
261 /**
262  * PangoAttrLanguage:
263  * @attr: the common portion of the attribute
264  * @value: the #PangoLanguage which is the value of the attribute
265  *
266  * The #PangoAttrLanguage structure is used to represent attributes that
267  * are languages.
268  */
269 struct PangoAttrLanguage
270 {
271   PangoAttribute attr;
272   PangoLanguage *value;
273 }
274 /**
275  * PangoAttrInt:
276  * @attr: the common portion of the attribute
277  * @value: the value of the attribute
278  *
279  * The #PangoAttrInt structure is used to represent attributes with
280  * an integer or enumeration value.
281  */
282 struct PangoAttrInt
283 {
284   PangoAttribute attr;
285   int value;
286 }
287 /**
288  * PangoAttrFloat:
289  * @attr: the common portion of the attribute
290  * @value: the value of the attribute
291  *
292  * The #PangoAttrFloat structure is used to represent attributes with
293  * a float or double value.
294  */
295 struct PangoAttrFloat
296 {
297   PangoAttribute attr;
298   double value;
299 }
300 /**
301  * PangoAttrColor:
302  * @attr: the common portion of the attribute
303  * @color: the #PangoColor which is the value of the attribute
304  *
305  * The #PangoAttrColor structure is used to represent attributes that
306  * are colors.
307  */
308 struct PangoAttrColor
309 {
310   PangoAttribute attr;
311   PangoColor color;
312 }
313 
314 /**
315  * PangoAttrSize:
316  * @attr: the common portion of the attribute
317  * @size: size of font, in units of 1/%PANGO_SCALE of a point (for
318  * %PANGO_ATTR_SIZE) or of a device uni (for %PANGO_ATTR_ABSOLUTE_SIZE)
319  * @absolute: whether the font size is in device units or points.
320  * This field is only present for compatibility with Pango-1.8.0
321  * (%PANGO_ATTR_ABSOLUTE_SIZE was added in 1.8.1); and always will
322  * be %FALSE for %PANGO_ATTR_SIZE and %TRUE for %PANGO_ATTR_ABSOLUTE_SIZE.
323  *
324  * The #PangoAttrSize structure is used to represent attributes which
325  * set font size.
326  */
327 struct PangoAttrSize
328 {
329   PangoAttribute attr;
330   int size;
331   mixin(bitfields!(
332               guint, "absolute", 1,
333               guint, "", 7));
334 }
335 
336 /**
337  * PangoAttrShape:
338  * @attr: the common portion of the attribute
339  * @ink_rect: the ink rectangle to restrict to
340  * @logical_rect: the logical rectangle to restrict to
341  * @data: user data set (see pango_attr_shape_new_with_data())
342  * @copy_func: copy function for the user data
343  * @destroy_func: destroy function for the user data
344  *
345  * The #PangoAttrShape structure is used to represent attributes which
346  * impose shape restrictions.
347  */
348 struct PangoAttrShape
349 {
350   PangoAttribute attr;
351   PangoRectangle ink_rect;
352   PangoRectangle logical_rect;
353 
354   gpointer              data;
355   PangoAttrDataCopyFunc copy_func;
356   GDestroyNotify        destroy_func;
357 }
358 
359 /**
360  * PangoAttrFontDesc:
361  * @attr: the common portion of the attribute
362  * @desc: the font description which is the value of this attribute
363  *
364  * The #PangoAttrFontDesc structure is used to store an attribute that
365  * sets all aspects of the font description at once.
366  */
367 struct PangoAttrFontDesc
368 {
369   PangoAttribute attr;
370   PangoFontDescription *desc;
371 }
372 
373 PangoAttrType         pango_attr_type_register (const(gchar)        *name);
374 pure const(char) *          pango_attr_type_get_name (PangoAttrType       type);
375 
376 void             pango_attribute_init        (PangoAttribute       *attr,
377 					      const(PangoAttrClass) *klass);
378 PangoAttribute * pango_attribute_copy        (const(PangoAttribute) *attr);
379 void             pango_attribute_destroy     (PangoAttribute       *attr);
380 pure gboolean         pango_attribute_equal       (const(PangoAttribute) *attr1,
381 					      const(PangoAttribute) *attr2);
382 
383 PangoAttribute *pango_attr_language_new      (PangoLanguage              *language);
384 PangoAttribute *pango_attr_family_new        (const(char)                 *family);
385 PangoAttribute *pango_attr_foreground_new    (guint16                     red,
386 					      guint16                     green,
387 					      guint16                     blue);
388 PangoAttribute *pango_attr_background_new    (guint16                     red,
389 					      guint16                     green,
390 					      guint16                     blue);
391 PangoAttribute *pango_attr_size_new          (int                         size);
392 PangoAttribute *pango_attr_size_new_absolute (int                         size);
393 PangoAttribute *pango_attr_style_new         (PangoStyle                  style);
394 PangoAttribute *pango_attr_weight_new        (PangoWeight                 weight);
395 PangoAttribute *pango_attr_variant_new       (PangoVariant                variant);
396 PangoAttribute *pango_attr_stretch_new       (PangoStretch                stretch);
397 PangoAttribute *pango_attr_font_desc_new     (const(PangoFontDescription) *desc);
398 
399 PangoAttribute *pango_attr_underline_new           (PangoUnderline underline);
400 PangoAttribute *pango_attr_underline_color_new     (guint16        red,
401 						    guint16        green,
402 						    guint16        blue);
403 PangoAttribute *pango_attr_strikethrough_new       (gboolean       strikethrough);
404 PangoAttribute *pango_attr_strikethrough_color_new (guint16        red,
405 						    guint16        green,
406 						    guint16        blue);
407 
408 PangoAttribute *pango_attr_rise_new          (int                         rise);
409 PangoAttribute *pango_attr_scale_new         (double                      scale_factor);
410 PangoAttribute *pango_attr_fallback_new      (gboolean                    enable_fallback);
411 PangoAttribute *pango_attr_letter_spacing_new (int                        letter_spacing);
412 
413 PangoAttribute *pango_attr_shape_new           (const(PangoRectangle)       *ink_rect,
414 						const(PangoRectangle)       *logical_rect);
415 PangoAttribute *pango_attr_shape_new_with_data (const(PangoRectangle)       *ink_rect,
416 						const(PangoRectangle)       *logical_rect,
417 						gpointer                    data,
418 						PangoAttrDataCopyFunc       copy_func,
419 						GDestroyNotify              destroy_func);
420 
421 PangoAttribute *pango_attr_gravity_new      (PangoGravity     gravity);
422 PangoAttribute *pango_attr_gravity_hint_new (PangoGravityHint hint);
423 
424 pure GType              pango_attr_list_get_type      ();
425 PangoAttrList *    pango_attr_list_new           ();
426 PangoAttrList *    pango_attr_list_ref           (PangoAttrList  *list);
427 void               pango_attr_list_unref         (PangoAttrList  *list);
428 PangoAttrList *    pango_attr_list_copy          (PangoAttrList  *list);
429 void               pango_attr_list_insert        (PangoAttrList  *list,
430 						  PangoAttribute *attr);
431 void               pango_attr_list_insert_before (PangoAttrList  *list,
432 						  PangoAttribute *attr);
433 void               pango_attr_list_change        (PangoAttrList  *list,
434 						  PangoAttribute *attr);
435 void               pango_attr_list_splice        (PangoAttrList  *list,
436 						  PangoAttrList  *other,
437 						  gint            pos,
438 						  gint            len);
439 
440 PangoAttrList *pango_attr_list_filter (PangoAttrList       *list,
441 				       PangoAttrFilterFunc  func,
442 				       gpointer             data);
443 
444 PangoAttrIterator *pango_attr_list_get_iterator  (PangoAttrList  *list);
445 
446 void               pango_attr_iterator_range    (PangoAttrIterator     *iterator,
447 						 gint                  *start,
448 						 gint                  *end);
449 gboolean           pango_attr_iterator_next     (PangoAttrIterator     *iterator);
450 PangoAttrIterator *pango_attr_iterator_copy     (PangoAttrIterator     *iterator);
451 void               pango_attr_iterator_destroy  (PangoAttrIterator     *iterator);
452 PangoAttribute *   pango_attr_iterator_get      (PangoAttrIterator     *iterator,
453 						 PangoAttrType          type);
454 void               pango_attr_iterator_get_font (PangoAttrIterator     *iterator,
455 						 PangoFontDescription  *desc,
456 						 PangoLanguage        **language,
457 						 GSList               **extra_attrs);
458 GSList *          pango_attr_iterator_get_attrs (PangoAttrIterator     *iterator);
459 
460 
461 gboolean pango_parse_markup (const(char)                 *markup_text,
462 			     int                         length,
463 			     gunichar                    accel_marker,
464 			     PangoAttrList             **attr_list,
465 			     char                      **text,
466 			     gunichar                   *accel_char,
467 			     GError                    **error);
468 
469 GMarkupParseContext * pango_markup_parser_new (gunichar               accel_marker);
470 gboolean              pango_markup_parser_finish (GMarkupParseContext   *context,
471                                                   PangoAttrList        **attr_list,
472                                                   char                 **text,
473                                                   gunichar              *accel_char,
474                                                   GError               **error);
475