Commit 54ec4f23 authored by Mike Reed's avatar Mike Reed Committed by Commit Bot

use new SkFontMgr API

TBR=

Bug: 
Change-Id: I2e837413ced0b2befa77e6c8cff4b548cc574198
Reviewed-on: https://chromium-review.googlesource.com/685586
Commit-Queue: Mike Reed <reed@chromium.org>
Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Reviewed-by: default avatarBen Wagner <bungeman@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506506}
parent 56a2356a
......@@ -17,6 +17,7 @@
#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
......@@ -178,23 +179,25 @@ class TestSkFontMgr : public SkFontMgr {
return nullptr;
}
SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override {
sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override {
ADD_FAILURE();
return nullptr;
}
SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const override {
sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
int ttcIndex) const override {
ADD_FAILURE();
return nullptr;
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
sk_sp<SkTypeface> onMakeFromFile(const char path[],
int ttcIndex) const override {
ADD_FAILURE();
return nullptr;
}
SkTypeface* onLegacyCreateTypeface(const char familyName[],
SkFontStyle style) const override {
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[],
SkFontStyle style) const override {
ADD_FAILURE();
return nullptr;
}
......
......@@ -158,7 +158,7 @@ void RegisterSideloadedTypefaces(SkFontMgr* fontmgr) {
for (std::vector<std::string>::const_iterator i(files.begin());
i != files.end();
++i) {
SkTypeface* typeface = fontmgr->createFromFile(i->c_str());
SkTypeface* typeface = fontmgr->makeFromFile(i->c_str()).release();
blink::WebFontRendering::AddSideloadedFontForTesting(typeface);
}
}
......
......@@ -220,10 +220,6 @@ SK_API void SkDebugf_FileLine(const char* file, int line, bool fatal,
#define SK_SUPPORT_LEGACY_TILED_BITMAPS
#endif
#ifndef SK_SUPPORT_LEGACY_FONTMGR_API
#define SK_SUPPORT_LEGACY_FONTMGR_API
#endif
#ifndef SK_SUPPORT_LEGACY_SAFESIZE64
#define SK_SUPPORT_LEGACY_SAFESIZE64
#endif
......
......@@ -91,17 +91,17 @@ FontPlatformData FontCustomPlatformData::GetFontPlatformData(
#else
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
#endif
Vector<SkFontMgr::FontParameters::Axis, 0> axes;
Vector<SkFontArguments::Axis, 0> axes;
SkFontMgr::FontParameters::Axis weight_axis = {
SkFontArguments::Axis weight_axis = {
SkSetFourByteTag('w', 'g', 'h', 't'),
SkFloatToScalar(selection_capabilities.weight.clampToRange(
selection_request.weight))};
SkFontMgr::FontParameters::Axis width_axis = {
SkFontArguments::Axis width_axis = {
SkSetFourByteTag('w', 'd', 't', 'h'),
SkFloatToScalar(selection_capabilities.width.clampToRange(
selection_request.width))};
SkFontMgr::FontParameters::Axis slant_axis = {
SkFontArguments::Axis slant_axis = {
SkSetFourByteTag('s', 'l', 'n', 't'),
SkFloatToScalar(selection_capabilities.slope.clampToRange(
selection_request.slope))};
......@@ -113,16 +113,16 @@ FontPlatformData FontCustomPlatformData::GetFontPlatformData(
if (variation_settings && variation_settings->size() < UINT16_MAX) {
axes.ReserveCapacity(variation_settings->size() + axes.size());
for (size_t i = 0; i < variation_settings->size(); ++i) {
SkFontMgr::FontParameters::Axis axis = {
SkFontArguments::Axis axis = {
AtomicStringToFourByteTag(variation_settings->at(i).Tag()),
SkFloatToScalar(variation_settings->at(i).Value())};
axes.push_back(axis);
}
}
sk_sp<SkTypeface> sk_variation_font(fm->createFromStream(
base_typeface_->openStream(nullptr)->duplicate().release(),
SkFontMgr::FontParameters().setAxes(axes.data(), axes.size())));
sk_sp<SkTypeface> sk_variation_font(fm->makeFromStream(
base_typeface_->openStream(nullptr)->duplicate(),
SkFontArguments().setAxes(axes.data(), axes.size())));
if (sk_variation_font) {
ReportWebFontInstantiationResult(kSuccessVariableWebFont);
......
......@@ -218,12 +218,13 @@ sk_sp<SkTypeface> WebFontDecoder::Decode(SharedBuffer* buffer) {
// TODO(fmalita): we can avoid this copy by processing into a
// SkDynamicMemoryWStream-backed OTSStream.
sk_sp<SkData> sk_data = SkData::MakeWithCopy(output.get(), decoded_length);
SkMemoryStream* stream = new SkMemoryStream(sk_data);
std::unique_ptr<SkStreamAsset> stream(new SkMemoryStream(sk_data));
#if defined(OS_WIN)
sk_sp<SkTypeface> typeface(
FontCache::GetFontCache()->FontManager()->createFromStream(stream));
FontCache::GetFontCache()->FontManager()->makeFromStream(
std::move(stream)));
#else
sk_sp<SkTypeface> typeface = SkTypeface::MakeFromStream(stream);
sk_sp<SkTypeface> typeface = SkTypeface::MakeFromStream(stream.release());
#endif
if (!typeface) {
SetErrorString("Not a valid font data");
......
......@@ -44,7 +44,7 @@ static AtomicString DefaultFontFamily(SkFontMgr* font_manager) {
// Pass nullptr to get the default typeface. The default typeface in Android
// is "sans-serif" if exists, or the first entry in fonts.xml.
sk_sp<SkTypeface> typeface(
font_manager->legacyCreateTypeface(nullptr, SkFontStyle()));
font_manager->legacyMakeTypeface(nullptr, SkFontStyle()));
if (typeface) {
SkString family_name;
typeface->getFamilyName(&family_name);
......
......@@ -182,7 +182,7 @@ FontPlatformData::FontPlatformData(NSFont* ns_font,
}
if (variation_settings && variation_settings->size() < UINT16_MAX) {
SkFontMgr::FontParameters::Axis axes[variation_settings->size()];
SkFontArguments::Axis axes[variation_settings->size()];
for (size_t i = 0; i < variation_settings->size(); ++i) {
AtomicString feature_tag = variation_settings->at(i).Tag();
axes[i] = {AtomicStringToFourByteTag(feature_tag),
......@@ -191,9 +191,9 @@ FontPlatformData::FontPlatformData(NSFont* ns_font,
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
// TODO crbug.com/670246: Refactor this to a future Skia API that acccepts
// axis parameters on system fonts directly.
typeface_ = sk_sp<SkTypeface>(fm->createFromStream(
typeface_->openStream(nullptr)->duplicate().release(),
SkFontMgr::FontParameters().setAxes(axes, variation_settings->size())));
typeface_ = fm->makeFromStream(
typeface_->openStream(nullptr)->duplicate(),
SkFontArguments().setAxes(axes, variation_settings->size()));
}
}
......
......@@ -273,8 +273,7 @@ sk_sp<SkTypeface> FontCache::CreateTypeface(
// FIXME: Use m_fontManager, matchFamilyStyle instead of
// legacyCreateTypeface on all platforms.
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
return sk_sp<SkTypeface>(
fm->legacyCreateTypeface(name.data(), font_description.SkiaFontStyle()));
return fm->legacyMakeTypeface(name.data(), font_description.SkiaFontStyle());
}
#if !defined(OS_WIN)
......
......@@ -25,9 +25,7 @@ bool g_default_impl_initialized = false;
bool IsFontFamilyAvailable(const std::string& family, SkFontMgr* fontManager) {
#if defined(OS_LINUX)
sk_sp<SkTypeface> typeface(
fontManager->legacyCreateTypeface(family.c_str(), SkFontStyle()));
return typeface;
return fontManager->legacyMakeTypeface(family.c_str(), SkFontStyle());
#else
sk_sp<SkFontStyleSet> set(fontManager->matchFamily(family.c_str()));
return set && set->count();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment