2022-01-20 23:39:48 +01:00
|
|
|
#ifndef OT_LAYOUT_GSUB_SINGLESUBST_HH
|
|
|
|
#define OT_LAYOUT_GSUB_SINGLESUBST_HH
|
2022-01-13 23:17:51 +01:00
|
|
|
|
|
|
|
#include "Common.hh"
|
|
|
|
#include "SingleSubstFormat1.hh"
|
|
|
|
#include "SingleSubstFormat2.hh"
|
|
|
|
|
|
|
|
namespace OT {
|
|
|
|
namespace Layout {
|
2022-06-30 01:52:08 +02:00
|
|
|
namespace GSUB_impl {
|
2022-01-13 23:17:51 +01:00
|
|
|
|
|
|
|
struct SingleSubst
|
|
|
|
{
|
2022-01-26 16:22:40 +01:00
|
|
|
protected:
|
|
|
|
union {
|
2022-07-06 21:11:53 +02:00
|
|
|
HBUINT16 format; /* Format identifier */
|
|
|
|
SingleSubstFormat1_3<SmallTypes> format1;
|
|
|
|
SingleSubstFormat2_4<SmallTypes> format2;
|
2022-10-29 19:15:03 +02:00
|
|
|
#ifndef HB_NO_BEYOND_64K
|
2022-07-06 21:28:17 +02:00
|
|
|
SingleSubstFormat1_3<MediumTypes> format3;
|
|
|
|
SingleSubstFormat2_4<MediumTypes> format4;
|
|
|
|
#endif
|
2022-01-26 16:22:40 +01:00
|
|
|
} u;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
template <typename context_t, typename ...Ts>
|
|
|
|
typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const
|
|
|
|
{
|
2023-01-21 23:00:41 +01:00
|
|
|
if (unlikely (!c->may_dispatch (this, &u.format))) return c->no_dispatch_return_value ();
|
2022-01-26 16:22:40 +01:00
|
|
|
TRACE_DISPATCH (this, u.format);
|
|
|
|
switch (u.format) {
|
|
|
|
case 1: return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...));
|
|
|
|
case 2: return_trace (c->dispatch (u.format2, std::forward<Ts> (ds)...));
|
2022-10-29 19:15:03 +02:00
|
|
|
#ifndef HB_NO_BEYOND_64K
|
2022-07-06 21:28:17 +02:00
|
|
|
case 3: return_trace (c->dispatch (u.format3, std::forward<Ts> (ds)...));
|
|
|
|
case 4: return_trace (c->dispatch (u.format4, std::forward<Ts> (ds)...));
|
|
|
|
#endif
|
2022-01-26 16:22:40 +01:00
|
|
|
default:return_trace (c->default_return_value ());
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 23:17:51 +01:00
|
|
|
|
|
|
|
template<typename Iterator,
|
|
|
|
hb_requires (hb_is_sorted_source_of (Iterator,
|
|
|
|
const hb_codepoint_pair_t))>
|
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
Iterator glyphs)
|
|
|
|
{
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
if (unlikely (!c->extend_min (u.format))) return_trace (false);
|
|
|
|
unsigned format = 2;
|
|
|
|
unsigned delta = 0;
|
|
|
|
if (glyphs)
|
|
|
|
{
|
|
|
|
format = 1;
|
2022-07-06 21:28:17 +02:00
|
|
|
hb_codepoint_t mask = 0xFFFFu;
|
|
|
|
|
2022-10-29 19:15:03 +02:00
|
|
|
#ifndef HB_NO_BEYOND_64K
|
2022-07-06 21:28:17 +02:00
|
|
|
if (+ glyphs
|
|
|
|
| hb_map_retains_sorting (hb_first)
|
|
|
|
| hb_filter ([] (hb_codepoint_t gid) { return gid > 0xFFFFu; }))
|
|
|
|
{
|
|
|
|
format += 2;
|
|
|
|
mask = 0xFFFFFFu;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-13 23:17:51 +01:00
|
|
|
auto get_delta = [=] (hb_codepoint_pair_t _)
|
2022-07-06 21:28:17 +02:00
|
|
|
{ return (unsigned) (_.second - _.first) & mask; };
|
2022-01-13 23:17:51 +01:00
|
|
|
delta = get_delta (*glyphs);
|
2022-07-06 21:28:17 +02:00
|
|
|
if (!hb_all (++(+glyphs), delta, get_delta)) format += 1;
|
2022-01-13 23:17:51 +01:00
|
|
|
}
|
2022-07-06 21:28:17 +02:00
|
|
|
|
2022-01-13 23:17:51 +01:00
|
|
|
u.format = format;
|
|
|
|
switch (u.format) {
|
|
|
|
case 1: return_trace (u.format1.serialize (c,
|
|
|
|
+ glyphs
|
|
|
|
| hb_map_retains_sorting (hb_first),
|
|
|
|
delta));
|
|
|
|
case 2: return_trace (u.format2.serialize (c, glyphs));
|
2022-10-29 19:15:03 +02:00
|
|
|
#ifndef HB_NO_BEYOND_64K
|
2022-07-06 21:28:17 +02:00
|
|
|
case 3: return_trace (u.format3.serialize (c,
|
|
|
|
+ glyphs
|
|
|
|
| hb_map_retains_sorting (hb_first),
|
|
|
|
delta));
|
|
|
|
case 4: return_trace (u.format4.serialize (c, glyphs));
|
|
|
|
#endif
|
2022-01-13 23:17:51 +01:00
|
|
|
default:return_trace (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Iterator>
|
|
|
|
static void
|
|
|
|
SingleSubst_serialize (hb_serialize_context_t *c,
|
|
|
|
Iterator it)
|
|
|
|
{ c->start_embed<SingleSubst> ()->serialize (c, it); }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 23:39:48 +01:00
|
|
|
#endif /* OT_LAYOUT_GSUB_SINGLESUBST_HH */
|