nsILineBreaker.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsILineBreaker_h__
  6. #define nsILineBreaker_h__
  7. #include "nsISupports.h"
  8. #include "nscore.h"
  9. #define NS_LINEBREAKER_NEED_MORE_TEXT -1
  10. // {0x4b0b9e04-6ffb-4647-aa5f-2fa2ebd883e8}
  11. #define NS_ILINEBREAKER_IID \
  12. {0x4b0b9e04, 0x6ffb, 0x4647, \
  13. {0xaa, 0x5f, 0x2f, 0xa2, 0xeb, 0xd8, 0x83, 0xe8}}
  14. class nsILineBreaker : public nsISupports
  15. {
  16. public:
  17. NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINEBREAKER_IID)
  18. enum {
  19. kWordBreak_Normal = 0, // default
  20. kWordBreak_BreakAll = 1, // break all
  21. kWordBreak_KeepAll = 2 // always keep
  22. };
  23. virtual int32_t Next( const char16_t* aText, uint32_t aLen,
  24. uint32_t aPos) = 0;
  25. virtual int32_t Prev( const char16_t* aText, uint32_t aLen,
  26. uint32_t aPos) = 0;
  27. // Call this on a word with whitespace at either end. We will apply JISx4051
  28. // rules to find breaks inside the word. aBreakBefore is set to the break-
  29. // before status of each character; aBreakBefore[0] will always be false
  30. // because we never return a break before the first character.
  31. // aLength is the length of the aText array and also the length of the aBreakBefore
  32. // output array.
  33. virtual void GetJISx4051Breaks(const char16_t* aText, uint32_t aLength,
  34. uint8_t aWordBreak,
  35. uint8_t* aBreakBefore) = 0;
  36. virtual void GetJISx4051Breaks(const uint8_t* aText, uint32_t aLength,
  37. uint8_t aWordBreak,
  38. uint8_t* aBreakBefore) = 0;
  39. };
  40. NS_DEFINE_STATIC_IID_ACCESSOR(nsILineBreaker, NS_ILINEBREAKER_IID)
  41. static inline bool
  42. NS_IsSpace(char16_t u)
  43. {
  44. return u == 0x0020 || // SPACE
  45. u == 0x0009 || // CHARACTER TABULATION
  46. u == 0x000D || // CARRIAGE RETURN
  47. u == 0x1680 || // OGHAM SPACE MARK
  48. (0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE,
  49. // EM SPACE, THREE-PER-EM SPACE,
  50. // FOUR-PER-SPACE, SIX-PER-EM SPACE,
  51. (0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE,
  52. // HAIR SPACE, ZERO WIDTH SPACE
  53. u == 0x205F; // MEDIUM MATHEMATICAL SPACE
  54. }
  55. static inline bool
  56. NS_NeedsPlatformNativeHandling(char16_t aChar)
  57. {
  58. return (0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan
  59. (0x1780 <= aChar && aChar <= 0x17ff); // Khmer
  60. }
  61. #endif /* nsILineBreaker_h__ */