2018-11-20 20:56:46 +01:00
|
|
|
/*
|
2019-07-21 10:08:04 +02:00
|
|
|
* Copyright © 2018-2019 Ebrahim Byagowi
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hb.hh"
|
|
|
|
|
|
|
|
#include "hb-ot-var-mvar-table.hh"
|
2019-07-20 11:30:20 +02:00
|
|
|
#include "hb-ot-gasp-table.hh" // Just so we compile it; unused otherwise.
|
|
|
|
#include "hb-ot-os2-table.hh"
|
|
|
|
#include "hb-ot-post-table.hh"
|
2019-07-20 12:03:57 +02:00
|
|
|
#include "hb-ot-hhea-table.hh"
|
2019-07-20 11:30:20 +02:00
|
|
|
#include "hb-ot-metrics.hh"
|
2018-11-20 20:56:46 +01:00
|
|
|
#include "hb-ot-face.hh"
|
|
|
|
|
2019-07-20 12:31:37 +02:00
|
|
|
|
2020-12-22 23:45:39 +01:00
|
|
|
/**
|
|
|
|
* SECTION:hb-ot-metrics
|
|
|
|
* @title: hb-ot-metrics
|
|
|
|
* @short_description: OpenType Metrics
|
|
|
|
* @include: hb-ot.h
|
|
|
|
*
|
|
|
|
* Functions for fetching metrics from fonts.
|
|
|
|
**/
|
|
|
|
|
2019-07-20 12:31:37 +02:00
|
|
|
static float
|
2019-07-29 19:33:56 +02:00
|
|
|
_fix_ascender_descender (float value, hb_ot_metrics_tag_t metrics_tag)
|
2019-07-20 12:31:37 +02:00
|
|
|
{
|
2019-07-30 01:13:15 +02:00
|
|
|
if (metrics_tag == HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER ||
|
|
|
|
metrics_tag == HB_OT_METRICS_TAG_VERTICAL_ASCENDER)
|
2019-07-20 12:31:37 +02:00
|
|
|
return fabs ((double) value);
|
2019-07-30 01:13:15 +02:00
|
|
|
if (metrics_tag == HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER ||
|
|
|
|
metrics_tag == HB_OT_METRICS_TAG_VERTICAL_DESCENDER)
|
2019-07-20 12:31:37 +02:00
|
|
|
return -fabs ((double) value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-07-21 10:08:04 +02:00
|
|
|
/* The common part of _get_position logic needed on hb-ot-font and here
|
|
|
|
to be able to have slim builds without the not always needed parts */
|
2019-07-20 12:20:31 +02:00
|
|
|
bool
|
2019-07-29 19:33:56 +02:00
|
|
|
_hb_ot_metrics_get_position_common (hb_font_t *font,
|
|
|
|
hb_ot_metrics_tag_t metrics_tag,
|
|
|
|
hb_position_t *position /* OUT. May be NULL. */)
|
2019-07-20 12:20:31 +02:00
|
|
|
{
|
|
|
|
hb_face_t *face = font->face;
|
2019-07-25 12:19:02 +02:00
|
|
|
switch ((unsigned) metrics_tag)
|
2019-07-20 12:20:31 +02:00
|
|
|
{
|
|
|
|
#ifndef HB_NO_VAR
|
2019-07-22 16:05:55 +02:00
|
|
|
#define GET_VAR face->table.MVAR->get_var (metrics_tag, font->coords, font->num_coords)
|
2019-07-20 12:20:31 +02:00
|
|
|
#else
|
2019-07-20 12:31:37 +02:00
|
|
|
#define GET_VAR .0f
|
2019-07-20 12:20:31 +02:00
|
|
|
#endif
|
|
|
|
#define GET_METRIC_X(TABLE, ATTR) \
|
|
|
|
(face->table.TABLE->has_data () && \
|
2022-07-13 18:36:53 +02:00
|
|
|
((void) (position && (*position = font->em_scalef_x (_fix_ascender_descender ( \
|
|
|
|
face->table.TABLE->ATTR + GET_VAR, metrics_tag)))), true))
|
2019-07-20 12:20:31 +02:00
|
|
|
#define GET_METRIC_Y(TABLE, ATTR) \
|
|
|
|
(face->table.TABLE->has_data () && \
|
2022-07-13 18:36:53 +02:00
|
|
|
((void) (position && (*position = font->em_scalef_y (_fix_ascender_descender ( \
|
|
|
|
face->table.TABLE->ATTR + GET_VAR, metrics_tag)))), true))
|
2021-12-08 17:32:41 +01:00
|
|
|
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER:
|
2019-07-20 20:33:51 +02:00
|
|
|
return (face->table.OS2->use_typo_metrics () && GET_METRIC_Y (OS2, sTypoAscender)) ||
|
|
|
|
GET_METRIC_Y (hhea, ascender);
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER:
|
2019-07-20 20:33:51 +02:00
|
|
|
return (face->table.OS2->use_typo_metrics () && GET_METRIC_Y (OS2, sTypoDescender)) ||
|
|
|
|
GET_METRIC_Y (hhea, descender);
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP:
|
2019-07-20 20:33:51 +02:00
|
|
|
return (face->table.OS2->use_typo_metrics () && GET_METRIC_Y (OS2, sTypoLineGap)) ||
|
|
|
|
GET_METRIC_Y (hhea, lineGap);
|
2021-12-08 17:32:41 +01:00
|
|
|
|
|
|
|
#ifndef HB_NO_VERTICAL
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_ASCENDER: return GET_METRIC_X (vhea, ascender);
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_DESCENDER: return GET_METRIC_X (vhea, descender);
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_LINE_GAP: return GET_METRIC_X (vhea, lineGap);
|
2021-12-08 17:32:41 +01:00
|
|
|
#endif
|
|
|
|
|
2019-07-20 12:20:31 +02:00
|
|
|
#undef GET_METRIC_Y
|
|
|
|
#undef GET_METRIC_X
|
|
|
|
#undef GET_VAR
|
|
|
|
default: assert (0); return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HB_NO_METRICS
|
|
|
|
|
2019-07-20 11:30:20 +02:00
|
|
|
#if 0
|
|
|
|
static bool
|
2019-07-29 19:33:56 +02:00
|
|
|
_get_gasp (hb_face_t *face, float *result, hb_ot_metrics_tag_t metrics_tag)
|
2019-07-20 11:30:20 +02:00
|
|
|
{
|
|
|
|
const OT::GaspRange& range = face->table.gasp->get_gasp_range (metrics_tag - HB_TAG ('g','s','p','0'));
|
|
|
|
if (&range == &Null (OT::GaspRange)) return false;
|
2019-07-22 16:05:55 +02:00
|
|
|
if (result) *result = range.rangeMaxPPEM + font->face->table.MVAR->get_var (metrics_tag, font->coords, font->num_coords);
|
2019-07-20 11:30:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-26 14:16:04 +02:00
|
|
|
/* Private tags for https://github.com/harfbuzz/harfbuzz/issues/1866 */
|
2019-07-30 01:13:15 +02:00
|
|
|
#define _HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER_OS2 HB_TAG ('O','a','s','c')
|
|
|
|
#define _HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER_HHEA HB_TAG ('H','a','s','c')
|
|
|
|
#define _HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER_OS2 HB_TAG ('O','d','s','c')
|
|
|
|
#define _HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER_HHEA HB_TAG ('H','d','s','c')
|
|
|
|
#define _HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP_OS2 HB_TAG ('O','l','g','p')
|
|
|
|
#define _HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP_HHEA HB_TAG ('H','l','g','p')
|
2019-07-26 14:16:04 +02:00
|
|
|
|
2018-11-20 20:56:46 +01:00
|
|
|
/**
|
|
|
|
* hb_ot_metrics_get_position:
|
2020-12-30 22:40:25 +01:00
|
|
|
* @font: an #hb_font_t object.
|
2019-07-20 11:38:11 +02:00
|
|
|
* @metrics_tag: tag of metrics value you like to fetch.
|
|
|
|
* @position: (out) (optional): result of metrics value from the font.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2020-12-30 22:40:25 +01:00
|
|
|
* Fetches metrics value corresponding to @metrics_tag from @font.
|
2019-07-20 12:03:57 +02:00
|
|
|
*
|
2019-07-20 11:38:11 +02:00
|
|
|
* Returns: Whether found the requested metrics in the font.
|
2019-08-14 07:20:54 +02:00
|
|
|
* Since: 2.6.0
|
2018-11-20 20:56:46 +01:00
|
|
|
**/
|
|
|
|
hb_bool_t
|
2019-07-29 19:33:56 +02:00
|
|
|
hb_ot_metrics_get_position (hb_font_t *font,
|
|
|
|
hb_ot_metrics_tag_t metrics_tag,
|
|
|
|
hb_position_t *position /* OUT. May be NULL. */)
|
2018-11-20 20:56:46 +01:00
|
|
|
{
|
2019-07-20 12:03:57 +02:00
|
|
|
hb_face_t *face = font->face;
|
2019-07-25 12:19:02 +02:00
|
|
|
switch ((unsigned) metrics_tag)
|
2018-11-20 20:56:46 +01:00
|
|
|
{
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER:
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER:
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP:
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_ASCENDER:
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_DESCENDER:
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_LINE_GAP: return _hb_ot_metrics_get_position_common (font, metrics_tag, position);
|
2019-07-20 12:03:57 +02:00
|
|
|
#ifndef HB_NO_VAR
|
2019-07-22 16:05:55 +02:00
|
|
|
#define GET_VAR hb_ot_metrics_get_variation (font, metrics_tag)
|
2019-07-20 12:03:57 +02:00
|
|
|
#else
|
|
|
|
#define GET_VAR 0
|
|
|
|
#endif
|
|
|
|
#define GET_METRIC_X(TABLE, ATTR) \
|
|
|
|
(face->table.TABLE->has_data () && \
|
2022-07-13 18:36:53 +02:00
|
|
|
((void) (position && (*position = font->em_scalef_x (face->table.TABLE->ATTR + GET_VAR))), true))
|
2019-07-20 12:03:57 +02:00
|
|
|
#define GET_METRIC_Y(TABLE, ATTR) \
|
|
|
|
(face->table.TABLE->has_data () && \
|
2022-07-13 18:36:53 +02:00
|
|
|
((void) (position && (*position = font->em_scalef_y (face->table.TABLE->ATTR + GET_VAR))), true))
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_ASCENT: return GET_METRIC_Y (OS2, usWinAscent);
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_DESCENT: return GET_METRIC_Y (OS2, usWinDescent);
|
2022-01-02 18:41:41 +01:00
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE:
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN:
|
|
|
|
{
|
2022-01-02 19:16:33 +01:00
|
|
|
unsigned mult = 1u;
|
|
|
|
|
|
|
|
if (font->slant)
|
|
|
|
{
|
|
|
|
unsigned rise = face->table.hhea->caretSlopeRise;
|
|
|
|
unsigned upem = face->get_upem ();
|
|
|
|
mult = (rise && rise < upem) ? hb_min (upem / rise, 256u) : 1u;
|
|
|
|
}
|
2022-01-02 18:46:38 +01:00
|
|
|
|
2022-01-02 18:41:41 +01:00
|
|
|
if (metrics_tag == HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE)
|
2022-01-02 19:26:45 +01:00
|
|
|
{
|
|
|
|
bool ret = GET_METRIC_Y (hhea, caretSlopeRise);
|
|
|
|
|
|
|
|
if (position)
|
|
|
|
*position *= mult;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2022-01-02 18:41:41 +01:00
|
|
|
else
|
2022-01-02 18:46:38 +01:00
|
|
|
{
|
2022-01-02 19:26:45 +01:00
|
|
|
hb_position_t rise = 0;
|
|
|
|
|
|
|
|
if (font->slant && position && GET_METRIC_Y (hhea, caretSlopeRise))
|
|
|
|
rise = *position;
|
|
|
|
|
|
|
|
bool ret = GET_METRIC_X (hhea, caretSlopeRun);
|
|
|
|
|
|
|
|
if (position)
|
|
|
|
{
|
|
|
|
*position *= mult;
|
2022-01-02 18:46:38 +01:00
|
|
|
|
2022-01-02 19:26:45 +01:00
|
|
|
if (font->slant)
|
2022-01-02 19:56:45 +01:00
|
|
|
*position += _hb_roundf (mult * font->slant_xy * rise);
|
2022-01-02 19:26:45 +01:00
|
|
|
}
|
2022-01-02 18:46:38 +01:00
|
|
|
|
2022-01-02 19:26:45 +01:00
|
|
|
return ret;
|
2022-01-02 18:46:38 +01:00
|
|
|
}
|
2022-01-02 18:41:41 +01:00
|
|
|
}
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET: return GET_METRIC_X (hhea, caretOffset);
|
2022-01-02 18:41:41 +01:00
|
|
|
|
2021-12-08 19:40:40 +01:00
|
|
|
#ifndef HB_NO_VERTICAL
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_CARET_RISE: return GET_METRIC_X (vhea, caretSlopeRise);
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_CARET_RUN: return GET_METRIC_Y (vhea, caretSlopeRun);
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET: return GET_METRIC_Y (vhea, caretOffset);
|
2021-12-08 19:40:40 +01:00
|
|
|
#endif
|
2019-07-30 01:13:15 +02:00
|
|
|
case HB_OT_METRICS_TAG_X_HEIGHT: return GET_METRIC_Y (OS2->v2 (), sxHeight);
|
|
|
|
case HB_OT_METRICS_TAG_CAP_HEIGHT: return GET_METRIC_Y (OS2->v2 (), sCapHeight);
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_X_SIZE: return GET_METRIC_X (OS2, ySubscriptXSize);
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_Y_SIZE: return GET_METRIC_Y (OS2, ySubscriptYSize);
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_X_OFFSET: return GET_METRIC_X (OS2, ySubscriptXOffset);
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_Y_OFFSET: return GET_METRIC_Y (OS2, ySubscriptYOffset);
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_SIZE: return GET_METRIC_X (OS2, ySuperscriptXSize);
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_Y_SIZE: return GET_METRIC_Y (OS2, ySuperscriptYSize);
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET: return GET_METRIC_X (OS2, ySuperscriptXOffset);
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_Y_OFFSET: return GET_METRIC_Y (OS2, ySuperscriptYOffset);
|
|
|
|
case HB_OT_METRICS_TAG_STRIKEOUT_SIZE: return GET_METRIC_Y (OS2, yStrikeoutSize);
|
|
|
|
case HB_OT_METRICS_TAG_STRIKEOUT_OFFSET: return GET_METRIC_Y (OS2, yStrikeoutPosition);
|
|
|
|
case HB_OT_METRICS_TAG_UNDERLINE_SIZE: return GET_METRIC_Y (post->table, underlineThickness);
|
|
|
|
case HB_OT_METRICS_TAG_UNDERLINE_OFFSET: return GET_METRIC_Y (post->table, underlinePosition);
|
2019-07-26 14:16:04 +02:00
|
|
|
|
|
|
|
/* Private tags */
|
2019-07-30 01:13:15 +02:00
|
|
|
case _HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER_OS2: return GET_METRIC_Y (OS2, sTypoAscender);
|
|
|
|
case _HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER_HHEA: return GET_METRIC_Y (hhea, ascender);
|
|
|
|
case _HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER_OS2: return GET_METRIC_Y (OS2, sTypoDescender);
|
|
|
|
case _HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER_HHEA: return GET_METRIC_Y (hhea, descender);
|
|
|
|
case _HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP_OS2: return GET_METRIC_Y (OS2, sTypoLineGap);
|
|
|
|
case _HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP_HHEA: return GET_METRIC_Y (hhea, lineGap);
|
2019-07-20 12:03:57 +02:00
|
|
|
#undef GET_METRIC_Y
|
|
|
|
#undef GET_METRIC_X
|
|
|
|
#undef GET_VAR
|
|
|
|
default: return false;
|
2018-11-20 20:56:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 00:17:09 +01:00
|
|
|
/**
|
|
|
|
* hb_ot_metrics_get_position_with_fallback:
|
|
|
|
* @font: an #hb_font_t object.
|
|
|
|
* @metrics_tag: tag of metrics value you like to fetch.
|
|
|
|
* @position: (out) (optional): result of metrics value from the font.
|
|
|
|
*
|
|
|
|
* Fetches metrics value corresponding to @metrics_tag from @font,
|
|
|
|
* and synthesizes a value if it the value is missing in the font.
|
|
|
|
*
|
2022-03-01 20:27:32 +01:00
|
|
|
* Since: 4.0.0
|
2022-02-16 00:17:09 +01:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
hb_ot_metrics_get_position_with_fallback (hb_font_t *font,
|
|
|
|
hb_ot_metrics_tag_t metrics_tag,
|
|
|
|
hb_position_t *position /* OUT */)
|
|
|
|
{
|
|
|
|
hb_font_extents_t font_extents;
|
|
|
|
hb_codepoint_t glyph;
|
|
|
|
hb_glyph_extents_t extents;
|
|
|
|
|
|
|
|
if (hb_ot_metrics_get_position (font, metrics_tag, position))
|
|
|
|
{
|
|
|
|
if ((metrics_tag != HB_OT_METRICS_TAG_STRIKEOUT_SIZE &&
|
|
|
|
metrics_tag != HB_OT_METRICS_TAG_UNDERLINE_SIZE) ||
|
|
|
|
*position != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (metrics_tag)
|
|
|
|
{
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER:
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_ASCENT:
|
|
|
|
hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
|
|
|
|
*position = font_extents.ascender;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_ASCENDER:
|
|
|
|
hb_font_get_extents_for_direction (font, HB_DIRECTION_TTB, &font_extents);
|
|
|
|
*position = font_extents.ascender;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_DESCENDER:
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CLIPPING_DESCENT:
|
|
|
|
hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
|
|
|
|
*position = font_extents.descender;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_DESCENDER:
|
|
|
|
hb_font_get_extents_for_direction (font, HB_DIRECTION_TTB, &font_extents);
|
|
|
|
*position = font_extents.ascender;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_LINE_GAP:
|
|
|
|
hb_font_get_extents_for_direction (font, HB_DIRECTION_LTR, &font_extents);
|
|
|
|
*position = font_extents.line_gap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_LINE_GAP:
|
|
|
|
hb_font_get_extents_for_direction (font, HB_DIRECTION_TTB, &font_extents);
|
|
|
|
*position = font_extents.line_gap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CARET_RISE:
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_CARET_RISE:
|
|
|
|
*position = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CARET_RUN:
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_CARET_RUN:
|
|
|
|
*position = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_HORIZONTAL_CARET_OFFSET:
|
|
|
|
case HB_OT_METRICS_TAG_VERTICAL_CARET_OFFSET:
|
|
|
|
*position = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_X_HEIGHT:
|
2022-03-15 17:45:50 +01:00
|
|
|
if (hb_font_get_nominal_glyph (font, 'x', &glyph) &&
|
2022-02-16 00:17:09 +01:00
|
|
|
hb_font_get_glyph_extents (font, glyph, &extents))
|
2022-03-15 17:45:50 +01:00
|
|
|
*position = extents.y_bearing;
|
2022-02-16 00:17:09 +01:00
|
|
|
else
|
|
|
|
*position = font->y_scale / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_CAP_HEIGHT:
|
|
|
|
if (hb_font_get_nominal_glyph (font, 'O', &glyph) &&
|
|
|
|
hb_font_get_glyph_extents (font, glyph, &extents))
|
|
|
|
*position = extents.height + 2 * extents.y_bearing;
|
|
|
|
else
|
|
|
|
*position = font->y_scale * 2 / 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_STRIKEOUT_SIZE:
|
|
|
|
case HB_OT_METRICS_TAG_UNDERLINE_SIZE:
|
|
|
|
*position = font->y_scale / 18;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_STRIKEOUT_OFFSET:
|
|
|
|
{
|
|
|
|
hb_position_t ascender;
|
|
|
|
hb_ot_metrics_get_position_with_fallback (font,
|
|
|
|
HB_OT_METRICS_TAG_HORIZONTAL_ASCENDER,
|
|
|
|
&ascender);
|
|
|
|
*position = ascender / 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_UNDERLINE_OFFSET:
|
|
|
|
*position = - font->y_scale / 18;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_X_SIZE:
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_SIZE:
|
|
|
|
*position = font->x_scale * 10 / 12;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_Y_SIZE:
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_Y_SIZE:
|
|
|
|
*position = font->y_scale * 10 / 12;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_X_OFFSET:
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_X_OFFSET:
|
|
|
|
*position = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_OT_METRICS_TAG_SUBSCRIPT_EM_Y_OFFSET:
|
|
|
|
case HB_OT_METRICS_TAG_SUPERSCRIPT_EM_Y_OFFSET:
|
|
|
|
*position = font->y_scale / 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _HB_OT_METRICS_TAG_MAX_VALUE:
|
|
|
|
default:
|
|
|
|
*position = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:11:07 +02:00
|
|
|
#ifndef HB_NO_VAR
|
2018-11-20 20:56:46 +01:00
|
|
|
/**
|
|
|
|
* hb_ot_metrics_get_variation:
|
2020-12-30 22:40:25 +01:00
|
|
|
* @font: an #hb_font_t object.
|
|
|
|
* @metrics_tag: tag of metrics value you like to fetch.
|
|
|
|
*
|
|
|
|
* Fetches metrics value corresponding to @metrics_tag from @font with the
|
|
|
|
* current font variation settings applied.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2020-12-30 22:40:25 +01:00
|
|
|
* Returns: The requested metric value.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2019-08-14 07:20:54 +02:00
|
|
|
* Since: 2.6.0
|
2018-11-20 20:56:46 +01:00
|
|
|
**/
|
|
|
|
float
|
2019-07-29 19:33:56 +02:00
|
|
|
hb_ot_metrics_get_variation (hb_font_t *font, hb_ot_metrics_tag_t metrics_tag)
|
2018-11-20 20:56:46 +01:00
|
|
|
{
|
2019-07-22 16:05:55 +02:00
|
|
|
return font->face->table.MVAR->get_var (metrics_tag, font->coords, font->num_coords);
|
2018-11-20 20:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_metrics_get_x_variation:
|
2020-12-30 22:40:25 +01:00
|
|
|
* @font: an #hb_font_t object.
|
|
|
|
* @metrics_tag: tag of metrics value you like to fetch.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2020-12-30 22:40:25 +01:00
|
|
|
* Fetches horizontal metrics value corresponding to @metrics_tag from @font
|
|
|
|
* with the current font variation settings applied.
|
|
|
|
*
|
|
|
|
* Returns: The requested metric value.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2019-08-14 07:20:54 +02:00
|
|
|
* Since: 2.6.0
|
2018-11-20 20:56:46 +01:00
|
|
|
**/
|
|
|
|
hb_position_t
|
2019-07-29 19:33:56 +02:00
|
|
|
hb_ot_metrics_get_x_variation (hb_font_t *font, hb_ot_metrics_tag_t metrics_tag)
|
2018-11-20 20:56:46 +01:00
|
|
|
{
|
2019-07-22 16:05:55 +02:00
|
|
|
return font->em_scalef_x (hb_ot_metrics_get_variation (font, metrics_tag));
|
2018-11-20 20:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_ot_metrics_get_y_variation:
|
2020-12-30 22:40:25 +01:00
|
|
|
* @font: an #hb_font_t object.
|
|
|
|
* @metrics_tag: tag of metrics value you like to fetch.
|
|
|
|
*
|
|
|
|
* Fetches vertical metrics value corresponding to @metrics_tag from @font with
|
|
|
|
* the current font variation settings applied.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2020-12-30 22:40:25 +01:00
|
|
|
* Returns: The requested metric value.
|
2018-11-20 20:56:46 +01:00
|
|
|
*
|
2019-08-14 07:20:54 +02:00
|
|
|
* Since: 2.6.0
|
2018-11-20 20:56:46 +01:00
|
|
|
**/
|
|
|
|
hb_position_t
|
2019-07-29 19:33:56 +02:00
|
|
|
hb_ot_metrics_get_y_variation (hb_font_t *font, hb_ot_metrics_tag_t metrics_tag)
|
2018-11-20 20:56:46 +01:00
|
|
|
{
|
2019-07-22 16:05:55 +02:00
|
|
|
return font->em_scalef_y (hb_ot_metrics_get_variation (font, metrics_tag));
|
2018-11-20 20:56:46 +01:00
|
|
|
}
|
2019-07-19 09:11:07 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|