2013-02-25 20:38:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkFontConfigInterface_DEFINED
|
|
|
|
#define SkFontConfigInterface_DEFINED
|
|
|
|
|
2013-04-19 20:45:30 +00:00
|
|
|
#include "SkDataTable.h"
|
2013-04-09 15:54:52 +00:00
|
|
|
#include "SkFontStyle.h"
|
2013-02-25 20:38:07 +00:00
|
|
|
#include "SkRefCnt.h"
|
2013-04-19 20:45:30 +00:00
|
|
|
#include "SkTArray.h"
|
2013-02-25 22:19:20 +00:00
|
|
|
#include "SkTypeface.h"
|
2013-02-25 20:38:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \class SkFontConfigInterface
|
|
|
|
*
|
|
|
|
* Provides SkFontHost clients with access to fontconfig services. They will
|
|
|
|
* access the global instance found in RefGlobal().
|
|
|
|
*/
|
2013-03-04 17:26:02 +00:00
|
|
|
class SK_API SkFontConfigInterface : public SkRefCnt {
|
2013-02-25 20:38:07 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Returns the global SkFontConfigInterface instance, and if it is not
|
|
|
|
* NULL, calls ref() on it. The caller must balance this with a call to
|
|
|
|
* unref().
|
|
|
|
*/
|
|
|
|
static SkFontConfigInterface* RefGlobal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace the current global instance with the specified one, safely
|
|
|
|
* ref'ing the new instance, and unref'ing the previous. Returns its
|
|
|
|
* parameter (the new global instance).
|
|
|
|
*/
|
|
|
|
static SkFontConfigInterface* SetGlobal(SkFontConfigInterface*);
|
|
|
|
|
|
|
|
/**
|
2013-02-27 19:06:30 +00:00
|
|
|
* This should be treated as private to the impl of SkFontConfigInterface.
|
|
|
|
* Callers should not change or expect any particular values. It is meant
|
|
|
|
* to be a union of possible storage types to aid the impl.
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2013-02-27 19:06:30 +00:00
|
|
|
struct FontIdentity {
|
2013-03-06 13:06:03 +00:00
|
|
|
FontIdentity() : fID(0), fTTCIndex(0) {}
|
|
|
|
|
|
|
|
bool operator==(const FontIdentity& other) const {
|
|
|
|
return fID == other.fID &&
|
|
|
|
fTTCIndex == other.fTTCIndex &&
|
|
|
|
fString == other.fString;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t fID;
|
|
|
|
int32_t fTTCIndex;
|
2013-02-27 19:06:30 +00:00
|
|
|
SkString fString;
|
2013-04-09 15:54:52 +00:00
|
|
|
SkFontStyle fStyle;
|
2013-02-27 19:06:30 +00:00
|
|
|
};
|
2013-02-25 20:38:07 +00:00
|
|
|
|
|
|
|
/**
|
2013-02-27 19:06:30 +00:00
|
|
|
* Given a familyName and style, find the best match.
|
|
|
|
*
|
|
|
|
* If a match is found, return true and set its outFontIdentifier.
|
|
|
|
* If outFamilyName is not null, assign the found familyName to it
|
|
|
|
* (which may differ from the requested familyName).
|
|
|
|
* If outStyle is not null, assign the found style to it
|
|
|
|
* (which may differ from the requested style).
|
|
|
|
*
|
|
|
|
* If a match is not found, return false, and ignore all out parameters.
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2013-02-27 19:06:30 +00:00
|
|
|
virtual bool matchFamilyName(const char familyName[],
|
|
|
|
SkTypeface::Style requested,
|
|
|
|
FontIdentity* outFontIdentifier,
|
|
|
|
SkString* outFamilyName,
|
|
|
|
SkTypeface::Style* outStyle) = 0;
|
2013-02-25 20:38:07 +00:00
|
|
|
|
|
|
|
/**
|
2013-02-27 19:06:30 +00:00
|
|
|
* Given a FontRef, open a stream to access its data, or return null
|
|
|
|
* if the FontRef's data is not available. The caller is responsible for
|
|
|
|
* calling stream->unref() when it is done accessing the data.
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2013-02-27 19:06:30 +00:00
|
|
|
virtual SkStream* openStream(const FontIdentity&) = 0;
|
2013-03-04 19:07:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a singleton instance of a direct subclass that calls into
|
|
|
|
* libfontconfig. This does not affect the refcnt of the returned instance.
|
|
|
|
*/
|
|
|
|
static SkFontConfigInterface* GetSingletonDirectInterface();
|
2013-04-09 15:54:52 +00:00
|
|
|
|
|
|
|
// New APIS, which have default impls for now (which do nothing)
|
|
|
|
|
2013-04-19 20:45:30 +00:00
|
|
|
virtual SkDataTable* getFamilyNames() { return SkDataTable::NewEmpty(); }
|
|
|
|
virtual bool matchFamilySet(const char inFamilyName[],
|
|
|
|
SkString* outFamilyName,
|
|
|
|
SkTArray<FontIdentity>*) {
|
|
|
|
return false;
|
2013-04-09 23:56:51 +00:00
|
|
|
}
|
2013-02-25 20:38:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|