1 /* Pango
2  * pango-glyph.h: Glyph storage
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_GLYPH_H__
23 #define __PANGO_GLYPH_H__
24 
25 #include <pango/pango-types.h>
26 #include <pango/pango-item.h>
27 
28 G_BEGIN_DECLS
29 
30 typedef struct _PangoGlyphGeometry PangoGlyphGeometry;
31 typedef struct _PangoGlyphVisAttr PangoGlyphVisAttr;
32 typedef struct _PangoGlyphInfo PangoGlyphInfo;
33 typedef struct _PangoGlyphString PangoGlyphString;
34 
35 /* 1024ths of a device unit */
36 /**
37  * PangoGlyphUnit:
38  *
39  * The `PangoGlyphUnit` type is used to store dimensions within
40  * Pango.
41  *
42  * Dimensions are stored in 1/%PANGO_SCALE of a device unit.
43  * (A device unit might be a pixel for screen display, or
44  * a point on a printer.) %PANGO_SCALE is currently 1024, and
45  * may change in the future (unlikely though), but you should not
46  * depend on its exact value. The PANGO_PIXELS() macro can be used
47  * to convert from glyph units into device units with correct rounding.
48  */
49 typedef gint32 PangoGlyphUnit;
50 
51 /* Positioning information about a glyph
52  */
53 /**
54  * PangoGlyphGeometry:
55  * @width: the logical width to use for the the character.
56  * @x_offset: horizontal offset from nominal character position.
57  * @y_offset: vertical offset from nominal character position.
58  *
59  * The `PangoGlyphGeometry` structure contains width and positioning
60  * information for a single glyph.
61  */
62 struct _PangoGlyphGeometry
63 {
64   PangoGlyphUnit width;
65   PangoGlyphUnit x_offset;
66   PangoGlyphUnit y_offset;
67 };
68 
69 /* Visual attributes of a glyph
70  */
71 /**
72  * PangoGlyphVisAttr:
73  * @is_cluster_start: set for the first logical glyph in each cluster.
74  *   (Clusters are stored in visual order, within the cluster, glyphs
75  *   are always ordered in logical order, since visual order is meaningless;
76  *   that is, in Arabic text, accent glyphs follow the glyphs for the
77  *   base character.)
78  *
79  * A `PangoGlyphVisAttr` structure communicates information between
80  * the shaping and rendering phases.
81  *
82  * Currently, it contains only cluster start information. More attributes
83  * may be added in the future.
84  */
85 struct _PangoGlyphVisAttr
86 {
87   guint is_cluster_start : 1;
88 };
89 
90 /* A single glyph
91  */
92 /**
93  * PangoGlyphInfo:
94  * @glyph: the glyph itself.
95  * @geometry: the positional information about the glyph.
96  * @attr: the visual attributes of the glyph.
97  *
98  * A `PangoGlyphInfo` structure represents a single glyph with
99  * positioning information and visual attributes.
100  */
101 struct _PangoGlyphInfo
102 {
103   PangoGlyph    glyph;
104   PangoGlyphGeometry geometry;
105   PangoGlyphVisAttr  attr;
106 };
107 
108 /**
109  * PangoGlyphString:
110  * @num_glyphs: number of the glyphs in this glyph string.
111  * @glyphs: (array length=num_glyphs): array of glyph information
112  *   for the glyph string.
113  * @log_clusters: logical cluster info, indexed by the byte index
114  *   within the text corresponding to the glyph string.
115  *
116  * A `PangoGlyphString` is used to store strings of glyphs with geometry
117  * and visual attribute information.
118  *
119  * The storage for the glyph information is owned by the structure
120  * which simplifies memory management.
121  */
122 struct _PangoGlyphString {
123   gint num_glyphs;
124 
125   PangoGlyphInfo *glyphs;
126   gint *log_clusters;
127 
128   /*< private >*/
129   gint space;
130 };
131 
132 #define PANGO_TYPE_GLYPH_STRING (pango_glyph_string_get_type ())
133 
134 PANGO_AVAILABLE_IN_ALL
135 PangoGlyphString *pango_glyph_string_new      (void);
136 PANGO_AVAILABLE_IN_ALL
137 void              pango_glyph_string_set_size (PangoGlyphString *string,
138 					       gint              new_len);
139 PANGO_AVAILABLE_IN_ALL
140 GType             pango_glyph_string_get_type (void) G_GNUC_CONST;
141 PANGO_AVAILABLE_IN_ALL
142 PangoGlyphString *pango_glyph_string_copy     (PangoGlyphString *string);
143 PANGO_AVAILABLE_IN_ALL
144 void              pango_glyph_string_free     (PangoGlyphString *string);
145 PANGO_AVAILABLE_IN_ALL
146 void              pango_glyph_string_extents  (PangoGlyphString *glyphs,
147 					       PangoFont        *font,
148 					       PangoRectangle   *ink_rect,
149 					       PangoRectangle   *logical_rect);
150 PANGO_AVAILABLE_IN_1_14
151 int               pango_glyph_string_get_width(PangoGlyphString *glyphs);
152 
153 PANGO_AVAILABLE_IN_ALL
154 void              pango_glyph_string_extents_range  (PangoGlyphString *glyphs,
155 						     int               start,
156 						     int               end,
157 						     PangoFont        *font,
158 						     PangoRectangle   *ink_rect,
159 						     PangoRectangle   *logical_rect);
160 
161 PANGO_AVAILABLE_IN_ALL
162 void pango_glyph_string_get_logical_widths (PangoGlyphString *glyphs,
163 					    const char       *text,
164 					    int               length,
165 					    int               embedding_level,
166 					    int              *logical_widths);
167 
168 PANGO_AVAILABLE_IN_ALL
169 void pango_glyph_string_index_to_x (PangoGlyphString *glyphs,
170 				    char             *text,
171 				    int               length,
172 				    PangoAnalysis    *analysis,
173 				    int               index_,
174 				    gboolean          trailing,
175 				    int              *x_pos);
176 PANGO_AVAILABLE_IN_ALL
177 void pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
178 				    char             *text,
179 				    int               length,
180 				    PangoAnalysis    *analysis,
181 				    int               x_pos,
182 				    int              *index_,
183 				    int              *trailing);
184 
185 /* Turn a string of characters into a string of glyphs
186  */
187 PANGO_AVAILABLE_IN_ALL
188 void pango_shape (const char          *text,
189                   int                  length,
190                   const PangoAnalysis *analysis,
191                   PangoGlyphString    *glyphs);
192 
193 PANGO_AVAILABLE_IN_1_32
194 void pango_shape_full (const char          *item_text,
195                        int                  item_length,
196                        const char          *paragraph_text,
197                        int                  paragraph_length,
198                        const PangoAnalysis *analysis,
199                        PangoGlyphString    *glyphs);
200 
201 /**
202  * PangoShapeFlags:
203  * @PANGO_SHAPE_NONE: Default value.
204  * @PANGO_SHAPE_ROUND_POSITIONS: Round glyph positions
205  *   and widths to whole device units. This option should
206  *   be set if the target renderer can't do subpixel
207  *   positioning of glyphs.
208  *
209  * Flags influencing the shaping process.
210  *
211  * `PangoShapeFlags` can be passed to [func@Pango.shape_with_flags].
212  */
213 typedef enum {
214   PANGO_SHAPE_NONE            = 0,
215   PANGO_SHAPE_ROUND_POSITIONS = 1 << 0,
216 } PangoShapeFlags;
217 
218 PANGO_AVAILABLE_IN_1_44
219 void pango_shape_with_flags (const char          *item_text,
220                              int                  item_length,
221                              const char          *paragraph_text,
222                              int                  paragraph_length,
223                              const PangoAnalysis *analysis,
224                              PangoGlyphString    *glyphs,
225                              PangoShapeFlags      flags);
226 
227 PANGO_AVAILABLE_IN_ALL
228 GList *pango_reorder_items (GList *logical_items);
229 
230 G_END_DECLS
231 
232 #endif /* __PANGO_GLYPH_H__ */
233