1 |
673 |
markom |
/*
|
2 |
|
|
* hre.h: API for Handwriting Recognition Engine on Unix
|
3 |
|
|
* Author: James Kempf
|
4 |
|
|
* Created On: Wed Oct 28 11:30:43 1992
|
5 |
|
|
* Last Modified By: James Kempf
|
6 |
|
|
* Last Modified On: Fri Sep 23 13:49:26 1994
|
7 |
|
|
* Update Count: 74
|
8 |
|
|
* Copyright (c) 1994 by Sun Microsystems Computer Company
|
9 |
|
|
* All rights reserved.
|
10 |
|
|
*
|
11 |
|
|
* Use and copying of this software and preparation of
|
12 |
|
|
* derivative works based upon this software are permitted.
|
13 |
|
|
* Any distribution of this software or derivative works
|
14 |
|
|
* must comply with all applicable United States export control
|
15 |
|
|
* laws.
|
16 |
|
|
*
|
17 |
|
|
* This software is made available as is, and Sun Microsystems
|
18 |
|
|
* Computer Company makes no warranty about the software, its
|
19 |
|
|
* performance, or its conformity to any specification
|
20 |
|
|
*/
|
21 |
|
|
|
22 |
|
|
#ifndef _HRE_H_
|
23 |
|
|
|
24 |
|
|
#define _HRE_H_
|
25 |
|
|
|
26 |
|
|
#include <sys/types.h>
|
27 |
|
|
#include <stdlib.h>
|
28 |
|
|
/*#include <libintl.h>*/
|
29 |
|
|
|
30 |
|
|
#ifdef ELX
|
31 |
|
|
typedef unsigned int wchar_t;
|
32 |
|
|
#endif
|
33 |
|
|
|
34 |
|
|
/* Scalar Type Definitions */
|
35 |
|
|
|
36 |
|
|
/*For better readibility.*/
|
37 |
|
|
|
38 |
|
|
#ifndef true
|
39 |
|
|
|
40 |
|
|
typedef u_char bool;
|
41 |
|
|
|
42 |
|
|
#define true 1
|
43 |
|
|
#define false 0
|
44 |
|
|
|
45 |
|
|
#endif
|
46 |
|
|
|
47 |
|
|
/*For pointers to extra functions on recognizer.*/
|
48 |
|
|
|
49 |
|
|
typedef void (*rec_fn)();
|
50 |
|
|
|
51 |
|
|
/*
|
52 |
|
|
*rec_confidence is an integer between 0-100 giving the confidence of the
|
53 |
|
|
* recognizer in a particular result.
|
54 |
|
|
*/
|
55 |
|
|
|
56 |
|
|
typedef u_char rec_confidence;
|
57 |
|
|
|
58 |
|
|
/*Time value. This is the same as in X.h, so we conditionally define.*/
|
59 |
|
|
/* ari -- no it's not. *SIGH* there's an ifdef in X.h specifically */
|
60 |
|
|
/* for osf. */
|
61 |
|
|
#ifndef X_H
|
62 |
|
|
|
63 |
|
|
#ifndef __osf__
|
64 |
|
|
typedef unsigned long Time;
|
65 |
|
|
#else
|
66 |
|
|
typedef unsigned int Time;
|
67 |
|
|
#endif
|
68 |
|
|
/* (mips) typedef unsigned long Time; */
|
69 |
|
|
/* (osf) typedef unsigned int Time; */
|
70 |
|
|
|
71 |
|
|
#endif
|
72 |
|
|
|
73 |
|
|
/**************** RECOGNIZER CONFIGURATION INFORMATION *******************/
|
74 |
|
|
|
75 |
|
|
/*
|
76 |
|
|
* Recognizer information. Gives the locale, category of the character
|
77 |
|
|
* set returned by the recognizer, and any subsets to which the
|
78 |
|
|
* recognition can be limited. The locale and category should be
|
79 |
|
|
* suitable for the setlocale(3). Those recognizers which don't do text
|
80 |
|
|
* can simply report a blank locale and category, and report the
|
81 |
|
|
* graphics types they recognize in the subset.
|
82 |
|
|
*/
|
83 |
|
|
|
84 |
|
|
typedef struct {
|
85 |
|
|
char* ri_locale; /*The locale of the character set.*/
|
86 |
|
|
char* ri_name; /*Complete pathname to the recognizer.*/
|
87 |
|
|
char** ri_subset; /*Null terminated list of subsets supported*/
|
88 |
|
|
} rec_info;
|
89 |
|
|
|
90 |
|
|
/*These define a set of common character subset names.*/
|
91 |
|
|
|
92 |
|
|
#define GESTURE "GESTURE" /* gestures only */
|
93 |
|
|
#define MATHSET "MATHSET" /* %^*()_+={}<>,/. */
|
94 |
|
|
#define MONEYSET "MONEYSET" /* $, maybe cent, pound, and yen */
|
95 |
|
|
#define WHITESPACE "WHITESPACE" /* gaps are recognized as space */
|
96 |
|
|
#define KANJI_JIS1 "KANJI_JIS1" /* the JIS1 kanji only */
|
97 |
|
|
#define KANJI_JIS1_PLUS "KANJI_JIS1_PLUS" /* JIS1 plus some JIS2 */
|
98 |
|
|
#define KANJI_JIS2 "KANJI_JIS2" /* the JIS1 + JIS2 kanji */
|
99 |
|
|
#define HIRIGANA "HIRIGANA" /* the hirigana */
|
100 |
|
|
#define KATAKANA "KATAKANA" /* the katakana */
|
101 |
|
|
#define UPPERCASE "UPPERCASE" /* upper case alphabetics, no digits */
|
102 |
|
|
#define LOWERCASE "LOWERCASE" /* lower case alphabetics, no digits */
|
103 |
|
|
#define DIGITS "DIGITS" /* digits 0-9 only */
|
104 |
|
|
#define PUNCTUATION "PUNCTUATION" /* \!-;'"?()&., */
|
105 |
|
|
#define NONALPHABETIC "NONALPHABETIC" /* all nonalphabetics, no digits */
|
106 |
|
|
#define ASCII "ASCII" /* the ASCII character set */
|
107 |
|
|
#define ISO_LATIN12 "ISO_LATIN12" /* The ISO Latin 12 characters */
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
/******************** RECOGNITION INPUT STRUCTURES ***********************/
|
111 |
|
|
|
112 |
|
|
/*
|
113 |
|
|
* WINDOW SYSTEM INTERFACE
|
114 |
|
|
*/
|
115 |
|
|
|
116 |
|
|
/*Basic point. Note that it is identical to XTimeCoord, for easy conversion*/
|
117 |
|
|
|
118 |
|
|
typedef struct {
|
119 |
|
|
Time time;
|
120 |
|
|
short x, y;
|
121 |
|
|
} pen_point;
|
122 |
|
|
|
123 |
|
|
/*Bounding box. Structurally identical to XRectangle.*/
|
124 |
|
|
|
125 |
|
|
typedef struct {
|
126 |
|
|
short x,y; /*Upper left corner.*/
|
127 |
|
|
short width,height; /*Width and height.*/
|
128 |
|
|
} pen_rect;
|
129 |
|
|
|
130 |
|
|
/* Button flags - pen's button configuration. */
|
131 |
|
|
|
132 |
|
|
#define TABLET_TIP 0x1 /*tip switch*/
|
133 |
|
|
#define TABLET_BUTTON1 0x2 /*one barrel switch*/
|
134 |
|
|
#define TABLET_BUTTON2 0x4 /*two barrel switches*/
|
135 |
|
|
#define TABLET_BUTTON3 0x8 /*three barrel switches*/
|
136 |
|
|
|
137 |
|
|
/* Pen flags - additional state information that can be reported by the pen.*/
|
138 |
|
|
|
139 |
|
|
#define TABLET_PROXIMITY 0x1 /*can report position when pen not in contact*/
|
140 |
|
|
#define TABLET_RELATIVE 0x2 /*can report relative coords, like mouse*/
|
141 |
|
|
#define TABLET_ABSOLUTE 0x4 /*can report absolute co-ordinates*/
|
142 |
|
|
#define TABLET_RANGE 0x8 /*can report when pen goes out of range*/
|
143 |
|
|
#define TABLET_INVERT 0x10 /*can report when pen is inverted*/
|
144 |
|
|
#define TABLET_TOUCH 0x20 /*finger can be used as pen*/
|
145 |
|
|
|
146 |
|
|
/* Angle flags - reporting of information about the pen angle. */
|
147 |
|
|
|
148 |
|
|
#define TABLET_ANGLEX 0x1 /*can report angle with the x axis*/
|
149 |
|
|
#define TABLET_ANGLEY 0x2 /*can report angle with the y axis*/
|
150 |
|
|
#define TABLET_ROTATE 0x4 /*can report barrel rotation*/
|
151 |
|
|
|
152 |
|
|
/*
|
153 |
|
|
* Sensor flags - configuration and reporting capabilities
|
154 |
|
|
* of the tablet's sensor panel.
|
155 |
|
|
*/
|
156 |
|
|
|
157 |
|
|
#define TABLET_INTEGRATED 0x1 /*sensor panel is integrated with display*/
|
158 |
|
|
#define TABLET_PRESSURE 0x2 /*sensor panel can report pressure*/
|
159 |
|
|
#define TABLET_HEIGHT 0x4 /*sensor panel can report height*/
|
160 |
|
|
|
161 |
|
|
/* Units flags - in what units x and y coordinate data reported.*/
|
162 |
|
|
|
163 |
|
|
#define TABLET_DIMENSIONLESS 0x1 /*no units*/
|
164 |
|
|
#define TABLET_ENGLISH 0x2 /*thousandths of an inch*/
|
165 |
|
|
#define TABLET_METRIC 0x4 /*tenths of a millimeter*/
|
166 |
|
|
|
167 |
|
|
/* Origin flags - where the tablet's origin is located.*/
|
168 |
|
|
|
169 |
|
|
#define TABLET_ULEFT 0x1 /*upper left corner*/
|
170 |
|
|
#define TABLET_URIGHT 0x2 /*upper right corner*/
|
171 |
|
|
#define TABLET_LLEFT 0x4 /*lower left corner*/
|
172 |
|
|
#define TABLET_LRIGHT 0x8 /*lower right corner*/
|
173 |
|
|
#define TABLET_CENTER 0x10 /*center of tablet*/
|
174 |
|
|
|
175 |
|
|
/*
|
176 |
|
|
* Tablet capabilities structure. Defines basic information about tablet
|
177 |
|
|
* configuration.
|
178 |
|
|
*/
|
179 |
|
|
|
180 |
|
|
typedef struct {
|
181 |
|
|
char tc_id[20]; /*tablet identifier, null terminated*/
|
182 |
|
|
u_short tc_button; /*button capabilities*/
|
183 |
|
|
u_short tc_pen; /*pen capabilities*/
|
184 |
|
|
u_short tc_angle; /*pen angle reporting*/
|
185 |
|
|
u_int tc_sensor : 8; /*sensor capabilities*/
|
186 |
|
|
u_int tc_units : 8; /*units for xy reporting*/
|
187 |
|
|
u_int tc_default_units : 8; /*default units*/
|
188 |
|
|
u_int tc_origin : 8; /*where origin located*/
|
189 |
|
|
short tc_x[2]; /*minimum/maximum x*/
|
190 |
|
|
short tc_y[2]; /*minimum/maximum y*/
|
191 |
|
|
short tc_pressure[2]; /*minimum/maximum pressure/height*/
|
192 |
|
|
u_int tc_sample_rate; /*rate of event reporting*/
|
193 |
|
|
u_int tc_sample_distance; /*xy coords per sample*/
|
194 |
|
|
|
195 |
|
|
} tablet_cap;
|
196 |
|
|
|
197 |
|
|
/*
|
198 |
|
|
* PEN STROKE DATA
|
199 |
|
|
*/
|
200 |
|
|
|
201 |
|
|
/*
|
202 |
|
|
* Pen state parameters. "Basic" state is pen up/down, barrel buttons
|
203 |
|
|
* (if any), and in/out of range. Others may be reported by particular pens.
|
204 |
|
|
*/
|
205 |
|
|
|
206 |
|
|
typedef struct {
|
207 |
|
|
u_short pt_button; /*button state - same as tc_button*/
|
208 |
|
|
u_short pt_pen; /*other state - same as tc_pen*/
|
209 |
|
|
short pt_pressure; /*Pressure. + against tablet, - above tablet.*/
|
210 |
|
|
double pt_anglex; /*angle of tilt in the x direction, in radians.*/
|
211 |
|
|
double pt_angley; /*angle of tilt in the y direction, in radians.*/
|
212 |
|
|
double pt_barrelrotate; /*angle of barrel rotation, in radians.*/
|
213 |
|
|
} pen_state;
|
214 |
|
|
|
215 |
|
|
/*
|
216 |
|
|
* Stroke structure.
|
217 |
|
|
*/
|
218 |
|
|
|
219 |
|
|
typedef struct {
|
220 |
|
|
u_int ps_npts; /*Number of pen_point in array.*/
|
221 |
|
|
pen_point* ps_pts; /*Array of points.*/
|
222 |
|
|
u_int ps_nstate; /*Number of pen_state in array.*/
|
223 |
|
|
u_int* ps_trans; /*State transition point indicies.*/
|
224 |
|
|
pen_state* ps_state; /*Array of state.*/
|
225 |
|
|
} pen_stroke;
|
226 |
|
|
|
227 |
|
|
/*
|
228 |
|
|
* RECOGNITION CONTEXT
|
229 |
|
|
*/
|
230 |
|
|
|
231 |
|
|
/* Structure for reporting writing area geometric constraints. */
|
232 |
|
|
|
233 |
|
|
typedef struct {
|
234 |
|
|
pen_rect pr_area;
|
235 |
|
|
short pr_row, pr_col;
|
236 |
|
|
double pr_rowpitch, pr_colpitch;
|
237 |
|
|
} pen_frame;
|
238 |
|
|
|
239 |
|
|
/*User preferences*/
|
240 |
|
|
|
241 |
|
|
#define REC_RIGHTH 0x0 /*Right-handed writer.*/
|
242 |
|
|
#define REC_LEFTH 0x1 /*Left-handed writer.*/
|
243 |
|
|
|
244 |
|
|
/*
|
245 |
|
|
* Writing direction. There will generally be a preferred and a
|
246 |
|
|
* secondary direction (example: English is left to right, then
|
247 |
|
|
* top to bottom). High byte has preferred, low byte secondary.
|
248 |
|
|
* The recognizer can ignore this and key off of locale.
|
249 |
|
|
*/
|
250 |
|
|
|
251 |
|
|
#define REC_DEFAULT 0x0 /*Use default direction.*/
|
252 |
|
|
#define REC_BOTTOM_TOP 0x1 /*Bottom to top.*/
|
253 |
|
|
#define REC_LEFT_RIGHT 0x2 /*Left to right.*/
|
254 |
|
|
#define REC_RIGHT_LEFT 0x3 /*Right to left.*/
|
255 |
|
|
#define REC_TOP_BOTTOM 0x4 /*Top to bottom.*/
|
256 |
|
|
|
257 |
|
|
/*
|
258 |
|
|
* Structure for describing a set of letters to constrain recognition.
|
259 |
|
|
* ls_type is the same as the re_type field for rec_element below.
|
260 |
|
|
*/
|
261 |
|
|
|
262 |
|
|
typedef struct _letterset {
|
263 |
|
|
char ls_type;
|
264 |
|
|
union _ls_set {
|
265 |
|
|
char* aval;
|
266 |
|
|
wchar_t* wval;
|
267 |
|
|
} ls_set;
|
268 |
|
|
} letterset;
|
269 |
|
|
|
270 |
|
|
/*
|
271 |
|
|
* Recognition context. Describes the context in which the pen stroke
|
272 |
|
|
* data was obtained and in which recognition should proceed.
|
273 |
|
|
*/
|
274 |
|
|
|
275 |
|
|
typedef struct {
|
276 |
|
|
u_short rc_upref; /*User preference. */
|
277 |
|
|
bool rc_gesture; /*Look for gesture if true.*/
|
278 |
|
|
u_short rc_direction; /*Primary and secondary writing direction.*/
|
279 |
|
|
rec_confidence rc_cutoff; /*Cut off recognition below this confidence*/
|
280 |
|
|
tablet_cap* rc_tinfo; /*Tablet capabilities.*/
|
281 |
|
|
char** rc_subset; /*Confine recognition to these subsets.*/
|
282 |
|
|
pen_frame* rc_frame; /*If nonNULL, writing area geometry.*/
|
283 |
|
|
wordset rc_wordset; /*If nonNULL, dictionary.*/
|
284 |
|
|
letterset rc_letterset; /*If nonNULL, constrain to these chars.*/
|
285 |
|
|
void* rc_context; /*For recognizer-specific context.*/
|
286 |
|
|
} rc;
|
287 |
|
|
|
288 |
|
|
/************************** GESTURES **************************/
|
289 |
|
|
|
290 |
|
|
/*
|
291 |
|
|
* Gestures. The toolkit initializes the recognizer with a
|
292 |
|
|
* set of gestures having appropriate callbacks.
|
293 |
|
|
* When a gesture is recognized, it is returned as part of a
|
294 |
|
|
* recognition element. The recognizer fills in the bounding
|
295 |
|
|
* box and hotspots. The toolkit fills in any additional values,
|
296 |
|
|
* such as the current window, and calls the callback.
|
297 |
|
|
*/
|
298 |
|
|
|
299 |
|
|
typedef struct Gesture {
|
300 |
|
|
char* g_name; /*The gesture's name.*/
|
301 |
|
|
u_int g_nhs; /*Number of hotspots.*/
|
302 |
|
|
pen_point* g_hspots; /*The hotspots.*/
|
303 |
|
|
pen_rect g_bbox; /*The bounding box.*/
|
304 |
|
|
void (*g_action)(struct Gesture*); /*Pointer to execution function.*/
|
305 |
|
|
void* g_wsinfo; /*For toolkit to fill in.*/
|
306 |
|
|
} gesture;
|
307 |
|
|
|
308 |
|
|
typedef void (*xgesture)(gesture*);
|
309 |
|
|
|
310 |
|
|
/*These provide some common gesture names.*/
|
311 |
|
|
|
312 |
|
|
#define COPY "COPY" /*Copy target to clipboard*/
|
313 |
|
|
#define CUT "CUT" /*Copy target and delete*/
|
314 |
|
|
#define PASTE "PASTE" /*Paste clipboard into target*/
|
315 |
|
|
#define UNDO "UNDO" /*Undo the previous gesture action*/
|
316 |
|
|
#define CLEAR "CLEAR" /*Clear clipboard*/
|
317 |
|
|
#define EXTEND "EXTEND" /*Extend selection to target location*/
|
318 |
|
|
#define RETURN "RETURN" /*Insert newline/carriage return at target*/
|
319 |
|
|
#define SPACE "SPACE" /*Insert space at target*/
|
320 |
|
|
#define TAB "TAB" /*Insert tab at target*/
|
321 |
|
|
#define KKCONVERT "KKCONVERT" /*Perform kana-kanji conversion on target*/
|
322 |
|
|
|
323 |
|
|
/********************* RECOGNITION RETURN VALUES *************************/
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
/*Different types in union. "Other" indicates a cast is needed.*/
|
327 |
|
|
|
328 |
|
|
#define REC_NONE 0x0 /*No return value*/
|
329 |
|
|
#define REC_GESTURE 0x1 /*Gesture.*/
|
330 |
|
|
#define REC_ASCII 0x2 /*Array of 8 bit ASCII*/
|
331 |
|
|
#define REC_VAR 0x4 /*Array of variable width characters. */
|
332 |
|
|
#define REC_WCHAR 0x8 /*Array of Unicode (wide) characters. */
|
333 |
|
|
#define REC_OTHER 0x10 /*Undefined type.*/
|
334 |
|
|
#define REC_CORR 0x20 /*rec_correlation struct*/
|
335 |
|
|
|
336 |
|
|
/*
|
337 |
|
|
* Recognition elements. A recognition element is a structure having a
|
338 |
|
|
* confidence level member, and a union, along with a flag indicating
|
339 |
|
|
* the union type. The union contains a pointer to the result. This
|
340 |
|
|
* is the basic recognition return value, corresponding to one
|
341 |
|
|
* recognized word, letter, or group of letters.
|
342 |
|
|
*/
|
343 |
|
|
|
344 |
|
|
/*Ruse to make types woik*/
|
345 |
|
|
|
346 |
|
|
#define rec_correlation void
|
347 |
|
|
|
348 |
|
|
typedef struct {
|
349 |
|
|
char re_type; /*Union type flag.*/
|
350 |
|
|
union {
|
351 |
|
|
gesture* gval; /*Gesture.*/
|
352 |
|
|
char* aval; /*ASCII and variable width.*/
|
353 |
|
|
wchar_t* wval; /*Unicode.*/
|
354 |
|
|
rec_correlation* rcval; /*rec_correlation*/
|
355 |
|
|
} re_result;
|
356 |
|
|
rec_confidence re_conf; /*Confidence (0-100).*/
|
357 |
|
|
} rec_element;
|
358 |
|
|
|
359 |
|
|
/*
|
360 |
|
|
* Recognition alternative. The recognition alternative gives
|
361 |
|
|
* a translated element for a particular segmentation, and
|
362 |
|
|
* a pointer to an array of alternatives for the next position
|
363 |
|
|
* in the segmentation thread.
|
364 |
|
|
*/
|
365 |
|
|
|
366 |
|
|
struct _Rec_alternative {
|
367 |
|
|
rec_element ra_elem; /*the translated element*/
|
368 |
|
|
u_int ra_nalter; /*number of next alternatives*/
|
369 |
|
|
struct _Rec_alternative* ra_next; /*the array of next alternatives*/
|
370 |
|
|
};
|
371 |
|
|
|
372 |
|
|
typedef struct _Rec_alternative rec_alternative;
|
373 |
|
|
|
374 |
|
|
/*
|
375 |
|
|
* Recognition correlation. A recognition correlation is a recognition
|
376 |
|
|
* of the stroke input along with a correlation between the stroke
|
377 |
|
|
* input and the recognized text. The rec_correlation struct contains
|
378 |
|
|
* a pointer to an arrray of pointers to strokes, and
|
379 |
|
|
two arrays of integers, giving the starting point and
|
380 |
|
|
* stopping point of each corresponding recogition element returned
|
381 |
|
|
* in the strokes.
|
382 |
|
|
*/
|
383 |
|
|
|
384 |
|
|
#undef rec_correlation
|
385 |
|
|
|
386 |
|
|
typedef struct {
|
387 |
|
|
rec_element ro_elem; /*The recognized alternative.*/
|
388 |
|
|
u_int ro_nstrokes; /*Number of strokes.*/
|
389 |
|
|
pen_stroke* ro_strokes; /*Array of strokes.*/
|
390 |
|
|
u_int* ro_start; /*Starting index of points.*/
|
391 |
|
|
u_int* ro_stop; /*Stopping index of points.*/
|
392 |
|
|
} rec_correlation;
|
393 |
|
|
|
394 |
|
|
#endif
|