/src/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 | | driver (driver_), |
44 | 0 | 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) Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<OT::KernOTSubTableHeader>::accelerator_t>::hb_kern_machine_t(AAT::KerxSubTableFormat0<OT::KernOTSubTableHeader>::accelerator_t const&, bool) 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 | 0 | { |
52 | 0 | if (!buffer->message (font, "start kern")) |
53 | 0 | return; |
54 | | |
55 | 0 | buffer->unsafe_to_concat (); |
56 | 0 | OT::hb_ot_apply_context_t c (1, font, buffer, hb_blob_get_empty ()); |
57 | 0 | c.set_lookup_mask (kern_mask); |
58 | 0 | c.set_lookup_props (OT::LookupFlag::IgnoreMarks); |
59 | 0 | auto &skippy_iter = c.iter_input; |
60 | |
|
61 | 0 | bool horizontal = HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction); |
62 | 0 | unsigned int count = buffer->len; |
63 | 0 | hb_glyph_info_t *info = buffer->info; |
64 | 0 | hb_glyph_position_t *pos = buffer->pos; |
65 | 0 | for (unsigned int idx = 0; idx < count;) |
66 | 0 | { |
67 | 0 | if (!(info[idx].mask & kern_mask)) |
68 | 0 | { |
69 | 0 | idx++; |
70 | 0 | continue; |
71 | 0 | } |
72 | | |
73 | 0 | skippy_iter.reset (idx); |
74 | 0 | unsigned unsafe_to; |
75 | 0 | if (!skippy_iter.next (&unsafe_to)) |
76 | 0 | { |
77 | 0 | idx++; |
78 | 0 | continue; |
79 | 0 | } |
80 | | |
81 | 0 | unsigned int i = idx; |
82 | 0 | unsigned int j = skippy_iter.idx; |
83 | |
|
84 | 0 | hb_position_t kern = driver.get_kerning (info[i].codepoint, |
85 | 0 | info[j].codepoint); |
86 | | |
87 | |
|
88 | 0 | if (likely (!kern)) |
89 | 0 | goto skip; |
90 | | |
91 | 0 | if (horizontal) |
92 | 0 | { |
93 | 0 | if (scale) |
94 | 0 | kern = font->em_scale_x (kern); |
95 | 0 | 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 | 0 | else |
101 | 0 | { |
102 | 0 | hb_position_t kern1 = kern >> 1; |
103 | 0 | hb_position_t kern2 = kern - kern1; |
104 | 0 | pos[i].x_advance += kern1; |
105 | 0 | pos[j].x_advance += kern2; |
106 | 0 | pos[j].x_offset += kern2; |
107 | 0 | } |
108 | 0 | } |
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 | 0 | buffer->unsafe_to_break (i, j + 1); |
129 | |
|
130 | 0 | skip: |
131 | 0 | idx = skippy_iter.idx; |
132 | 0 | } |
133 | | |
134 | 0 | (void) buffer->message (font, "end kern"); |
135 | 0 | } Unexecuted instantiation: OT::hb_kern_machine_t<AAT::KerxSubTableFormat0<OT::KernOTSubTableHeader>::accelerator_t>::kern(hb_font_t*, hb_buffer_t*, unsigned int, bool) const 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<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 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 */ |