SkTypeface.h revision 08df48d2411b33a9078f1621894d630f0b11cd60
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkTypeface_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkTypeface_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
13325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org#include "SkAdvancedTypefaceMetrics.h"
14a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.com#include "SkWeakRefCnt.h"
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
16dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgclass SkDescriptor;
17dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgclass SkFontDescriptor;
18dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgclass SkScalerContext;
19dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgstruct SkScalerContextRec;
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkStream;
21c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.orgclass SkAdvancedTypefaceMetrics;
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkWStream;
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
242f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.comtypedef uint32_t SkFontID;
25f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.comtypedef uint32_t SkFontTableTag;
262f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkTypeface
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    The SkTypeface class specifies the typeface and intrinsic style of a font.
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    This is used in the paint, along with optionally algorithmic settings like
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    textSize, textSkewX, textScaleX, kFakeBoldText_Mask, to specify
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    how text appears when drawn (and measured).
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
34069b827f8e4f8ca212548719db64983a69b8dc25reed@android.com    Typeface objects are immutable, and so they can be shared between threads.
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
36a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.comclass SK_API SkTypeface : public SkWeakRefCnt {
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
38fcb57b5570ec8b3176d4025d4c44d145591f819creed@google.com    SK_DECLARE_INST_COUNT(SkTypeface)
39fcb57b5570ec8b3176d4025d4c44d145591f819creed@google.com
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Style specifies the intrinsic style attributes of a given typeface
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    enum Style {
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kNormal = 0,
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kBold   = 0x01,
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kItalic = 0x02,
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        // helpers
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        kBoldItalic = 0x03
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns the typeface's intrinsic style attributes
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Style style() const { return fStyle; }
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if getStyle() has the kBold bit set.
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isBold() const { return (fStyle & kBold) != 0; }
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Returns true if getStyle() has the kItalic bit set.
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isItalic() const { return (fStyle & kItalic) != 0; }
625b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
63fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com    /** Returns true if the typeface claims to be fixed-pitch.
64fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com     *  This is a style bit, advance widths may vary even if this returns true.
65875b4ecef79fd61f7d23260928638bcca4133751reed@google.com     */
66fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com    bool isFixedPitch() const { return fIsFixedPitch; }
67875b4ecef79fd61f7d23260928638bcca4133751reed@google.com
68ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com    /** Return a 32bit value for this typeface, unique for the underlying font
69ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com        data. Will never return 0.
70ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com     */
712f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com    SkFontID uniqueID() const { return fUniqueID; }
72fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the uniqueID for the specified typeface. If the face is null,
74b1d9d2ef2803bd55fdc886d13033b48f8450dd14reed@android.com        resolve it to the default font and return its uniqueID. Will never
75b1d9d2ef2803bd55fdc886d13033b48f8450dd14reed@android.com        return 0.
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
772f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com    static SkFontID UniqueID(const SkTypeface* face);
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
79ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com    /** Returns true if the two typefaces reference the same underlying font,
80ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com        handling either being null (treating null as the default font)
81ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com     */
82ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com    static bool Equal(const SkTypeface* facea, const SkTypeface* faceb);
835b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
84fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com    /**
85fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com     *  Returns a ref() to the default typeface. The caller must call unref()
86fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com     *  when they are done referencing the object. Never returns NULL.
87fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com     */
884fa748d5801df66e46e6f4e98e07523d44d261a2djsollen@google.com    static SkTypeface* RefDefault(Style style = SkTypeface::kNormal);
89fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return a new reference to the typeface that most closely matches the
918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        requested familyName and style. Pass null as the familyName to return
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the default font for the requested style. Will never return null
935b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param familyName  May be NULL. The name of the font family.
958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param style       The style (normal, bold, italic) of the typeface.
968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return reference to the closest-matching typeface. Call must call
978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                unref() when they are done.
988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
99069b827f8e4f8ca212548719db64983a69b8dc25reed@android.com    static SkTypeface* CreateFromName(const char familyName[], Style style);
1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return a new reference to the typeface that most closely matches the
1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        requested typeface and specified Style. Use this call if you want to
1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        pick a new style from the same family of the existing typeface.
1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        If family is NULL, this selects from the default font's family.
1055b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param family  May be NULL. The name of the existing type face.
1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @param s       The style (normal, bold, italic) of the type face.
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        @return reference to the closest-matching typeface. Call must call
1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com                unref() when they are done.
1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s);
1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return a new typeface given a file. If the file does not exist, or is
1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        not a valid font file, returns null.
1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkTypeface* CreateFromFile(const char path[]);
1175b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return a new typeface given a stream. If the stream is
1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        not a valid font file, returns null. Ownership of the stream is
1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        transferred, so the caller must not reference it again.
1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkTypeface* CreateFromStream(SkStream* stream);
1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
12462533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com    /** Write a unique signature to a stream, sufficient to reconstruct a
12562533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com        typeface referencing the same font when Deserialize is called.
12662533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com     */
1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void serialize(SkWStream*) const;
1285b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
12962533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com    /** Given the data previously written by serialize(), return a new instance
13062533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com        to a typeface referring to the same font. If that font is not available,
13162533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com        return null. If an instance is returned, the caller is responsible for
13262533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com        calling unref() when they are done with it.
13362533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com     */
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkTypeface* Deserialize(SkStream*);
1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
136c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.org    /** Retrieve detailed typeface metrics.  Used by the PDF backend.
137325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org        @param perGlyphInfo Indicate what glyph specific information (advances,
138325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org                            names, etc.) should be populated.
13937ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org        @param glyphIDs  For per-glyph info, specify subset of the font by
14037ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org                         giving glyph ids.  Each integer represents a glyph
14137ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org                         id.  Passing NULL means all glyphs in the font.
14237ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org        @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
14337ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org                             glyphIDs is NULL.
144c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.org        @return The returned object has already been referenced.
1452a22e10ab2946c5590cd2a258427ce3ccfca9bfavandebo@chromium.org     */
146c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.org    SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics(
14737ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org            SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
14837ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org            const uint32_t* glyphIDs = NULL,
14937ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org            uint32_t glyphIDsCount = 0) const;
150325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org
151bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    enum Encoding {
152bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com        kUTF8_Encoding,
153bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com        kUTF16_Encoding,
154bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com        kUTF32_Encoding
155bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    };
156bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com
157bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    /**
158bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  Given an array of character codes, of the specified encoding,
159bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  optionally return their corresponding glyph IDs (if glyphs is not NULL).
160bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *
161bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  @param chars pointer to the array of character codes
162bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  @param encoding how the characteds are encoded
163bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  @param glyphs (optional) returns the corresponding glyph IDs for each
164bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *          character code, up to glyphCount values. If a character code is
165bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *          not found in the typeface, the corresponding glyph ID will be 0.
166bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  @param glyphCount number of code points in 'chars' to process. If glyphs
167bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *          is not NULL, then it must point sufficient memory to write
168bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *          glyphCount values into it.
169bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  @return the number of number of continuous non-zero glyph IDs computed
170bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *          from the beginning of chars. This value is valid, even if the
171bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *          glyphs parameter is NULL.
172bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     */
173bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    int charsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[],
174bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com                      int glyphCount) const;
175bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com
176bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    /**
177bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     *  Return the number of glyphs in the typeface.
178bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com     */
179bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    int countGlyphs() const;
180bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com
181f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    // Table getters -- may fail if the underlying font format is not organized
182f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    // as 4-byte tables.
183f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com
184f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    /** Return the number of tables in the font. */
185f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    int countTables() const;
186fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
187f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    /** Copy into tags[] (allocated by the caller) the list of table tags in
188f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  the font, and return the number. This will be the same as CountTables()
189f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  or 0 if an error occured. If tags == NULL, this only returns the count
190f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  (the same as calling countTables()).
191f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     */
192f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    int getTableTags(SkFontTableTag tags[]) const;
193fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
194f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    /** Given a table tag, return the size of its contents, or 0 if not present
195f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     */
196f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    size_t getTableSize(SkFontTableTag) const;
197fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
198f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    /** Copy the contents of a table into data (allocated by the caller). Note
199f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  that the contents of the table will be in their native endian order
200f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  (which for most truetype tables is big endian). If the table tag is
201f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  not found, or there is an error copying the data, then 0 is returned.
202f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  If this happens, it is possible that some or all of the memory pointed
203f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  to by data may have been written to, even though an error has occured.
204fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com     *
205f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  @param fontID the font to copy the table from
206f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  @param tag  The table tag whose contents are to be copied
207f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  @param offset The offset in bytes into the table's contents where the
208f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  copy should start from.
209f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  @param length The number of bytes, starting at offset, of table data
210f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  to copy.
211f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  @param data storage address where the table contents are copied to
212f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  @return the number of bytes actually copied into data. If offset+length
213f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  exceeds the table's size, then only the bytes up to the table's
214f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  size are actually copied, and this is the value returned. If
215f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  offset > the table's size, or tag is not a valid table,
216f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     *  then 0 is returned.
217f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com     */
218f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com    size_t getTableData(SkFontTableTag tag, size_t offset, size_t length,
219f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com                        void* data) const;
2204b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com
2214b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com    /**
2224b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com     *  Return the units-per-em value for this typeface, or zero if there is an
2234b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com     *  error.
2244b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com     */
2254b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com    int getUnitsPerEm() const;
2264b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com
2272cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com    /**
22808df48d2411b33a9078f1621894d630f0b11cd60reed@google.com     *  Return the family name for this typeface. It will always be returned
22908df48d2411b33a9078f1621894d630f0b11cd60reed@google.com     *  encoded as UTF8, but the language of the name is whatever the host
23008df48d2411b33a9078f1621894d630f0b11cd60reed@google.com     *  platform chooses.
23108df48d2411b33a9078f1621894d630f0b11cd60reed@google.com     */
23208df48d2411b33a9078f1621894d630f0b11cd60reed@google.com    void getFamilyName(SkString* name) const;
23308df48d2411b33a9078f1621894d630f0b11cd60reed@google.com
23408df48d2411b33a9078f1621894d630f0b11cd60reed@google.com    /**
2352cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com     *  Return a stream for the contents of the font data, or NULL on failure.
2362cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com     *  If ttcIndex is not null, it is set to the TrueTypeCollection index
2372cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com     *  of this typeface within the stream, or 0 if the stream is not a
2382cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com     *  collection.
2392cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com     */
240fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com    SkStream* openStream(int* ttcIndex) const;
24184e22d847fc84727bc220947162363ee1fe068fcreed@google.com
24284e22d847fc84727bc220947162363ee1fe068fcreed@google.com    /**
24384e22d847fc84727bc220947162363ee1fe068fcreed@google.com     *  Return a scalercontext for the given descriptor. If this fails, then
24484e22d847fc84727bc220947162363ee1fe068fcreed@google.com     *  if allowFailure is true, this returns NULL, else it returns a
24584e22d847fc84727bc220947162363ee1fe068fcreed@google.com     *  dummy scalercontext that will not crash, but will draw nothing.
24684e22d847fc84727bc220947162363ee1fe068fcreed@google.com     */
24784e22d847fc84727bc220947162363ee1fe068fcreed@google.com    SkScalerContext* createScalerContext(const SkDescriptor*,
24884e22d847fc84727bc220947162363ee1fe068fcreed@google.com                                         bool allowFailure = false) const;
249fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com
2507edec140391ce06933cc1506d96bb70093b63c7breed@google.com    // PRIVATE / EXPERIMENTAL -- do not call
2517edec140391ce06933cc1506d96bb70093b63c7breed@google.com    void filterRec(SkScalerContextRec* rec) const {
2527edec140391ce06933cc1506d96bb70093b63c7breed@google.com        this->onFilterRec(rec);
2537edec140391ce06933cc1506d96bb70093b63c7breed@google.com    }
2547edec140391ce06933cc1506d96bb70093b63c7breed@google.com    // PRIVATE / EXPERIMENTAL -- do not call
2557edec140391ce06933cc1506d96bb70093b63c7breed@google.com    void getFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const {
2567edec140391ce06933cc1506d96bb70093b63c7breed@google.com        this->onGetFontDescriptor(desc, isLocal);
2577edec140391ce06933cc1506d96bb70093b63c7breed@google.com    }
2587edec140391ce06933cc1506d96bb70093b63c7breed@google.com
2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
260dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org    /** uniqueID must be unique and non-zero
2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
262fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com    SkTypeface(Style style, SkFontID uniqueID, bool isFixedPitch = false);
2632f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com    virtual ~SkTypeface();
2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
265fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com    /** Sets the fixedPitch bit. If used, must be called in the constructor. */
266fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com    void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; }
267fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com
268cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com    friend class SkScalerContext;
2694fa748d5801df66e46e6f4e98e07523d44d261a2djsollen@google.com    static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal);
270cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com
2710da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com    virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0;
2720da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com    virtual void onFilterRec(SkScalerContextRec*) const = 0;
2732689f615e364dc48ad73826564f5b13d2329179dreed@google.com    virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
2742689f615e364dc48ad73826564f5b13d2329179dreed@google.com                        SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
2752689f615e364dc48ad73826564f5b13d2329179dreed@google.com                        const uint32_t* glyphIDs,
2762689f615e364dc48ad73826564f5b13d2329179dreed@google.com                        uint32_t glyphIDsCount) const = 0;
277292b1d4903a770a77282508054917b48fb989d49reed@google.com    virtual SkStream* onOpenStream(int* ttcIndex) const = 0;
2785526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com    virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0;
279c1641fc92259a1ca5cfc32cd5c8c55ea316b2bd1skia.committer@gmail.com
280bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com    virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
281bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com                                int glyphCount) const;
2827bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com    virtual int onCountGlyphs() const = 0;
283bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com
2847bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com    virtual int onGetUPEM() const = 0;
2852cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com
286dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org    virtual int onGetTableTags(SkFontTableTag tags[]) const;
287dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org    virtual size_t onGetTableData(SkFontTableTag, size_t offset,
288dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org                                  size_t length, void* data) const;
289dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org
2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
2912f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com    SkFontID    fUniqueID;
2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Style       fStyle;
293fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com    bool        fIsFixedPitch;
2945b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com
295fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com    friend class SkPaint;
29690808e87c21e93b8e670360655e0b0eb12cb2f87reed@google.com    friend class SkGlyphCache;  // GetDefaultTypeface
297dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org    // just so deprecated fonthost can call protected methods
298dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org    friend class SkFontHost;
299dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org
300a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.com    typedef SkWeakRefCnt INHERITED;
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
304