Skip to content

Commit

Permalink
Add skia extension to allow setting default fontmgr on linux. Use it …
Browse files Browse the repository at this point in the history
…to allow the linux blimp client to use android fonts

BUG=617821

Review-Url: https://codereview.chromium.org/2500643002
Cr-Commit-Position: refs/heads/master@{#432023}
  • Loading branch information
steimelchrome authored and Commit bot committed Nov 15, 2016
1 parent f08f1e4 commit f6c1cd2
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 2 deletions.
49 changes: 49 additions & 0 deletions blimp/client/app/linux/blimp_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "blimp/client/app/linux/blimp_display_manager.h"
#include "blimp/client/app/linux/blimp_display_manager_delegate_main.h"
#include "blimp/client/core/settings/settings_prefs.h"
#include "blimp/client/core/switches/blimp_client_switches.h"
#include "blimp/client/public/blimp_client_context.h"
#include "blimp/client/public/contents/blimp_navigation_controller.h"
#include "blimp/client/support/compositor/compositor_dependencies_impl.h"
Expand All @@ -22,6 +23,10 @@
#include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_service_factory.h"
#include "skia/ext/fontmgr_default_linux.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontMgr_android.h"
#include "ui/gfx/x/x11_connection.h"

namespace {
Expand All @@ -39,11 +44,55 @@ class BlimpShellCommandLinePrefStore : public CommandLinePrefStore {
protected:
~BlimpShellCommandLinePrefStore() override = default;
};

bool HasAndroidFontSwitch() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
blimp::switches::kAndroidFontsPath);
}

std::string GetAndroidFontsDirectory() {
std::string android_fonts_dir =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
blimp::switches::kAndroidFontsPath);
if (android_fonts_dir.size() > 0 && android_fonts_dir.back() != '/') {
android_fonts_dir += '/';
}
return android_fonts_dir;
}

sk_sp<SkFontMgr> CreateAndroidFontMgr(std::string android_fonts_dir) {
SkFontMgr_Android_CustomFonts custom;
custom.fSystemFontUse =
SkFontMgr_Android_CustomFonts::SystemFontUse::kOnlyCustom;
custom.fBasePath = android_fonts_dir.c_str();

std::string font_config;
std::string fallback_font_config;
if (android_fonts_dir.find("kitkat") != std::string::npos) {
font_config = android_fonts_dir + "system_fonts.xml";
fallback_font_config = android_fonts_dir + "fallback_fonts.xml";
custom.fFallbackFontsXml = fallback_font_config.c_str();
} else {
font_config = android_fonts_dir + "fonts.xml";
custom.fFallbackFontsXml = nullptr;
}
custom.fFontsXml = font_config.c_str();
custom.fIsolated = true;

return sk_sp<SkFontMgr>(SkFontMgr_New_Android(&custom));
}

void SetupAndroidFontManager() {
if (HasAndroidFontSwitch()) {
SetDefaultSkiaFactory(CreateAndroidFontMgr(GetAndroidFontsDirectory()));
}
}
} // namespace

int main(int argc, const char**argv) {
base::AtExitManager at_exit;
base::CommandLine::Init(argc, argv);
SetupAndroidFontManager();

CHECK(gfx::InitializeThreadedX11());

Expand Down
2 changes: 2 additions & 0 deletions blimp/client/core/switches/blimp_client_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ const char kEngineTransport[] = "engine-transport";

const char kDownloadWholeDocument[] = "download-whole-document";

const char kAndroidFontsPath[] = "android-fonts-path";

} // namespace switches
} // namespace blimp
3 changes: 3 additions & 0 deletions blimp/client/core/switches/blimp_client_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern const char kEngineTransport[];
// Enables downloading the complete page from the engine.
extern const char kDownloadWholeDocument[];

// Specifies directory where android fonts are stored for use in Linux client.
extern const char kAndroidFontsPath[];

} // namespace switches
} // namespace blimp

Expand Down
3 changes: 1 addition & 2 deletions skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ component("skia") {
"ext/benchmarking_canvas.cc",
"ext/convolver.cc",
"ext/event_tracer_impl.cc",
"ext/fontmgr_default_linux.cc",
"ext/fontmgr_default_win.cc",
"ext/google_logging.cc",
"ext/image_operations.cc",
Expand Down Expand Up @@ -251,7 +252,6 @@ component("skia") {
"//third_party/skia/src/ports/SkFontHost_mac.cpp",
"//third_party/skia/src/ports/SkFontHost_win.cpp",
"//third_party/skia/src/ports/SkFontMgr_FontConfigInterface.cpp",
"//third_party/skia/src/ports/SkFontMgr_FontConfigInterface_factory.cpp",
"//third_party/skia/src/ports/SkFontMgr_android.cpp",
"//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
"//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
Expand Down Expand Up @@ -368,7 +368,6 @@ component("skia") {
"//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
"//third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp",
"//third_party/skia/src/ports/SkFontMgr_FontConfigInterface.cpp",
"//third_party/skia/src/ports/SkFontMgr_FontConfigInterface_factory.cpp",
]
}

Expand Down
25 changes: 25 additions & 0 deletions skia/ext/fontmgr_default_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 The Chromium 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 "skia/ext/fontmgr_default_linux.h"

#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontMgr_FontConfigInterface.h"

namespace {
sk_sp<SkFontMgr> g_default_fontmgr;
} // namespace

void SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr) {
g_default_fontmgr = fontmgr;
}

SK_API SkFontMgr* SkFontMgr::Factory() {
if (g_default_fontmgr) {
return SkRef(g_default_fontmgr.get());
}
sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
return fci ? SkFontMgr_New_FCI(std::move(fci)) : nullptr;
}
15 changes: 15 additions & 0 deletions skia/ext/fontmgr_default_linux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SKIA_EXT_FONTMGR_DEFAULT_LINUX_H_
#define SKIA_EXT_FONTMGR_DEFAULT_LINUX_H_

#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkTypes.h"

class SkFontMgr;

void SK_API SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr);

#endif // SKIA_EXT_FONTMGR_DEFAULT_LINUX_H_

0 comments on commit f6c1cd2

Please sign in to comment.