SkTypeface.h revision ddc218e508c4cdd16ff3461498cbbc2b5189b2be
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; 25ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com/** Machine endian. */ 26f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.comtypedef uint32_t SkFontTableTag; 272f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkTypeface 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The SkTypeface class specifies the typeface and intrinsic style of a font. 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This is used in the paint, along with optionally algorithmic settings like 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com textSize, textSkewX, textScaleX, kFakeBoldText_Mask, to specify 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com how text appears when drawn (and measured). 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 35069b827f8e4f8ca212548719db64983a69b8dc25reed@android.com Typeface objects are immutable, and so they can be shared between threads. 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 37a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.comclass SK_API SkTypeface : public SkWeakRefCnt { 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 39fcb57b5570ec8b3176d4025d4c44d145591f819creed@google.com SK_DECLARE_INST_COUNT(SkTypeface) 40fcb57b5570ec8b3176d4025d4c44d145591f819creed@google.com 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Style specifies the intrinsic style attributes of a given typeface 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Style { 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kNormal = 0, 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBold = 0x01, 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kItalic = 0x02, 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helpers 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBoldItalic = 0x03 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the typeface's intrinsic style attributes 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Style style() const { return fStyle; } 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if getStyle() has the kBold bit set. 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isBold() const { return (fStyle & kBold) != 0; } 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if getStyle() has the kItalic bit set. 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isItalic() const { return (fStyle & kItalic) != 0; } 635b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 64fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com /** Returns true if the typeface claims to be fixed-pitch. 65fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com * This is a style bit, advance widths may vary even if this returns true. 66875b4ecef79fd61f7d23260928638bcca4133751reed@google.com */ 67fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com bool isFixedPitch() const { return fIsFixedPitch; } 68875b4ecef79fd61f7d23260928638bcca4133751reed@google.com 69ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com /** Return a 32bit value for this typeface, unique for the underlying font 70ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com data. Will never return 0. 71ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com */ 722f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com SkFontID uniqueID() const { return fUniqueID; } 73fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the uniqueID for the specified typeface. If the face is null, 75b1d9d2ef2803bd55fdc886d13033b48f8450dd14reed@android.com resolve it to the default font and return its uniqueID. Will never 76b1d9d2ef2803bd55fdc886d13033b48f8450dd14reed@android.com return 0. 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 782f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com static SkFontID UniqueID(const SkTypeface* face); 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 80ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com /** Returns true if the two typefaces reference the same underlying font, 81ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com handling either being null (treating null as the default font) 82ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com */ 83ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); 845b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 85fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com /** 86fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com * Returns a ref() to the default typeface. The caller must call unref() 87fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com * when they are done referencing the object. Never returns NULL. 88fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com */ 894fa748d5801df66e46e6f4e98e07523d44d261a2djsollen@google.com static SkTypeface* RefDefault(Style style = SkTypeface::kNormal); 90fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new reference to the typeface that most closely matches the 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com requested familyName and style. Pass null as the familyName to return 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the default font for the requested style. Will never return null 945b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param familyName May be NULL. The name of the font family. 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param style The style (normal, bold, italic) of the typeface. 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return reference to the closest-matching typeface. Call must call 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unref() when they are done. 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 100069b827f8e4f8ca212548719db64983a69b8dc25reed@android.com static SkTypeface* CreateFromName(const char familyName[], Style style); 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new reference to the typeface that most closely matches the 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com requested typeface and specified Style. Use this call if you want to 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pick a new style from the same family of the existing typeface. 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If family is NULL, this selects from the default font's family. 1065b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param family May be NULL. The name of the existing type face. 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param s The style (normal, bold, italic) of the type face. 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return reference to the closest-matching typeface. Call must call 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unref() when they are done. 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new typeface given a file. If the file does not exist, or is 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not a valid font file, returns null. 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkTypeface* CreateFromFile(const char path[]); 1185b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new typeface given a stream. If the stream is 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not a valid font file, returns null. Ownership of the stream is 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com transferred, so the caller must not reference it again. 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkTypeface* CreateFromStream(SkStream* stream); 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 12562533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com /** Write a unique signature to a stream, sufficient to reconstruct a 12662533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com typeface referencing the same font when Deserialize is called. 12762533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com */ 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void serialize(SkWStream*) const; 1295b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 13062533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com /** Given the data previously written by serialize(), return a new instance 13162533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com to a typeface referring to the same font. If that font is not available, 13262533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com return null. If an instance is returned, the caller is responsible for 13362533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com calling unref() when they are done with it. 13462533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com */ 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkTypeface* Deserialize(SkStream*); 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 137c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.org /** Retrieve detailed typeface metrics. Used by the PDF backend. 138325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org @param perGlyphInfo Indicate what glyph specific information (advances, 139325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org names, etc.) should be populated. 14037ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org @param glyphIDs For per-glyph info, specify subset of the font by 14137ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org giving glyph ids. Each integer represents a glyph 14237ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org id. Passing NULL means all glyphs in the font. 14337ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if 14437ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org glyphIDs is NULL. 145c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.org @return The returned object has already been referenced. 1462a22e10ab2946c5590cd2a258427ce3ccfca9bfavandebo@chromium.org */ 147c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.org SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( 14837ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, 14937ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org const uint32_t* glyphIDs = NULL, 15037ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org uint32_t glyphIDsCount = 0) const; 151325cb9aa17b94258b362082eb3a799524f4345f3vandebo@chromium.org 152bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com enum Encoding { 153bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com kUTF8_Encoding, 154bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com kUTF16_Encoding, 155bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com kUTF32_Encoding 156bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com }; 157bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 158bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com /** 159bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * Given an array of character codes, of the specified encoding, 160bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * optionally return their corresponding glyph IDs (if glyphs is not NULL). 161bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * 162bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param chars pointer to the array of character codes 163bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param encoding how the characteds are encoded 164bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param glyphs (optional) returns the corresponding glyph IDs for each 165bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * character code, up to glyphCount values. If a character code is 166bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * not found in the typeface, the corresponding glyph ID will be 0. 167bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param glyphCount number of code points in 'chars' to process. If glyphs 168bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * is not NULL, then it must point sufficient memory to write 169bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * glyphCount values into it. 170bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @return the number of number of continuous non-zero glyph IDs computed 171bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * from the beginning of chars. This value is valid, even if the 172bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * glyphs parameter is NULL. 173bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com */ 174bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int charsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], 175bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int glyphCount) const; 176bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 177bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com /** 178bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * Return the number of glyphs in the typeface. 179bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com */ 180bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int countGlyphs() const; 181bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 182f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com // Table getters -- may fail if the underlying font format is not organized 183f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com // as 4-byte tables. 184f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com 185f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Return the number of tables in the font. */ 186f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com int countTables() const; 187fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 188f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Copy into tags[] (allocated by the caller) the list of table tags in 189f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * the font, and return the number. This will be the same as CountTables() 190f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * or 0 if an error occured. If tags == NULL, this only returns the count 191f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * (the same as calling countTables()). 192f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com */ 193f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com int getTableTags(SkFontTableTag tags[]) const; 194fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 195f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Given a table tag, return the size of its contents, or 0 if not present 196f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com */ 197f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com size_t getTableSize(SkFontTableTag) const; 198fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 199f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Copy the contents of a table into data (allocated by the caller). Note 200f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * that the contents of the table will be in their native endian order 201f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * (which for most truetype tables is big endian). If the table tag is 202f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * not found, or there is an error copying the data, then 0 is returned. 203f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * If this happens, it is possible that some or all of the memory pointed 204f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * to by data may have been written to, even though an error has occured. 205fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * 206f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param fontID the font to copy the table from 207f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param tag The table tag whose contents are to be copied 208f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param offset The offset in bytes into the table's contents where the 209f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * copy should start from. 210f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param length The number of bytes, starting at offset, of table data 211f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * to copy. 212f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param data storage address where the table contents are copied to 213f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @return the number of bytes actually copied into data. If offset+length 214f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * exceeds the table's size, then only the bytes up to the table's 215f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * size are actually copied, and this is the value returned. If 216f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * offset > the table's size, or tag is not a valid table, 217f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * then 0 is returned. 218f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com */ 219f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com size_t getTableData(SkFontTableTag tag, size_t offset, size_t length, 220f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com void* data) const; 2214b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com 2224b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com /** 2234b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com * Return the units-per-em value for this typeface, or zero if there is an 2244b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com * error. 2254b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com */ 2264b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com int getUnitsPerEm() const; 2274b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com 2282cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com /** 22908df48d2411b33a9078f1621894d630f0b11cd60reed@google.com * Return the family name for this typeface. It will always be returned 23008df48d2411b33a9078f1621894d630f0b11cd60reed@google.com * encoded as UTF8, but the language of the name is whatever the host 23108df48d2411b33a9078f1621894d630f0b11cd60reed@google.com * platform chooses. 23208df48d2411b33a9078f1621894d630f0b11cd60reed@google.com */ 23308df48d2411b33a9078f1621894d630f0b11cd60reed@google.com void getFamilyName(SkString* name) const; 23408df48d2411b33a9078f1621894d630f0b11cd60reed@google.com 23508df48d2411b33a9078f1621894d630f0b11cd60reed@google.com /** 2362cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * Return a stream for the contents of the font data, or NULL on failure. 2372cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * If ttcIndex is not null, it is set to the TrueTypeCollection index 2382cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * of this typeface within the stream, or 0 if the stream is not a 2392cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * collection. 2402cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com */ 241fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com SkStream* openStream(int* ttcIndex) const; 24284e22d847fc84727bc220947162363ee1fe068fcreed@google.com 24384e22d847fc84727bc220947162363ee1fe068fcreed@google.com /** 24430ddd615c447fed73286151b463af20d309c85f1reed@google.com * Search within this typeface's family for a best match to the 24530ddd615c447fed73286151b463af20d309c85f1reed@google.com * specified style, and return a ref to that typeface. Note: the 24630ddd615c447fed73286151b463af20d309c85f1reed@google.com * returned object could be this, if it is the best match, or it 24730ddd615c447fed73286151b463af20d309c85f1reed@google.com * could be a different typeface. Either way, the caller must balance 24830ddd615c447fed73286151b463af20d309c85f1reed@google.com * this call with unref() on the returned object. 24930ddd615c447fed73286151b463af20d309c85f1reed@google.com * 25030ddd615c447fed73286151b463af20d309c85f1reed@google.com * Will never return NULL. 25130ddd615c447fed73286151b463af20d309c85f1reed@google.com */ 25230ddd615c447fed73286151b463af20d309c85f1reed@google.com SkTypeface* refMatchingStyle(Style) const; 25330ddd615c447fed73286151b463af20d309c85f1reed@google.com 25430ddd615c447fed73286151b463af20d309c85f1reed@google.com /** 25584e22d847fc84727bc220947162363ee1fe068fcreed@google.com * Return a scalercontext for the given descriptor. If this fails, then 25684e22d847fc84727bc220947162363ee1fe068fcreed@google.com * if allowFailure is true, this returns NULL, else it returns a 25784e22d847fc84727bc220947162363ee1fe068fcreed@google.com * dummy scalercontext that will not crash, but will draw nothing. 25884e22d847fc84727bc220947162363ee1fe068fcreed@google.com */ 25984e22d847fc84727bc220947162363ee1fe068fcreed@google.com SkScalerContext* createScalerContext(const SkDescriptor*, 26084e22d847fc84727bc220947162363ee1fe068fcreed@google.com bool allowFailure = false) const; 261fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com 2627edec140391ce06933cc1506d96bb70093b63c7breed@google.com // PRIVATE / EXPERIMENTAL -- do not call 2637edec140391ce06933cc1506d96bb70093b63c7breed@google.com void filterRec(SkScalerContextRec* rec) const { 2647edec140391ce06933cc1506d96bb70093b63c7breed@google.com this->onFilterRec(rec); 2657edec140391ce06933cc1506d96bb70093b63c7breed@google.com } 2667edec140391ce06933cc1506d96bb70093b63c7breed@google.com // PRIVATE / EXPERIMENTAL -- do not call 2677edec140391ce06933cc1506d96bb70093b63c7breed@google.com void getFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { 2687edec140391ce06933cc1506d96bb70093b63c7breed@google.com this->onGetFontDescriptor(desc, isLocal); 2697edec140391ce06933cc1506d96bb70093b63c7breed@google.com } 2707edec140391ce06933cc1506d96bb70093b63c7breed@google.com 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 272dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org /** uniqueID must be unique and non-zero 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 274fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com SkTypeface(Style style, SkFontID uniqueID, bool isFixedPitch = false); 2752f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com virtual ~SkTypeface(); 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 277fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com /** Sets the fixedPitch bit. If used, must be called in the constructor. */ 278fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; } 279fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com 280cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com friend class SkScalerContext; 2814fa748d5801df66e46e6f4e98e07523d44d261a2djsollen@google.com static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal); 282cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com 2830da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0; 2840da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com virtual void onFilterRec(SkScalerContextRec*) const = 0; 2852689f615e364dc48ad73826564f5b13d2329179dreed@google.com virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 2862689f615e364dc48ad73826564f5b13d2329179dreed@google.com SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, 2872689f615e364dc48ad73826564f5b13d2329179dreed@google.com const uint32_t* glyphIDs, 2882689f615e364dc48ad73826564f5b13d2329179dreed@google.com uint32_t glyphIDsCount) const = 0; 289292b1d4903a770a77282508054917b48fb989d49reed@google.com virtual SkStream* onOpenStream(int* ttcIndex) const = 0; 2905526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0; 291c1641fc92259a1ca5cfc32cd5c8c55ea316b2bd1skia.committer@gmail.com 292bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], 293bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int glyphCount) const; 2947bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com virtual int onCountGlyphs() const = 0; 295bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 2967bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com virtual int onGetUPEM() const = 0; 2972cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com 298ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com virtual int onGetTableTags(SkFontTableTag tags[]) const = 0; 299dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org virtual size_t onGetTableData(SkFontTableTag, size_t offset, 300ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com size_t length, void* data) const = 0; 301dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org 302ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com virtual SkTypeface* onRefMatchingStyle(Style styleBits) const = 0; 30330ddd615c447fed73286151b463af20d309c85f1reed@google.com 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 3052f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com SkFontID fUniqueID; 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Style fStyle; 307fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com bool fIsFixedPitch; 3085b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 309fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com friend class SkPaint; 31090808e87c21e93b8e670360655e0b0eb12cb2f87reed@google.com friend class SkGlyphCache; // GetDefaultTypeface 311dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org // just so deprecated fonthost can call protected methods 312dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org friend class SkFontHost; 313dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org 314a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.com typedef SkWeakRefCnt INHERITED; 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 318