2018-03-10 08:37:56 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Ebrahim Byagowi
|
2020-01-24 21:09:44 +01:00
|
|
|
|
* Copyright © 2020 Google, Inc.
|
2018-03-10 08:37:56 +01: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.
|
2020-01-24 21:09:44 +01:00
|
|
|
|
*
|
|
|
|
|
* Google Author(s): Calder Kitagawa
|
2018-03-10 08:37:56 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef HB_OT_COLOR_SBIX_TABLE_HH
|
|
|
|
|
#define HB_OT_COLOR_SBIX_TABLE_HH
|
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
|
#include "hb-open-type.hh"
|
2020-01-09 16:44:20 +01:00
|
|
|
|
#include "hb-ot-layout-common.hh"
|
2018-03-10 08:37:56 +01:00
|
|
|
|
|
2018-04-12 11:08:19 +02:00
|
|
|
|
/*
|
|
|
|
|
* sbix -- Standard Bitmap Graphics
|
|
|
|
|
* https://docs.microsoft.com/en-us/typography/opentype/spec/sbix
|
|
|
|
|
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6sbix.html
|
|
|
|
|
*/
|
2018-03-27 14:27:09 +02:00
|
|
|
|
#define HB_OT_TAG_sbix HB_TAG('s','b','i','x')
|
2018-03-10 08:37:56 +01:00
|
|
|
|
|
2018-04-12 11:08:19 +02:00
|
|
|
|
|
2018-03-10 08:37:56 +01:00
|
|
|
|
namespace OT {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct SBIXGlyph
|
|
|
|
|
{
|
2020-01-24 18:16:08 +01:00
|
|
|
|
SBIXGlyph* copy (hb_serialize_context_t *c, unsigned int data_length) const
|
|
|
|
|
{
|
2020-01-09 16:44:20 +01:00
|
|
|
|
TRACE_SERIALIZE (this);
|
2020-01-14 17:01:09 +01:00
|
|
|
|
SBIXGlyph* new_glyph = c->start_embed<SBIXGlyph> ();
|
|
|
|
|
if (unlikely (!new_glyph)) return_trace (nullptr);
|
2020-01-14 20:56:02 +01:00
|
|
|
|
if (unlikely (!c->extend_min (new_glyph))) return_trace (nullptr);
|
2020-01-14 17:01:09 +01:00
|
|
|
|
|
|
|
|
|
new_glyph->xOffset = xOffset;
|
|
|
|
|
new_glyph->yOffset = yOffset;
|
|
|
|
|
new_glyph->graphicType = graphicType;
|
2020-01-24 21:09:44 +01:00
|
|
|
|
data.copy (c, data_length);
|
2020-01-14 17:01:09 +01:00
|
|
|
|
return_trace (new_glyph);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-11 20:38:40 +01:00
|
|
|
|
HBINT16 xOffset; /* The horizontal (x-axis) offset from the left
|
|
|
|
|
* edge of the graphic to the glyph’s origin.
|
|
|
|
|
* That is, the x-coordinate of the point on the
|
|
|
|
|
* baseline at the left edge of the glyph. */
|
|
|
|
|
HBINT16 yOffset; /* The vertical (y-axis) offset from the bottom
|
|
|
|
|
* edge of the graphic to the glyph’s origin.
|
|
|
|
|
* That is, the y-coordinate of the point on the
|
|
|
|
|
* baseline at the left edge of the glyph. */
|
|
|
|
|
Tag graphicType; /* Indicates the format of the embedded graphic
|
|
|
|
|
* data: one of 'jpg ', 'png ' or 'tiff', or the
|
|
|
|
|
* special format 'dupe'. */
|
2018-04-11 14:43:20 +02:00
|
|
|
|
UnsizedArrayOf<HBUINT8>
|
|
|
|
|
data; /* The actual embedded graphic data. The total
|
2018-03-11 20:38:40 +01:00
|
|
|
|
* length is inferred from sequential entries in
|
|
|
|
|
* the glyphDataOffsets array and the fixed size
|
|
|
|
|
* (8 bytes) of the preceding fields. */
|
2018-03-10 08:37:56 +01:00
|
|
|
|
public:
|
2018-03-11 20:38:40 +01:00
|
|
|
|
DEFINE_SIZE_ARRAY (8, data);
|
2018-03-10 08:37:56 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-03-11 20:38:40 +01:00
|
|
|
|
struct SBIXStrike
|
2018-03-10 08:37:56 +01:00
|
|
|
|
{
|
2020-01-09 16:44:20 +01:00
|
|
|
|
static unsigned int get_size (unsigned num_glyphs)
|
|
|
|
|
{ return min_size + num_glyphs * HBUINT32::static_size; }
|
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-03-10 08:37:56 +01:00
|
|
|
|
{
|
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
|
return_trace (c->check_struct (this) &&
|
2018-07-17 18:45:25 +02:00
|
|
|
|
imageOffsetsZ.sanitize_shallow (c, c->get_num_glyphs () + 1));
|
2018-03-10 08:37:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
hb_blob_t *get_glyph_blob (unsigned int glyph_id,
|
|
|
|
|
hb_blob_t *sbix_blob,
|
|
|
|
|
hb_tag_t file_type,
|
|
|
|
|
int *x_offset,
|
|
|
|
|
int *y_offset,
|
|
|
|
|
unsigned int num_glyphs,
|
|
|
|
|
unsigned int *strike_ppem) const
|
2018-10-26 22:25:11 +02:00
|
|
|
|
{
|
2018-10-28 23:53:11 +01:00
|
|
|
|
if (unlikely (!ppem)) return hb_blob_get_empty (); /* To get Null() object out of the way. */
|
|
|
|
|
|
2018-10-28 23:30:57 +01:00
|
|
|
|
unsigned int retry_count = 8;
|
2018-10-28 23:12:05 +01:00
|
|
|
|
unsigned int sbix_len = sbix_blob->length;
|
2018-10-28 23:11:10 +01:00
|
|
|
|
unsigned int strike_offset = (const char *) this - (const char *) sbix_blob->data;
|
2018-10-28 23:38:42 +01:00
|
|
|
|
assert (strike_offset < sbix_len);
|
2018-10-28 23:30:57 +01:00
|
|
|
|
|
|
|
|
|
retry:
|
2018-10-28 23:33:12 +01:00
|
|
|
|
if (unlikely (glyph_id >= num_glyphs ||
|
2018-10-28 23:53:11 +01:00
|
|
|
|
imageOffsetsZ[glyph_id + 1] <= imageOffsetsZ[glyph_id] ||
|
2018-10-28 23:38:42 +01:00
|
|
|
|
imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] <= SBIXGlyph::min_size ||
|
|
|
|
|
(unsigned int) imageOffsetsZ[glyph_id + 1] > sbix_len - strike_offset))
|
2018-10-26 22:25:11 +02:00
|
|
|
|
return hb_blob_get_empty ();
|
|
|
|
|
|
2018-10-28 23:36:17 +01:00
|
|
|
|
unsigned int glyph_offset = strike_offset + (unsigned int) imageOffsetsZ[glyph_id] + SBIXGlyph::min_size;
|
2018-10-28 23:43:54 +01:00
|
|
|
|
unsigned int glyph_length = imageOffsetsZ[glyph_id + 1] - imageOffsetsZ[glyph_id] - SBIXGlyph::min_size;
|
2018-10-27 09:20:53 +02:00
|
|
|
|
|
2018-10-26 22:25:11 +02:00
|
|
|
|
const SBIXGlyph *glyph = &(this+imageOffsetsZ[glyph_id]);
|
2018-10-28 23:30:57 +01:00
|
|
|
|
|
|
|
|
|
if (glyph->graphicType == HB_TAG ('d','u','p','e'))
|
2018-10-26 22:25:11 +02:00
|
|
|
|
{
|
2018-10-28 23:43:54 +01:00
|
|
|
|
if (glyph_length >= 2)
|
2018-10-26 22:25:11 +02:00
|
|
|
|
{
|
2018-10-28 23:30:57 +01:00
|
|
|
|
glyph_id = *((HBUINT16 *) &glyph->data);
|
2018-10-28 23:33:12 +01:00
|
|
|
|
if (retry_count--)
|
2018-10-28 23:30:57 +01:00
|
|
|
|
goto retry;
|
2018-10-26 22:25:11 +02:00
|
|
|
|
}
|
2018-10-28 23:30:57 +01:00
|
|
|
|
return hb_blob_get_empty ();
|
2018-10-26 22:25:11 +02:00
|
|
|
|
}
|
2018-10-28 23:30:57 +01:00
|
|
|
|
|
2018-10-28 19:08:56 +01:00
|
|
|
|
if (unlikely (file_type != glyph->graphicType))
|
2018-10-26 22:25:11 +02:00
|
|
|
|
return hb_blob_get_empty ();
|
2018-10-28 20:49:04 +01:00
|
|
|
|
|
2018-10-29 06:11:13 +01:00
|
|
|
|
if (strike_ppem) *strike_ppem = ppem;
|
2018-10-28 20:49:04 +01:00
|
|
|
|
if (x_offset) *x_offset = glyph->xOffset;
|
|
|
|
|
if (y_offset) *y_offset = glyph->yOffset;
|
2018-10-28 23:43:54 +01:00
|
|
|
|
return hb_blob_create_sub_blob (sbix_blob, glyph_offset, glyph_length);
|
2018-10-26 22:25:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 15:07:32 +01:00
|
|
|
|
bool subset (hb_subset_context_t *c, unsigned int available_len) const
|
2020-01-09 16:44:20 +01:00
|
|
|
|
{
|
|
|
|
|
TRACE_SUBSET (this);
|
|
|
|
|
unsigned int num_output_glyphs = c->plan->num_output_glyphs ();
|
|
|
|
|
|
|
|
|
|
auto* out = c->serializer->start_embed<SBIXStrike> ();
|
|
|
|
|
if (unlikely (!out)) return_trace (false);
|
2020-01-14 17:01:09 +01:00
|
|
|
|
auto snap = c->serializer->snapshot ();
|
2020-01-09 16:44:20 +01:00
|
|
|
|
if (unlikely (!c->serializer->extend (*out, num_output_glyphs + 1))) return_trace (false);
|
|
|
|
|
out->ppem = ppem;
|
|
|
|
|
out->resolution = resolution;
|
|
|
|
|
HBUINT32 head;
|
2020-01-24 21:09:44 +01:00
|
|
|
|
head = get_size (num_output_glyphs + 1);
|
2020-01-14 17:01:09 +01:00
|
|
|
|
|
|
|
|
|
bool has_glyphs = false;
|
2020-01-09 16:44:20 +01:00
|
|
|
|
for (unsigned new_gid = 0; new_gid < num_output_glyphs; new_gid++)
|
|
|
|
|
{
|
|
|
|
|
hb_codepoint_t old_gid;
|
|
|
|
|
if (!c->plan->old_gid_for_new_gid (new_gid, &old_gid) ||
|
2020-01-24 21:09:44 +01:00
|
|
|
|
unlikely (imageOffsetsZ[old_gid].is_null () ||
|
|
|
|
|
imageOffsetsZ[old_gid + 1].is_null () ||
|
|
|
|
|
imageOffsetsZ[old_gid + 1] <= imageOffsetsZ[old_gid] ||
|
|
|
|
|
imageOffsetsZ[old_gid + 1] - imageOffsetsZ[old_gid] <= SBIXGlyph::min_size) ||
|
|
|
|
|
(unsigned int) imageOffsetsZ[old_gid + 1] > available_len)
|
2020-01-21 21:19:33 +01:00
|
|
|
|
{
|
2020-01-24 21:09:44 +01:00
|
|
|
|
out->imageOffsetsZ[new_gid] = head;
|
|
|
|
|
continue;
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
2020-01-14 17:01:09 +01:00
|
|
|
|
has_glyphs = true;
|
2020-01-09 16:44:20 +01:00
|
|
|
|
unsigned int delta = imageOffsetsZ[old_gid + 1] - imageOffsetsZ[old_gid];
|
|
|
|
|
unsigned int glyph_data_length = delta - SBIXGlyph::min_size;
|
2020-01-24 18:16:08 +01:00
|
|
|
|
if (!(this+imageOffsetsZ[old_gid]).copy (c->serializer, glyph_data_length))
|
2020-01-24 21:09:44 +01:00
|
|
|
|
return_trace (false);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
out->imageOffsetsZ[new_gid] = head;
|
|
|
|
|
head += delta;
|
|
|
|
|
}
|
2020-01-14 17:01:09 +01:00
|
|
|
|
if (has_glyphs)
|
|
|
|
|
out->imageOffsetsZ[num_output_glyphs] = head;
|
|
|
|
|
else
|
|
|
|
|
c->serializer->revert (snap);
|
|
|
|
|
return_trace (has_glyphs);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 23:44:40 +01:00
|
|
|
|
public:
|
2018-04-11 14:43:20 +02:00
|
|
|
|
HBUINT16 ppem; /* The PPEM size for which this strike was designed. */
|
|
|
|
|
HBUINT16 resolution; /* The device pixel density (in PPI) for which this
|
|
|
|
|
* strike was designed. (E.g., 96 PPI, 192 PPI.) */
|
2018-10-28 23:44:40 +01:00
|
|
|
|
protected:
|
2019-04-30 22:05:10 +02:00
|
|
|
|
UnsizedArrayOf<LOffsetTo<SBIXGlyph>>
|
2018-04-11 14:43:20 +02:00
|
|
|
|
imageOffsetsZ; /* Offset from the beginning of the strike data header
|
|
|
|
|
* to bitmap data for an individual glyph ID. */
|
2018-03-10 08:37:56 +01:00
|
|
|
|
public:
|
2019-09-06 22:41:12 +02:00
|
|
|
|
DEFINE_SIZE_ARRAY (4, imageOffsetsZ);
|
2018-03-10 08:37:56 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sbix
|
|
|
|
|
{
|
2019-01-22 12:08:57 +01:00
|
|
|
|
static constexpr hb_tag_t tableTag = HB_OT_TAG_sbix;
|
2018-03-10 08:37:56 +01:00
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
|
bool has_data () const { return version; }
|
2018-03-10 08:37:56 +01:00
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
const SBIXStrike &get_strike (unsigned int i) const { return this+strikes[i]; }
|
2018-10-29 00:26:03 +01:00
|
|
|
|
|
2018-03-27 14:27:09 +02:00
|
|
|
|
struct accelerator_t
|
|
|
|
|
{
|
2018-12-16 20:08:10 +01:00
|
|
|
|
void init (hb_face_t *face)
|
2018-03-27 14:27:09 +02:00
|
|
|
|
{
|
2020-01-24 21:09:44 +01:00
|
|
|
|
table = hb_sanitize_context_t ().reference_table<sbix> (face);
|
2018-10-26 22:25:11 +02:00
|
|
|
|
num_glyphs = face->get_num_glyphs ();
|
2018-03-27 14:27:09 +02:00
|
|
|
|
}
|
2018-12-17 19:01:01 +01:00
|
|
|
|
void fini () { table.destroy (); }
|
2018-03-27 14:27:09 +02:00
|
|
|
|
|
2018-12-17 19:01:01 +01:00
|
|
|
|
bool has_data () const { return table->has_data (); }
|
2018-10-28 22:20:50 +01:00
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
bool get_extents (hb_font_t *font,
|
2018-12-17 19:01:01 +01:00
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
|
hb_glyph_extents_t *extents) const
|
2018-10-28 22:20:50 +01:00
|
|
|
|
{
|
|
|
|
|
/* We only support PNG right now, and following function checks type. */
|
2018-10-28 22:51:18 +01:00
|
|
|
|
return get_png_extents (font, glyph, extents);
|
2018-10-28 22:20:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
hb_blob_t *reference_png (hb_font_t *font,
|
|
|
|
|
hb_codepoint_t glyph_id,
|
|
|
|
|
int *x_offset,
|
|
|
|
|
int *y_offset,
|
|
|
|
|
unsigned int *available_ppem) const
|
2018-10-28 23:11:10 +01:00
|
|
|
|
{
|
2018-11-11 06:26:55 +01:00
|
|
|
|
return choose_strike (font).get_glyph_blob (glyph_id, table.get_blob (),
|
2018-10-29 07:04:37 +01:00
|
|
|
|
HB_TAG ('p','n','g',' '),
|
|
|
|
|
x_offset, y_offset,
|
|
|
|
|
num_glyphs, available_ppem);
|
2018-10-28 23:11:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
const SBIXStrike &choose_strike (hb_font_t *font) const
|
2018-10-26 22:25:11 +02:00
|
|
|
|
{
|
2018-10-29 07:14:15 +01:00
|
|
|
|
unsigned count = table->strikes.len;
|
|
|
|
|
if (unlikely (!count))
|
2020-01-24 21:09:44 +01:00
|
|
|
|
return Null (SBIXStrike);
|
2018-10-26 22:25:11 +02:00
|
|
|
|
|
2019-05-08 05:54:31 +02:00
|
|
|
|
unsigned int requested_ppem = hb_max (font->x_ppem, font->y_ppem);
|
2018-10-28 22:51:18 +01:00
|
|
|
|
if (!requested_ppem)
|
2019-08-24 15:27:14 +02:00
|
|
|
|
requested_ppem = 1<<30; /* Choose largest strike. */
|
2018-10-28 22:51:18 +01:00
|
|
|
|
/* TODO Add DPI sensitivity as well? */
|
|
|
|
|
unsigned int best_i = 0;
|
2018-10-29 00:26:03 +01:00
|
|
|
|
unsigned int best_ppem = table->get_strike (0).ppem;
|
2018-10-28 22:51:18 +01:00
|
|
|
|
|
2018-10-29 07:14:15 +01:00
|
|
|
|
for (unsigned int i = 1; i < count; i++)
|
2018-10-28 22:51:18 +01:00
|
|
|
|
{
|
2018-10-29 00:26:03 +01:00
|
|
|
|
unsigned int ppem = (table->get_strike (i)).ppem;
|
2018-10-28 22:51:18 +01:00
|
|
|
|
if ((requested_ppem <= ppem && ppem < best_ppem) ||
|
|
|
|
|
(requested_ppem > best_ppem && ppem > best_ppem))
|
|
|
|
|
{
|
|
|
|
|
best_i = i;
|
|
|
|
|
best_ppem = ppem;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-26 22:25:11 +02:00
|
|
|
|
|
2018-10-29 00:26:03 +01:00
|
|
|
|
return table->get_strike (best_i);
|
2018-10-28 20:49:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-28 21:13:50 +01:00
|
|
|
|
struct PNGHeader
|
|
|
|
|
{
|
2018-10-28 21:58:44 +01:00
|
|
|
|
HBUINT8 signature[8];
|
2018-10-28 22:16:52 +01:00
|
|
|
|
struct
|
|
|
|
|
{
|
2019-08-24 15:27:14 +02:00
|
|
|
|
struct
|
2018-10-28 22:16:52 +01:00
|
|
|
|
{
|
|
|
|
|
HBUINT32 length;
|
|
|
|
|
Tag type;
|
|
|
|
|
} header;
|
|
|
|
|
HBUINT32 width;
|
|
|
|
|
HBUINT32 height;
|
|
|
|
|
HBUINT8 bitDepth;
|
|
|
|
|
HBUINT8 colorType;
|
|
|
|
|
HBUINT8 compressionMethod;
|
|
|
|
|
HBUINT8 filterMethod;
|
|
|
|
|
HBUINT8 interlaceMethod;
|
|
|
|
|
} IHDR;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DEFINE_SIZE_STATIC (29);
|
2018-10-28 21:13:50 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
bool get_png_extents (hb_font_t *font,
|
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
|
hb_glyph_extents_t *extents) const
|
2018-10-28 20:49:04 +01:00
|
|
|
|
{
|
2018-11-03 21:15:30 +01:00
|
|
|
|
/* Following code is safe to call even without data.
|
|
|
|
|
* But faster to short-circuit. */
|
2018-10-28 23:58:48 +01:00
|
|
|
|
if (!has_data ())
|
2019-08-24 15:27:14 +02:00
|
|
|
|
return false;
|
2018-10-28 23:58:48 +01:00
|
|
|
|
|
2018-10-28 22:52:25 +01:00
|
|
|
|
int x_offset = 0, y_offset = 0;
|
2018-10-29 06:11:13 +01:00
|
|
|
|
unsigned int strike_ppem = 0;
|
|
|
|
|
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset, &strike_ppem);
|
2018-10-28 21:37:26 +01:00
|
|
|
|
|
2018-10-28 22:52:25 +01:00
|
|
|
|
const PNGHeader &png = *blob->as<PNGHeader>();
|
|
|
|
|
|
2018-10-28 20:49:04 +01:00
|
|
|
|
extents->x_bearing = x_offset;
|
2019-07-22 03:57:24 +02:00
|
|
|
|
extents->y_bearing = png.IHDR.height + y_offset;
|
2018-10-28 22:16:52 +01:00
|
|
|
|
extents->width = png.IHDR.width;
|
2020-02-11 17:20:51 +01:00
|
|
|
|
extents->height = -1 * png.IHDR.height;
|
2018-10-29 06:11:13 +01:00
|
|
|
|
|
2018-10-29 06:45:53 +01:00
|
|
|
|
/* Convert to font units. */
|
2018-10-29 06:11:13 +01:00
|
|
|
|
if (strike_ppem)
|
|
|
|
|
{
|
2019-05-08 08:26:09 +02:00
|
|
|
|
float scale = font->face->get_upem () / (float) strike_ppem;
|
2019-10-06 16:39:14 +02:00
|
|
|
|
extents->x_bearing = font->em_scalef_x (extents->x_bearing * scale);
|
|
|
|
|
extents->y_bearing = font->em_scalef_y (extents->y_bearing * scale);
|
|
|
|
|
extents->width = font->em_scalef_x (extents->width * scale);
|
|
|
|
|
extents->height = font->em_scalef_y (extents->height * scale);
|
2018-10-29 06:11:13 +01:00
|
|
|
|
}
|
2019-10-08 21:57:37 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
extents->x_bearing = font->em_scale_x (extents->x_bearing);
|
|
|
|
|
extents->y_bearing = font->em_scale_y (extents->y_bearing);
|
|
|
|
|
extents->width = font->em_scale_x (extents->width);
|
|
|
|
|
extents->height = font->em_scale_y (extents->height);
|
|
|
|
|
}
|
2018-10-29 06:11:13 +01:00
|
|
|
|
|
2018-10-28 20:49:04 +01:00
|
|
|
|
hb_blob_destroy (blob);
|
|
|
|
|
|
2018-11-03 21:15:30 +01:00
|
|
|
|
return strike_ppem;
|
2018-10-26 22:25:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 14:27:09 +02:00
|
|
|
|
private:
|
2018-11-11 06:26:55 +01:00
|
|
|
|
hb_blob_ptr_t<sbix> table;
|
2018-03-27 14:27:09 +02:00
|
|
|
|
|
|
|
|
|
unsigned int num_glyphs;
|
|
|
|
|
};
|
2018-03-10 08:37:56 +01:00
|
|
|
|
|
2018-12-16 20:08:10 +01:00
|
|
|
|
bool sanitize (hb_sanitize_context_t *c) const
|
2018-10-28 23:58:48 +01:00
|
|
|
|
{
|
|
|
|
|
TRACE_SANITIZE (this);
|
|
|
|
|
return_trace (likely (c->check_struct (this) &&
|
|
|
|
|
version >= 1 &&
|
|
|
|
|
strikes.sanitize (c, this)));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 19:54:25 +01:00
|
|
|
|
bool
|
2020-03-07 20:02:36 +01:00
|
|
|
|
add_strike (hb_subset_context_t *c, unsigned i) const
|
2020-02-28 19:54:25 +01:00
|
|
|
|
{
|
|
|
|
|
if (strikes[i].is_null () || c->source_blob->length < (unsigned) strikes[i])
|
2020-01-09 16:44:20 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
2020-02-28 19:54:25 +01:00
|
|
|
|
return (this+strikes[i]).subset (c, c->source_blob->length - (unsigned) strikes[i]);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-07 20:02:36 +01:00
|
|
|
|
bool serialize_strike_offsets (hb_subset_context_t *c) const
|
2020-01-09 16:44:20 +01:00
|
|
|
|
{
|
|
|
|
|
TRACE_SERIALIZE (this);
|
|
|
|
|
|
|
|
|
|
auto *out = c->serializer->start_embed<LOffsetLArrayOf<SBIXStrike>> ();
|
|
|
|
|
if (unlikely (!out)) return_trace (false);
|
2020-01-24 21:09:44 +01:00
|
|
|
|
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
|
|
|
|
|
hb_vector_t<LOffsetTo<SBIXStrike>*> new_strikes;
|
|
|
|
|
hb_vector_t<hb_serialize_context_t::objidx_t> objidxs;
|
|
|
|
|
for (int i = strikes.len - 1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
auto* o = out->serialize_append (c->serializer);
|
|
|
|
|
if (unlikely (!o)) return_trace (false);
|
2020-01-22 15:07:32 +01:00
|
|
|
|
*o = 0;
|
2020-01-09 16:44:20 +01:00
|
|
|
|
auto snap = c->serializer->snapshot ();
|
2020-01-23 17:36:47 +01:00
|
|
|
|
c->serializer->push ();
|
2020-03-07 20:02:36 +01:00
|
|
|
|
bool ret = add_strike (c, i);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
if (!ret)
|
|
|
|
|
{
|
2020-01-24 21:09:44 +01:00
|
|
|
|
c->serializer->pop_discard ();
|
|
|
|
|
out->pop ();
|
|
|
|
|
c->serializer->revert (snap);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-24 21:09:44 +01:00
|
|
|
|
objidxs.push (c->serializer->pop_pack ());
|
|
|
|
|
new_strikes.push (o);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (unsigned int i = 0; i < new_strikes.length; ++i)
|
2020-03-07 20:02:36 +01:00
|
|
|
|
c->serializer->add_link (*new_strikes[i], objidxs[new_strikes.length - 1 - i]);
|
2020-01-09 16:44:20 +01:00
|
|
|
|
|
|
|
|
|
return_trace (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool subset (hb_subset_context_t* c) const
|
|
|
|
|
{
|
|
|
|
|
TRACE_SUBSET (this);
|
|
|
|
|
|
|
|
|
|
sbix *sbix_prime = c->serializer->start_embed<sbix> ();
|
|
|
|
|
if (unlikely (!sbix_prime)) return_trace (false);
|
|
|
|
|
if (unlikely (!c->serializer->embed (this->version))) return_trace (false);
|
|
|
|
|
if (unlikely (!c->serializer->embed (this->flags))) return_trace (false);
|
|
|
|
|
|
2020-03-07 20:02:36 +01:00
|
|
|
|
return_trace (serialize_strike_offsets (c));
|
2020-01-09 16:44:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-10 08:37:56 +01:00
|
|
|
|
protected:
|
2018-03-11 20:38:40 +01:00
|
|
|
|
HBUINT16 version; /* Table version number — set to 1 */
|
|
|
|
|
HBUINT16 flags; /* Bit 0: Set to 1. Bit 1: Draw outlines.
|
|
|
|
|
* Bits 2 to 15: reserved (set to 0). */
|
2018-10-29 00:27:18 +01:00
|
|
|
|
LOffsetLArrayOf<SBIXStrike>
|
2018-03-11 20:38:40 +01:00
|
|
|
|
strikes; /* Offsets from the beginning of the 'sbix'
|
|
|
|
|
* table to data for each individual bitmap strike. */
|
2018-03-10 08:37:56 +01:00
|
|
|
|
public:
|
2018-03-11 20:38:40 +01:00
|
|
|
|
DEFINE_SIZE_ARRAY (8, strikes);
|
2018-03-10 08:37:56 +01:00
|
|
|
|
};
|
|
|
|
|
|
2018-10-23 16:30:48 +02:00
|
|
|
|
struct sbix_accelerator_t : sbix::accelerator_t {};
|
|
|
|
|
|
2018-03-10 08:37:56 +01:00
|
|
|
|
} /* namespace OT */
|
|
|
|
|
|
|
|
|
|
#endif /* HB_OT_COLOR_SBIX_TABLE_HH */
|