fribidi-bidi.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* FriBidi
  2. * fribidi-bidi.h - bidirectional algorithm
  3. *
  4. * Authors:
  5. * Behdad Esfahbod, 2001, 2002, 2004
  6. * Dov Grobgeld, 1999, 2000
  7. *
  8. * Copyright (C) 2004 Sharif FarsiWeb, Inc
  9. * Copyright (C) 2001,2002 Behdad Esfahbod
  10. * Copyright (C) 1999,2000 Dov Grobgeld
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * along with this library, in a file named COPYING; if not, write to the
  24. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  25. * Boston, MA 02110-1301, USA
  26. *
  27. * For licensing issues, contact <fribidi.license@gmail.com>.
  28. */
  29. #ifndef _FRIBIDI_BIDI_H
  30. #define _FRIBIDI_BIDI_H
  31. #include "fribidi-common.h"
  32. #include "fribidi-types.h"
  33. #include "fribidi-flags.h"
  34. #include "fribidi-bidi-types.h"
  35. #include "fribidi-begindecls.h"
  36. /* fribidi_get_par_direction - get base paragraph direction
  37. *
  38. * This function finds the base direction of a single paragraph,
  39. * as defined by rule P2 of the Unicode Bidirectional Algorithm available at
  40. * http://www.unicode.org/reports/tr9/#P2.
  41. *
  42. * You typically do not need this function as
  43. * fribidi_get_par_embedding_levels() knows how to compute base direction
  44. * itself, but you may need this to implement a more sophisticated paragraph
  45. * direction handling. Note that you can pass more than a paragraph to this
  46. * function and the direction of the first non-neutral paragraph is returned,
  47. * which is a very good heuristic to set direction of the neutral paragraphs
  48. * at the beginning of text. For other neutral paragraphs, you better use the
  49. * direction of the previous paragraph.
  50. *
  51. * Returns: Base pargraph direction. No weak paragraph direction is returned,
  52. * only LTR, RTL, or ON.
  53. */
  54. FRIBIDI_ENTRY FriBidiParType fribidi_get_par_direction (
  55. const FriBidiCharType *bidi_types, /* input list of bidi types as returned by
  56. fribidi_get_bidi_types() */
  57. const FriBidiStrIndex len /* input string length */
  58. );
  59. /* fribidi_get_par_embedding_levels_ex - get bidi embedding levels of a paragraph
  60. *
  61. * This function finds the bidi embedding levels of a single paragraph,
  62. * as defined by the Unicode Bidirectional Algorithm available at
  63. * http://www.unicode.org/reports/tr9/. This function implements rules P2 to
  64. * I1 inclusive, and parts 1 to 3 of L1, except for rule X9 which is
  65. * implemented in fribidi_remove_bidi_marks(). Part 4 of L1 is implemented
  66. * in fribidi_reorder_line().
  67. *
  68. * There are a few macros defined in fribidi-bidi-types.h to work with this
  69. * embedding levels.
  70. *
  71. * Returns: Maximum level found plus one, or zero if any error occurred
  72. * (memory allocation failure most probably).
  73. */
  74. FRIBIDI_ENTRY FriBidiLevel
  75. fribidi_get_par_embedding_levels_ex (
  76. const FriBidiCharType *bidi_types, /* input list of bidi types as returned by
  77. fribidi_get_bidi_types() */
  78. const FriBidiBracketType *bracket_types, /* input list of bracket types as returned by
  79. fribidi_get_bracket_types() */
  80. const FriBidiStrIndex len, /* input string length of the paragraph */
  81. FriBidiParType *pbase_dir, /* requested and resolved paragraph
  82. * base direction */
  83. FriBidiLevel *embedding_levels /* output list of embedding levels */
  84. ) FRIBIDI_GNUC_WARN_UNUSED;
  85. /* fribidi_reorder_line - reorder a line of logical string to visual
  86. *
  87. * This function reorders the characters in a line of text from logical to
  88. * final visual order. This function implements part 4 of rule L1, and rules
  89. * L2 and L3 of the Unicode Bidirectional Algorithm available at
  90. * http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels.
  91. *
  92. * As a side effect it also sets position maps if not NULL.
  93. *
  94. * You should provide the resolved paragraph direction and embedding levels as
  95. * set by fribidi_get_par_embedding_levels(). Also note that the embedding
  96. * levels may change a bit. To be exact, the embedding level of any sequence
  97. * of white space at the end of line is reset to the paragraph embedding level
  98. * (That is part 4 of rule L1).
  99. *
  100. * Note that the bidi types and embedding levels are not reordered. You can
  101. * reorder these (or any other) arrays using the map later. The user is
  102. * responsible to initialize map to something sensible, like an identity
  103. * mapping, or pass NULL if no map is needed.
  104. *
  105. * There is an optional part to this function, which is whether non-spacing
  106. * marks for right-to-left parts of the text should be reordered to come after
  107. * their base characters in the visual string or not. Most rendering engines
  108. * expect this behavior, but console-based systems for example do not like it.
  109. * This is controlled by the FRIBIDI_FLAG_REORDER_NSM flag. The flag is on
  110. * in FRIBIDI_FLAGS_DEFAULT.
  111. *
  112. * Returns: Maximum level found in this line plus one, or zero if any error
  113. * occurred (memory allocation failure most probably).
  114. */
  115. FRIBIDI_ENTRY FriBidiLevel fribidi_reorder_line (
  116. FriBidiFlags flags, /* reorder flags */
  117. const FriBidiCharType *bidi_types, /* input list of bidi types as returned by
  118. fribidi_get_bidi_types() */
  119. const FriBidiStrIndex len, /* input length of the line */
  120. const FriBidiStrIndex off, /* input offset of the beginning of the line
  121. in the paragraph */
  122. const FriBidiParType base_dir, /* resolved paragraph base direction */
  123. FriBidiLevel *embedding_levels, /* input list of embedding levels,
  124. as returned by
  125. fribidi_get_par_embedding_levels */
  126. FriBidiChar *visual_str, /* visual string to reorder */
  127. FriBidiStrIndex *map /* a map of string indices which is reordered
  128. * to reflect where each glyph ends up. */
  129. ) FRIBIDI_GNUC_WARN_UNUSED;
  130. #include "fribidi-enddecls.h"
  131. #endif /* !_FRIBIDI_BIDI_H */
  132. /* Editor directions:
  133. * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
  134. */