Restructure Building and new features for Flutter support.

Change-Id: Ia0454fabcd89806cfb0e07148696e9ae66c351b6
This commit is contained in:
Gary Qian
2017-06-08 18:27:29 -07:00
parent cf223546c4
commit ef3b6d0b6e
8 changed files with 85 additions and 47 deletions

View File

@@ -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",
]
}

View File

@@ -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",
]

View File

@@ -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",
]
}

View File

@@ -22,7 +22,7 @@
#include <vector>
#include <minikin/Layout.h>
#include <minikin/LineBreaker.h>
#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

View File

@@ -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<PaintRecord> 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<uint16_t> text, StyledRuns runs);
void SetParagraphStyle(const ParagraphStyle& style);
void AddRunsToLineBreaker(const std::string& rootdir = "");
FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph);

View File

@@ -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<Paragraph> ParagraphBuilder::Build() {
runs_.EndRunIfNeeded(text_.size());
std::unique_ptr<Paragraph> paragraph = std::make_unique<Paragraph>();
paragraph->SetText(std::move(text_), std::move(runs_));
paragraph->SetParagraphStyle(paragraph_style_);
return paragraph;
}

View File

@@ -50,6 +50,7 @@ class ParagraphBuilder {
std::vector<uint16_t> text_;
std::vector<size_t> style_stack_;
StyledRuns runs_;
ParagraphStyle paragraph_style_;
FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder);
};

View File

@@ -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",