SkFontDescriptor.h revision 5f213d9627d2eefa7da81cd97f36754f75eb4ae9
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkFontDescriptor_DEFINED
9#define SkFontDescriptor_DEFINED
10
11#include "SkStream.h"
12#include "SkString.h"
13#include "SkTypeface.h"
14
15class SkFontDescriptor {
16public:
17    SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal);
18    // Does not affect ownership of SkStream.
19    SkFontDescriptor(SkStream*);
20
21    void serialize(SkWStream*);
22
23    SkTypeface::Style getStyle() { return fStyle; }
24    void setStyle(SkTypeface::Style style) { fStyle = style; }
25
26    const char* getFamilyName() const { return fFamilyName.c_str(); }
27    const char* getFullName() const { return fFullName.c_str(); }
28    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; }
31    // Transfers ownership to the caller.
32    SkStreamAsset* transferFontData() { return fFontData.detach(); }
33    int getFontIndex() const { return fFontIndex; }
34
35    void setFamilyName(const char* name) { fFamilyName.set(name); }
36    void setFullName(const char* name) { fFullName.set(name); }
37    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.
40     *  This method takes ownership of the stream (both reference and cursor).
41     */
42    void setFontData(SkStreamAsset* stream) { fFontData.reset(stream); }
43    void setFontIndex(int index) { fFontIndex = index; }
44
45private:
46    SkString fFamilyName;
47    SkString fFullName;
48    SkString fPostscriptName;
49    SkString fFontFileName;
50    SkAutoTDelete<SkStreamAsset> fFontData;
51    int fFontIndex;
52
53    SkTypeface::Style fStyle;
54};
55
56#endif // SkFontDescriptor_DEFINED
57