10910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project/* 20910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 30910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * 40910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 50910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * you may not use this file except in compliance with the License. 60910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * You may obtain a copy of the License at 70910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * 80910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 90910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * 100910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 110910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 120910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * See the License for the specific language governing permissions and 140910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project * limitations under the License. 150910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 160910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 170910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#ifndef SkFontHost_DEFINED 180910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#define SkFontHost_DEFINED 190910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 200910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#include "SkScalerContext.h" 210910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#include "SkTypeface.h" 220910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 230910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectclass SkDescriptor; 240910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectclass SkStream; 250910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectclass SkWStream; 260910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 27f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reedtypedef uint32_t SkFontTableTag; 28f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 290910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project/** \class SkFontHost 300910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 313298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project This class is ported to each environment. It is responsible for bridging 323298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project the gap between the (sort of) abstract class SkTypeface and the 333298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project platform-specific implementation that provides access to font files. 343298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 353298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project One basic task is for each create (subclass of) SkTypeface, the FontHost is 363298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project resonsible for assigning a uniqueID. The ID should be unique for the 373298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project underlying font file/data, not unique per typeface instance. Thus it is 383298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project possible/common to request a typeface for the same font more than once 393298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project (e.g. asking for the same font by name several times). The FontHost may 403298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project return seperate typeface instances in that case, or it may choose to use a 413298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project cache and return the same instance (but calling typeface->ref(), since the 423298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project caller is always responsible for calling unref() on each instance that is 433298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project returned). Either way, the fontID for those instance(s) will be the same. 443298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project In addition, the fontID should never be set to 0. That value is used as a 453298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project sentinel to indicate no-font-id. 463298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 473298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project The major aspects are: 483298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 1) Given either a name/style, return a subclass of SkTypeface that 493298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project references the closest matching font available on the host system. 503298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 2) Given the data for a font (either in a stream or a file name), return 513298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project a typeface that allows access to that data. 523298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 3) Each typeface instance carries a 32bit ID for its corresponding font. 533298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project SkFontHost turns that ID into a stream to access the font's data. 543298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 4) Given a font ID, return a subclass of SkScalerContext, which connects a 553298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project font scaler (e.g. freetype or other) to the font's data. 563298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 5) Utilites to manage the font cache (budgeting) and gamma correction 570910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project*/ 5835e2e62b55598210f6999fc2ea26ff8f41446ffeDerek Sollenbergerclass SK_API SkFontHost { 590910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Projectpublic: 603298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /** Return a new, closest matching typeface given either an existing family 6140528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger (specified by a typeface in that family) or by a familyName and a 6240528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger requested style, or by a set of Unicode codepoitns to cover in a given 6340528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger style. 6440528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger 1) If familyFace is null, use familyName. 6540528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger 2) If familyName is null, use data (UTF-16 to cover). 6640528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger 3) If all are null, return the default font that best matches style 670910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 683298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project static SkTypeface* CreateTypeface(const SkTypeface* familyFace, 6940528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger const char familyName[], 7040528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger const void* data, size_t bytelength, 713298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project SkTypeface::Style style); 723298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 733298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /** Return a new typeface given the data buffer. If the data does not 743298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project represent a valid font, returns null. 753298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 763298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project If a typeface instance is returned, the caller is responsible for 773298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project calling unref() on the typeface when they are finished with it. 783298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 793298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project The returned typeface may or may not have called ref() on the stream 803298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project parameter. If the typeface has not called ref(), then it may have made 813298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project a copy of the releveant data. In either case, the caller is still 823298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project responsible for its refcnt ownership of the stream. 830910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 843298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project static SkTypeface* CreateTypefaceFromStream(SkStream*); 850910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 860910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /** Return a new typeface from the specified file path. If the file does not 870910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project represent a valid font, this returns null. If a typeface is returned, 880910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project the caller is responsible for calling unref() when it is no longer used. 890910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 900910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static SkTypeface* CreateTypefaceFromFile(const char path[]); 91e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed 920910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /////////////////////////////////////////////////////////////////////////// 933298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 943298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /** Returns true if the specified unique ID matches an existing font. 953298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project Returning false is similar to calling OpenStream with an invalid ID, 963298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project which will return NULL in that case. 973298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project */ 98f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed static bool ValidFontID(SkFontID uniqueID); 993298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 1003298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /** Return a new stream to read the font data, or null if the uniqueID does 1013298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project not match an existing typeface. .The caller must call stream->unref() 1023298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project when it is finished reading the data. 1033298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project */ 104f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed static SkStream* OpenStream(SkFontID uniqueID); 1053298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 106e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed /** Some fonts are stored in files. If that is true for the fontID, then 107e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed this returns the byte length of the full file path. If path is not null, 108e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed then the full path is copied into path (allocated by the caller), up to 109e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed length bytes. If index is not null, then it is set to the truetype 110e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed collection index for this font, or 0 if the font is not in a collection. 111e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed 112e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed Note: GetFileName does not assume that path is a null-terminated string, 113e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed so when it succeeds, it only copies the bytes of the file name and 114e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed nothing else (i.e. it copies exactly the number of bytes returned by the 115e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed function. If the caller wants to treat path[] as a C string, it must be 116e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed sure that it is allocated at least 1 byte larger than the returned size, 117e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed and it must copy in the terminating 0. 118e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed 119e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed If the fontID does not correspond to a file, then the function returns 120e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed 0, and the path and index parameters are ignored. 121e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed 122e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed @param fontID The font whose file name is being queried 123e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed @param path Either NULL, or storage for receiving up to length bytes 124e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed of the font's file name. Allocated by the caller. 125e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed @param length The maximum space allocated in path (by the caller). 126e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed Ignored if path is NULL. 127e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed @param index Either NULL, or receives the TTC index for this font. 128e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed If the font is not a TTC, then will be set to 0. 129e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed @return The byte length of th font's file name, or 0 if the font is not 130e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed baked by a file. 131e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed */ 132e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed static size_t GetFileName(SkFontID fontID, char path[], size_t length, 133e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed int32_t* index); 134e3c6561496ef60345d830f1ab883afb1d1f251efMike Reed 1353298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /////////////////////////////////////////////////////////////////////////// 1360910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 1370910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /** Write a unique identifier to the stream, so that the same typeface can 1380910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project be retrieved with Deserialize(). 1390910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 1400910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static void Serialize(const SkTypeface*, SkWStream*); 1410910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 1423298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /** Given a stream created by Serialize(), return a new typeface (like 1433298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project CreateTypeface) or return NULL if no match is found. 1440910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 1450910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static SkTypeface* Deserialize(SkStream*); 1460910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 1470910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /////////////////////////////////////////////////////////////////////////// 1480910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 1490910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /** Return a subclass of SkScalarContext 1500910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 1510910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static SkScalerContext* CreateScalerContext(const SkDescriptor* desc); 1520910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 1530199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger /** 1540199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * Given a "current" fontID, return the next logical fontID to use 1550199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * when searching fonts for a given unicode value. Typically the caller 1560199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * will query a given font, and if a unicode value is not supported, they 1570199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * will call this, and if 0 is not returned, will search that font, and so 1580199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * on. This process must be finite, and when the fonthost sees a 1590199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * font with no logical successor, it must return 0. 1600199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * 1610199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * The original fontID is also provided. This is the initial font that was 1620199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * stored in the typeface of the caller. It is provided as an aid to choose 1630199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * the best next logical font. e.g. If the original font was bold or serif, 1640199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * but the 2nd in the logical chain was plain, then a subsequent call to 1650199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * get the 3rd can still inspect the original, and try to match its 1660199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger * stylistic attributes. 1670199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger */ 1680199fa7423f89a129da2b22a488f2c18e2e4727fDerek Sollenberger static SkFontID NextLogicalFont(SkFontID currFontID, SkFontID origFontID); 1690910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 1703298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project /////////////////////////////////////////////////////////////////////////// 171f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 172af2616552738d653d5453915d3236e7154b868cdMike Reed /** Given a filled-out rec, the fonthost may decide to modify it to reflect 173af2616552738d653d5453915d3236e7154b868cdMike Reed what the host is actually capable of fulfilling. For example, if the 174af2616552738d653d5453915d3236e7154b868cdMike Reed rec is requesting a level of hinting that, for this host, maps some 175af2616552738d653d5453915d3236e7154b868cdMike Reed other level (e.g. kFull -> kNormal), it should update the rec to reflect 176af2616552738d653d5453915d3236e7154b868cdMike Reed what will actually be done. This is an optimization so that the font 177af2616552738d653d5453915d3236e7154b868cdMike Reed cache does not contain different recs (i.e. keys) that in reality map to 178af2616552738d653d5453915d3236e7154b868cdMike Reed the same output. 179af2616552738d653d5453915d3236e7154b868cdMike Reed 180af2616552738d653d5453915d3236e7154b868cdMike Reed A lazy (but valid) fonthost can do nothing in its FilterRec routine. 181af2616552738d653d5453915d3236e7154b868cdMike Reed */ 182af2616552738d653d5453915d3236e7154b868cdMike Reed static void FilterRec(SkScalerContext::Rec* rec); 183af2616552738d653d5453915d3236e7154b868cdMike Reed 184af2616552738d653d5453915d3236e7154b868cdMike Reed /////////////////////////////////////////////////////////////////////////// 185af2616552738d653d5453915d3236e7154b868cdMike Reed 18640528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger /** Retrieve detailed typeface metrics. Used by the PDF backend. 18787b8e645865f9633f410c02252a0fd3feb18f09bDerek Sollenberger @param perGlyphInfo Indicate what glyph specific information (advances, 18887b8e645865f9633f410c02252a0fd3feb18f09bDerek Sollenberger names, etc.) should be populated. 18940528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger @return The returned object has already been referenced. NULL is 19040528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger returned if the font is not found. 19140528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger */ 19240528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger static SkAdvancedTypefaceMetrics* GetAdvancedTypefaceMetrics( 19387b8e645865f9633f410c02252a0fd3feb18f09bDerek Sollenberger SkFontID fontID, 19487b8e645865f9633f410c02252a0fd3feb18f09bDerek Sollenberger SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo); 19540528743dbb9ce7f39f093e0cdc47849ac8887cfDerek Sollenberger 196f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed /** Return the number of tables in the font 197f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed */ 198f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed static int CountTables(SkFontID); 199f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 200f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed /** Copy into tags[] (allocated by the caller) the list of table tags in 201f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed the font, and return the number. This will be the same as CountTables() 202f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed or 0 if an error occured. 203f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed */ 204f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed static int GetTableTags(SkFontID, SkFontTableTag[]); 205f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 206f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed /** Given a table tag, return the size of its contents, or 0 if not present 207f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed */ 208f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed static size_t GetTableSize(SkFontID, SkFontTableTag); 2093298d565d8a70b84f28b455f6289293883c85494The Android Open Source Project 210f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed /** Copy the contents of a table into data (allocated by the caller). Note 211f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed that the contents of the table will be in their native endian order 212f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed (which for most truetype tables is big endian). If the table tag is 213f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed not found, or there is an error copying the data, then 0 is returned. 214f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed If this happens, it is possible that some or all of the memory pointed 215f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed to by data may have been written to, even though an error has occured. 216f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 217f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed @param fontID the font to copy the table from 218f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed @param tag The table tag whose contents are to be copied 219f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed @param offset The offset in bytes into the table's contents where the 220f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed copy should start from. 221f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed @param length The number of bytes, starting at offset, of table data 222f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed to copy. 223f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed @param data storage address where the table contents are copied to 224f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed @return the number of bytes actually copied into data. If offset+length 225f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed exceeds the table's size, then only the bytes up to the table's 226f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed size are actually copied, and this is the value returned. If 227f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed offset > the table's size, or tag is not a valid table, 228f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed then 0 is returned. 229f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed */ 230f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed static size_t GetTableData(SkFontID fontID, SkFontTableTag tag, 231f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed size_t offset, size_t length, void* data); 232f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 233f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed /////////////////////////////////////////////////////////////////////////// 234f95abb54afa5469c53d3ac899ecbce8a386471c1Mike Reed 2350910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /** Return the number of bytes (approx) that should be purged from the font 2360910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project cache. The input parameter is the cache's estimate of how much as been 2370910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project allocated by the cache so far. 2380910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project To purge (basically) everything, return the input parameter. 2390910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project To purge nothing, return 0 2400910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 2410910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static size_t ShouldPurgeFontCache(size_t sizeAllocatedSoFar); 2420910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 2430910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /** Return SkScalerContext gamma flag, or 0, based on the paint that will be 2440910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project used to draw something with antialiasing. 2450910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 2460910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static int ComputeGammaFlag(const SkPaint& paint); 2470910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 2480910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project /** Return NULL or a pointer to 256 bytes for the black (table[0]) and 2490910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project white (table[1]) gamma tables. 2500910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project */ 2510910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project static void GetGammaTables(const uint8_t* tables[2]); 252af2616552738d653d5453915d3236e7154b868cdMike Reed 253af2616552738d653d5453915d3236e7154b868cdMike Reed /////////////////////////////////////////////////////////////////////////// 254af2616552738d653d5453915d3236e7154b868cdMike Reed 255af2616552738d653d5453915d3236e7154b868cdMike Reed /** LCDs either have their color elements arranged horizontally or 256af2616552738d653d5453915d3236e7154b868cdMike Reed vertically. When rendering subpixel glyphs we need to know which way 257af2616552738d653d5453915d3236e7154b868cdMike Reed round they are. 258af2616552738d653d5453915d3236e7154b868cdMike Reed 259af2616552738d653d5453915d3236e7154b868cdMike Reed Note, if you change this after startup, you'll need to flush the glyph 260af2616552738d653d5453915d3236e7154b868cdMike Reed cache because it'll have the wrong type of masks cached. 261af2616552738d653d5453915d3236e7154b868cdMike Reed */ 262af2616552738d653d5453915d3236e7154b868cdMike Reed enum LCDOrientation { 263af2616552738d653d5453915d3236e7154b868cdMike Reed kHorizontal_LCDOrientation = 0, //!< this is the default 264af2616552738d653d5453915d3236e7154b868cdMike Reed kVertical_LCDOrientation = 1, 265af2616552738d653d5453915d3236e7154b868cdMike Reed }; 266af2616552738d653d5453915d3236e7154b868cdMike Reed 267af2616552738d653d5453915d3236e7154b868cdMike Reed static void SetSubpixelOrientation(LCDOrientation orientation); 268af2616552738d653d5453915d3236e7154b868cdMike Reed static LCDOrientation GetSubpixelOrientation(); 269af2616552738d653d5453915d3236e7154b868cdMike Reed 270af2616552738d653d5453915d3236e7154b868cdMike Reed /** LCD color elements can vary in order. For subpixel text we need to know 271af2616552738d653d5453915d3236e7154b868cdMike Reed the order which the LCDs uses so that the color fringes are in the 272af2616552738d653d5453915d3236e7154b868cdMike Reed correct place. 273af2616552738d653d5453915d3236e7154b868cdMike Reed 274af2616552738d653d5453915d3236e7154b868cdMike Reed Note, if you change this after startup, you'll need to flush the glyph 275af2616552738d653d5453915d3236e7154b868cdMike Reed cache because it'll have the wrong type of masks cached. 2760a81c953145c77abea5ca1df9e84c62d9da96094Mike Reed 2770a81c953145c77abea5ca1df9e84c62d9da96094Mike Reed kNONE_LCDOrder means that the subpixel elements are not spatially 2780a81c953145c77abea5ca1df9e84c62d9da96094Mike Reed separated in any usable fashion. 2790a81c953145c77abea5ca1df9e84c62d9da96094Mike Reed */ 280af2616552738d653d5453915d3236e7154b868cdMike Reed enum LCDOrder { 281af2616552738d653d5453915d3236e7154b868cdMike Reed kRGB_LCDOrder = 0, //!< this is the default 282af2616552738d653d5453915d3236e7154b868cdMike Reed kBGR_LCDOrder = 1, 2830a81c953145c77abea5ca1df9e84c62d9da96094Mike Reed kNONE_LCDOrder = 2, 284af2616552738d653d5453915d3236e7154b868cdMike Reed }; 285af2616552738d653d5453915d3236e7154b868cdMike Reed 286af2616552738d653d5453915d3236e7154b868cdMike Reed static void SetSubpixelOrder(LCDOrder order); 287af2616552738d653d5453915d3236e7154b868cdMike Reed static LCDOrder GetSubpixelOrder(); 2882b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson 28905b6b4d746867a9fb02e14edfe1bf3685abeb813Derek Sollenberger#ifdef ANDROID 2902b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson /////////////////////////////////////////////////////////////////////////// 2912b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson 2922b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson /** 2932b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson * Return the number of font units per em. 2942b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson * 2952b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson * @param fontID the font to query. 2962b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson * @return the number of font units per em or 0 on error. 2972b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson */ 2982b910807112618cb20b689bc6ae20e0e211ed41cPeter Eliasson static uint32_t GetUnitsPerEm(SkFontID fontID); 29905b6b4d746867a9fb02e14edfe1bf3685abeb813Derek Sollenberger#endif 3000910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project}; 3010910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 3020910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project#endif 3030910916c0f7b951ee55c4b7c6358295b9bca0565The Android Open Source Project 304