Update libTXT sources and tests from initial prototype.
This separates libTXT tests and Minikin tests and accounts for building with an older version of ICU. Once ICU has been updated, the workarounds for emoji handling will be removed. Change-Id: Ic184e653a2561629b01f98aeb4f6fb88aebbfa88
This commit is contained in:
@@ -16,9 +16,9 @@ group("txt") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"libs/minikin",
|
||||
"src",
|
||||
"tests/unittest($host_toolchain)",
|
||||
"examples:txt_example($host_toolchain)",
|
||||
"src",
|
||||
"tests/txt($host_toolchain)", # txt_unittests
|
||||
"tests/unittest($host_toolchain)", # minikin_unittest
|
||||
]
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ executable("txt_example") {
|
||||
deps = [
|
||||
"//dart/runtime:libdart_jit",
|
||||
"//flutter/fml",
|
||||
"//lib/txt/libs/minikin",
|
||||
"//lib/txt/src",
|
||||
"//third_party/icu:icuuc",
|
||||
"//third_party/skia",
|
||||
|
||||
@@ -31,7 +31,9 @@ int runTest() {
|
||||
"I can tell. Rock, rock on. "
|
||||
"\xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5"
|
||||
"\x87";
|
||||
icu::UnicodeString text = icu::UnicodeString::fromUTF8(utf8_text);
|
||||
icu::UnicodeString icu_text = icu::UnicodeString::fromUTF8(utf8_text);
|
||||
std::u16string u16_text(icu_text.getBuffer(),
|
||||
icu_text.getBuffer() + icu_text.length());
|
||||
|
||||
ParagraphStyle paragraph_style;
|
||||
ParagraphBuilder builder(paragraph_style);
|
||||
@@ -39,18 +41,18 @@ int runTest() {
|
||||
style.color = SK_ColorBLUE;
|
||||
style.font_size = 32.0;
|
||||
builder.PushStyle(style);
|
||||
builder.AddText(text.getBuffer(), text.length());
|
||||
builder.AddText(u16_text);
|
||||
style.color = SK_ColorYELLOW;
|
||||
builder.PushStyle(style);
|
||||
builder.AddText(text.getBuffer(), text.length());
|
||||
builder.AddText(u16_text);
|
||||
builder.Pop();
|
||||
builder.AddText(text.getBuffer(), text.length());
|
||||
builder.AddText(u16_text);
|
||||
builder.Pop();
|
||||
auto paragraph = builder.Build();
|
||||
|
||||
int width = 800;
|
||||
int height = 600;
|
||||
paragraph->Layout(width);
|
||||
paragraph->Layout(ParagraphConstraints(width));
|
||||
|
||||
SkAutoGraphics ag;
|
||||
SkBitmap bitmap;
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
* An implementation of Liang's hyphenation algorithm.
|
||||
*/
|
||||
|
||||
#ifndef U_USING_ICU_NAMESPACE
|
||||
#define U_USING_ICU_NAMESPACE 0
|
||||
#endif // U_USING_ICU_NAMESPACE
|
||||
|
||||
#include "unicode/locid.h"
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#ifndef MINIKIN_LINE_BREAKER_H
|
||||
#define MINIKIN_LINE_BREAKER_H
|
||||
|
||||
#ifndef U_USING_ICU_NAMESPACE
|
||||
#define U_USING_ICU_NAMESPACE 0
|
||||
#endif // U_USING_ICU_NAMESPACE
|
||||
|
||||
#include "unicode/brkiter.h"
|
||||
#include "unicode/locid.h"
|
||||
#include <cmath>
|
||||
|
||||
@@ -17,6 +17,8 @@ config("minikin_config") {
|
||||
}
|
||||
|
||||
static_library("minikin") {
|
||||
defines = [ "WIP_NEEDS_ICU_UPDATE" ]
|
||||
|
||||
sources = [
|
||||
"CmapCoverage.cpp",
|
||||
"Emoji.cpp",
|
||||
|
||||
@@ -37,16 +37,27 @@ bool isNewEmoji(uint32_t c) {
|
||||
}
|
||||
|
||||
bool isEmoji(uint32_t c) {
|
||||
#if WIP_NEEDS_ICU_UPDATE
|
||||
return false;
|
||||
#else // WIP_NEEDS_ICU_UPDATE
|
||||
return isNewEmoji(c) || u_hasBinaryProperty(c, UCHAR_EMOJI);
|
||||
#endif // WIP_NEEDS_ICU_UPDATE
|
||||
}
|
||||
|
||||
bool isEmojiModifier(uint32_t c) {
|
||||
#if WIP_NEEDS_ICU_UPDATE
|
||||
return false;
|
||||
#else // WIP_NEEDS_ICU_UPDATE
|
||||
// Emoji modifier are not expected to change, so there's a small change we need to customize
|
||||
// this.
|
||||
return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER);
|
||||
#endif // WIP_NEEDS_ICU_UPDATE
|
||||
}
|
||||
|
||||
bool isEmojiBase(uint32_t c) {
|
||||
#if WIP_NEEDS_ICU_UPDATE
|
||||
return false;
|
||||
#else // WIP_NEEDS_ICU_UPDATE
|
||||
// These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep
|
||||
// them as emoji modifier bases since there are fonts and user-generated text out there that
|
||||
// treats these as potential emoji bases.
|
||||
@@ -62,6 +73,7 @@ bool isEmojiBase(uint32_t c) {
|
||||
return true;
|
||||
}
|
||||
return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE);
|
||||
#endif // WIP_NEEDS_ICU_UPDATE
|
||||
}
|
||||
|
||||
UCharDirection emojiBidiOverride(const void* /* context */, UChar32 c) {
|
||||
|
||||
@@ -711,6 +711,10 @@ static void addFeatures(const string &str, vector<hb_feature_t>* features) {
|
||||
static const hb_codepoint_t CHAR_HYPHEN = 0x2010; /* HYPHEN */
|
||||
|
||||
static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, hb_font_t* font) {
|
||||
#if WIP_NEEDS_ICU_UPDATE
|
||||
(void)CHAR_HYPHEN;
|
||||
return 0x002D; // HYPHEN-MINUS
|
||||
#else // WIP_NEEDS_ICU_UPDATE
|
||||
hb_codepoint_t glyph;
|
||||
if (preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */
|
||||
|| preferredHyphen == 0x05BE /* HEBREW PUNCTUATION MAQAF */
|
||||
@@ -732,6 +736,7 @@ static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen,
|
||||
}
|
||||
}
|
||||
return preferredHyphen;
|
||||
#endif // WIP_NEEDS_ICU_UPDATE
|
||||
}
|
||||
|
||||
static inline void addHyphenToHbBuffer(hb_buffer_t* buffer, hb_font_t* font, uint32_t hyphen,
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
static_library("src") {
|
||||
source_set("src") {
|
||||
sources = [
|
||||
"font_provider.cc",
|
||||
"font_provider.h",
|
||||
"font_collection.cc",
|
||||
"font_collection.h",
|
||||
"font_skia.cc",
|
||||
"font_skia.h",
|
||||
"font_style.h",
|
||||
@@ -26,15 +26,18 @@ static_library("src") {
|
||||
"paragraph.h",
|
||||
"paragraph_builder.cc",
|
||||
"paragraph_builder.h",
|
||||
"paragraph_constraints.cc",
|
||||
"paragraph_constraints.h",
|
||||
"paragraph_style.cc",
|
||||
"paragraph_style.h",
|
||||
"styled_runs.cc",
|
||||
"styled_runs.h",
|
||||
"text_align.h",
|
||||
"text_style.cc",
|
||||
"text_style.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//lib/ftl",
|
||||
deps = [
|
||||
"//lib/txt/libs/minikin",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
87
engine/src/flutter/src/font_collection.cc
Normal file
87
engine/src/flutter/src/font_collection.cc
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lib/txt/src/font_collection.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "lib/txt/src/font_skia.h"
|
||||
#include "third_party/skia/include/ports/SkFontMgr.h"
|
||||
|
||||
namespace txt {
|
||||
|
||||
FontCollection& FontCollection::GetDefaultFontCollection() {
|
||||
static FontCollection* collection = nullptr;
|
||||
static std::once_flag once;
|
||||
std::call_once(once, []() { collection = new FontCollection(); });
|
||||
return *collection;
|
||||
}
|
||||
|
||||
FontCollection::FontCollection() = default;
|
||||
|
||||
FontCollection::~FontCollection() = default;
|
||||
|
||||
std::shared_ptr<minikin::FontCollection>
|
||||
FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) {
|
||||
// Get the Skia font manager.
|
||||
auto skia_font_manager = SkFontMgr::RefDefault();
|
||||
FTL_DCHECK(skia_font_manager != nullptr);
|
||||
|
||||
// Ask Skia to resolve a font style set for a font family name.
|
||||
// FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText
|
||||
// crashes when passed a null string. This seems to be a bug in Skia as
|
||||
// SkFontMgr explicitly says passing in nullptr gives the default font.
|
||||
auto font_style_set = skia_font_manager->matchFamily(
|
||||
family.length() == 0 ? "Helvetica" : family.c_str());
|
||||
FTL_DCHECK(font_style_set != nullptr);
|
||||
|
||||
std::vector<minikin::Font> minikin_fonts;
|
||||
|
||||
// Add fonts to the Minikin font family.
|
||||
for (int i = 0, style_count = font_style_set->count(); i < style_count; ++i) {
|
||||
// Create the skia typeface
|
||||
auto skia_typeface =
|
||||
sk_ref_sp<SkTypeface>(font_style_set->createTypeface(i));
|
||||
|
||||
if (skia_typeface == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the minikin font from the skia typeface.
|
||||
minikin::Font minikin_font(
|
||||
std::make_shared<FontSkia>(skia_typeface),
|
||||
minikin::FontStyle{skia_typeface->fontStyle().weight(),
|
||||
skia_typeface->isItalic()});
|
||||
|
||||
minikin_fonts.emplace_back(std::move(minikin_font));
|
||||
}
|
||||
|
||||
// Create a Minikin font family.
|
||||
auto minikin_family =
|
||||
std::make_shared<minikin::FontFamily>(std::move(minikin_fonts));
|
||||
|
||||
// Create a vector of font families for the Minkin font collection. For now,
|
||||
// we only have one family in our collection.
|
||||
std::vector<std::shared_ptr<minikin::FontFamily>> minikin_families = {
|
||||
minikin_family,
|
||||
};
|
||||
|
||||
// Return the font collection.
|
||||
return std::make_shared<minikin::FontCollection>(minikin_families);
|
||||
}
|
||||
|
||||
} // namespace txt
|
||||
@@ -22,25 +22,25 @@
|
||||
#include <vector>
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/txt/include/minikin/FontCollection.h"
|
||||
#include "lib/txt/include/minikin/FontFamily.h"
|
||||
#include "minikin/FontCollection.h"
|
||||
#include "minikin/FontFamily.h"
|
||||
|
||||
namespace txt {
|
||||
|
||||
class FontProvider {
|
||||
class FontCollection {
|
||||
public:
|
||||
static FontProvider& GetDefault();
|
||||
static FontCollection& GetDefaultFontCollection();
|
||||
|
||||
FontProvider();
|
||||
FontCollection();
|
||||
|
||||
~FontProvider();
|
||||
~FontCollection();
|
||||
|
||||
std::shared_ptr<minikin::FontCollection> GetFontCollectionForFamily(
|
||||
std::shared_ptr<minikin::FontCollection> GetMinikinFontCollectionForFamily(
|
||||
const std::string& family);
|
||||
|
||||
private:
|
||||
// TODO(chinmaygarde): Caches go here.
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(FontProvider);
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection);
|
||||
};
|
||||
|
||||
} // namespace txt
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lib/txt/src/font_provider.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "lib/txt/src/font_skia.h"
|
||||
#include "third_party/skia/include/ports/SkFontMgr.h"
|
||||
|
||||
namespace txt {
|
||||
namespace {
|
||||
|
||||
bool IsItalic(SkFontStyle::Slant slant) {
|
||||
return slant != SkFontStyle::Slant::kUpright_Slant;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
FontProvider& FontProvider::GetDefault() {
|
||||
static FontProvider* provider = nullptr;
|
||||
static std::once_flag once;
|
||||
std::call_once(once, []() { provider = new FontProvider(); });
|
||||
return *provider;
|
||||
}
|
||||
|
||||
FontProvider::FontProvider() = default;
|
||||
|
||||
FontProvider::~FontProvider() = default;
|
||||
|
||||
std::shared_ptr<minikin::FontCollection>
|
||||
FontProvider::GetFontCollectionForFamily(const std::string& family) {
|
||||
// Get the Skia font manager.
|
||||
auto font_manager = SkFontMgr::RefDefault();
|
||||
FTL_DCHECK(font_manager != nullptr);
|
||||
|
||||
// Ask Skia to resolve a font style set for a font family name.
|
||||
// FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText
|
||||
// crashes when passed a null string. This seems to be a bug in Skia as
|
||||
// SkFontMgr explicitly says passing in nullptr gives the default font.
|
||||
auto font_style_set = font_manager->matchFamily(
|
||||
family.length() == 0 ? "Helvetica" : family.c_str());
|
||||
FTL_DCHECK(font_style_set != nullptr);
|
||||
|
||||
std::vector<minikin::Font> fonts;
|
||||
|
||||
// Add fonts to the Minikin font family.
|
||||
for (int i = 0, style_count = font_style_set->count(); i < style_count; ++i) {
|
||||
auto skia_typeface =
|
||||
sk_ref_sp<SkTypeface>(font_style_set->createTypeface(i));
|
||||
auto typeface = std::make_shared<FontSkia>(std::move(skia_typeface));
|
||||
|
||||
SkFontStyle font_style;
|
||||
font_style_set->getStyle(i, &font_style, nullptr);
|
||||
minikin::FontStyle style(font_style.weight(), IsItalic(font_style.slant()));
|
||||
|
||||
fonts.push_back(minikin::Font(std::move(typeface), style));
|
||||
}
|
||||
|
||||
auto minikin_family = std::make_shared<minikin::FontFamily>(std::move(fonts));
|
||||
return std::make_shared<minikin::FontCollection>(std::move(minikin_family));
|
||||
}
|
||||
|
||||
} // namespace txt
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "lib/ftl/logging.h"
|
||||
|
||||
#include "lib/txt/src/font_provider.h"
|
||||
#include "lib/txt/src/font_collection.h"
|
||||
#include "lib/txt/src/font_skia.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkPaint.h"
|
||||
@@ -114,7 +114,8 @@ void Paragraph::SetText(std::vector<uint16_t> text, StyledRuns runs) {
|
||||
}
|
||||
|
||||
void Paragraph::AddRunsToLineBreaker() {
|
||||
auto collection = FontProvider::GetDefault().GetFontCollectionForFamily("");
|
||||
auto collection = FontCollection::GetDefaultFontCollection()
|
||||
.GetMinikinFontCollectionForFamily("");
|
||||
minikin::FontStyle font;
|
||||
minikin::MinikinPaint paint;
|
||||
for (size_t i = 0; i < runs_.size(); ++i) {
|
||||
@@ -124,8 +125,8 @@ void Paragraph::AddRunsToLineBreaker() {
|
||||
}
|
||||
}
|
||||
|
||||
void Paragraph::Layout(double width) {
|
||||
breaker_.setLineWidths(0.0f, 0, width);
|
||||
void Paragraph::Layout(const ParagraphConstraints& constraints) {
|
||||
breaker_.setLineWidths(0.0f, 0, constraints.width());
|
||||
AddRunsToLineBreaker();
|
||||
size_t breaks_count = breaker_.computeBreaks();
|
||||
const int* breaks = breaker_.getBreaks();
|
||||
@@ -138,7 +139,8 @@ void Paragraph::Layout(double width) {
|
||||
minikin::MinikinPaint minikin_paint;
|
||||
|
||||
SkTextBlobBuilder builder;
|
||||
auto collection = FontProvider::GetDefault().GetFontCollectionForFamily("");
|
||||
auto collection = FontCollection::GetDefaultFontCollection()
|
||||
.GetMinikinFontCollectionForFamily("");
|
||||
minikin::Layout layout;
|
||||
SkScalar x = 0.0f;
|
||||
SkScalar y = 0.0f;
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <minikin/LineBreaker.h>
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/txt/src/paint_record.h"
|
||||
#include "lib/txt/src/paragraph_constraints.h"
|
||||
#include "lib/txt/src/styled_runs.h"
|
||||
#include "minikin/LineBreaker.h"
|
||||
#include "third_party/skia/include/core/SkTextBlob.h"
|
||||
|
||||
class SkCanvas;
|
||||
@@ -36,7 +36,7 @@ class Paragraph {
|
||||
|
||||
~Paragraph();
|
||||
|
||||
void Layout(double width);
|
||||
void Layout(const ParagraphConstraints& constraints);
|
||||
|
||||
void Paint(SkCanvas* canvas, double x, double y);
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ void ParagraphBuilder::Pop() {
|
||||
runs_.StartRun(style_index, text_index);
|
||||
}
|
||||
|
||||
void ParagraphBuilder::AddText(const uint16_t* text, size_t length) {
|
||||
text_.insert(text_.end(), text, text + length);
|
||||
void ParagraphBuilder::AddText(const std::u16string& text) {
|
||||
text_.insert(text_.end(), text.begin(), text.end());
|
||||
}
|
||||
|
||||
std::unique_ptr<Paragraph> ParagraphBuilder::Build() {
|
||||
|
||||
@@ -38,7 +38,7 @@ class ParagraphBuilder {
|
||||
|
||||
void Pop();
|
||||
|
||||
void AddText(const uint16_t* text, size_t length);
|
||||
void AddText(const std::u16string& text);
|
||||
|
||||
std::unique_ptr<Paragraph> Build();
|
||||
|
||||
|
||||
23
engine/src/flutter/src/paragraph_constraints.cc
Normal file
23
engine/src/flutter/src/paragraph_constraints.cc
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lib/txt/src/paragraph_constraints.h"
|
||||
|
||||
namespace txt {
|
||||
|
||||
ParagraphConstraints::ParagraphConstraints(double width) : width_(width) {}
|
||||
|
||||
} // namespace txt
|
||||
38
engine/src/flutter/src/paragraph_constraints.h
Normal file
38
engine/src/flutter/src/paragraph_constraints.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_
|
||||
#define LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
|
||||
namespace txt {
|
||||
|
||||
class ParagraphConstraints {
|
||||
public:
|
||||
explicit ParagraphConstraints(double width);
|
||||
|
||||
double width() const { return width_; }
|
||||
|
||||
private:
|
||||
double width_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphConstraints);
|
||||
};
|
||||
|
||||
} // namespace txt
|
||||
|
||||
#endif // LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_
|
||||
17
engine/src/flutter/src/paragraph_style.cc
Normal file
17
engine/src/flutter/src/paragraph_style.cc
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lib/txt/src/paragraph_style.h"
|
||||
17
engine/src/flutter/src/text_style.cc
Normal file
17
engine/src/flutter/src/text_style.cc
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lib/txt/src/text_style.h"
|
||||
40
engine/src/flutter/tests/txt/BUILD.gn
Normal file
40
engine/src/flutter/tests/txt/BUILD.gn
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright 2017 Google, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
executable("txt") {
|
||||
output_name = "txt_unittests"
|
||||
|
||||
include_dirs = [
|
||||
"//lib/txt/src",
|
||||
"//lib/txt/include",
|
||||
"//third_party/icu/source/common",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"font_collection_unittests.cc",
|
||||
"paragraph_unittests.cc",
|
||||
"render_test.cc",
|
||||
"txt_run_all_unittests.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//dart/runtime:libdart_jit", # Logging
|
||||
"//flutter/fml",
|
||||
"//lib/txt/shims",
|
||||
"//lib/txt/src",
|
||||
"//third_party/gtest",
|
||||
"//third_party/harfbuzz",
|
||||
"//third_party/skia",
|
||||
]
|
||||
}
|
||||
25
engine/src/flutter/tests/txt/font_collection_unittests.cc
Normal file
25
engine/src/flutter/tests/txt/font_collection_unittests.cc
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "font_collection.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(FontCollection, HasDefaultRegistrations) {
|
||||
auto collection = txt::FontCollection::GetDefaultFontCollection()
|
||||
.GetMinikinFontCollectionForFamily("");
|
||||
|
||||
ASSERT_NE(collection.get(), nullptr);
|
||||
}
|
||||
47
engine/src/flutter/tests/txt/paragraph_unittests.cc
Normal file
47
engine/src/flutter/tests/txt/paragraph_unittests.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_builder.h"
|
||||
#include "render_test.h"
|
||||
#include "third_party/icu/source/common/unicode/unistr.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
TEST_F(RenderTest, SimpleParagraph) {
|
||||
const char* text = "Hello World";
|
||||
auto icu_text = icu::UnicodeString::fromUTF8(text);
|
||||
std::u16string u16_text(icu_text.getBuffer(),
|
||||
icu_text.getBuffer() + icu_text.length());
|
||||
|
||||
txt::ParagraphStyle paragraph_style;
|
||||
txt::ParagraphBuilder builder(paragraph_style);
|
||||
|
||||
txt::TextStyle text_style;
|
||||
text_style.color = SK_ColorBLACK;
|
||||
builder.PushStyle(text_style);
|
||||
|
||||
builder.AddText(u16_text);
|
||||
|
||||
builder.Pop();
|
||||
|
||||
auto paragraph = builder.Build();
|
||||
|
||||
paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()});
|
||||
|
||||
paragraph->Paint(GetCanvas(), 10.0, 10.0);
|
||||
|
||||
ASSERT_TRUE(Snapshot());
|
||||
}
|
||||
67
engine/src/flutter/tests/txt/render_test.cc
Normal file
67
engine/src/flutter/tests/txt/render_test.cc
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "render_test.h"
|
||||
#include "third_party/skia/include/core/SkImageEncoder.h"
|
||||
#include "third_party/skia/include/core/SkStream.h"
|
||||
|
||||
RenderTest::RenderTest() : snapshots_(0) {}
|
||||
|
||||
RenderTest::~RenderTest() {}
|
||||
|
||||
SkCanvas* RenderTest::GetCanvas() {
|
||||
return canvas_ == nullptr ? nullptr : canvas_.get();
|
||||
}
|
||||
|
||||
std::string RenderTest::GetNextSnapshotName() {
|
||||
const auto& test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
std::stringstream stream;
|
||||
stream << test_info->test_case_name() << "_" << test_info->name();
|
||||
stream << "_" << ++snapshots_ << ".png";
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
bool RenderTest::Snapshot() {
|
||||
if (!canvas_ || !bitmap_) {
|
||||
return false;
|
||||
}
|
||||
auto file_name = GetNextSnapshotName();
|
||||
SkFILEWStream file(file_name.c_str());
|
||||
return SkEncodeImage(&file, *bitmap_, SkEncodedImageFormat::kPNG, 100);
|
||||
}
|
||||
|
||||
size_t RenderTest::GetTestCanvasWidth() const {
|
||||
return 800;
|
||||
}
|
||||
|
||||
size_t RenderTest::GetTestCanvasHeight() const {
|
||||
return 600;
|
||||
}
|
||||
|
||||
void RenderTest::SetUp() {
|
||||
bitmap_ = std::make_unique<SkBitmap>();
|
||||
bitmap_->allocN32Pixels(GetTestCanvasWidth(), GetTestCanvasHeight());
|
||||
canvas_ = std::make_unique<SkCanvas>(*bitmap_);
|
||||
canvas_->clear(SK_ColorTRANSPARENT);
|
||||
}
|
||||
|
||||
void RenderTest::TearDown() {
|
||||
canvas_ = nullptr;
|
||||
bitmap_ = nullptr;
|
||||
}
|
||||
52
engine/src/flutter/tests/txt/render_test.h
Normal file
52
engine/src/flutter/tests/txt/render_test.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
class RenderTest : public ::testing::Test {
|
||||
public:
|
||||
RenderTest();
|
||||
|
||||
~RenderTest();
|
||||
|
||||
SkCanvas* GetCanvas();
|
||||
|
||||
bool Snapshot();
|
||||
|
||||
size_t GetTestCanvasWidth() const;
|
||||
|
||||
size_t GetTestCanvasHeight() const;
|
||||
|
||||
protected:
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
|
||||
private:
|
||||
size_t snapshots_;
|
||||
std::unique_ptr<SkBitmap> bitmap_;
|
||||
std::unique_ptr<SkCanvas> canvas_;
|
||||
|
||||
std::string GetNextSnapshotName();
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(RenderTest);
|
||||
};
|
||||
26
engine/src/flutter/tests/txt/txt_run_all_unittests.cc
Normal file
26
engine/src/flutter/tests/txt/txt_run_all_unittests.cc
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2017 Google, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "flutter/fml/icu_util.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkGraphics.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
fml::icu::InitializeICU();
|
||||
SkGraphics::Init();
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -3,38 +3,39 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
executable("unittest") {
|
||||
output_name = "txt_unittests"
|
||||
output_name = "minikin_unittests"
|
||||
|
||||
testonly = true
|
||||
|
||||
sources = [
|
||||
# "WordBreakerTests.cpp",
|
||||
"//lib/ftl/test/run_all_unittests.cc",
|
||||
"CmapCoverageTest.cpp",
|
||||
"EmojiTest.cpp",
|
||||
|
||||
# TODO(abarth): Re-enable once we have wired up SkFontMgr.
|
||||
# "FontCollectionItemizeTest.cpp",
|
||||
# "FontCollectionTest.cpp",
|
||||
# "FontFamilyTest.cpp",
|
||||
# "FontLanguageListCacheTest.cpp",
|
||||
"GraphemeBreakTests.cpp",
|
||||
|
||||
# "HbFontCacheTest.cpp",
|
||||
# "HyphenatorTest.cpp",
|
||||
"ICUTestBase.h",
|
||||
|
||||
# "LayoutTest.cpp",
|
||||
"LayoutUtilsTest.cpp",
|
||||
"MeasurementTests.cpp",
|
||||
"SparseBitSetTest.cpp",
|
||||
"UnicodeUtilsTest.cpp",
|
||||
# "WordBreakerTests.cpp",
|
||||
"//lib/ftl/test/run_all_unittests.cc",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"kTestFontDir=\"/data/nativetest/minikin_tests/data/\"",
|
||||
]
|
||||
defines = [ "kTestFontDir=\"/data/nativetest/minikin_tests/data/\"" ]
|
||||
|
||||
deps = [
|
||||
"//lib/txt/tests/util",
|
||||
"//lib/txt/libs/minikin",
|
||||
"//lib/txt/tests/util",
|
||||
"//third_party/gtest",
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user