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 132880df2609eba09b555ca37be04b6ad89290c765Tom Hudson#include "../private/SkOncePtr.h" 142880df2609eba09b555ca37be04b6ad89290c765Tom Hudson#include "../private/SkWeakRefCnt.h" 15a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman#include "SkFontStyle.h" 1639a9a5069b25aa8b9529118cfd0ece5f412fb56breed#include "SkRect.h" 1739a9a5069b25aa8b9529118cfd0ece5f412fb56breed#include "SkString.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgclass SkDescriptor; 2041868fe5625fc3bd70daa3f461c881b5db6a9265bungemanclass SkFontData; 21dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgclass SkFontDescriptor; 22dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgclass SkScalerContext; 23dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.orgstruct SkScalerContextRec; 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkStream; 255f213d9627d2eefa7da81cd97f36754f75eb4ae9bungemanclass SkStreamAsset; 26c48b2b330f8bf0e01381e27ca36f48ef5c7d8d5fvandebo@chromium.orgclass SkAdvancedTypefaceMetrics; 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkWStream; 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 292f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.comtypedef uint32_t SkFontID; 30ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com/** Machine endian. */ 31f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.comtypedef uint32_t SkFontTableTag; 322f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkTypeface 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The SkTypeface class specifies the typeface and intrinsic style of a font. 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This is used in the paint, along with optionally algorithmic settings like 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com textSize, textSkewX, textScaleX, kFakeBoldText_Mask, to specify 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com how text appears when drawn (and measured). 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 40069b827f8e4f8ca212548719db64983a69b8dc25reed@android.com Typeface objects are immutable, and so they can be shared between threads. 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 42a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.comclass SK_API SkTypeface : public SkWeakRefCnt { 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Style specifies the intrinsic style attributes of a given typeface 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Style { 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kNormal = 0, 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBold = 0x01, 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kItalic = 0x02, 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // helpers 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kBoldItalic = 0x03 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 55a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman /** Returns the typeface's intrinsic style attributes. */ 56a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman SkFontStyle fontStyle() const { 57a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman return fStyle; 58a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman } 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 60a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman /** Returns the typeface's intrinsic style attributes. 61a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman * @deprecated use fontStyle() instead. 62a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman */ 63a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman Style style() const { 64a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman return static_cast<Style>( 65a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman (fStyle.weight() >= SkFontStyle::kSemiBold_Weight ? kBold : kNormal) | 66a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman (fStyle.slant() != SkFontStyle::kUpright_Slant ? kItalic : kNormal)); 67a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman } 6843b8b36b20ae00e2d78421c4cda1f3f922983a20bungeman 69a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman /** Returns true if style() has the kBold bit set. */ 70a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman bool isBold() const { return fStyle.weight() >= SkFontStyle::kSemiBold_Weight; } 71a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman 72a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman /** Returns true if style() has the kItalic bit set. */ 73a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman bool isItalic() const { return fStyle.slant() != SkFontStyle::kUpright_Slant; } 745b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 75fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com /** Returns true if the typeface claims to be fixed-pitch. 76fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com * This is a style bit, advance widths may vary even if this returns true. 77875b4ecef79fd61f7d23260928638bcca4133751reed@google.com */ 78fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com bool isFixedPitch() const { return fIsFixedPitch; } 79875b4ecef79fd61f7d23260928638bcca4133751reed@google.com 80ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com /** Return a 32bit value for this typeface, unique for the underlying font 81ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com data. Will never return 0. 82ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com */ 832f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com SkFontID uniqueID() const { return fUniqueID; } 84fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the uniqueID for the specified typeface. If the face is null, 86b1d9d2ef2803bd55fdc886d13033b48f8450dd14reed@android.com resolve it to the default font and return its uniqueID. Will never 87b1d9d2ef2803bd55fdc886d13033b48f8450dd14reed@android.com return 0. 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 892f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com static SkFontID UniqueID(const SkTypeface* face); 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 91ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com /** Returns true if the two typefaces reference the same underlying font, 92ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com handling either being null (treating null as the default font) 93ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com */ 94ef772ddb86e9ab5e7e2811c67ed75a24f3ce0e5ereed@android.com static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); 955b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 96fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com /** 97fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com * Returns a ref() to the default typeface. The caller must call unref() 98fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com * when they are done referencing the object. Never returns NULL. 99fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com */ 1004fa748d5801df66e46e6f4e98e07523d44d261a2djsollen@google.com static SkTypeface* RefDefault(Style style = SkTypeface::kNormal); 101fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new reference to the typeface that most closely matches the 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com requested familyName and style. Pass null as the familyName to return 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the default font for the requested style. Will never return null 1055b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param familyName May be NULL. The name of the font family. 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param style The style (normal, bold, italic) of the typeface. 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return reference to the closest-matching typeface. Call must call 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unref() when they are done. 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 111069b827f8e4f8ca212548719db64983a69b8dc25reed@android.com static SkTypeface* CreateFromName(const char familyName[], Style style); 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new reference to the typeface that most closely matches the 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com requested typeface and specified Style. Use this call if you want to 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com pick a new style from the same family of the existing typeface. 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If family is NULL, this selects from the default font's family. 1175b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param family May be NULL. The name of the existing type face. 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param s The style (normal, bold, italic) of the type face. 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return reference to the closest-matching typeface. Call must call 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com unref() when they are done. 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new typeface given a file. If the file does not exist, or is 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not a valid font file, returns null. 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 128d71b75757335393d9643a5b7a0f2769b6ba52fb6bungeman static SkTypeface* CreateFromFile(const char path[], int index = 0); 1295b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a new typeface given a stream. If the stream is 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com not a valid font file, returns null. Ownership of the stream is 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com transferred, so the caller must not reference it again. 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1345f213d9627d2eefa7da81cd97f36754f75eb4ae9bungeman static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 13641868fe5625fc3bd70daa3f461c881b5db6a9265bungeman /** Return a new typeface given font data and configuration. If the data 13741868fe5625fc3bd70daa3f461c881b5db6a9265bungeman is not valid font data, returns null. Ownership of the font data is 13841868fe5625fc3bd70daa3f461c881b5db6a9265bungeman transferred, so the caller must not reference it again. 13941868fe5625fc3bd70daa3f461c881b5db6a9265bungeman */ 14041868fe5625fc3bd70daa3f461c881b5db6a9265bungeman static SkTypeface* CreateFromFontData(SkFontData*); 14141868fe5625fc3bd70daa3f461c881b5db6a9265bungeman 14262533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com /** Write a unique signature to a stream, sufficient to reconstruct a 14362533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com typeface referencing the same font when Deserialize is called. 14462533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com */ 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void serialize(SkWStream*) const; 1465b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 14762533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com /** Given the data previously written by serialize(), return a new instance 14862533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com to a typeface referring to the same font. If that font is not available, 14962533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com return null. If an instance is returned, the caller is responsible for 15062533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com calling unref() when they are done with it. 151a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo Does not affect ownership of SkStream. 15262533ed6bb490e9abf5d02686d897a93c5e85d51reed@android.com */ 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static SkTypeface* Deserialize(SkStream*); 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 155bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com enum Encoding { 156bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com kUTF8_Encoding, 157bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com kUTF16_Encoding, 158bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com kUTF32_Encoding 159bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com }; 160bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 161bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com /** 162bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * Given an array of character codes, of the specified encoding, 163bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * optionally return their corresponding glyph IDs (if glyphs is not NULL). 164bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * 165bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param chars pointer to the array of character codes 1663c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com * @param encoding how the characters are encoded 167bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param glyphs (optional) returns the corresponding glyph IDs for each 168bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * character code, up to glyphCount values. If a character code is 169bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * not found in the typeface, the corresponding glyph ID will be 0. 170bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @param glyphCount number of code points in 'chars' to process. If glyphs 171bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * is not NULL, then it must point sufficient memory to write 172bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * glyphCount values into it. 173bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * @return the number of number of continuous non-zero glyph IDs computed 174bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * from the beginning of chars. This value is valid, even if the 175bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * glyphs parameter is NULL. 176bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com */ 177bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int charsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], 178bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int glyphCount) const; 179bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 180bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com /** 181bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com * Return the number of glyphs in the typeface. 182bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com */ 183bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com int countGlyphs() const; 184bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 185f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com // Table getters -- may fail if the underlying font format is not organized 186f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com // as 4-byte tables. 187f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com 188f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Return the number of tables in the font. */ 189f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com int countTables() const; 190fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 191f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Copy into tags[] (allocated by the caller) the list of table tags in 192f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * the font, and return the number. This will be the same as CountTables() 193f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * or 0 if an error occured. If tags == NULL, this only returns the count 194f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * (the same as calling countTables()). 195f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com */ 196f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com int getTableTags(SkFontTableTag tags[]) const; 197fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 198f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Given a table tag, return the size of its contents, or 0 if not present 199f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com */ 200f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com size_t getTableSize(SkFontTableTag) const; 201fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 202f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com /** Copy the contents of a table into data (allocated by the caller). Note 203f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * that the contents of the table will be in their native endian order 204f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * (which for most truetype tables is big endian). If the table tag is 205f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * not found, or there is an error copying the data, then 0 is returned. 206f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * If this happens, it is possible that some or all of the memory pointed 207f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * to by data may have been written to, even though an error has occured. 208fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com * 209f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param fontID the font to copy the table from 210f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param tag The table tag whose contents are to be copied 211f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param offset The offset in bytes into the table's contents where the 212f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * copy should start from. 213f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param length The number of bytes, starting at offset, of table data 214f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * to copy. 215f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @param data storage address where the table contents are copied to 216f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * @return the number of bytes actually copied into data. If offset+length 217f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * exceeds the table's size, then only the bytes up to the table's 218f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * size are actually copied, and this is the value returned. If 219f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * offset > the table's size, or tag is not a valid table, 220f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com * then 0 is returned. 221f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com */ 222f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com size_t getTableData(SkFontTableTag tag, size_t offset, size_t length, 223f11508d7f4aae52739b9c4f3bb2da2fd78fa23d9reed@google.com void* data) const; 2244b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com 2254b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com /** 2264b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com * Return the units-per-em value for this typeface, or zero if there is an 2274b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com * error. 2284b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com */ 2294b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com int getUnitsPerEm() const; 2304b2af9c91d39c2176a32e7ba42a0276dca68034areed@google.com 23135fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com /** 23235fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * Given a run of glyphs, return the associated horizontal adjustments. 23335fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * Adjustments are in "design units", which are integers relative to the 23435fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * typeface's units per em (see getUnitsPerEm). 23535fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * 23635fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * Some typefaces are known to never support kerning. Calling this method 23735fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * with all zeros (e.g. getKerningPairAdustments(NULL, 0, NULL)) returns 23835fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * a boolean indicating if the typeface might support kerning. If it 23935fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * returns false, then it will always return false (no kerning) for all 24035fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * possible glyph runs. If it returns true, then it *may* return true for 24135fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * somne glyph runs. 24235fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * 24335fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * If count is non-zero, then the glyphs parameter must point to at least 24435fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * [count] valid glyph IDs, and the adjustments parameter must be 24535fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * sized to at least [count - 1] entries. If the method returns true, then 24635fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * [count-1] entries in the adjustments array will be set. If the method 24735fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * returns false, then no kerning should be applied, and the adjustments 24835fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * array will be in an undefined state (possibly some values may have been 24935fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com * written, but none of them should be interpreted as valid values). 25035fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com */ 25135fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com bool getKerningPairAdjustments(const uint16_t glyphs[], int count, 25235fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com int32_t adjustments[]) const; 25335fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com 254a980269c2498836101146adc729ef780fb89824ebungeman@google.com struct LocalizedString { 255a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkString fString; 256a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkString fLanguage; 257a980269c2498836101146adc729ef780fb89824ebungeman@google.com }; 258a980269c2498836101146adc729ef780fb89824ebungeman@google.com class LocalizedStrings : ::SkNoncopyable { 259a980269c2498836101146adc729ef780fb89824ebungeman@google.com public: 260a980269c2498836101146adc729ef780fb89824ebungeman@google.com virtual ~LocalizedStrings() { } 261a980269c2498836101146adc729ef780fb89824ebungeman@google.com virtual bool next(LocalizedString* localizedString) = 0; 2622880df2609eba09b555ca37be04b6ad89290c765Tom Hudson void unref() { delete this; } 263a980269c2498836101146adc729ef780fb89824ebungeman@google.com }; 264a980269c2498836101146adc729ef780fb89824ebungeman@google.com /** 265a980269c2498836101146adc729ef780fb89824ebungeman@google.com * Returns an iterator which will attempt to enumerate all of the 266a980269c2498836101146adc729ef780fb89824ebungeman@google.com * family names specified by the font. 267839702b61934914118ec557dd641be322eba3b5fbungeman@google.com * It is the caller's responsibility to unref() the returned pointer. 268a980269c2498836101146adc729ef780fb89824ebungeman@google.com */ 269839702b61934914118ec557dd641be322eba3b5fbungeman@google.com LocalizedStrings* createFamilyNameIterator() const; 270a980269c2498836101146adc729ef780fb89824ebungeman@google.com 2712cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com /** 27208df48d2411b33a9078f1621894d630f0b11cd60reed@google.com * Return the family name for this typeface. It will always be returned 27308df48d2411b33a9078f1621894d630f0b11cd60reed@google.com * encoded as UTF8, but the language of the name is whatever the host 27408df48d2411b33a9078f1621894d630f0b11cd60reed@google.com * platform chooses. 27508df48d2411b33a9078f1621894d630f0b11cd60reed@google.com */ 27608df48d2411b33a9078f1621894d630f0b11cd60reed@google.com void getFamilyName(SkString* name) const; 27708df48d2411b33a9078f1621894d630f0b11cd60reed@google.com 27808df48d2411b33a9078f1621894d630f0b11cd60reed@google.com /** 2792cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * Return a stream for the contents of the font data, or NULL on failure. 2802cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * If ttcIndex is not null, it is set to the TrueTypeCollection index 2812cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * of this typeface within the stream, or 0 if the stream is not a 2822cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com * collection. 283a1193e4b0e34a7e4e1bd33e9708d7341679f8321scroggo * The caller is responsible for deleting the stream. 2842cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com */ 2855f213d9627d2eefa7da81cd97f36754f75eb4ae9bungeman SkStreamAsset* openStream(int* ttcIndex) const; 28684e22d847fc84727bc220947162363ee1fe068fcreed@google.com 28784e22d847fc84727bc220947162363ee1fe068fcreed@google.com /** 28841868fe5625fc3bd70daa3f461c881b5db6a9265bungeman * Return the font data, or NULL on failure. 28941868fe5625fc3bd70daa3f461c881b5db6a9265bungeman * The caller is responsible for deleting the font data. 29041868fe5625fc3bd70daa3f461c881b5db6a9265bungeman */ 29141868fe5625fc3bd70daa3f461c881b5db6a9265bungeman SkFontData* createFontData() const; 29241868fe5625fc3bd70daa3f461c881b5db6a9265bungeman 29341868fe5625fc3bd70daa3f461c881b5db6a9265bungeman /** 29484e22d847fc84727bc220947162363ee1fe068fcreed@google.com * Return a scalercontext for the given descriptor. If this fails, then 29584e22d847fc84727bc220947162363ee1fe068fcreed@google.com * if allowFailure is true, this returns NULL, else it returns a 29684e22d847fc84727bc220947162363ee1fe068fcreed@google.com * dummy scalercontext that will not crash, but will draw nothing. 29784e22d847fc84727bc220947162363ee1fe068fcreed@google.com */ 29884e22d847fc84727bc220947162363ee1fe068fcreed@google.com SkScalerContext* createScalerContext(const SkDescriptor*, 29984e22d847fc84727bc220947162363ee1fe068fcreed@google.com bool allowFailure = false) const; 300fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com 301a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed /** 302a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed * Return a rectangle (scaled to 1-pt) that represents the union of the bounds of all 303a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed * of the glyphs, but each one positioned at (0,). This may be conservatively large, and 304a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed * will not take into account any hinting or other size-specific adjustments. 305a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed */ 306a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed SkRect getBounds() const; 307a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed 3087edec140391ce06933cc1506d96bb70093b63c7breed@google.com // PRIVATE / EXPERIMENTAL -- do not call 3097edec140391ce06933cc1506d96bb70093b63c7breed@google.com void filterRec(SkScalerContextRec* rec) const { 3107edec140391ce06933cc1506d96bb70093b63c7breed@google.com this->onFilterRec(rec); 3117edec140391ce06933cc1506d96bb70093b63c7breed@google.com } 3127edec140391ce06933cc1506d96bb70093b63c7breed@google.com // PRIVATE / EXPERIMENTAL -- do not call 3137edec140391ce06933cc1506d96bb70093b63c7breed@google.com void getFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { 3147edec140391ce06933cc1506d96bb70093b63c7breed@google.com this->onGetFontDescriptor(desc, isLocal); 3157edec140391ce06933cc1506d96bb70093b63c7breed@google.com } 3167edec140391ce06933cc1506d96bb70093b63c7breed@google.com 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 31839a9a5069b25aa8b9529118cfd0ece5f412fb56breed // The type of advance data wanted. 31939a9a5069b25aa8b9529118cfd0ece5f412fb56breed enum PerGlyphInfo { 32039a9a5069b25aa8b9529118cfd0ece5f412fb56breed kNo_PerGlyphInfo = 0x0, // Don't populate any per glyph info. 32139a9a5069b25aa8b9529118cfd0ece5f412fb56breed kHAdvance_PerGlyphInfo = 0x1, // Populate horizontal advance data. 32239a9a5069b25aa8b9529118cfd0ece5f412fb56breed kVAdvance_PerGlyphInfo = 0x2, // Populate vertical advance data. 32339a9a5069b25aa8b9529118cfd0ece5f412fb56breed kGlyphNames_PerGlyphInfo = 0x4, // Populate glyph names (Type 1 only). 32439a9a5069b25aa8b9529118cfd0ece5f412fb56breed kToUnicode_PerGlyphInfo = 0x8 // Populate ToUnicode table, ignored 32539a9a5069b25aa8b9529118cfd0ece5f412fb56breed // for Type 1 fonts 32639a9a5069b25aa8b9529118cfd0ece5f412fb56breed }; 32739a9a5069b25aa8b9529118cfd0ece5f412fb56breed 328dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org /** uniqueID must be unique and non-zero 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 330a4c4a2d8cd65abb1e5ac20813831cdb9ace6c7eebungeman SkTypeface(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch = false); 3312f3dc9dc4c970bd066be329a842a791d91f524e2reed@google.com virtual ~SkTypeface(); 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 333fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com /** Sets the fixedPitch bit. If used, must be called in the constructor. */ 334fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com void setIsFixedPitch(bool isFixedPitch) { fIsFixedPitch = isFixedPitch; } 335fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com 336cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com friend class SkScalerContext; 3374fa748d5801df66e46e6f4e98e07523d44d261a2djsollen@google.com static SkTypeface* GetDefaultTypeface(Style style = SkTypeface::kNormal); 338cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com 3390da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0; 3400da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com virtual void onFilterRec(SkScalerContextRec*) const = 0; 3412689f615e364dc48ad73826564f5b13d2329179dreed@google.com virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 34239a9a5069b25aa8b9529118cfd0ece5f412fb56breed PerGlyphInfo, 3432689f615e364dc48ad73826564f5b13d2329179dreed@google.com const uint32_t* glyphIDs, 3442689f615e364dc48ad73826564f5b13d2329179dreed@google.com uint32_t glyphIDsCount) const = 0; 34535fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com 3465f213d9627d2eefa7da81cd97f36754f75eb4ae9bungeman virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0; 34741868fe5625fc3bd70daa3f461c881b5db6a9265bungeman // TODO: make pure virtual. 34841868fe5625fc3bd70daa3f461c881b5db6a9265bungeman virtual SkFontData* onCreateFontData() const; 34941868fe5625fc3bd70daa3f461c881b5db6a9265bungeman 3505526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0; 351c1641fc92259a1ca5cfc32cd5c8c55ea316b2bd1skia.committer@gmail.com 352bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], 3533c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphCount) const = 0; 3547bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com virtual int onCountGlyphs() const = 0; 355bcb42aecf1bdb9ae80d766d203b4f636b954cf03reed@google.com 3567bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com virtual int onGetUPEM() const = 0; 35735fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, 35835fe7372b1b897a77578a220c334e1fb36d144e9reed@google.com int32_t adjustments[]) const; 3592cdc6713fb04c46ecbc73a724029a8b266004ddfreed@google.com 360b374d6a62c0259387d90cad74753d8bad9ee1beabungeman /** Returns the family name of the typeface as known by its font manager. 361b374d6a62c0259387d90cad74753d8bad9ee1beabungeman * This name may or may not be produced by the family name iterator. 362b374d6a62c0259387d90cad74753d8bad9ee1beabungeman */ 363b374d6a62c0259387d90cad74753d8bad9ee1beabungeman virtual void onGetFamilyName(SkString* familyName) const = 0; 364b374d6a62c0259387d90cad74753d8bad9ee1beabungeman 365b374d6a62c0259387d90cad74753d8bad9ee1beabungeman /** Returns an iterator over the family names in the font. */ 366839702b61934914118ec557dd641be322eba3b5fbungeman@google.com virtual LocalizedStrings* onCreateFamilyNameIterator() const = 0; 367a980269c2498836101146adc729ef780fb89824ebungeman@google.com 368ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com virtual int onGetTableTags(SkFontTableTag tags[]) const = 0; 369dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org virtual size_t onGetTableData(SkFontTableTag, size_t offset, 370ddc218e508c4cdd16ff3461498cbbc2b5189b2bebungeman@google.com size_t length, void* data) const = 0; 371dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org 372a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed virtual bool onComputeBounds(SkRect*) const; 373a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 37599f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com friend class SkGTypeface; 3762880df2609eba09b555ca37be04b6ad89290c765Tom Hudson friend class SkRandomTypeface; 37799f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com friend class SkPDFFont; 37899f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com friend class SkPDFCIDFont; 379855d83ff79c6c822b2ad653f2f890178ad0f637bcdalton friend class GrPathRendering; 380855d83ff79c6c822b2ad653f2f890178ad0f637bcdalton friend class GrGLPathRendering; 38199f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com 38299f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com /** Retrieve detailed typeface metrics. Used by the PDF backend. 38399f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com @param perGlyphInfo Indicate what glyph specific information (advances, 38499f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com names, etc.) should be populated. 38599f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com @param glyphIDs For per-glyph info, specify subset of the font by 38699f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com giving glyph ids. Each integer represents a glyph 38799f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com id. Passing NULL means all glyphs in the font. 38899f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if 38999f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com glyphIDs is NULL. 39099f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com @return The returned object has already been referenced. 39199f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com */ 39299f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( 39339a9a5069b25aa8b9529118cfd0ece5f412fb56breed PerGlyphInfo, 39499f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com const uint32_t* glyphIDs = NULL, 39599f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com uint32_t glyphIDsCount = 0) const; 39699f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.com 39799f381ad769cc13b0f23c99c47b65c3f236e15ccreed@google.comprivate: 39878358bf624c7e7c09ffccf638c50870808d884d6mtklein static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int, not a Style. 39978358bf624c7e7c09ffccf638c50870808d884d6mtklein static void DeleteDefault(SkTypeface*); 40018b75e54ab64763615e09761fcaeb3f439835f59bungeman@google.com 4012880df2609eba09b555ca37be04b6ad89290c765Tom Hudson SkOncePtr<SkRect> fLazyBounds; 402a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed SkFontID fUniqueID; 403a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed SkFontStyle fStyle; 404a0c814cffb7ba91e1c3b533e68ab591d9cee8f2breed bool fIsFixedPitch; 4055b31b0f1eaca0cdc3aa5697e8efa1baf68b0774ereed@google.com 406fed86bdb8b9f037439bbfa7cdbd53a581dbc5985reed@google.com friend class SkPaint; 40790808e87c21e93b8e670360655e0b0eb12cb2f87reed@google.com friend class SkGlyphCache; // GetDefaultTypeface 408dc09f07671145b21c83de7153c9c9b950c871f1amike@reedtribe.org 409a02bc1519cf49afa31fb38bed097dd5014880d04bungeman@google.com typedef SkWeakRefCnt INHERITED; 4108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 4118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 413