OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
3 * Copyright © 2010,2012 Google, Inc. | 3 * Copyright © 2010,2012 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 | 1163 |
1164 struct Device | 1164 struct Device |
1165 { | 1165 { |
1166 | 1166 |
1167 inline hb_position_t get_x_delta (hb_font_t *font) const | 1167 inline hb_position_t get_x_delta (hb_font_t *font) const |
1168 { return get_delta (font->x_ppem, font->x_scale); } | 1168 { return get_delta (font->x_ppem, font->x_scale); } |
1169 | 1169 |
1170 inline hb_position_t get_y_delta (hb_font_t *font) const | 1170 inline hb_position_t get_y_delta (hb_font_t *font) const |
1171 { return get_delta (font->y_ppem, font->y_scale); } | 1171 { return get_delta (font->y_ppem, font->y_scale); } |
1172 | 1172 |
| 1173 inline unsigned int get_size (void) const |
| 1174 { |
| 1175 unsigned int f = deltaFormat; |
| 1176 if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::sta
tic_size; |
| 1177 return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); |
| 1178 } |
| 1179 |
| 1180 inline bool sanitize (hb_sanitize_context_t *c) const |
| 1181 { |
| 1182 TRACE_SANITIZE (this); |
| 1183 return_trace (c->check_struct (this) && c->check_range (this, this->get_size
())); |
| 1184 } |
| 1185 |
| 1186 private: |
| 1187 |
1173 inline int get_delta (unsigned int ppem, int scale) const | 1188 inline int get_delta (unsigned int ppem, int scale) const |
1174 { | 1189 { |
1175 if (!ppem) return 0; | 1190 if (!ppem) return 0; |
1176 | 1191 |
1177 int pixels = get_delta_pixels (ppem); | 1192 int pixels = get_delta_pixels (ppem); |
1178 | 1193 |
1179 if (!pixels) return 0; | 1194 if (!pixels) return 0; |
1180 | 1195 |
1181 return (int) (pixels * (int64_t) scale / ppem); | 1196 return (int) (pixels * (int64_t) scale / ppem); |
1182 } | 1197 } |
1183 | |
1184 | |
1185 inline int get_delta_pixels (unsigned int ppem_size) const | 1198 inline int get_delta_pixels (unsigned int ppem_size) const |
1186 { | 1199 { |
1187 unsigned int f = deltaFormat; | 1200 unsigned int f = deltaFormat; |
1188 if (unlikely (f < 1 || f > 3)) | 1201 if (unlikely (f < 1 || f > 3)) |
1189 return 0; | 1202 return 0; |
1190 | 1203 |
1191 if (ppem_size < startSize || ppem_size > endSize) | 1204 if (ppem_size < startSize || ppem_size > endSize) |
1192 return 0; | 1205 return 0; |
1193 | 1206 |
1194 unsigned int s = ppem_size - startSize; | 1207 unsigned int s = ppem_size - startSize; |
1195 | 1208 |
1196 unsigned int byte = deltaValue[s >> (4 - f)]; | 1209 unsigned int byte = deltaValue[s >> (4 - f)]; |
1197 unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f)))
; | 1210 unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f)))
; |
1198 unsigned int mask = (0xFFFFu >> (16 - (1 << f))); | 1211 unsigned int mask = (0xFFFFu >> (16 - (1 << f))); |
1199 | 1212 |
1200 int delta = bits & mask; | 1213 int delta = bits & mask; |
1201 | 1214 |
1202 if ((unsigned int) delta >= ((mask + 1) >> 1)) | 1215 if ((unsigned int) delta >= ((mask + 1) >> 1)) |
1203 delta -= mask + 1; | 1216 delta -= mask + 1; |
1204 | 1217 |
1205 return delta; | 1218 return delta; |
1206 } | 1219 } |
1207 | 1220 |
1208 inline unsigned int get_size (void) const | |
1209 { | |
1210 unsigned int f = deltaFormat; | |
1211 if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::sta
tic_size; | |
1212 return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); | |
1213 } | |
1214 | |
1215 inline bool sanitize (hb_sanitize_context_t *c) const | |
1216 { | |
1217 TRACE_SANITIZE (this); | |
1218 return_trace (c->check_struct (this) && c->check_range (this, this->get_size
())); | |
1219 } | |
1220 | |
1221 protected: | 1221 protected: |
1222 USHORT startSize; /* Smallest size to correct--in ppem */ | 1222 USHORT startSize; /* Smallest size to correct--in ppem */ |
1223 USHORT endSize; /* Largest size to correct--in ppem */ | 1223 USHORT endSize; /* Largest size to correct--in ppem */ |
1224 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2
, or 3 | 1224 USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2
, or 3 |
1225 * 1 Signed 2-bit value, 8 values per
uint16 | 1225 * 1 Signed 2-bit value, 8 values per
uint16 |
1226 * 2 Signed 4-bit value, 4 values per
uint16 | 1226 * 2 Signed 4-bit value, 4 values per
uint16 |
1227 * 3 Signed 8-bit value, 2 values per
uint16 | 1227 * 3 Signed 8-bit value, 2 values per
uint16 |
1228 */ | 1228 */ |
1229 USHORT deltaValue[VAR]; /* Array of compressed data */ | 1229 USHORT deltaValue[VAR]; /* Array of compressed data */ |
1230 public: | 1230 public: |
1231 DEFINE_SIZE_ARRAY (6, deltaValue); | 1231 DEFINE_SIZE_ARRAY (6, deltaValue); |
1232 }; | 1232 }; |
1233 | 1233 |
1234 | 1234 |
1235 } /* namespace OT */ | 1235 } /* namespace OT */ |
1236 | 1236 |
1237 | 1237 |
1238 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ | 1238 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ |
OLD | NEW |