tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gfxScriptItemizer.h (3771B)


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