Coverage Report

Created: 2025-11-16 09:57

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