aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-25 18:44:17 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-25 18:44:17 +0000
commitc452d82c8276a7c73debe3c7c2bf2e1e2f5c6c66 (patch)
tree3a2a3063380fdff8e7be839d5991de088c00a234
parentc26d94fd7dc0b00cd6d0e42d28285f4a38aff021 (diff)
move fontmgr into include/ports for now
git-svn-id: http://skia.googlecode.com/svn/trunk@8370 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--experimental/SkFontMgr.h126
-rw-r--r--include/ports/SkFontMgr.h75
-rw-r--r--include/ports/SkFontStyle.h69
3 files changed, 144 insertions, 126 deletions
diff --git a/experimental/SkFontMgr.h b/experimental/SkFontMgr.h
deleted file mode 100644
index 295a2c78e6..0000000000
--- a/experimental/SkFontMgr.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkFontMgr_DEFINED
-#define SkFontMgr_DEFINED
-
-#include "SkRefCnt.h"
-
-class SkData;
-class SkStream;
-class SkString;
-
-class SkFontStyle {
-public:
- enum Weight {
- kThin_Weight = 100,
- kExtraLight_Weight = 200,
- kLight_Weight = 300,
- kNormal_Weight = 400,
- kMedium_Weight = 500,
- kSemiBold_Weight = 600,
- kBold_Weight = 700,
- kExtraBold_Weight = 800,
- kBlack_Weight = 900
- };
-
- enum Width {
- kUltraCondensed_Width = 1,
- kExtraCondensed_Width = 2,
- kCondensed_Width = 3,
- kSemiCondensed_Width = 4,
- kNormal_Width = 5,
- kSemiExpanded_Width = 6,
- kExpanded_Width = 7,
- kExtraExpanded_Width = 8,
- kUltaExpanded_Width = 9
- };
-
- enum Flags {
- kItalic_Flag = 1 << 0,
- };
-
- SkFontStyle();
- SkFontStyle(int weight, int width, unsigned flags);
-
- bool operator==(const SkFontStyle&) const {
- return fUnion.fU32 == other.fUnion.fU32;
- }
-
- int weight() const { return fUnion.fR.fWeight; }
- int width() const { return fUnion.fR.fWidth; }
- unsigned flags() const { return fUnion.fR.fFlags; }
-
- bool isItalic() const {
- return SkToBool(fUnion.fR.fFlags & kItalic_Flag);
- }
-
-private:
- union {
- struct {
- uint16_t fWeight; // 100 ... 900
- uint8_t fWidth; // 1 .. 9
- uint8_t fFlags;
- } fR;
- uint32_t fU32;
- } fUnion;
-};
-
-class SkFontMgr : public SkRefCnt {
-public:
- /**
- * SkData contains an array of [const char*]
- */
- SkData* refFamilyNames();
-
- /**
- * Given a familyName, if a corresponding family is found, return
- * the array of available styles in SkData (as [SkFontStyle]).
- *
- * If foundFamilyName is not null, set it to the actual familyName for the
- * found family.
- */
- SkData* refFamilyStyles(const char familyName[], SkString* foundFamilyName);
-
- /**
- * Find the closest matching typeface to the specified familyName and style
- * and return a ref to it. The caller must call unref() on the returned
- * object. Will never return NULL.
- *
- * If foundFamilyName is not null, set it to the actual familyName for the
- * returned typeface.
- */
- SkTypeface* matchFamilyName(const char familyName[], const Desc&,
- SkString* foundFamilyName);
-
- /**
- * Create a typeface for the specified data and TTC index (pass 0 for none)
- * or NULL if the data is not recognized. The caller must call unref() on
- * the returned object if it is not null.
- */
- SkTypeface* createFromData(SkData*, int ttcIndex = 0);
-
- /**
- * Create a typeface for the specified stream and TTC index
- * (pass 0 for none) or NULL if the stream is not recognized. The caller
- * must call unref() on the returned object if it is not null.
- */
- SkTypeface* createFromStream(SkStream*, int ttcIndex = 0);
-
- /**
- * Create a typeface for the specified fileName and TTC index
- * (pass 0 for none) or NULL if the file is not found, or its contents are
- * not recognized. The caller must call unref() on the returned object
- * if it is not null.
- */
- SkTypeface* createFromFile(const char path[], int ttcIndex = 0);
-
-private:
- typedef SkRefCnt INHERITED;
-};
-
-#endif
diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h
new file mode 100644
index 0000000000..b3d38138b8
--- /dev/null
+++ b/include/ports/SkFontMgr.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkFontMgr_DEFINED
+#define SkFontMgr_DEFINED
+
+#include "SkRefCnt.h"
+#include "SkFontStyle.h"
+
+class SkData;
+class SkStream;
+class SkString;
+
+class SkFontStyleSet : public SkRefCnt {
+public:
+ int count() const;
+ void getStyle(int index, SkFontStyle*) const;
+ SkTypeface* createTypeface(int index) const;
+};
+
+class SkFontFamilySet : public SkRefCnt {
+public:
+ int count() const;
+ void getName(int index, SkString* familyName) const;
+ SkFontStyleSet* refStyleSet(int index) const;
+};
+
+class SkFontMgr : public SkRefCnt {
+public:
+ /**
+ * Return a fontfamily set, which can iterate all of the font families
+ * available to this fontmgr. The caller is responsible for calling unref()
+ * on the returned object. Will never return NULL.
+ */
+ SkFontFamilySet* createFamilySet();
+
+ /**
+ * Find the closest matching typeface to the specified familyName and style
+ * and return a ref to it. The caller must call unref() on the returned
+ * object. Will never return NULL, as it will return the default font if
+ * no matching font is found.
+ */
+ SkTypeface* matchFamilyStyle(const char familyName[], const SkFontStyle&);
+
+ /**
+ * Create a typeface for the specified data and TTC index (pass 0 for none)
+ * or NULL if the data is not recognized. The caller must call unref() on
+ * the returned object if it is not null.
+ */
+ SkTypeface* createFromData(SkData*, int ttcIndex = 0);
+
+ /**
+ * Create a typeface for the specified stream and TTC index
+ * (pass 0 for none) or NULL if the stream is not recognized. The caller
+ * must call unref() on the returned object if it is not null.
+ */
+ SkTypeface* createFromStream(SkStream*, int ttcIndex = 0);
+
+ /**
+ * Create a typeface for the specified fileName and TTC index
+ * (pass 0 for none) or NULL if the file is not found, or its contents are
+ * not recognized. The caller must call unref() on the returned object
+ * if it is not null.
+ */
+ SkTypeface* createFromFile(const char path[], int ttcIndex = 0);
+
+private:
+ typedef SkRefCnt INHERITED;
+};
+
+#endif
diff --git a/include/ports/SkFontStyle.h b/include/ports/SkFontStyle.h
new file mode 100644
index 0000000000..f145a6ee74
--- /dev/null
+++ b/include/ports/SkFontStyle.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkFontMgr_DEFINED
+#define SkFontMgr_DEFINED
+
+#include "SkTypes.h"
+
+class SkFontStyle {
+public:
+ enum Weight {
+ kThin_Weight = 100,
+ kExtraLight_Weight = 200,
+ kLight_Weight = 300,
+ kNormal_Weight = 400,
+ kMedium_Weight = 500,
+ kSemiBold_Weight = 600,
+ kBold_Weight = 700,
+ kExtraBold_Weight = 800,
+ kBlack_Weight = 900
+ };
+
+ enum Width {
+ kUltraCondensed_Width = 1,
+ kExtraCondensed_Width = 2,
+ kCondensed_Width = 3,
+ kSemiCondensed_Width = 4,
+ kNormal_Width = 5,
+ kSemiExpanded_Width = 6,
+ kExpanded_Width = 7,
+ kExtraExpanded_Width = 8,
+ kUltaExpanded_Width = 9
+ };
+
+ enum Slant {
+ kUpright_Slant,
+ kItalic_Slant,
+ };
+
+ SkFontStyle();
+ SkFontStyle(int weight, int width, Slant);
+
+ bool operator==(const SkFontStyle& rhs) const {
+ return fUnion.fU32 == rhs.fUnion.fU32;
+ }
+
+ int weight() const { return fUnion.fR.fWeight; }
+ int width() const { return fUnion.fR.fWidth; }
+
+ bool isItalic() const {
+ return kItalic_Slant == fUnion.fR.fSlant;
+ }
+
+private:
+ union {
+ struct {
+ uint16_t fWeight; // 100 .. 900
+ uint8_t fWidth; // 1 .. 9
+ uint8_t fSlant; // 0 .. 2
+ } fR;
+ uint32_t fU32;
+ } fUnion;
+};
+
+#endif