1 /** 2 Bidirectional text processing. 3 4 Derived from the SmartOffice code, which is itself derived 5 from the example unicode standard code. Original copyright 6 messages follow: 7 8 Copyright (C) Picsel, 2004-2008. All Rights Reserved. 9 10 Processes Unicode text by arranging the characters into an order 11 suitable for display. E.g. Hebrew text will be arranged from 12 right-to-left and any English within the text will remain in the 13 left-to-right order. 14 15 This is an implementation of the Unicode Bidirectional Algorithm 16 which can be found here: http://www.unicode.org/reports/tr9/ and 17 is based on the reference implementation found on Unicode.org. 18 */ 19 20 #ifndef FITZ_BIDI_H 21 #define FITZ_BIDI_H 22 23 #include "mupdf/fitz/system.h" 24 25 /* Implementation details: subject to change. */ 26 27 typedef enum 28 { 29 FZ_BIDI_LTR = 0, 30 FZ_BIDI_RTL = 1, 31 FZ_BIDI_NEUTRAL = 2 32 } 33 fz_bidi_direction; 34 35 typedef enum 36 { 37 FZ_BIDI_CLASSIFY_WHITE_SPACE = 1, 38 FZ_BIDI_REPLACE_TAB = 2 39 } 40 fz_bidi_flags; 41 42 /** 43 Prototype for callback function supplied to fz_bidi_fragment_text. 44 45 @param fragment first character in fragment 46 @param fragmentLen number of characters in fragment 47 @param bidiLevel The bidirectional level for this text. 48 The bottom bit will be set iff block 49 should concatenate with other blocks as 50 right-to-left 51 @param script the script in use for this fragment (other 52 than common or inherited) 53 @param arg data from caller of Bidi_fragmentText 54 */ 55 typedef void (fz_bidi_fragment_fn)(const uint32_t *fragment, 56 size_t fragmentLen, 57 int bidiLevel, 58 int script, 59 void *arg); 60 61 /** 62 Partitions the given Unicode sequence into one or more 63 unidirectional fragments and invokes the given callback 64 function for each fragment. 65 66 For example, if directionality of text is: 67 0123456789 68 rrlllrrrrr, 69 we'll invoke callback with: 70 &text[0], length == 2 71 &text[2], length == 3 72 &text[5], length == 5 73 74 @param[in] text start of Unicode sequence 75 @param[in] textlen number of Unicodes to analyse 76 @param[in] baseDir direction of paragraph (specify FZ_BIDI_NEUTRAL to force auto-detection) 77 @param[in] callback function to be called for each fragment 78 @param[in] arg data to be passed to the callback function 79 @param[in] flags flags to control operation (see fz_bidi_flags above) 80 */ 81 void fz_bidi_fragment_text(fz_context *ctx, 82 const uint32_t *text, 83 size_t textlen, 84 fz_bidi_direction *baseDir, 85 fz_bidi_fragment_fn *callback, 86 void *arg, 87 int flags); 88 89 #endif 90