SkFontConfigInterface.h revision d66045ec7d37720309dae4879efc01793c3e746a
1/* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkFontConfigInterface_DEFINED 9#define SkFontConfigInterface_DEFINED 10 11#include "SkRefCnt.h" 12#include "SkTypeface.h" 13 14/** 15 * \class SkFontConfigInterface 16 * 17 * Provides SkFontHost clients with access to fontconfig services. They will 18 * access the global instance found in RefGlobal(). 19 */ 20class SK_API SkFontConfigInterface : public SkRefCnt { 21public: 22 /** 23 * Returns the global SkFontConfigInterface instance, and if it is not 24 * NULL, calls ref() on it. The caller must balance this with a call to 25 * unref(). 26 */ 27 static SkFontConfigInterface* RefGlobal(); 28 29 /** 30 * Replace the current global instance with the specified one, safely 31 * ref'ing the new instance, and unref'ing the previous. Returns its 32 * parameter (the new global instance). 33 */ 34 static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*); 35 36 /** 37 * This should be treated as private to the impl of SkFontConfigInterface. 38 * Callers should not change or expect any particular values. It is meant 39 * to be a union of possible storage types to aid the impl. 40 */ 41 struct FontIdentity { 42 intptr_t fIntPtr; 43 SkString fString; 44 }; 45 46 /** 47 * Given a familyName and style, find the best match. 48 * 49 * If a match is found, return true and set its outFontIdentifier. 50 * If outFamilyName is not null, assign the found familyName to it 51 * (which may differ from the requested familyName). 52 * If outStyle is not null, assign the found style to it 53 * (which may differ from the requested style). 54 * 55 * If a match is not found, return false, and ignore all out parameters. 56 */ 57 virtual bool matchFamilyName(const char familyName[], 58 SkTypeface::Style requested, 59 FontIdentity* outFontIdentifier, 60 SkString* outFamilyName, 61 SkTypeface::Style* outStyle) = 0; 62 63 /** 64 * Given a FontRef, open a stream to access its data, or return null 65 * if the FontRef's data is not available. The caller is responsible for 66 * calling stream->unref() when it is done accessing the data. 67 */ 68 virtual SkStream* openStream(const FontIdentity&) = 0; 69 70 /** 71 * Return a singleton instance of a direct subclass that calls into 72 * libfontconfig. This does not affect the refcnt of the returned instance. 73 */ 74 static SkFontConfigInterface* GetSingletonDirectInterface(); 75}; 76 77#endif 78