summaryrefslogtreecommitdiffstats
path: root/tqtinterface/qt4/include/private/qt4_harfbuzz/src/harfbuzz-shape.h
blob: e4b5f9ad8af1f4f0cddac6be8291961a0d59b7af (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
/*
 * Copyright (C) 2006  Red Hat, Inc.
 *
 * This is part of HarfBuzz, an OpenType Layout engine library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Owen Taylor
 */

#include <stdint.h>

/* Base Types */

typedef hb_uint16 HB_CodePoint; /* UTF-16 codepoint (not character ) */
typedef char HB_Boolean;
typedef hb_uint32 HB_Fixed; /* 26.6 */
typedef hb_uint32 HB_Glyph;
typedef hb_uint32 HB_Unichar;

/* Metrics reported by the font backend for use of the shaper */
typedef struct _HB_GlyphMetrics HB_GlyphMetrics;
struct _HB_GlyphMetrics
{
    HB_Fixed advance;
    
    /* Do we need ink/logical extents for the glyph here? */
};

/*
 * HB_Font: Abstract font interface.
 *  First pass of this might just have FT_Face *getFace();
 */
typedef struct _HB_Font HB_Font;
typedef struct _HB_FontClass HB_FontClass;

struct HB_FontClass {
    HB_Glyph   (*charToGlyph)(HB_Font *font, HB_Unichar chr);
    void       (*getMetrics)(HB_Font *font, HB_Glyph glyph, HB_GlyphMetrics *metrics);
    HB_Boolean (*getSFontTable)(HB_Font *font, void **cookie, char **start, int *len);
    HB_Boolean (*freeSFontTable)(void **cookie);
};

struct _HB_Font {
    HB_FontClass *clazz;
};

/*
 * Language tags, of the form en-us; represented as interned, canonicalized
 * strings. hb_language_from_string("en_US"), hb_language_from_string("en-us")
 * both return the same (pointer-comparable) HB_Language).
 */
typedef struct HB_Language_ *HB_Language;

HB_Language hb_language_from_string(const char *str);
const char *hb_language_to_string(HB_Language language);

/* Special treatment for the edges of runs.
 */
typedef enum {
    HB_RUN_EDGE_LINE_VISUAL_EDGE    = 1 << 0,
    HB_RUN_EDGE_LINE_LOGICAL_EDGE   = 1 << 1,
    HB_RUN_EDGE_LINE_ADD_HYPHEN     = 1 << 2  /* ???? */
} HB_RunEdge;

/* Defines optional informaiton in HB_ShapeInput; this allows extension
 * of HB_ShapeInput while keeping binary compatibility
 */
typedef enum {
    HB_SHAPE_START_TYPE = 1 << 0,
    HB_SHAPE_END_TYPE   = 1 << 1
} HB_ShapeFlags;

/* Attributes types are described by "interned strings"; this is a little
 * annoying if you want to write a switch statement, but keeps things
 * simple.
 */
typedef struct _HB_AttributeType *HB_AttributeType;

HB_AttributeType hb_attribute_type_from_string(const char *str);
const char *hb_attribute_type_to_string(HB_AttributeType attribute_type);

struct HB_Attribute {
    HB_AttributeType type;
    int start; 
    int end;
};


/**
 * You could handle this like HB_Language, but an enum seems a little nicer;
 * another approach would be to use OpenType script tags.
 */
typedef enum {
    HB_SCRIPT_LATIN
    /* ... */
} HB_ShapeScript;

/* This is just the subset of direction information needed by the shaper */
typedef enum {
    HB_DIRECTION_LTR,
    HB_DIRECTION_RTL,
    HB_DIRECTION_TTB
} HB_Direction;

typedef struct _HB_ShapeInput HB_ShapeInput;
struct _HB_ShapeInput {
    /* Defines what fields the caller has initialized - fields not in
     * the enum are mandatory.
     */
    HB_ShapeFlags flags;
    
    HB_CodePoint *text;
    int length;       /* total length of text to shape */
    int shape_offset; /* start of section to shape */
    int shape_length; /* number of code points to shape */

    HB_Direction direction;
    HB_ShapeScript script;
    HB_Language language;

    HB_AttributeType *attributes;
    int n_attributes;

    HB_RunEdge start_type;
    HB_RunEdge end_type;
};

struct HB_GlyphItem {
    HB_Glyph glyph;
    
    HB_Fixed x_offset;
    HB_Fixed y_offset;
    HB_Fixed advance;

    /* Add kashida information, etc, here */
};

typedef enum {
    HB_RESULT_SUCCESS,
    HB_RESULT_NO_MEMORY,
    HB_SHAPE_RESULT_FAILED
} HB_Result;

/*
 * Buffer for output 
 */
typedef struct _HB_GlyphBuffer HB_GlyphBuffer;
struct _HB_GlyphBuffer {
    int glyph_item_size;
    int total_glyphs;
    
    int *log_clusters; /* Uniscribe style */
    int cluster_space;
  
    int glyph_space;
    void *glyph_buffer;
};

/* Making this self-allocating simplifies writing shapers and
 * also keeps things easier for caller. item_size passed in
 * must be at least sizeof(HB_GlyphItem) but can be bigger,
 * to accomodate application structures that extend HB_GlyphItem.
 * The allocated items will be zero-initialized.
 *
 * (Hack: Harfbuzz could choose to use even a *bigger* item size
 * and stick internal information before the public item structure.
 * This hack could possibly be used to unify this with HB_Buffer)
 */
HB_GlyphBuffer *hb_glyph_buffer_new             (size_t item_size);
void            hb_glyph_buffer_clear           (HB_GlyphBuffer *buf);
HB_Result       hb_glyph_buffer_extend_glyphs   (HB_GlyphBuffer *buf, int n_items);
HB_Result       hb_glyph_buffer_extend_clusters (HB_GlyphBuffer *buf, int n_clusters);
void            hb_glyph_buffer_free            (HB_GlyphBuffer *buf);


/* Accessor for a particular glyph */
#define HB_GLYPH_BUFFER_ITEM(buffer, index)

/*
 * Main shaping function
 */
HB_Result hb_shape(HB_ShapeInput *input, HB_GlyphBuffer *output);