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

Side by Side Diff: tools/using_skia_and_harfbuzz.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. Created 4 years, 7 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/sk_tool_utils_font.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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 struct Face { 135 struct Face {
136 struct HBFDel { void operator()(hb_face_t* f) { hb_face_destroy(f); } }; 136 struct HBFDel { void operator()(hb_face_t* f) { hb_face_destroy(f); } };
137 std::unique_ptr<hb_face_t, HBFDel> fHarfBuzzFace; 137 std::unique_ptr<hb_face_t, HBFDel> fHarfBuzzFace;
138 sk_sp<SkTypeface> fSkiaTypeface; 138 sk_sp<SkTypeface> fSkiaTypeface;
139 139
140 Face(const char* path, int index) { 140 Face(const char* path, int index) {
141 // fairly portable mmap impl 141 // fairly portable mmap impl
142 auto data = SkData::MakeFromFileName(path); 142 auto data = SkData::MakeFromFileName(path);
143 assert(data); 143 assert(data);
144 if (!data) { return; } 144 if (!data) { return; }
145 fSkiaTypeface.reset( 145 fSkiaTypeface = SkTypeface::MakeFromStream(new SkMemoryStream(data), index);
146 SkTypeface::CreateFromStream(
147 new SkMemoryStream(data), index));
148 assert(fSkiaTypeface); 146 assert(fSkiaTypeface);
149 if (!fSkiaTypeface) { return; } 147 if (!fSkiaTypeface) { return; }
150 auto destroy = [](void *d) { static_cast<SkData*>(d)->unref(); }; 148 auto destroy = [](void *d) { static_cast<SkData*>(d)->unref(); };
151 const char* bytes = (const char*)data->data(); 149 const char* bytes = (const char*)data->data();
152 unsigned int size = (unsigned int)data->size(); 150 unsigned int size = (unsigned int)data->size();
153 hb_blob_t* blob = hb_blob_create(bytes, 151 hb_blob_t* blob = hb_blob_create(bytes,
154 size, 152 size,
155 HB_MEMORY_MODE_READONLY, 153 HB_MEMORY_MODE_READONLY,
156 data.release(), 154 data.release(),
157 destroy); 155 destroy);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 Config config(argc, argv); 295 Config config(argc, argv);
298 296
299 Placement placement(config, new SkFILEWStream(config.output_file_name->value .c_str())); 297 Placement placement(config, new SkFILEWStream(config.output_file_name->value .c_str()));
300 for (std::string line; std::getline(std::cin, line);) { 298 for (std::string line; std::getline(std::cin, line);) {
301 placement.WriteLine(line.c_str()); 299 placement.WriteLine(line.c_str());
302 } 300 }
303 placement.Close(); 301 placement.Close();
304 302
305 return 0; 303 return 0;
306 } 304 }
OLDNEW
« no previous file with comments | « tools/sk_tool_utils_font.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698