/src/harfbuzz/src/hb-subset-instancer-solver.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2023 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_SUBSET_INSTANCER_SOLVER_HH |
26 | | #define HB_SUBSET_INSTANCER_SOLVER_HH |
27 | | |
28 | | #include "hb.hh" |
29 | | |
30 | | /* pre-normalized distances */ |
31 | | struct TripleDistances |
32 | | { |
33 | 28.0k | TripleDistances (): negative (1.0), positive (1.0) {} |
34 | 347 | TripleDistances (double neg_, double pos_): negative (neg_), positive (pos_) {} |
35 | | TripleDistances (double min, double default_, double max) |
36 | 2.35k | { |
37 | 2.35k | negative = default_ - min; |
38 | 2.35k | positive = max - default_; |
39 | 2.35k | } |
40 | | |
41 | | double negative; |
42 | | double positive; |
43 | | }; |
44 | | |
45 | | struct Triple { |
46 | | |
47 | | Triple () : |
48 | 44.7M | minimum (0.0), middle (0.0), maximum (0.0) {} |
49 | | |
50 | | Triple (double minimum_, double middle_, double maximum_) : |
51 | 2.70M | minimum (minimum_), middle (middle_), maximum (maximum_) {} |
52 | | |
53 | | bool operator == (const Triple &o) const |
54 | 49.7k | { |
55 | 49.7k | return minimum == o.minimum && |
56 | 49.7k | middle == o.middle && |
57 | 49.7k | maximum == o.maximum; |
58 | 49.7k | } |
59 | | |
60 | | bool operator != (const Triple o) const |
61 | 49.7k | { return !(*this == o); } |
62 | | |
63 | | bool is_point () const |
64 | 16.0k | { return minimum == middle && middle == maximum; } |
65 | | |
66 | | bool contains (double point) const |
67 | 0 | { return minimum <= point && point <= maximum; } |
68 | | |
69 | | /* from hb_array_t hash ()*/ |
70 | | uint32_t hash () const |
71 | 2.75M | { |
72 | 2.75M | uint32_t current = /*cbf29ce4*/0x84222325; |
73 | 2.75M | current = current ^ hb_hash (minimum); |
74 | 2.75M | current = current * 16777619; |
75 | | |
76 | 2.75M | current = current ^ hb_hash (middle); |
77 | 2.75M | current = current * 16777619; |
78 | | |
79 | 2.75M | current = current ^ hb_hash (maximum); |
80 | 2.75M | current = current * 16777619; |
81 | 2.75M | return current; |
82 | 2.75M | } |
83 | | |
84 | | |
85 | | double minimum; |
86 | | double middle; |
87 | | double maximum; |
88 | | }; |
89 | | |
90 | | using rebase_tent_result_item_t = hb_pair_t<double, Triple>; |
91 | | using rebase_tent_result_t = hb_vector_t<rebase_tent_result_item_t>; |
92 | | |
93 | | /* renormalize a normalized value v to the range of an axis, |
94 | | * considering the prenormalized distances as well as the new axis limits. |
95 | | * Ported from fonttools */ |
96 | | HB_INTERNAL double renormalizeValue (double v, const Triple &triple, |
97 | | const TripleDistances &triple_distances, |
98 | | bool extrapolate = true); |
99 | | /* Given a tuple (lower,peak,upper) "tent" and new axis limits |
100 | | * (axisMin,axisDefault,axisMax), solves how to represent the tent |
101 | | * under the new axis configuration. All values are in normalized |
102 | | * -1,0,+1 coordinate system. Tent values can be outside this range. |
103 | | * |
104 | | * Return value: a list of tuples. Each tuple is of the form |
105 | | * (scalar,tent), where scalar is a multipler to multiply any |
106 | | * delta-sets by, and tent is a new tent for that output delta-set. |
107 | | * If tent value is Triple{}, that is a special deltaset that should |
108 | | * be always-enabled (called "gain"). |
109 | | */ |
110 | | HB_INTERNAL rebase_tent_result_t rebase_tent (Triple tent, |
111 | | Triple axisLimit, |
112 | | TripleDistances axis_triple_distances); |
113 | | |
114 | | #endif /* HB_SUBSET_INSTANCER_SOLVER_HH */ |