Coverage Report

Created: 2026-08-11 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/woff2/include/woff2/output.h
Line
Count
Source
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 <stdint.h>
13
14
#include <algorithm>
15
#include <cstring>
16
#include <memory>
17
#include <string>
18
19
namespace woff2 {
20
21
// Suggested max size for output.
22
const size_t kDefaultMaxSize = 128 * 1024 * 1024;
23
24
/**
25
 * Output interface for the woff2 decoding.
26
 *
27
 * Writes to arbitrary offsets are supported to facilitate updating offset
28
 * table and checksums after tables are ready. Reading the current size is
29
 * supported so a 'loca' table can be built up while writing glyphs.
30
 *
31
 * By default limits size to kDefaultMaxSize.
32
 */
33
class WOFF2Out {
34
 public:
35
16.3k
  virtual ~WOFF2Out(void) {}
36
37
  // Append n bytes of data from buf.
38
  // Return true if all written, false otherwise.
39
  virtual bool Write(const void *buf, size_t n) = 0;
40
41
  // Write n bytes of data from buf at offset.
42
  // Return true if all written, false otherwise.
43
  virtual bool Write(const void *buf, size_t offset, size_t n) = 0;
44
45
  virtual size_t Size() = 0;
46
};
47
48
/**
49
 * Expanding memory block for woff2 out. By default limited to kDefaultMaxSize.
50
 */
51
class WOFF2StringOut : public WOFF2Out {
52
 public:
53
  // Create a writer that writes its data to buf.
54
  // buf->size() will grow to at most max_size
55
  // buf may be sized (e.g. using EstimateWOFF2FinalSize) or empty.
56
  explicit WOFF2StringOut(std::string *buf);
57
58
  bool Write(const void *buf, size_t n) override;
59
  bool Write(const void *buf, size_t offset, size_t n) override;
60
1.07M
  size_t Size() override { return offset_; }
61
0
  size_t MaxSize() { return max_size_; }
62
  void SetMaxSize(size_t max_size);
63
 private:
64
  std::string *buf_;
65
  size_t max_size_;
66
  size_t offset_;
67
};
68
69
/**
70
 * Fixed memory block for woff2 out.
71
 */
72
class WOFF2MemoryOut : public WOFF2Out {
73
 public:
74
  // Create a writer that writes its data to buf.
75
  WOFF2MemoryOut(uint8_t* buf, size_t buf_size);
76
77
  bool Write(const void *buf, size_t n) override;
78
  bool Write(const void *buf, size_t offset, size_t n) override;
79
0
  size_t Size() override { return offset_; }
80
 private:
81
  uint8_t* buf_;
82
  size_t buf_size_;
83
  size_t offset_;
84
};
85
86
} // namespace woff2
87
88
#endif  // WOFF2_WOFF2_OUT_H_