• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2007,2008,2009  Red Hat, Inc.
3  * Copyright © 2010,2012  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod, Garret Rieger
27  */
28 
29 #ifndef OT_LAYOUT_COMMON_RANGERECORD_HH
30 #define OT_LAYOUT_COMMON_RANGERECORD_HH
31 
32 namespace OT {
33 namespace Layout {
34 namespace Common {
35 
36 template <typename Types>
37 struct RangeRecord
38 {
39   typename Types::HBGlyphID     first;          /* First GlyphID in the range */
40   typename Types::HBGlyphID     last;           /* Last GlyphID in the range */
41   HBUINT16                      value;          /* Value */
42 
43   DEFINE_SIZE_STATIC (2 + 2 * Types::size);
44 
sanitizeOT::Layout::Common::RangeRecord45   bool sanitize (hb_sanitize_context_t *c) const
46   {
47     TRACE_SANITIZE (this);
48     return_trace (c->check_struct (this));
49   }
50 
cmpOT::Layout::Common::RangeRecord51   int cmp (hb_codepoint_t g) const
52   { return g < first ? -1 : g <= last ? 0 : +1; }
53 
get_populationOT::Layout::Common::RangeRecord54   unsigned get_population () const
55   {
56     if (unlikely (last < first)) return 0;
57     return (last - first + 1);
58   }
59 
intersectsOT::Layout::Common::RangeRecord60   bool intersects (const hb_set_t &glyphs) const
61   { return glyphs.intersects (first, last); }
62 
63   template <typename set_t>
collect_coverageOT::Layout::Common::RangeRecord64   bool collect_coverage (set_t *glyphs) const
65   { return glyphs->add_range (first, last); }
66 };
67 
68 }
69 }
70 }
71 
72 // TODO(garretrieger): This was previously implemented using
73 //    DECLARE_NULL_NAMESPACE_BYTES_TEMPLATE1 (OT, RangeRecord, 9);
74 //    but that only works when there is only a single namespace level.
75 //    The macro should probably be fixed so it can work in this situation.
76 extern HB_INTERNAL const unsigned char _hb_Null_OT_RangeRecord[9];
77 template <typename Spec>
78 struct Null<OT::Layout::Common::RangeRecord<Spec>> {
get_nullNull79   static OT::Layout::Common::RangeRecord<Spec> const & get_null () {
80     return *reinterpret_cast<const OT::Layout::Common::RangeRecord<Spec> *> (_hb_Null_OT_RangeRecord);
81   }
82 };
83 
84 
85 #endif  // #ifndef OT_LAYOUT_COMMON_RANGERECORD_HH
86