bidi.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Header file shared between bidi.c and its tests. Not used by
  3. * anything outside the bidi subsystem.
  4. */
  5. #ifndef PUTTY_BIDI_H
  6. #define PUTTY_BIDI_H
  7. #define LMASK 0x3F /* Embedding Level mask */
  8. #define OMASK 0xC0 /* Override mask */
  9. #define OISL 0x80 /* Override is L */
  10. #define OISR 0x40 /* Override is R */
  11. /* Shaping Helpers */
  12. #define STYPE(xh) ((((xh) >= SHAPE_FIRST) && ((xh) <= SHAPE_LAST)) ? \
  13. shapetypes[(xh)-SHAPE_FIRST].type : SU) /*))*/
  14. #define SISOLATED(xh) (shapetypes[(xh)-SHAPE_FIRST].form_b)
  15. #define SFINAL(xh) ((xh)+1)
  16. #define SINITIAL(xh) ((xh)+2)
  17. #define SMEDIAL(ch) ((ch)+3)
  18. #define leastGreaterOdd(x) ( ((x)+1) | 1 )
  19. #define leastGreaterEven(x) ( ((x)+2) &~ 1 )
  20. /* Function declarations used outside bidi.c */
  21. unsigned char bidi_getType(int ch);
  22. /* Bidi character types */
  23. #define BIDI_CHAR_TYPE_LIST(X) \
  24. X(L) \
  25. X(LRE) \
  26. X(LRO) \
  27. X(LRI) \
  28. X(R) \
  29. X(AL) \
  30. X(RLE) \
  31. X(RLO) \
  32. X(RLI) \
  33. X(PDF) \
  34. X(PDI) \
  35. X(FSI) \
  36. X(EN) \
  37. X(ES) \
  38. X(ET) \
  39. X(AN) \
  40. X(CS) \
  41. X(NSM) \
  42. X(BN) \
  43. X(B) \
  44. X(S) \
  45. X(WS) \
  46. X(ON) \
  47. /* end of list */
  48. /* Shaping Types */
  49. #define SHAPING_CHAR_TYPE_LIST(X) \
  50. X(SL) /* Left-Joining, doesn't exist in U+0600 - U+06FF */ \
  51. X(SR) /* Right-Joining, ie has Isolated, Final */ \
  52. X(SD) /* Dual-Joining, ie has Isolated, Final, Initial, Medial */ \
  53. X(SU) /* Non-Joining */ \
  54. X(SC) /* Join-Causing, like U+0640 (TATWEEL) */ \
  55. /* end of list */
  56. #define ENUM_DECL(name) name,
  57. typedef enum { BIDI_CHAR_TYPE_LIST(ENUM_DECL) N_BIDI_TYPES } BidiType;
  58. typedef enum { SHAPING_CHAR_TYPE_LIST(ENUM_DECL) N_SHAPING_TYPES } ShapingType;
  59. #undef ENUM_DECL
  60. static inline bool typeIsStrong(BidiType t)
  61. {
  62. return ((1<<L) | (1<<R) | (1<<AL)) & (1 << t);
  63. }
  64. static inline bool typeIsWeak(BidiType t)
  65. {
  66. return ((1<<EN) | (1<<ES) | (1<<ET) | (1<<AN) |
  67. (1<<CS) | (1<<NSM) | (1<<BN)) & (1 << t);
  68. }
  69. static inline bool typeIsNeutral(BidiType t)
  70. {
  71. return ((1<<B) | (1<<S) | (1<<WS) | (1<<ON)) & (1 << t);
  72. }
  73. static inline bool typeIsBidiActive(BidiType t)
  74. {
  75. return ((1<<R) | (1<<AL) | (1<<AN) | (1<<RLE) | (1<<LRE) | (1<<RLO) |
  76. (1<<LRO) | (1<<PDF) | (1<<RLI)) & (1 << t);
  77. }
  78. static inline bool typeIsIsolateInitiator(BidiType t)
  79. {
  80. return ((1<<LRI) | (1<<RLI) | (1<<FSI)) & (1 << t);
  81. }
  82. static inline bool typeIsIsolateInitiatorOrPDI(BidiType t)
  83. {
  84. return ((1<<LRI) | (1<<RLI) | (1<<FSI) | (1<<PDI)) & (1 << t);
  85. }
  86. static inline bool typeIsEmbeddingInitiator(BidiType t)
  87. {
  88. return ((1<<LRE) | (1<<RLE) | (1<<LRO) | (1<<RLO)) & (1 << t);
  89. }
  90. static inline bool typeIsEmbeddingInitiatorOrPDF(BidiType t)
  91. {
  92. return ((1<<LRE) | (1<<RLE) | (1<<LRO) | (1<<RLO) | (1<<PDF)) & (1 << t);
  93. }
  94. static inline bool typeIsWeakSeparatorOrTerminator(BidiType t)
  95. {
  96. return ((1<<ES) | (1<<ET) | (1<<CS)) & (1 << t);
  97. }
  98. static inline bool typeIsNeutralOrIsolate(BidiType t)
  99. {
  100. return ((1<<S) | (1<<WS) | (1<<ON) | (1<<FSI) | (1<<LRI) | (1<<RLI) |
  101. (1<<PDI)) & (1 << t);
  102. }
  103. static inline bool typeIsSegmentOrParaSeparator(BidiType t)
  104. {
  105. return ((1<<S) | (1<<B)) & (1 << t);
  106. }
  107. static inline bool typeIsWhitespaceOrIsolate(BidiType t)
  108. {
  109. return ((1<<WS) | (1<<FSI) | (1<<LRI) | (1<<RLI) | (1<<PDI)) & (1 << t);
  110. }
  111. static inline bool typeIsRemovedDuringProcessing(BidiType t)
  112. {
  113. return ((1<<RLE) | (1<<LRE) | (1<<RLO) | (1<<LRO) | (1<<PDF) |
  114. (1<<BN)) & (1 << t);
  115. }
  116. static inline bool typeIsStrongOrNumber(BidiType t)
  117. {
  118. return ((1<<L) | (1<<R) | (1<<AL) | (1<<EN) | (1<<AN)) & (1 << t);
  119. }
  120. static inline bool typeIsETOrBN(BidiType t)
  121. {
  122. return ((1<<ET) | (1<<BN)) & (1 << t);
  123. }
  124. /*
  125. * More featureful interface to the bidi code, for use in bidi_test.c.
  126. * It returns a potentially different value of textlen (in case we're
  127. * compiling in REMOVE_FORMATTING_CHARACTERS mode), and also permits
  128. * you to pass in an override to the paragraph direction (because many
  129. * of the UCD conformance tests use one).
  130. *
  131. * 'override' is 0 for no override, +1 for left-to-right, -1 for
  132. * right-to-left.
  133. */
  134. size_t do_bidi_test(BidiContext *ctx, bidi_char *text, size_t textlen,
  135. int override);
  136. #endif /* PUTTY_BIDI_H */