scribbleimpl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. * scribble.h: User-Level API for Handwriting Recognition
  3. * Author: James Kempf
  4. * Created On: Mon Nov 2 14:01:25 1992
  5. * Last Modified By: Sape Mullender
  6. * Last Modified On: Fri Aug 25 10:24:50 EDT 2000
  7. * Copyright (c) 1994 by Sun Microsystems Computer Company
  8. * All rights reserved.
  9. *
  10. * Use and copying of this software and preparation of
  11. * derivative works based upon this software are permitted.
  12. * Any distribution of this software or derivative works
  13. * must comply with all applicable United States export control
  14. * laws.
  15. *
  16. * This software is made available as is, and Sun Microsystems
  17. * Computer Company makes no warranty about the software, its
  18. * performance, or its conformity to any specification
  19. */
  20. /*
  21. * Opaque type for the recognizer. The toolkit must access through
  22. * appropriate access functions.
  23. */
  24. typedef struct _Recognizer* recognizer;
  25. #pragma incomplete recognizer
  26. /*
  27. * Opaque type for recognizers to implement dictionaries.
  28. */
  29. typedef struct _wordset *wordset;
  30. typedef struct rc rc;
  31. typedef struct rec_correlation rec_correlation;
  32. typedef struct rec_alternative rec_alternative;
  33. typedef struct rec_element rec_element;
  34. typedef struct gesture gesture;
  35. typedef uint wchar_t;
  36. /* Scalar Type Definitions */
  37. /* For better readibility.*/
  38. typedef int bool;
  39. #define true 1
  40. #define false 0
  41. /*For pointers to extra functions on recognizer.*/
  42. typedef void (*rec_fn)();
  43. /*
  44. * rec_confidence is an integer between 0-100 giving the confidence of the
  45. * recognizer in a particular result.
  46. */
  47. typedef uchar rec_confidence;
  48. /**************** RECOGNIZER CONFIGURATION INFORMATION *******************/
  49. /*
  50. * Recognizer information. Gives the locale, category of the character
  51. * set returned by the recognizer, and any subsets to which the
  52. * recognition can be limited. The locale and category should be
  53. * suitable for the setlocale(3). Those recognizers which don't do text
  54. * can simply report a blank locale and category, and report the
  55. * graphics types they recognize in the subset.
  56. */
  57. typedef struct {
  58. char* ri_locale; /*The locale of the character set.*/
  59. char* ri_name; /*Complete pathname to the recognizer.*/
  60. char** ri_subset; /*Null terminated list of subsets supported*/
  61. } rec_info;
  62. /*These define a set of common character subset names.*/
  63. #define GESTURE "GESTURE" /* gestures only */
  64. #define MATHSET "MATHSET" /* %^*()_+={}<>,/. */
  65. #define MONEYSET "MONEYSET" /* $, maybe cent, pound, and yen */
  66. #define WHITESPACE "WHITESPACE" /* gaps are recognized as space */
  67. #define KANJI_JIS1 "KANJI_JIS1" /* the JIS1 kanji only */
  68. #define KANJI_JIS1_PLUS "KANJI_JIS1_PLUS" /* JIS1 plus some JIS2 */
  69. #define KANJI_JIS2 "KANJI_JIS2" /* the JIS1 + JIS2 kanji */
  70. #define HIRIGANA "HIRIGANA" /* the hirigana */
  71. #define KATAKANA "KATAKANA" /* the katakana */
  72. #define UPPERCASE "UPPERCASE" /* upper case alphabetics, no digits */
  73. #define LOWERCASE "LOWERCASE" /* lower case alphabetics, no digits */
  74. #define DIGITS "DIGITS" /* digits 0-9 only */
  75. #define PUNCTUATION "PUNCTUATION" /* \!-;'"?()&., */
  76. #define NONALPHABETIC "NONALPHABETIC" /* all nonalphabetics, no digits */
  77. #define ASCII "ASCII" /* the ASCII character set */
  78. #define ISO_LATIN12 "ISO_LATIN12" /* The ISO Latin 12 characters */
  79. /******************** RECOGNITION INPUT STRUCTURES ***********************/
  80. /*
  81. * WINDOW SYSTEM INTERFACE
  82. */
  83. /*Bounding box. Structurally identical to Rectangle.*/
  84. typedef Rectangle pen_rect;
  85. /*
  86. * RECOGNITION CONTEXT
  87. */
  88. /* Structure for reporting writing area geometric constraints. */
  89. typedef struct {
  90. pen_rect pr_area;
  91. short pr_row, pr_col;
  92. } pen_frame;
  93. /*
  94. * Structure for describing a set of letters to constrain recognition.
  95. * ls_type is the same as the re_type field for rec_element below.
  96. */
  97. typedef struct _letterset {
  98. char ls_type;
  99. union _ls_set {
  100. char* aval;
  101. wchar_t* wval;
  102. } ls_set;
  103. } letterset;
  104. /********************* RECOGNITION RETURN VALUES *************************/
  105. /*Different types in union. "Other" indicates a cast is needed.*/
  106. #define REC_NONE 0x0 /*No return value*/
  107. #define REC_GESTURE 0x1 /*Gesture.*/
  108. #define REC_ASCII 0x2 /*Array of 8 bit ASCII*/
  109. #define REC_VAR 0x4 /*Array of variable width characters. */
  110. #define REC_WCHAR 0x8 /*Array of Unicode (wide) characters. */
  111. #define REC_OTHER 0x10 /*Undefined type.*/
  112. #define REC_CORR 0x20 /*rec_correlation struct*/
  113. /*
  114. * Recognition elements. A recognition element is a structure having a
  115. * confidence level member, and a union, along with a flag indicating
  116. * the union type. The union contains a pointer to the result. This
  117. * is the basic recognition return value, corresponding to one
  118. * recognized word, letter, or group of letters.
  119. */
  120. struct rec_element {
  121. char re_type; /*Union type flag.*/
  122. union {
  123. gesture * gval; /*Gesture.*/
  124. char* aval; /*ASCII and variable width.*/
  125. wchar_t* wval; /*Unicode.*/
  126. rec_correlation* rcval; /*rec_correlation*/
  127. } re_result;
  128. rec_confidence re_conf; /*Confidence (0-100).*/
  129. };
  130. /*
  131. * Recognition alternative. The recognition alternative gives
  132. * a translated element for a particular segmentation, and
  133. * a pointer to an array of alternatives for the next position
  134. * in the segmentation thread.
  135. */
  136. struct rec_alternative {
  137. rec_element ra_elem; /*the translated element*/
  138. uint ra_nalter; /*number of next alternatives*/
  139. rec_alternative* ra_next; /*the array of next alternatives*/
  140. };
  141. /************************** GESTURES **************************/
  142. /*
  143. * Gestures. The toolkit initializes the recognizer with a
  144. * set of gestures having appropriate callbacks.
  145. * When a gesture is recognized, it is returned as part of a
  146. * recognition element. The recognizer fills in the bounding
  147. * box and hotspots. The toolkit fills in any additional values,
  148. * such as the current window, and calls the callback.
  149. */
  150. struct gesture {
  151. char* g_name; /*The gesture's name.*/
  152. uint g_nhs; /*Number of hotspots.*/
  153. pen_point* g_hspots; /*The hotspots.*/
  154. pen_rect g_bbox; /*The bounding box.*/
  155. void (*g_action)(gesture*); /*Pointer to execution function.*/
  156. void* g_wsinfo; /*For toolkit to fill in.*/
  157. };
  158. typedef void (*xgesture)(gesture*);
  159. /*
  160. * Recognition correlation. A recognition correlation is a recognition
  161. * of the stroke input along with a correlation between the stroke
  162. * input and the recognized text. The rec_correlation struct contains
  163. * a pointer to an arrray of pointers to strokes, and
  164. * two arrays of integers, giving the starting point and
  165. * stopping point of each corresponding recogition element returned
  166. * in the strokes.
  167. */
  168. struct rec_correlation {
  169. rec_element ro_elem; /*The recognized alternative.*/
  170. uint ro_nstrokes; /*Number of strokes.*/
  171. Stroke* ro_strokes; /*Array of strokes.*/
  172. uint* ro_start; /*Starting index of points.*/
  173. uint* ro_stop; /*Stopping index of points.*/
  174. };
  175. /*
  176. * ADMINISTRATION
  177. */
  178. /*
  179. * recognizer_load - If directory is not NULL, then use it as a pathname
  180. * to find the recognizer. Otherwise, use the default naming conventions
  181. * to find the recognizer having file name name. The subset argument
  182. * contains a null-terminated array of names for character subsets which
  183. * the recognizer should translate.
  184. */
  185. recognizer recognizer_load(char*, char*, char**);
  186. /*
  187. * recognizer_unload - Unload the recognizer.
  188. */
  189. int recognizer_unload(recognizer);
  190. /*
  191. * recognizer_get_info-Get a pointer to a rec_info
  192. * giving the locale and subsets supported by the recognizer, and shared
  193. * library pathname.
  194. */
  195. const rec_info* recognizer_get_info(recognizer);
  196. /*
  197. * recognizer_manager_version-Return the version number string of the
  198. * recognition manager.
  199. */
  200. const char* recognizer_manager_version(recognizer);
  201. /*
  202. * recognizer_load_state-Get any recognizer state associated with name
  203. * in dir. Note that name may not be simple file name, since
  204. * there may be more than one file involved. Return 0 if successful,
  205. * -1 if not.
  206. */
  207. int recognizer_load_state(recognizer, char*, char*);
  208. /*
  209. * recognizer_save_state-Save any recognizer state to name
  210. * in dir. Note that name may not be a simple file name, since
  211. * there may be more than one file involved. Return 0 if successful,
  212. * -1 if not.
  213. */
  214. int recognizer_save_state(recognizer, char*, char*);
  215. /*
  216. * recognizer_error-Return the last error message, or NULL if none.
  217. */
  218. char* recognizer_error(recognizer);
  219. /*
  220. * DICTIONARIES
  221. */
  222. /* recognizer_load_dictionary-Load a dictionary from the directory
  223. * dir and file name. Return the dictionary pointer if successful,
  224. * otherwise NULL.
  225. */
  226. wordset recognizer_load_dictionary(recognizer, char*, char*);
  227. /* recoginzer_save_dictionary-Save the dictionary to the file. Return 0
  228. * successful, -1 if error occurs.
  229. */
  230. int recognizer_save_dictionary(recognizer, char*, char*, wordset);
  231. /*
  232. * recognizer_free_dictionary-Free the dictionary. Return 0 if successful,
  233. * -1 if error occurs.
  234. */
  235. int recognizer_free_dictionary(recognizer, wordset);
  236. /*
  237. * recognizer_add_to_dictionary-Add the word to the dictionary. Return 0
  238. * if successful, -1 if error occurs.
  239. */
  240. int recognizer_add_to_dictionary(recognizer, letterset*, wordset);
  241. /*
  242. * recognizer_delete_from_dictionary-Delete the word from the dictionary.
  243. * Return 0 if successful, -1 if error occurs.
  244. */
  245. int recognizer_delete_from_dictionary(recognizer, letterset*, wordset);
  246. /*
  247. * TRANSLATION
  248. */
  249. /* recognizer_set/get_context - Set/get the recognition context for
  250. * subsequent buffering and translation. recognizer_set_context()
  251. * returns -1 if an error occurs, otherwise 0. recognizer_get_context()
  252. * returns NULL if no context has been set. The context is copied to avoid
  253. * potential memory deallocation problems.
  254. */
  255. int recognizer_set_context(recognizer, rc*);
  256. rc* recognizer_get_context(recognizer);
  257. /* recognizer_clear - Set stroke buffer to NULL and clear the context.
  258. * Returns -1 if an error occurred, otherwise 0. Both the context and the
  259. * stroke buffer are deallocated. If delete_points_p is true, delete the
  260. * points also.
  261. */
  262. int recognizer_clear(recognizer, bool);
  263. /* recognizer_get/set_buffer - Get/set the stroke buffer. The stroke buffer
  264. * is copied to avoid potential memory allocation problems. Returns -1 if
  265. * an error occurs, otherwise 0.
  266. */
  267. int recognizer_get_buffer(recognizer, uint*, Stroke**);
  268. int recognizer_set_buffer(recognizer, uint, Stroke*);
  269. /* recognizer_translate - Copy the strokes argument into the stroke buffer and
  270. * translate the buffer. If correlate_p is true, then provide stroke
  271. * correlations as well. If either nstrokes is 0 or strokes is NULL, then
  272. * just translate the stroke buffer and return the translation. Return an
  273. * array of alternative translation segmentations in the ret pointer and the
  274. * number of alternatives in nret, or NULL and 0 if there is no translation.
  275. * The direction of segmentation is as specified by the rc_direction field in
  276. * the buffered recognition context. Returns -1 if an error occurred,
  277. * otherwise 0.
  278. */
  279. int recognizer_translate(recognizer, uint, Stroke*, bool,
  280. int*, rec_alternative**);
  281. /*
  282. * recognizer_get_extension_functions-Return a null terminated array
  283. * of functions providing extended functionality. Their interfaces
  284. * will change depending on the recognizer.
  285. */
  286. rec_fn* recognizer_get_extension_functions(recognizer);
  287. /*
  288. * GESTURE SUPPORT
  289. */
  290. /*
  291. * recognizer_get_gesture_names - Return a null terminated array of
  292. * character strings containing the gesture names.
  293. */
  294. char** recognizer_get_gesture_names(recognizer);
  295. /*
  296. * recognizer_set_gesture_action-Set the action function associated with the
  297. * name.
  298. */
  299. xgesture recognizer_set_gesture_action(recognizer, char*, xgesture, void*);
  300. /*
  301. * The following functions are for deleting data structures returned
  302. * by the API functions.
  303. */
  304. void delete_rec_alternative_array(uint, rec_alternative*, bool);
  305. void delete_rec_correlation(rec_correlation*, bool);
  306. /*
  307. * These are used by clients to create arrays for passing to API
  308. * functions.
  309. */
  310. Stroke* make_Stroke_array(uint);
  311. void delete_Stroke_array(uint, Stroke*, bool);
  312. pen_point* make_pen_point_array(uint);
  313. void delete_pen_point_array(pen_point*);
  314. Stroke* copy_Stroke_array(uint, Stroke*);
  315. /*Extension function interfaces and indices.*/
  316. #define LI_ISA_LI 0 /*Is this a li recognizer?.*/
  317. #define LI_TRAIN 1 /*Train recognizer*/
  318. #define LI_CLEAR 2 /* ari's clear-state extension fn. */
  319. #define LI_GET_CLASSES 3 /* ari's get-classes extension fn. */
  320. #define LI_NUM_EX_FNS 4 /*Number of extension functions*/
  321. typedef bool (*li_isa_li)(recognizer r);
  322. typedef int (*li_recognizer_train)(recognizer, rc*, uint,
  323. Stroke*, rec_element*, bool);
  324. typedef int (*li_recognizer_clearState)(recognizer);
  325. typedef int (*li_recognizer_getClasses)(recognizer, char ***, int *);