~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to third_party/skia/include/core/SkFontHost.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006 The Android Open Source Project
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#ifndef SkFontHost_DEFINED
 
18
#define SkFontHost_DEFINED
 
19
 
 
20
#include "SkScalerContext.h"
 
21
#include "SkTypeface.h"
 
22
 
 
23
class SkDescriptor;
 
24
class SkStream;
 
25
class SkWStream;
 
26
 
 
27
/** \class SkFontHost
 
28
 
 
29
    This class is ported to each environment. It is responsible for bridging the gap
 
30
    between SkTypeface and the resulting platform-specific instance of SkScalerContext.
 
31
*/
 
32
class SkFontHost {
 
33
public:
 
34
    /** Return the closest matching typeface given either an existing family
 
35
        (specified by a typeface in that family) or by a familyName, and a
 
36
        requested style.
 
37
        1) If familyFace is null, use famillyName.
 
38
        2) If famillyName is null, use familyFace.
 
39
        3) If both are null, return the default font that best matches style
 
40
 
 
41
        NOTE: this does not return a new typeface, nor does it affect the
 
42
        owner count of an existing one, so the caller is free to ignore the
 
43
        return result, or just compare it against null.
 
44
     */
 
45
    static SkTypeface* FindTypeface(const SkTypeface* familyFace,
 
46
                                    const char famillyName[],
 
47
                                    SkTypeface::Style style);
 
48
 
 
49
    /** Return the typeface associated with the uniqueID, or null if that ID
 
50
        does not match any faces.
 
51
 
 
52
        NOTE: this does not return a new typeface, nor does it affect the
 
53
        owner count of an existing one, so the caller is free to ignore the
 
54
        return result, or just compare it against null.
 
55
    */
 
56
    static SkTypeface* ResolveTypeface(uint32_t uniqueID);
 
57
    
 
58
    /** Return a new stream to read the font data, or null if the uniqueID does
 
59
        not match an existing typeface. The caller must call CloseStream() when
 
60
        it is finished reading the stream.
 
61
    */
 
62
    static SkStream* OpenStream(uint32_t uniqueID);
 
63
    
 
64
    /** Call this when finished reading from the stream returned by OpenStream.
 
65
        The caller should NOT try to delete the stream.
 
66
     */
 
67
    static void CloseStream(uint32_t uniqueID, SkStream*);
 
68
 
 
69
    /** Return a new typeface given the data buffer (owned by the caller).
 
70
        If the data does not represent a valid font, return null. The caller is
 
71
        responsible for unref-ing the returned typeface (if it is not null).
 
72
    */
 
73
    static SkTypeface* CreateTypeface(SkStream*);
 
74
    
 
75
    /** Return a new typeface from the specified file path. If the file does not
 
76
        represent a valid font, this returns null. If a typeface is returned,
 
77
        the caller is responsible for calling unref() when it is no longer used.
 
78
     */
 
79
    static SkTypeface* CreateTypefaceFromFile(const char path[]);
 
80
    
 
81
    ///////////////////////////////////////////////////////////////////////////
 
82
 
 
83
    /** Write a unique identifier to the stream, so that the same typeface can
 
84
        be retrieved with Deserialize().
 
85
    */
 
86
    static void Serialize(const SkTypeface*, SkWStream*);
 
87
 
 
88
    /** Given a stream created by Serialize(), return the corresponding typeface
 
89
        or null if no match is found.
 
90
 
 
91
        NOTE: this does not return a new typeface, nor does it affect the
 
92
        owner count of an existing one, so the caller is free to ignore the
 
93
        return result, or just compare it against null.
 
94
     */
 
95
    static SkTypeface* Deserialize(SkStream*);
 
96
 
 
97
    ///////////////////////////////////////////////////////////////////////////
 
98
    
 
99
    /** Return a subclass of SkScalarContext
 
100
    */
 
101
    static SkScalerContext* CreateScalerContext(const SkDescriptor* desc);
 
102
 
 
103
    /** Return a scalercontext using the "fallback" font. If there is no designated
 
104
        fallback, return null.
 
105
    */
 
106
    static SkScalerContext* CreateFallbackScalerContext(const SkScalerContext::Rec&);
 
107
 
 
108
    /** Return the number of bytes (approx) that should be purged from the font
 
109
        cache. The input parameter is the cache's estimate of how much as been
 
110
        allocated by the cache so far.
 
111
        To purge (basically) everything, return the input parameter.
 
112
        To purge nothing, return 0
 
113
    */
 
114
    static size_t ShouldPurgeFontCache(size_t sizeAllocatedSoFar);
 
115
 
 
116
    /** Return SkScalerContext gamma flag, or 0, based on the paint that will be
 
117
        used to draw something with antialiasing.
 
118
    */
 
119
    static int ComputeGammaFlag(const SkPaint& paint);
 
120
 
 
121
    /** Return NULL or a pointer to 256 bytes for the black (table[0]) and
 
122
        white (table[1]) gamma tables.
 
123
    */
 
124
    static void GetGammaTables(const uint8_t* tables[2]);
 
125
};
 
126
 
 
127
#endif
 
128