michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkFontConfigInterface_DEFINED michael@0: #define SkFontConfigInterface_DEFINED michael@0: michael@0: #include "SkDataTable.h" michael@0: #include "SkFontStyle.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkTArray.h" michael@0: #include "SkTypeface.h" michael@0: michael@0: /** michael@0: * \class SkFontConfigInterface michael@0: * michael@0: * Provides SkFontHost clients with access to fontconfig services. They will michael@0: * access the global instance found in RefGlobal(). michael@0: */ michael@0: class SK_API SkFontConfigInterface : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkFontConfigInterface) michael@0: michael@0: /** michael@0: * Returns the global SkFontConfigInterface instance, and if it is not michael@0: * NULL, calls ref() on it. The caller must balance this with a call to michael@0: * unref(). michael@0: */ michael@0: static SkFontConfigInterface* RefGlobal(); michael@0: michael@0: /** michael@0: * Replace the current global instance with the specified one, safely michael@0: * ref'ing the new instance, and unref'ing the previous. Returns its michael@0: * parameter (the new global instance). michael@0: */ michael@0: static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*); michael@0: michael@0: /** michael@0: * This should be treated as private to the impl of SkFontConfigInterface. michael@0: * Callers should not change or expect any particular values. It is meant michael@0: * to be a union of possible storage types to aid the impl. michael@0: */ michael@0: struct FontIdentity { michael@0: FontIdentity() : fID(0), fTTCIndex(0) {} michael@0: michael@0: bool operator==(const FontIdentity& other) const { michael@0: return fID == other.fID && michael@0: fTTCIndex == other.fTTCIndex && michael@0: fString == other.fString; michael@0: } michael@0: bool operator!=(const FontIdentity& other) const { michael@0: return !(*this == other); michael@0: } michael@0: michael@0: uint32_t fID; michael@0: int32_t fTTCIndex; michael@0: SkString fString; michael@0: SkFontStyle fStyle; michael@0: michael@0: // If buffer is NULL, just return the number of bytes that would have michael@0: // been written. Will pad contents to a multiple of 4. michael@0: size_t writeToMemory(void* buffer = NULL) const; michael@0: michael@0: // Recreate from a flattened buffer, returning the number of bytes read. michael@0: size_t readFromMemory(const void* buffer, size_t length); michael@0: }; michael@0: michael@0: /** michael@0: * Given a familyName and style, find the best match. michael@0: * michael@0: * If a match is found, return true and set its outFontIdentifier. michael@0: * If outFamilyName is not null, assign the found familyName to it michael@0: * (which may differ from the requested familyName). michael@0: * If outStyle is not null, assign the found style to it michael@0: * (which may differ from the requested style). michael@0: * michael@0: * If a match is not found, return false, and ignore all out parameters. michael@0: */ michael@0: virtual bool matchFamilyName(const char familyName[], michael@0: SkTypeface::Style requested, michael@0: FontIdentity* outFontIdentifier, michael@0: SkString* outFamilyName, michael@0: SkTypeface::Style* outStyle) = 0; michael@0: michael@0: /** michael@0: * Given a FontRef, open a stream to access its data, or return null michael@0: * if the FontRef's data is not available. The caller is responsible for michael@0: * calling stream->unref() when it is done accessing the data. michael@0: */ michael@0: virtual SkStream* openStream(const FontIdentity&) = 0; michael@0: michael@0: /** michael@0: * Return a singleton instance of a direct subclass that calls into michael@0: * libfontconfig. This does not affect the refcnt of the returned instance. michael@0: */ michael@0: static SkFontConfigInterface* GetSingletonDirectInterface(); michael@0: michael@0: // New APIS, which have default impls for now (which do nothing) michael@0: michael@0: virtual SkDataTable* getFamilyNames() { return SkDataTable::NewEmpty(); } michael@0: virtual bool matchFamilySet(const char inFamilyName[], michael@0: SkString* outFamilyName, michael@0: SkTArray*) { michael@0: return false; michael@0: } michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif