diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index 95ac27128..ea24c9f0c 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -576,7 +576,7 @@ struct StateTable if (unlikely (stop > states)) return_trace (false); for (const HBUSHORT *p = states; stop < p; p--) - num_entries = MAX (num_entries, *(p - 1) + 1); + num_entries = hb_max (num_entries, *(p - 1) + 1); state_neg = min_state; } } @@ -597,7 +597,7 @@ struct StateTable if (unlikely (stop < states)) return_trace (false); for (const HBUSHORT *p = &states[state_pos * num_classes]; p < stop; p++) - num_entries = MAX (num_entries, *p + 1); + num_entries = hb_max (num_entries, *p + 1); state_pos = max_state + 1; } } @@ -611,8 +611,8 @@ struct StateTable for (const Entry *p = &entries[entry]; p < stop; p++) { int newState = new_state (p->newState); - min_state = MIN (min_state, newState); - max_state = MAX (max_state, newState); + min_state = hb_min (min_state, newState); + max_state = hb_max (max_state, newState); } entry = num_entries; } diff --git a/src/hb-aat-layout-feat-table.hh b/src/hb-aat-layout-feat-table.hh index ab23ee056..a20ef8640 100644 --- a/src/hb-aat-layout-feat-table.hh +++ b/src/hb-aat-layout-feat-table.hh @@ -165,7 +165,7 @@ struct feat unsigned int feature_count = featureNameCount; if (count && *count) { - unsigned int len = MIN (feature_count - start_offset, *count); + unsigned int len = hb_min (feature_count - start_offset, *count); for (unsigned int i = 0; i < len; i++) features[i] = namesZ[i + start_offset].get_feature_type (); *count = len; diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index bb41fea9d..1b3f1f942 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -251,7 +251,7 @@ struct KerxSubTableFormat1 if (Format1EntryT::performAction (entry) && depth) { - unsigned int tuple_count = MAX (1u, table->header.tuple_count ()); + unsigned int tuple_count = hb_max (1u, table->header.tuple_count ()); unsigned int kern_idx = Format1EntryT::kernActionIndex (entry); kern_idx = Types::byteOffsetToIndex (kern_idx, &table->machine, kernAction.arrayZ); diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 4c4ea6206..7aa830d64 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -88,7 +88,7 @@ struct RearrangementSubtable start = buffer->idx; if (flags & MarkLast) - end = MIN (buffer->idx + 1, buffer->len); + end = hb_min (buffer->idx + 1, buffer->len); if ((flags & Verb) && start < end) { @@ -117,14 +117,14 @@ struct RearrangementSubtable }; unsigned int m = map[flags & Verb]; - unsigned int l = MIN (2, m >> 4); - unsigned int r = MIN (2, m & 0x0F); + unsigned int l = hb_min (2u, m >> 4); + unsigned int r = hb_min (2u, m & 0x0F); bool reverse_l = 3 == (m >> 4); bool reverse_r = 3 == (m & 0x0F); if (end - start >= l + r) { - buffer->merge_clusters (start, MIN (buffer->idx + 1, buffer->len)); + buffer->merge_clusters (start, hb_min (buffer->idx + 1, buffer->len)); buffer->merge_clusters (start, end); hb_glyph_info_t *info = buffer->info; @@ -261,13 +261,13 @@ struct ContextualSubtable } if (replacement) { - buffer->unsafe_to_break (mark, MIN (buffer->idx + 1, buffer->len)); + buffer->unsafe_to_break (mark, hb_min (buffer->idx + 1, buffer->len)); buffer->info[mark].codepoint = *replacement; ret = true; } replacement = nullptr; - unsigned int idx = MIN (buffer->idx, buffer->len - 1); + unsigned int idx = hb_min (buffer->idx, buffer->len - 1); if (Types::extended) { if (entry.data.currentIndex != 0xFFFF) @@ -337,9 +337,9 @@ struct ContextualSubtable const EntryData &data = entries[i].data; if (data.markIndex != 0xFFFF) - num_lookups = MAX (num_lookups, 1 + data.markIndex); + num_lookups = hb_max (num_lookups, 1 + data.markIndex); if (data.currentIndex != 0xFFFF) - num_lookups = MAX (num_lookups, 1 + data.currentIndex); + num_lookups = hb_max (num_lookups, 1 + data.currentIndex); } return_trace (substitutionTables.sanitize (c, this, num_lookups)); @@ -744,7 +744,7 @@ struct InsertionSubtable buffer->move_to (end + count); - buffer->unsafe_to_break_from_outbuffer (mark, MIN (buffer->idx + 1, buffer->len)); + buffer->unsafe_to_break_from_outbuffer (mark, hb_min (buffer->idx + 1, buffer->len)); } if (flags & SetMark) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 2d2fe31f0..eeac4b956 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -186,6 +186,10 @@ struct } HB_FUNCOBJ (hb_second); +/* Note. In min/max, we can use hb_type_identity for second argument. + * However, that would silently convert between different-signedness integers. + * Instead we accept two different types, such that compiler can err if + * comparing integers of different signedness. */ struct { template auto @@ -409,14 +413,6 @@ static inline unsigned char TOUPPER (unsigned char c) static inline unsigned char TOLOWER (unsigned char c) { return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } -#undef MIN -template -static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; } - -#undef MAX -template -static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; } - static inline unsigned int DIV_CEIL (const unsigned int a, unsigned int b) { return (a + (b - 1)) / b; } @@ -668,7 +664,7 @@ hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *o { /* Pain because we don't know whether s is nul-terminated. */ char buf[64]; - len = MIN (ARRAY_LENGTH (buf) - 1, len); + len = hb_min (ARRAY_LENGTH (buf) - 1, len); strncpy (buf, s, len); buf[len] = '\0'; diff --git a/src/hb-array.hh b/src/hb-array.hh index 37ca63d35..2da8df0bb 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -143,7 +143,7 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> } void qsort (unsigned int start, unsigned int end) { - end = MIN (end, length); + end = hb_min (end, length); assert (start <= end); if (likely (start < end)) ::qsort (arrayZ + start, end - start, this->item_size, Type::cmp); @@ -166,7 +166,7 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> else count -= start_offset; if (seg_count) - count = *seg_count = MIN (count, *seg_count); + count = *seg_count = hb_min (count, *seg_count); return hb_array_t (arrayZ + start_offset, count); } hb_array_t sub_array (unsigned int start_offset, unsigned int seg_count) const diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 54637c727..699f66b1a 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -155,7 +155,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent, hb_blob_make_immutable (parent); blob = hb_blob_create (parent->data + offset, - MIN (length, parent->length - offset), + hb_min (length, parent->length - offset), HB_MEMORY_MODE_READONLY, hb_blob_reference (parent), _hb_blob_destroy); diff --git a/src/hb-buffer-serialize.cc b/src/hb-buffer-serialize.cc index 6e265e84c..dcbdcea45 100644 --- a/src/hb-buffer-serialize.cc +++ b/src/hb-buffer-serialize.cc @@ -138,34 +138,34 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer, *p++ = '"'; } else - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint)); if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) { - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i].cluster)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i].cluster)); } if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS)) { - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d", + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d", x+pos[i].x_offset, y+pos[i].y_offset)); if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES)) - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d", + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d", pos[i].x_advance, pos[i].y_advance)); } if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS) { if (info[i].mask & HB_GLYPH_FLAG_DEFINED) - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"fl\":%u", info[i].mask & HB_GLYPH_FLAG_DEFINED)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"fl\":%u", info[i].mask & HB_GLYPH_FLAG_DEFINED)); } if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS) { hb_glyph_extents_t extents; hb_font_get_glyph_extents(font, info[i].codepoint, &extents); - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"xb\":%d,\"yb\":%d", + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"xb\":%d,\"yb\":%d", extents.x_bearing, extents.y_bearing)); - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"w\":%d,\"h\":%d", + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"w\":%d,\"h\":%d", extents.width, extents.height)); } @@ -224,37 +224,37 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, p += strlen (p); } else - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint)); if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) { - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster)); } if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS)) { if (x+pos[i].x_offset || y+pos[i].y_offset) - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", x+pos[i].x_offset, y+pos[i].y_offset)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", x+pos[i].x_offset, y+pos[i].y_offset)); if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_ADVANCES)) { *p++ = '+'; - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance)); if (pos[i].y_advance) - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance)); } } if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS) { if (info[i].mask & HB_GLYPH_FLAG_DEFINED) - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "#%X", info[i].mask &HB_GLYPH_FLAG_DEFINED)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "#%X", info[i].mask &HB_GLYPH_FLAG_DEFINED)); } if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS) { hb_glyph_extents_t extents; hb_font_get_glyph_extents(font, info[i].codepoint, &extents); - p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "<%d,%d,%d,%d>", extents.x_bearing, extents.y_bearing, extents.width, extents.height)); + p += hb_max (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "<%d,%d,%d,%d>", extents.x_bearing, extents.y_bearing, extents.width, extents.height)); } unsigned int l = p - b; @@ -380,7 +380,7 @@ static hb_bool_t parse_uint (const char *pp, const char *end, uint32_t *pv) { char buf[32]; - unsigned int len = MIN (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - pp)); + unsigned int len = hb_min (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - pp)); strncpy (buf, pp, len); buf[len] = '\0'; @@ -401,7 +401,7 @@ static hb_bool_t parse_int (const char *pp, const char *end, int32_t *pv) { char buf[32]; - unsigned int len = MIN (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - pp)); + unsigned int len = hb_min (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - pp)); strncpy (buf, pp, len); buf[len] = '\0'; diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index 2dc02e9d6..d95404f5c 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -524,7 +524,7 @@ hb_buffer_t::merge_clusters_impl (unsigned int start, unsigned int cluster = info[start].cluster; for (unsigned int i = start + 1; i < end; i++) - cluster = MIN (cluster, info[i].cluster); + cluster = hb_min (cluster, info[i].cluster); /* Extend end */ while (end < len && info[end - 1].cluster == info[end].cluster) @@ -555,7 +555,7 @@ hb_buffer_t::merge_out_clusters (unsigned int start, unsigned int cluster = out_info[start].cluster; for (unsigned int i = start + 1; i < end; i++) - cluster = MIN (cluster, out_info[i].cluster); + cluster = hb_min (cluster, out_info[i].cluster); /* Extend start */ while (start && out_info[start - 1].cluster == out_info[start].cluster) diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 330f88bac..b2b190ace 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -379,7 +379,7 @@ struct hb_buffer_t unsigned int cluster) const { for (unsigned int i = start; i < end; i++) - cluster = MIN (cluster, infos[i].cluster); + cluster = hb_min (cluster, infos[i].cluster); return cluster; } void diff --git a/src/hb-common.cc b/src/hb-common.cc index 6db801cdd..70be6939b 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -356,7 +356,7 @@ hb_language_from_string (const char *str, int len) { /* NUL-terminate it. */ char strbuf[64]; - len = MIN (len, (int) sizeof (strbuf) - 1); + len = hb_min (len, (int) sizeof (strbuf) - 1); memcpy (strbuf, str, len); strbuf[len] = '\0'; item = lang_find_or_insert (strbuf); @@ -720,7 +720,7 @@ static bool parse_uint (const char **pp, const char *end, unsigned int *pv) { char buf[32]; - unsigned int len = MIN (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); + unsigned int len = hb_min (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); strncpy (buf, *pp, len); buf[len] = '\0'; @@ -744,7 +744,7 @@ static bool parse_uint32 (const char **pp, const char *end, uint32_t *pv) { char buf[32]; - unsigned int len = MIN (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); + unsigned int len = hb_min (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); strncpy (buf, *pp, len); buf[len] = '\0'; @@ -825,7 +825,7 @@ static bool parse_float (const char **pp, const char *end, float *pv) { char buf[32]; - unsigned int len = MIN (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); + unsigned int len = hb_min (ARRAY_LENGTH (buf) - 1, (unsigned int) (end - *pp)); strncpy (buf, *pp, len); buf[len] = '\0'; @@ -1071,21 +1071,21 @@ hb_feature_to_string (hb_feature_t *feature, { s[len++] = '['; if (feature->start) - len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->start)); + len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->start)); if (feature->end != feature->start + 1) { s[len++] = ':'; if (feature->end != (unsigned int) -1) - len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->end)); + len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->end)); } s[len++] = ']'; } if (feature->value > 1) { s[len++] = '='; - len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->value)); + len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->value)); } assert (len < ARRAY_LENGTH (s)); - len = MIN (len, size - 1); + len = hb_min (len, size - 1); memcpy (buf, s, len); buf[len] = '\0'; } @@ -1152,10 +1152,10 @@ hb_variation_to_string (hb_variation_t *variation, while (len && s[len - 1] == ' ') len--; s[len++] = '='; - len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%g", (double) variation->value)); + len += hb_max (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%g", (double) variation->value)); assert (len < ARRAY_LENGTH (s)); - len = MIN (len, size - 1); + len = hb_min (len, size - 1); memcpy (buf, s, len); buf[len] = '\0'; } diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 66f0fce1a..e0579bed8 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -771,7 +771,7 @@ resize_and_retry: feature.start < chars_len && feature.start < feature.end) { CFRange feature_range = CFRangeMake (feature.start, - MIN (feature.end, chars_len) - feature.start); + hb_min (feature.end, chars_len) - feature.start); if (feature.value) CFAttributedStringRemoveAttribute (attr_string, feature_range, kCTKernAttributeName); else @@ -1116,7 +1116,7 @@ resize_and_retry: unsigned int cluster = info[count - 1].cluster; for (unsigned int i = count - 1; i > 0; i--) { - cluster = MIN (cluster, info[i - 1].cluster); + cluster = hb_min (cluster, info[i - 1].cluster); info[i - 1].cluster = cluster; } } @@ -1125,7 +1125,7 @@ resize_and_retry: unsigned int cluster = info[0].cluster; for (unsigned int i = 1; i < count; i++) { - cluster = MIN (cluster, info[i].cluster); + cluster = hb_min (cluster, info[i].cluster); info[i].cluster = cluster; } } diff --git a/src/hb-debug.hh b/src/hb-debug.hh index e5328e916..57b3f1b04 100644 --- a/src/hb-debug.hh +++ b/src/hb-debug.hh @@ -161,7 +161,7 @@ _hb_debug_msg_va (const char *what, VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR; fprintf (stderr, "%2u %s" VRBAR "%s", level, - bars + sizeof (bars) - 1 - MIN ((unsigned int) sizeof (bars) - 1, (unsigned int) (sizeof (VBAR) - 1) * level), + bars + sizeof (bars) - 1 - hb_min ((unsigned int) sizeof (bars) - 1, (unsigned int) (sizeof (VBAR) - 1) * level), level_dir ? (level_dir > 0 ? DLBAR : ULBAR) : LBAR); } else fprintf (stderr, " " VRBAR LBAR); diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index 8f2e66025..6b2761e83 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -778,7 +778,7 @@ retry_getglyphs: { uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index ()]]; - *p = MIN (*p, buffer->info[i].cluster); + *p = hb_min (*p, buffer->info[i].cluster); } for (unsigned int i = 1; i < glyphCount; i++) if (vis_clusters[i] == (uint32_t) -1) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index f8dab8bc1..d70c38a7a 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -439,7 +439,7 @@ hb_ft_get_glyph_from_name (hb_font_t *font HB_UNUSED, else { /* Make a nul-terminated version. */ char buf[128]; - len = MIN (len, (int) sizeof (buf) - 1); + len = hb_min (len, (int) sizeof (buf) - 1); strncpy (buf, name, len); buf[len] = '\0'; *glyph = FT_Get_Name_Index (ft_face, buf); diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 418ae9576..7358256c8 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -464,7 +464,7 @@ struct hb_zip_iter_t : __item_t__ __item__ () const { return __item_t__ (*a, *b); } __item_t__ __item_at__ (unsigned i) const { return __item_t__ (a[i], b[i]); } bool __more__ () const { return a && b; } - unsigned __len__ () const { return MIN (a.len (), b.len ()); } + unsigned __len__ () const { return hb_min (a.len (), b.len ()); } void __next__ () { ++a; ++b; } void __forward__ (unsigned n) { a += n; b += n; } void __prev__ () { --a; --b; } diff --git a/src/hb-open-file.hh b/src/hb-open-file.hh index 0689facd0..5318c7fca 100644 --- a/src/hb-open-file.hh +++ b/src/hb-open-file.hh @@ -94,7 +94,7 @@ typedef struct OffsetTable if (start_offset >= tables.len) *table_count = 0; else - *table_count = MIN (*table_count, tables.len - start_offset); + *table_count = hb_min (*table_count, tables.len - start_offset); const TableRecord *sub_tables = tables.arrayZ + start_offset; unsigned int count = *table_count; diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 2bfbee525..9458ceea7 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -921,7 +921,7 @@ struct BinSearchHeader { len = v; assert (len == v); - entrySelector = MAX (1u, hb_bit_storage (v)) - 1; + entrySelector = hb_max (1u, hb_bit_storage (v)) - 1; searchRange = 16 * (1u << entrySelector); rangeShift = v * 16 > searchRange ? 16 * v - searchRange diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 0a7d1ef67..b4c8c608b 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -93,7 +93,7 @@ struct CmapSubtableFormat4 this->length = get_sub_table_size (segments); this->segCountX2 = segments.length * 2; - this->entrySelector = MAX (1u, hb_bit_storage (segments.length)) - 1; + this->entrySelector = hb_max (1u, hb_bit_storage (segments.length)) - 1; this->searchRange = 2 * (1u << this->entrySelector); this->rangeShift = segments.length * 2 > this->searchRange ? 2 * segments.length - this->searchRange @@ -348,7 +348,7 @@ struct CmapSubtableFormat4 /* Some broken fonts have too long of a "length" value. * If that is the case, just change the value to truncate * the subtable at the end of the blob. */ - uint16_t new_length = (uint16_t) MIN ((uintptr_t) 65535, + uint16_t new_length = (uint16_t) hb_min ((uintptr_t) 65535, (uintptr_t) (c->end - (char *) this)); if (!c->try_set (&length, new_length)) @@ -478,7 +478,7 @@ struct CmapSubtableLongSegmented { for (unsigned int i = 0; i < this->groups.len; i++) { out->add_range (this->groups[i].startCharCode, - MIN ((hb_codepoint_t) this->groups[i].endCharCode, + hb_min ((hb_codepoint_t) this->groups[i].endCharCode, (hb_codepoint_t) HB_UNICODE_MAX)); } } @@ -623,7 +623,7 @@ struct DefaultUVS : SortedArrayOf for (unsigned int i = 0; i < count; i++) { hb_codepoint_t first = arrayZ[i].startUnicodeValue; - hb_codepoint_t last = MIN ((hb_codepoint_t) (first + arrayZ[i].additionalCount), + hb_codepoint_t last = hb_min ((hb_codepoint_t) (first + arrayZ[i].additionalCount), (hb_codepoint_t) HB_UNICODE_MAX); out->add_range (first, last); } diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index b6dc364a1..96b14bd68 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -349,15 +349,15 @@ struct CBLC if (unlikely (!count)) return Null(BitmapSizeTable); - unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem); + unsigned int requested_ppem = hb_max (font->x_ppem, font->y_ppem); if (!requested_ppem) requested_ppem = 1<<30; /* Choose largest strike. */ unsigned int best_i = 0; - unsigned int best_ppem = MAX (sizeTables[0].ppemX, sizeTables[0].ppemY); + unsigned int best_ppem = hb_max (sizeTables[0].ppemX, sizeTables[0].ppemY); for (unsigned int i = 1; i < count; i++) { - unsigned int ppem = MAX (sizeTables[i].ppemX, sizeTables[i].ppemY); + unsigned int ppem = hb_max (sizeTables[i].ppemX, sizeTables[i].ppemY); if ((requested_ppem <= ppem && ppem < best_ppem) || (requested_ppem > best_ppem && ppem > best_ppem)) { diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index 7df7059a8..9ec2957ea 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -144,7 +144,7 @@ struct CPAL { hb_array_t segment_colors = palette_colors.sub_array (start_offset, *color_count); /* Always return numColors colors per palette even if it has out-of-bounds start index. */ - unsigned int count = MIN (MAX (numColors - start_offset, 0), *color_count); + unsigned int count = hb_min ((unsigned) hb_max ((int) (numColors - start_offset), 0), *color_count); *color_count = count; for (unsigned int i = 0; i < count; i++) colors[i] = segment_colors[i]; /* Bound-checked read. */ diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 670c05504..f9739f9ef 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -175,7 +175,7 @@ struct sbix if (unlikely (!count)) return Null(SBIXStrike); - unsigned int requested_ppem = MAX (font->x_ppem, font->y_ppem); + unsigned int requested_ppem = hb_max (font->x_ppem, font->y_ppem); if (!requested_ppem) requested_ppem = 1<<30; /* Choose largest strike. */ /* TODO Add DPI sensitivity as well? */ diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index b595e5efe..2a96c2e35 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -58,7 +58,7 @@ struct loca public: DEFINE_SIZE_MIN (0); /* In reality, this is UNBOUNDED() type; but since we always * check the size externally, allow Null() object of it by - * defining it MIN() instead. */ + * defining it _MIN instead. */ }; @@ -241,7 +241,7 @@ struct glyf loca_table = hb_sanitize_context_t ().reference_table (face); glyf_table = hb_sanitize_context_t ().reference_table (face); - num_glyphs = MAX (1u, loca_table.get_length () / (short_offset ? 2 : 4)) - 1; + num_glyphs = hb_max (1u, loca_table.get_length () / (short_offset ? 2 : 4)) - 1; } void fini () @@ -451,10 +451,10 @@ struct glyf const GlyphHeader &glyph_header = StructAtOffset (glyf_table, start_offset); - extents->x_bearing = MIN (glyph_header.xMin, glyph_header.xMax); - extents->y_bearing = MAX (glyph_header.yMin, glyph_header.yMax); - extents->width = MAX (glyph_header.xMin, glyph_header.xMax) - extents->x_bearing; - extents->height = MIN (glyph_header.yMin, glyph_header.yMax) - extents->y_bearing; + extents->x_bearing = hb_min (glyph_header.xMin, glyph_header.xMax); + extents->y_bearing = hb_max (glyph_header.yMin, glyph_header.yMax); + extents->width = hb_max (glyph_header.xMin, glyph_header.xMax) - extents->x_bearing; + extents->height = hb_min (glyph_header.yMin, glyph_header.yMax) - extents->y_bearing; return true; } @@ -471,7 +471,7 @@ struct glyf public: DEFINE_SIZE_MIN (0); /* In reality, this is UNBOUNDED() type; but since we always * check the size externally, allow Null() object of it by - * defining it MIN() instead. */ + * defining it _MIN instead. */ }; struct glyf_accelerator_t : glyf::accelerator_t {}; diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 5dff981ef..b3a97109b 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -240,7 +240,7 @@ struct hmtxvmtx return default_advance; } - return table->longMetricZ[MIN (glyph, (uint32_t) num_advances - 1)].advance; + return table->longMetricZ[hb_min (glyph, (uint32_t) num_advances - 1)].advance; } unsigned int get_advance (hb_codepoint_t glyph, diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index 556e4316d..4693f3818 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -1287,7 +1287,7 @@ struct MarkLigPosFormat1 unsigned int mark_id = _hb_glyph_info_get_lig_id (&buffer->cur()); unsigned int mark_comp = _hb_glyph_info_get_lig_comp (&buffer->cur()); if (lig_id && lig_id == mark_id && mark_comp > 0) - comp_index = MIN (comp_count, _hb_glyph_info_get_lig_comp (&buffer->cur())) - 1; + comp_index = hb_min (comp_count, _hb_glyph_info_get_lig_comp (&buffer->cur())) - 1; else comp_index = comp_count - 1; diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index c5ebe44ec..5b25137c8 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -484,7 +484,7 @@ struct AlternateSet unsigned int shift = hb_ctz (lookup_mask); unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift); - /* If alt_index is MAX, randomize feature if it is the rand feature. */ + /* If alt_index is MAX_VALUE, randomize feature if it is the rand feature. */ if (alt_index == HB_OT_MAP_MAX_VALUE && c->random) alt_index = c->random_number () % count + 1; @@ -792,7 +792,7 @@ struct LigatureSet if (unlikely (!ligature.serialize (c, ligatures.length))) return_trace (false); for (unsigned int i = 0; i < ligatures.length; i++) { - unsigned int component_count = MAX (component_count_list[i] - 1, 0); + unsigned int component_count = (unsigned) hb_max ((int) component_count_list[i] - 1, 0); if (unlikely (!ligature[i].serialize (c, this) .serialize (c, ligatures[i], diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 5837e76d9..3c4bfa2c3 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -973,7 +973,7 @@ static inline bool ligate_input (hb_ot_apply_context_t *c, if (this_comp == 0) this_comp = last_num_components; unsigned int new_lig_comp = components_so_far - last_num_components + - MIN (this_comp, last_num_components); + hb_min (this_comp, last_num_components); _hb_glyph_info_set_lig_props_for_mark (&buffer->cur(), lig_id, new_lig_comp); } buffer->next_glyph (); @@ -995,7 +995,7 @@ static inline bool ligate_input (hb_ot_apply_context_t *c, if (!this_comp) break; unsigned int new_lig_comp = components_so_far - last_num_components + - MIN (this_comp, last_num_components); + hb_min (this_comp, last_num_components); _hb_glyph_info_set_lig_props_for_mark (&buffer->info[i], lig_id, new_lig_comp); } else break; @@ -1173,7 +1173,7 @@ static inline bool apply_lookup (hb_ot_apply_context_t *c, else { /* NOTE: delta is negative. */ - delta = MAX (delta, (int) next - (int) count); + delta = hb_max (delta, (int) next - (int) count); next -= delta; } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 1e2d159b5..817b28e68 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1735,7 +1735,7 @@ hb_ot_layout_feature_get_characters (hb_face_t *face, unsigned int len = 0; if (char_count && characters && start_offset < cv_params.characters.len) { - len = MIN (cv_params.characters.len - start_offset, *char_count); + len = hb_min (cv_params.characters.len - start_offset, *char_count); for (unsigned int i = 0; i < len; ++i) characters[i] = cv_params.characters[start_offset + i]; } diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 846414c9b..92d70bb41 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -188,12 +188,12 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, feature_infos[j].default_value = feature_infos[i].default_value; } else { feature_infos[j].flags &= ~F_GLOBAL; - feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_infos[i].max_value); + feature_infos[j].max_value = hb_max (feature_infos[j].max_value, feature_infos[i].max_value); /* Inherit default_value from j */ } feature_infos[j].flags |= (feature_infos[i].flags & F_HAS_FALLBACK); - feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_infos[i].stage[0]); - feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_infos[i].stage[1]); + feature_infos[j].stage[0] = hb_min (feature_infos[j].stage[0], feature_infos[i].stage[0]); + feature_infos[j].stage[1] = hb_min (feature_infos[j].stage[1], feature_infos[i].stage[1]); } feature_infos.shrink (j + 1); } @@ -213,7 +213,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m, bits_needed = 0; else /* Limit bits per feature. */ - bits_needed = MIN(HB_OT_MAP_MAX_BITS, hb_bit_storage (info->max_value)); + bits_needed = hb_min (HB_OT_MAP_MAX_BITS, hb_bit_storage (info->max_value)); if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t)) continue; /* Feature disabled, or not enough bits. */ diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 21aa94dad..12e08316a 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -131,7 +131,7 @@ struct post hb_bytes_t s = find_glyph_name (glyph); if (!s.length) return false; if (!buf_len) return true; - unsigned int len = MIN (buf_len - 1, s.length); + unsigned int len = hb_min (buf_len - 1, s.length); strncpy (buf, s.arrayZ, len); buf[len] = '\0'; return true; diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 6d46fe33c..7befbf630 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -645,7 +645,7 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, /* Reorder characters */ for (unsigned int i = start; i < base; i++) - info[i].indic_position() = MIN (POS_PRE_C, (indic_position_t) info[i].indic_position()); + info[i].indic_position() = hb_min (POS_PRE_C, (indic_position_t) info[i].indic_position()); if (base < end) info[base].indic_position() = POS_BASE_C; @@ -801,7 +801,7 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, unsigned int j = start + info[i].syllable(); while (j != i) { - max = MAX (max, j); + max = hb_max (max, j); unsigned int next = start + info[j].syllable(); info[j].syllable() = 255; /* So we don't process j later again. */ j = next; @@ -1231,14 +1231,14 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan, /* Note: this merge_clusters() is intentionally *after* the reordering. * Indic matra reordering is special and tricky... */ - buffer->merge_clusters (new_pos, MIN (end, base + 1)); + buffer->merge_clusters (new_pos, hb_min (end, base + 1)); new_pos--; } } else { for (unsigned int i = start; i < base; i++) if (info[i].indic_position () == POS_PRE_M) { - buffer->merge_clusters (i, MIN (end, base + 1)); + buffer->merge_clusters (i, hb_min (end, base + 1)); break; } } diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc index ec4d4aa7e..cbaa519c4 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc @@ -294,7 +294,7 @@ setup_rphf_mask (const hb_ot_shape_plan_t *plan, foreach_syllable (buffer, start, end) { - unsigned int limit = info[start].use_category() == USE_R ? 1 : MIN (3u, end - start); + unsigned int limit = info[start].use_category() == USE_R ? 1 : hb_min (3u, end - start); for (unsigned int i = start; i < start + limit; i++) info[i].mask |= mask; } diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 7fff3059e..03d9a68ae 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -962,12 +962,12 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR))) { - c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR, + c->buffer->max_len = hb_max (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR, (unsigned) HB_BUFFER_MAX_LEN_MIN); } if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR))) { - c->buffer->max_ops = MAX (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR, + c->buffer->max_ops = hb_max (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR, (unsigned) HB_BUFFER_MAX_OPS_MIN); } diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index c57c688d4..4b42da42d 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -212,7 +212,7 @@ struct LangTag p = strchr (b, '-'); db = p ? (unsigned int) (p - b) : strlen (b); - return strncmp (a, b, MAX (da, db)); + return strncmp (a, b, hb_max (da, db)); } int cmp (const LangTag *that) const { return cmp (that->language); } diff --git a/src/hb-ot-var-avar-table.hh b/src/hb-ot-var-avar-table.hh index c4a192dc9..57a3a6d16 100644 --- a/src/hb-ot-var-avar-table.hh +++ b/src/hb-ot-var-avar-table.hh @@ -123,7 +123,7 @@ struct avar void map_coords (int *coords, unsigned int coords_length) const { - unsigned int count = MIN (coords_length, axisCount); + unsigned int count = hb_min (coords_length, axisCount); const SegmentMaps *map = &firstAxisSegmentMaps; for (unsigned int i = 0; i < count; i++) diff --git a/src/hb-ot-var-fvar-table.hh b/src/hb-ot-var-fvar-table.hh index 78cb3c867..3565185fd 100644 --- a/src/hb-ot-var-fvar-table.hh +++ b/src/hb-ot-var-fvar-table.hh @@ -122,8 +122,8 @@ struct fvar info->name_id = axis.axisNameID; info->default_value = axis.defaultValue / 65536.; /* Ensure order, to simplify client math. */ - info->min_value = MIN (info->default_value, axis.minValue / 65536.); - info->max_value = MAX (info->default_value, axis.maxValue / 65536.); + info->min_value = hb_min (info->default_value, axis.minValue / 65536.); + info->max_value = hb_max (info->default_value, axis.maxValue / 65536.); } void get_axis_info (unsigned int axis_index, @@ -136,8 +136,8 @@ struct fvar info->flags = (hb_ot_var_axis_flags_t) (unsigned int) axis.flags; info->default_value = axis.defaultValue / 65536.; /* Ensure order, to simplify client math. */ - info->min_value = MIN (info->default_value, axis.minValue / 65536.); - info->max_value = MAX (info->default_value, axis.maxValue / 65536.); + info->min_value = hb_min (info->default_value, axis.minValue / 65536.); + info->max_value = hb_max (info->default_value, axis.maxValue / 65536.); info->reserved = 0; } @@ -149,12 +149,12 @@ struct fvar { /* TODO Rewrite as hb_array_t<>::sub-array() */ unsigned int count = axisCount; - start_offset = MIN (start_offset, count); + start_offset = hb_min (start_offset, count); count -= start_offset; axes_array += start_offset; - count = MIN (count, *axes_count); + count = hb_min (count, *axes_count); *axes_count = count; for (unsigned int i = 0; i < count; i++) @@ -171,12 +171,12 @@ struct fvar { /* TODO Rewrite as hb_array_t<>::sub-array() */ unsigned int count = axisCount; - start_offset = MIN (start_offset, count); + start_offset = hb_min (start_offset, count); count -= start_offset; axes_array += start_offset; - count = MIN (count, *axes_count); + count = hb_min (count, *axes_count); *axes_count = count; for (unsigned int i = 0; i < count; i++) @@ -223,7 +223,7 @@ struct fvar hb_ot_var_axis_info_t axis; get_axis_info (axis_index, &axis); - v = MAX (MIN (v, axis.max_value), axis.min_value); /* Clamp. */ + v = hb_max (hb_min (v, axis.max_value), axis.min_value); /* Clamp. */ if (v == axis.default_value) return 0; diff --git a/src/hb-sanitize.hh b/src/hb-sanitize.hh index 6799b7862..982723362 100644 --- a/src/hb-sanitize.hh +++ b/src/hb-sanitize.hh @@ -175,7 +175,7 @@ struct hb_sanitize_context_t : else { this->start = obj_start; - this->end = obj_start + MIN (this->end - obj_start, obj->get_size ()); + this->end = obj_start + hb_min (this->end - obj_start, obj->get_size ()); } } @@ -189,7 +189,7 @@ struct hb_sanitize_context_t : void start_processing () { reset_object (); - this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR, + this->max_ops = hb_max ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR, (unsigned) HB_SANITIZE_MAX_OPS_MIN); this->edit_count = 0; this->debug_depth = 0; diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 4bbbf6122..ac4ff6366 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -967,7 +967,7 @@ retry: vis_clusters[i] = (uint32_t) -1; for (unsigned int i = 0; i < buffer->len; i++) { uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index()]]; - *p = MIN (*p, buffer->info[i].cluster); + *p = hb_min (*p, buffer->info[i].cluster); } for (unsigned int i = 1; i < glyphs_len; i++) if (vis_clusters[i] == (uint32_t) -1)