From e346b1eea442065261c14f92b304031e1330e491 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Tue, 26 Jun 2018 11:22:37 -0400 Subject: Add SkTypeface::getVariationDesignParameters This adds a way for users to query the axis parameters for a typeface. Change-Id: Idc2ac0d84bc7ae2ca484ae410cba5b01883418e5 Reviewed-on: https://skia-review.googlesource.com/137706 Commit-Queue: Ben Wagner Reviewed-by: Mike Reed --- include/core/SkFontArguments.h | 10 +++++----- include/core/SkFontParameters.h | 38 ++++++++++++++++++++++++++++++++++++++ include/core/SkTypeface.h | 18 ++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 include/core/SkFontParameters.h (limited to 'include') diff --git a/include/core/SkFontArguments.h b/include/core/SkFontArguments.h index 473798fb84..52f20728a1 100644 --- a/include/core/SkFontArguments.h +++ b/include/core/SkFontArguments.h @@ -5,8 +5,8 @@ * found in the LICENSE file. */ -#ifndef SkFontAgruments_DEFINED -#define SkFontAgruments_DEFINED +#ifndef SkFontArguments_DEFINED +#define SkFontArguments_DEFINED #include "SkScalar.h" #include "SkTypes.h" @@ -16,15 +16,15 @@ struct SkFontArguments { struct VariationPosition { struct Coordinate { SkFourByteTag axis; - SkScalar value; + float value; }; const Coordinate* coordinates; int coordinateCount; }; - // deprecated, use VariationCoordinate instead + // deprecated, use VariationPosition::Coordinate instead struct Axis { SkFourByteTag fTag; - SkScalar fStyleValue; + float fStyleValue; }; SkFontArguments() : fCollectionIndex(0), fVariationDesignPosition{nullptr, 0} {} diff --git a/include/core/SkFontParameters.h b/include/core/SkFontParameters.h new file mode 100644 index 0000000000..7d3c407add --- /dev/null +++ b/include/core/SkFontParameters.h @@ -0,0 +1,38 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkFontParameters_DEFINED +#define SkFontParameters_DEFINED + +#include "SkScalar.h" +#include "SkTypes.h" + +struct SkFontParameters { + struct Variation { + // Parameters in a variation font axis. + struct Axis { + // Four character identifier of the font axis (weight, width, slant, italic...). + SkFourByteTag tag; + // Minimum value supported by this axis. + float min; + // Default value set by this axis. + float def; + // Maximum value supported by this axis. The maximum can equal the minimum. + float max; + // Return whether this axis is recommended to be remain hidden in user interfaces. + bool isHidden() const { return flags & HIDDEN; } + // Set this axis to be remain hidden in user interfaces. + void setHidden(bool hidden) { flags = hidden ? (flags | HIDDEN) : (flags & ~HIDDEN); } + private: + static constexpr uint16_t HIDDEN = 0x0001; + // Attributes for a font axis. + uint16_t flags; + }; + }; +}; + +#endif diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 4118152dea..51f339ccfa 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -11,6 +11,7 @@ #include "../private/SkOnce.h" #include "../private/SkWeakRefCnt.h" #include "SkFontArguments.h" +#include "SkFontParameters.h" #include "SkFontStyle.h" #include "SkRect.h" #include "SkString.h" @@ -71,6 +72,20 @@ public: int getVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const; + /** Copy into 'parameters' (allocated by the caller) the design variation parameters. + * + * @param parameters the buffer into which to write the design variation parameters. + * @param coordinateCount the number of entries available through 'parameters'. + * + * @return The number of axes, or -1 if there is an error. + * If 'parameters != nullptr' and 'parameterCount >= numAxes' then 'parameters' will be + * filled with the variation parameters describing the position of this typeface in design + * variation space. It is possible the number of axes can be retrieved but actual parameters + * cannot. + */ + int getVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], + int parameterCount) const; + /** Return a 32bit value for this typeface, unique for the underlying font data. Will never return 0. */ @@ -341,6 +356,9 @@ protected: SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const = 0; + virtual int onGetVariationDesignParameters( + SkFontParameters::Variation::Axis parameters[], int parameterCount) const; + virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0; virtual int onCharsToGlyphs(const void* chars, Encoding, SkGlyphID glyphs[], -- cgit v1.2.3