| 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" |
| 12 | |
| 13 | /** |
| 14 | * \class SkFontConfigInterface |
| 15 | * |
| 16 | * Provides SkFontHost clients with access to fontconfig services. They will |
| 17 | * access the global instance found in RefGlobal(). |
| 18 | */ |
| 19 | class SkFontConfigInterface : public SkRefCnt { |
| 20 | public: |
| 21 | /** |
| 22 | * Returns the global SkFontConfigInterface instance, and if it is not |
| 23 | * NULL, calls ref() on it. The caller must balance this with a call to |
| 24 | * unref(). |
| 25 | */ |
| 26 | static SkFontConfigInterface* RefGlobal(); |
| 27 | |
| 28 | /** |
| 29 | * Replace the current global instance with the specified one, safely |
| 30 | * ref'ing the new instance, and unref'ing the previous. Returns its |
| 31 | * parameter (the new global instance). |
| 32 | */ |
| 33 | static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*); |
| 34 | |
| 35 | /** |
| 36 | * Given a familyName and style, find the best matching font and return |
| 37 | * its fileFaceID and actual style (if outStyle is not null) and return |
| 38 | * true. If no matching font can be found, ignore fileFaceID and outStyle |
| 39 | * and return false. |
| 40 | */ |
| 41 | virtual bool match(const char familyName[], SkTypeface::Style requested, |
| 42 | unsigned* fileFaceID, SkTypeface::Style* outStyle) = 0; |
| 43 | |
| 44 | /** |
| 45 | * Given a fileFaceID (returned by match), return the associated familyName |
| 46 | * and return true. If the associated name cannot be returned, ignore the |
| 47 | * name parameter, and return false. |
| 48 | */ |
| 49 | virtual bool getFamilyName(unsigned fileFaceID, SkString* name) = 0; |
| 50 | |
| 51 | /** |
| 52 | * Given a fileFaceID (returned by match), open a stream to access its |
| 53 | * data, which the caller while take ownership of (and will call unref() |
| 54 | * when they're through). On failure, return NULL. |
| 55 | */ |
| 56 | virtual SkStream* openStream(unsigned fileFaceID) = 0; |
| 57 | }; |
| 58 | |
| 59 | #endif |