// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using SixLabors.Fonts.Tables.AdvancedTypographic;
using SixLabors.Fonts.Tables.AdvancedTypographic.Variations;
using SixLabors.Fonts.Unicode;
namespace SixLabors.Fonts {
///
/// Represents a font face with metrics, which is a set of glyphs with a specific style (regular, italic, bold etc).
///
public abstract class FontMetrics
{
internal FontMetrics()
{
}
///
/// Gets the basic description of the face.
///
public abstract FontDescription Description { get; }
///
/// Gets the number of font units per EM square for this face.
///
public abstract ushort UnitsPerEm { get; }
///
/// Gets the scale factor that is applied to all glyphs in this face.
/// Calculated as 72 * so that 1pt = 1px.
///
public abstract float ScaleFactor { get; }
///
/// Gets the metrics specific to horizontal text.
///
public abstract HorizontalMetrics HorizontalMetrics { get; }
///
/// Gets the metrics specific to vertical text.
///
public abstract VerticalMetrics VerticalMetrics { get; }
///
/// Gets the recommended horizontal size in font design units for subscripts for this font.
///
public abstract short SubscriptXSize { get; }
///
/// Gets the recommended vertical size in font design units for subscripts for this font.
///
public abstract short SubscriptYSize { get; }
///
/// Gets the recommended horizontal offset in font design units for subscripts for this font.
///
public abstract short SubscriptXOffset { get; }
///
/// Gets the recommended vertical offset in font design units for subscripts for this font.
///
public abstract short SubscriptYOffset { get; }
///
/// Gets the recommended horizontal size in font design units for superscripts for this font.
///
public abstract short SuperscriptXSize { get; }
///
/// Gets the recommended vertical size in font design units for superscripts for this font.
///
public abstract short SuperscriptYSize { get; }
///
/// Gets the recommended horizontal offset in font design units for superscripts for this font.
///
public abstract short SuperscriptXOffset { get; }
///
/// Gets the recommended vertical offset in font design units for superscripts for this font.
///
public abstract short SuperscriptYOffset { get; }
///
/// Gets thickness of the strikeout stroke in font design units.
///
public abstract short StrikeoutSize { get; }
///
/// Gets the position of the top of the strikeout stroke relative to the baseline in font design units.
///
public abstract short StrikeoutPosition { get; }
///
/// Gets the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
///
public abstract short UnderlinePosition { get; }
///
/// Gets the suggested values for the underline thickness. In general, the underline thickness should match the thickness of
/// the underscore character (U+005F LOW LINE), and should also match the strikeout thickness, which is specified in the OS/2 table.
///
public abstract short UnderlineThickness { get; }
///
/// Gets the italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
///
public abstract float ItalicAngle { get; }
///
/// Gets the specified glyph id matching the codepoint.
///
/// The codepoint.
///
/// When this method returns, contains the glyph id associated with the specified codepoint,
/// if the codepoint is found; otherwise, 0.
/// This parameter is passed uninitialized.
///
///
/// if the face contains a glyph for the specified codepoint; otherwise, .
///
internal abstract bool TryGetGlyphId(CodePoint codePoint, out ushort glyphId);
///
/// Gets the specified glyph id matching the codepoint pair.
///
/// The codepoint.
/// The next codepoint. Can be null.
///
/// When this method returns, contains the glyph id associated with the specified codepoint,
/// if the codepoint is found; otherwise, 0.
/// This parameter is passed uninitialized.
///
///
/// When this method return, contains a value indicating whether the next codepoint should be skipped.
///
///
/// if the face contains a glyph for the specified codepoint; otherwise, .
///
internal abstract bool TryGetGlyphId(CodePoint codePoint, CodePoint? nextCodePoint, out ushort glyphId, out bool skipNextCodePoint);
///
/// Gets the specified glyph id matching the codepoint.
///
/// The glyph identifier.
///
/// When this method returns, contains the codepoint associated with the specified glyph id,
/// if the glyph id is found; otherwise, default.
///
///
/// if the face contains a codepoint for the specified glyph id; otherwise, .
///
internal abstract bool TryGetCodePoint(ushort glyphId, out CodePoint codePoint);
///
/// Tries to get the glyph class for a given glyph id.
/// The font needs to have a GDEF table defined.
///
/// The glyph identifier.
/// The glyph class.
/// true, if the glyph class could be retrieved.
internal abstract bool TryGetGlyphClass(ushort glyphId, [NotNullWhen(true)] out GlyphClassDef? glyphClass);
///
/// Tries to get the mark attachment class for a given glyph id.
/// The font needs to have a GDEF table defined.
///
/// The glyph identifier.
/// The mark attachment class.
/// true, if the mark attachment class could be retrieved.
internal abstract bool TryGetMarkAttachmentClass(ushort glyphId, [NotNullWhen(true)] out GlyphClassDef? markAttachmentClass);
///
/// Tries to get the variation axes that this font supports.
/// The font needs to have a fvar table.
///
/// A read-only memory region containing the variation axes.
/// True, if fvar table is present.
public abstract bool TryGetVariationAxes(out ReadOnlyMemory variationAxes);
///
/// Returns a value indicating whether the specified glyph is in the given mark filtering set.
/// The font needs to have a GDEF table defined.
///
/// The mark glyph set index.
/// The glyph identifier.
///
/// true, if the glyph is in the mark filtering set.
///
internal abstract bool IsInMarkFilteringSet(ushort markGlyphSetIndex, ushort glyphId);
///
/// Gets the glyph metrics for a given code point.
///
/// The Unicode code point to get the glyph for.
/// The text attributes applied to the glyph.
/// The text decorations applied to the glyph.
/// The layout mode applied to the glyph.
/// Options for enabling color font support during layout and rendering.
///
/// When this method returns, contains the metrics for the given codepoint and color support if the metrics
/// are found; otherwise the default value. This parameter is passed uninitialized.
///
///
/// if the face contains glyph metrics for the specified codepoint; otherwise, .
///
public abstract bool TryGetGlyphMetrics(
CodePoint codePoint,
TextAttributes textAttributes,
TextDecorations textDecorations,
LayoutMode layoutMode,
ColorFontSupport support,
[NotNullWhen(true)] out FontGlyphMetrics? metrics);
///
/// Gets the unicode codepoints for which a glyph exists in the font.
///
/// A read-only memory region containing the available codepoints.
public abstract ReadOnlyMemory GetAvailableCodePoints();
///
/// Gets the glyph metrics for a given code point and glyph id.
///
/// The Unicode codepoint.
///
/// The previously matched or substituted glyph id for the codepoint in the face.
/// If this value equals 0 the default fallback metrics are returned.
///
/// The text attributes applied to the glyph.
/// The text decorations applied to the glyph.
/// The layout mode applied to the glyph.
/// Options for enabling color font support during layout and rendering.
/// The font glyph metrics.
internal abstract FontGlyphMetrics GetGlyphMetrics(
CodePoint codePoint,
ushort glyphId,
TextAttributes textAttributes,
TextDecorations textDecorations,
LayoutMode layoutMode,
ColorFontSupport colorSupport);
///
/// Tries to get the GSUB table.
///
/// The GSUB table.
/// true, if the glyph class could be retrieved.
internal abstract bool TryGetGSubTable([NotNullWhen(true)] out GSubTable? gSubTable);
///
/// Applies any available substitutions to the collection of glyphs.
///
/// The glyph substitution collection.
internal abstract void ApplySubstitution(GlyphSubstitutionCollection collection);
///
/// Gets the amount, in font units, the glyph should be offset if it is followed by
/// the glyph.
///
/// The current glyph id.
/// The next glyph id.
///
/// When this method returns, contains the offset, in font units, that should be applied to the
/// glyph, if the offset is found; otherwise the default vector value.
/// This parameter is passed uninitialized.
///
///
/// if the face contains and offset for the glyph combination; otherwise, .
///
internal abstract bool TryGetKerningOffset(ushort currentId, ushort nextId, out Vector2 vector);
///
/// Applies any available positioning updates to the collection of glyphs.
///
/// The glyph positioning collection.
internal abstract void UpdatePositions(GlyphPositioningCollection collection);
///
/// Computes a GPOS/GSUB variation delta for the given packed VariationIndex.
/// The delta is computed using the GDEF ItemVariationStore and the current
/// variation coordinates from the GlyphVariationProcessor.
///
///
/// The packed VariationIndex: (outerIndex << 16) | innerIndex.
/// A value of 0 returns 0.
///
/// The delta value in design units, or 0 if no variation data is available.
internal abstract float GetGDefVariationDelta(uint packedVariationIndex);
///
/// Gets the normalized variation coordinates for this font instance.
/// Returns an empty span for non-variable fonts or fonts at default coordinates.
///
/// The normalized coordinates, or an empty span.
internal abstract ReadOnlySpan GetNormalizedCoordinates();
}
}