Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkFontConfigInterface_DEFINED |
michael@0 | 9 | #define SkFontConfigInterface_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkDataTable.h" |
michael@0 | 12 | #include "SkFontStyle.h" |
michael@0 | 13 | #include "SkRefCnt.h" |
michael@0 | 14 | #include "SkTArray.h" |
michael@0 | 15 | #include "SkTypeface.h" |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * \class SkFontConfigInterface |
michael@0 | 19 | * |
michael@0 | 20 | * Provides SkFontHost clients with access to fontconfig services. They will |
michael@0 | 21 | * access the global instance found in RefGlobal(). |
michael@0 | 22 | */ |
michael@0 | 23 | class SK_API SkFontConfigInterface : public SkRefCnt { |
michael@0 | 24 | public: |
michael@0 | 25 | SK_DECLARE_INST_COUNT(SkFontConfigInterface) |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Returns the global SkFontConfigInterface instance, and if it is not |
michael@0 | 29 | * NULL, calls ref() on it. The caller must balance this with a call to |
michael@0 | 30 | * unref(). |
michael@0 | 31 | */ |
michael@0 | 32 | static SkFontConfigInterface* RefGlobal(); |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * Replace the current global instance with the specified one, safely |
michael@0 | 36 | * ref'ing the new instance, and unref'ing the previous. Returns its |
michael@0 | 37 | * parameter (the new global instance). |
michael@0 | 38 | */ |
michael@0 | 39 | static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*); |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * This should be treated as private to the impl of SkFontConfigInterface. |
michael@0 | 43 | * Callers should not change or expect any particular values. It is meant |
michael@0 | 44 | * to be a union of possible storage types to aid the impl. |
michael@0 | 45 | */ |
michael@0 | 46 | struct FontIdentity { |
michael@0 | 47 | FontIdentity() : fID(0), fTTCIndex(0) {} |
michael@0 | 48 | |
michael@0 | 49 | bool operator==(const FontIdentity& other) const { |
michael@0 | 50 | return fID == other.fID && |
michael@0 | 51 | fTTCIndex == other.fTTCIndex && |
michael@0 | 52 | fString == other.fString; |
michael@0 | 53 | } |
michael@0 | 54 | bool operator!=(const FontIdentity& other) const { |
michael@0 | 55 | return !(*this == other); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | uint32_t fID; |
michael@0 | 59 | int32_t fTTCIndex; |
michael@0 | 60 | SkString fString; |
michael@0 | 61 | SkFontStyle fStyle; |
michael@0 | 62 | |
michael@0 | 63 | // If buffer is NULL, just return the number of bytes that would have |
michael@0 | 64 | // been written. Will pad contents to a multiple of 4. |
michael@0 | 65 | size_t writeToMemory(void* buffer = NULL) const; |
michael@0 | 66 | |
michael@0 | 67 | // Recreate from a flattened buffer, returning the number of bytes read. |
michael@0 | 68 | size_t readFromMemory(const void* buffer, size_t length); |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Given a familyName and style, find the best match. |
michael@0 | 73 | * |
michael@0 | 74 | * If a match is found, return true and set its outFontIdentifier. |
michael@0 | 75 | * If outFamilyName is not null, assign the found familyName to it |
michael@0 | 76 | * (which may differ from the requested familyName). |
michael@0 | 77 | * If outStyle is not null, assign the found style to it |
michael@0 | 78 | * (which may differ from the requested style). |
michael@0 | 79 | * |
michael@0 | 80 | * If a match is not found, return false, and ignore all out parameters. |
michael@0 | 81 | */ |
michael@0 | 82 | virtual bool matchFamilyName(const char familyName[], |
michael@0 | 83 | SkTypeface::Style requested, |
michael@0 | 84 | FontIdentity* outFontIdentifier, |
michael@0 | 85 | SkString* outFamilyName, |
michael@0 | 86 | SkTypeface::Style* outStyle) = 0; |
michael@0 | 87 | |
michael@0 | 88 | /** |
michael@0 | 89 | * Given a FontRef, open a stream to access its data, or return null |
michael@0 | 90 | * if the FontRef's data is not available. The caller is responsible for |
michael@0 | 91 | * calling stream->unref() when it is done accessing the data. |
michael@0 | 92 | */ |
michael@0 | 93 | virtual SkStream* openStream(const FontIdentity&) = 0; |
michael@0 | 94 | |
michael@0 | 95 | /** |
michael@0 | 96 | * Return a singleton instance of a direct subclass that calls into |
michael@0 | 97 | * libfontconfig. This does not affect the refcnt of the returned instance. |
michael@0 | 98 | */ |
michael@0 | 99 | static SkFontConfigInterface* GetSingletonDirectInterface(); |
michael@0 | 100 | |
michael@0 | 101 | // New APIS, which have default impls for now (which do nothing) |
michael@0 | 102 | |
michael@0 | 103 | virtual SkDataTable* getFamilyNames() { return SkDataTable::NewEmpty(); } |
michael@0 | 104 | virtual bool matchFamilySet(const char inFamilyName[], |
michael@0 | 105 | SkString* outFamilyName, |
michael@0 | 106 | SkTArray<FontIdentity>*) { |
michael@0 | 107 | return false; |
michael@0 | 108 | } |
michael@0 | 109 | typedef SkRefCnt INHERITED; |
michael@0 | 110 | }; |
michael@0 | 111 | |
michael@0 | 112 | #endif |