bidi.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #ifndef BDE_BIDI_H
  17. #define BDE_BIDI_H
  18. #include "types.h"
  19. // The purpose of the BiDi class (and the public typdefs) is to make the
  20. // interface of the actual BiDi engine (FriBiDi) hidden from the user. This
  21. // BiDi class could be implemented using other engines, e.g. IBM's ICU.
  22. //
  23. // Ideally, The BiDi class would be an abstract class from which we derive
  24. // class FriBiDi, class ICUBiDi etc. The configre script could then tell us
  25. // which class to use based on what engine the system has.
  26. //
  27. // Note that we use very little of FriBiDi. We implement reordering ourselves
  28. // (see the comments at EditBox::reorder()).
  29. typedef FriBidiCharType ctype_t;
  30. typedef FriBidiLevel level_t;
  31. enum direction_t { dirLTR, dirRTL, dirN };
  32. enum diralgo_t { algoUnicode, algoContextStrong, algoContextRTL, algoForceLTR, algoForceRTL };
  33. #include "univalues.h"
  34. class BiDi {
  35. public:
  36. static bool mirror_char(unichar *ch) {
  37. return fribidi_get_mirror_char(*ch, ch);
  38. }
  39. static bool is_space(unichar ch) {
  40. return FRIBIDI_IS_SPACE(fribidi_get_type(ch));
  41. }
  42. static bool is_alnum(unichar ch) {
  43. ctype_t ctype = fribidi_get_type(ch);
  44. return FRIBIDI_IS_LETTER(ctype) || FRIBIDI_IS_NUMBER(ctype);
  45. }
  46. static bool is_nsm(unichar ch) {
  47. return fribidi_get_type(ch) == FRIBIDI_TYPE_NSM;
  48. }
  49. // is_wordch() returns what constitutes a word.
  50. static bool is_wordch(unichar ch) {
  51. return is_alnum(ch) || is_nsm(ch);
  52. }
  53. static bool is_rtl(unichar ch) {
  54. return FRIBIDI_IS_RTL(fribidi_get_type(ch));
  55. }
  56. static bool is_explicit_mark(unichar ch)
  57. {
  58. return ch == UNI_LRM ||
  59. ch == UNI_RLM ||
  60. ch == UNI_LRE ||
  61. ch == UNI_RLE ||
  62. ch == UNI_PDF ||
  63. ch == UNI_LRO ||
  64. ch == UNI_RLO;
  65. }
  66. static bool is_transparent_formatting_code(unichar ch)
  67. {
  68. return is_explicit_mark(ch) ||
  69. ch == UNI_ZWNJ ||
  70. ch == UNI_ZWJ;
  71. }
  72. static bool is_hebrew_nsm(unichar ch)
  73. {
  74. return (ch >= UNI_HEB_ETNAHTA && ch <= UNI_HEB_UPPER_DOT
  75. || ch == UNI_NS_UNDERSCORE)
  76. && (ch != UNI_HEB_MAQAF &&
  77. ch != UNI_HEB_PASEQ &&
  78. ch != UNI_HEB_SOF_PASUQ);
  79. }
  80. static bool is_arabic_nsm(unichar ch)
  81. {
  82. return (ch >= UNI_ARA_FATHATAN && ch <= UNI_ARA_SUKUN
  83. || ch == UNI_ARA_SUPERSCIPT_ALEF);
  84. }
  85. static bool is_cantillation_nsm(unichar ch)
  86. {
  87. return (ch >= UNI_HEB_ETNAHTA && ch <= UNI_HEB_MASORA_CIRCLE);
  88. }
  89. static void get_embedding_levels(unichar *str, idx_t len,
  90. direction_t dir,
  91. level_t *levels,
  92. int line_breaks_count = 0,
  93. idx_t *line_breaks = NULL,
  94. bool disable_bidi = false);
  95. static direction_t determine_base_dir(unichar *str, idx_t len,
  96. diralgo_t dir_algo);
  97. static void simple_log2vis(unistring &str, direction_t dir, unistring &dest);
  98. };
  99. #endif