1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #if 0 // should we revitalize this by consing up a device for drawTextBlob() ? 9 #include "src/text/GlyphRun.h" 10 11 #include "include/core/SkTextBlob.h" 12 #include "tests/Test.h" 13 14 #include <algorithm> 15 #include <memory> 16 17 DEF_TEST(GlyphRunBlob, reporter) { 18 constexpr uint16_t count = 5; 19 constexpr int runCount = 2; 20 21 auto tf = SkTypeface::MakeFromName("monospace", SkFontStyle()); 22 23 SkFont font; 24 font.setTypeface(tf); 25 font.setHinting(SkFontHinting::kNormal); 26 font.setSize(1u); 27 28 SkTextBlobBuilder blobBuilder; 29 for (int runNum = 0; runNum < runCount; runNum++) { 30 const auto& runBuffer = blobBuilder.allocRunPosH(font, count, runNum); 31 SkASSERT(runBuffer.utf8text == nullptr); 32 SkASSERT(runBuffer.clusters == nullptr); 33 34 for (int i = 0; i < count; i++) { 35 runBuffer.glyphs[i] = static_cast<SkGlyphID>(i + runNum * count); 36 runBuffer.pos[i] = SkIntToScalar(i + runNum * count); 37 } 38 } 39 40 auto blob = blobBuilder.make(); 41 42 sktext::GlyphRunBuilder runBuilder; 43 SkPaint legacy_paint; 44 font.LEGACY_applyToPaint(&legacy_paint); 45 runBuilder.drawTextBlob(legacy_paint, *blob, SkPoint::Make(0, 0)); 46 47 auto runList = runBuilder.useGlyphRunList(); 48 49 REPORTER_ASSERT(reporter, runList.size() == runCount); 50 int runIndex = 0; 51 for (auto& run : runList) { 52 REPORTER_ASSERT(reporter, run.runSize() == count); 53 54 int index = 0; 55 for (auto p : run.positions()) { 56 if (p.x() != runIndex * count + index) { 57 ERRORF(reporter, "x: %g != k: %d", p.x(), runIndex * count + index); 58 break; 59 } 60 index += 1; 61 } 62 63 runIndex += 1; 64 } 65 } 66 #endif 67