tor-browser

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

hb-paint-bounded.hh (2821B)


      1 /*
      2 * Copyright © 2022 Behdad Esfahbod
      3 *
      4 *  This is part of HarfBuzz, a text shaping library.
      5 *
      6 * Permission is hereby granted, without written agreement and without
      7 * license or royalty fees, to use, copy, modify, and distribute this
      8 * software and its documentation for any purpose, provided that the
      9 * above copyright notice and the following two paragraphs appear in
     10 * all copies of this software.
     11 *
     12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
     13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
     14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
     15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
     16 * DAMAGE.
     17 *
     18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
     19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
     20 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
     21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
     22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
     23 */
     24 
     25 #ifndef HB_PAINT_BOUNDED_HH
     26 #define HB_PAINT_BOUNDED_HH
     27 
     28 #include "hb.hh"
     29 #include "hb-paint.h"
     30 
     31 #include "hb-geometry.hh"
     32 
     33 
     34 typedef struct  hb_paint_bounded_context_t hb_paint_bounded_context_t;
     35 
     36 struct hb_paint_bounded_context_t
     37 {
     38  void clear ()
     39  {
     40    clips = 0;
     41    bounded = true;
     42    groups.clear ();
     43  }
     44 
     45  hb_paint_bounded_context_t ()
     46  {
     47    clear ();
     48  }
     49 
     50  bool is_bounded ()
     51  {
     52    return bounded;
     53  }
     54 
     55  void push_clip ()
     56  {
     57    clips++;
     58  }
     59 
     60  void pop_clip ()
     61  {
     62    if (clips == 0) return;
     63    clips--;
     64  }
     65 
     66  void push_group ()
     67  {
     68    groups.push (bounded);
     69    bounded = true;
     70  }
     71 
     72  void pop_group (hb_paint_composite_mode_t mode)
     73  {
     74    const bool src_bounded = bounded;
     75    bounded = groups.pop ();
     76    bool &backdrop_bounded = bounded;
     77 
     78    // https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite
     79    switch ((int) mode)
     80    {
     81      case HB_PAINT_COMPOSITE_MODE_CLEAR:
     82 backdrop_bounded = true;
     83 break;
     84      case HB_PAINT_COMPOSITE_MODE_SRC:
     85      case HB_PAINT_COMPOSITE_MODE_SRC_OUT:
     86 backdrop_bounded = src_bounded;
     87 break;
     88      case HB_PAINT_COMPOSITE_MODE_DEST:
     89      case HB_PAINT_COMPOSITE_MODE_DEST_OUT:
     90 break;
     91      case HB_PAINT_COMPOSITE_MODE_SRC_IN:
     92      case HB_PAINT_COMPOSITE_MODE_DEST_IN:
     93 backdrop_bounded = backdrop_bounded && src_bounded;
     94 break;
     95      default:
     96 backdrop_bounded = backdrop_bounded || src_bounded;
     97 break;
     98     }
     99  }
    100 
    101  void paint ()
    102  {
    103    if (!clips)
    104      bounded = false;
    105  }
    106 
    107  protected:
    108  bool bounded; // true if current drawing bounded
    109  unsigned clips; // number of active clips
    110  hb_vector_t<bool> groups; // true if group bounded
    111 };
    112 
    113 HB_INTERNAL hb_paint_funcs_t *
    114 hb_paint_bounded_get_funcs ();
    115 
    116 
    117 #endif /* HB_PAINT_BOUNDED_HH */