blob: 0769362c8b31c8a5c4598f6af5f897e5f34a44fa [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 {
reed@google.com8c9737e2013-03-06 13:06:03 +000042 FontIdentity() : fID(0), fTTCIndex(0) {}
43
44 bool operator==(const FontIdentity& other) const {
45 return fID == other.fID &&
46 fTTCIndex == other.fTTCIndex &&
47 fString == other.fString;
48 }
49
50 uint32_t fID;
51 int32_t fTTCIndex;
reed@google.comf71a2332013-02-27 19:06:30 +000052 SkString fString;
53 };
reed@google.comd71fe992013-02-25 20:38:07 +000054
55 /**
reed@google.comf71a2332013-02-27 19:06:30 +000056 * Given a familyName and style, find the best match.
57 *
58 * If a match is found, return true and set its outFontIdentifier.
59 * If outFamilyName is not null, assign the found familyName to it
60 * (which may differ from the requested familyName).
61 * If outStyle is not null, assign the found style to it
62 * (which may differ from the requested style).
63 *
64 * If a match is not found, return false, and ignore all out parameters.
reed@google.comd71fe992013-02-25 20:38:07 +000065 */
reed@google.comf71a2332013-02-27 19:06:30 +000066 virtual bool matchFamilyName(const char familyName[],
67 SkTypeface::Style requested,
68 FontIdentity* outFontIdentifier,
69 SkString* outFamilyName,
70 SkTypeface::Style* outStyle) = 0;
reed@google.comd71fe992013-02-25 20:38:07 +000071
72 /**
reed@google.comf71a2332013-02-27 19:06:30 +000073 * Given a FontRef, open a stream to access its data, or return null
74 * if the FontRef's data is not available. The caller is responsible for
75 * calling stream->unref() when it is done accessing the data.
reed@google.comd71fe992013-02-25 20:38:07 +000076 */
reed@google.comf71a2332013-02-27 19:06:30 +000077 virtual SkStream* openStream(const FontIdentity&) = 0;
reed@google.comd66045e2013-03-04 19:07:02 +000078
79 /**
80 * Return a singleton instance of a direct subclass that calls into
81 * libfontconfig. This does not affect the refcnt of the returned instance.
82 */
83 static SkFontConfigInterface* GetSingletonDirectInterface();
reed@google.comd71fe992013-02-25 20:38:07 +000084};
85
86#endif