scribbleimpl.h 13 KB

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