diff options
author | Ebrahim Byagowi <ebrahim@gnu.org> | 2018-02-25 12:30:33 +0330 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-02-26 00:15:26 -0800 |
commit | bb82f01383db7cf05040fbd5881e17e263ef6369 (patch) | |
tree | 744a949cbfa28a323da1864c6b18032cd8bef0c4 | |
parent | becb1d9eea15c07f9ea4e229be56f9aca0f768af (diff) |
[aat] trak sanitization
-rwxr-xr-x | src/dev-run.sh | 4 | ||||
-rw-r--r-- | src/hb-aat-layout-trak-table.hh | 95 | ||||
-rw-r--r-- | src/hb-aat-layout.cc | 2 | ||||
-rw-r--r-- | util/options.hh | 2 |
4 files changed, 78 insertions, 25 deletions
diff --git a/src/dev-run.sh b/src/dev-run.sh index 3b2257b1..c7018112 100755 --- a/src/dev-run.sh +++ b/src/dev-run.sh @@ -35,7 +35,7 @@ find src/ | entr printf '\0' | while read -d ""; do fi done -read -n 1 -p "[T]est, [D]ebug, [R]estart, [Q]uit?" answer +read -n 1 -p "[T]est, [D]ebug, [R]estart, [Q]uit? " answer case "$answer" in t|T ) if [[ $CMAKENINJA ]]; then @@ -48,7 +48,7 @@ d|D ) if [[ $CMAKENINJA ]]; then echo "Not supported on cmake builds yet" else - build/libtool --mode=execute $GDB build/util/hb-shape $@ + build/libtool --mode=execute $GDB -- build/util/hb-shape $@ fi ;; r|R ) diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index b248db2f..7af62022 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -39,11 +39,15 @@ namespace AAT { struct TrackTableEntry { - inline bool sanitize (hb_sanitize_context_t *c) const + inline bool sanitize (hb_sanitize_context_t *c, const void *base, uint16_t size) const { TRACE_SANITIZE (this); - /* XXX Sanitize values */ - return_trace (c->check_struct (this)); + return_trace (c->check_struct (this) && ((base+values).sanitize (c, size))); + } + + inline Fixed get_track_value () const + { + return track; } inline float get_value (const void *base, unsigned int index) const @@ -64,11 +68,29 @@ struct TrackTableEntry struct TrackData { - inline bool sanitize (hb_sanitize_context_t *c) const + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - /* TODO */ - return_trace (c->check_struct (this)); + if (!(c->check_struct (this))) + return_trace (false); + + uint16_t tracks = (uint16_t) nTracks; + uint16_t sizes = (uint16_t) nSizes; + + // It should have at least one track + if (tracks < 1) return_trace (false); + + // We can not do interpolation with less than two + if (sizes < 2) return_trace (false); + + if (!((base+sizeTable).sanitize (c, sizes))) + return_trace (false); + + for (uint16_t i = 0; i < tracks; ++i) + if (!(trackTable[i].sanitize (c, base, sizes))) + return_trace (false); + + return_trace (true); } inline float get_tracking (const void *base, float ptem) const @@ -84,26 +106,37 @@ struct TrackData /* TODO Clean this up. */ - // TODO: Make indexing work and use only an entry with zero track - const TrackTableEntry &trackTableEntry = trackTable[0]; + uint16_t tracks = (uint16_t) nTracks; + uint16_t sizes = (uint16_t) nSizes; + + const TrackTableEntry *trackTableEntry = nullptr; + for (unsigned int i = 0; i < sizes; ++i) + // For now we only seek for track entries with zero tracking value + if (trackTable[i].get_track_value () == 0) + trackTableEntry = &trackTable[0]; + + // We couldn't match any, exit + if (!trackTableEntry) return 0.; /* TODO bfind() */ unsigned int size_index; - for (size_index = 0; size_index < nSizes; ++size_index) - if ((base+sizeTable)[size_index] >= fixed_size) + UnsizedArrayOf<Fixed> size_table = base+sizeTable; + for (size_index = 0; size_index < sizes; ++size_index) + if (size_table[size_index] >= fixed_size) break; - // We don't attempt to extrapolate to larger or smaller values - if (size_index == nSizes) - return trackTableEntry.get_value (base, nSizes - 1); - if (size_index == 0 || (base+sizeTable)[size_index] == fixed_size) - return trackTableEntry.get_value (base, size_index); + // TODO(ebraminio): We don't attempt to extrapolate to larger or + // smaller values for now but we should do, per spec + if (size_index == sizes) + return trackTableEntry->get_value (base, sizes - 1); + if (size_index == 0 || size_table[size_index] == fixed_size) + return trackTableEntry->get_value (base, size_index); - float s0 = (base+sizeTable)[size_index - 1].to_float (); - float s1 = (base+sizeTable)[size_index].to_float (); + float s0 = size_table[size_index - 1].to_float (); + float s1 = size_table[size_index].to_float (); float t = (csspx - s0) / (s1 - s0); - return t * trackTableEntry.get_value (base, size_index) + - (1.0 - t) * trackTableEntry.get_value (base, size_index - 1); + return t * trackTableEntry->get_value (base, size_index) + + (1.0 - t) * trackTableEntry->get_value (base, size_index - 1); } protected: @@ -124,8 +157,28 @@ struct trak inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - /* TODO */ - return_trace (c->check_struct (this)); + + if (!(c->check_struct (this))) + return_trace (false); + + if ((format != 0) || (reserved != 0)) + return_trace (false); + + if (horizData) + { + const TrackData &trackData = this+horizData; + if (!trackData.sanitize (c, this)) + return_trace (false); + } + + if (vertData) + { + const TrackData &trackData = this+horizData; + if (!trackData.sanitize (c, this)) + return_trace (false); + } + + return_trace (true); } inline bool apply (hb_aat_apply_context_t *c) const diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index bdbe41f9..45268e3e 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -36,7 +36,7 @@ #include "hb-aat-layout-trak-table.hh" /* - * mort/morx + * morx/kerx/trak */ static inline const AAT::ankr& diff --git a/util/options.hh b/util/options.hh index cfbbade2..09d7245f 100644 --- a/util/options.hh +++ b/util/options.hh @@ -454,7 +454,7 @@ struct font_options_t : option_group_t default_font_size = default_font_size_; x_ppem = 0; y_ppem = 0; - ptem = .0; + ptem = 0.; subpixel_bits = subpixel_bits_; font_file = nullptr; face_index = 0; |