| 1 |
/* |
| 2 |
* Copyright 2019 Google Inc. |
| 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 |
#ifndef SkShaperJSONWriter_DEFINED |
| 9 |
#define SkShaperJSONWriter_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkPoint.h" |
| 12 |
#include "include/core/SkSpan.h" |
| 13 |
#include "include/core/SkTypes.h" |
| 14 |
#include "modules/skshaper/include/SkShaper.h" |
| 15 |
|
| 16 |
#include <cstdint> |
| 17 |
#include <functional> |
| 18 |
#include <string> |
| 19 |
#include <vector> |
| 20 |
|
| 21 |
class SkJSONWriter; |
| 22 |
|
| 23 |
class SkShaperJSONWriter final : public SkShaper::RunHandler { |
| 24 |
public: |
| 25 |
SkShaperJSONWriter(SkJSONWriter* JSONWriter, const char* utf8, size_t size); |
| 26 |
|
| 27 |
void beginLine() override; |
| 28 |
void runInfo(const RunInfo& info) override; |
| 29 |
void commitRunInfo() override; |
| 30 |
|
| 31 |
Buffer runBuffer(const RunInfo& info) override; |
| 32 |
|
| 33 |
void commitRunBuffer(const RunInfo& info) override; |
| 34 |
|
| 35 |
void commitLine() override {} |
| 36 |
|
| 37 |
using BreakupClustersCallback = |
| 38 |
std::function<void(size_t, size_t, uint32_t, uint32_t)>; |
| 39 |
|
| 40 |
// Break up cluster into a set of ranges for the UTF8, and the glyphIDs. |
| 41 |
static void BreakupClusters(size_t utf8Begin, size_t utf8End, |
| 42 |
SkSpan<const uint32_t> clusters, |
| 43 |
const BreakupClustersCallback& processMToN); |
| 44 |
|
| 45 |
|
| 46 |
using VisualizeClustersCallback = |
| 47 |
std::function<void(size_t, SkSpan<const char>, SkSpan<const SkGlyphID>)>; |
| 48 |
|
| 49 |
// Gather runs of 1:1 into larger runs, and display M:N as single entries. |
| 50 |
static void VisualizeClusters(const char utf8[], |
| 51 |
size_t utf8Begin, size_t utf8End, |
| 52 |
SkSpan<const SkGlyphID> glyphIDs, |
| 53 |
SkSpan<const uint32_t> clusters, |
| 54 |
const VisualizeClustersCallback& processMToN); |
| 55 |
|
| 56 |
private: |
| 57 |
void displayMToN(size_t codePointCount, |
| 58 |
SkSpan<const char> utf8, |
| 59 |
SkSpan<const SkGlyphID> glyphIDs); |
| 60 |
|
| 61 |
SkJSONWriter* fJSONWriter; |
| 62 |
std::vector<SkGlyphID> fGlyphs; |
| 63 |
std::vector<SkPoint> fPositions; |
| 64 |
std::vector<uint32_t> fClusters; |
| 65 |
|
| 66 |
std::string fUTF8; |
| 67 |
}; |
| 68 |
|
| 69 |
#endif // SkShaperJSONWriter_DEFINED |