1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2014 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef SkRemotableFontMgr_DEFINED 9cb93a386Sopenharmony_ci#define SkRemotableFontMgr_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/core/SkFontStyle.h" 12cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 13cb93a386Sopenharmony_ci#include "include/core/SkTypes.h" 14cb93a386Sopenharmony_ci#include "include/private/SkTemplates.h" 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ciclass SkDataTable; 17cb93a386Sopenharmony_ciclass SkStreamAsset; 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_cistruct SK_API SkFontIdentity { 20cb93a386Sopenharmony_ci static const uint32_t kInvalidDataId = 0xFFFFFFFF; 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci // Note that fDataId is a data identifier, not a font identifier. 23cb93a386Sopenharmony_ci // (fDataID, fTtcIndex) can be seen as a font identifier. 24cb93a386Sopenharmony_ci uint32_t fDataId; 25cb93a386Sopenharmony_ci uint32_t fTtcIndex; 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci // On Linux/FontConfig there is also the ability to specify preferences for rendering 28cb93a386Sopenharmony_ci // antialias, embedded bitmaps, autohint, hinting, hintstyle, lcd rendering 29cb93a386Sopenharmony_ci // may all be set or set to no-preference 30cb93a386Sopenharmony_ci // (No-preference is resolved against globals set by the platform) 31cb93a386Sopenharmony_ci // Since they may be selected against, these are really 'extensions' to SkFontStyle. 32cb93a386Sopenharmony_ci // SkFontStyle should pick these up. 33cb93a386Sopenharmony_ci SkFontStyle fFontStyle; 34cb93a386Sopenharmony_ci}; 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ciclass SK_API SkRemotableFontIdentitySet : public SkRefCnt { 37cb93a386Sopenharmony_cipublic: 38cb93a386Sopenharmony_ci SkRemotableFontIdentitySet(int count, SkFontIdentity** data); 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ci int count() const { return fCount; } 41cb93a386Sopenharmony_ci const SkFontIdentity& at(int index) const { return fData[index]; } 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci static SkRemotableFontIdentitySet* NewEmpty(); 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_ciprivate: 46cb93a386Sopenharmony_ci SkRemotableFontIdentitySet() : fCount(0), fData() { } 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci friend SkRemotableFontIdentitySet* sk_remotable_font_identity_set_new(); 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci int fCount; 51cb93a386Sopenharmony_ci SkAutoTArray<SkFontIdentity> fData; 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ci using INHERITED = SkRefCnt; 54cb93a386Sopenharmony_ci}; 55cb93a386Sopenharmony_ci 56cb93a386Sopenharmony_ciclass SK_API SkRemotableFontMgr : public SkRefCnt { 57cb93a386Sopenharmony_cipublic: 58cb93a386Sopenharmony_ci /** 59cb93a386Sopenharmony_ci * Returns all of the fonts with the given familyIndex. 60cb93a386Sopenharmony_ci * Returns NULL if the index is out of bounds. 61cb93a386Sopenharmony_ci * Returns empty if there are no fonts at the given index. 62cb93a386Sopenharmony_ci * 63cb93a386Sopenharmony_ci * The caller must unref() the returned object. 64cb93a386Sopenharmony_ci */ 65cb93a386Sopenharmony_ci virtual SkRemotableFontIdentitySet* getIndex(int familyIndex) const = 0; 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci /** 68cb93a386Sopenharmony_ci * Returns the closest match to the given style in the given index. 69cb93a386Sopenharmony_ci * If there are no available fonts at the given index, the return value's 70cb93a386Sopenharmony_ci * data id will be kInvalidDataId. 71cb93a386Sopenharmony_ci */ 72cb93a386Sopenharmony_ci virtual SkFontIdentity matchIndexStyle(int familyIndex, const SkFontStyle&) const = 0; 73cb93a386Sopenharmony_ci 74cb93a386Sopenharmony_ci /** 75cb93a386Sopenharmony_ci * Returns all the fonts on the system with the given name. 76cb93a386Sopenharmony_ci * If the given name is NULL, will return the default font family. 77cb93a386Sopenharmony_ci * Never returns NULL; will return an empty set if the name is not found. 78cb93a386Sopenharmony_ci * 79cb93a386Sopenharmony_ci * It is possible that this will return fonts not accessible from 80cb93a386Sopenharmony_ci * getIndex(int) or matchIndexStyle(int, SkFontStyle) due to 81cb93a386Sopenharmony_ci * hidden or auto-activated fonts. 82cb93a386Sopenharmony_ci * 83cb93a386Sopenharmony_ci * The matching may be done in a system dependent way. The name may be 84cb93a386Sopenharmony_ci * matched case-insensitive, there may be system aliases which resolve, 85cb93a386Sopenharmony_ci * and names outside the current locale may be considered. However, this 86cb93a386Sopenharmony_ci * should only return fonts which are somehow associated with the requested 87cb93a386Sopenharmony_ci * name. 88cb93a386Sopenharmony_ci * 89cb93a386Sopenharmony_ci * The caller must unref() the returned object. 90cb93a386Sopenharmony_ci */ 91cb93a386Sopenharmony_ci virtual SkRemotableFontIdentitySet* matchName(const char familyName[]) const = 0; 92cb93a386Sopenharmony_ci 93cb93a386Sopenharmony_ci /** 94cb93a386Sopenharmony_ci * Returns the closest matching font to the specified name and style. 95cb93a386Sopenharmony_ci * If there are no available fonts which match the name, the return value's 96cb93a386Sopenharmony_ci * data id will be kInvalidDataId. 97cb93a386Sopenharmony_ci * If the given name is NULL, the match will be against any default fonts. 98cb93a386Sopenharmony_ci * 99cb93a386Sopenharmony_ci * It is possible that this will return a font identity not accessible from 100cb93a386Sopenharmony_ci * methods returning sets due to hidden or auto-activated fonts. 101cb93a386Sopenharmony_ci * 102cb93a386Sopenharmony_ci * The matching may be done in a system dependent way. The name may be 103cb93a386Sopenharmony_ci * matched case-insensitive, there may be system aliases which resolve, 104cb93a386Sopenharmony_ci * and names outside the current locale may be considered. However, this 105cb93a386Sopenharmony_ci * should only return a font which is somehow associated with the requested 106cb93a386Sopenharmony_ci * name. 107cb93a386Sopenharmony_ci * 108cb93a386Sopenharmony_ci * The caller must unref() the returned object. 109cb93a386Sopenharmony_ci */ 110cb93a386Sopenharmony_ci virtual SkFontIdentity matchNameStyle(const char familyName[], const SkFontStyle&) const = 0; 111cb93a386Sopenharmony_ci 112cb93a386Sopenharmony_ci /** 113cb93a386Sopenharmony_ci * Use the system fall-back to find a font for the given character. 114cb93a386Sopenharmony_ci * If no font can be found for the character, the return value's data id 115cb93a386Sopenharmony_ci * will be kInvalidDataId. 116cb93a386Sopenharmony_ci * If the name is NULL, the match will start against any default fonts. 117cb93a386Sopenharmony_ci * If the bpc47 is NULL, a default locale will be assumed. 118cb93a386Sopenharmony_ci * 119cb93a386Sopenharmony_ci * Note that bpc47 is a combination of ISO 639, 15924, and 3166-1 codes, 120cb93a386Sopenharmony_ci * so it is fine to just pass a ISO 639 here. 121cb93a386Sopenharmony_ci */ 122cb93a386Sopenharmony_ci virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&, 123cb93a386Sopenharmony_ci const char* bcp47[], int bcp47Count, 124cb93a386Sopenharmony_ci SkUnichar character) const=0; 125cb93a386Sopenharmony_ci 126cb93a386Sopenharmony_ci /** 127cb93a386Sopenharmony_ci * Returns the data for the given data id. 128cb93a386Sopenharmony_ci * Will return NULL if the data id is invalid. 129cb93a386Sopenharmony_ci * Note that this is a data id, not a font id. 130cb93a386Sopenharmony_ci * 131cb93a386Sopenharmony_ci * The caller must unref() the returned object. 132cb93a386Sopenharmony_ci */ 133cb93a386Sopenharmony_ci virtual SkStreamAsset* getData(int dataId) const = 0; 134cb93a386Sopenharmony_ci 135cb93a386Sopenharmony_ciprivate: 136cb93a386Sopenharmony_ci using INHERITED = SkRefCnt; 137cb93a386Sopenharmony_ci}; 138cb93a386Sopenharmony_ci 139cb93a386Sopenharmony_ci#endif 140