2012-05-31 19:55:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkFontDescriptor_DEFINED
|
|
|
|
#define SkFontDescriptor_DEFINED
|
|
|
|
|
2016-04-07 15:49:31 +00:00
|
|
|
#include "SkFixed.h"
|
2014-09-18 17:55:32 +00:00
|
|
|
#include "SkStream.h"
|
2012-05-31 19:55:08 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
|
2015-05-20 16:21:04 +00:00
|
|
|
class SkFontData {
|
|
|
|
public:
|
2016-09-16 13:24:20 +00:00
|
|
|
/** Makes a copy of the data in 'axis'. */
|
|
|
|
SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed axis[],int axisCount)
|
|
|
|
: fStream(std::move(stream)), fIndex(index), fAxisCount(axisCount), fAxis(axisCount)
|
2015-05-20 16:21:04 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < axisCount; ++i) {
|
|
|
|
fAxis[i] = axis[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkFontData(const SkFontData& that)
|
|
|
|
: fStream(that.fStream->duplicate())
|
|
|
|
, fIndex(that.fIndex)
|
|
|
|
, fAxisCount(that.fAxisCount)
|
|
|
|
, fAxis(fAxisCount)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fAxisCount; ++i) {
|
|
|
|
fAxis[i] = that.fAxis[i];
|
|
|
|
}
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
bool hasStream() const { return fStream.get() != nullptr; }
|
2016-09-16 13:24:20 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); }
|
2015-05-20 16:21:04 +00:00
|
|
|
SkStreamAsset* getStream() { return fStream.get(); }
|
2016-09-16 13:24:20 +00:00
|
|
|
SkStreamAsset const* getStream() const { return fStream.get(); }
|
2015-05-20 16:21:04 +00:00
|
|
|
int getIndex() const { return fIndex; }
|
|
|
|
int getAxisCount() const { return fAxisCount; }
|
|
|
|
const SkFixed* getAxis() const { return fAxis.get(); }
|
|
|
|
|
|
|
|
private:
|
2016-09-16 13:24:20 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> fStream;
|
2015-05-20 16:21:04 +00:00
|
|
|
int fIndex;
|
|
|
|
int fAxisCount;
|
|
|
|
SkAutoSTMalloc<4, SkFixed> fAxis;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkFontDescriptor : SkNoncopyable {
|
2012-05-31 19:55:08 +00:00
|
|
|
public:
|
2016-07-25 23:54:59 +00:00
|
|
|
SkFontDescriptor();
|
2015-01-21 20:09:53 +00:00
|
|
|
// Does not affect ownership of SkStream.
|
2016-02-25 18:58:49 +00:00
|
|
|
static bool Deserialize(SkStream*, SkFontDescriptor* result);
|
2012-05-31 19:55:08 +00:00
|
|
|
|
|
|
|
void serialize(SkWStream*);
|
|
|
|
|
2016-07-25 23:54:59 +00:00
|
|
|
SkFontStyle getStyle() { return fStyle; }
|
|
|
|
void setStyle(SkFontStyle style) { fStyle = style; }
|
2012-05-31 19:55:08 +00:00
|
|
|
|
2014-09-18 17:55:32 +00:00
|
|
|
const char* getFamilyName() const { return fFamilyName.c_str(); }
|
|
|
|
const char* getFullName() const { return fFullName.c_str(); }
|
|
|
|
const char* getPostscriptName() const { return fPostscriptName.c_str(); }
|
2015-08-27 14:41:13 +00:00
|
|
|
bool hasFontData() const { return fFontData.get() != nullptr; }
|
2016-09-16 13:24:20 +00:00
|
|
|
std::unique_ptr<SkFontData> detachFontData() { return std::move(fFontData); }
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-31 21:16:48 +00:00
|
|
|
void setFamilyName(const char* name) { fFamilyName.set(name); }
|
|
|
|
void setFullName(const char* name) { fFullName.set(name); }
|
|
|
|
void setPostscriptName(const char* name) { fPostscriptName.set(name); }
|
2016-09-16 13:24:20 +00:00
|
|
|
/** Set the font data only if it is necessary for serialization. */
|
|
|
|
void setFontData(std::unique_ptr<SkFontData> data) { fFontData = std::move(data); }
|
2012-05-31 21:16:48 +00:00
|
|
|
|
2012-05-31 19:55:08 +00:00
|
|
|
private:
|
2012-05-31 21:16:48 +00:00
|
|
|
SkString fFamilyName;
|
|
|
|
SkString fFullName;
|
|
|
|
SkString fPostscriptName;
|
2016-09-16 13:24:20 +00:00
|
|
|
std::unique_ptr<SkFontData> fFontData;
|
2012-05-31 21:16:48 +00:00
|
|
|
|
2016-07-25 23:54:59 +00:00
|
|
|
SkFontStyle fStyle;
|
2012-05-31 19:55:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkFontDescriptor_DEFINED
|