Path: blob/master/src/java.desktop/share/native/libharfbuzz/hb-font.cc
41152 views
/*1* Copyright © 2009 Red Hat, Inc.2* Copyright © 2012 Google, Inc.3*4* This is part of HarfBuzz, a text shaping library.5*6* Permission is hereby granted, without written agreement and without7* license or royalty fees, to use, copy, modify, and distribute this8* software and its documentation for any purpose, provided that the9* above copyright notice and the following two paragraphs appear in10* all copies of this software.11*12* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR13* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES14* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN15* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH16* DAMAGE.17*18* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,19* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND20* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS21* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO22* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.23*24* Red Hat Author(s): Behdad Esfahbod25* Google Author(s): Behdad Esfahbod26*/2728#include "hb.hh"2930#include "hb-font.hh"31#include "hb-machinery.hh"3233#include "hb-ot.h"3435#include "hb-ot-var-avar-table.hh"36#include "hb-ot-var-fvar-table.hh"373839/**40* SECTION:hb-font41* @title: hb-font42* @short_description: Font objects43* @include: hb.h44*45* Functions for working with font objects.46*47* A font object represents a font face at a specific size and with48* certain other parameters (pixels-per-em, points-per-em, variation49* settings) specified. Font objects are created from font face50* objects, and are used as input to hb_shape(), among other things.51*52* Client programs can optionally pass in their own functions that53* implement the basic, lower-level queries of font objects. This set54* of font functions is defined by the virtual methods in55* #hb_font_funcs_t.56*57* HarfBuzz provides a built-in set of lightweight default58* functions for each method in #hb_font_funcs_t.59**/606162/*63* hb_font_funcs_t64*/6566static hb_bool_t67hb_font_get_font_h_extents_nil (hb_font_t *font HB_UNUSED,68void *font_data HB_UNUSED,69hb_font_extents_t *extents,70void *user_data HB_UNUSED)71{72memset (extents, 0, sizeof (*extents));73return false;74}7576static hb_bool_t77hb_font_get_font_h_extents_default (hb_font_t *font,78void *font_data HB_UNUSED,79hb_font_extents_t *extents,80void *user_data HB_UNUSED)81{82hb_bool_t ret = font->parent->get_font_h_extents (extents);83if (ret) {84extents->ascender = font->parent_scale_y_distance (extents->ascender);85extents->descender = font->parent_scale_y_distance (extents->descender);86extents->line_gap = font->parent_scale_y_distance (extents->line_gap);87}88return ret;89}9091static hb_bool_t92hb_font_get_font_v_extents_nil (hb_font_t *font HB_UNUSED,93void *font_data HB_UNUSED,94hb_font_extents_t *extents,95void *user_data HB_UNUSED)96{97memset (extents, 0, sizeof (*extents));98return false;99}100101static hb_bool_t102hb_font_get_font_v_extents_default (hb_font_t *font,103void *font_data HB_UNUSED,104hb_font_extents_t *extents,105void *user_data HB_UNUSED)106{107hb_bool_t ret = font->parent->get_font_v_extents (extents);108if (ret) {109extents->ascender = font->parent_scale_x_distance (extents->ascender);110extents->descender = font->parent_scale_x_distance (extents->descender);111extents->line_gap = font->parent_scale_x_distance (extents->line_gap);112}113return ret;114}115116static hb_bool_t117hb_font_get_nominal_glyph_nil (hb_font_t *font HB_UNUSED,118void *font_data HB_UNUSED,119hb_codepoint_t unicode HB_UNUSED,120hb_codepoint_t *glyph,121void *user_data HB_UNUSED)122{123*glyph = 0;124return false;125}126127static hb_bool_t128hb_font_get_nominal_glyph_default (hb_font_t *font,129void *font_data HB_UNUSED,130hb_codepoint_t unicode,131hb_codepoint_t *glyph,132void *user_data HB_UNUSED)133{134if (font->has_nominal_glyphs_func_set ())135{136return font->get_nominal_glyphs (1, &unicode, 0, glyph, 0);137}138return font->parent->get_nominal_glyph (unicode, glyph);139}140141#define hb_font_get_nominal_glyphs_nil hb_font_get_nominal_glyphs_default142143static unsigned int144hb_font_get_nominal_glyphs_default (hb_font_t *font,145void *font_data HB_UNUSED,146unsigned int count,147const hb_codepoint_t *first_unicode,148unsigned int unicode_stride,149hb_codepoint_t *first_glyph,150unsigned int glyph_stride,151void *user_data HB_UNUSED)152{153if (font->has_nominal_glyph_func_set ())154{155for (unsigned int i = 0; i < count; i++)156{157if (!font->get_nominal_glyph (*first_unicode, first_glyph))158return i;159160first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);161first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);162}163return count;164}165166return font->parent->get_nominal_glyphs (count,167first_unicode, unicode_stride,168first_glyph, glyph_stride);169}170171static hb_bool_t172hb_font_get_variation_glyph_nil (hb_font_t *font HB_UNUSED,173void *font_data HB_UNUSED,174hb_codepoint_t unicode HB_UNUSED,175hb_codepoint_t variation_selector HB_UNUSED,176hb_codepoint_t *glyph,177void *user_data HB_UNUSED)178{179*glyph = 0;180return false;181}182183static hb_bool_t184hb_font_get_variation_glyph_default (hb_font_t *font,185void *font_data HB_UNUSED,186hb_codepoint_t unicode,187hb_codepoint_t variation_selector,188hb_codepoint_t *glyph,189void *user_data HB_UNUSED)190{191return font->parent->get_variation_glyph (unicode, variation_selector, glyph);192}193194195static hb_position_t196hb_font_get_glyph_h_advance_nil (hb_font_t *font,197void *font_data HB_UNUSED,198hb_codepoint_t glyph HB_UNUSED,199void *user_data HB_UNUSED)200{201return font->x_scale;202}203204static hb_position_t205hb_font_get_glyph_h_advance_default (hb_font_t *font,206void *font_data HB_UNUSED,207hb_codepoint_t glyph,208void *user_data HB_UNUSED)209{210if (font->has_glyph_h_advances_func_set ())211{212hb_position_t ret;213font->get_glyph_h_advances (1, &glyph, 0, &ret, 0);214return ret;215}216return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph));217}218219static hb_position_t220hb_font_get_glyph_v_advance_nil (hb_font_t *font,221void *font_data HB_UNUSED,222hb_codepoint_t glyph HB_UNUSED,223void *user_data HB_UNUSED)224{225/* TODO use font_extents.ascender+descender */226return font->y_scale;227}228229static hb_position_t230hb_font_get_glyph_v_advance_default (hb_font_t *font,231void *font_data HB_UNUSED,232hb_codepoint_t glyph,233void *user_data HB_UNUSED)234{235if (font->has_glyph_v_advances_func_set ())236{237hb_position_t ret;238font->get_glyph_v_advances (1, &glyph, 0, &ret, 0);239return ret;240}241return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph));242}243244#define hb_font_get_glyph_h_advances_nil hb_font_get_glyph_h_advances_default245246static void247hb_font_get_glyph_h_advances_default (hb_font_t* font,248void* font_data HB_UNUSED,249unsigned int count,250const hb_codepoint_t *first_glyph,251unsigned int glyph_stride,252hb_position_t *first_advance,253unsigned int advance_stride,254void *user_data HB_UNUSED)255{256if (font->has_glyph_h_advance_func_set ())257{258for (unsigned int i = 0; i < count; i++)259{260*first_advance = font->get_glyph_h_advance (*first_glyph);261first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);262first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);263}264return;265}266267font->parent->get_glyph_h_advances (count,268first_glyph, glyph_stride,269first_advance, advance_stride);270for (unsigned int i = 0; i < count; i++)271{272*first_advance = font->parent_scale_x_distance (*first_advance);273first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);274}275}276277#define hb_font_get_glyph_v_advances_nil hb_font_get_glyph_v_advances_default278static void279hb_font_get_glyph_v_advances_default (hb_font_t* font,280void* font_data HB_UNUSED,281unsigned int count,282const hb_codepoint_t *first_glyph,283unsigned int glyph_stride,284hb_position_t *first_advance,285unsigned int advance_stride,286void *user_data HB_UNUSED)287{288if (font->has_glyph_v_advance_func_set ())289{290for (unsigned int i = 0; i < count; i++)291{292*first_advance = font->get_glyph_v_advance (*first_glyph);293first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);294first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);295}296return;297}298299font->parent->get_glyph_v_advances (count,300first_glyph, glyph_stride,301first_advance, advance_stride);302for (unsigned int i = 0; i < count; i++)303{304*first_advance = font->parent_scale_y_distance (*first_advance);305first_advance = &StructAtOffsetUnaligned<hb_position_t> (first_advance, advance_stride);306}307}308309static hb_bool_t310hb_font_get_glyph_h_origin_nil (hb_font_t *font HB_UNUSED,311void *font_data HB_UNUSED,312hb_codepoint_t glyph HB_UNUSED,313hb_position_t *x,314hb_position_t *y,315void *user_data HB_UNUSED)316{317*x = *y = 0;318return true;319}320321static hb_bool_t322hb_font_get_glyph_h_origin_default (hb_font_t *font,323void *font_data HB_UNUSED,324hb_codepoint_t glyph,325hb_position_t *x,326hb_position_t *y,327void *user_data HB_UNUSED)328{329hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y);330if (ret)331font->parent_scale_position (x, y);332return ret;333}334335static hb_bool_t336hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,337void *font_data HB_UNUSED,338hb_codepoint_t glyph HB_UNUSED,339hb_position_t *x,340hb_position_t *y,341void *user_data HB_UNUSED)342{343*x = *y = 0;344return false;345}346347static hb_bool_t348hb_font_get_glyph_v_origin_default (hb_font_t *font,349void *font_data HB_UNUSED,350hb_codepoint_t glyph,351hb_position_t *x,352hb_position_t *y,353void *user_data HB_UNUSED)354{355hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y);356if (ret)357font->parent_scale_position (x, y);358return ret;359}360361static hb_position_t362hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,363void *font_data HB_UNUSED,364hb_codepoint_t left_glyph HB_UNUSED,365hb_codepoint_t right_glyph HB_UNUSED,366void *user_data HB_UNUSED)367{368return 0;369}370371static hb_position_t372hb_font_get_glyph_h_kerning_default (hb_font_t *font,373void *font_data HB_UNUSED,374hb_codepoint_t left_glyph,375hb_codepoint_t right_glyph,376void *user_data HB_UNUSED)377{378return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph));379}380381#ifndef HB_DISABLE_DEPRECATED382static hb_position_t383hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,384void *font_data HB_UNUSED,385hb_codepoint_t top_glyph HB_UNUSED,386hb_codepoint_t bottom_glyph HB_UNUSED,387void *user_data HB_UNUSED)388{389return 0;390}391392static hb_position_t393hb_font_get_glyph_v_kerning_default (hb_font_t *font,394void *font_data HB_UNUSED,395hb_codepoint_t top_glyph,396hb_codepoint_t bottom_glyph,397void *user_data HB_UNUSED)398{399return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph));400}401#endif402403static hb_bool_t404hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,405void *font_data HB_UNUSED,406hb_codepoint_t glyph HB_UNUSED,407hb_glyph_extents_t *extents,408void *user_data HB_UNUSED)409{410memset (extents, 0, sizeof (*extents));411return false;412}413414static hb_bool_t415hb_font_get_glyph_extents_default (hb_font_t *font,416void *font_data HB_UNUSED,417hb_codepoint_t glyph,418hb_glyph_extents_t *extents,419void *user_data HB_UNUSED)420{421hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents);422if (ret) {423font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);424font->parent_scale_distance (&extents->width, &extents->height);425}426return ret;427}428429static hb_bool_t430hb_font_get_glyph_contour_point_nil (hb_font_t *font HB_UNUSED,431void *font_data HB_UNUSED,432hb_codepoint_t glyph HB_UNUSED,433unsigned int point_index HB_UNUSED,434hb_position_t *x,435hb_position_t *y,436void *user_data HB_UNUSED)437{438*x = *y = 0;439return false;440}441442static hb_bool_t443hb_font_get_glyph_contour_point_default (hb_font_t *font,444void *font_data HB_UNUSED,445hb_codepoint_t glyph,446unsigned int point_index,447hb_position_t *x,448hb_position_t *y,449void *user_data HB_UNUSED)450{451hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y);452if (ret)453font->parent_scale_position (x, y);454return ret;455}456457static hb_bool_t458hb_font_get_glyph_name_nil (hb_font_t *font HB_UNUSED,459void *font_data HB_UNUSED,460hb_codepoint_t glyph HB_UNUSED,461char *name,462unsigned int size,463void *user_data HB_UNUSED)464{465if (size) *name = '\0';466return false;467}468469static hb_bool_t470hb_font_get_glyph_name_default (hb_font_t *font,471void *font_data HB_UNUSED,472hb_codepoint_t glyph,473char *name,474unsigned int size,475void *user_data HB_UNUSED)476{477return font->parent->get_glyph_name (glyph, name, size);478}479480static hb_bool_t481hb_font_get_glyph_from_name_nil (hb_font_t *font HB_UNUSED,482void *font_data HB_UNUSED,483const char *name HB_UNUSED,484int len HB_UNUSED, /* -1 means nul-terminated */485hb_codepoint_t *glyph,486void *user_data HB_UNUSED)487{488*glyph = 0;489return false;490}491492static hb_bool_t493hb_font_get_glyph_from_name_default (hb_font_t *font,494void *font_data HB_UNUSED,495const char *name,496int len, /* -1 means nul-terminated */497hb_codepoint_t *glyph,498void *user_data HB_UNUSED)499{500return font->parent->get_glyph_from_name (name, len, glyph);501}502503DEFINE_NULL_INSTANCE (hb_font_funcs_t) =504{505HB_OBJECT_HEADER_STATIC,506507{508#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,509HB_FONT_FUNCS_IMPLEMENT_CALLBACKS510#undef HB_FONT_FUNC_IMPLEMENT511},512{513#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,514HB_FONT_FUNCS_IMPLEMENT_CALLBACKS515#undef HB_FONT_FUNC_IMPLEMENT516},517{518{519#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil,520HB_FONT_FUNCS_IMPLEMENT_CALLBACKS521#undef HB_FONT_FUNC_IMPLEMENT522}523}524};525526static const hb_font_funcs_t _hb_font_funcs_default = {527HB_OBJECT_HEADER_STATIC,528529{530#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,531HB_FONT_FUNCS_IMPLEMENT_CALLBACKS532#undef HB_FONT_FUNC_IMPLEMENT533},534{535#define HB_FONT_FUNC_IMPLEMENT(name) nullptr,536HB_FONT_FUNCS_IMPLEMENT_CALLBACKS537#undef HB_FONT_FUNC_IMPLEMENT538},539{540{541#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_default,542HB_FONT_FUNCS_IMPLEMENT_CALLBACKS543#undef HB_FONT_FUNC_IMPLEMENT544}545}546};547548549/**550* hb_font_funcs_create: (Xconstructor)551*552* Creates a new #hb_font_funcs_t structure of font functions.553*554* Return value: (transfer full): The font-functions structure555*556* Since: 0.9.2557**/558hb_font_funcs_t *559hb_font_funcs_create ()560{561hb_font_funcs_t *ffuncs;562563if (!(ffuncs = hb_object_create<hb_font_funcs_t> ()))564return hb_font_funcs_get_empty ();565566ffuncs->get = _hb_font_funcs_default.get;567568return ffuncs;569}570571/**572* hb_font_funcs_get_empty:573*574* Fetches an empty font-functions structure.575*576* Return value: (transfer full): The font-functions structure577*578* Since: 0.9.2579**/580hb_font_funcs_t *581hb_font_funcs_get_empty ()582{583return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_default);584}585586/**587* hb_font_funcs_reference: (skip)588* @ffuncs: The font-functions structure589*590* Increases the reference count on a font-functions structure.591*592* Return value: The font-functions structure593*594* Since: 0.9.2595**/596hb_font_funcs_t *597hb_font_funcs_reference (hb_font_funcs_t *ffuncs)598{599return hb_object_reference (ffuncs);600}601602/**603* hb_font_funcs_destroy: (skip)604* @ffuncs: The font-functions structure605*606* Decreases the reference count on a font-functions structure. When607* the reference count reaches zero, the font-functions structure is608* destroyed, freeing all memory.609*610* Since: 0.9.2611**/612void613hb_font_funcs_destroy (hb_font_funcs_t *ffuncs)614{615if (!hb_object_destroy (ffuncs)) return;616617#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \618ffuncs->destroy.name (ffuncs->user_data.name);619HB_FONT_FUNCS_IMPLEMENT_CALLBACKS620#undef HB_FONT_FUNC_IMPLEMENT621622free (ffuncs);623}624625/**626* hb_font_funcs_set_user_data: (skip)627* @ffuncs: The font-functions structure628* @key: The user-data key to set629* @data: A pointer to the user data set630* @destroy: (nullable): A callback to call when @data is not needed anymore631* @replace: Whether to replace an existing data with the same key632*633* Attaches a user-data key/data pair to the specified font-functions structure.634*635* Return value: %true if success, %false otherwise636*637* Since: 0.9.2638**/639hb_bool_t640hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,641hb_user_data_key_t *key,642void * data,643hb_destroy_func_t destroy /* May be NULL. */,644hb_bool_t replace)645{646return hb_object_set_user_data (ffuncs, key, data, destroy, replace);647}648649/**650* hb_font_funcs_get_user_data: (skip)651* @ffuncs: The font-functions structure652* @key: The user-data key to query653*654* Fetches the user data associated with the specified key,655* attached to the specified font-functions structure.656*657* Return value: (transfer none): A pointer to the user data658*659* Since: 0.9.2660**/661void *662hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,663hb_user_data_key_t *key)664{665return hb_object_get_user_data (ffuncs, key);666}667668669/**670* hb_font_funcs_make_immutable:671* @ffuncs: The font-functions structure672*673* Makes a font-functions structure immutable.674*675* Since: 0.9.2676**/677void678hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)679{680if (hb_object_is_immutable (ffuncs))681return;682683hb_object_make_immutable (ffuncs);684}685686/**687* hb_font_funcs_is_immutable:688* @ffuncs: The font-functions structure689*690* Tests whether a font-functions structure is immutable.691*692* Return value: %true if @ffuncs is immutable, %false otherwise693*694* Since: 0.9.2695**/696hb_bool_t697hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs)698{699return hb_object_is_immutable (ffuncs);700}701702703#define HB_FONT_FUNC_IMPLEMENT(name) \704\705void \706hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \707hb_font_get_##name##_func_t func, \708void *user_data, \709hb_destroy_func_t destroy) \710{ \711if (hb_object_is_immutable (ffuncs)) \712{ \713if (destroy) \714destroy (user_data); \715return; \716} \717\718if (ffuncs->destroy.name) \719ffuncs->destroy.name (ffuncs->user_data.name); \720\721if (func) { \722ffuncs->get.f.name = func; \723ffuncs->user_data.name = user_data; \724ffuncs->destroy.name = destroy; \725} else { \726ffuncs->get.f.name = hb_font_get_##name##_default; \727ffuncs->user_data.name = nullptr; \728ffuncs->destroy.name = nullptr; \729} \730}731732HB_FONT_FUNCS_IMPLEMENT_CALLBACKS733#undef HB_FONT_FUNC_IMPLEMENT734735bool736hb_font_t::has_func_set (unsigned int i)737{738return this->klass->get.array[i] != _hb_font_funcs_default.get.array[i];739}740741bool742hb_font_t::has_func (unsigned int i)743{744return has_func_set (i) ||745(parent && parent != &_hb_Null_hb_font_t && parent->has_func (i));746}747748/* Public getters */749750/**751* hb_font_get_h_extents:752* @font: #hb_font_t to work upon753* @extents: (out): The font extents retrieved754*755* Fetches the extents for a specified font, for horizontal756* text segments.757*758* Return value: %true if data found, %false otherwise759*760* Since: 1.1.3761**/762hb_bool_t763hb_font_get_h_extents (hb_font_t *font,764hb_font_extents_t *extents)765{766return font->get_font_h_extents (extents);767}768769/**770* hb_font_get_v_extents:771* @font: #hb_font_t to work upon772* @extents: (out): The font extents retrieved773*774* Fetches the extents for a specified font, for vertical775* text segments.776*777* Return value: %true if data found, %false otherwise778*779* Since: 1.1.3780**/781hb_bool_t782hb_font_get_v_extents (hb_font_t *font,783hb_font_extents_t *extents)784{785return font->get_font_v_extents (extents);786}787788/**789* hb_font_get_glyph:790* @font: #hb_font_t to work upon791* @unicode: The Unicode code point to query792* @variation_selector: A variation-selector code point793* @glyph: (out): The glyph ID retrieved794*795* Fetches the glyph ID for a Unicode code point in the specified796* font, with an optional variation selector.797*798* If @variation_selector is 0, calls hb_font_get_nominal_glyph();799* otherwise calls hb_font_get_variation_glyph().800*801* Return value: %true if data found, %false otherwise802*803* Since: 0.9.2804**/805hb_bool_t806hb_font_get_glyph (hb_font_t *font,807hb_codepoint_t unicode,808hb_codepoint_t variation_selector,809hb_codepoint_t *glyph)810{811if (unlikely (variation_selector))812return font->get_variation_glyph (unicode, variation_selector, glyph);813return font->get_nominal_glyph (unicode, glyph);814}815816/**817* hb_font_get_nominal_glyph:818* @font: #hb_font_t to work upon819* @unicode: The Unicode code point to query820* @glyph: (out): The glyph ID retrieved821*822* Fetches the nominal glyph ID for a Unicode code point in the823* specified font.824*825* This version of the function should not be used to fetch glyph IDs826* for code points modified by variation selectors. For variation-selector827* support, user hb_font_get_variation_glyph() or use hb_font_get_glyph().828*829* Return value: %true if data found, %false otherwise830*831* Since: 1.2.3832**/833hb_bool_t834hb_font_get_nominal_glyph (hb_font_t *font,835hb_codepoint_t unicode,836hb_codepoint_t *glyph)837{838return font->get_nominal_glyph (unicode, glyph);839}840841/**842* hb_font_get_nominal_glyphs:843* @font: #hb_font_t to work upon844* @count: number of code points to query845* @first_unicode: The first Unicode code point to query846* @unicode_stride: The stride between successive code points847* @first_glyph: (out): The first glyph ID retrieved848* @glyph_stride: The stride between successive glyph IDs849*850* Fetches the nominal glyph IDs for a sequence of Unicode code points. Glyph851* IDs must be returned in a #hb_codepoint_t output parameter.852*853* Return value: the number of code points processed854*855* Since: 2.6.3856**/857unsigned int858hb_font_get_nominal_glyphs (hb_font_t *font,859unsigned int count,860const hb_codepoint_t *first_unicode,861unsigned int unicode_stride,862hb_codepoint_t *first_glyph,863unsigned int glyph_stride)864{865return font->get_nominal_glyphs (count,866first_unicode, unicode_stride,867first_glyph, glyph_stride);868}869870/**871* hb_font_get_variation_glyph:872* @font: #hb_font_t to work upon873* @unicode: The Unicode code point to query874* @variation_selector: The variation-selector code point to query875* @glyph: (out): The glyph ID retrieved876*877* Fetches the glyph ID for a Unicode code point when followed by878* by the specified variation-selector code point, in the specified879* font.880*881* Return value: %true if data found, %false otherwise882*883* Since: 1.2.3884**/885hb_bool_t886hb_font_get_variation_glyph (hb_font_t *font,887hb_codepoint_t unicode,888hb_codepoint_t variation_selector,889hb_codepoint_t *glyph)890{891return font->get_variation_glyph (unicode, variation_selector, glyph);892}893894/**895* hb_font_get_glyph_h_advance:896* @font: #hb_font_t to work upon897* @glyph: The glyph ID to query898*899* Fetches the advance for a glyph ID in the specified font,900* for horizontal text segments.901*902* Return value: The advance of @glyph within @font903*904* Since: 0.9.2905**/906hb_position_t907hb_font_get_glyph_h_advance (hb_font_t *font,908hb_codepoint_t glyph)909{910return font->get_glyph_h_advance (glyph);911}912913/**914* hb_font_get_glyph_v_advance:915* @font: #hb_font_t to work upon916* @glyph: The glyph ID to query917*918* Fetches the advance for a glyph ID in the specified font,919* for vertical text segments.920*921* Return value: The advance of @glyph within @font922*923* Since: 0.9.2924**/925hb_position_t926hb_font_get_glyph_v_advance (hb_font_t *font,927hb_codepoint_t glyph)928{929return font->get_glyph_v_advance (glyph);930}931932/**933* hb_font_get_glyph_h_advances:934* @font: #hb_font_t to work upon935* @count: The number of glyph IDs in the sequence queried936* @first_glyph: The first glyph ID to query937* @glyph_stride: The stride between successive glyph IDs938* @first_advance: (out): The first advance retrieved939* @advance_stride: The stride between successive advances940*941* Fetches the advances for a sequence of glyph IDs in the specified942* font, for horizontal text segments.943*944* Since: 1.8.6945**/946void947hb_font_get_glyph_h_advances (hb_font_t* font,948unsigned int count,949const hb_codepoint_t *first_glyph,950unsigned glyph_stride,951hb_position_t *first_advance,952unsigned advance_stride)953{954font->get_glyph_h_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);955}956/**957* hb_font_get_glyph_v_advances:958* @font: #hb_font_t to work upon959* @count: The number of glyph IDs in the sequence queried960* @first_glyph: The first glyph ID to query961* @glyph_stride: The stride between successive glyph IDs962* @first_advance: (out): The first advance retrieved963* @advance_stride: (out): The stride between successive advances964*965* Fetches the advances for a sequence of glyph IDs in the specified966* font, for vertical text segments.967*968* Since: 1.8.6969**/970void971hb_font_get_glyph_v_advances (hb_font_t* font,972unsigned int count,973const hb_codepoint_t *first_glyph,974unsigned glyph_stride,975hb_position_t *first_advance,976unsigned advance_stride)977{978font->get_glyph_v_advances (count, first_glyph, glyph_stride, first_advance, advance_stride);979}980981/**982* hb_font_get_glyph_h_origin:983* @font: #hb_font_t to work upon984* @glyph: The glyph ID to query985* @x: (out): The X coordinate of the origin986* @y: (out): The Y coordinate of the origin987*988* Fetches the (X,Y) coordinates of the origin for a glyph ID989* in the specified font, for horizontal text segments.990*991* Return value: %true if data found, %false otherwise992*993* Since: 0.9.2994**/995hb_bool_t996hb_font_get_glyph_h_origin (hb_font_t *font,997hb_codepoint_t glyph,998hb_position_t *x,999hb_position_t *y)1000{1001return font->get_glyph_h_origin (glyph, x, y);1002}10031004/**1005* hb_font_get_glyph_v_origin:1006* @font: #hb_font_t to work upon1007* @glyph: The glyph ID to query1008* @x: (out): The X coordinate of the origin1009* @y: (out): The Y coordinate of the origin1010*1011* Fetches the (X,Y) coordinates of the origin for a glyph ID1012* in the specified font, for vertical text segments.1013*1014* Return value: %true if data found, %false otherwise1015*1016* Since: 0.9.21017**/1018hb_bool_t1019hb_font_get_glyph_v_origin (hb_font_t *font,1020hb_codepoint_t glyph,1021hb_position_t *x,1022hb_position_t *y)1023{1024return font->get_glyph_v_origin (glyph, x, y);1025}10261027/**1028* hb_font_get_glyph_h_kerning:1029* @font: #hb_font_t to work upon1030* @left_glyph: The glyph ID of the left glyph in the glyph pair1031* @right_glyph: The glyph ID of the right glyph in the glyph pair1032*1033* Fetches the kerning-adjustment value for a glyph-pair in1034* the specified font, for horizontal text segments.1035*1036* <note>It handles legacy kerning only (as returned by the corresponding1037* #hb_font_funcs_t function).</note>1038*1039* Return value: The kerning adjustment value1040*1041* Since: 0.9.21042**/1043hb_position_t1044hb_font_get_glyph_h_kerning (hb_font_t *font,1045hb_codepoint_t left_glyph,1046hb_codepoint_t right_glyph)1047{1048return font->get_glyph_h_kerning (left_glyph, right_glyph);1049}10501051#ifndef HB_DISABLE_DEPRECATED1052/**1053* hb_font_get_glyph_v_kerning:1054* @font: #hb_font_t to work upon1055* @top_glyph: The glyph ID of the top glyph in the glyph pair1056* @bottom_glyph: The glyph ID of the bottom glyph in the glyph pair1057*1058* Fetches the kerning-adjustment value for a glyph-pair in1059* the specified font, for vertical text segments.1060*1061* <note>It handles legacy kerning only (as returned by the corresponding1062* #hb_font_funcs_t function).</note>1063*1064* Return value: The kerning adjustment value1065*1066* Since: 0.9.21067* Deprecated: 2.0.01068**/1069hb_position_t1070hb_font_get_glyph_v_kerning (hb_font_t *font,1071hb_codepoint_t top_glyph,1072hb_codepoint_t bottom_glyph)1073{1074return font->get_glyph_v_kerning (top_glyph, bottom_glyph);1075}1076#endif10771078/**1079* hb_font_get_glyph_extents:1080* @font: #hb_font_t to work upon1081* @glyph: The glyph ID to query1082* @extents: (out): The #hb_glyph_extents_t retrieved1083*1084* Fetches the #hb_glyph_extents_t data for a glyph ID1085* in the specified font.1086*1087* Return value: %true if data found, %false otherwise1088*1089* Since: 0.9.21090**/1091hb_bool_t1092hb_font_get_glyph_extents (hb_font_t *font,1093hb_codepoint_t glyph,1094hb_glyph_extents_t *extents)1095{1096return font->get_glyph_extents (glyph, extents);1097}10981099/**1100* hb_font_get_glyph_contour_point:1101* @font: #hb_font_t to work upon1102* @glyph: The glyph ID to query1103* @point_index: The contour-point index to query1104* @x: (out): The X value retrieved for the contour point1105* @y: (out): The Y value retrieved for the contour point1106*1107* Fetches the (x,y) coordinates of a specified contour-point index1108* in the specified glyph, within the specified font.1109*1110* Return value: %true if data found, %false otherwise1111*1112* Since: 0.9.21113**/1114hb_bool_t1115hb_font_get_glyph_contour_point (hb_font_t *font,1116hb_codepoint_t glyph,1117unsigned int point_index,1118hb_position_t *x,1119hb_position_t *y)1120{1121return font->get_glyph_contour_point (glyph, point_index, x, y);1122}11231124/**1125* hb_font_get_glyph_name:1126* @font: #hb_font_t to work upon1127* @glyph: The glyph ID to query1128* @name: (out) (array length=size): Name string retrieved for the glyph ID1129* @size: Length of the glyph-name string retrieved1130*1131* Fetches the glyph-name string for a glyph ID in the specified @font.1132*1133* Return value: %true if data found, %false otherwise1134*1135* Since: 0.9.21136**/1137hb_bool_t1138hb_font_get_glyph_name (hb_font_t *font,1139hb_codepoint_t glyph,1140char *name,1141unsigned int size)1142{1143return font->get_glyph_name (glyph, name, size);1144}11451146/**1147* hb_font_get_glyph_from_name:1148* @font: #hb_font_t to work upon1149* @name: (array length=len): The name string to query1150* @len: The length of the name queried1151* @glyph: (out): The glyph ID retrieved1152*1153* Fetches the glyph ID that corresponds to a name string in the specified @font.1154*1155* <note>Note: @len == -1 means the name string is null-terminated.</note>1156*1157* Return value: %true if data found, %false otherwise1158*1159* Since: 0.9.21160**/1161hb_bool_t1162hb_font_get_glyph_from_name (hb_font_t *font,1163const char *name,1164int len, /* -1 means nul-terminated */1165hb_codepoint_t *glyph)1166{1167return font->get_glyph_from_name (name, len, glyph);1168}116911701171/* A bit higher-level, and with fallback */11721173/**1174* hb_font_get_extents_for_direction:1175* @font: #hb_font_t to work upon1176* @direction: The direction of the text segment1177* @extents: (out): The #hb_font_extents_t retrieved1178*1179* Fetches the extents for a font in a text segment of the1180* specified direction.1181*1182* Calls the appropriate direction-specific variant (horizontal1183* or vertical) depending on the value of @direction.1184*1185* Since: 1.1.31186**/1187void1188hb_font_get_extents_for_direction (hb_font_t *font,1189hb_direction_t direction,1190hb_font_extents_t *extents)1191{1192return font->get_extents_for_direction (direction, extents);1193}1194/**1195* hb_font_get_glyph_advance_for_direction:1196* @font: #hb_font_t to work upon1197* @glyph: The glyph ID to query1198* @direction: The direction of the text segment1199* @x: (out): The horizontal advance retrieved1200* @y: (out): The vertical advance retrieved1201*1202* Fetches the advance for a glyph ID from the specified font,1203* in a text segment of the specified direction.1204*1205* Calls the appropriate direction-specific variant (horizontal1206* or vertical) depending on the value of @direction.1207*1208* Since: 0.9.21209**/1210void1211hb_font_get_glyph_advance_for_direction (hb_font_t *font,1212hb_codepoint_t glyph,1213hb_direction_t direction,1214hb_position_t *x,1215hb_position_t *y)1216{1217return font->get_glyph_advance_for_direction (glyph, direction, x, y);1218}1219/**1220* hb_font_get_glyph_advances_for_direction:1221* @font: #hb_font_t to work upon1222* @direction: The direction of the text segment1223* @count: The number of glyph IDs in the sequence queried1224* @first_glyph: The first glyph ID to query1225* @glyph_stride: The stride between successive glyph IDs1226* @first_advance: (out): The first advance retrieved1227* @advance_stride: (out): The stride between successive advances1228*1229* Fetches the advances for a sequence of glyph IDs in the specified1230* font, in a text segment of the specified direction.1231*1232* Calls the appropriate direction-specific variant (horizontal1233* or vertical) depending on the value of @direction.1234*1235* Since: 1.8.61236**/1237HB_EXTERN void1238hb_font_get_glyph_advances_for_direction (hb_font_t* font,1239hb_direction_t direction,1240unsigned int count,1241const hb_codepoint_t *first_glyph,1242unsigned glyph_stride,1243hb_position_t *first_advance,1244unsigned advance_stride)1245{1246font->get_glyph_advances_for_direction (direction, count, first_glyph, glyph_stride, first_advance, advance_stride);1247}12481249/**1250* hb_font_get_glyph_origin_for_direction:1251* @font: #hb_font_t to work upon1252* @glyph: The glyph ID to query1253* @direction: The direction of the text segment1254* @x: (out): The X coordinate retrieved for the origin1255* @y: (out): The Y coordinate retrieved for the origin1256*1257* Fetches the (X,Y) coordinates of the origin for a glyph in1258* the specified font.1259*1260* Calls the appropriate direction-specific variant (horizontal1261* or vertical) depending on the value of @direction.1262*1263* Since: 0.9.21264**/1265void1266hb_font_get_glyph_origin_for_direction (hb_font_t *font,1267hb_codepoint_t glyph,1268hb_direction_t direction,1269hb_position_t *x,1270hb_position_t *y)1271{1272return font->get_glyph_origin_for_direction (glyph, direction, x, y);1273}12741275/**1276* hb_font_add_glyph_origin_for_direction:1277* @font: #hb_font_t to work upon1278* @glyph: The glyph ID to query1279* @direction: The direction of the text segment1280* @x: (inout): Input = The original X coordinate1281* Output = The X coordinate plus the X-coordinate of the origin1282* @y: (inout): Input = The original Y coordinate1283* Output = The Y coordinate plus the Y-coordinate of the origin1284*1285* Adds the origin coordinates to an (X,Y) point coordinate, in1286* the specified glyph ID in the specified font.1287*1288* Calls the appropriate direction-specific variant (horizontal1289* or vertical) depending on the value of @direction.1290*1291* Since: 0.9.21292**/1293void1294hb_font_add_glyph_origin_for_direction (hb_font_t *font,1295hb_codepoint_t glyph,1296hb_direction_t direction,1297hb_position_t *x,1298hb_position_t *y)1299{1300return font->add_glyph_origin_for_direction (glyph, direction, x, y);1301}13021303/**1304* hb_font_subtract_glyph_origin_for_direction:1305* @font: #hb_font_t to work upon1306* @glyph: The glyph ID to query1307* @direction: The direction of the text segment1308* @x: (inout): Input = The original X coordinate1309* Output = The X coordinate minus the X-coordinate of the origin1310* @y: (inout): Input = The original Y coordinate1311* Output = The Y coordinate minus the Y-coordinate of the origin1312*1313* Subtracts the origin coordinates from an (X,Y) point coordinate,1314* in the specified glyph ID in the specified font.1315*1316* Calls the appropriate direction-specific variant (horizontal1317* or vertical) depending on the value of @direction.1318*1319* Since: 0.9.21320**/1321void1322hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,1323hb_codepoint_t glyph,1324hb_direction_t direction,1325hb_position_t *x,1326hb_position_t *y)1327{1328return font->subtract_glyph_origin_for_direction (glyph, direction, x, y);1329}13301331/**1332* hb_font_get_glyph_kerning_for_direction:1333* @font: #hb_font_t to work upon1334* @first_glyph: The glyph ID of the first glyph in the glyph pair to query1335* @second_glyph: The glyph ID of the second glyph in the glyph pair to query1336* @direction: The direction of the text segment1337* @x: (out): The horizontal kerning-adjustment value retrieved1338* @y: (out): The vertical kerning-adjustment value retrieved1339*1340* Fetches the kerning-adjustment value for a glyph-pair in the specified font.1341*1342* Calls the appropriate direction-specific variant (horizontal1343* or vertical) depending on the value of @direction.1344*1345* Since: 0.9.21346**/1347void1348hb_font_get_glyph_kerning_for_direction (hb_font_t *font,1349hb_codepoint_t first_glyph,1350hb_codepoint_t second_glyph,1351hb_direction_t direction,1352hb_position_t *x,1353hb_position_t *y)1354{1355return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y);1356}13571358/**1359* hb_font_get_glyph_extents_for_origin:1360* @font: #hb_font_t to work upon1361* @glyph: The glyph ID to query1362* @direction: The direction of the text segment1363* @extents: (out): The #hb_glyph_extents_t retrieved1364*1365* Fetches the #hb_glyph_extents_t data for a glyph ID1366* in the specified font, with respect to the origin in1367* a text segment in the specified direction.1368*1369* Calls the appropriate direction-specific variant (horizontal1370* or vertical) depending on the value of @direction.1371*1372* Return value: %true if data found, %false otherwise1373*1374* Since: 0.9.21375**/1376hb_bool_t1377hb_font_get_glyph_extents_for_origin (hb_font_t *font,1378hb_codepoint_t glyph,1379hb_direction_t direction,1380hb_glyph_extents_t *extents)1381{1382return font->get_glyph_extents_for_origin (glyph, direction, extents);1383}13841385/**1386* hb_font_get_glyph_contour_point_for_origin:1387* @font: #hb_font_t to work upon1388* @glyph: The glyph ID to query1389* @point_index: The contour-point index to query1390* @direction: The direction of the text segment1391* @x: (out): The X value retrieved for the contour point1392* @y: (out): The Y value retrieved for the contour point1393*1394* Fetches the (X,Y) coordinates of a specified contour-point index1395* in the specified glyph ID in the specified font, with respect1396* to the origin in a text segment in the specified direction.1397*1398* Calls the appropriate direction-specific variant (horizontal1399* or vertical) depending on the value of @direction.1400*1401* Return value: %true if data found, %false otherwise1402*1403* Since: 0.9.21404**/1405hb_bool_t1406hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,1407hb_codepoint_t glyph,1408unsigned int point_index,1409hb_direction_t direction,1410hb_position_t *x,1411hb_position_t *y)1412{1413return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y);1414}14151416/**1417* hb_font_glyph_to_string:1418* @font: #hb_font_t to work upon1419* @glyph: The glyph ID to query1420* @s: (out) (array length=size): The string containing the glyph name1421* @size: Length of string @s1422*1423* Fetches the name of the specified glyph ID in @font and returns1424* it in string @s.1425*1426* If the glyph ID has no name in @font, a string of the form `gidDDD` is1427* generated, with `DDD` being the glyph ID.1428*1429* Since: 0.9.21430**/1431void1432hb_font_glyph_to_string (hb_font_t *font,1433hb_codepoint_t glyph,1434char *s,1435unsigned int size)1436{1437font->glyph_to_string (glyph, s, size);1438}14391440/**1441* hb_font_glyph_from_string:1442* @font: #hb_font_t to work upon1443* @s: (array length=len) (element-type uint8_t): string to query1444* @len: The length of the string @s1445* @glyph: (out): The glyph ID corresponding to the string requested1446*1447* Fetches the glyph ID from @font that matches the specified string.1448* Strings of the format `gidDDD` or `uniUUUU` are parsed automatically.1449*1450* <note>Note: @len == -1 means the string is null-terminated.</note>1451*1452* Return value: %true if data found, %false otherwise1453*1454* Since: 0.9.21455**/1456hb_bool_t1457hb_font_glyph_from_string (hb_font_t *font,1458const char *s,1459int len,1460hb_codepoint_t *glyph)1461{1462return font->glyph_from_string (s, len, glyph);1463}146414651466/*1467* hb_font_t1468*/14691470DEFINE_NULL_INSTANCE (hb_font_t) =1471{1472HB_OBJECT_HEADER_STATIC,14731474nullptr, /* parent */1475const_cast<hb_face_t *> (&_hb_Null_hb_face_t),147614771000, /* x_scale */14781000, /* y_scale */14791<<16, /* x_mult */14801<<16, /* y_mult */148114820, /* x_ppem */14830, /* y_ppem */14840, /* ptem */148514860, /* num_coords */1487nullptr, /* coords */1488nullptr, /* design_coords */14891490const_cast<hb_font_funcs_t *> (&_hb_Null_hb_font_funcs_t),14911492/* Zero for the rest is fine. */1493};149414951496static hb_font_t *1497_hb_font_create (hb_face_t *face)1498{1499hb_font_t *font;15001501if (unlikely (!face))1502face = hb_face_get_empty ();1503if (!(font = hb_object_create<hb_font_t> ()))1504return hb_font_get_empty ();15051506hb_face_make_immutable (face);1507font->parent = hb_font_get_empty ();1508font->face = hb_face_reference (face);1509font->klass = hb_font_funcs_get_empty ();1510font->data.init0 (font);1511font->x_scale = font->y_scale = hb_face_get_upem (face);1512font->x_mult = font->y_mult = 1 << 16;15131514return font;1515}15161517/**1518* hb_font_create: (Xconstructor)1519* @face: a face.1520*1521* Constructs a new font object from the specified face.1522*1523* Return value: (transfer full): The new font object1524*1525* Since: 0.9.21526**/1527hb_font_t *1528hb_font_create (hb_face_t *face)1529{1530hb_font_t *font = _hb_font_create (face);15311532#ifndef HB_NO_OT_FONT1533/* Install our in-house, very lightweight, funcs. */1534hb_ot_font_set_funcs (font);1535#endif15361537return font;1538}15391540static void1541_hb_font_adopt_var_coords (hb_font_t *font,1542int *coords, /* 2.14 normalized */1543float *design_coords,1544unsigned int coords_length)1545{1546free (font->coords);1547free (font->design_coords);15481549font->coords = coords;1550font->design_coords = design_coords;1551font->num_coords = coords_length;1552}15531554/**1555* hb_font_create_sub_font:1556* @parent: The parent font object1557*1558* Constructs a sub-font font object from the specified @parent font,1559* replicating the parent's properties.1560*1561* Return value: (transfer full): The new sub-font font object1562*1563* Since: 0.9.21564**/1565hb_font_t *1566hb_font_create_sub_font (hb_font_t *parent)1567{1568if (unlikely (!parent))1569parent = hb_font_get_empty ();15701571hb_font_t *font = _hb_font_create (parent->face);15721573if (unlikely (hb_object_is_immutable (font)))1574return font;15751576font->parent = hb_font_reference (parent);15771578font->x_scale = parent->x_scale;1579font->y_scale = parent->y_scale;1580font->mults_changed ();1581font->x_ppem = parent->x_ppem;1582font->y_ppem = parent->y_ppem;1583font->ptem = parent->ptem;15841585unsigned int num_coords = parent->num_coords;1586if (num_coords)1587{1588int *coords = (int *) calloc (num_coords, sizeof (parent->coords[0]));1589float *design_coords = (float *) calloc (num_coords, sizeof (parent->design_coords[0]));1590if (likely (coords && design_coords))1591{1592memcpy (coords, parent->coords, num_coords * sizeof (parent->coords[0]));1593memcpy (design_coords, parent->design_coords, num_coords * sizeof (parent->design_coords[0]));1594_hb_font_adopt_var_coords (font, coords, design_coords, num_coords);1595}1596else1597{1598free (coords);1599free (design_coords);1600}1601}16021603return font;1604}16051606/**1607* hb_font_get_empty:1608*1609* Fetches the empty font object.1610*1611* Return value: (transfer full): The empty font object1612*1613* Since: 0.9.21614**/1615hb_font_t *1616hb_font_get_empty ()1617{1618return const_cast<hb_font_t *> (&Null (hb_font_t));1619}16201621/**1622* hb_font_reference: (skip)1623* @font: #hb_font_t to work upon1624*1625* Increases the reference count on the given font object.1626*1627* Return value: (transfer full): The @font object1628*1629* Since: 0.9.21630**/1631hb_font_t *1632hb_font_reference (hb_font_t *font)1633{1634return hb_object_reference (font);1635}16361637/**1638* hb_font_destroy: (skip)1639* @font: #hb_font_t to work upon1640*1641* Decreases the reference count on the given font object. When the1642* reference count reaches zero, the font is destroyed,1643* freeing all memory.1644*1645* Since: 0.9.21646**/1647void1648hb_font_destroy (hb_font_t *font)1649{1650if (!hb_object_destroy (font)) return;16511652font->data.fini ();16531654if (font->destroy)1655font->destroy (font->user_data);16561657hb_font_destroy (font->parent);1658hb_face_destroy (font->face);1659hb_font_funcs_destroy (font->klass);16601661free (font->coords);1662free (font->design_coords);16631664free (font);1665}16661667/**1668* hb_font_set_user_data: (skip)1669* @font: #hb_font_t to work upon1670* @key: The user-data key1671* @data: A pointer to the user data1672* @destroy: (nullable): A callback to call when @data is not needed anymore1673* @replace: Whether to replace an existing data with the same key1674*1675* Attaches a user-data key/data pair to the specified font object.1676*1677* Return value: %true if success, %false otherwise1678*1679* Since: 0.9.21680**/1681hb_bool_t1682hb_font_set_user_data (hb_font_t *font,1683hb_user_data_key_t *key,1684void * data,1685hb_destroy_func_t destroy /* May be NULL. */,1686hb_bool_t replace)1687{1688return hb_object_set_user_data (font, key, data, destroy, replace);1689}16901691/**1692* hb_font_get_user_data: (skip)1693* @font: #hb_font_t to work upon1694* @key: The user-data key to query1695*1696* Fetches the user-data object associated with the specified key,1697* attached to the specified font object.1698*1699* Return value: (transfer none): Pointer to the user data1700*1701* Since: 0.9.21702**/1703void *1704hb_font_get_user_data (hb_font_t *font,1705hb_user_data_key_t *key)1706{1707return hb_object_get_user_data (font, key);1708}17091710/**1711* hb_font_make_immutable:1712* @font: #hb_font_t to work upon1713*1714* Makes @font immutable.1715*1716* Since: 0.9.21717**/1718void1719hb_font_make_immutable (hb_font_t *font)1720{1721if (hb_object_is_immutable (font))1722return;17231724if (font->parent)1725hb_font_make_immutable (font->parent);17261727hb_object_make_immutable (font);1728}17291730/**1731* hb_font_is_immutable:1732* @font: #hb_font_t to work upon1733*1734* Tests whether a font object is immutable.1735*1736* Return value: %true if @font is immutable, %false otherwise1737*1738* Since: 0.9.21739**/1740hb_bool_t1741hb_font_is_immutable (hb_font_t *font)1742{1743return hb_object_is_immutable (font);1744}17451746/**1747* hb_font_set_parent:1748* @font: #hb_font_t to work upon1749* @parent: The parent font object to assign1750*1751* Sets the parent font of @font.1752*1753* Since: 1.0.51754**/1755void1756hb_font_set_parent (hb_font_t *font,1757hb_font_t *parent)1758{1759if (hb_object_is_immutable (font))1760return;17611762if (!parent)1763parent = hb_font_get_empty ();17641765hb_font_t *old = font->parent;17661767font->parent = hb_font_reference (parent);17681769hb_font_destroy (old);1770}17711772/**1773* hb_font_get_parent:1774* @font: #hb_font_t to work upon1775*1776* Fetches the parent font of @font.1777*1778* Return value: (transfer none): The parent font object1779*1780* Since: 0.9.21781**/1782hb_font_t *1783hb_font_get_parent (hb_font_t *font)1784{1785return font->parent;1786}17871788/**1789* hb_font_set_face:1790* @font: #hb_font_t to work upon1791* @face: The #hb_face_t to assign1792*1793* Sets @face as the font-face value of @font.1794*1795* Since: 1.4.31796**/1797void1798hb_font_set_face (hb_font_t *font,1799hb_face_t *face)1800{1801if (hb_object_is_immutable (font))1802return;18031804if (unlikely (!face))1805face = hb_face_get_empty ();18061807hb_face_t *old = font->face;18081809hb_face_make_immutable (face);1810font->face = hb_face_reference (face);1811font->mults_changed ();18121813hb_face_destroy (old);1814}18151816/**1817* hb_font_get_face:1818* @font: #hb_font_t to work upon1819*1820* Fetches the face associated with the specified font object.1821*1822* Return value: (transfer none): The #hb_face_t value1823*1824* Since: 0.9.21825**/1826hb_face_t *1827hb_font_get_face (hb_font_t *font)1828{1829return font->face;1830}183118321833/**1834* hb_font_set_funcs:1835* @font: #hb_font_t to work upon1836* @klass: (closure font_data) (destroy destroy) (scope notified): The font-functions structure.1837* @font_data: Data to attach to @font1838* @destroy: (nullable): The function to call when @font_data is not needed anymore1839*1840* Replaces the font-functions structure attached to a font, updating1841* the font's user-data with @font-data and the @destroy callback.1842*1843* Since: 0.9.21844**/1845void1846hb_font_set_funcs (hb_font_t *font,1847hb_font_funcs_t *klass,1848void *font_data,1849hb_destroy_func_t destroy /* May be NULL. */)1850{1851if (hb_object_is_immutable (font))1852{1853if (destroy)1854destroy (font_data);1855return;1856}18571858if (font->destroy)1859font->destroy (font->user_data);18601861if (!klass)1862klass = hb_font_funcs_get_empty ();18631864hb_font_funcs_reference (klass);1865hb_font_funcs_destroy (font->klass);1866font->klass = klass;1867font->user_data = font_data;1868font->destroy = destroy;1869}18701871/**1872* hb_font_set_funcs_data:1873* @font: #hb_font_t to work upon1874* @font_data: (destroy destroy) (scope notified): Data to attach to @font1875* @destroy: (nullable): The function to call when @font_data is not needed anymore1876*1877* Replaces the user data attached to a font, updating the font's1878* @destroy callback.1879*1880* Since: 0.9.21881**/1882void1883hb_font_set_funcs_data (hb_font_t *font,1884void *font_data,1885hb_destroy_func_t destroy /* May be NULL. */)1886{1887/* Destroy user_data? */1888if (hb_object_is_immutable (font))1889{1890if (destroy)1891destroy (font_data);1892return;1893}18941895if (font->destroy)1896font->destroy (font->user_data);18971898font->user_data = font_data;1899font->destroy = destroy;1900}190119021903/**1904* hb_font_set_scale:1905* @font: #hb_font_t to work upon1906* @x_scale: Horizontal scale value to assign1907* @y_scale: Vertical scale value to assign1908*1909* Sets the horizontal and vertical scale of a font.1910*1911* Since: 0.9.21912**/1913void1914hb_font_set_scale (hb_font_t *font,1915int x_scale,1916int y_scale)1917{1918if (hb_object_is_immutable (font))1919return;19201921font->x_scale = x_scale;1922font->y_scale = y_scale;1923font->mults_changed ();1924}19251926/**1927* hb_font_get_scale:1928* @font: #hb_font_t to work upon1929* @x_scale: (out): Horizontal scale value1930* @y_scale: (out): Vertical scale value1931*1932* Fetches the horizontal and vertical scale of a font.1933*1934* Since: 0.9.21935**/1936void1937hb_font_get_scale (hb_font_t *font,1938int *x_scale,1939int *y_scale)1940{1941if (x_scale) *x_scale = font->x_scale;1942if (y_scale) *y_scale = font->y_scale;1943}19441945/**1946* hb_font_set_ppem:1947* @font: #hb_font_t to work upon1948* @x_ppem: Horizontal ppem value to assign1949* @y_ppem: Vertical ppem value to assign1950*1951* Sets the horizontal and vertical pixels-per-em (ppem) of a font.1952*1953* Since: 0.9.21954**/1955void1956hb_font_set_ppem (hb_font_t *font,1957unsigned int x_ppem,1958unsigned int y_ppem)1959{1960if (hb_object_is_immutable (font))1961return;19621963font->x_ppem = x_ppem;1964font->y_ppem = y_ppem;1965}19661967/**1968* hb_font_get_ppem:1969* @font: #hb_font_t to work upon1970* @x_ppem: (out): Horizontal ppem value1971* @y_ppem: (out): Vertical ppem value1972*1973* Fetches the horizontal and vertical points-per-em (ppem) of a font.1974*1975* Since: 0.9.21976**/1977void1978hb_font_get_ppem (hb_font_t *font,1979unsigned int *x_ppem,1980unsigned int *y_ppem)1981{1982if (x_ppem) *x_ppem = font->x_ppem;1983if (y_ppem) *y_ppem = font->y_ppem;1984}19851986/**1987* hb_font_set_ptem:1988* @font: #hb_font_t to work upon1989* @ptem: font size in points.1990*1991* Sets the "point size" of a font. Set to zero to unset.1992* Used in CoreText to implement optical sizing.1993*1994* <note>Note: There are 72 points in an inch.</note>1995*1996* Since: 1.6.01997**/1998void1999hb_font_set_ptem (hb_font_t *font,2000float ptem)2001{2002if (hb_object_is_immutable (font))2003return;20042005font->ptem = ptem;2006}20072008/**2009* hb_font_get_ptem:2010* @font: #hb_font_t to work upon2011*2012* Fetches the "point size" of a font. Used in CoreText to2013* implement optical sizing.2014*2015* Return value: Point size. A value of zero means "not set."2016*2017* Since: 0.9.22018**/2019float2020hb_font_get_ptem (hb_font_t *font)2021{2022return font->ptem;2023}20242025#ifndef HB_NO_VAR2026/*2027* Variations2028*/20292030/**2031* hb_font_set_variations:2032* @font: #hb_font_t to work upon2033* @variations: (array length=variations_length): Array of variation settings to apply2034* @variations_length: Number of variations to apply2035*2036* Applies a list of font-variation settings to a font.2037*2038* Since: 1.4.22039*/2040void2041hb_font_set_variations (hb_font_t *font,2042const hb_variation_t *variations,2043unsigned int variations_length)2044{2045if (hb_object_is_immutable (font))2046return;20472048if (!variations_length)2049{2050hb_font_set_var_coords_normalized (font, nullptr, 0);2051return;2052}20532054unsigned int coords_length = hb_ot_var_get_axis_count (font->face);20552056int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;2057float *design_coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;20582059if (unlikely (coords_length && !(normalized && design_coords)))2060{2061free (normalized);2062free (design_coords);2063return;2064}20652066const OT::fvar &fvar = *font->face->table.fvar;2067for (unsigned int i = 0; i < variations_length; i++)2068{2069hb_ot_var_axis_info_t info;2070if (hb_ot_var_find_axis_info (font->face, variations[i].tag, &info) &&2071info.axis_index < coords_length)2072{2073float v = variations[i].value;2074design_coords[info.axis_index] = v;2075normalized[info.axis_index] = fvar.normalize_axis_value (info.axis_index, v);2076}2077}2078font->face->table.avar->map_coords (normalized, coords_length);20792080_hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);2081}20822083/**2084* hb_font_set_var_coords_design:2085* @font: #hb_font_t to work upon2086* @coords: (array length=coords_length): Array of variation coordinates to apply2087* @coords_length: Number of coordinates to apply2088*2089* Applies a list of variation coordinates (in design-space units)2090* to a font.2091*2092* Since: 1.4.22093*/2094void2095hb_font_set_var_coords_design (hb_font_t *font,2096const float *coords,2097unsigned int coords_length)2098{2099if (hb_object_is_immutable (font))2100return;21012102int *normalized = coords_length ? (int *) calloc (coords_length, sizeof (int)) : nullptr;2103float *design_coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;21042105if (unlikely (coords_length && !(normalized && design_coords)))2106{2107free (normalized);2108free (design_coords);2109return;2110}21112112if (coords_length)2113memcpy (design_coords, coords, coords_length * sizeof (font->design_coords[0]));21142115hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);2116_hb_font_adopt_var_coords (font, normalized, design_coords, coords_length);2117}21182119/**2120* hb_font_set_var_named_instance:2121* @font: a font.2122* @instance_index: named instance index.2123*2124* Sets design coords of a font from a named instance index.2125*2126* Since: 2.6.02127*/2128void2129hb_font_set_var_named_instance (hb_font_t *font,2130unsigned instance_index)2131{2132if (hb_object_is_immutable (font))2133return;21342135unsigned int coords_length = hb_ot_var_named_instance_get_design_coords (font->face, instance_index, nullptr, nullptr);21362137float *coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;2138if (unlikely (coords_length && !coords))2139return;21402141hb_ot_var_named_instance_get_design_coords (font->face, instance_index, &coords_length, coords);2142hb_font_set_var_coords_design (font, coords, coords_length);2143free (coords);2144}21452146/**2147* hb_font_set_var_coords_normalized:2148* @font: #hb_font_t to work upon2149* @coords: (array length=coords_length): Array of variation coordinates to apply2150* @coords_length: Number of coordinates to apply2151*2152* Applies a list of variation coordinates (in normalized units)2153* to a font.2154*2155* <note>Note: Coordinates should be normalized to 2.14.</note>2156*2157* Since: 1.4.22158*/2159void2160hb_font_set_var_coords_normalized (hb_font_t *font,2161const int *coords, /* 2.14 normalized */2162unsigned int coords_length)2163{2164if (hb_object_is_immutable (font))2165return;21662167int *copy = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;2168int *unmapped = coords_length ? (int *) calloc (coords_length, sizeof (coords[0])) : nullptr;2169float *design_coords = coords_length ? (float *) calloc (coords_length, sizeof (design_coords[0])) : nullptr;21702171if (unlikely (coords_length && !(copy && unmapped && design_coords)))2172{2173free (copy);2174free (unmapped);2175free (design_coords);2176return;2177}21782179if (coords_length)2180{2181memcpy (copy, coords, coords_length * sizeof (coords[0]));2182memcpy (unmapped, coords, coords_length * sizeof (coords[0]));2183}21842185/* Best effort design coords simulation */2186font->face->table.avar->unmap_coords (unmapped, coords_length);2187for (unsigned int i = 0; i < coords_length; ++i)2188design_coords[i] = font->face->table.fvar->unnormalize_axis_value (i, unmapped[i]);2189free (unmapped);21902191_hb_font_adopt_var_coords (font, copy, design_coords, coords_length);2192}21932194/**2195* hb_font_get_var_coords_normalized:2196* @font: #hb_font_t to work upon2197* @length: Number of coordinates retrieved2198*2199* Fetches the list of normalized variation coordinates currently2200* set on a font.2201*2202* Return value is valid as long as variation coordinates of the font2203* are not modified.2204*2205* Since: 1.4.22206*/2207const int *2208hb_font_get_var_coords_normalized (hb_font_t *font,2209unsigned int *length)2210{2211if (length)2212*length = font->num_coords;22132214return font->coords;2215}22162217#ifdef HB_EXPERIMENTAL_API2218/**2219* hb_font_get_var_coords_design:2220* @font: #hb_font_t to work upon2221* @length: (out): number of coordinates2222*2223* Return value is valid as long as variation coordinates of the font2224* are not modified.2225*2226* Return value: coordinates array2227*2228* Since: EXPERIMENTAL2229*/2230const float *2231hb_font_get_var_coords_design (hb_font_t *font,2232unsigned int *length)2233{2234if (length)2235*length = font->num_coords;22362237return font->design_coords;2238}2239#endif2240#endif22412242#ifndef HB_DISABLE_DEPRECATED2243/*2244* Deprecated get_glyph_func():2245*/22462247struct hb_trampoline_closure_t2248{2249void *user_data;2250hb_destroy_func_t destroy;2251unsigned int ref_count;2252};22532254template <typename FuncType>2255struct hb_trampoline_t2256{2257hb_trampoline_closure_t closure; /* Must be first. */2258FuncType func;2259};22602261template <typename FuncType>2262static hb_trampoline_t<FuncType> *2263trampoline_create (FuncType func,2264void *user_data,2265hb_destroy_func_t destroy)2266{2267typedef hb_trampoline_t<FuncType> trampoline_t;22682269trampoline_t *trampoline = (trampoline_t *) calloc (1, sizeof (trampoline_t));22702271if (unlikely (!trampoline))2272return nullptr;22732274trampoline->closure.user_data = user_data;2275trampoline->closure.destroy = destroy;2276trampoline->closure.ref_count = 1;2277trampoline->func = func;22782279return trampoline;2280}22812282static void2283trampoline_reference (hb_trampoline_closure_t *closure)2284{2285closure->ref_count++;2286}22872288static void2289trampoline_destroy (void *user_data)2290{2291hb_trampoline_closure_t *closure = (hb_trampoline_closure_t *) user_data;22922293if (--closure->ref_count)2294return;22952296if (closure->destroy)2297closure->destroy (closure->user_data);2298free (closure);2299}23002301typedef hb_trampoline_t<hb_font_get_glyph_func_t> hb_font_get_glyph_trampoline_t;23022303static hb_bool_t2304hb_font_get_nominal_glyph_trampoline (hb_font_t *font,2305void *font_data,2306hb_codepoint_t unicode,2307hb_codepoint_t *glyph,2308void *user_data)2309{2310hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;2311return trampoline->func (font, font_data, unicode, 0, glyph, trampoline->closure.user_data);2312}23132314static hb_bool_t2315hb_font_get_variation_glyph_trampoline (hb_font_t *font,2316void *font_data,2317hb_codepoint_t unicode,2318hb_codepoint_t variation_selector,2319hb_codepoint_t *glyph,2320void *user_data)2321{2322hb_font_get_glyph_trampoline_t *trampoline = (hb_font_get_glyph_trampoline_t *) user_data;2323return trampoline->func (font, font_data, unicode, variation_selector, glyph, trampoline->closure.user_data);2324}23252326/**2327* hb_font_funcs_set_glyph_func:2328* @ffuncs: The font-functions structure2329* @func: (closure user_data) (destroy destroy) (scope notified): callback function2330* @user_data: data to pass to @func2331* @destroy: (nullable): function to call when @user_data is not needed anymore2332*2333* Deprecated. Use hb_font_funcs_set_nominal_glyph_func() and2334* hb_font_funcs_set_variation_glyph_func() instead.2335*2336* Since: 0.9.22337* Deprecated: 1.2.32338**/2339void2340hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,2341hb_font_get_glyph_func_t func,2342void *user_data,2343hb_destroy_func_t destroy /* May be NULL. */)2344{2345if (hb_object_is_immutable (ffuncs))2346{2347if (destroy)2348destroy (user_data);2349return;2350}23512352hb_font_get_glyph_trampoline_t *trampoline;23532354trampoline = trampoline_create (func, user_data, destroy);2355if (unlikely (!trampoline))2356{2357if (destroy)2358destroy (user_data);2359return;2360}23612362hb_font_funcs_set_nominal_glyph_func (ffuncs,2363hb_font_get_nominal_glyph_trampoline,2364trampoline,2365trampoline_destroy);23662367trampoline_reference (&trampoline->closure);2368hb_font_funcs_set_variation_glyph_func (ffuncs,2369hb_font_get_variation_glyph_trampoline,2370trampoline,2371trampoline_destroy);2372}2373#endif237423752376