-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add font manager with switching capabilities
- Loading branch information
1 parent
095dc8d
commit 836a958
Showing
6 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include "../../externals/skia/include/core/SkFontMgr.h" | ||
|
||
class SkFontMgr_AlphaSkia : public SkFontMgr | ||
{ | ||
public: | ||
explicit SkFontMgr_AlphaSkia(); | ||
|
||
void switch_to_operating_system_fonts(); | ||
void switch_to_freetype_fonts(); | ||
|
||
protected: | ||
int onCountFamilies() const override; | ||
void onGetFamilyName(int index, SkString *familyName) const override; | ||
sk_sp<SkFontStyleSet> onCreateStyleSet(int index) const override; | ||
sk_sp<SkFontStyleSet> onMatchFamily(const char familyName[]) const override; | ||
sk_sp<SkTypeface> onMatchFamilyStyle(const char familyName[], | ||
const SkFontStyle &fontStyle) const override; | ||
sk_sp<SkTypeface> onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &, | ||
const char *bcp47[], int bcp47Count, | ||
SkUnichar character) const override; | ||
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override; | ||
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>, int ttcIndex) const override; | ||
sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>, const SkFontArguments &) const override; | ||
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override; | ||
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override; | ||
|
||
private: | ||
sk_sp<SkFontMgr> currentFontMgr_; | ||
sk_sp<SkFontMgr> freeTypeFontMgr_; | ||
sk_sp<SkFontMgr> operatingSystemTypeFontMgr_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include "../include/SkFontMgr_alphaskia.h" | ||
|
||
#include "../../externals/skia/include/core/SkSpan.h" | ||
#include "../../externals/skia/include/core/SkFontStyle.h" | ||
#include "../../externals/skia/include/core/SkTypeface.h" | ||
#include "../../externals/skia/include/core/SkStream.h" | ||
#include "../../externals/skia/include/ports/SkFontMgr_data.h" | ||
|
||
#if defined(ALPHASKIA_FONTMGR_WINDOWS) | ||
#include "../../externals/skia/include/ports/SkTypeface_win.h" | ||
#define CREATE_OPERATING_SYSTEM_FONTMGR SkFontMgr_New_DirectWrite() | ||
#elif defined(ALPHASKIA_FONTMGR_ANDROID) | ||
#include "../../externals/skia/include/ports/SkFontMgr_android.h" | ||
#define CREATE_OPERATING_SYSTEM_FONTMGR SkFontMgr_New_Android(nullptr) | ||
#elif defined(ALPHASKIA_FONTMGR_MAC) | ||
#include "../../externals/skia/include/ports/SkFontMgr_mac_ct.h" | ||
#define CREATE_OPERATING_SYSTEM_FONTMGR SkFontMgr_New_CoreText(nullptr) | ||
#elif defined(ALPHASKIA_FONTMGR_IOS) | ||
#include "../../externals/skia/include/ports/SkFontMgr_mac_ct.h" | ||
#define CREATE_OPERATING_SYSTEM_FONTMGR SkFontMgr_New_CoreText(nullptr) | ||
#else | ||
#error "Unsupported operating system - extend font mgr" | ||
#endif | ||
|
||
SkFontMgr_AlphaSkia::SkFontMgr_AlphaSkia() | ||
{ | ||
operatingSystemTypeFontMgr_ = CREATE_OPERATING_SYSTEM_FONTMGR; | ||
currentFontMgr_ = operatingSystemTypeFontMgr_; | ||
} | ||
|
||
void SkFontMgr_AlphaSkia::switch_to_operating_system_fonts() | ||
{ | ||
currentFontMgr_ = operatingSystemTypeFontMgr_; | ||
} | ||
|
||
void SkFontMgr_AlphaSkia::switch_to_freetype_fonts() | ||
{ | ||
if (!freeTypeFontMgr_) | ||
{ | ||
freeTypeFontMgr_ = SkFontMgr_New_Custom_Data(SkSpan<sk_sp<SkData>>(nullptr, 0)); | ||
} | ||
currentFontMgr_ = freeTypeFontMgr_; | ||
} | ||
|
||
int SkFontMgr_AlphaSkia::onCountFamilies() const | ||
{ | ||
return currentFontMgr_->countFamilies(); | ||
} | ||
|
||
void SkFontMgr_AlphaSkia::onGetFamilyName(int index, SkString *familyName) const | ||
{ | ||
currentFontMgr_->getFamilyName(index, familyName); | ||
} | ||
sk_sp<SkFontStyleSet> SkFontMgr_AlphaSkia::onCreateStyleSet(int index) const | ||
{ | ||
return currentFontMgr_->createStyleSet(index); | ||
} | ||
|
||
sk_sp<SkFontStyleSet> SkFontMgr_AlphaSkia::onMatchFamily(const char familyName[]) const | ||
{ | ||
return currentFontMgr_->matchFamily(familyName); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onMatchFamilyStyle(const char familyName[], | ||
const SkFontStyle &fontStyle) const | ||
{ | ||
return currentFontMgr_->matchFamilyStyle(familyName, fontStyle); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle &style, | ||
const char *bcp47[], int bcp47Count, | ||
SkUnichar character) const | ||
{ | ||
return currentFontMgr_->matchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onMakeFromData(sk_sp<SkData> data, int ttcIndex) const | ||
{ | ||
return currentFontMgr_->makeFromData(data, ttcIndex); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream, int ttcIndex) const | ||
{ | ||
if (stream == nullptr) | ||
{ | ||
return nullptr; | ||
} | ||
return currentFontMgr_->makeFromStream(std::move(stream), ttcIndex); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream, const SkFontArguments &args) const | ||
{ | ||
if (stream == nullptr) | ||
{ | ||
return nullptr; | ||
} | ||
return currentFontMgr_->makeFromStream(std::move(stream), args); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onMakeFromFile(const char path[], int ttcIndex) const | ||
{ | ||
return currentFontMgr_->makeFromFile(path, ttcIndex); | ||
} | ||
|
||
sk_sp<SkTypeface> SkFontMgr_AlphaSkia::onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const | ||
{ | ||
return currentFontMgr_->legacyMakeTypeface(familyName, style); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#include "../../externals/skia/include/core/SkFontMgr.h" | ||
#include "../../externals/skia/include/ports/SkTypeface_win.h" | ||
#include "../include/SkFontMgr_alphaskia.h" | ||
|
||
sk_sp<SkFontMgr> SkFontMgr::Factory() { | ||
// TODO: functions for dynamic changing | ||
return SkFontMgr_New_DirectWrite(); | ||
sk_sp<SkFontMgr> SkFontMgr::Factory() | ||
{ | ||
return sk_make_sp<SkFontMgr_AlphaSkia>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters