summaryrefslogtreecommitdiff
path: root/pango/pango.h
blob: 0b375a96f55f3b59cd22b7c14571bb7cfa3af5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* Pango
 * pango.h:
 *
 * Copyright (C) 1999 Red Hat Software
 *
 * 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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * 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.
 */

/* The API here is based fairly closely on Microsoft's Uniscript
 * API. Differences here:
 * 
 * - Memory management is more convenient (Pango handles 
 *   all buffer reallocation)
 * - Unicode strings are represented in UTF-8
 * - Representation of fonts and glyphs is abstracted to be
 *   rendering-system dependent.
 */

#ifndef __PANGO_H__
#define __PANGO_H__

#include <glib.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

typedef struct _PangoAnalysis PangoAnalysis;
typedef struct _PangoItem PangoItem;
typedef struct _PangoContext PangoContext;
typedef struct _PangoLangRange PangoLangRange;
typedef struct _PangoLogAttr PangoLogAttr;

typedef struct _PangoFont PangoFont;
typedef struct _PangoFontClass PangoFontClass;
typedef struct _PangoCFont PangoCFont;
typedef struct _PangoCFontClass PangoCFontClass;

typedef struct _PangoGlyph PangoGlyph;
typedef struct _PangoGlyphGeometry PangoGlyphGeometry;
typedef struct _PangoGlyphVisAttr PangoGlyphVisAttr;
typedef struct _PangoGlyphString PangoGlyphString;

typedef struct _PangoEngineInfo PangoEngineInfo;
typedef struct _PangoEngineRange PangoEngineRange;
typedef struct _PangoEngine PangoEngine;
typedef struct _PangoEngineLang PangoEngineLang;
typedef struct _PangoEngineShape PangoEngineShape;

/* 64'ths of a point - 1/4608 in, 5.51 * 10^-5 in. */
typedef guint32 PangoGlyphUnit;

/* Information about a segment of text with a consistent
 * shaping/language engine and bidirectional level
 */
struct _PangoAnalysis {
  PangoEngineShape *shape_engine;
  PangoEngineLang *lang_engine;
  guint8 level;
};

struct _PangoItem {
  gint offset;
  gint length;
  gint num_chars;
  PangoAnalysis analysis;
};

/* Sort of like a GC - application set information about how
 * to handle scripts
 */

typedef enum {
  PANGO_DIRECTION_LTR,
  PANGO_DIRECTION_RTL,
  PANGO_DIRECTION_TTB
} PangoDirection;

struct _PangoContext {
  gchar *lang;
  gchar *render_type;
  PangoDirection direction;
};

/* Language tagging information
 */
struct _PangoLangRange
{
  gint start;
  gint length;
  gchar *lang;
};

/* Break a string of Unicode characters into segments with
 * consistent shaping/language engine and bidrectional level.
 * Returns a GList of PangoItem's
 */
GList *pango_itemize (PangoContext   *context, 
                         gchar            *text, 
                         gint              length,
			 PangoLangRange *lang_info,
			 gint              n_langs);

/* Logical attributes of a character
 */
struct _PangoLogAttr {
  guint is_break : 1;  /* Break in front of character */
  guint is_white : 1;
  guint is_char_stop : 1;
  guint is_word_stop : 1;
  /* Uniscript has is_invalid  */
};

/* Determine information about cluster/word/line breaks in a string
 * of Unicode text.
 */
void pango_break (gchar           *text, 
                     gint             length, 
                     PangoAnalysis *analysis, 
                     PangoLogAttr  *attrs);

/*
 * FONT OPERATIONS
 */

/* This structure represents a logical font */
struct _PangoFont {
  PangoFontClass *klass;

  /*< private >*/
  gint ref_count;
  GData *data;
};

struct _PangoFontClass {
  void (*destroy) (PangoFont *font);
};
 
void     pango_font_init     (PangoFont      *font);
void     pango_font_ref      (PangoFont      *font);
void     pango_font_unref    (PangoFont      *font);
gpointer pango_font_get_data (PangoFont      *font,
			      gchar          *key);
void     pango_font_set_data (PangoFont      *font,
			      gchar          *key,
			      gpointer        data,
			      GDestroyNotify  destroy_func);

/* A component of a font. The contents of this are completely
 * rendering system dependent
 */
struct _PangoCFont {
  PangoCFontClass *klass;

  /*< private >*/
  gint ref_count;
};

struct _PangoCFontClass {
  void (*destroy) (PangoCFont *cfont);
};

void pango_cfont_init  (PangoCFont *font);
void pango_cfont_ref   (PangoCFont *font);
void pango_cfont_unref (PangoCFont *font);


/*
 * GLYPH STORAGE
 */

/* A index of a glyph into a PangoCFont. Rendering system dependent
 */
typedef guint32 PangoGlyphIndex;

/* A single glyph 
 */
struct _PangoGlyph
{
  PangoGlyphIndex  glyph;
  PangoCFont *font;
};

/* Positioning information about a glyph
 */
struct _PangoGlyphGeometry
{
  PangoGlyphUnit width;
  PangoGlyphUnit x_offset;  
  PangoGlyphUnit y_offset;
};

/* Visual attributes of a glyph
 */
struct _PangoGlyphVisAttr
{
  guint is_cluster_start : 1;
};

/* A string of glyphs with positional information and visual attributes -
 * ready for drawing
 */
struct _PangoGlyphString {
  gint num_glyphs;
  PangoGlyph *glyphs;
  PangoGlyphGeometry *geometry;
  PangoGlyphVisAttr *attrs;

  /* This is a memory inefficient way of representing the
   * information here - each value gives the character index
   * of the start of the cluster to which the glyph belongs.
   */
  gint *log_clusters;

  /*< private >*/
  gint space;
};

PangoGlyphString *pango_glyph_string_new      (void);
void              pango_glyph_string_set_size (PangoGlyphString *string,
					       gint              new_len);
void              pango_glyph_string_free     (PangoGlyphString *string);

/* Turn a string of characters into a string of glyphs
 */
void pango_shape (PangoFont      *font, 
                     gchar            *text, 
                     gint              length, 
                     PangoAnalysis *analysis,
                     PangoGlyphString     *glyphs);

/* [ pango_place - subsume into g_script_shape? ] */

GList *pango_reorder_items (GList *logical_items);

/* Take a PangoGlyphString and add justification to fill to a
 * given width
 */
void pango_justify (PangoGlyphString *glyphs,
		    gint              new_line_width,
		    gint              min_kashida_width);

/* For selection/cursor positioning - turn a character position into a
 * X position.
 */
void pango_cp_to_x (gchar            *text,
		    gint              length,
		    PangoAnalysis    *analysis,
		    PangoGlyphString *glyphs,
		    gint              char_pos,
		    gboolean          trailing,
		    gint             *x_pos);


/* For selection/cursor positioning - turn a X position into a
 * character position
 */
void pango_x_to_cp (gchar            *text,
		    gint              length,
		    PangoAnalysis    *analysis,
		    PangoGlyphString *glyphs,
		    gint              x_pos,
		    gint             *char_pos,
		    gint             *trailing);

/* Module API */

#define PANGO_ENGINE_TYPE_LANG "PangoEngineLang"
#define PANGO_ENGINE_TYPE_SHAPE "PangoEngineShape"

#define PANGO_RENDER_TYPE_NONE "PangoRenderNone"

struct _PangoEngineRange 
{
  guint32 start;
  guint32 end;
  gchar *langs;
};

struct _PangoEngineInfo
{
  gchar *id;
  gchar *engine_type;
  gchar *render_type;
  PangoEngineRange *ranges;
  gint n_ranges;
};

struct _PangoEngine
{
  gchar *id;
  gchar *type;
  gint length;
};

struct _PangoEngineLang
{
  PangoEngine engine;
  void (*script_break) (gchar            *text,
			gint             len,
			PangoAnalysis *analysis,
			PangoLogAttr  *attrs);
};

struct _PangoEngineShape {
  PangoEngine engine;
  void (*script_shape) (PangoFont     *font,
			gchar           *text,
			gint             length,
			PangoAnalysis *analysis,
			PangoGlyphString    *glyphs);
};

/* A module should export the following functions */

void         script_engine_list   (PangoEngineInfo **engines,
				   gint             *n_engines);
PangoEngine *script_engine_load   (const gchar      *id);
void         script_engine_unload (PangoEngine      *engine);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __PANGO_H__ */