1 #ifndef OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH 2 #define OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH 3 4 #include "Common.hh" 5 #include "ValueFormat.hh" 6 7 namespace OT { 8 namespace Layout { 9 namespace GPOS_impl { 10 11 struct SinglePosFormat1 12 { 13 protected: 14 HBUINT16 format; /* Format identifier--format = 1 */ 15 Offset16To<Coverage> 16 coverage; /* Offset to Coverage table--from 17 * beginning of subtable */ 18 ValueFormat valueFormat; /* Defines the types of data in the 19 * ValueRecord */ 20 ValueRecord values; /* Defines positioning 21 * value(s)--applied to all glyphs in 22 * the Coverage table */ 23 public: 24 DEFINE_SIZE_ARRAY (6, values); 25 sanitizeOT::Layout::GPOS_impl::SinglePosFormat126 bool sanitize (hb_sanitize_context_t *c) const 27 { 28 TRACE_SANITIZE (this); 29 return_trace (c->check_struct (this) && 30 coverage.sanitize (c, this) && 31 valueFormat.sanitize_value (c, this, values)); 32 } 33 intersectsOT::Layout::GPOS_impl::SinglePosFormat134 bool intersects (const hb_set_t *glyphs) const 35 { return (this+coverage).intersects (glyphs); } 36 closure_lookupsOT::Layout::GPOS_impl::SinglePosFormat137 void closure_lookups (hb_closure_lookups_context_t *c) const {} collect_variation_indicesOT::Layout::GPOS_impl::SinglePosFormat138 void collect_variation_indices (hb_collect_variation_indices_context_t *c) const 39 { 40 if (!valueFormat.has_device ()) return; 41 42 hb_set_t intersection; 43 (this+coverage).intersect_set (*c->glyph_set, intersection); 44 if (!intersection) return; 45 46 valueFormat.collect_variation_indices (c, this, values.as_array (valueFormat.get_len ())); 47 } 48 collect_glyphsOT::Layout::GPOS_impl::SinglePosFormat149 void collect_glyphs (hb_collect_glyphs_context_t *c) const 50 { if (unlikely (!(this+coverage).collect_coverage (c->input))) return; } 51 get_coverageOT::Layout::GPOS_impl::SinglePosFormat152 const Coverage &get_coverage () const { return this+coverage; } 53 get_value_formatOT::Layout::GPOS_impl::SinglePosFormat154 ValueFormat get_value_format () const { return valueFormat; } 55 applyOT::Layout::GPOS_impl::SinglePosFormat156 bool apply (hb_ot_apply_context_t *c) const 57 { 58 TRACE_APPLY (this); 59 hb_buffer_t *buffer = c->buffer; 60 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint); 61 if (likely (index == NOT_COVERED)) return_trace (false); 62 63 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) 64 { 65 c->buffer->message (c->font, 66 "positioning glyph at %d", 67 c->buffer->idx); 68 } 69 70 valueFormat.apply_value (c, this, values, buffer->cur_pos()); 71 72 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) 73 { 74 c->buffer->message (c->font, 75 "positioned glyph at %d", 76 c->buffer->idx); 77 } 78 79 buffer->idx++; 80 return_trace (true); 81 } 82 83 bool position_singleOT::Layout::GPOS_impl::SinglePosFormat184 position_single (hb_font_t *font, 85 hb_direction_t direction, 86 hb_codepoint_t gid, 87 hb_glyph_position_t &pos) const 88 { 89 unsigned int index = (this+coverage).get_coverage (gid); 90 if (likely (index == NOT_COVERED)) return false; 91 92 /* This is ugly... */ 93 hb_buffer_t buffer; 94 buffer.props.direction = direction; 95 OT::hb_ot_apply_context_t c (1, font, &buffer); 96 97 valueFormat.apply_value (&c, this, values, pos); 98 return true; 99 } 100 101 template<typename Iterator, 102 typename SrcLookup, 103 hb_requires (hb_is_iterator (Iterator))> serializeOT::Layout::GPOS_impl::SinglePosFormat1104 void serialize (hb_serialize_context_t *c, 105 const SrcLookup *src, 106 Iterator it, 107 ValueFormat newFormat, 108 const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map) 109 { 110 if (unlikely (!c->extend_min (this))) return; 111 if (unlikely (!c->check_assign (valueFormat, 112 newFormat, 113 HB_SERIALIZE_ERROR_INT_OVERFLOW))) return; 114 115 for (const hb_array_t<const Value>& _ : + it | hb_map (hb_second)) 116 { 117 src->get_value_format ().copy_values (c, newFormat, src, &_, layout_variation_idx_delta_map); 118 // Only serialize the first entry in the iterator, the rest are assumed to 119 // be the same. 120 break; 121 } 122 123 auto glyphs = 124 + it 125 | hb_map_retains_sorting (hb_first) 126 ; 127 128 coverage.serialize_serialize (c, glyphs); 129 } 130 subsetOT::Layout::GPOS_impl::SinglePosFormat1131 bool subset (hb_subset_context_t *c) const 132 { 133 TRACE_SUBSET (this); 134 const hb_set_t &glyphset = *c->plan->glyphset_gsub (); 135 const hb_map_t &glyph_map = *c->plan->glyph_map; 136 137 hb_set_t intersection; 138 (this+coverage).intersect_set (glyphset, intersection); 139 140 auto it = 141 + hb_iter (intersection) 142 | hb_map_retains_sorting (glyph_map) 143 | hb_zip (hb_repeat (values.as_array (valueFormat.get_len ()))) 144 ; 145 146 bool ret = bool (it); 147 SinglePos_serialize (c->serializer, this, it, c->plan->layout_variation_idx_delta_map, c->plan->all_axes_pinned); 148 return_trace (ret); 149 } 150 }; 151 152 } 153 } 154 } 155 156 #endif /* OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH */ 157