2016-04-30 19:20:56 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2016 Google, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_OT_POST_TABLE_HH
|
|
|
|
#define HB_OT_POST_TABLE_HH
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-open-type.hh"
|
2023-01-11 22:25:37 +01:00
|
|
|
#include "hb-ot-var-mvar-table.hh"
|
2016-04-30 19:20:56 +02:00
|
|
|
|
2017-10-27 04:34:04 +02:00
|
|
|
#define HB_STRING_ARRAY_NAME format1_names
|
|
|
|
#define HB_STRING_ARRAY_LIST "hb-ot-post-macroman.hh"
|
|
|
|
#include "hb-string-array.hh"
|
|
|
|
#undef HB_STRING_ARRAY_LIST
|
|
|
|
#undef HB_STRING_ARRAY_NAME
|
2017-10-16 10:05:42 +02:00
|
|
|
|
2016-04-30 19:20:56 +02:00
|
|
|
/*
|
|
|
|
* post -- PostScript
|
2018-04-12 11:08:19 +02:00
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/post
|
2016-04-30 19:20:56 +02:00
|
|
|
*/
|
|
|
|
#define HB_OT_TAG_post HB_TAG('p','o','s','t')
|
|
|
|
|
|
|
|
|
2018-04-12 11:08:19 +02:00
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
|
2016-04-30 19:20:56 +02:00
|
|
|
struct postV2Tail
|
|
|
|
{
|
2018-11-07 15:13:51 +01:00
|
|
|
friend struct post;
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2016-04-30 19:20:56 +02:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2017-10-29 00:58:56 +02:00
|
|
|
return_trace (glyphNameIndex.sanitize (c));
|
2016-04-30 19:20:56 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 05:05:35 +02:00
|
|
|
template<typename Iterator>
|
|
|
|
bool serialize (hb_serialize_context_t *c,
|
|
|
|
Iterator it,
|
|
|
|
const void* _post) const;
|
|
|
|
|
|
|
|
bool subset (hb_subset_context_t *c) const;
|
|
|
|
|
2018-11-07 15:13:51 +01:00
|
|
|
protected:
|
2021-04-01 00:04:43 +02:00
|
|
|
Array16Of<HBUINT16> glyphNameIndex; /* This is not an offset, but is the
|
2016-04-30 19:20:56 +02:00
|
|
|
* ordinal number of the glyph in 'post'
|
|
|
|
* string tables. */
|
2018-11-22 05:23:49 +01:00
|
|
|
/*UnsizedArrayOf<HBUINT8>
|
|
|
|
namesX;*/ /* Glyph names with length bytes [variable]
|
2016-04-30 19:20:56 +02:00
|
|
|
* (a Pascal string). */
|
|
|
|
|
2018-11-07 15:13:51 +01:00
|
|
|
public:
|
2018-11-22 05:23:49 +01:00
|
|
|
DEFINE_SIZE_ARRAY (2, glyphNameIndex);
|
2016-04-30 19:20:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct post
|
|
|
|
{
|
2019-01-22 12:08:57 +01:00
|
|
|
static constexpr hb_tag_t tableTag = HB_OT_TAG_post;
|
2016-04-30 19:20:56 +02:00
|
|
|
|
2021-07-21 05:05:35 +02:00
|
|
|
bool serialize (hb_serialize_context_t *c, bool glyph_names) const
|
2018-03-07 03:33:39 +01:00
|
|
|
{
|
2021-07-21 05:05:35 +02:00
|
|
|
TRACE_SERIALIZE (this);
|
2019-06-06 01:51:31 +02:00
|
|
|
post *post_prime = c->allocate_min<post> ();
|
2021-07-21 05:05:35 +02:00
|
|
|
if (unlikely (!post_prime)) return_trace (false);
|
2018-03-07 03:33:39 +01:00
|
|
|
|
2022-11-22 20:54:50 +01:00
|
|
|
hb_memcpy (post_prime, this, post::min_size);
|
2021-07-21 05:05:35 +02:00
|
|
|
if (!glyph_names)
|
|
|
|
return_trace (c->check_assign (post_prime->version.major, 3,
|
|
|
|
HB_SERIALIZE_ERROR_INT_OVERFLOW)); // Version 3 does not have any glyph names.
|
|
|
|
|
|
|
|
return_trace (true);
|
2019-06-06 01:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subset (hb_subset_context_t *c) const
|
|
|
|
{
|
|
|
|
TRACE_SUBSET (this);
|
|
|
|
post *post_prime = c->serializer->start_embed<post> ();
|
|
|
|
if (unlikely (!post_prime)) return_trace (false);
|
|
|
|
|
2023-02-24 19:17:32 +01:00
|
|
|
bool glyph_names = c->plan->flags & HB_SUBSET_FLAGS_GLYPH_NAMES;
|
|
|
|
if (!serialize (c->serializer, glyph_names))
|
|
|
|
return_trace (false);
|
|
|
|
|
2023-01-11 22:25:37 +01:00
|
|
|
#ifndef HB_NO_VAR
|
|
|
|
if (c->plan->normalized_coords)
|
|
|
|
{
|
|
|
|
auto &MVAR = *c->plan->source->table.MVAR;
|
|
|
|
auto *table = post_prime;
|
|
|
|
|
|
|
|
HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_UNDERLINE_SIZE, underlineThickness);
|
|
|
|
HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_UNDERLINE_OFFSET, underlinePosition);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-11 20:36:54 +01:00
|
|
|
if (c->plan->user_axes_location.has (HB_TAG ('s','l','n','t')) &&
|
2022-07-27 22:18:21 +02:00
|
|
|
!c->plan->pinned_at_default)
|
|
|
|
{
|
2023-01-11 20:36:54 +01:00
|
|
|
float italic_angle = c->plan->user_axes_location.get (HB_TAG ('s','l','n','t'));
|
2022-07-27 22:18:21 +02:00
|
|
|
italic_angle = hb_max (-90.f, hb_min (italic_angle, 90.f));
|
|
|
|
post_prime->italicAngle.set_float (italic_angle);
|
|
|
|
}
|
|
|
|
|
2021-07-30 00:07:13 +02:00
|
|
|
if (glyph_names && version.major == 2)
|
2021-07-21 05:05:35 +02:00
|
|
|
return_trace (v2X.subset (c));
|
2018-03-07 03:33:39 +01:00
|
|
|
|
2019-06-06 01:51:31 +02:00
|
|
|
return_trace (true);
|
2018-03-07 03:33:39 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 02:54:04 +01:00
|
|
|
struct accelerator_t
|
2017-10-16 10:05:42 +02:00
|
|
|
{
|
2021-07-21 05:05:35 +02:00
|
|
|
friend struct postV2Tail;
|
2022-01-20 19:47:17 +01:00
|
|
|
|
|
|
|
accelerator_t (hb_face_t *face)
|
2017-10-16 10:05:42 +02:00
|
|
|
{
|
2018-11-15 20:40:56 +01:00
|
|
|
table = hb_sanitize_context_t ().reference_table<post> (face);
|
2018-11-11 06:39:52 +01:00
|
|
|
unsigned int table_length = table.get_length ();
|
2017-11-15 04:31:50 +01:00
|
|
|
|
2017-10-29 02:54:04 +01:00
|
|
|
version = table->version.to_int ();
|
2018-11-15 20:40:56 +01:00
|
|
|
if (version != 0x00020000) return;
|
2017-10-16 10:05:42 +02:00
|
|
|
|
2018-11-30 06:38:08 +01:00
|
|
|
const postV2Tail &v2 = table->v2X;
|
2017-10-29 02:54:04 +01:00
|
|
|
|
|
|
|
glyphNameIndex = &v2.glyphNameIndex;
|
|
|
|
pool = &StructAfter<uint8_t> (v2.glyphNameIndex);
|
|
|
|
|
2018-11-11 06:39:52 +01:00
|
|
|
const uint8_t *end = (const uint8_t *) (const void *) table + table_length;
|
2022-12-30 21:58:34 +01:00
|
|
|
index_to_offset.alloc (hb_min (face->get_num_glyphs (), table_length / 8));
|
2018-11-07 15:14:42 +01:00
|
|
|
for (const uint8_t *data = pool;
|
2018-12-22 00:46:51 +01:00
|
|
|
index_to_offset.length < 65535 && data < end && data + *data < end;
|
2018-11-07 15:14:42 +01:00
|
|
|
data += 1 + *data)
|
2018-06-02 02:48:37 +02:00
|
|
|
index_to_offset.push (data - pool);
|
2017-10-29 02:54:04 +01:00
|
|
|
}
|
2022-01-20 19:47:17 +01:00
|
|
|
~accelerator_t ()
|
2017-10-29 02:54:04 +01:00
|
|
|
{
|
2022-08-03 20:43:28 +02:00
|
|
|
hb_free (gids_sorted_by_name.get_acquire ());
|
2018-11-11 17:40:57 +01:00
|
|
|
table.destroy ();
|
2017-10-16 10:05:42 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph_name (hb_codepoint_t glyph,
|
|
|
|
char *buf, unsigned int buf_len) const
|
2017-10-30 20:15:05 +01:00
|
|
|
{
|
2018-05-08 10:57:27 +02:00
|
|
|
hb_bytes_t s = find_glyph_name (glyph);
|
2018-12-22 00:46:51 +01:00
|
|
|
if (!s.length) return false;
|
2018-11-15 20:40:56 +01:00
|
|
|
if (!buf_len) return true;
|
2019-05-08 05:54:31 +02:00
|
|
|
unsigned int len = hb_min (buf_len - 1, s.length);
|
2018-11-07 15:16:53 +01:00
|
|
|
strncpy (buf, s.arrayZ, len);
|
|
|
|
buf[len] = '\0';
|
2017-10-30 20:15:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool get_glyph_from_name (const char *name, int len,
|
|
|
|
hb_codepoint_t *glyph) const
|
2017-10-30 20:15:05 +01:00
|
|
|
{
|
|
|
|
unsigned int count = get_glyph_count ();
|
2018-11-15 20:40:56 +01:00
|
|
|
if (unlikely (!count)) return false;
|
2017-10-30 20:15:05 +01:00
|
|
|
|
2018-11-15 20:40:56 +01:00
|
|
|
if (len < 0) len = strlen (name);
|
2017-10-30 20:15:05 +01:00
|
|
|
|
2018-11-15 20:40:56 +01:00
|
|
|
if (unlikely (!len)) return false;
|
2017-10-30 20:15:05 +01:00
|
|
|
|
|
|
|
retry:
|
2022-08-03 20:43:28 +02:00
|
|
|
uint16_t *gids = gids_sorted_by_name.get_acquire ();
|
2017-10-30 20:15:05 +01:00
|
|
|
|
|
|
|
if (unlikely (!gids))
|
|
|
|
{
|
2021-07-08 18:58:50 +02:00
|
|
|
gids = (uint16_t *) hb_malloc (count * sizeof (gids[0]));
|
2017-10-30 20:15:05 +01:00
|
|
|
if (unlikely (!gids))
|
|
|
|
return false; /* Anything better?! */
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
gids[i] = i;
|
2019-06-07 10:28:09 +02:00
|
|
|
hb_qsort (gids, count, sizeof (gids[0]), cmp_gids, (void *) this);
|
2017-10-30 20:15:05 +01:00
|
|
|
|
2018-08-09 09:22:37 +02:00
|
|
|
if (unlikely (!gids_sorted_by_name.cmpexch (nullptr, gids)))
|
|
|
|
{
|
2021-07-08 18:58:50 +02:00
|
|
|
hb_free (gids);
|
2017-10-30 20:15:05 +01:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 10:57:27 +02:00
|
|
|
hb_bytes_t st (name, len);
|
2019-12-06 05:28:06 +01:00
|
|
|
auto* gid = hb_bsearch (st, gids, count, sizeof (gids[0]), cmp_key, (void *) this);
|
2017-10-30 20:15:05 +01:00
|
|
|
if (gid)
|
|
|
|
{
|
|
|
|
*glyph = *gid;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-20 20:56:46 +01:00
|
|
|
hb_blob_ptr_t<post> table;
|
|
|
|
|
2017-10-30 20:15:05 +01:00
|
|
|
protected:
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
unsigned int get_glyph_count () const
|
2017-10-30 20:15:05 +01:00
|
|
|
{
|
|
|
|
if (version == 0x00010000)
|
2019-11-19 00:09:24 +01:00
|
|
|
return format1_names_length;
|
2017-10-30 20:15:05 +01:00
|
|
|
|
|
|
|
if (version == 0x00020000)
|
2018-11-15 20:40:56 +01:00
|
|
|
return glyphNameIndex->len;
|
2017-10-30 20:15:05 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static int cmp_gids (const void *pa, const void *pb, void *arg)
|
2017-10-30 20:15:05 +01:00
|
|
|
{
|
|
|
|
const accelerator_t *thiz = (const accelerator_t *) arg;
|
|
|
|
uint16_t a = * (const uint16_t *) pa;
|
|
|
|
uint16_t b = * (const uint16_t *) pb;
|
|
|
|
return thiz->find_glyph_name (b).cmp (thiz->find_glyph_name (a));
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
static int cmp_key (const void *pk, const void *po, void *arg)
|
2017-10-30 20:15:05 +01:00
|
|
|
{
|
|
|
|
const accelerator_t *thiz = (const accelerator_t *) arg;
|
2018-05-08 10:57:27 +02:00
|
|
|
const hb_bytes_t *key = (const hb_bytes_t *) pk;
|
2017-10-30 20:15:05 +01:00
|
|
|
uint16_t o = * (const uint16_t *) po;
|
|
|
|
return thiz->find_glyph_name (o).cmp (*key);
|
|
|
|
}
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
hb_bytes_t find_glyph_name (hb_codepoint_t glyph) const
|
2017-10-16 10:05:42 +02:00
|
|
|
{
|
2017-10-29 02:54:04 +01:00
|
|
|
if (version == 0x00010000)
|
|
|
|
{
|
2019-11-19 00:09:24 +01:00
|
|
|
if (glyph >= format1_names_length)
|
2018-05-08 10:57:27 +02:00
|
|
|
return hb_bytes_t ();
|
2017-10-16 10:05:42 +02:00
|
|
|
|
2017-10-30 19:21:44 +01:00
|
|
|
return format1_names (glyph);
|
2017-10-29 02:54:04 +01:00
|
|
|
}
|
|
|
|
|
2017-10-30 16:46:36 +01:00
|
|
|
if (version != 0x00020000 || glyph >= glyphNameIndex->len)
|
2018-05-08 10:57:27 +02:00
|
|
|
return hb_bytes_t ();
|
2017-10-26 01:40:50 +02:00
|
|
|
|
2018-05-09 01:56:11 +02:00
|
|
|
unsigned int index = glyphNameIndex->arrayZ[glyph];
|
2019-11-19 00:09:24 +01:00
|
|
|
if (index < format1_names_length)
|
2017-10-30 19:21:44 +01:00
|
|
|
return format1_names (index);
|
2019-11-19 00:09:24 +01:00
|
|
|
index -= format1_names_length;
|
2017-10-26 01:40:50 +02:00
|
|
|
|
2018-12-22 00:46:51 +01:00
|
|
|
if (index >= index_to_offset.length)
|
2018-05-08 10:57:27 +02:00
|
|
|
return hb_bytes_t ();
|
2018-10-05 18:39:48 +02:00
|
|
|
unsigned int offset = index_to_offset[index];
|
2017-10-16 10:05:42 +02:00
|
|
|
|
2017-10-29 02:54:04 +01:00
|
|
|
const uint8_t *data = pool + offset;
|
|
|
|
unsigned int name_length = *data;
|
|
|
|
data++;
|
2017-10-18 20:49:16 +02:00
|
|
|
|
2018-05-08 10:57:27 +02:00
|
|
|
return hb_bytes_t ((const char *) data, name_length);
|
2017-10-30 16:46:36 +01:00
|
|
|
}
|
|
|
|
|
2017-11-15 04:47:31 +01:00
|
|
|
private:
|
2017-10-29 02:54:04 +01:00
|
|
|
uint32_t version;
|
2022-01-21 15:30:09 +01:00
|
|
|
const Array16Of<HBUINT16> *glyphNameIndex = nullptr;
|
2018-12-27 23:56:22 +01:00
|
|
|
hb_vector_t<uint32_t> index_to_offset;
|
2022-01-21 15:30:09 +01:00
|
|
|
const uint8_t *pool = nullptr;
|
2018-08-09 09:22:37 +02:00
|
|
|
hb_atomic_ptr_t<uint16_t *> gids_sorted_by_name;
|
2017-10-29 02:54:04 +01:00
|
|
|
};
|
2017-10-18 20:49:16 +02:00
|
|
|
|
2018-11-20 20:56:46 +01:00
|
|
|
bool has_data () const { return version.to_int (); }
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-11-10 06:26:36 +01:00
|
|
|
{
|
|
|
|
TRACE_SANITIZE (this);
|
2022-07-11 22:01:52 +02:00
|
|
|
return_trace (c->check_struct (this) &&
|
|
|
|
(version.to_int () == 0x00010000 ||
|
|
|
|
(version.to_int () == 0x00020000 && v2X.sanitize (c)) ||
|
|
|
|
version.to_int () == 0x00030000));
|
2018-11-10 06:26:36 +01:00
|
|
|
}
|
|
|
|
|
2016-04-30 19:20:56 +02:00
|
|
|
public:
|
|
|
|
FixedVersion<>version; /* 0x00010000 for version 1.0
|
|
|
|
* 0x00020000 for version 2.0
|
|
|
|
* 0x00025000 for version 2.5 (deprecated)
|
|
|
|
* 0x00030000 for version 3.0 */
|
2022-10-13 20:04:32 +02:00
|
|
|
F16DOT16 italicAngle; /* Italic angle in counter-clockwise degrees
|
2016-04-30 19:20:56 +02:00
|
|
|
* from the vertical. Zero for upright text,
|
|
|
|
* negative for text that leans to the right
|
|
|
|
* (forward). */
|
|
|
|
FWORD underlinePosition; /* This is the suggested distance of the top
|
|
|
|
* of the underline from the baseline
|
|
|
|
* (negative values indicate below baseline).
|
|
|
|
* The PostScript definition of this FontInfo
|
|
|
|
* dictionary key (the y coordinate of the
|
|
|
|
* center of the stroke) is not used for
|
|
|
|
* historical reasons. The value of the
|
|
|
|
* PostScript key may be calculated by
|
|
|
|
* subtracting half the underlineThickness
|
|
|
|
* from the value of this field. */
|
|
|
|
FWORD underlineThickness; /* Suggested values for the underline
|
|
|
|
thickness. */
|
2018-01-17 21:46:08 +01:00
|
|
|
HBUINT32 isFixedPitch; /* Set to 0 if the font is proportionally
|
2016-04-30 19:20:56 +02:00
|
|
|
* spaced, non-zero if the font is not
|
|
|
|
* proportionally spaced (i.e. monospaced). */
|
2018-01-17 21:46:08 +01:00
|
|
|
HBUINT32 minMemType42; /* Minimum memory usage when an OpenType font
|
2016-04-30 19:20:56 +02:00
|
|
|
* is downloaded. */
|
2018-01-17 21:46:08 +01:00
|
|
|
HBUINT32 maxMemType42; /* Maximum memory usage when an OpenType font
|
2016-04-30 19:20:56 +02:00
|
|
|
* is downloaded. */
|
2018-01-17 21:46:08 +01:00
|
|
|
HBUINT32 minMemType1; /* Minimum memory usage when an OpenType font
|
2016-04-30 19:20:56 +02:00
|
|
|
* is downloaded as a Type 1 font. */
|
2018-01-17 21:46:08 +01:00
|
|
|
HBUINT32 maxMemType1; /* Maximum memory usage when an OpenType font
|
2016-04-30 19:20:56 +02:00
|
|
|
* is downloaded as a Type 1 font. */
|
2018-11-30 06:38:08 +01:00
|
|
|
postV2Tail v2X;
|
2018-11-10 06:37:17 +01:00
|
|
|
DEFINE_SIZE_MIN (32);
|
2016-04-30 19:20:56 +02:00
|
|
|
};
|
|
|
|
|
2022-01-20 19:47:17 +01:00
|
|
|
struct post_accelerator_t : post::accelerator_t {
|
|
|
|
post_accelerator_t (hb_face_t *face) : post::accelerator_t (face) {}
|
|
|
|
};
|
|
|
|
|
2018-08-27 00:11:24 +02:00
|
|
|
|
2016-04-30 19:20:56 +02:00
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* HB_OT_POST_TABLE_HH */
|