gfxScriptItemizer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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. /*
  6. * This file is based on usc_impl.c from ICU 4.2.0.1, slightly adapted
  7. * for use within Mozilla Gecko, separate from a standard ICU build.
  8. *
  9. * The original ICU license of the code follows:
  10. *
  11. * ICU License - ICU 1.8.1 and later
  12. *
  13. * COPYRIGHT AND PERMISSION NOTICE
  14. *
  15. * Copyright (c) 1995-2009 International Business Machines Corporation and
  16. * others
  17. *
  18. * All rights reserved.
  19. *
  20. * Permission is hereby granted, free of charge, to any person obtaining a
  21. * copy of this software and associated documentation files (the "Software"),
  22. * to deal in the Software without restriction, including without limitation
  23. * the rights to use, copy, modify, merge, publish, distribute, and/or sell
  24. * copies of the Software, and to permit persons to whom the Software is
  25. * furnished to do so, provided that the above copyright notice(s) and this
  26. * permission notice appear in all copies of the Software and that both the
  27. * above copyright notice(s) and this permission notice appear in supporting
  28. * documentation.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  31. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  33. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
  34. * BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
  35. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  36. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  37. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  38. * SOFTWARE.
  39. *
  40. * Except as contained in this notice, the name of a copyright holder shall
  41. * not be used in advertising or otherwise to promote the sale, use or other
  42. * dealings in this Software without prior written authorization of the
  43. * copyright holder.
  44. *
  45. * All trademarks and registered trademarks mentioned herein are the property
  46. * of their respective owners.
  47. */
  48. #ifndef GFX_SCRIPTITEMIZER_H
  49. #define GFX_SCRIPTITEMIZER_H
  50. #include <stdint.h>
  51. #include "nsUnicodeScriptCodes.h"
  52. #define PAREN_STACK_DEPTH 32
  53. class gfxScriptItemizer
  54. {
  55. public:
  56. typedef mozilla::unicode::Script Script;
  57. gfxScriptItemizer(const char16_t *src, uint32_t length);
  58. void SetText(const char16_t *src, uint32_t length);
  59. bool Next(uint32_t& aRunStart, uint32_t& aRunLimit,
  60. Script& aRunScript);
  61. protected:
  62. void reset() {
  63. scriptStart = 0;
  64. scriptLimit = 0;
  65. scriptCode = Script::INVALID;
  66. parenSP = -1;
  67. pushCount = 0;
  68. fixupCount = 0;
  69. }
  70. void push(uint32_t endPairChar, Script newScriptCode);
  71. void pop();
  72. void fixup(Script newScriptCode);
  73. struct ParenStackEntry {
  74. uint32_t endPairChar;
  75. Script scriptCode;
  76. };
  77. const char16_t *textPtr;
  78. uint32_t textLength;
  79. uint32_t scriptStart;
  80. uint32_t scriptLimit;
  81. Script scriptCode;
  82. struct ParenStackEntry parenStack[PAREN_STACK_DEPTH];
  83. uint32_t parenSP;
  84. uint32_t pushCount;
  85. uint32_t fixupCount;
  86. };
  87. #endif /* GFX_SCRIPTITEMIZER_H */