aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-01-29 15:45:30 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-29 21:47:14 +0000
commit36a944f1f878591c0e93197b7842951ff02284a5 (patch)
tree7e46cb2bcb66464adf1972de8d74d8ed78540486 /tools
parentb4d01a95c9cbb7adf7adaba193c813313d9d7261 (diff)
Don't add lines that don't fit on the page.
Check to see if the paragraph will fit on the page and start a new page if it doesn't. Change-Id: I053e4199d992628321fc317003c7b44b58fa61f8 Reviewed-on: https://skia-review.googlesource.com/101481 Reviewed-by: Hal Canary <halcanary@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/shape/using_skia_and_harfbuzz.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/tools/shape/using_skia_and_harfbuzz.cpp b/tools/shape/using_skia_and_harfbuzz.cpp
index 01d9a3ed86..5a74866794 100644
--- a/tools/shape/using_skia_and_harfbuzz.cpp
+++ b/tools/shape/using_skia_and_harfbuzz.cpp
@@ -138,7 +138,16 @@ public:
}
void WriteLine(const SkShaper& shaper, const char *text, size_t textBytes) {
- if (!pageCanvas || current_y > config->page_height.value) {
+ SkTextBlobBuilder textBlobBuilder;
+ SkPoint endPoint = shaper.shape(&textBlobBuilder, glyph_paint, text, textBytes, true,
+ SkPoint{0, 0},
+ config->page_width.value - 2*config->left_margin.value);
+ sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
+ // If we don't have a page, or if we're not at the start of the page and the blob won't fit
+ if (!pageCanvas ||
+ (current_y > config->line_spacing_ratio.value * config->font_size.value &&
+ current_y + endPoint.y() > config->page_height.value)
+ ) {
if (pageCanvas) {
document->endPage();
}
@@ -149,11 +158,6 @@ public:
current_x = config->left_margin.value;
current_y = config->line_spacing_ratio.value * config->font_size.value;
}
- SkTextBlobBuilder textBlobBuilder;
- SkPoint endPoint = shaper.shape(&textBlobBuilder, glyph_paint, text, textBytes, true,
- SkPoint{0, 0},
- config->page_width.value - 2*config->left_margin.value);
- sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
pageCanvas->drawTextBlob(
blob.get(), SkDoubleToScalar(current_x),
SkDoubleToScalar(current_y), glyph_paint);