/work/workdir/UnpackedTarball/harfbuzz/src/hb-kern.hh
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2017 Google, Inc. |
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 | | * Google Author(s): Behdad Esfahbod |
25 | | */ |
26 | | |
27 | | #ifndef HB_KERN_HH |
28 | | #define HB_KERN_HH |
29 | | |
30 | | #include "hb-open-type.hh" |
31 | | #include "hb-aat-layout-common.hh" |
32 | | #include "hb-ot-layout-gpos-table.hh" |
33 | | |
34 | | |
35 | | namespace OT { |
36 | | |
37 | | |
38 | | template <typename Driver> |
39 | | struct hb_kern_machine_t |
40 | | { |
41 | | hb_kern_machine_t (const Driver &driver_, |
42 | | bool crossStream_ = false) : |
43 | 883k | driver (driver_), |
44 | 883k | crossStream (crossStream_) {} Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<AAT::KerxSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat0<AAT::KerxSubTableHeader>::accelerator_t const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat2<AAT::KerxSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat2<AAT::KerxSubTableHeader>::accelerator_t const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat6<AAT::KerxSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat6<AAT::KerxSubTableHeader>::accelerator_t const&, bool) OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<OT::KernOTSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat0<OT::KernOTSubTableHeader>::accelerator_t const&, bool) Line | Count | Source | 43 | 883k | driver (driver_), | 44 | 883k | crossStream (crossStream_) {} |
Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat2<OT::KernOTSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat2<OT::KernOTSubTableHeader>::accelerator_t const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<OT::KernSubTableFormat3<OT::KernOTSubTableHeader> >::hb_kern_machine_t(OT::KernSubTableFormat3<OT::KernOTSubTableHeader> const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<OT::KernAATSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat0<OT::KernAATSubTableHeader>::accelerator_t const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat2<OT::KernAATSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat2<OT::KernAATSubTableHeader>::accelerator_t const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<OT::KernSubTableFormat3<OT::KernAATSubTableHeader> >::hb_kern_machine_t(OT::KernSubTableFormat3<OT::KernAATSubTableHeader> const&, bool) Unexecuted instantiation: OT::hb_kern_machine_t<hb_ot_shape_fallback_kern_driver_t>::hb_kern_machine_t(hb_ot_shape_fallback_kern_driver_t const&, bool) |
45 | | |
46 | | HB_NO_SANITIZE_SIGNED_INTEGER_OVERFLOW |
47 | | void kern (hb_font_t *font, |
48 | | hb_buffer_t *buffer, |
49 | | hb_mask_t kern_mask, |
50 | | bool scale = true) const |
51 | 883k | { |
52 | 883k | if (!buffer->message (font, "start kern")) |
53 | 0 | return; |
54 | | |
55 | 883k | buffer->unsafe_to_concat (); |
56 | 883k | OT::hb_ot_apply_context_t c (1, font, buffer, hb_blob_get_empty ()); |
57 | 883k | c.set_lookup_mask (kern_mask); |
58 | 883k | c.set_lookup_props (OT::LookupFlag::IgnoreMarks); |
59 | 883k | auto &skippy_iter = c.iter_input; |
60 | | |
61 | 883k | bool horizontal = HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction); |
62 | 883k | unsigned int count = buffer->len; |
63 | 883k | hb_glyph_info_t *info = buffer->info; |
64 | 883k | hb_glyph_position_t *pos = buffer->pos; |
65 | 4.76M | for (unsigned int idx = 0; idx < count;) |
66 | 3.88M | { |
67 | 3.88M | if (!(info[idx].mask & kern_mask)) |
68 | 0 | { |
69 | 0 | idx++; |
70 | 0 | continue; |
71 | 0 | } |
72 | | |
73 | 3.88M | skippy_iter.reset (idx); |
74 | 3.88M | unsigned unsafe_to; |
75 | 3.88M | if (!skippy_iter.next (&unsafe_to)) |
76 | 884k | { |
77 | 884k | idx++; |
78 | 884k | continue; |
79 | 884k | } |
80 | | |
81 | 2.99M | unsigned int i = idx; |
82 | 2.99M | unsigned int j = skippy_iter.idx; |
83 | | |
84 | 2.99M | hb_position_t kern = driver.get_kerning (info[i].codepoint, |
85 | 2.99M | info[j].codepoint); |
86 | | |
87 | | |
88 | 2.99M | if (likely (!kern)) |
89 | 2.88M | goto skip; |
90 | | |
91 | 115k | if (horizontal) |
92 | 115k | { |
93 | 115k | if (scale) |
94 | 115k | kern = font->em_scale_x (kern); |
95 | 115k | if (crossStream) |
96 | 0 | { |
97 | 0 | pos[j].y_offset = kern; |
98 | 0 | buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT; |
99 | 0 | } |
100 | 115k | else |
101 | 115k | { |
102 | 115k | hb_position_t kern1 = kern >> 1; |
103 | 115k | hb_position_t kern2 = kern - kern1; |
104 | 115k | pos[i].x_advance += kern1; |
105 | 115k | pos[j].x_advance += kern2; |
106 | 115k | pos[j].x_offset += kern2; |
107 | 115k | } |
108 | 115k | } |
109 | 0 | else |
110 | 0 | { |
111 | 0 | if (scale) |
112 | 0 | kern = font->em_scale_y (kern); |
113 | 0 | if (crossStream) |
114 | 0 | { |
115 | 0 | pos[j].x_offset = kern; |
116 | 0 | buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT; |
117 | 0 | } |
118 | 0 | else |
119 | 0 | { |
120 | 0 | hb_position_t kern1 = kern >> 1; |
121 | 0 | hb_position_t kern2 = kern - kern1; |
122 | 0 | pos[i].y_advance += kern1; |
123 | 0 | pos[j].y_advance += kern2; |
124 | 0 | pos[j].y_offset += kern2; |
125 | 0 | } |
126 | 0 | } |
127 | | |
128 | 115k | buffer->unsafe_to_break (i, j + 1); |
129 | | |
130 | 2.99M | skip: |
131 | 2.99M | idx = skippy_iter.idx; |
132 | 2.99M | } |
133 | | |
134 | 883k | (void) buffer->message (font, "end kern"); |
135 | 883k | } Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<AAT::KerxSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat2<AAT::KerxSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat6<AAT::KerxSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<OT::KernOTSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Line | Count | Source | 51 | 883k | { | 52 | 883k | if (!buffer->message (font, "start kern")) | 53 | 0 | return; | 54 | | | 55 | 883k | buffer->unsafe_to_concat (); | 56 | 883k | OT::hb_ot_apply_context_t c (1, font, buffer, hb_blob_get_empty ()); | 57 | 883k | c.set_lookup_mask (kern_mask); | 58 | 883k | c.set_lookup_props (OT::LookupFlag::IgnoreMarks); | 59 | 883k | auto &skippy_iter = c.iter_input; | 60 | | | 61 | 883k | bool horizontal = HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction); | 62 | 883k | unsigned int count = buffer->len; | 63 | 883k | hb_glyph_info_t *info = buffer->info; | 64 | 883k | hb_glyph_position_t *pos = buffer->pos; | 65 | 4.76M | for (unsigned int idx = 0; idx < count;) | 66 | 3.88M | { | 67 | 3.88M | if (!(info[idx].mask & kern_mask)) | 68 | 0 | { | 69 | 0 | idx++; | 70 | 0 | continue; | 71 | 0 | } | 72 | | | 73 | 3.88M | skippy_iter.reset (idx); | 74 | 3.88M | unsigned unsafe_to; | 75 | 3.88M | if (!skippy_iter.next (&unsafe_to)) | 76 | 884k | { | 77 | 884k | idx++; | 78 | 884k | continue; | 79 | 884k | } | 80 | | | 81 | 2.99M | unsigned int i = idx; | 82 | 2.99M | unsigned int j = skippy_iter.idx; | 83 | | | 84 | 2.99M | hb_position_t kern = driver.get_kerning (info[i].codepoint, | 85 | 2.99M | info[j].codepoint); | 86 | | | 87 | | | 88 | 2.99M | if (likely (!kern)) | 89 | 2.88M | goto skip; | 90 | | | 91 | 115k | if (horizontal) | 92 | 115k | { | 93 | 115k | if (scale) | 94 | 115k | kern = font->em_scale_x (kern); | 95 | 115k | if (crossStream) | 96 | 0 | { | 97 | 0 | pos[j].y_offset = kern; | 98 | 0 | buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT; | 99 | 0 | } | 100 | 115k | else | 101 | 115k | { | 102 | 115k | hb_position_t kern1 = kern >> 1; | 103 | 115k | hb_position_t kern2 = kern - kern1; | 104 | 115k | pos[i].x_advance += kern1; | 105 | 115k | pos[j].x_advance += kern2; | 106 | 115k | pos[j].x_offset += kern2; | 107 | 115k | } | 108 | 115k | } | 109 | 0 | else | 110 | 0 | { | 111 | 0 | if (scale) | 112 | 0 | kern = font->em_scale_y (kern); | 113 | 0 | if (crossStream) | 114 | 0 | { | 115 | 0 | pos[j].x_offset = kern; | 116 | 0 | buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT; | 117 | 0 | } | 118 | 0 | else | 119 | 0 | { | 120 | 0 | hb_position_t kern1 = kern >> 1; | 121 | 0 | hb_position_t kern2 = kern - kern1; | 122 | 0 | pos[i].y_advance += kern1; | 123 | 0 | pos[j].y_advance += kern2; | 124 | 0 | pos[j].y_offset += kern2; | 125 | 0 | } | 126 | 0 | } | 127 | | | 128 | 115k | buffer->unsafe_to_break (i, j + 1); | 129 | | | 130 | 2.99M | skip: | 131 | 2.99M | idx = skippy_iter.idx; | 132 | 2.99M | } | 133 | | | 134 | 883k | (void) buffer->message (font, "end kern"); | 135 | 883k | } |
Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat2<OT::KernOTSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<OT::KernSubTableFormat3<OT::KernOTSubTableHeader> >::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<OT::KernAATSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat2<OT::KernAATSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<OT::KernSubTableFormat3<OT::KernAATSubTableHeader> >::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const Unexecuted instantiation: OT::hb_kern_machine_t<hb_ot_shape_fallback_kern_driver_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const |
136 | | |
137 | | const Driver &driver; |
138 | | bool crossStream; |
139 | | }; |
140 | | |
141 | | |
142 | | } /* namespace OT */ |
143 | | |
144 | | |
145 | | #endif /* HB_KERN_HH */ |