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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFontStyle.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
2013-02-25 20:38:07 +00:00
|
|
|
|
2016-05-02 18:54:13 +00:00
|
|
|
class SkFontMgr;
|
2014-07-02 01:54:41 +00:00
|
|
|
|
2013-02-25 20:38:07 +00:00
|
|
|
/**
|
|
|
|
* \class SkFontConfigInterface
|
|
|
|
*
|
2015-02-23 16:25:00 +00:00
|
|
|
* A simple interface for remotable font management.
|
|
|
|
* The global instance can be found with RefGlobal().
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2013-03-04 17:26:02 +00:00
|
|
|
class SK_API SkFontConfigInterface : public SkRefCnt {
|
2013-02-25 20:38:07 +00:00
|
|
|
public:
|
2013-07-11 22:29:29 +00:00
|
|
|
|
2013-02-25 20:38:07 +00:00
|
|
|
/**
|
2016-09-19 19:13:16 +00:00
|
|
|
* Returns the global SkFontConfigInterface instance. If it is not
|
|
|
|
* nullptr, calls ref() on it. The caller must balance this with a call to
|
|
|
|
* unref(). The default SkFontConfigInterface is the result of calling
|
|
|
|
* GetSingletonDirectInterface.
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2018-05-14 17:51:10 +00:00
|
|
|
static sk_sp<SkFontConfigInterface> RefGlobal();
|
2013-02-25 20:38:07 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-14 17:51:10 +00:00
|
|
|
* Replace the current global instance with the specified one.
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2018-05-14 17:51:10 +00:00
|
|
|
static void SetGlobal(sk_sp<SkFontConfigInterface> fc);
|
2013-02-25 20:38:07 +00:00
|
|
|
|
|
|
|
/**
|
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;
|
|
|
|
}
|
2013-04-22 18:48:45 +00:00
|
|
|
bool operator!=(const FontIdentity& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2013-03-06 13:06:03 +00:00
|
|
|
|
|
|
|
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-04-23 07:01:29 +00:00
|
|
|
|
2013-04-22 18:48:45 +00:00
|
|
|
// If buffer is NULL, just return the number of bytes that would have
|
|
|
|
// been written. Will pad contents to a multiple of 4.
|
2017-08-28 14:34:05 +00:00
|
|
|
size_t writeToMemory(void* buffer = nullptr) const;
|
2013-04-23 07:01:29 +00:00
|
|
|
|
2013-04-22 18:48:45 +00:00
|
|
|
// Recreate from a flattened buffer, returning the number of bytes read.
|
|
|
|
size_t readFromMemory(const void* buffer, size_t length);
|
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
|
|
|
*/
|
2016-04-12 20:45:06 +00:00
|
|
|
virtual bool matchFamilyName(const char familyName[],
|
|
|
|
SkFontStyle requested,
|
|
|
|
FontIdentity* outFontIdentifier,
|
|
|
|
SkString* outFamilyName,
|
|
|
|
SkFontStyle* 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
|
2015-01-27 13:39:10 +00:00
|
|
|
* deleting the stream when it is done accessing the data.
|
2013-02-25 20:38:07 +00:00
|
|
|
*/
|
2015-01-27 13:39:10 +00:00
|
|
|
virtual SkStreamAsset* openStream(const FontIdentity&) = 0;
|
2013-03-04 19:07:02 +00:00
|
|
|
|
2015-11-20 21:47:55 +00:00
|
|
|
/**
|
|
|
|
* Return an SkTypeface for the given FontIdentity.
|
|
|
|
*
|
|
|
|
* The default implementation simply returns a new typeface built using data obtained from
|
|
|
|
* openStream(), but derived classes may implement more complex caching schemes.
|
|
|
|
*/
|
2016-05-12 17:09:30 +00:00
|
|
|
virtual sk_sp<SkTypeface> makeTypeface(const FontIdentity& identity) {
|
2018-09-07 15:19:39 +00:00
|
|
|
return SkTypeface::MakeFromStream(std::unique_ptr<SkStreamAsset>(this->openStream(identity)),
|
|
|
|
identity.fTTCIndex);
|
|
|
|
|
2016-05-12 17:09:30 +00:00
|
|
|
}
|
2015-11-20 21:47:55 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2016-05-02 18:54:13 +00:00
|
|
|
static SkFontConfigInterface* GetSingletonDirectInterface();
|
2013-04-09 15:54:52 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkRefCnt;
|
2013-02-25 20:38:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|