diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 34c9c145fa..8cb56f42a9 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -12,13 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. -group("txt") { - testonly = true - - deps = [ - "examples:txt_example($host_toolchain)", - "src", - "tests/txt($host_toolchain)", # txt_unittests - "tests/unittest($host_toolchain)", # minikin_unittest +config("txt_config") { + include_dirs = [ + "//lib/txt/include", + "//third_party/harfbuzz/src", + "//lib/txt/shims", ] } + +static_library("txt") { + sources = [ + "src/font_collection.cc", + "src/font_collection.h", + "src/font_skia.cc", + "src/font_skia.h", + "src/font_style.h", + "src/font_weight.h", + "src/paint_record.cc", + "src/paint_record.h", + "src/paragraph.cc", + "src/paragraph.h", + "src/paragraph_builder.cc", + "src/paragraph_builder.h", + "src/paragraph_constraints.cc", + "src/paragraph_constraints.h", + "src/paragraph_style.cc", + "src/paragraph_style.h", + "src/styled_runs.cc", + "src/styled_runs.h", + "src/text_align.h", + "src/text_baseline.h", + "src/text_decoration.cc", + "src/text_decoration.h", + "src/text_style.cc", + "src/text_style.h", + ] + + public_configs = [ ":txt_config" ] + + deps = [ + "//lib/txt/libs/minikin", + "//third_party/skia", + "//third_party/gtest", + ] + +} diff --git a/engine/src/flutter/examples/BUILD.gn b/engine/src/flutter/examples/BUILD.gn index 20780a3d65..b0452feb4c 100644 --- a/engine/src/flutter/examples/BUILD.gn +++ b/engine/src/flutter/examples/BUILD.gn @@ -21,7 +21,7 @@ executable("txt_example") { "//dart/runtime:libdart_jit", "//flutter/fml", "//lib/txt/libs/minikin", - "//lib/txt/src", + "//lib/txt", "//third_party/icu:icuuc", "//third_party/skia", ] diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index 3ff3e9c6b0..024820767e 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -13,36 +13,5 @@ # limitations under the License. source_set("src") { - sources = [ - "font_collection.cc", - "font_collection.h", - "font_skia.cc", - "font_skia.h", - "font_style.h", - "font_weight.h", - "paint_record.cc", - "paint_record.h", - "paragraph.cc", - "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_baseline.h", - "text_decoration.cc", - "text_decoration.h", - "text_style.cc", - "text_style.h", - ] - - deps = [ - "//lib/txt/libs/minikin", - "//third_party/skia", - "//third_party/gtest", - ] + } diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 517be88eb6..0912565557 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -22,7 +22,7 @@ #include #include -#include +#include "minikin/LineBreaker.h" #include "lib/ftl/logging.h" @@ -145,7 +145,6 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, minikin::Layout layout; SkScalar x = 0.0f; - SkScalar y = 0.0f; size_t break_index = 0; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); @@ -188,13 +187,14 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. records_.push_back( - PaintRecord(run.style.color, SkPoint::Make(x, y), builder.make())); + PaintRecord(run.style.color, SkPoint::Make(x, y_), builder.make())); if (layout_end == next_break) { x = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. - y += run.style.font_size * run.style.height; + y_ += run.style.font_size * run.style.height; + lines_++; break_index += 1; } else { x += layout.getAdvance(); @@ -205,6 +205,18 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, } } +const ParagraphStyle& Paragraph::GetParagraphStyle() const { + return paragraph_style_; +} + +double Paragraph::GetHeight() const { + return y_; +} + +void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { + paragraph_style_ = style; +} + void Paragraph::Paint(SkCanvas* canvas, double x, double y) { SkPaint paint; for (const auto& record : records_) { @@ -214,4 +226,10 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { } } +bool Paragraph::DidExceedMaxLines() const { + if (lines_ > paragraph_style_.max_lines) + return true; + return false; +} + } // namespace txt diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 0ec43df129..c515e9839d 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -22,6 +22,7 @@ #include "lib/ftl/macros.h" #include "lib/txt/src/paint_record.h" #include "lib/txt/src/paragraph_constraints.h" +#include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" #include "minikin/LineBreaker.h" #include "third_party/gtest/include/gtest/gtest_prod.h" @@ -42,6 +43,12 @@ class Paragraph { void Paint(SkCanvas* canvas, double x, double y); + const ParagraphStyle& GetParagraphStyle() const; + + double GetHeight() const; + + bool DidExceedMaxLines() const; + private: friend class ParagraphBuilder; FRIEND_TEST(RenderTest, SimpleParagraph); @@ -56,9 +63,14 @@ class Paragraph { StyledRuns runs_; minikin::LineBreaker breaker_; std::vector records_; + ParagraphStyle paragraph_style_; + int lines_ = 1; // Number of lines after Layout(). + SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). void SetText(std::vector text, StyledRuns runs); + void SetParagraphStyle(const ParagraphStyle& style); + void AddRunsToLineBreaker(const std::string& rootdir = ""); FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 4976b86126..116936e184 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -15,11 +15,13 @@ */ #include "lib/txt/src/paragraph_builder.h" +#include "lib/txt/src/paragraph_style.h" #include "third_party/icu/source/common/unicode/unistr.h" namespace txt { -ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) {} +ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) + : paragraph_style_(style) {} ParagraphBuilder::~ParagraphBuilder() = default; @@ -65,6 +67,7 @@ std::unique_ptr ParagraphBuilder::Build() { runs_.EndRunIfNeeded(text_.size()); std::unique_ptr paragraph = std::make_unique(); paragraph->SetText(std::move(text_), std::move(runs_)); + paragraph->SetParagraphStyle(paragraph_style_); return paragraph; } diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 71598af0b5..41bd6a02a2 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -50,6 +50,7 @@ class ParagraphBuilder { std::vector text_; std::vector style_stack_; StyledRuns runs_; + ParagraphStyle paragraph_style_; FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder); }; diff --git a/engine/src/flutter/tests/txt/BUILD.gn b/engine/src/flutter/tests/txt/BUILD.gn index 3fb1019628..dad5c408f3 100644 --- a/engine/src/flutter/tests/txt/BUILD.gn +++ b/engine/src/flutter/tests/txt/BUILD.gn @@ -35,7 +35,7 @@ executable("txt") { "//dart/runtime:libdart_jit", # Logging "//flutter/fml", "//lib/txt/shims", - "//lib/txt/src", + "//lib/txt", "//third_party/gtest", "//third_party/harfbuzz", "//third_party/skia",