• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SkTypeface(Style style,SkFontID fontID,bool isFixedWidth)20 SkTypeface::SkTypeface(Style style, SkFontID fontID, bool isFixedWidth)
21     : 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 }
27 
~SkTypeface()28 SkTypeface::~SkTypeface() {
29 #ifdef TRACE_LIFECYCLE
30     SkDebugf("SkTypeface: destroy %p fontID %d total %d\n",
31              this, fUniqueID, --gTypefaceCounter);
32 #endif
33 }
34 
35 ///////////////////////////////////////////////////////////////////////////////
36 
get_default_typeface()37 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     if (NULL == gDefaultTypeface) {
44         gDefaultTypeface =
45         SkFontHost::CreateTypeface(NULL, NULL, NULL, 0,
46                                    SkTypeface::kNormal);
47     }
48     return gDefaultTypeface;
49 }
50 
UniqueID(const SkTypeface * face)51 uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
52     if (NULL == face) {
53         face = get_default_typeface();
54     }
55     return face->uniqueID();
56 }
57 
Equal(const SkTypeface * facea,const SkTypeface * faceb)58 bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
59     return SkTypeface::UniqueID(facea) == SkTypeface::UniqueID(faceb);
60 }
61 
62 ///////////////////////////////////////////////////////////////////////////////
63 
CreateFromName(const char name[],Style style)64 SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
65     return SkFontHost::CreateTypeface(NULL, name, NULL, 0, style);
66 }
67 
CreateForChars(const void * data,size_t bytelength,Style s)68 SkTypeface* SkTypeface::CreateForChars(const void* data, size_t bytelength,
69                                        Style s) {
70     return SkFontHost::CreateTypeface(NULL, NULL, data, bytelength, s);
71 }
72 
CreateFromTypeface(const SkTypeface * family,Style s)73 SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
74     return SkFontHost::CreateTypeface(family, NULL, NULL, 0, s);
75 }
76 
CreateFromStream(SkStream * stream)77 SkTypeface* SkTypeface::CreateFromStream(SkStream* stream) {
78     return SkFontHost::CreateTypefaceFromStream(stream);
79 }
80 
CreateFromFile(const char path[])81 SkTypeface* SkTypeface::CreateFromFile(const char path[]) {
82     return SkFontHost::CreateTypefaceFromFile(path);
83 }
84 
85 ///////////////////////////////////////////////////////////////////////////////
86 
serialize(SkWStream * stream) const87 void SkTypeface::serialize(SkWStream* stream) const {
88     SkFontHost::Serialize(this, stream);
89 }
90 
Deserialize(SkStream * stream)91 SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
92     return SkFontHost::Deserialize(stream);
93 }
94 
getAdvancedTypefaceMetrics(SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,const uint32_t * glyphIDs,uint32_t glyphIDsCount) const95 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                                                   glyphIDsCount);
103 }
104