1 :
2 : /*
3 : * Copyright 2011 The Android Open Source Project
4 : *
5 : * Use of this source code is governed by a BSD-style license that can be
6 : * found in the LICENSE file.
7 : */
8 :
9 :
10 : #include "SkAdvancedTypefaceMetrics.h"
11 : #include "SkTypeface.h"
12 : #include "SkFontHost.h"
13 :
14 : //#define TRACE_LIFECYCLE
15 :
16 : #ifdef TRACE_LIFECYCLE
17 : static int32_t gTypefaceCounter;
18 : #endif
19 :
20 0 : SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedWidth)
21 0 : : fUniqueID(fontID), fStyle(style), fIsFixedWidth(isFixedWidth) {
22 : #ifdef TRACE_LIFECYCLE
23 : SkDebugf("SkTypeface: create %p fontID %d total %d\n",
24 : this, fontID, ++gTypefaceCounter);
25 : #endif
26 0 : }
27 :
28 0 : SkTypeface::~SkTypeface() {
29 : #ifdef TRACE_LIFECYCLE
30 : SkDebugf("SkTypeface: destroy %p fontID %d total %d\n",
31 : this, fUniqueID, --gTypefaceCounter);
32 : #endif
33 0 : }
34 :
35 : ///////////////////////////////////////////////////////////////////////////////
36 :
37 0 : static SkTypeface* get_default_typeface() {
38 : // we keep a reference to this guy for all time, since if we return its
39 : // fontID, the font cache may later on ask to resolve that back into a
40 : // typeface object.
41 : static SkTypeface* gDefaultTypeface;
42 :
43 0 : if (NULL == gDefaultTypeface) {
44 : gDefaultTypeface =
45 : SkFontHost::CreateTypeface(NULL, NULL, NULL, 0,
46 0 : SkTypeface::kNormal);
47 : }
48 0 : return gDefaultTypeface;
49 : }
50 :
51 0 : uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
52 0 : if (NULL == face) {
53 0 : face = get_default_typeface();
54 : }
55 0 : return face->uniqueID();
56 : }
57 :
58 0 : bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
59 0 : return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb);
60 : }
61 :
62 : ///////////////////////////////////////////////////////////////////////////////
63 :
64 0 : SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
65 0 : return SkFontHost::CreateTypeface(NULL, name, NULL, 0, style);
66 : }
67 :
68 0 : SkTypeface* SkTypeface::CreateForChars(const void* data, size_t bytelength,
69 : Style s) {
70 0 : return SkFontHost::CreateTypeface(NULL, NULL, data, bytelength, s);
71 : }
72 :
73 0 : SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
74 0 : return SkFontHost::CreateTypeface(family, NULL, NULL, 0, s);
75 : }
76 :
77 0 : SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) {
78 0 : return SkFontHost::CreateTypefaceFromStream(stream);
79 : }
80 :
81 0 : SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
82 0 : return SkFontHost::CreateTypefaceFromFile(path);
83 : }
84 :
85 : ///////////////////////////////////////////////////////////////////////////////
86 :
87 0 : void SkTypeface::serialize(SkWStream* stream) const {
88 0 : SkFontHost::Serialize(this, stream);
89 0 : }
90 :
91 0 : SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
92 0 : return SkFontHost::Deserialize(stream);
93 : }
94 :
95 0 : SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
96 : SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
97 : const uint32_t* glyphIDs,
98 : uint32_t glyphIDsCount) const {
99 : return SkFontHost::GetAdvancedTypefaceMetrics(fUniqueID,
100 : perGlyphInfo,
101 : glyphIDs,
102 0 : glyphIDsCount);
103 : }
|