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 | |
| 11 | #include "SkRefCnt.h" |
reed@google.com | 80f5465 | 2013-02-25 22:19:20 +0000 | [diff] [blame] | 12 | #include "SkTypeface.h" |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 86a44b8 | 2013-03-04 17:26:02 +0000 | [diff] [blame] | 20 | class SK_API SkFontConfigInterface : public SkRefCnt { |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 21 | public: |
| 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 | /** |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 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. |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 40 | */ |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 41 | struct FontIdentity { |
| 42 | intptr_t fIntPtr; |
| 43 | SkString fString; |
| 44 | }; |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 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. |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 56 | */ |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 57 | virtual bool matchFamilyName(const char familyName[], |
| 58 | SkTypeface::Style requested, |
| 59 | FontIdentity* outFontIdentifier, |
| 60 | SkString* outFamilyName, |
| 61 | SkTypeface::Style* outStyle) = 0; |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
reed@google.com | f71a233 | 2013-02-27 19:06:30 +0000 | [diff] [blame] | 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. |
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 SkStream* openStream(const FontIdentity&) = 0; |
reed@google.com | d66045e | 2013-03-04 19:07:02 +0000 | [diff] [blame] | 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(); |
reed@google.com | d71fe99 | 2013-02-25 20:38:07 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | #endif |