forked from flutter/engine
-
-
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.
Add option to desktop test shells to use an embedded font for consist…
…ent unit tests. (flutter#3301) * This allows the tests to add their own FLX files but still use consistent fonts. * The test fonts are only embedded on the desktop test shells. The option is not available on mobile platforms. * Right now, all fonts will resolve to the test font. If we want tests to be able to use the fonts they embed in FLX files but use the test font for platform fallbacks, we will need to add font selector fallbacks. I can do this in an another patch. So far, there are no users of this functionality.
- Loading branch information
1 parent
9eeed70
commit e133b4f
Showing
11 changed files
with
1,371 additions
and
6 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
// 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 FLUTTER_RUNTIME_TEST_FONT_DATA_H_ | ||
#define FLUTTER_RUNTIME_TEST_FONT_DATA_H_ | ||
|
||
#include <memory> | ||
#include "third_party/skia/include/core/SkStream.h" | ||
|
||
namespace blink { | ||
|
||
std::unique_ptr<SkStreamAsset> GetTestFontData(); | ||
|
||
} // namespace blink | ||
|
||
#endif // FLUTTER_RUNTIME_TEST_FONT_DATA_H_ |
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,50 @@ | ||
// 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 "flutter/runtime/test_font_selector.h" | ||
#include "flutter/lib/ui/ui_dart_state.h" | ||
#include "flutter/runtime/test_font_data.h" | ||
#include "flutter/sky/engine/platform/fonts/SimpleFontData.h" | ||
#include "third_party/skia/include/core/SkTypeface.h" | ||
|
||
namespace blink { | ||
|
||
void TestFontSelector::Install() { | ||
auto font_selector = adoptRef(new TestFontSelector()); | ||
UIDartState::Current()->set_font_selector(font_selector); | ||
} | ||
|
||
TestFontSelector::TestFontSelector() = default; | ||
|
||
TestFontSelector::~TestFontSelector() = default; | ||
|
||
PassRefPtr<FontData> TestFontSelector::getFontData( | ||
const FontDescription&, | ||
const AtomicString& familyName) { | ||
if (test_font_data_ != nullptr) { | ||
return test_font_data_; | ||
} | ||
|
||
auto typeface = SkTypeface::MakeFromStream(GetTestFontData().get()); | ||
|
||
FontPlatformData platform_data(typeface, "Ahem", 14.0, false, false, | ||
FontOrientation::Horizontal, false); | ||
|
||
test_font_data_ = | ||
SimpleFontData::create(platform_data, CustomFontData::create()); | ||
|
||
return test_font_data_; | ||
} | ||
|
||
void TestFontSelector::willUseFontData(const FontDescription&, | ||
const AtomicString& familyName, | ||
UChar32) {} | ||
|
||
unsigned TestFontSelector::version() const { | ||
return 0; | ||
} | ||
|
||
void TestFontSelector::fontCacheInvalidated() {} | ||
|
||
} // namespace blink |
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,41 @@ | ||
// 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 FLUTTER_RUNTIME_TEST_FONT_SELECTOR_H_ | ||
#define FLUTTER_RUNTIME_TEST_FONT_SELECTOR_H_ | ||
|
||
#include "flutter/sky/engine/platform/fonts/FontSelector.h" | ||
#include "flutter/sky/engine/wtf/RefPtr.h" | ||
#include "lib/ftl/macros.h" | ||
|
||
namespace blink { | ||
|
||
class TestFontSelector : public FontSelector { | ||
public: | ||
static void Install(); | ||
|
||
~TestFontSelector() override; | ||
|
||
PassRefPtr<FontData> getFontData(const FontDescription&, | ||
const AtomicString& familyName) override; | ||
|
||
void willUseFontData(const FontDescription&, | ||
const AtomicString& familyName, | ||
UChar32) override; | ||
|
||
unsigned version() const override; | ||
|
||
void fontCacheInvalidated() override; | ||
|
||
private: | ||
WTF::RefPtr<FontData> test_font_data_; | ||
|
||
TestFontSelector(); | ||
|
||
FTL_DISALLOW_COPY_AND_ASSIGN(TestFontSelector); | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // FLUTTER_RUNTIME_TEST_FONT_SELECTOR_H_ |
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
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
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