Coverage Report

Created: 2025-07-18 06:54

/src/ots/subprojects/woff2-1.0.2/include/woff2/output.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2016 Google Inc. All Rights Reserved.
2
3
   Distributed under MIT license.
4
   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
*/
6
7
/* Output buffer for WOFF2 decompression. */
8
9
#ifndef WOFF2_WOFF2_OUT_H_
10
#define WOFF2_WOFF2_OUT_H_
11
12
#include <algorithm>
13
#include <cstring>
14
#include <memory>
15
#include <string>
16
17
namespace woff2 {
18
19
// Suggested max size for output.
20
const size_t kDefaultMaxSize = 30 * 1024 * 1024;
21
22
/**
23
 * Output interface for the woff2 decoding.
24
 *
25
 * Writes to arbitrary offsets are supported to facilitate updating offset
26
 * table and checksums after tables are ready. Reading the current size is
27
 * supported so a 'loca' table can be built up while writing glyphs.
28
 *
29
 * By default limits size to kDefaultMaxSize.
30
 */
31
class WOFF2Out {
32
 public:
33
2.51k
  virtual ~WOFF2Out(void) {}
34
35
  // Append n bytes of data from buf.
36
  // Return true if all written, false otherwise.
37
  virtual bool Write(const void *buf, size_t n) = 0;
38
39
  // Write n bytes of data from buf at offset.
40
  // Return true if all written, false otherwise.
41
  virtual bool Write(const void *buf, size_t offset, size_t n) = 0;
42
43
  virtual size_t Size() = 0;
44
};
45
46
/**
47
 * Expanding memory block for woff2 out. By default limited to kDefaultMaxSize.
48
 */
49
class WOFF2StringOut : public WOFF2Out {
50
 public:
51
  // Create a writer that writes its data to buf.
52
  // buf->size() will grow to at most max_size
53
  // buf may be sized (e.g. using EstimateWOFF2FinalSize) or empty.
54
  explicit WOFF2StringOut(std::string* buf);
55
56
  bool Write(const void *buf, size_t n) override;
57
  bool Write(const void *buf, size_t offset, size_t n) override;
58
102k
  size_t Size() override { return offset_; }
59
0
  size_t MaxSize() { return max_size_; }
60
  void SetMaxSize(size_t max_size);
61
 private:
62
  std::string* buf_;
63
  size_t max_size_;
64
  size_t offset_;
65
};
66
67
/**
68
 * Fixed memory block for woff2 out.
69
 */
70
class WOFF2MemoryOut : public WOFF2Out {
71
 public:
72
  // Create a writer that writes its data to buf.
73
  WOFF2MemoryOut(uint8_t* buf, size_t buf_size);
74
75
  bool Write(const void *buf, size_t n) override;
76
  bool Write(const void *buf, size_t offset, size_t n) override;
77
0
  size_t Size() override { return offset_; }
78
 private:
79
  uint8_t* buf_;
80
  size_t buf_size_;
81
  size_t offset_;
82
};
83
84
} // namespace woff2
85
86
#endif  // WOFF2_WOFF2_OUT_H_