Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: tools/using_skia_and_harfbuzz.cpp

Issue 2201153002: SkShaper: optionally disable harfbuzz (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-02 (Tuesday) 18:27:47 EDT Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/SkShaper_primitive.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 // This sample progam demonstrates how to use Skia and HarfBuzz to 8 // This sample progam demonstrates how to use Skia and HarfBuzz to
9 // produce a PDF file from UTF-8 text in stdin. 9 // produce a PDF file from UTF-8 text in stdin.
10 10
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // Placement /////////////////////////////////////////////////////////////////// 127 // Placement ///////////////////////////////////////////////////////////////////
128 128
129 class Placement { 129 class Placement {
130 public: 130 public:
131 Placement(const Config* conf, SkDocument *doc) 131 Placement(const Config* conf, SkDocument *doc)
132 : config(conf), document(doc), pageCanvas(nullptr) { 132 : config(conf), document(doc), pageCanvas(nullptr) {
133 white_paint.setColor(SK_ColorWHITE); 133 white_paint.setColor(SK_ColorWHITE);
134 glyph_paint.setColor(SK_ColorBLACK); 134 glyph_paint.setColor(SK_ColorBLACK);
135 glyph_paint.setFlags(SkPaint::kAntiAlias_Flag | 135 glyph_paint.setFlags(SkPaint::kAntiAlias_Flag |
136 SkPaint::kSubpixelText_Flag); 136 SkPaint::kSubpixelText_Flag);
137 glyph_paint.setTextSize(config->font_size.value); 137 glyph_paint.setTextSize(SkDoubleToScalar(config->font_size.value));
138 } 138 }
139 139
140 void WriteLine(const SkShaper& shaper, const char *text, size_t textBytes) { 140 void WriteLine(const SkShaper& shaper, const char *text, size_t textBytes) {
141 if (!pageCanvas || current_y > config->page_height.value) { 141 if (!pageCanvas || current_y > config->page_height.value) {
142 if (pageCanvas) { 142 if (pageCanvas) {
143 document->endPage(); 143 document->endPage();
144 } 144 }
145 pageCanvas = document->beginPage(config->page_width.value, 145 pageCanvas = document->beginPage(
146 config->page_height.value); 146 SkDoubleToScalar(config->page_width.value),
147 SkDoubleToScalar(config->page_height.value));
147 pageCanvas->drawPaint(white_paint); 148 pageCanvas->drawPaint(white_paint);
148 current_x = config->left_margin.value; 149 current_x = config->left_margin.value;
149 current_y = config->line_spacing_ratio.value * config->font_size.val ue; 150 current_y = config->line_spacing_ratio.value * config->font_size.val ue;
150 } 151 }
151 SkTextBlobBuilder textBlobBuilder; 152 SkTextBlobBuilder textBlobBuilder;
152 shaper.shape(&textBlobBuilder, glyph_paint, text, textBytes, SkPoint{0, 0}); 153 shaper.shape(&textBlobBuilder, glyph_paint, text, textBytes, SkPoint{0, 0});
153 sk_sp<const SkTextBlob> blob(textBlobBuilder.build()); 154 sk_sp<const SkTextBlob> blob(textBlobBuilder.build());
154 pageCanvas->drawTextBlob(blob.get(), current_x, current_y, glyph_paint); 155 pageCanvas->drawTextBlob(
155 156 blob.get(), SkDoubleToScalar(current_x),
157 SkDoubleToScalar(current_y), glyph_paint);
156 // Advance to the next line. 158 // Advance to the next line.
157 current_y += config->line_spacing_ratio.value * config->font_size.value; 159 current_y += config->line_spacing_ratio.value * config->font_size.value;
158 } 160 }
159 161
160 private: 162 private:
161 const Config* config; 163 const Config* config;
162 SkDocument *document; 164 SkDocument *document;
163 SkCanvas *pageCanvas; 165 SkCanvas *pageCanvas;
164 SkPaint white_paint; 166 SkPaint white_paint;
165 SkPaint glyph_paint; 167 SkPaint glyph_paint;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 207 }
206 SkShaper shaper(typeface); 208 SkShaper shaper(typeface);
207 assert(shaper.good()); 209 assert(shaper.good());
208 for (std::string line; std::getline(std::cin, line);) { 210 for (std::string line; std::getline(std::cin, line);) {
209 placement.WriteLine(shaper, line.c_str(), line.size()); 211 placement.WriteLine(shaper, line.c_str(), line.size());
210 } 212 }
211 213
212 doc->close(); 214 doc->close();
213 return 0; 215 return 0;
214 } 216 }
OLDNEW
« no previous file with comments | « tools/SkShaper_primitive.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698