Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: src/core/SkFontDescriptor.h

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Initial Mac implementation (buggy). Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkFontDescriptor_DEFINED 8 #ifndef SkFontDescriptor_DEFINED
9 #define SkFontDescriptor_DEFINED 9 #define SkFontDescriptor_DEFINED
10 10
11 #include "SkStream.h" 11 #include "SkStream.h"
12 #include "SkString.h" 12 #include "SkString.h"
13 #include "SkTypeface.h" 13 #include "SkTypeface.h"
14 14
15 class SkFontData {
16 public:
17 struct Axis {
18 Axis() : fTag(SkSetFourByteTag('\0','\0','\0','\0')), fValue(0) { }
19 SkFourByteTag fTag;
20 SkFixed fValue;
21 };
22
23 /** This takes ownership of 'stream'. Makes a copy of the data in 'axis'. */
24 SkFontData(SkStreamAsset* stream, int index, int axisCount, const Axis axis[ ])
25 : fStream(stream), fIndex(index), fAxisCount(axisCount), fAxis(axisCount )
26 {
27 for (int i = 0; i < axisCount; ++i) {
28 fAxis[i] = axis[i];
29 }
30 }
31 bool hasStream() const { return fStream.get() != NULL; }
32 SkStreamAsset* transferStream() { return fStream.detach(); }
33 int getIndex() const { return fIndex; }
34 int getAxisCount() const { return fAxisCount; }
35 const Axis* getAxis() const { return fAxis.get(); }
36
37 private:
38 SkAutoTDelete<SkStreamAsset> fStream;
39 int fIndex;
40 int fAxisCount;
41 SkAutoSTMalloc<4, Axis> fAxis;
42 };
43
15 class SkFontDescriptor { 44 class SkFontDescriptor {
16 public: 45 public:
17 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); 46 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal);
18 // Does not affect ownership of SkStream. 47 // Does not affect ownership of SkStream.
19 SkFontDescriptor(SkStream*); 48 SkFontDescriptor(SkStream*);
20 49
21 void serialize(SkWStream*); 50 void serialize(SkWStream*);
22 51
23 SkTypeface::Style getStyle() { return fStyle; } 52 SkTypeface::Style getStyle() { return fStyle; }
24 void setStyle(SkTypeface::Style style) { fStyle = style; } 53 void setStyle(SkTypeface::Style style) { fStyle = style; }
25 54
26 const char* getFamilyName() const { return fFamilyName.c_str(); } 55 const char* getFamilyName() const { return fFamilyName.c_str(); }
27 const char* getFullName() const { return fFullName.c_str(); } 56 const char* getFullName() const { return fFullName.c_str(); }
28 const char* getPostscriptName() const { return fPostscriptName.c_str(); } 57 const char* getPostscriptName() const { return fPostscriptName.c_str(); }
29 bool hasFontData() const { return fFontData.get() != NULL; } 58 bool hasFontData() const { return fFontData.get() != NULL; }
30 // Transfers ownership to the caller. 59 // Transfers ownership to the caller.
31 SkStreamAsset* transferFontData() { return fFontData.detach(); } 60 SkFontData* getFontData() { return fFontData.get(); }
32 int getFontIndex() const { return fFontIndex; }
33 61
34 void setFamilyName(const char* name) { fFamilyName.set(name); } 62 void setFamilyName(const char* name) { fFamilyName.set(name); }
35 void setFullName(const char* name) { fFullName.set(name); } 63 void setFullName(const char* name) { fFullName.set(name); }
36 void setPostscriptName(const char* name) { fPostscriptName.set(name); } 64 void setPostscriptName(const char* name) { fPostscriptName.set(name); }
37 /** Set the font data only if it is necessary for serialization. 65 /** Set the font data only if it is necessary for serialization.
38 * This method takes ownership of the stream (both reference and cursor). 66 * This method takes ownership of the font data. */
39 */ 67 void setFontData(SkFontData* data) { fFontData.reset(data); }
40 void setFontData(SkStreamAsset* stream) { fFontData.reset(stream); }
41 void setFontIndex(int index) { fFontIndex = index; }
42 68
43 private: 69 private:
44 SkString fFamilyName; 70 SkString fFamilyName;
45 SkString fFullName; 71 SkString fFullName;
46 SkString fPostscriptName; 72 SkString fPostscriptName;
47 SkAutoTDelete<SkStreamAsset> fFontData; 73 SkAutoTDelete<SkFontData> fFontData;
48 int fFontIndex;
49 74
50 SkTypeface::Style fStyle; 75 SkTypeface::Style fStyle;
51 }; 76 };
52 77
53 #endif // SkFontDescriptor_DEFINED 78 #endif // SkFontDescriptor_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698