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

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

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Slightly more palatable. 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 /** This takes ownership of 'stream'. Makes a copy of the data in 'axis'. */
18 SkFontData(SkStreamAsset* stream, int index, int axisCount, const SkFixed ax is[])
19 : fStream(stream), fIndex(index), fAxisCount(axisCount), fAxis(axisCount )
20 {
21 for (int i = 0; i < axisCount; ++i) {
22 fAxis[i] = axis[i];
23 }
24 }
25 bool hasStream() const { return fStream.get() != NULL; }
26 SkStreamAsset* transferStream() { return fStream.detach(); }
27 int getIndex() const { return fIndex; }
28 int getAxisCount() const { return fAxisCount; }
29 const SkFixed* getAxis() const { return fAxis.get(); }
30
31 private:
32 SkAutoTDelete<SkStreamAsset> fStream;
33 int fIndex;
34 int fAxisCount;
35 SkAutoSTMalloc<4, SkFixed> fAxis;
36 };
37
15 class SkFontDescriptor { 38 class SkFontDescriptor {
16 public: 39 public:
17 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); 40 SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal);
18 // Does not affect ownership of SkStream. 41 // Does not affect ownership of SkStream.
19 SkFontDescriptor(SkStream*); 42 SkFontDescriptor(SkStream*);
20 43
21 void serialize(SkWStream*); 44 void serialize(SkWStream*);
22 45
23 SkTypeface::Style getStyle() { return fStyle; } 46 SkTypeface::Style getStyle() { return fStyle; }
24 void setStyle(SkTypeface::Style style) { fStyle = style; } 47 void setStyle(SkTypeface::Style style) { fStyle = style; }
25 48
26 const char* getFamilyName() const { return fFamilyName.c_str(); } 49 const char* getFamilyName() const { return fFamilyName.c_str(); }
27 const char* getFullName() const { return fFullName.c_str(); } 50 const char* getFullName() const { return fFullName.c_str(); }
28 const char* getPostscriptName() const { return fPostscriptName.c_str(); } 51 const char* getPostscriptName() const { return fPostscriptName.c_str(); }
29 const char* getFontFileName() const { return fFontFileName.c_str(); }
30 bool hasFontData() const { return fFontData.get() != NULL; } 52 bool hasFontData() const { return fFontData.get() != NULL; }
31 // Transfers ownership to the caller. 53 // Transfers ownership to the caller.
32 SkStreamAsset* transferFontData() { return fFontData.detach(); } 54 SkFontData* getFontData() { return fFontData.get(); }
33 int getFontIndex() const { return fFontIndex; }
34 55
35 void setFamilyName(const char* name) { fFamilyName.set(name); } 56 void setFamilyName(const char* name) { fFamilyName.set(name); }
36 void setFullName(const char* name) { fFullName.set(name); } 57 void setFullName(const char* name) { fFullName.set(name); }
37 void setPostscriptName(const char* name) { fPostscriptName.set(name); } 58 void setPostscriptName(const char* name) { fPostscriptName.set(name); }
38 void setFontFileName(const char* name) { fFontFileName.set(name); }
39 /** Set the font data only if it is necessary for serialization. 59 /** Set the font data only if it is necessary for serialization.
40 * This method takes ownership of the stream (both reference and cursor). 60 * This method takes ownership of the font data. */
41 */ 61 void setFontData(SkFontData* data) { fFontData.reset(data); }
42 void setFontData(SkStreamAsset* stream) { fFontData.reset(stream); }
43 void setFontIndex(int index) { fFontIndex = index; }
44 62
45 private: 63 private:
46 SkString fFamilyName; 64 SkString fFamilyName;
47 SkString fFullName; 65 SkString fFullName;
48 SkString fPostscriptName; 66 SkString fPostscriptName;
49 SkString fFontFileName; 67 SkAutoTDelete<SkFontData> fFontData;
50 SkAutoTDelete<SkStreamAsset> fFontData;
51 int fFontIndex;
52 68
53 SkTypeface::Style fStyle; 69 SkTypeface::Style fStyle;
54 }; 70 };
55 71
56 #endif // SkFontDescriptor_DEFINED 72 #endif // SkFontDescriptor_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698