blob: 1e20438a0845eee61c5cda021cfcd460b8a8be30 [file] [log] [blame]
reed@google.comd71fe992013-02-25 20:38:07 +00001/*
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.com80f54652013-02-25 22:19:20 +000012#include "SkTypeface.h"
reed@google.comd71fe992013-02-25 20:38:07 +000013
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.com86a44b82013-03-04 17:26:02 +000020class SK_API SkFontConfigInterface : public SkRefCnt {
reed@google.comd71fe992013-02-25 20:38:07 +000021public:
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.comf71a2332013-02-27 19:06:30 +000037 * 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.comd71fe992013-02-25 20:38:07 +000040 */
reed@google.comf71a2332013-02-27 19:06:30 +000041 struct FontIdentity {
42 intptr_t fIntPtr;
43 SkString fString;
44 };
reed@google.comd71fe992013-02-25 20:38:07 +000045
46 /**
reed@google.comf71a2332013-02-27 19:06:30 +000047 * 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.comd71fe992013-02-25 20:38:07 +000056 */
reed@google.comf71a2332013-02-27 19:06:30 +000057 virtual bool matchFamilyName(const char familyName[],
58 SkTypeface::Style requested,
59 FontIdentity* outFontIdentifier,
60 SkString* outFamilyName,
61 SkTypeface::Style* outStyle) = 0;
reed@google.comd71fe992013-02-25 20:38:07 +000062
63 /**
reed@google.comf71a2332013-02-27 19:06:30 +000064 * 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.comd71fe992013-02-25 20:38:07 +000067 */
reed@google.comf71a2332013-02-27 19:06:30 +000068 virtual SkStream* openStream(const FontIdentity&) = 0;
reed@google.comd66045e2013-03-04 19:07:02 +000069
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.comd71fe992013-02-25 20:38:07 +000075};
76
77#endif