Blame src/hb-ot-math.cc

Packit Service 5bcba8
/*
Packit Service 5bcba8
 * Copyright © 2016  Igalia S.L.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 *  This is part of HarfBuzz, a text shaping library.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Permission is hereby granted, without written agreement and without
Packit Service 5bcba8
 * license or royalty fees, to use, copy, modify, and distribute this
Packit Service 5bcba8
 * software and its documentation for any purpose, provided that the
Packit Service 5bcba8
 * above copyright notice and the following two paragraphs appear in
Packit Service 5bcba8
 * all copies of this software.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
Packit Service 5bcba8
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
Packit Service 5bcba8
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
Packit Service 5bcba8
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
Packit Service 5bcba8
 * DAMAGE.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
Packit Service 5bcba8
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
Packit Service 5bcba8
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
Packit Service 5bcba8
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
Packit Service 5bcba8
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Igalia Author(s): Frédéric Wang
Packit Service 5bcba8
 */
Packit Service 5bcba8
Packit Service 5bcba8
#include "hb-open-type-private.hh"
Packit Service 5bcba8
Packit Service 5bcba8
#include "hb-ot-layout-private.hh"
Packit Service 5bcba8
#include "hb-ot-math-table.hh"
Packit Service 5bcba8
Packit Service 5bcba8
static inline const OT::MATH&
Packit Service 5bcba8
_get_math (hb_face_t *face)
Packit Service 5bcba8
{
Packit Service 5bcba8
  if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::MATH);
Packit Service 5bcba8
  hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
Packit Service 5bcba8
  return *(layout->math.get ());
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/*
Packit Service 5bcba8
 * OT::MATH
Packit Service 5bcba8
 */
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_has_data:
Packit Service 5bcba8
 * @face: #hb_face_t to test
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * This function allows to verify the presence of an OpenType MATH table on the
Packit Service 5bcba8
 * face.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: true if face has a MATH table, false otherwise
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_bool_t
Packit Service 5bcba8
hb_ot_math_has_data (hb_face_t *face)
Packit Service 5bcba8
{
Packit Service 5bcba8
  return &_get_math (face) != &OT::Null(OT::MATH);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_constant:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the value
Packit Service 5bcba8
 * @constant: #hb_ot_math_constant_t the constant to retrieve
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * This function returns the requested math constants as a #hb_position_t.
Packit Service 5bcba8
 * If the request constant is HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN,
Packit Service 5bcba8
 * HB_OT_MATH_CONSTANT_SCRIPT_SCRIPT_PERCENT_SCALE_DOWN or
Packit Service 5bcba8
 * HB_OT_MATH_CONSTANT_SCRIPT_PERCENT_SCALE_DOWN then the return value is
Packit Service 5bcba8
 * actually an integer between 0 and 100 representing that percentage.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: the requested constant or 0
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_position_t
Packit Service 5bcba8
hb_ot_math_get_constant (hb_font_t *font,
Packit Service 5bcba8
			 hb_ot_math_constant_t constant)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_constant(constant, font);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_glyph_italics_correction:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the value
Packit Service 5bcba8
 * @glyph: glyph index from which to retrieve the value
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: the italics correction of the glyph or 0
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_position_t
Packit Service 5bcba8
hb_ot_math_get_glyph_italics_correction (hb_font_t *font,
Packit Service 5bcba8
					 hb_codepoint_t glyph)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_math_glyph_info().get_italics_correction (glyph, font);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_glyph_top_accent_attachment:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the value
Packit Service 5bcba8
 * @glyph: glyph index from which to retrieve the value
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: the top accent attachment of the glyph or 0
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_position_t
Packit Service 5bcba8
hb_ot_math_get_glyph_top_accent_attachment (hb_font_t *font,
Packit Service 5bcba8
					    hb_codepoint_t glyph)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_math_glyph_info().get_top_accent_attachment (glyph, font);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_is_glyph_extended_shape:
Packit Service 5bcba8
 * @face: a #hb_face_t to test
Packit Service 5bcba8
 * @glyph: a glyph index to test
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: true if the glyph is an extended shape, false otherwise
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_bool_t
Packit Service 5bcba8
hb_ot_math_is_glyph_extended_shape (hb_face_t *face,
Packit Service 5bcba8
				    hb_codepoint_t glyph)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (face);
Packit Service 5bcba8
  return math.get_math_glyph_info().is_extended_shape (glyph);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_glyph_kerning:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the value
Packit Service 5bcba8
 * @glyph: glyph index from which to retrieve the value
Packit Service 5bcba8
 * @kern: the #hb_ot_math_kern_t from which to retrieve the value
Packit Service 5bcba8
 * @correction_height: the correction height to use to determine the kerning.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * This function tries to retrieve the MathKern table for the specified font,
Packit Service 5bcba8
 * glyph and #hb_ot_math_kern_t. Then it browses the list of heights from the
Packit Service 5bcba8
 * MathKern table to find one value that is greater or equal to specified
Packit Service 5bcba8
 * correction_height. If one is found the corresponding value from the list of
Packit Service 5bcba8
 * kerns is returned and otherwise the last kern value is returned.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: requested kerning or 0
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_position_t
Packit Service 5bcba8
hb_ot_math_get_glyph_kerning (hb_font_t *font,
Packit Service 5bcba8
			      hb_codepoint_t glyph,
Packit Service 5bcba8
			      hb_ot_math_kern_t kern,
Packit Service 5bcba8
			      hb_position_t correction_height)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_math_glyph_info().get_kerning (glyph, kern, correction_height, font);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_glyph_variants:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the values
Packit Service 5bcba8
 * @glyph: index of the glyph to stretch
Packit Service 5bcba8
 * @direction: direction of the stretching
Packit Service 5bcba8
 * @start_offset: offset of the first variant to retrieve
Packit Service 5bcba8
 * @variants_count: maximum number of variants to retrieve after start_offset
Packit Service 5bcba8
 * (IN) and actual number of variants retrieved (OUT)
Packit Service 5bcba8
 * @variants: array of size at least @variants_count to store the result
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * This function tries to retrieve the MathGlyphConstruction for the specified
Packit Service 5bcba8
 * font, glyph and direction. Note that only the value of
Packit Service 5bcba8
 * #HB_DIRECTION_IS_HORIZONTAL is considered. It provides the corresponding list
Packit Service 5bcba8
 * of size variants as an array of hb_ot_math_glyph_variant_t structs.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: the total number of size variants available or 0
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
unsigned int
Packit Service 5bcba8
hb_ot_math_get_glyph_variants (hb_font_t *font,
Packit Service 5bcba8
			       hb_codepoint_t glyph,
Packit Service 5bcba8
			       hb_direction_t direction,
Packit Service 5bcba8
			       unsigned int start_offset,
Packit Service 5bcba8
			       unsigned int *variants_count, /* IN/OUT */
Packit Service 5bcba8
			       hb_ot_math_glyph_variant_t *variants /* OUT */)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_math_variants().get_glyph_variants (glyph, direction, font,
Packit Service 5bcba8
						      start_offset,
Packit Service 5bcba8
						      variants_count,
Packit Service 5bcba8
						      variants);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_min_connector_overlap:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the value
Packit Service 5bcba8
 * @direction: direction of the stretching
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * This function tries to retrieve the MathVariants table for the specified
Packit Service 5bcba8
 * font and returns the minimum overlap of connecting glyphs to draw a glyph
Packit Service 5bcba8
 * assembly in the specified direction. Note that only the value of
Packit Service 5bcba8
 * #HB_DIRECTION_IS_HORIZONTAL is considered.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: requested min connector overlap or 0
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
hb_position_t
Packit Service 5bcba8
hb_ot_math_get_min_connector_overlap (hb_font_t *font,
Packit Service 5bcba8
				      hb_direction_t direction)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_math_variants().get_min_connector_overlap (direction, font);
Packit Service 5bcba8
}
Packit Service 5bcba8
Packit Service 5bcba8
/**
Packit Service 5bcba8
 * hb_ot_math_get_glyph_assembly:
Packit Service 5bcba8
 * @font: #hb_font_t from which to retrieve the values
Packit Service 5bcba8
 * @glyph: index of the glyph to stretch
Packit Service 5bcba8
 * @direction: direction of the stretching
Packit Service 5bcba8
 * @start_offset: offset of the first glyph part to retrieve
Packit Service 5bcba8
 * @parts_count: maximum number of glyph parts to retrieve after start_offset
Packit Service 5bcba8
 * (IN) and actual number of parts retrieved (OUT)
Packit Service 5bcba8
 * @parts: array of size at least @parts_count to store the result
Packit Service 5bcba8
 * @italics_correction: italic correction of the glyph assembly
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * This function tries to retrieve the GlyphAssembly for the specified font,
Packit Service 5bcba8
 * glyph and direction. Note that only the value of #HB_DIRECTION_IS_HORIZONTAL
Packit Service 5bcba8
 * is considered. It provides the information necessary to draw the glyph
Packit Service 5bcba8
 * assembly as an array of #hb_ot_math_glyph_part_t.
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Return value: the total number of parts in the glyph assembly
Packit Service 5bcba8
 *
Packit Service 5bcba8
 * Since: 1.3.3
Packit Service 5bcba8
 **/
Packit Service 5bcba8
unsigned int
Packit Service 5bcba8
hb_ot_math_get_glyph_assembly (hb_font_t *font,
Packit Service 5bcba8
			       hb_codepoint_t glyph,
Packit Service 5bcba8
			       hb_direction_t direction,
Packit Service 5bcba8
			       unsigned int start_offset,
Packit Service 5bcba8
			       unsigned int *parts_count, /* IN/OUT */
Packit Service 5bcba8
			       hb_ot_math_glyph_part_t *parts, /* OUT */
Packit Service 5bcba8
			       hb_position_t *italics_correction /* OUT */)
Packit Service 5bcba8
{
Packit Service 5bcba8
  const OT::MATH &math = _get_math (font->face);
Packit Service 5bcba8
  return math.get_math_variants().get_glyph_parts (glyph, direction, font,
Packit Service 5bcba8
						   start_offset,
Packit Service 5bcba8
						   parts_count,
Packit Service 5bcba8
						   parts,
Packit Service 5bcba8
						   italics_correction);
Packit Service 5bcba8
}