2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2006 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkFontHost.h"
|
2013-03-21 13:33:49 +00:00
|
|
|
#include "SkFontHost_FreeType_common.h"
|
2012-05-31 19:55:08 +00:00
|
|
|
#include "SkFontDescriptor.h"
|
2013-11-11 15:53:29 +00:00
|
|
|
#include "SkFontMgr.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkDescriptor.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkThread.h"
|
|
|
|
#include "SkTSearch.h"
|
2013-11-11 15:53:29 +00:00
|
|
|
#include "SkTypefaceCache.h"
|
|
|
|
#include "SkTArray.h"
|
|
|
|
|
|
|
|
#include <limits>
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#ifndef SK_FONT_FILE_PREFIX
|
2013-11-11 15:53:29 +00:00
|
|
|
# define SK_FONT_FILE_PREFIX "/usr/share/fonts/truetype/"
|
2012-09-26 19:16:54 +00:00
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-02-15 21:03:45 +00:00
|
|
|
bool find_name_and_attributes(SkStream* stream, SkString* name,
|
2013-03-25 19:36:11 +00:00
|
|
|
SkTypeface::Style* style, bool* isFixedPitch);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
/** The base SkTypeface implementation for the custom font manager. */
|
|
|
|
class SkTypeface_Custom : public SkTypeface_FreeType {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface_Custom(Style style, bool sysFont, bool isFixedPitch, const SkString familyName)
|
|
|
|
: INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
|
|
|
|
, fIsSysFont(sysFont), fFamilyName(familyName)
|
|
|
|
{ }
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
bool isSysFont() const { return fIsSysFont; }
|
2013-03-22 17:21:59 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual const char* getUniqueString() const = 0;
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-25 13:03:37 +00:00
|
|
|
protected:
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVERRIDE {
|
|
|
|
desc->setFamilyName(fFamilyName.c_str());
|
|
|
|
desc->setFontFileName(this->getUniqueString());
|
|
|
|
*isLocal = !this->isSysFont();
|
|
|
|
}
|
2013-03-25 13:03:37 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2013-11-11 15:53:29 +00:00
|
|
|
bool fIsSysFont;
|
|
|
|
SkString fFamilyName;
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-21 13:38:18 +00:00
|
|
|
typedef SkTypeface_FreeType INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
/** The empty SkTypeface implementation for the custom font manager.
|
|
|
|
* Used as the last resort fallback typeface.
|
2010-04-16 12:40:08 +00:00
|
|
|
*/
|
2013-11-11 15:53:29 +00:00
|
|
|
class SkTypeface_Empty : public SkTypeface_Custom {
|
2010-04-16 12:40:08 +00:00
|
|
|
public:
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface_Empty() : INHERITED(SkTypeface::kNormal, true, false, SkString()) {}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-22 17:21:59 +00:00
|
|
|
protected:
|
|
|
|
virtual SkStream* onOpenStream(int*) const SK_OVERRIDE { return NULL; }
|
|
|
|
|
2010-04-16 12:40:08 +00:00
|
|
|
private:
|
2013-11-11 15:53:29 +00:00
|
|
|
typedef SkTypeface_Custom INHERITED;
|
2010-04-16 12:40:08 +00:00
|
|
|
};
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
/** The stream SkTypeface implementation for the custom font manager. */
|
|
|
|
class SkTypeface_Stream : public SkTypeface_Custom {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface_Stream(Style style, bool sysFont, SkStream* stream,
|
|
|
|
bool isFixedPitch, const SkString familyName)
|
|
|
|
: INHERITED(style, sysFont, isFixedPitch, familyName)
|
|
|
|
, fStream(SkRef(stream))
|
|
|
|
{ }
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-18 21:08:46 +00:00
|
|
|
virtual const char* getUniqueString() const SK_OVERRIDE { return NULL; }
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-22 17:21:59 +00:00
|
|
|
protected:
|
|
|
|
virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
|
|
|
|
*ttcIndex = 0;
|
2014-03-24 21:42:01 +00:00
|
|
|
return fStream->duplicate();
|
2013-03-22 17:21:59 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2013-11-11 15:53:29 +00:00
|
|
|
SkAutoTUnref<SkStream> fStream;
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
typedef SkTypeface_Custom INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
/** The file SkTypeface implementation for the custom font manager. */
|
|
|
|
class SkTypeface_File : public SkTypeface_Custom {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface_File(Style style, bool sysFont, const char path[],
|
|
|
|
bool isFixedPitch, const SkString familyName)
|
|
|
|
: INHERITED(style, sysFont, isFixedPitch, familyName)
|
|
|
|
, fPath(path)
|
|
|
|
{ }
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-18 21:08:46 +00:00
|
|
|
virtual const char* getUniqueString() const SK_OVERRIDE {
|
2008-12-17 15:59:43 +00:00
|
|
|
const char* str = strrchr(fPath.c_str(), '/');
|
|
|
|
if (str) {
|
|
|
|
str += 1; // skip the '/'
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-03-22 17:21:59 +00:00
|
|
|
protected:
|
|
|
|
virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE {
|
|
|
|
*ttcIndex = 0;
|
|
|
|
return SkStream::NewFromFile(fPath.c_str());
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
SkString fPath;
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
typedef SkTypeface_Custom INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
/**
|
|
|
|
* SkFontStyleSet_Custom
|
|
|
|
*
|
|
|
|
* This class is used by SkFontMgr_Custom to hold SkTypeface_Custom families.
|
|
|
|
*/
|
|
|
|
class SkFontStyleSet_Custom : public SkFontStyleSet {
|
|
|
|
public:
|
|
|
|
explicit SkFontStyleSet_Custom(const SkString familyName) : fFamilyName(familyName) { }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual int count() SK_OVERRIDE {
|
|
|
|
return fStyles.count();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual void getStyle(int index, SkFontStyle* style, SkString* name) SK_OVERRIDE {
|
|
|
|
SkASSERT(index < fStyles.count());
|
|
|
|
bool bold = fStyles[index]->isBold();
|
|
|
|
bool italic = fStyles[index]->isItalic();
|
|
|
|
*style = SkFontStyle(bold ? SkFontStyle::kBold_Weight : SkFontStyle::kNormal_Weight,
|
|
|
|
SkFontStyle::kNormal_Width,
|
|
|
|
italic ? SkFontStyle::kItalic_Slant : SkFontStyle::kUpright_Slant);
|
|
|
|
name->reset();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
|
|
|
|
SkASSERT(index < fStyles.count());
|
|
|
|
return SkRef(fStyles[index].get());
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
|
|
|
|
int score = 0;
|
|
|
|
score += (pattern.width() - candidate.width()) * 100;
|
|
|
|
score += (pattern.isItalic() == candidate.isItalic()) ? 0 : 1000;
|
|
|
|
score += pattern.weight() - candidate.weight();
|
|
|
|
return score;
|
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE {
|
|
|
|
if (0 == fStyles.count()) {
|
|
|
|
return NULL;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2009-09-28 16:12:48 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface_Custom* closest = fStyles[0];
|
|
|
|
int minScore = std::numeric_limits<int>::max();
|
|
|
|
for (int i = 0; i < fStyles.count(); ++i) {
|
|
|
|
bool bold = fStyles[i]->isBold();
|
|
|
|
bool italic = fStyles[i]->isItalic();
|
|
|
|
SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight
|
|
|
|
: SkFontStyle::kNormal_Weight,
|
|
|
|
SkFontStyle::kNormal_Width,
|
|
|
|
italic ? SkFontStyle::kItalic_Slant
|
|
|
|
: SkFontStyle::kUpright_Slant);
|
|
|
|
|
|
|
|
int score = match_score(pattern, style);
|
|
|
|
if (score < minScore) {
|
|
|
|
closest = fStyles[i];
|
|
|
|
minScore = score;
|
|
|
|
}
|
2010-04-15 14:04:52 +00:00
|
|
|
}
|
2013-11-11 15:53:29 +00:00
|
|
|
return SkRef(closest);
|
|
|
|
}
|
2010-04-15 14:04:52 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
private:
|
|
|
|
SkTArray<SkAutoTUnref<SkTypeface_Custom>, true> fStyles;
|
|
|
|
SkString fFamilyName;
|
|
|
|
|
|
|
|
void appendTypeface(SkTypeface_Custom* typeface) {
|
|
|
|
fStyles.push_back().reset(typeface);
|
2010-04-16 12:40:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
friend class SkFontMgr_Custom;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SkFontMgr_Custom
|
|
|
|
*
|
|
|
|
* This class is essentially a collection of SkFontStyleSet_Custom,
|
|
|
|
* one SkFontStyleSet_Custom for each family. This class may be modified
|
|
|
|
* to load fonts from any source by changing the initialization.
|
|
|
|
*/
|
|
|
|
class SkFontMgr_Custom : public SkFontMgr {
|
|
|
|
public:
|
|
|
|
explicit SkFontMgr_Custom(const char* dir) {
|
|
|
|
this->load_system_fonts(dir);
|
2012-09-26 19:16:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
protected:
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual int onCountFamilies() const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
return fFamilies.count();
|
2012-09-26 19:16:54 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
SkASSERT(index < fFamilies.count());
|
|
|
|
familyName->set(fFamilies[index]->fFamilyName);
|
|
|
|
}
|
2012-09-26 19:16:54 +00:00
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkFontStyleSet_Custom* onCreateStyleSet(int index) const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
SkASSERT(index < fFamilies.count());
|
|
|
|
return SkRef(fFamilies[index].get());
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2009-09-28 16:12:48 +00:00
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkFontStyleSet_Custom* onMatchFamily(const char familyName[]) const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
for (int i = 0; i < fFamilies.count(); ++i) {
|
|
|
|
if (fFamilies[i]->fFamilyName.equals(familyName)) {
|
|
|
|
return SkRef(fFamilies[i].get());
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2013-11-11 15:53:29 +00:00
|
|
|
return NULL;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2013-11-11 15:53:29 +00:00
|
|
|
|
|
|
|
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
2014-02-04 22:35:01 +00:00
|
|
|
const SkFontStyle& fontStyle) const SK_OVERRIDE
|
2013-11-11 15:53:29 +00:00
|
|
|
{
|
|
|
|
SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName));
|
|
|
|
return sset->matchStyle(fontStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
2014-02-04 22:35:01 +00:00
|
|
|
const SkFontStyle& fontStyle) const SK_OVERRIDE
|
2013-11-11 15:53:29 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < fFamilies.count(); ++i) {
|
|
|
|
for (int j = 0; j < fFamilies[i]->fStyles.count(); ++j) {
|
|
|
|
if (fFamilies[i]->fStyles[j] == familyMember) {
|
|
|
|
return fFamilies[i]->matchStyle(fontStyle);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-11 15:53:29 +00:00
|
|
|
return NULL;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
SkAutoTUnref<SkStream> stream(new SkMemoryStream(data));
|
|
|
|
return this->createFromStream(stream, ttcIndex);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
if (NULL == stream || stream->getLength() <= 0) {
|
|
|
|
SkDELETE(stream);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
bool isFixedPitch;
|
|
|
|
SkTypeface::Style style;
|
|
|
|
SkString name;
|
|
|
|
if (find_name_and_attributes(stream, &name, &style, &isFixedPitch)) {
|
|
|
|
return SkNEW_ARGS(SkTypeface_Stream, (style, false, stream, isFixedPitch, name));
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2014-02-04 22:35:01 +00:00
|
|
|
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
|
2013-11-11 15:53:29 +00:00
|
|
|
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
|
|
|
|
return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
|
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
|
2014-02-04 22:35:01 +00:00
|
|
|
unsigned styleBits) const SK_OVERRIDE
|
2013-11-11 15:53:29 +00:00
|
|
|
{
|
|
|
|
SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
|
|
|
|
SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
|
|
|
|
? SkFontStyle::kBold_Weight
|
|
|
|
: SkFontStyle::kNormal_Weight,
|
|
|
|
SkFontStyle::kNormal_Width,
|
|
|
|
oldStyle & SkTypeface::kItalic
|
|
|
|
? SkFontStyle::kItalic_Slant
|
|
|
|
: SkFontStyle::kUpright_Slant);
|
|
|
|
SkTypeface* tf = NULL;
|
|
|
|
|
|
|
|
if (NULL != familyName) {
|
|
|
|
tf = this->onMatchFamilyStyle(familyName, style);
|
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
if (NULL == tf) {
|
|
|
|
tf = gDefaultFamily->matchStyle(style);
|
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
return SkSafeRef(tf);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
static bool get_name_and_style(const char path[], SkString* name,
|
|
|
|
SkTypeface::Style* style, bool* isFixedPitch) {
|
|
|
|
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
|
|
|
|
if (stream.get()) {
|
|
|
|
return find_name_and_attributes(stream, name, style, isFixedPitch);
|
|
|
|
} else {
|
|
|
|
SkDebugf("---- failed to open <%s> as a font\n", path);
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-07-30 12:59:12 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
void load_directory_fonts(const SkString& directory) {
|
|
|
|
SkOSFile::Iter iter(directory.c_str(), ".ttf");
|
|
|
|
SkString name;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
while (iter.next(&name, false)) {
|
2014-03-13 16:24:49 +00:00
|
|
|
SkString filename(
|
|
|
|
SkOSPath::SkPathJoin(directory.c_str(), name.c_str()));
|
2013-08-02 00:20:34 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
bool isFixedPitch;
|
|
|
|
SkString realname;
|
|
|
|
SkTypeface::Style style = SkTypeface::kNormal; // avoid uninitialized warning
|
2013-08-02 00:20:34 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
if (!get_name_and_style(filename.c_str(), &realname, &style, &isFixedPitch)) {
|
|
|
|
SkDebugf("------ can't load <%s> as a font\n", filename.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-02 00:20:34 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface_Custom* tf = SkNEW_ARGS(SkTypeface_File, (
|
|
|
|
style,
|
|
|
|
true, // system-font (cannot delete)
|
|
|
|
filename.c_str(),
|
|
|
|
isFixedPitch,
|
|
|
|
realname));
|
|
|
|
|
|
|
|
SkFontStyleSet_Custom* addTo = this->onMatchFamily(realname.c_str());
|
|
|
|
if (NULL == addTo) {
|
|
|
|
addTo = new SkFontStyleSet_Custom(realname);
|
|
|
|
fFamilies.push_back().reset(addTo);
|
|
|
|
}
|
|
|
|
addTo->appendTypeface(tf);
|
|
|
|
}
|
2013-08-02 00:20:34 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
SkOSFile::Iter dirIter(directory.c_str());
|
|
|
|
while (dirIter.next(&name, true)) {
|
|
|
|
if (name.startsWith(".")) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-13 16:24:49 +00:00
|
|
|
SkString dirname(
|
|
|
|
SkOSPath::SkPathJoin(directory.c_str(), name.c_str()));
|
2013-11-11 15:53:29 +00:00
|
|
|
load_directory_fonts(dirname);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-02-23 14:49:33 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
void load_system_fonts(const char* dir) {
|
|
|
|
SkString baseDirectory(dir);
|
|
|
|
load_directory_fonts(baseDirectory);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
if (fFamilies.empty()) {
|
|
|
|
SkFontStyleSet_Custom* family = new SkFontStyleSet_Custom(SkString());
|
|
|
|
fFamilies.push_back().reset(family);
|
|
|
|
family->appendTypeface(SkNEW(SkTypeface_Empty));
|
|
|
|
}
|
2013-03-27 20:01:49 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
// Try to pick a default font.
|
|
|
|
static const char* gDefaultNames[] = {
|
2014-03-13 16:24:49 +00:00
|
|
|
"Arial", "Verdana", "Times New Roman", "Droid Sans", NULL
|
2013-11-11 15:53:29 +00:00
|
|
|
};
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) {
|
|
|
|
SkFontStyleSet_Custom* set = this->onMatchFamily(gDefaultNames[i]);
|
|
|
|
if (NULL == set) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-01 15:53:39 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
SkTypeface* tf = set->matchStyle(SkFontStyle(SkFontStyle::kNormal_Weight,
|
|
|
|
SkFontStyle::kNormal_Width,
|
|
|
|
SkFontStyle::kUpright_Slant));
|
|
|
|
if (NULL == tf) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-27 20:01:49 +00:00
|
|
|
|
2013-11-11 15:53:29 +00:00
|
|
|
gDefaultFamily = set;
|
|
|
|
gDefaultNormal = tf;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NULL == gDefaultNormal) {
|
|
|
|
gDefaultFamily = fFamilies[0];
|
|
|
|
gDefaultNormal = gDefaultFamily->fStyles[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkTArray<SkAutoTUnref<SkFontStyleSet_Custom>, true> fFamilies;
|
|
|
|
SkFontStyleSet_Custom* gDefaultFamily;
|
|
|
|
SkTypeface* gDefaultNormal;
|
|
|
|
};
|
2013-03-27 20:01:49 +00:00
|
|
|
|
|
|
|
SkFontMgr* SkFontMgr::Factory() {
|
2013-11-11 15:53:29 +00:00
|
|
|
return new SkFontMgr_Custom(SK_FONT_FILE_PREFIX);
|
2013-03-27 20:01:49 +00:00
|
|
|
}
|