Skip to content

Commit

Permalink
Allow per-platform customization of the default Skia font manager (fl…
Browse files Browse the repository at this point in the history
…utter#8358)

The font manager returned by SkFontMgr::RefDefault is determined by Skia's
build configuration flags.  Embedders may want to use a default font manager
other than the one selected by their build of Skia.
  • Loading branch information
jason-simmons authored Mar 29, 2019
1 parent 3de50b8 commit 6d1a6a4
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ FILE: ../../../flutter/synchronization/semaphore_unittest.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform.h
FILE: ../../../flutter/third_party/txt/src/txt/platform_android.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform_linux.cc
FILE: ../../../flutter/third_party/txt/src/txt/platform_mac.mm
FILE: ../../../flutter/vulkan/skia_vulkan_header.h
FILE: ../../../flutter/vulkan/vulkan_application.cc
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/text/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void _LoadFontFromList(Dart_NativeArguments args) {

FontCollection::FontCollection()
: collection_(std::make_shared<txt::FontCollection>()) {
collection_->SetDefaultFontManager(SkFontMgr::RefDefault());
collection_->SetupDefaultFontManager();

dynamic_font_manager_ = sk_make_sp<txt::DynamicFontManager>();
collection_->SetDynamicFontManager(dynamic_font_manager_);
Expand Down
2 changes: 2 additions & 0 deletions third_party/txt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ source_set("txt") {
deps += [ "$flutter_root/fml" ]
} else if (is_android) {
sources += [ "src/txt/platform_android.cc" ]
} else if (is_linux) {
sources += [ "src/txt/platform_linux.cc" ]
} else {
sources += [ "src/txt/platform.cc" ]
}
Expand Down
4 changes: 2 additions & 2 deletions third_party/txt/src/txt/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ size_t FontCollection::GetFontManagersCount() const {
return GetFontManagerOrder().size();
}

void FontCollection::SetDefaultFontManager(sk_sp<SkFontMgr> font_manager) {
default_font_manager_ = font_manager;
void FontCollection::SetupDefaultFontManager() {
default_font_manager_ = GetDefaultFontManager();
}

void FontCollection::SetAssetFontManager(sk_sp<SkFontMgr> font_manager) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/txt/src/txt/font_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FontCollection : public std::enable_shared_from_this<FontCollection> {

size_t GetFontManagersCount() const;

void SetDefaultFontManager(sk_sp<SkFontMgr> font_manager);
void SetupDefaultFontManager();
void SetAssetFontManager(sk_sp<SkFontMgr> font_manager);
void SetDynamicFontManager(sk_sp<SkFontMgr> font_manager);
void SetTestFontManager(sk_sp<SkFontMgr> font_manager);
Expand Down
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ std::string GetDefaultFontFamily() {
return "Arial";
}

sk_sp<SkFontMgr> GetDefaultFontManager() {
return SkFontMgr::RefDefault();
}

} // namespace txt
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
#include <string>
#include "flutter/fml/macros.h"

#include "third_party/skia/include/core/SkFontMgr.h"

namespace txt {

std::string GetDefaultFontFamily();

sk_sp<SkFontMgr> GetDefaultFontManager();

} // namespace txt

#endif // TXT_PLATFORM_H_
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/platform_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ std::string GetDefaultFontFamily() {
return "sans-serif";
}

sk_sp<SkFontMgr> GetDefaultFontManager() {
return SkFontMgr::RefDefault();
}

} // namespace txt
19 changes: 19 additions & 0 deletions third_party/txt/src/txt/platform_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "txt/platform.h"

#include "third_party/skia/include/ports/SkFontMgr_directory.h"

namespace txt {

std::string GetDefaultFontFamily() {
return "Arial";
}

sk_sp<SkFontMgr> GetDefaultFontManager() {
return SkFontMgr_New_Custom_Directory("/usr/share/fonts/");
}

} // namespace txt
4 changes: 4 additions & 0 deletions third_party/txt/src/txt/platform_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
}
}

sk_sp<SkFontMgr> GetDefaultFontManager() {
return SkFontMgr::RefDefault();
}

} // namespace txt

0 comments on commit 6d1a6a4

Please sign in to comment.