mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
[aat] Fix mort contextual substitution offsets
The legacy mort contextual subtable uses signed word offsets to per-glyph substitution tables. A zero offset means that there is no table for that action. We were treating the fields like morx lookup indices with 0xFFFF as the sentinel, so zero-offset state entries tried to substitute arbitrary glyphs from the start of the state table. Keep morx using lookup-index semantics, but use signed offsets and the zero sentinel for mort. This fixes CharcoalCY shaping of text such as "Empty-handed", which previously produced out-of-font glyph IDs. Testing: - b/util/hb-shape CharcoalCY.dfont Empty-handed - b/util/hb-shape CharcoalCY.dfont --unicodes=002D,002D - meson test -Cb Fixes: https://github.com/harfbuzz/harfbuzz/issues/5887 Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
4b287d9f86
commit
20bc59869e
2 files changed
+41
-30
No files matched your search
+11
-11
@@ -1134,31 +1134,31 @@ struct ObsoleteTypes
|
||||
typedef ClassTable<HBUINT16> ClassTypeWide;
|
||||
|
||||
template <typename T>
|
||||
static unsigned int offsetToIndex (unsigned int offset,
|
||||
const void *base,
|
||||
const T *array)
|
||||
static int offsetToIndex (int offset,
|
||||
const void *base,
|
||||
const T *array)
|
||||
{
|
||||
/* https://github.com/harfbuzz/harfbuzz/issues/3483 */
|
||||
/* If offset is less than base, return an offset that would
|
||||
* result in an address half a 32bit address-space away,
|
||||
* to make sure sanitize fails even on 32bit builds. */
|
||||
if (unlikely (offset < unsigned ((const char *) array - (const char *) base)))
|
||||
if (unlikely (offset < int ((const char *) array - (const char *) base)))
|
||||
return INT_MAX / T::static_size;
|
||||
|
||||
/* https://github.com/harfbuzz/harfbuzz/issues/2816 */
|
||||
return (offset - unsigned ((const char *) array - (const char *) base)) / T::static_size;
|
||||
return (offset - int ((const char *) array - (const char *) base)) / T::static_size;
|
||||
}
|
||||
template <typename T>
|
||||
static unsigned int byteOffsetToIndex (unsigned int offset,
|
||||
const void *base,
|
||||
const T *array)
|
||||
static int byteOffsetToIndex (int offset,
|
||||
const void *base,
|
||||
const T *array)
|
||||
{
|
||||
return offsetToIndex (offset, base, array);
|
||||
}
|
||||
template <typename T>
|
||||
static unsigned int wordOffsetToIndex (unsigned int offset,
|
||||
const void *base,
|
||||
const T *array)
|
||||
static int wordOffsetToIndex (int offset,
|
||||
const void *base,
|
||||
const T *array)
|
||||
{
|
||||
return offsetToIndex (2 * offset, base, array);
|
||||
}
|
||||
|
||||
@@ -200,10 +200,12 @@ struct ContextualSubtable
|
||||
|
||||
struct EntryData
|
||||
{
|
||||
HBUINT16 markIndex; /* Index of the substitution table for the
|
||||
* marked glyph (use 0xFFFF for none). */
|
||||
HBUINT16 currentIndex; /* Index of the substitution table for the
|
||||
* current glyph (use 0xFFFF for none). */
|
||||
typedef typename std::conditional<Types::extended, HBUINT16, HBINT16>::type OffsetType;
|
||||
|
||||
OffsetType markIndex; /* Index/offset of the substitution table for the
|
||||
* marked glyph. */
|
||||
OffsetType currentIndex; /* Index/offset of the substitution table for the
|
||||
* current glyph. */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (4);
|
||||
};
|
||||
@@ -222,7 +224,10 @@ struct ContextualSubtable
|
||||
}
|
||||
bool is_actionable (const Entry<EntryData> &entry) const
|
||||
{
|
||||
return entry.data.markIndex != 0xFFFF || entry.data.currentIndex != 0xFFFF;
|
||||
if (Types::extended)
|
||||
return entry.data.markIndex != 0xFFFF || entry.data.currentIndex != 0xFFFF;
|
||||
else
|
||||
return entry.data.markIndex || entry.data.currentIndex;
|
||||
}
|
||||
|
||||
struct driver_context_t
|
||||
@@ -260,13 +265,16 @@ struct ContextualSubtable
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int offset = entry.data.markIndex + buffer->info[mark].codepoint;
|
||||
const UnsizedArrayOf<HBGlyphID16> &subs_old = (const UnsizedArrayOf<HBGlyphID16> &) subs;
|
||||
replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
|
||||
if (!(replacement->sanitize (&c->sanitizer) &&
|
||||
hb_barrier () &&
|
||||
*replacement))
|
||||
replacement = nullptr;
|
||||
if (entry.data.markIndex)
|
||||
{
|
||||
int offset = (int) entry.data.markIndex + buffer->info[mark].codepoint;
|
||||
const UnsizedArrayOf<HBGlyphID16> &subs_old = (const UnsizedArrayOf<HBGlyphID16> &) subs;
|
||||
replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
|
||||
if (!(replacement->sanitize (&c->sanitizer) &&
|
||||
hb_barrier () &&
|
||||
*replacement))
|
||||
replacement = nullptr;
|
||||
}
|
||||
}
|
||||
if (replacement)
|
||||
{
|
||||
@@ -287,13 +295,16 @@ struct ContextualSubtable
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int offset = entry.data.currentIndex + buffer->info[idx].codepoint;
|
||||
const UnsizedArrayOf<HBGlyphID16> &subs_old = (const UnsizedArrayOf<HBGlyphID16> &) subs;
|
||||
replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
|
||||
if (!(replacement->sanitize (&c->sanitizer) &&
|
||||
hb_barrier () &&
|
||||
*replacement))
|
||||
replacement = nullptr;
|
||||
if (entry.data.currentIndex)
|
||||
{
|
||||
int offset = (int) entry.data.currentIndex + buffer->info[idx].codepoint;
|
||||
const UnsizedArrayOf<HBGlyphID16> &subs_old = (const UnsizedArrayOf<HBGlyphID16> &) subs;
|
||||
replacement = &subs_old[Types::wordOffsetToIndex (offset, table, subs_old.arrayZ)];
|
||||
if (!(replacement->sanitize (&c->sanitizer) &&
|
||||
hb_barrier () &&
|
||||
*replacement))
|
||||
replacement = nullptr;
|
||||
}
|
||||
}
|
||||
if (replacement)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user