mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 15:31:05 +01:00
Use the chained rule type width for backtrack, input, and lookahead arrays. The hardcoded 16-bit writes truncated extended glyph IDs and shifted the lookup-record array. Add a byte-level regression covering all three glyph arrays. Tested with: meson test -C build --print-errorlogs Assisted-by: OpenAI Codex
125 lines
3.7 KiB
C++
125 lines
3.7 KiB
C++
/*
|
|
* Copyright © 2022 Behdad Esfahbod
|
|
*
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
*
|
|
* Permission is hereby granted, without written agreement and without
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
* software and its documentation for any purpose, provided that the
|
|
* above copyright notice and the following two paragraphs appear in
|
|
* all copies of this software.
|
|
*
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
* DAMAGE.
|
|
*
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
*
|
|
*/
|
|
|
|
#include "hb.hh"
|
|
#include "hb-serialize.hh"
|
|
#include "hb-ot-layout-common.hh"
|
|
#include "hb-ot-layout-gsubgpos.hh"
|
|
|
|
using OT::Layout::Common::Coverage;
|
|
|
|
static void
|
|
test_medium_rule ()
|
|
{
|
|
static const char data[] = {
|
|
0, 2, 0, 1, /* inputCount, lookupCount */
|
|
0, 0, 5, /* input glyph */
|
|
0, 1, 0, 2, /* LookupRecord */
|
|
};
|
|
static const char expected[] = {
|
|
0, 2, 0, 1, /* inputCount, lookupCount */
|
|
1, 0, 1, /* input glyph */
|
|
0, 1, 0, 3, /* LookupRecord */
|
|
};
|
|
const auto &rule = *reinterpret_cast<const OT::Rule<OT::Layout::MediumTypes> *> (data);
|
|
|
|
hb_map_t glyph_map;
|
|
glyph_map.set (5, 0x10001);
|
|
hb_map_t lookup_map;
|
|
lookup_map.set (2, 3);
|
|
|
|
char buf[32];
|
|
hb_serialize_context_t s (buf, sizeof (buf));
|
|
s.start_serialize ();
|
|
hb_always_assert (rule.serialize (&s, &glyph_map, &lookup_map));
|
|
s.end_serialize ();
|
|
|
|
hb_bytes_t bytes = s.copy_bytes ();
|
|
hb_always_assert (bytes.length == sizeof (expected));
|
|
hb_always_assert (!hb_memcmp (bytes.arrayZ, expected, sizeof (expected)));
|
|
bytes.fini ();
|
|
}
|
|
|
|
static void
|
|
test_medium_chain_rule ()
|
|
{
|
|
static const char data[] = {
|
|
0, 1, 0, 0, 5, /* backtrack */
|
|
0, 2, 0, 0, 6, /* input */
|
|
0, 1, 0, 0, 7, /* lookahead */
|
|
0, 1, 0, 0, 0, 2, /* LookupRecord */
|
|
};
|
|
static const char expected[] = {
|
|
0, 1, 1, 0, 1, /* backtrack */
|
|
0, 2, 1, 0, 2, /* input */
|
|
0, 1, 1, 0, 3, /* lookahead */
|
|
0, 1, 0, 0, 0, 3, /* LookupRecord */
|
|
};
|
|
const auto &rule = *reinterpret_cast<const OT::ChainRule<OT::Layout::MediumTypes> *> (data);
|
|
|
|
hb_map_t glyph_map;
|
|
glyph_map.set (5, 0x10001);
|
|
glyph_map.set (6, 0x10002);
|
|
glyph_map.set (7, 0x10003);
|
|
hb_map_t lookup_map;
|
|
lookup_map.set (2, 3);
|
|
|
|
char buf[32];
|
|
hb_serialize_context_t s (buf, sizeof (buf));
|
|
s.start_serialize ();
|
|
hb_always_assert (rule.serialize (&s, &lookup_map, &glyph_map));
|
|
s.end_serialize ();
|
|
|
|
hb_bytes_t bytes = s.copy_bytes ();
|
|
hb_always_assert (bytes.length == sizeof (expected));
|
|
hb_always_assert (!hb_memcmp (bytes.arrayZ, expected, sizeof (expected)));
|
|
bytes.fini ();
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
test_medium_rule ();
|
|
test_medium_chain_rule ();
|
|
|
|
char buf[16384];
|
|
|
|
hb_serialize_context_t s (buf, sizeof (buf));
|
|
|
|
hb_sorted_vector_t<hb_codepoint_t> v{1, 2, 5};
|
|
|
|
auto c = s.start_serialize<Coverage> ();
|
|
|
|
c->serialize (&s, hb_iter (v));
|
|
|
|
s.end_serialize ();
|
|
|
|
hb_bytes_t bytes = s.copy_bytes ();
|
|
hb_always_assert (bytes.length == 10);
|
|
bytes.fini ();
|
|
|
|
return 0;
|
|
}
|