aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-02-24 11:15:26 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-24 16:59:05 +0000
commitfc497343cbcbd526f77da913ae2feca0e1b1b866 (patch)
tree98d57a95e80467c180b74f698072ea04c674af27 /include
parent9fe1b22249171087a0f01c67369559f6fd491540 (diff)
Add SkTypeface::getVariationDesignPosition.
Allow users to query a typeface's position in variation design space. Change-Id: Id7cae439e795b8c9586394f11359fb7fe55e1c0b Reviewed-on: https://skia-review.googlesource.com/8861 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkFontArguments.h79
-rw-r--r--include/core/SkTypeface.h34
-rw-r--r--include/ports/SkFontMgr.h51
3 files changed, 111 insertions, 53 deletions
diff --git a/include/core/SkFontArguments.h b/include/core/SkFontArguments.h
new file mode 100644
index 0000000000..473798fb84
--- /dev/null
+++ b/include/core/SkFontArguments.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkFontAgruments_DEFINED
+#define SkFontAgruments_DEFINED
+
+#include "SkScalar.h"
+#include "SkTypes.h"
+
+/** Represents a set of actual arguments for a font. */
+struct SkFontArguments {
+ struct VariationPosition {
+ struct Coordinate {
+ SkFourByteTag axis;
+ SkScalar value;
+ };
+ const Coordinate* coordinates;
+ int coordinateCount;
+ };
+ // deprecated, use VariationCoordinate instead
+ struct Axis {
+ SkFourByteTag fTag;
+ SkScalar fStyleValue;
+ };
+
+ SkFontArguments() : fCollectionIndex(0), fVariationDesignPosition{nullptr, 0} {}
+
+ /** Specify the index of the desired font.
+ *
+ * Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
+ * collections of fonts.
+ */
+ SkFontArguments& setCollectionIndex(int collectionIndex) {
+ fCollectionIndex = collectionIndex;
+ return *this;
+ }
+
+ // deprecated, use setVariationDesignPosition instead.
+ SkFontArguments& setAxes(const Axis* axes, int axisCount) {
+ fVariationDesignPosition.coordinates =
+ reinterpret_cast<const VariationPosition::Coordinate*>(axes);
+ fVariationDesignPosition.coordinateCount = axisCount;
+ return *this;
+ }
+
+ /** Specify a position in the variation design space.
+ *
+ * Any axis not specified will use the default value.
+ * Any specified axis not actually present in the font will be ignored.
+ *
+ * @param position not copied. The value must remain valid for life of SkFontArguments.
+ */
+ SkFontArguments& setVariationDesignPosition(VariationPosition position) {
+ fVariationDesignPosition.coordinates = position.coordinates;
+ fVariationDesignPosition.coordinateCount = position.coordinateCount;
+ return *this;
+ }
+
+ int getCollectionIndex() const {
+ return fCollectionIndex;
+ }
+ // deprecated, use getVariationDesignPosition instead.
+ const Axis* getAxes(int* axisCount) const {
+ *axisCount = fVariationDesignPosition.coordinateCount;
+ return reinterpret_cast<const Axis*>(fVariationDesignPosition.coordinates);
+ }
+ VariationPosition getVariationDesignPosition() const {
+ return fVariationDesignPosition;
+ }
+private:
+ int fCollectionIndex;
+ VariationPosition fVariationDesignPosition;
+};
+
+#endif
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 51d5a0b11c..24693a9af1 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -11,6 +11,7 @@
#include "../private/SkBitmaskEnum.h"
#include "../private/SkOnce.h"
#include "../private/SkWeakRefCnt.h"
+#include "SkFontArguments.h"
#include "SkFontStyle.h"
#include "SkRect.h"
#include "SkString.h"
@@ -77,6 +78,20 @@ public:
*/
bool isFixedPitch() const { return fIsFixedPitch; }
+ /** Copy into 'coordinates' (allocated by the caller) the design variation coordinates.
+ *
+ * @param coordinates the buffer into which to write the design variation coordinates.
+ * @param coordinateCount the number of entries available through 'coordinates'.
+ *
+ * @return The number of axes, or -1 if there is an error.
+ * If 'coordinates != nullptr' and 'coordinateCount >= numAxes' then 'coordinates' will be
+ * filled with the variation coordinates describing the position of this typeface in design
+ * variation space. It is possible the number of axes can be retrieved but actual position
+ * cannot.
+ */
+ int getVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
+ int coordinateCount) const;
+
/** Return a 32bit value for this typeface, unique for the underlying font
data. Will never return 0.
*/
@@ -96,16 +111,16 @@ public:
/** Returns the default typeface, which is never nullptr. */
static sk_sp<SkTypeface> MakeDefault(Style style = SkTypeface::kNormal);
- /** Creates a new reference to the typeface that most closely matches the
- requested familyName and fontStyle. This method allows extended font
- face specifiers as in the SkFontStyle type. Will never return null.
+ /** Creates a new reference to the typeface that most closely matches the
+ requested familyName and fontStyle. This method allows extended font
+ face specifiers as in the SkFontStyle type. Will never return null.
- @param familyName May be NULL. The name of the font family.
- @param fontStyle The style of the typeface.
- @return reference to the closest-matching typeface. Call must call
+ @param familyName May be NULL. The name of the font family.
+ @param fontStyle The style of the typeface.
+ @return reference to the closest-matching typeface. Call must call
unref() when they are done.
*/
- static sk_sp<SkTypeface> MakeFromName(const char familyName[], SkFontStyle fontStyle);
+ static sk_sp<SkTypeface> MakeFromName(const char familyName[], SkFontStyle fontStyle);
/** Return the typeface that most closely matches the requested typeface and style.
Use this to pick a new style from the same family of the existing typeface.
@@ -341,6 +356,11 @@ protected:
// TODO: make pure virtual.
virtual std::unique_ptr<SkFontData> onMakeFontData() const;
+ // TODO: make pure virtual.
+ virtual int onGetVariationDesignPosition(
+ SkFontArguments::VariationPosition::Coordinate coordinates[],
+ int coordinateCount) const;
+
virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0;
virtual int onCharsToGlyphs(const void* chars, Encoding, SkGlyphID glyphs[],
diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h
index 4103e8747e..b5879d35b8 100644
--- a/include/ports/SkFontMgr.h
+++ b/include/ports/SkFontMgr.h
@@ -8,9 +8,9 @@
#ifndef SkFontMgr_DEFINED
#define SkFontMgr_DEFINED
+#include "SkFontArguments.h"
#include "SkFontStyle.h"
#include "SkRefCnt.h"
-#include "SkScalar.h"
#include "SkTypes.h"
class SkData;
@@ -102,51 +102,10 @@ public:
*/
SkTypeface* createFromStream(SkStreamAsset*, int ttcIndex = 0) const;
- struct FontParameters {
- struct Axis {
- SkFourByteTag fTag;
- SkScalar fStyleValue;
- };
-
- FontParameters() : fCollectionIndex(0), fAxisCount(0), fAxes(nullptr) {}
-
- /** Specify the index of the desired font.
- *
- * Font formats like ttc, dfont, cff, cid, pfr, t42, t1, and fon may actually be indexed
- * collections of fonts.
- */
- FontParameters& setCollectionIndex(int collectionIndex) {
- fCollectionIndex = collectionIndex;
- return *this;
- }
-
- /** Specify the GX variation axis values.
- *
- * Any axes not specified will use the default value. Specified axes not present in the
- * font will be ignored.
- *
- * @param axes not copied. This pointer must remain valid for life of FontParameters.
- */
- FontParameters& setAxes(const Axis* axes, int axisCount) {
- fAxisCount = axisCount;
- fAxes = axes;
- return *this;
- }
-
- int getCollectionIndex() const {
- return fCollectionIndex;
- }
- const Axis* getAxes(int* axisCount) const {
- *axisCount = fAxisCount;
- return fAxes;
- }
- private:
- int fCollectionIndex;
- int fAxisCount;
- const Axis* fAxes;
- };
+ // deprecated, use SkFontArguments instead.
+ using FontParameters = SkFontArguments;
/* Experimental, API subject to change. */
- SkTypeface* createFromStream(SkStreamAsset*, const FontParameters&) const;
+ SkTypeface* createFromStream(SkStreamAsset*, const SkFontArguments&) const;
/**
* Create a typeface from the specified font data.
@@ -187,7 +146,7 @@ protected:
virtual SkTypeface* onCreateFromData(SkData*, int ttcIndex) const = 0;
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0;
// TODO: make pure virtual.
- virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const FontParameters&) const;
+ virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const SkFontArguments&) const;
virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const;
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0;