2018-10-23 10:58:59 +02:00
|
|
|
/*
|
2018-11-12 17:47:07 +01:00
|
|
|
* Copyright © 2018 Adobe Inc.
|
2018-10-23 10:58:59 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Adobe Author(s): Michiharu Ariza
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_OT_VORG_TABLE_HH
|
|
|
|
#define HB_OT_VORG_TABLE_HH
|
|
|
|
|
|
|
|
#include "hb-open-type.hh"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VORG -- Vertical Origin Table
|
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/vorg
|
|
|
|
*/
|
|
|
|
#define HB_OT_TAG_VORG HB_TAG('V','O','R','G')
|
|
|
|
|
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
struct VertOriginMetric
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
int cmp (hb_codepoint_t g) const { return glyph.cmp (g); }
|
2018-10-23 11:09:42 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-23 10:58:59 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2021-09-19 22:30:12 +02:00
|
|
|
HBGlyphID16 glyph;
|
2018-10-23 10:58:59 +02:00
|
|
|
FWORD vertOriginY;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_STATIC (4);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VORG
|
|
|
|
{
|
2019-01-22 12:08:57 +01:00
|
|
|
static constexpr hb_tag_t tableTag = HB_OT_TAG_VORG;
|
2018-10-23 10:58:59 +02:00
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
bool has_data () const { return version.to_int (); }
|
2018-10-23 11:09:42 +02:00
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
int get_y_origin (hb_codepoint_t glyph) const
|
2018-10-23 11:09:42 +02:00
|
|
|
{
|
2018-11-24 06:35:31 +01:00
|
|
|
unsigned int i;
|
|
|
|
if (!vertYOrigins.bfind (glyph, &i))
|
|
|
|
return defaultVertOriginY;
|
|
|
|
return vertYOrigins[i].vertOriginY;
|
2018-10-23 11:09:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-12 20:02:48 +02:00
|
|
|
template <typename Iterator,
|
2019-08-24 15:27:14 +02:00
|
|
|
hb_requires (hb_is_iterator (Iterator))>
|
2019-06-12 20:02:48 +02:00
|
|
|
void serialize (hb_serialize_context_t *c,
|
2019-08-24 15:27:14 +02:00
|
|
|
Iterator it,
|
|
|
|
FWORD defaultVertOriginY)
|
2018-10-23 10:58:59 +02:00
|
|
|
{
|
2019-06-12 20:02:48 +02:00
|
|
|
|
|
|
|
if (unlikely (!c->extend_min ((*this)))) return;
|
|
|
|
|
|
|
|
this->version.major = 1;
|
|
|
|
this->version.minor = 0;
|
|
|
|
|
|
|
|
this->defaultVertOriginY = defaultVertOriginY;
|
|
|
|
this->vertYOrigins.len = it.len ();
|
|
|
|
|
2019-09-23 22:18:08 +02:00
|
|
|
c->copy_all (it);
|
2018-10-23 10:58:59 +02:00
|
|
|
}
|
|
|
|
|
2019-06-12 20:02:48 +02:00
|
|
|
bool subset (hb_subset_context_t *c) const
|
2018-10-23 10:58:59 +02:00
|
|
|
{
|
2019-06-12 20:02:48 +02:00
|
|
|
TRACE_SUBSET (this);
|
|
|
|
VORG *vorg_prime = c->serializer->start_embed<VORG> ();
|
|
|
|
if (unlikely (!c->serializer->check_success (vorg_prime))) return_trace (false);
|
|
|
|
|
|
|
|
auto it =
|
|
|
|
+ vertYOrigins.as_array ()
|
|
|
|
| hb_filter (c->plan->glyphset (), &VertOriginMetric::glyph)
|
|
|
|
| hb_map ([&] (const VertOriginMetric& _)
|
2019-08-24 15:27:14 +02:00
|
|
|
{
|
|
|
|
hb_codepoint_t new_glyph = HB_SET_VALUE_INVALID;
|
|
|
|
c->plan->new_gid_for_old_gid (_.glyph, &new_glyph);
|
|
|
|
|
|
|
|
VertOriginMetric metric;
|
|
|
|
metric.glyph = new_glyph;
|
|
|
|
metric.vertOriginY = _.vertOriginY;
|
|
|
|
return metric;
|
|
|
|
})
|
2019-06-12 20:02:48 +02:00
|
|
|
;
|
2018-10-23 10:58:59 +02:00
|
|
|
|
|
|
|
/* serialize the new table */
|
2019-06-12 20:02:48 +02:00
|
|
|
vorg_prime->serialize (c->serializer, it, defaultVertOriginY);
|
|
|
|
return_trace (true);
|
2018-10-23 10:58:59 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-23 10:58:59 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
return_trace (c->check_struct (this) &&
|
2019-08-24 15:27:14 +02:00
|
|
|
version.major == 1 &&
|
|
|
|
vertYOrigins.sanitize (c));
|
2018-10-23 10:58:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-04-24 21:15:17 +02:00
|
|
|
FixedVersion<>version; /* Version of VORG table. Set to 0x00010000u. */
|
|
|
|
FWORD defaultVertOriginY;
|
|
|
|
/* The default vertical origin. */
|
2021-04-01 00:09:39 +02:00
|
|
|
SortedArray16Of<VertOriginMetric>
|
2020-04-24 21:15:17 +02:00
|
|
|
vertYOrigins; /* The array of vertical origins. */
|
2018-10-23 10:58:59 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
DEFINE_SIZE_ARRAY(8, vertYOrigins);
|
|
|
|
};
|
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
#endif /* HB_OT_VORG_TABLE_HH */
|