/** * SECTION:hb-ft * @title: hb-ft * @short_description: FreeType integration * @include: hb-ft.h * * Functions for using HarfBuzz with the FreeType library. * * HarfBuzz supports using FreeType to provide face and * font data. * * <note>Note that FreeType is not thread-safe, therefore these * functions are not thread-safe either.</note>
**/
/* TODO: * * In general, this file does a fine job of what it's supposed to do. * There are, however, things that need more work: * * - FreeType works in 26.6 mode. Clients can decide to use that mode, and everything * would work fine. However, we also abuse this API for performing in font-space, * but don't pass the correct flags to FreeType. We just abuse the no-hinting mode * for that, such that no rounding etc happens. As such, we don't set ppem, and * pass NO_HINTING as load_flags. Would be much better to use NO_SCALE, and scale * ourselves. * * - We don't handle / allow for emboldening / obliqueing. * * - In the future, we should add constructors to create fonts in font space?
*/
struct hb_ft_font_t
{ int load_flags; bool symbol; /* Whether selected cmap is symbol cmap. */ bool unref; /* Whether to destroy ft_face when done. */
/** * hb_ft_font_set_load_flags: * @font: #hb_font_t to work upon * @load_flags: The FreeType load flags to set * * Sets the FT_Load_Glyph load flags for the specified #hb_font_t. * * For more information, see * https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_load_xxx * * Since: 1.0.5
**/ void
hb_ft_font_set_load_flags (hb_font_t *font, int load_flags)
{ if (hb_object_is_immutable (font)) return;
if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return;
/** * hb_ft_font_get_load_flags: * @font: #hb_font_t to work upon * * Fetches the FT_Load_Glyph load flags of the specified #hb_font_t. * * For more information, see * https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_load_xxx * * Return value: FT_Load_Glyph flags found * * Since: 1.0.5
**/ int
hb_ft_font_get_load_flags (hb_font_t *font)
{ if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return 0;
/** * hb_ft_font_get_face: (skip) * @font: #hb_font_t to work upon * * Fetches the FT_Face associated with the specified #hb_font_t * font object. * * Return value: (nullable): the FT_Face found or %NULL * * Since: 0.9.2
**/
FT_Face
hb_ft_font_get_face (hb_font_t *font)
{ if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return nullptr;
/** * hb_ft_font_lock_face: (skip) * @font: #hb_font_t to work upon * * Gets the FT_Face associated with @font, This face will be kept around until * you call hb_ft_font_unlock_face(). * * Return value: (nullable): the FT_Face associated with @font or %NULL * Since: 2.6.5
**/
FT_Face
hb_ft_font_lock_face (hb_font_t *font)
{ if (unlikely (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)) return nullptr;
if (unlikely (!g))
{ if (unlikely (ft_font->symbol))
{ switch ((unsigned) font->face->table.OS2->get_font_page ()) { case OT::OS2::font_page_t::FONT_PAGE_NONE: if (unicode <= 0x00FFu) /* For symbol-encoded OpenType fonts, we duplicate the * U+F000..F0FF range at U+0000..U+00FF. That's what * Windows seems to do, and that's hinted about at: * https://docs.microsoft.com/en-us/typography/opentype/spec/recom
* under "Non-Standard (Symbol) Fonts". */
g = FT_Get_Char_Index (ft_font->ft_face, 0xF000u + unicode); break; #ifndef HB_NO_OT_SHAPER_ARABIC_FALLBACK case OT::OS2::font_page_t::FONT_PAGE_SIMP_ARABIC:
g = FT_Get_Char_Index (ft_font->ft_face, _hb_arabic_pua_simp_map (unicode)); break; case OT::OS2::font_page_t::FONT_PAGE_TRAD_ARABIC:
g = FT_Get_Char_Index (ft_font->ft_face, _hb_arabic_pua_trad_map (unicode)); break; #endif default: break;
} if (!g) returnfalse;
} else returnfalse;
}
*glyph = g; returntrue;
}
staticunsignedint
hb_ft_get_nominal_glyphs (hb_font_t *font HB_UNUSED, void *font_data, unsignedint count, const hb_codepoint_t *first_unicode, unsignedint unicode_stride,
hb_codepoint_t *first_glyph, unsignedint glyph_stride, void *user_data HB_UNUSED)
{ const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font_data;
hb_lock_t lock (ft_font->lock); unsignedint done; for (done = 0;
done < count && (*first_glyph = FT_Get_Char_Index (ft_font->ft_face, *first_unicode));
done++)
{
first_unicode = &StructAtOffsetUnaligned<hb_codepoint_t> (first_unicode, unicode_stride);
first_glyph = &StructAtOffsetUnaligned<hb_codepoint_t> (first_glyph, glyph_stride);
} /* We don't need to do ft_font->symbol dance here, since HB calls the singular
* nominal_glyph() for what we don't handle here. */ return done;
}
if (unlikely (FT_Load_Glyph (ft_face, glyph, ft_font->load_flags))) returnfalse;
/* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
* have a Y growing upward. Hence the extra negation. */
*x = ft_face->glyph->metrics.horiBearingX - ft_face->glyph->metrics.vertBearingX;
*y = ft_face->glyph->metrics.horiBearingY - (-ft_face->glyph->metrics.vertBearingY);
if (font->x_scale < 0)
*x = -*x; if (font->y_scale < 0)
*y = -*y;
if (*glyph == 0)
{ /* Check whether the given name was actually the name of glyph 0. */ char buf[128]; if (!FT_Get_Glyph_Name(ft_face, 0, buf, sizeof (buf)) &&
len < 0 ? !strcmp (buf, name) : !strncmp (buf, name, len)) returntrue;
}
/** * hb_ft_face_create: * @ft_face: (destroy destroy) (scope notified): FT_Face to work upon * @destroy: (nullable): A callback to call when the face object is not needed anymore * * Creates an #hb_face_t face object from the specified FT_Face. * * This variant of the function does not provide any life-cycle management. * * Most client programs should use hb_ft_face_create_referenced() * (or, perhaps, hb_ft_face_create_cached()) instead. * * If you know you have valid reasons not to use hb_ft_face_create_referenced(), * then it is the client program's responsibility to destroy @ft_face * after the #hb_face_t face object has been destroyed. * * Return value: (transfer full): the new #hb_face_t face object * * Since: 0.9.2
**/
hb_face_t *
hb_ft_face_create (FT_Face ft_face,
hb_destroy_func_t destroy)
{
hb_face_t *face;
/** * hb_ft_face_create_referenced: * @ft_face: FT_Face to work upon * * Creates an #hb_face_t face object from the specified FT_Face. * * This is the preferred variant of the hb_ft_face_create* * function family, because it calls FT_Reference_Face() on @ft_face, * ensuring that @ft_face remains alive as long as the resulting * #hb_face_t face object remains alive. Also calls FT_Done_Face() * when the #hb_face_t face object is destroyed. * * Use this version unless you know you have good reasons not to. * * Return value: (transfer full): the new #hb_face_t face object * * Since: 0.9.38
**/
hb_face_t *
hb_ft_face_create_referenced (FT_Face ft_face)
{
FT_Reference_Face (ft_face); return hb_ft_face_create (ft_face, _hb_ft_face_destroy);
}
/** * hb_ft_face_create_cached: * @ft_face: FT_Face to work upon * * Creates an #hb_face_t face object from the specified FT_Face. * * This variant of the function caches the newly created #hb_face_t * face object, using the @generic pointer of @ft_face. Subsequent function * calls that are passed the same @ft_face parameter will have the same * #hb_face_t returned to them, and that #hb_face_t will be correctly * reference counted. * * However, client programs are still responsible for destroying * @ft_face after the last #hb_face_t face object has been destroyed. * * Return value: (transfer full): the new #hb_face_t face object * * Since: 0.9.2
**/
hb_face_t *
hb_ft_face_create_cached (FT_Face ft_face)
{ if (unlikely (!ft_face->generic.data || ft_face->generic.finalizer != (FT_Generic_Finalizer) hb_ft_face_finalize))
{ if (ft_face->generic.finalizer)
ft_face->generic.finalizer (ft_face);
/** * hb_ft_font_create: * @ft_face: (destroy destroy) (scope notified): FT_Face to work upon * @destroy: (nullable): A callback to call when the font object is not needed anymore * * Creates an #hb_font_t font object from the specified FT_Face. * * <note>Note: You must set the face size on @ft_face before calling * hb_ft_font_create() on it. HarfBuzz assumes size is always set and will * access `size` member of FT_Face unconditionally.</note> * * This variant of the function does not provide any life-cycle management. * * Most client programs should use hb_ft_font_create_referenced() * instead. * * If you know you have valid reasons not to use hb_ft_font_create_referenced(), * then it is the client program's responsibility to destroy @ft_face * after the #hb_font_t font object has been destroyed. * * HarfBuzz will use the @destroy callback on the #hb_font_t font object * if it is supplied when you use this function. However, even if @destroy * is provided, it is the client program's responsibility to destroy @ft_face, * and it is the client program's responsibility to ensure that @ft_face is * destroyed only after the #hb_font_t font object has been destroyed. * * Return value: (transfer full): the new #hb_font_t font object * * Since: 0.9.2
**/
hb_font_t *
hb_ft_font_create (FT_Face ft_face,
hb_destroy_func_t destroy)
{
hb_font_t *font;
hb_face_t *face;
face = hb_ft_face_create (ft_face, destroy);
font = hb_font_create (face);
hb_face_destroy (face);
_hb_ft_font_set_funcs (font, ft_face, false);
hb_ft_font_changed (font); return font;
}
/** * hb_ft_font_changed: * @font: #hb_font_t to work upon * * Refreshes the state of @font when the underlying FT_Face has changed. * This function should be called after changing the size or * variation-axis settings on the FT_Face. * * Since: 1.0.5
**/ void
hb_ft_font_changed (hb_font_t *font)
{ if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy) return;
/** * hb_ft_hb_font_changed: * @font: #hb_font_t to work upon * * Refreshes the state of the underlying FT_Face of @font when the hb_font_t * @font has changed. * This function should be called after changing the size or * variation-axis settings on the @font. * This call is fast if nothing has changed on @font. * * Return value: true if changed, false otherwise * * Since: 4.4.0
**/
hb_bool_t
hb_ft_hb_font_changed (hb_font_t *font)
{ if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy) returnfalse;
/** * hb_ft_font_create_referenced: * @ft_face: FT_Face to work upon * * Creates an #hb_font_t font object from the specified FT_Face. * * <note>Note: You must set the face size on @ft_face before calling * hb_ft_font_create_referenced() on it. HarfBuzz assumes size is always set * and will access `size` member of FT_Face unconditionally.</note> * * This is the preferred variant of the hb_ft_font_create* * function family, because it calls FT_Reference_Face() on @ft_face, * ensuring that @ft_face remains alive as long as the resulting * #hb_font_t font object remains alive. * * Use this version unless you know you have good reasons not to. * * Return value: (transfer full): the new #hb_font_t font object * * Since: 0.9.38
**/
hb_font_t *
hb_ft_font_create_referenced (FT_Face ft_face)
{
FT_Reference_Face (ft_face); return hb_ft_font_create (ft_face, _hb_ft_face_destroy);
}
/** * hb_ft_font_set_funcs: * @font: #hb_font_t to work upon * * Configures the font-functions structure of the specified * #hb_font_t font object to use FreeType font functions. * * In particular, you can use this function to configure an * existing #hb_face_t face object for use with FreeType font * functions even if that #hb_face_t face object was initially * created with hb_face_create(), and therefore was not * initially configured to use FreeType font functions. * * An #hb_face_t face object created with hb_ft_face_create() * is preconfigured for FreeType font functions and does not * require this function to be used. * * <note>Note: Internally, this function creates an FT_Face. * </note> * * Since: 1.0.5
**/ void
hb_ft_font_set_funcs (hb_font_t *font)
{
hb_blob_t *blob = hb_face_reference_blob (font->face); unsignedint blob_length; constchar *blob_data = hb_blob_get_data (blob, &blob_length); if (unlikely (!blob_length))
DEBUG_MSG (FT, font, "Font face has empty blob");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.