| 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 | */ |
| 20 | class SkFontConfigInterface : public SkRefCnt { |
| 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 | /** |
| 37 | * Given a familyName and style, find the best matching font and return |
| 38 | * its fileFaceID and actual style (if outStyle is not null) and return |
| 39 | * true. If no matching font can be found, ignore fileFaceID and outStyle |
| 40 | * and return false. |
| 41 | */ |
| 42 | virtual bool match(const char familyName[], SkTypeface::Style requested, |
| 43 | unsigned* fileFaceID, SkTypeface::Style* outStyle) = 0; |
| 44 | |
| 45 | /** |
| 46 | * Given a fileFaceID (returned by match), return the associated familyName |
| 47 | * and return true. If the associated name cannot be returned, ignore the |
| 48 | * name parameter, and return false. |
| 49 | */ |
| 50 | virtual bool getFamilyName(unsigned fileFaceID, SkString* name) = 0; |
| 51 | |
| 52 | /** |
| 53 | * Given a fileFaceID (returned by match), open a stream to access its |
| 54 | * data, which the caller while take ownership of (and will call unref() |
| 55 | * when they're through). On failure, return NULL. |
| 56 | */ |
| 57 | virtual SkStream* openStream(unsigned fileFaceID) = 0; |
| 58 | }; |
| 59 | |
| 60 | #endif |