reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 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 | |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 11 | #include "SkFontStyle.h" |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 12 | #include "SkRefCnt.h" |
reed@google.com | 80f5465 | 2013-02-25 22:19:20 +0000 | [diff] [blame] | 13 | #include "SkTypeface.h" |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * \class SkFontConfigInterface |
| 17 | * |
| 18 | * Provides SkFontHost clients with access to fontconfig services. They will |
| 19 | * access the global instance found in RefGlobal(). |
| 20 | */ |
reed@google.com | 86a44b8 | 2013-03-04 17:26:02 +0000 | [diff] [blame] | 21 | class SK_API SkFontConfigInterface : public SkRefCnt { |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 22 | public: |
| 23 | /** |
| 24 | * Returns the global SkFontConfigInterface instance, and if it is not |
| 25 | * NULL, calls ref() on it. The caller must balance this with a call to |
| 26 | * unref(). |
| 27 | */ |
| 28 | static SkFontConfigInterface* RefGlobal(); |
| 29 | |
| 30 | /** |
| 31 | * Replace the current global instance with the specified one, safely |
| 32 | * ref'ing the new instance, and unref'ing the previous. Returns its |
| 33 | * parameter (the new global instance). |
| 34 | */ |
| 35 | static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*); |
| 36 | |
| 37 | /** |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 38 | * This should be treated as private to the impl of SkFontConfigInterface. |
| 39 | * Callers should not change or expect any particular values. It is meant |
| 40 | * to be a union of possible storage types to aid the impl. |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 41 | */ |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 42 | struct FontIdentity { |
reed@google.com | 8c9737e | 2013-03-06 13:06:03 +0000 | [diff] [blame] | 43 | FontIdentity() : fID(0), fTTCIndex(0) {} |
| 44 | |
| 45 | bool operator==(const FontIdentity& other) const { |
| 46 | return fID == other.fID && |
| 47 | fTTCIndex == other.fTTCIndex && |
| 48 | fString == other.fString; |
| 49 | } |
| 50 | |
| 51 | uint32_t fID; |
| 52 | int32_t fTTCIndex; |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 53 | SkString fString; |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 54 | SkFontStyle fStyle; |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 55 | }; |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 58 | * Given a familyName and style, find the best match. |
| 59 | * |
| 60 | * If a match is found, return true and set its outFontIdentifier. |
| 61 | * If outFamilyName is not null, assign the found familyName to it |
| 62 | * (which may differ from the requested familyName). |
| 63 | * If outStyle is not null, assign the found style to it |
| 64 | * (which may differ from the requested style). |
| 65 | * |
| 66 | * If a match is not found, return false, and ignore all out parameters. |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 67 | */ |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 68 | virtual bool matchFamilyName(const char familyName[], |
| 69 | SkTypeface::Style requested, |
| 70 | FontIdentity* outFontIdentifier, |
| 71 | SkString* outFamilyName, |
| 72 | SkTypeface::Style* outStyle) = 0; |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 73 | |
| 74 | /** |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 75 | * Given a FontRef, open a stream to access its data, or return null |
| 76 | * if the FontRef's data is not available. The caller is responsible for |
| 77 | * calling stream->unref() when it is done accessing the data. |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 78 | */ |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 79 | virtual SkStream* openStream(const FontIdentity&) = 0; |
reed@google.com | d66045e | 2013-03-04 19:07:02 +0000 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Return a singleton instance of a direct subclass that calls into |
| 83 | * libfontconfig. This does not affect the refcnt of the returned instance. |
| 84 | */ |
| 85 | static SkFontConfigInterface* GetSingletonDirectInterface(); |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 86 | |
| 87 | // New APIS, which have default impls for now (which do nothing) |
| 88 | |
robertphillips@google.com | 21db1db | 2013-04-09 23:56:51 +0000 | [diff] [blame^] | 89 | virtual int countFamilies() { return 0; }; |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 90 | virtual int getFamilySet(int index, SkString* outFamilyName, |
robertphillips@google.com | 21db1db | 2013-04-09 23:56:51 +0000 | [diff] [blame^] | 91 | FontIdentity outIdentities[], int maxCount) { |
| 92 | return 0; |
| 93 | } |
reed@google.com | 54c6914 | 2013-04-09 15:54:52 +0000 | [diff] [blame] | 94 | virtual int matchFamilySet(const char familyName[], SkString* outFamilyName, |
robertphillips@google.com | 21db1db | 2013-04-09 23:56:51 +0000 | [diff] [blame^] | 95 | FontIdentity outIdentities[], int maxCount) { |
| 96 | return 0; |
| 97 | } |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | #endif |