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