2020-08-11 11:10:23 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2019 Ebrahim Byagowi
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#ifndef HB_NO_STYLE
|
|
|
|
|
|
|
|
#include "hb-ot-var-avar-table.hh"
|
|
|
|
#include "hb-ot-var-fvar-table.hh"
|
|
|
|
#include "hb-ot-stat-table.hh"
|
|
|
|
#include "hb-ot-os2-table.hh"
|
|
|
|
#include "hb-ot-head-table.hh"
|
|
|
|
#include "hb-ot-post-table.hh"
|
|
|
|
#include "hb-ot-face.hh"
|
|
|
|
|
|
|
|
/**
|
2021-09-19 22:31:36 +02:00
|
|
|
* SECTION:hb-style
|
|
|
|
* @title: hb-style
|
|
|
|
* @short_description: Font Styles
|
|
|
|
* @include: hb.h
|
2020-08-11 11:10:23 +02:00
|
|
|
*
|
2021-09-19 22:31:36 +02:00
|
|
|
* Functions for fetching style information from fonts.
|
2020-08-11 11:10:23 +02:00
|
|
|
**/
|
|
|
|
|
2021-09-19 22:31:36 +02:00
|
|
|
static inline float
|
|
|
|
_hb_angle_to_ratio (float a)
|
|
|
|
{
|
2023-05-23 02:05:01 +02:00
|
|
|
return tanf (a * -HB_PI / 180.f);
|
2021-09-19 22:31:36 +02:00
|
|
|
}
|
2022-02-02 15:04:28 +01:00
|
|
|
|
2021-09-19 22:31:36 +02:00
|
|
|
static inline float
|
|
|
|
_hb_ratio_to_angle (float r)
|
|
|
|
{
|
2023-05-23 02:05:01 +02:00
|
|
|
return atanf (r) * -180.f / HB_PI;
|
2021-09-19 22:31:36 +02:00
|
|
|
}
|
2020-08-11 11:10:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hb_style_get_value:
|
|
|
|
* @font: a #hb_font_t object.
|
|
|
|
* @style_tag: a style tag.
|
|
|
|
*
|
2021-09-19 22:31:36 +02:00
|
|
|
* Searches variation axes of a #hb_font_t object for a specific axis first,
|
2020-08-11 11:10:23 +02:00
|
|
|
* if not set, then tries to get default style values from different
|
|
|
|
* tables of the font.
|
|
|
|
*
|
|
|
|
* Returns: Corresponding axis or default value to a style tag.
|
|
|
|
*
|
2021-09-19 22:31:36 +02:00
|
|
|
* Since: 3.0.0
|
2020-08-11 11:10:23 +02:00
|
|
|
**/
|
|
|
|
float
|
2021-09-19 22:31:36 +02:00
|
|
|
hb_style_get_value (hb_font_t *font, hb_style_tag_t style_tag)
|
2020-08-11 11:10:23 +02:00
|
|
|
{
|
2021-09-19 22:31:36 +02:00
|
|
|
if (unlikely (style_tag == HB_STYLE_TAG_SLANT_RATIO))
|
2022-03-02 09:48:37 +01:00
|
|
|
return _hb_angle_to_ratio (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE));
|
2021-09-19 22:31:36 +02:00
|
|
|
|
2020-08-11 11:10:23 +02:00
|
|
|
hb_face_t *face = font->face;
|
|
|
|
|
|
|
|
#ifndef HB_NO_VAR
|
|
|
|
hb_ot_var_axis_info_t axis;
|
|
|
|
if (hb_ot_var_find_axis_info (face, style_tag, &axis))
|
|
|
|
{
|
|
|
|
if (axis.axis_index < font->num_coords) return font->design_coords[axis.axis_index];
|
|
|
|
/* If a face is variable, fvar's default_value is better than STAT records */
|
|
|
|
return axis.default_value;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (style_tag == HB_STYLE_TAG_OPTICAL_SIZE && font->ptem)
|
|
|
|
return font->ptem;
|
|
|
|
|
|
|
|
/* STAT */
|
|
|
|
float value;
|
|
|
|
if (face->table.STAT->get_value (style_tag, &value))
|
|
|
|
return value;
|
|
|
|
|
|
|
|
switch ((unsigned) style_tag)
|
|
|
|
{
|
|
|
|
case HB_STYLE_TAG_ITALIC:
|
|
|
|
return face->table.OS2->is_italic () || face->table.head->is_italic () ? 1 : 0;
|
|
|
|
case HB_STYLE_TAG_OPTICAL_SIZE:
|
|
|
|
{
|
2021-09-19 22:31:36 +02:00
|
|
|
unsigned int lower, design, upper;
|
2020-08-11 11:10:23 +02:00
|
|
|
return face->table.OS2->v5 ().get_optical_size (&lower, &upper)
|
|
|
|
? (float) (lower + upper) / 2.f
|
2021-09-19 22:31:36 +02:00
|
|
|
: hb_ot_layout_get_size_params (face, &design, nullptr, nullptr, nullptr, nullptr)
|
|
|
|
? design / 10.f
|
2020-08-11 11:10:23 +02:00
|
|
|
: 12.f;
|
|
|
|
}
|
2021-09-19 22:31:36 +02:00
|
|
|
case HB_STYLE_TAG_SLANT_ANGLE:
|
2022-02-02 15:04:28 +01:00
|
|
|
{
|
|
|
|
float angle = face->table.post->table->italicAngle.to_float ();
|
|
|
|
|
|
|
|
if (font->slant)
|
|
|
|
angle = _hb_ratio_to_angle (font->slant + _hb_angle_to_ratio (angle));
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
2020-08-11 11:10:23 +02:00
|
|
|
case HB_STYLE_TAG_WIDTH:
|
|
|
|
return face->table.OS2->has_data ()
|
|
|
|
? face->table.OS2->get_width ()
|
2021-11-04 09:01:30 +01:00
|
|
|
: (face->table.head->is_condensed () ? 75 :
|
|
|
|
face->table.head->is_expanded () ? 125 :
|
|
|
|
100);
|
2020-08-11 11:10:23 +02:00
|
|
|
case HB_STYLE_TAG_WEIGHT:
|
|
|
|
return face->table.OS2->has_data ()
|
|
|
|
? face->table.OS2->usWeightClass
|
|
|
|
: (face->table.head->is_bold () ? 700 : 400);
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|