OLD | NEW |
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 Loading... |
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 Loading... |
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 } |
OLD | NEW |