2014-03-24 22:26:36 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2011,2014 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, Roozbeh Pournader
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hb-private.hh"
|
|
|
|
|
|
|
|
#include "hb-ot.h"
|
|
|
|
|
|
|
|
#include "hb-font-private.hh"
|
|
|
|
|
2014-05-09 21:35:56 +02:00
|
|
|
#include "hb-ot-cmap-table.hh"
|
2015-08-23 15:42:20 +02:00
|
|
|
#include "hb-ot-glyf-table.hh"
|
|
|
|
#include "hb-ot-head-table.hh"
|
2014-03-24 22:26:36 +01:00
|
|
|
#include "hb-ot-hhea-table.hh"
|
|
|
|
#include "hb-ot-hmtx-table.hh"
|
2015-10-26 08:23:22 +01:00
|
|
|
#include "hb-ot-os2-table.hh"
|
2014-03-24 22:26:36 +01:00
|
|
|
|
|
|
|
|
2014-09-25 16:26:56 +02:00
|
|
|
struct hb_ot_face_metrics_accelerator_t
|
2014-09-25 15:53:24 +02:00
|
|
|
{
|
|
|
|
unsigned int num_metrics;
|
|
|
|
unsigned int num_advances;
|
2014-09-25 16:15:35 +02:00
|
|
|
unsigned int default_advance;
|
2015-10-26 08:23:22 +01:00
|
|
|
unsigned short ascender;
|
|
|
|
unsigned short descender;
|
|
|
|
unsigned short line_gap;
|
|
|
|
|
2014-09-25 15:53:24 +02:00
|
|
|
const OT::_mtx *table;
|
|
|
|
hb_blob_t *blob;
|
|
|
|
|
2014-09-25 16:26:56 +02:00
|
|
|
inline void init (hb_face_t *face,
|
2015-10-26 08:23:22 +01:00
|
|
|
hb_tag_t _hea_tag,
|
|
|
|
hb_tag_t _mtx_tag,
|
|
|
|
hb_tag_t os2_tag)
|
2014-09-25 15:53:24 +02:00
|
|
|
{
|
2015-11-03 00:37:29 +01:00
|
|
|
this->default_advance = face->get_upem ();
|
2014-09-25 15:53:24 +02:00
|
|
|
|
2015-10-26 08:23:22 +01:00
|
|
|
bool got_font_extents = false;
|
|
|
|
if (os2_tag)
|
|
|
|
{
|
|
|
|
hb_blob_t *os2_blob = OT::Sanitizer<OT::os2>::sanitize (face->reference_table (os2_tag));
|
|
|
|
const OT::os2 *os2 = OT::Sanitizer<OT::os2>::lock_instance (os2_blob);
|
2015-12-10 16:37:49 +01:00
|
|
|
#define USE_TYPO_METRICS (1u<<7)
|
|
|
|
if (0 != (os2->fsSelection & USE_TYPO_METRICS))
|
|
|
|
{
|
|
|
|
this->ascender = os2->sTypoAscender;
|
|
|
|
this->descender = os2->sTypoDescender;
|
|
|
|
this->line_gap = os2->sTypoLineGap;
|
|
|
|
got_font_extents = (this->ascender | this->descender) != 0;
|
|
|
|
}
|
2015-10-26 08:23:22 +01:00
|
|
|
hb_blob_destroy (os2_blob);
|
|
|
|
}
|
|
|
|
|
2014-09-25 16:26:56 +02:00
|
|
|
hb_blob_t *_hea_blob = OT::Sanitizer<OT::_hea>::sanitize (face->reference_table (_hea_tag));
|
2014-09-25 15:53:24 +02:00
|
|
|
const OT::_hea *_hea = OT::Sanitizer<OT::_hea>::lock_instance (_hea_blob);
|
|
|
|
this->num_advances = _hea->numberOfLongMetrics;
|
2015-10-26 08:23:22 +01:00
|
|
|
if (!got_font_extents)
|
|
|
|
{
|
|
|
|
this->ascender = _hea->ascender;
|
|
|
|
this->descender = _hea->descender;
|
|
|
|
this->line_gap = _hea->lineGap;
|
|
|
|
}
|
2014-09-25 15:53:24 +02:00
|
|
|
hb_blob_destroy (_hea_blob);
|
|
|
|
|
2014-09-25 16:26:56 +02:00
|
|
|
this->blob = OT::Sanitizer<OT::_mtx>::sanitize (face->reference_table (_mtx_tag));
|
2015-11-03 00:37:29 +01:00
|
|
|
|
|
|
|
/* Cap num_metrics() and num_advances() based on table length. */
|
|
|
|
unsigned int len = hb_blob_get_length (this->blob);
|
2015-11-03 21:15:12 +01:00
|
|
|
if (unlikely (this->num_advances * 4 > len))
|
2015-11-03 00:37:29 +01:00
|
|
|
this->num_advances = len / 4;
|
|
|
|
this->num_metrics = this->num_advances + (len - 4 * this->num_advances) / 2;
|
|
|
|
|
2015-11-03 21:15:12 +01:00
|
|
|
/* We MUST set num_metrics to zero if num_advances is zero.
|
2015-11-03 00:37:29 +01:00
|
|
|
* Our get_advance() depends on that. */
|
|
|
|
if (unlikely (!this->num_advances))
|
2014-09-25 15:53:24 +02:00
|
|
|
{
|
2014-09-25 16:15:35 +02:00
|
|
|
this->num_metrics = this->num_advances = 0;
|
2014-09-25 15:53:24 +02:00
|
|
|
hb_blob_destroy (this->blob);
|
|
|
|
this->blob = hb_blob_get_empty ();
|
|
|
|
}
|
|
|
|
this->table = OT::Sanitizer<OT::_mtx>::lock_instance (this->blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
|
|
|
hb_blob_destroy (this->blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned int get_advance (hb_codepoint_t glyph) const
|
|
|
|
{
|
|
|
|
if (unlikely (glyph >= this->num_metrics))
|
2014-09-25 16:15:35 +02:00
|
|
|
{
|
|
|
|
/* If this->num_metrics is zero, it means we don't have the metrics table
|
2015-08-23 15:42:20 +02:00
|
|
|
* for this direction: return default advance. Otherwise, it means that the
|
|
|
|
* glyph index is out of bound: return zero. */
|
2014-09-25 16:15:35 +02:00
|
|
|
if (this->num_metrics)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return this->default_advance;
|
|
|
|
}
|
2014-09-25 15:53:24 +02:00
|
|
|
|
|
|
|
if (glyph >= this->num_advances)
|
|
|
|
glyph = this->num_advances - 1;
|
|
|
|
|
|
|
|
return this->table->longMetric[glyph].advance;
|
|
|
|
}
|
|
|
|
};
|
2014-03-24 22:26:36 +01:00
|
|
|
|
2015-08-23 15:42:20 +02:00
|
|
|
struct hb_ot_face_glyf_accelerator_t
|
|
|
|
{
|
|
|
|
bool short_offset;
|
|
|
|
unsigned int num_glyphs;
|
|
|
|
const OT::loca *loca;
|
|
|
|
const OT::glyf *glyf;
|
|
|
|
hb_blob_t *loca_blob;
|
|
|
|
hb_blob_t *glyf_blob;
|
|
|
|
unsigned int glyf_len;
|
|
|
|
|
|
|
|
inline void init (hb_face_t *face)
|
|
|
|
{
|
|
|
|
hb_blob_t *head_blob = OT::Sanitizer<OT::head>::sanitize (face->reference_table (HB_OT_TAG_head));
|
|
|
|
const OT::head *head = OT::Sanitizer<OT::head>::lock_instance (head_blob);
|
|
|
|
if ((unsigned int) head->indexToLocFormat > 1 || head->glyphDataFormat != 0)
|
|
|
|
{
|
|
|
|
/* Unknown format. Leave num_glyphs=0, that takes care of disabling us. */
|
|
|
|
hb_blob_destroy (head_blob);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->short_offset = 0 == head->indexToLocFormat;
|
|
|
|
hb_blob_destroy (head_blob);
|
|
|
|
|
|
|
|
this->loca_blob = OT::Sanitizer<OT::loca>::sanitize (face->reference_table (HB_OT_TAG_loca));
|
|
|
|
this->loca = OT::Sanitizer<OT::loca>::lock_instance (this->loca_blob);
|
|
|
|
this->glyf_blob = OT::Sanitizer<OT::glyf>::sanitize (face->reference_table (HB_OT_TAG_glyf));
|
|
|
|
this->glyf = OT::Sanitizer<OT::glyf>::lock_instance (this->glyf_blob);
|
|
|
|
|
|
|
|
this->num_glyphs = MAX (1u, hb_blob_get_length (this->loca_blob) / (this->short_offset ? 2 : 4)) - 1;
|
|
|
|
this->glyf_len = hb_blob_get_length (this->glyf_blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
|
|
|
hb_blob_destroy (this->loca_blob);
|
|
|
|
hb_blob_destroy (this->glyf_blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool get_extents (hb_codepoint_t glyph,
|
|
|
|
hb_glyph_extents_t *extents) const
|
|
|
|
{
|
|
|
|
if (unlikely (glyph >= this->num_glyphs))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int start_offset, end_offset;
|
|
|
|
if (this->short_offset)
|
|
|
|
{
|
2015-08-24 14:45:12 +02:00
|
|
|
start_offset = 2 * this->loca->u.shortsZ[glyph];
|
|
|
|
end_offset = 2 * this->loca->u.shortsZ[glyph + 1];
|
2015-08-23 15:42:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start_offset = this->loca->u.longsZ[glyph];
|
|
|
|
end_offset = this->loca->u.longsZ[glyph + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_offset > end_offset || end_offset > this->glyf_len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (end_offset - start_offset < OT::glyfGlyphHeader::static_size)
|
|
|
|
return true; /* Empty glyph; zero extents. */
|
|
|
|
|
|
|
|
const OT::glyfGlyphHeader &glyph_header = OT::StructAtOffset<OT::glyfGlyphHeader> (this->glyf, start_offset);
|
|
|
|
|
|
|
|
extents->x_bearing = MIN (glyph_header.xMin, glyph_header.xMax);
|
|
|
|
extents->y_bearing = MAX (glyph_header.yMin, glyph_header.yMax);
|
|
|
|
extents->width = MAX (glyph_header.xMin, glyph_header.xMax) - extents->x_bearing;
|
|
|
|
extents->height = MIN (glyph_header.yMin, glyph_header.yMax) - extents->y_bearing;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-25 16:45:49 +02:00
|
|
|
struct hb_ot_face_cmap_accelerator_t
|
|
|
|
{
|
|
|
|
const OT::CmapSubtable *table;
|
2016-02-24 11:32:43 +01:00
|
|
|
const OT::CmapSubtableFormat14 *uvs_table;
|
2014-09-25 16:45:49 +02:00
|
|
|
hb_blob_t *blob;
|
|
|
|
|
|
|
|
inline void init (hb_face_t *face)
|
|
|
|
{
|
|
|
|
this->blob = OT::Sanitizer<OT::cmap>::sanitize (face->reference_table (HB_OT_TAG_cmap));
|
|
|
|
const OT::cmap *cmap = OT::Sanitizer<OT::cmap>::lock_instance (this->blob);
|
|
|
|
const OT::CmapSubtable *subtable = NULL;
|
2016-02-24 11:32:43 +01:00
|
|
|
const OT::CmapSubtableFormat14 *subtable_uvs = NULL;
|
2014-09-25 16:45:49 +02:00
|
|
|
|
|
|
|
/* 32-bit subtables. */
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (3, 10);
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (0, 6);
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (0, 4);
|
|
|
|
/* 16-bit subtables. */
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (3, 1);
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (0, 3);
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (0, 2);
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (0, 1);
|
|
|
|
if (!subtable) subtable = cmap->find_subtable (0, 0);
|
2015-04-17 22:08:08 +02:00
|
|
|
if (!subtable) subtable = cmap->find_subtable (3, 0);
|
2014-09-25 16:45:49 +02:00
|
|
|
/* Meh. */
|
|
|
|
if (!subtable) subtable = &OT::Null(OT::CmapSubtable);
|
|
|
|
|
|
|
|
/* UVS subtable. */
|
2016-02-24 11:32:43 +01:00
|
|
|
if (!subtable_uvs)
|
|
|
|
{
|
|
|
|
const OT::CmapSubtable *st = cmap->find_subtable (0, 5);
|
|
|
|
if (st && st->u.format == 14)
|
|
|
|
subtable_uvs = &st->u.format14;
|
|
|
|
}
|
2014-09-25 16:45:49 +02:00
|
|
|
/* Meh. */
|
2016-02-24 11:32:43 +01:00
|
|
|
if (!subtable_uvs) subtable_uvs = &OT::Null(OT::CmapSubtableFormat14);
|
2014-09-25 16:45:49 +02:00
|
|
|
|
|
|
|
this->table = subtable;
|
|
|
|
this->uvs_table = subtable_uvs;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void fini (void)
|
|
|
|
{
|
|
|
|
hb_blob_destroy (this->blob);
|
|
|
|
}
|
|
|
|
|
2016-02-24 11:05:23 +01:00
|
|
|
inline bool get_nominal_glyph (hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t *glyph) const
|
2014-09-25 16:45:49 +02:00
|
|
|
{
|
2016-02-24 11:05:23 +01:00
|
|
|
return this->table->get_glyph (unicode, glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool get_variation_glyph (hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t *glyph) const
|
|
|
|
{
|
|
|
|
switch (this->uvs_table->get_glyph_variant (unicode,
|
|
|
|
variation_selector,
|
|
|
|
glyph))
|
2014-09-25 16:45:49 +02:00
|
|
|
{
|
2016-02-24 11:05:23 +01:00
|
|
|
case OT::GLYPH_VARIANT_NOT_FOUND: return false;
|
|
|
|
case OT::GLYPH_VARIANT_FOUND: return true;
|
|
|
|
case OT::GLYPH_VARIANT_USE_DEFAULT: break;
|
2014-09-25 16:45:49 +02:00
|
|
|
}
|
|
|
|
|
2016-02-24 11:05:23 +01:00
|
|
|
return get_nominal_glyph (unicode, glyph);
|
2014-09-25 16:45:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-24 22:26:36 +01:00
|
|
|
struct hb_ot_font_t
|
|
|
|
{
|
2014-09-25 16:45:49 +02:00
|
|
|
hb_ot_face_cmap_accelerator_t cmap;
|
2014-09-25 16:26:56 +02:00
|
|
|
hb_ot_face_metrics_accelerator_t h_metrics;
|
|
|
|
hb_ot_face_metrics_accelerator_t v_metrics;
|
2015-08-23 15:42:20 +02:00
|
|
|
hb_ot_face_glyf_accelerator_t glyf;
|
2014-03-24 22:26:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static hb_ot_font_t *
|
2015-10-07 23:33:02 +02:00
|
|
|
_hb_ot_font_create (hb_face_t *face)
|
2014-03-24 22:26:36 +01:00
|
|
|
{
|
|
|
|
hb_ot_font_t *ot_font = (hb_ot_font_t *) calloc (1, sizeof (hb_ot_font_t));
|
|
|
|
|
|
|
|
if (unlikely (!ot_font))
|
|
|
|
return NULL;
|
|
|
|
|
2014-09-25 16:45:49 +02:00
|
|
|
ot_font->cmap.init (face);
|
2015-10-26 08:23:22 +01:00
|
|
|
ot_font->h_metrics.init (face, HB_OT_TAG_hhea, HB_OT_TAG_hmtx, HB_OT_TAG_os2);
|
|
|
|
ot_font->v_metrics.init (face, HB_OT_TAG_vhea, HB_OT_TAG_vmtx, HB_TAG_NONE); /* TODO Can we do this lazily? */
|
2015-08-23 15:42:20 +02:00
|
|
|
ot_font->glyf.init (face);
|
2014-05-12 19:46:29 +02:00
|
|
|
|
2014-03-24 22:26:36 +01:00
|
|
|
return ot_font;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_hb_ot_font_destroy (hb_ot_font_t *ot_font)
|
|
|
|
{
|
2014-09-25 16:45:49 +02:00
|
|
|
ot_font->cmap.fini ();
|
2014-09-25 15:53:24 +02:00
|
|
|
ot_font->h_metrics.fini ();
|
|
|
|
ot_font->v_metrics.fini ();
|
2015-10-13 15:32:56 +02:00
|
|
|
ot_font->glyf.fini ();
|
2014-03-24 22:26:36 +01:00
|
|
|
|
|
|
|
free (ot_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static hb_bool_t
|
2016-02-24 11:05:23 +01:00
|
|
|
hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED,
|
|
|
|
void *font_data,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t *glyph,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
|
|
|
|
{
|
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
|
|
|
return ot_font->cmap.get_nominal_glyph (unicode, glyph);
|
|
|
|
}
|
2014-03-24 22:26:36 +01:00
|
|
|
|
2016-02-24 11:05:23 +01:00
|
|
|
static hb_bool_t
|
|
|
|
hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED,
|
|
|
|
void *font_data,
|
|
|
|
hb_codepoint_t unicode,
|
|
|
|
hb_codepoint_t variation_selector,
|
|
|
|
hb_codepoint_t *glyph,
|
|
|
|
void *user_data HB_UNUSED)
|
2014-03-24 22:26:36 +01:00
|
|
|
{
|
2014-05-12 19:46:29 +02:00
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
2016-02-24 11:05:23 +01:00
|
|
|
return ot_font->cmap.get_variation_glyph (unicode, variation_selector, glyph);
|
2014-03-24 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_position_t
|
2014-05-12 19:46:29 +02:00
|
|
|
hb_ot_get_glyph_h_advance (hb_font_t *font HB_UNUSED,
|
2014-03-24 22:26:36 +01:00
|
|
|
void *font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
2014-09-25 15:53:24 +02:00
|
|
|
return font->em_scale_x (ot_font->h_metrics.get_advance (glyph));
|
2014-03-24 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_position_t
|
|
|
|
hb_ot_get_glyph_v_advance (hb_font_t *font HB_UNUSED,
|
|
|
|
void *font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
2014-09-25 12:04:08 +02:00
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
2015-05-21 23:00:15 +02:00
|
|
|
return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph));
|
2014-03-24 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t
|
|
|
|
hb_ot_get_glyph_extents (hb_font_t *font HB_UNUSED,
|
|
|
|
void *font_data,
|
|
|
|
hb_codepoint_t glyph,
|
|
|
|
hb_glyph_extents_t *extents,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
2015-08-23 15:42:20 +02:00
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
|
|
|
bool ret = ot_font->glyf.get_extents (glyph, extents);
|
|
|
|
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);
|
|
|
|
return ret;
|
2014-03-24 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
2015-10-26 08:23:22 +01:00
|
|
|
static hb_bool_t
|
|
|
|
hb_ot_get_font_h_extents (hb_font_t *font HB_UNUSED,
|
|
|
|
void *font_data,
|
|
|
|
hb_font_extents_t *metrics,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
|
|
|
metrics->ascender = font->em_scale_y (ot_font->h_metrics.ascender);
|
|
|
|
metrics->descender = font->em_scale_y (ot_font->h_metrics.descender);
|
|
|
|
metrics->line_gap = font->em_scale_y (ot_font->h_metrics.line_gap);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static hb_bool_t
|
|
|
|
hb_ot_get_font_v_extents (hb_font_t *font HB_UNUSED,
|
|
|
|
void *font_data,
|
|
|
|
hb_font_extents_t *metrics,
|
|
|
|
void *user_data HB_UNUSED)
|
|
|
|
{
|
|
|
|
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
|
|
|
|
metrics->ascender = font->em_scale_x (ot_font->v_metrics.ascender);
|
|
|
|
metrics->descender = font->em_scale_x (ot_font->v_metrics.descender);
|
|
|
|
metrics->line_gap = font->em_scale_x (ot_font->v_metrics.line_gap);
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-24 22:26:36 +01:00
|
|
|
|
2015-11-05 05:43:59 +01:00
|
|
|
static hb_font_funcs_t *static_ot_funcs = NULL;
|
|
|
|
|
|
|
|
#ifdef HB_USE_ATEXIT
|
|
|
|
static
|
|
|
|
void free_static_ot_funcs (void)
|
|
|
|
{
|
|
|
|
hb_font_funcs_destroy (static_ot_funcs);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-24 22:26:36 +01:00
|
|
|
static hb_font_funcs_t *
|
|
|
|
_hb_ot_get_font_funcs (void)
|
|
|
|
{
|
2015-11-05 05:43:59 +01:00
|
|
|
retry:
|
|
|
|
hb_font_funcs_t *funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ot_funcs);
|
2014-03-24 22:26:36 +01:00
|
|
|
|
2015-11-05 05:43:59 +01:00
|
|
|
if (unlikely (!funcs))
|
|
|
|
{
|
|
|
|
funcs = hb_font_funcs_create ();
|
|
|
|
|
2015-10-26 08:23:22 +01:00
|
|
|
hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, NULL, NULL);
|
|
|
|
hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, NULL, NULL);
|
2016-02-24 11:05:23 +01:00
|
|
|
hb_font_funcs_set_nominal_glyph_func (funcs, hb_ot_get_nominal_glyph, NULL, NULL);
|
|
|
|
hb_font_funcs_set_variation_glyph_func (funcs, hb_ot_get_variation_glyph, NULL, NULL);
|
2015-11-05 05:43:59 +01:00
|
|
|
hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ot_get_glyph_h_advance, NULL, NULL);
|
|
|
|
hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ot_get_glyph_v_advance, NULL, NULL);
|
2015-11-05 05:47:42 +01:00
|
|
|
//hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ot_get_glyph_h_origin, NULL, NULL);
|
|
|
|
//hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, NULL, NULL);
|
|
|
|
//hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ot_get_glyph_h_kerning, NULL, NULL); TODO
|
|
|
|
//hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ot_get_glyph_v_kerning, NULL, NULL);
|
2015-11-05 05:43:59 +01:00
|
|
|
hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, NULL, NULL);
|
2015-11-05 05:47:42 +01:00
|
|
|
//hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour_point, NULL, NULL); TODO
|
|
|
|
//hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, NULL, NULL); TODO
|
|
|
|
//hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, NULL, NULL); TODO
|
2015-11-05 05:43:59 +01:00
|
|
|
|
|
|
|
hb_font_funcs_make_immutable (funcs);
|
|
|
|
|
|
|
|
if (!hb_atomic_ptr_cmpexch (&static_ot_funcs, NULL, funcs)) {
|
|
|
|
hb_font_funcs_destroy (funcs);
|
|
|
|
goto retry;
|
2014-03-24 22:26:36 +01:00
|
|
|
}
|
2015-11-05 05:43:59 +01:00
|
|
|
|
|
|
|
#ifdef HB_USE_ATEXIT
|
|
|
|
atexit (free_static_ot_funcs); /* First person registers atexit() callback. */
|
|
|
|
#endif
|
2014-03-24 22:26:36 +01:00
|
|
|
};
|
|
|
|
|
2015-11-05 05:43:59 +01:00
|
|
|
return funcs;
|
2014-03-24 22:26:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-01 13:22:01 +02:00
|
|
|
/**
|
2015-11-27 01:30:37 +01:00
|
|
|
* hb_ot_font_set_funcs:
|
|
|
|
*
|
2015-06-01 13:22:01 +02:00
|
|
|
* Since: 0.9.28
|
|
|
|
**/
|
2014-03-24 22:26:36 +01:00
|
|
|
void
|
|
|
|
hb_ot_font_set_funcs (hb_font_t *font)
|
|
|
|
{
|
2015-10-07 23:33:02 +02:00
|
|
|
hb_ot_font_t *ot_font = _hb_ot_font_create (font->face);
|
2014-03-24 22:26:36 +01:00
|
|
|
if (unlikely (!ot_font))
|
|
|
|
return;
|
|
|
|
|
|
|
|
hb_font_set_funcs (font,
|
|
|
|
_hb_ot_get_font_funcs (),
|
|
|
|
ot_font,
|
|
|
|
(hb_destroy_func_t) _hb_ot_font_destroy);
|
|
|
|
}
|