Qunxin Liu | 22cca43 | 2023-04-20 14:37:29 -0700 | [diff] [blame] | 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 | struct Triple { |
| 31 | |
| 32 | Triple () : |
| 33 | minimum (0.f), middle (0.f), maximum (0.f) {} |
| 34 | |
| 35 | Triple (float minimum_, float middle_, float maximum_) : |
| 36 | minimum (minimum_), middle (middle_), maximum (maximum_) {} |
| 37 | |
| 38 | bool operator == (const Triple &o) const |
| 39 | { |
| 40 | return minimum == o.minimum && |
| 41 | middle == o.middle && |
| 42 | maximum == o.maximum; |
| 43 | } |
| 44 | |
Qunxin Liu | 389446c | 2023-06-08 09:07:47 -0700 | [diff] [blame] | 45 | bool operator != (const Triple o) const |
| 46 | { return !(*this == o); } |
| 47 | |
Qunxin Liu | 22cca43 | 2023-04-20 14:37:29 -0700 | [diff] [blame] | 48 | bool is_point () const |
| 49 | { return minimum == middle && middle == maximum; } |
| 50 | |
Qunxin Liu | 39ac79a | 2023-05-10 10:22:49 -0700 | [diff] [blame] | 51 | bool contains (float point) const |
| 52 | { return minimum <= point && point <= maximum; } |
| 53 | |
Qunxin Liu | 389446c | 2023-06-08 09:07:47 -0700 | [diff] [blame] | 54 | /* from hb_array_t hash ()*/ |
| 55 | uint32_t hash () const |
| 56 | { |
| 57 | uint32_t current = /*cbf29ce4*/0x84222325; |
| 58 | current = current ^ hb_hash (minimum); |
| 59 | current = current * 16777619; |
| 60 | |
| 61 | current = current ^ hb_hash (middle); |
| 62 | current = current * 16777619; |
| 63 | |
| 64 | current = current ^ hb_hash (maximum); |
| 65 | current = current * 16777619; |
| 66 | return current; |
| 67 | } |
| 68 | |
Qunxin Liu | 22cca43 | 2023-04-20 14:37:29 -0700 | [diff] [blame] | 69 | float minimum; |
| 70 | float middle; |
| 71 | float maximum; |
| 72 | }; |
| 73 | |
| 74 | using result_item_t = hb_pair_t<float, Triple>; |
| 75 | using result_t = hb_vector_t<result_item_t>; |
| 76 | |
| 77 | /* Given a tuple (lower,peak,upper) "tent" and new axis limits |
| 78 | * (axisMin,axisDefault,axisMax), solves how to represent the tent |
| 79 | * under the new axis configuration. All values are in normalized |
| 80 | * -1,0,+1 coordinate system. Tent values can be outside this range. |
| 81 | * |
| 82 | * Return value: a list of tuples. Each tuple is of the form |
| 83 | * (scalar,tent), where scalar is a multipler to multiply any |
| 84 | * delta-sets by, and tent is a new tent for that output delta-set. |
| 85 | * If tent value is Triple{}, that is a special deltaset that should |
| 86 | * be always-enabled (called "gain"). |
| 87 | */ |
| 88 | HB_INTERNAL result_t rebase_tent (Triple tent, Triple axisLimit); |
| 89 | |
| 90 | #endif /* HB_SUBSET_INSTANCER_SOLVER_HH */ |