| 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 #include <hb-ot.h> | 8 #include <hb-ot.h> |
| 9 | 9 |
| 10 #include "SkShaper.h" | 10 #include "SkShaper.h" |
| 11 #include "SkStream.h" | 11 #include "SkStream.h" |
| 12 #include "SkTextBlob.h" | 12 #include "SkTextBlob.h" |
| 13 #include "SkTypeface.h" | 13 #include "SkTypeface.h" |
| 14 | 14 |
| 15 static const int FONT_SIZE_SCALE = 512; | 15 static const int FONT_SIZE_SCALE = 512; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 struct HBFBlobDel { | 18 struct HBFBlobDel { |
| 19 void operator()(hb_blob_t* b) { hb_blob_destroy(b); } | 19 void operator()(hb_blob_t* b) { hb_blob_destroy(b); } |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 std::unique_ptr<hb_blob_t, HBFBlobDel> stream_to_blob(std::unique_ptr<SkStreamAs
set> asset) { | 22 std::unique_ptr<hb_blob_t, HBFBlobDel> stream_to_blob(std::unique_ptr<SkStreamAs
set> asset) { |
| 23 size_t size = asset->getLength(); | 23 size_t size = asset->getLength(); |
| 24 std::unique_ptr<hb_blob_t, HBFBlobDel> blob; | 24 std::unique_ptr<hb_blob_t, HBFBlobDel> blob; |
| 25 if (const void* base = asset->getMemoryBase()) { | 25 if (const void* base = asset->getMemoryBase()) { |
| 26 blob.reset(hb_blob_create((char*)base, size, | 26 blob.reset(hb_blob_create((char*)base, SkToUInt(size), |
| 27 HB_MEMORY_MODE_READONLY, asset.release(), | 27 HB_MEMORY_MODE_READONLY, asset.release(), |
| 28 [](void* p) { delete (SkStreamAsset*)p; })); | 28 [](void* p) { delete (SkStreamAsset*)p; })); |
| 29 } else { | 29 } else { |
| 30 // SkDebugf("Extra SkStreamAsset copy\n"); | 30 // SkDebugf("Extra SkStreamAsset copy\n"); |
| 31 SkAutoMalloc autoMalloc(size); | 31 SkAutoMalloc autoMalloc(size); |
| 32 asset->read(autoMalloc.get(), size); | 32 asset->read(autoMalloc.get(), size); |
| 33 void* ptr = autoMalloc.get(); | 33 void* ptr = autoMalloc.get(); |
| 34 blob.reset(hb_blob_create((char*)autoMalloc.release(), size, | 34 blob.reset(hb_blob_create((char*)autoMalloc.release(), SkToUInt(size), |
| 35 HB_MEMORY_MODE_READONLY, ptr, sk_free)); | 35 HB_MEMORY_MODE_READONLY, ptr, sk_free)); |
| 36 } | 36 } |
| 37 SkASSERT(blob); | 37 SkASSERT(blob); |
| 38 hb_blob_make_immutable(blob.get()); | 38 hb_blob_make_immutable(blob.get()); |
| 39 return blob; | 39 return blob; |
| 40 } | 40 } |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 struct SkShaper::Impl { | 43 struct SkShaper::Impl { |
| 44 struct HBFontDel { | 44 struct HBFontDel { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 double x = point.x(); | 110 double x = point.x(); |
| 111 double y = point.y(); | 111 double y = point.y(); |
| 112 | 112 |
| 113 double textSizeY = paint.getTextSize() / (double)FONT_SIZE_SCALE; | 113 double textSizeY = paint.getTextSize() / (double)FONT_SIZE_SCALE; |
| 114 double textSizeX = textSizeY * paint.getTextScaleX(); | 114 double textSizeX = textSizeY * paint.getTextScaleX(); |
| 115 | 115 |
| 116 for (unsigned i = 0; i < len; i++) { | 116 for (unsigned i = 0; i < len; i++) { |
| 117 runBuffer.glyphs[i] = info[i].codepoint; | 117 runBuffer.glyphs[i] = info[i].codepoint; |
| 118 reinterpret_cast<SkPoint*>(runBuffer.pos)[i] = | 118 reinterpret_cast<SkPoint*>(runBuffer.pos)[i] = |
| 119 SkPoint::Make(x + pos[i].x_offset * textSizeX, | 119 SkPoint::Make(SkDoubleToScalar(x + pos[i].x_offset * textSizeX), |
| 120 y - pos[i].y_offset * textSizeY); | 120 SkDoubleToScalar(y - pos[i].y_offset * textSizeY))
; |
| 121 x += pos[i].x_advance * textSizeX; | 121 x += pos[i].x_advance * textSizeX; |
| 122 y += pos[i].y_advance * textSizeY; | 122 y += pos[i].y_advance * textSizeY; |
| 123 } | 123 } |
| 124 hb_buffer_clear_contents(buffer); | 124 hb_buffer_clear_contents(buffer); |
| 125 return (SkScalar)x; | 125 return (SkScalar)x; |
| 126 } | 126 } |
| OLD | NEW |