-
Notifications
You must be signed in to change notification settings - Fork 3
/
glyphedit.h
335 lines (275 loc) · 8.76 KB
/
glyphedit.h
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
/*
* Copyright 2008 Department of Mathematical Sciences, New Mexico State University
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* DEPARTMENT OF MATHEMATICAL SCIENCES OR NEW MEXICO STATE UNIVERSITY BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _h_glyphedit
#define _h_glyphedit
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include "bdfP.h"
G_BEGIN_DECLS
typedef enum {
GLYPHEDIT_NONE = 0,
GLYPHEDIT_SELECT,
GLYPHEDIT_DRAW,
GLYPHEDIT_MOVE,
GLYPHEDIT_COPY,
GLYPHEDIT_FLIP_HORIZONTAL,
GLYPHEDIT_FLIP_VERTICAL,
GLYPHEDIT_SHEAR,
GLYPHEDIT_ROTATE_LEFT,
GLYPHEDIT_ROTATE_RIGHT,
GLYPHEDIT_ROTATE,
GLYPHEDIT_SHIFT_UP_LEFT,
GLYPHEDIT_SHIFT_UP,
GLYPHEDIT_SHIFT_UP_RIGHT,
GLYPHEDIT_SHIFT_LEFT,
GLYPHEDIT_SHIFT_RIGHT,
GLYPHEDIT_SHIFT_DOWN_LEFT,
GLYPHEDIT_SHIFT_DOWN,
GLYPHEDIT_SHIFT_DOWN_RIGHT
} GlypheditOperation;
/*
* The macros for accessing various parts of the widget class.
*/
#define GLYPHEDIT(o) \
(G_TYPE_CHECK_INSTANCE_CAST((o), glyphedit_get_type(), Glyphedit))
#define GLYPHEDIT_CLASS(c) \
(G_TYPE_CHECK_CLASS_CAST((c), glyphedit_get_type(), GlypheditClass))
#define IS_GLYPHEDIT(o) G_TYPE_CHECK_INSTANCE_TYPE((o), glyphedit_get_type())
#define IS_GLYPHEDIT_CLASS(c) \
(G_TYPE_CHECK_CLASS_TYPE((c), glyphedit_get_type()))
#define GLYPHEDIT_GET_CLASS(o) \
(G_TYPE_INSTANCE_GET_CLASS((o), glyphedit_get_type(), GlypheditClass))
typedef struct _Glyphedit Glyphedit;
typedef struct _GlypheditClass GlypheditClass;
struct _Glyphedit {
GtkWidget widget;
bdf_glyph_grid_t *grid;
gboolean show_cap_height;
gboolean show_x_height;
#if GTK_CHECK_VERSION(3, 0, 0)
GdkRGBA baselineColor;
GdkRGBA selectionColor;
GdkRGBA boundsColor;
#else
GdkColor baselineColor;
GdkColor selectionColor;
GdkColor boundsColor;
#endif
guint16 *colors;
/*
* Buffer for drawing grayscale pixels and color spots.
*/
guchar *spot;
guint spot_used;
guint spot_size;
gboolean owns_clipboard;
GlypheditOperation op;
GlypheditOperation pending_op;
GdkPoint sel_start;
GdkPoint sel_end;
gint last_x;
gint last_y;
gint lcolor;
gint cidx;
guint16 default_pixel_size;
guint16 pixel_size;
guint16 vmargin;
guint16 hmargin;
guint16 border;
gboolean mouse_down;
};
struct _GlypheditClass {
GtkWidgetClass parent_class;
/*
* Cursor.
*/
GdkCursor *cursor;
/*
* Signal handlers.
*/
void (*glyph_modified)(GtkWidget *, gpointer, gpointer);
void (*pointer_moved)(GtkWidget *, gpointer, gpointer);
void (*operation_change)(GtkWidget *, gpointer, gpointer);
void (*color_change)(GtkWidget *, gpointer, gpointer);
};
/**************************************************************************
*
* Structures used for the API.
*
**************************************************************************/
/*
* List of callback reasons.
*/
enum {
GLYPHEDIT_GLYPH_MODIFIED = 0,
GLYPHEDIT_POINTER_MOVED,
GLYPHEDIT_OPERATION_CHANGE,
GLYPHEDIT_COLOR_CHANGE
};
/*
* The structure passed back in the signals.
*/
typedef struct {
gint reason;
bdf_bitmap_t *image;
bdf_metrics_t *metrics;
GlypheditOperation operation;
gint x;
gint y;
gint color;
} GlypheditSignalInfo;
/**************************************************************************
*
* General API
*
**************************************************************************/
extern GType glyphedit_get_type(void);
extern GtkWidget *glyphedit_new(const gchar *prop1, ...);
extern GtkWidget *glyphedit_newv(bdf_glyph_grid_t *grid,
guint16 default_pixel_size,
gboolean show_x_height,
gboolean show_cap_height,
guint16 *colors);
/*
* Get the encoding of the current glyph.
*/
extern gint32 glyphedit_get_encoding(Glyphedit *gw);
/*
* Get the current glyph metrics or the current font metrics.
*/
extern void glyphedit_get_glyph_metrics(Glyphedit *gw, bdf_metrics_t *metrics);
extern void glyphedit_get_font_metrics(Glyphedit *gw, bdf_metrics_t *metrics);
/*
* Get the PSF Unicode mappings.
*/
extern bdf_psf_unimap_t *glyphedit_get_psf_mappings(Glyphedit *gw);
/*
* Changes device width, width, and height values from the metrics supplied.
*/
extern void glyphedit_set_metrics(Glyphedit *gw, bdf_metrics_t *metrics);
/*
* Get the glyph spacing.
*/
extern gint glyphedit_get_spacing(Glyphedit *gw);
/*
* Changes the font spacing and the mono width if necessary.
*/
extern void glyphedit_set_spacing(Glyphedit *gw, gint spacing,
guint16 monowidth);
/*
* Get and set the operation.
*/
extern void glyphedit_set_operation(Glyphedit *gw, GlypheditOperation op);
extern GlypheditOperation glyphedit_get_operation(Glyphedit *gw);
extern void glyphedit_set_pixel_size(Glyphedit *gw, guint pixel_size);
extern guint glyphedit_get_pixel_size(Glyphedit *gw);
/*
* Sets the glyph grid.
*/
extern void glyphedit_set_grid(Glyphedit *gw, bdf_glyph_grid_t *grid);
/*
* Check to see if the glyph or associated info has been modified.
*/
extern gboolean glyphedit_get_modified(Glyphedit *gw);
extern void glyphedit_set_modified(Glyphedit *gw, gboolean modified);
extern void glyphedit_signal_modified(Glyphedit *gw);
/*
* Determine if a selection is in progress.
*/
extern gboolean glyphedit_get_selecting(Glyphedit *gw);
/*
* Check to see if the glyph editor clipboard is empty or not.
*/
extern gboolean glyphedit_clipboard_empty(Glyphedit *gw);
/*
* Get the glyph image from the editor.
*/
extern void glyphedit_get_image(Glyphedit *gw, bdf_bitmap_t *image);
/*
* Retrieve the glyph grid.
*/
extern bdf_glyph_grid_t *glyphedit_get_grid(Glyphedit *gw);
/*
* Get the glyph itself.
*/
extern bdf_glyph_t *glyphedit_get_glyph(Glyphedit *gw, gboolean *unencoded);
/*
* Show or hide the cap height.
*/
extern void glyphedit_set_show_cap_height(Glyphedit *gw, gboolean show);
/*
* Show or hide the x height.
*/
extern void glyphedit_set_show_x_height(Glyphedit *gw, gboolean show);
/*
* Crop the glyph bitmap to get rid of empty rows and columns around the
* glyph.
*/
extern void glyphedit_crop_glyph(Glyphedit *gw);
/*
* Shift the bitmap horizontally, vertically or a combination of both.
*/
extern void glyphedit_shift_glyph(Glyphedit *gw, gint16 xcount, gint16 ycount);
/*
* Rotate the bitmap clockwise (positive count) or counter-clockwise
* (negative count).
*/
extern void glyphedit_rotate_glyph(Glyphedit *w, gint16 degrees);
/*
* Shear the bitmap clockwise (positive count) or counter-clockwise
* (negative count). Limited to the range of [-20,20] degrees.
*/
extern void glyphedit_shear_glyph(Glyphedit *gw, gint16 degrees);
/*
* Make the glyph bold.
*/
extern void glyphedit_embolden_glyph(Glyphedit *gw);
/*
* Flip the bitmap horizontally or vertically.
*/
extern void glyphedit_flip_glyph(Glyphedit *gw, GtkOrientation direction);
/*
* Change to the draw, select, move, or copy operation.
*/
extern void glyphedit_change_operation(Glyphedit *gw, GlypheditOperation op);
/*
* Change the current color index.
*/
extern void glyphedit_set_color(Glyphedit *gw, gint idx);
/*
* Insert a bitmap from some outside source.
*/
extern void glyphedit_insert_bitmap(Glyphedit *gw, bdf_bitmap_t *bitmap);
/*
* Functions explicitly for importing and exporting XBM bitmaps.
*/
extern int glyphedit_import_xbm(Glyphedit *gw, gchar *filename);
extern int glyphedit_export_xbm(Glyphedit *gw, gchar *filename);
/*
* Functions dealing with the selection.
*/
extern void glyphedit_copy_selection(Glyphedit *gw);
extern void glyphedit_cut_selection(Glyphedit *gw);
extern void glyphedit_paste_selection(Glyphedit *gw);
extern void glyphedit_select_all(Glyphedit *gw);
G_END_DECLS
#endif /* _h_glyphedit */