blob: e9d3f6ccd81d7f9ea87098ce4d2bf01c30725245 [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
reed@google.com54c69142013-04-09 15:54:52 +000011#include "SkFontStyle.h"
reed@google.comd71fe992013-02-25 20:38:07 +000012#include "SkRefCnt.h"
reed@google.com80f54652013-02-25 22:19:20 +000013#include "SkTypeface.h"
reed@google.comd71fe992013-02-25 20:38:07 +000014
15/**
16 * \class SkFontConfigInterface
17 *
18 * Provides SkFontHost clients with access to fontconfig services. They will
19 * access the global instance found in RefGlobal().
20 */
reed@google.com86a44b82013-03-04 17:26:02 +000021class SK_API SkFontConfigInterface : public SkRefCnt {
reed@google.comd71fe992013-02-25 20:38:07 +000022public:
23 /**
24 * Returns the global SkFontConfigInterface instance, and if it is not
25 * NULL, calls ref() on it. The caller must balance this with a call to
26 * unref().
27 */
28 static SkFontConfigInterface* RefGlobal();
29
30 /**
31 * Replace the current global instance with the specified one, safely
32 * ref'ing the new instance, and unref'ing the previous. Returns its
33 * parameter (the new global instance).
34 */
35 static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*);
36
37 /**
reed@google.comf71a2332013-02-27 19:06:30 +000038 * This should be treated as private to the impl of SkFontConfigInterface.
39 * Callers should not change or expect any particular values. It is meant
40 * to be a union of possible storage types to aid the impl.
reed@google.comd71fe992013-02-25 20:38:07 +000041 */
reed@google.comf71a2332013-02-27 19:06:30 +000042 struct FontIdentity {
reed@google.com8c9737e2013-03-06 13:06:03 +000043 FontIdentity() : fID(0), fTTCIndex(0) {}
44
45 bool operator==(const FontIdentity& other) const {
46 return fID == other.fID &&
47 fTTCIndex == other.fTTCIndex &&
48 fString == other.fString;
49 }
50
51 uint32_t fID;
52 int32_t fTTCIndex;
reed@google.comf71a2332013-02-27 19:06:30 +000053 SkString fString;
reed@google.com54c69142013-04-09 15:54:52 +000054 SkFontStyle fStyle;
reed@google.comf71a2332013-02-27 19:06:30 +000055 };
reed@google.comd71fe992013-02-25 20:38:07 +000056
57 /**
reed@google.comf71a2332013-02-27 19:06:30 +000058 * Given a familyName and style, find the best match.
59 *
60 * If a match is found, return true and set its outFontIdentifier.
61 * If outFamilyName is not null, assign the found familyName to it
62 * (which may differ from the requested familyName).
63 * If outStyle is not null, assign the found style to it
64 * (which may differ from the requested style).
65 *
66 * If a match is not found, return false, and ignore all out parameters.
reed@google.comd71fe992013-02-25 20:38:07 +000067 */
reed@google.comf71a2332013-02-27 19:06:30 +000068 virtual bool matchFamilyName(const char familyName[],
69 SkTypeface::Style requested,
70 FontIdentity* outFontIdentifier,
71 SkString* outFamilyName,
72 SkTypeface::Style* outStyle) = 0;
reed@google.comd71fe992013-02-25 20:38:07 +000073
74 /**
reed@google.comf71a2332013-02-27 19:06:30 +000075 * Given a FontRef, open a stream to access its data, or return null
76 * if the FontRef's data is not available. The caller is responsible for
77 * calling stream->unref() when it is done accessing the data.
reed@google.comd71fe992013-02-25 20:38:07 +000078 */
reed@google.comf71a2332013-02-27 19:06:30 +000079 virtual SkStream* openStream(const FontIdentity&) = 0;
reed@google.comd66045e2013-03-04 19:07:02 +000080
81 /**
82 * Return a singleton instance of a direct subclass that calls into
83 * libfontconfig. This does not affect the refcnt of the returned instance.
84 */
85 static SkFontConfigInterface* GetSingletonDirectInterface();
reed@google.com54c69142013-04-09 15:54:52 +000086
87 // New APIS, which have default impls for now (which do nothing)
88
robertphillips@google.com21db1db2013-04-09 23:56:51 +000089 virtual int countFamilies() { return 0; };
reed@google.com54c69142013-04-09 15:54:52 +000090 virtual int getFamilySet(int index, SkString* outFamilyName,
robertphillips@google.com21db1db2013-04-09 23:56:51 +000091 FontIdentity outIdentities[], int maxCount) {
92 return 0;
93 }
reed@google.com54c69142013-04-09 15:54:52 +000094 virtual int matchFamilySet(const char familyName[], SkString* outFamilyName,
robertphillips@google.com21db1db2013-04-09 23:56:51 +000095 FontIdentity outIdentities[], int maxCount) {
96 return 0;
97 }
reed@google.comd71fe992013-02-25 20:38:07 +000098};
99
100#endif