• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2011,2012,2013  Google, Inc.
3  * Copyright © 2021  Khaled Hosny
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  * Google Author(s): Behdad Esfahbod
26  */
27 
28 #ifndef HB_MS_FEATURE_RANGES_HH
29 #define HB_MS_FEATURE_RANGES_HH
30 
31 #include "hb.hh"
32 
33 typedef struct hb_ms_feature_t {
34   uint32_t tag_le;
35   uint32_t value;
36 } hb_ms_feature_t;
37 
38 typedef struct hb_ms_features_t {
39   hb_ms_feature_t *features;
40   uint32_t         num_features;
41 } hb_ms_features_t;
42 
43 struct hb_ms_active_feature_t {
44   hb_ms_feature_t fea;
45   unsigned int order;
46 
cmphb_ms_active_feature_t47   HB_INTERNAL static int cmp (const void *pa, const void *pb) {
48     const auto *a = (const hb_ms_active_feature_t *) pa;
49     const auto *b = (const hb_ms_active_feature_t *) pb;
50     return a->fea.tag_le < b->fea.tag_le ? -1 : a->fea.tag_le > b->fea.tag_le ? 1 :
51 	   a->order < b->order ? -1 : a->order > b->order ? 1 :
52 	   a->fea.value < b->fea.value ? -1 : a->fea.value > b->fea.value ? 1 :
53 	   0;
54   }
operator ==hb_ms_active_feature_t55   bool operator== (const hb_ms_active_feature_t *f)
56   { return cmp (this, f) == 0; }
57 };
58 
59 struct hb_ms_feature_event_t {
60   unsigned int index;
61   bool start;
62   hb_ms_active_feature_t feature;
63 
cmphb_ms_feature_event_t64   HB_INTERNAL static int cmp (const void *pa, const void *pb)
65   {
66     const auto *a = (const hb_ms_feature_event_t *) pa;
67     const auto *b = (const hb_ms_feature_event_t *) pb;
68     return a->index < b->index ? -1 : a->index > b->index ? 1 :
69 	   a->start < b->start ? -1 : a->start > b->start ? 1 :
70 	   hb_ms_active_feature_t::cmp (&a->feature, &b->feature);
71   }
72 };
73 
74 struct hb_ms_range_record_t {
75   hb_ms_features_t features;
76   unsigned int index_first; /* == start */
77   unsigned int index_last;  /* == end - 1 */
78 };
79 
80 HB_INTERNAL bool
81 hb_ms_setup_features (const hb_feature_t                *features,
82 		      unsigned int                       num_features,
83 		      hb_vector_t<hb_ms_feature_t>      &feature_records, /* OUT */
84 		      hb_vector_t<hb_ms_range_record_t> &range_records /* OUT */);
85 
86 
87 HB_INTERNAL void
88 hb_ms_make_feature_ranges (hb_vector_t<hb_ms_feature_t>      &feature_records,
89 			   hb_vector_t<hb_ms_range_record_t> &range_records,
90 			   unsigned int                       chars_offset,
91 			   unsigned int                       chars_len,
92 			   uint16_t                          *log_clusters,
93 			   hb_vector_t<hb_ms_features_t*>    &range_features, /* OUT */
94 			   hb_vector_t<uint32_t>             &range_counts /* OUT */);
95 
96 #endif /* HB_MS_FEATURE_RANGES_HH */
97