OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 Google Inc. All Rights Reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 // |
| 15 // Output buffer for WOFF2 decompression. |
| 16 |
| 17 // Copyright 2016 Google Inc. All Rights Reserved. |
| 18 // |
| 19 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 20 // you may not use this file except in compliance with the License. |
| 21 // You may obtain a copy of the License at |
| 22 // |
| 23 // http://www.apache.org/licenses/LICENSE-2.0 |
| 24 // |
| 25 // Unless required by applicable law or agreed to in writing, software |
| 26 // distributed under the License is distributed on an "AS IS" BASIS, |
| 27 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 28 // See the License for the specific language governing permissions and |
| 29 // limitations under the License. |
| 30 // |
| 31 // Output buffer for WOFF2 decompression. |
| 32 |
| 33 #ifndef WOFF2_WOFF2_OUT_H_ |
| 34 #define WOFF2_WOFF2_OUT_H_ |
| 35 |
| 36 #include <algorithm> |
| 37 #include <cstring> |
| 38 #include <memory> |
| 39 #include <string> |
| 40 #include "./port.h" |
| 41 |
| 42 namespace woff2 { |
| 43 |
| 44 // Suggested max size for output. |
| 45 const size_t kDefaultMaxSize = 30 * 1024 * 1024; |
| 46 |
| 47 using std::string; |
| 48 |
| 49 |
| 50 /** |
| 51 * Output interface for the woff2 decoding. |
| 52 * |
| 53 * Writes to arbitrary offsets are supported to facilitate updating offset |
| 54 * table and checksums after tables are ready. Reading the current size is |
| 55 * supported so a 'loca' table can be built up while writing glyphs. |
| 56 * |
| 57 * By default limits size to kDefaultMaxSize. |
| 58 */ |
| 59 class WOFF2Out { |
| 60 public: |
| 61 virtual ~WOFF2Out(void) {} |
| 62 |
| 63 // Append n bytes of data from buf. |
| 64 // Return true if all written, false otherwise. |
| 65 virtual bool Write(const void *buf, size_t n) = 0; |
| 66 |
| 67 // Write n bytes of data from buf at offset. |
| 68 // Return true if all written, false otherwise. |
| 69 virtual bool Write(const void *buf, size_t offset, size_t n) = 0; |
| 70 |
| 71 virtual size_t Size() = 0; |
| 72 }; |
| 73 |
| 74 /** |
| 75 * Expanding memory block for woff2 out. By default limited to kDefaultMaxSize. |
| 76 */ |
| 77 class WOFF2StringOut : public WOFF2Out { |
| 78 public: |
| 79 // Create a writer that writes its data to buf. |
| 80 // buf->size() will grow to at most max_size |
| 81 // buf may be sized (e.g. using EstimateWOFF2FinalSize) or empty. |
| 82 explicit WOFF2StringOut(string* buf); |
| 83 |
| 84 bool Write(const void *buf, size_t n) override; |
| 85 bool Write(const void *buf, size_t offset, size_t n) override; |
| 86 size_t Size() override { return offset_; } |
| 87 size_t MaxSize() { return max_size_; } |
| 88 void SetMaxSize(size_t max_size); |
| 89 private: |
| 90 string* buf_; |
| 91 size_t max_size_; |
| 92 size_t offset_; |
| 93 }; |
| 94 |
| 95 /** |
| 96 * Fixed memory block for woff2 out. |
| 97 */ |
| 98 class WOFF2MemoryOut : public WOFF2Out { |
| 99 public: |
| 100 // Create a writer that writes its data to buf. |
| 101 WOFF2MemoryOut(uint8_t* buf, size_t buf_size); |
| 102 |
| 103 bool Write(const void *buf, size_t n) override; |
| 104 bool Write(const void *buf, size_t offset, size_t n) override; |
| 105 size_t Size() override { return offset_; } |
| 106 private: |
| 107 uint8_t* buf_; |
| 108 size_t buf_size_; |
| 109 size_t offset_; |
| 110 }; |
| 111 |
| 112 } // namespace woff2 |
| 113 |
| 114 #endif // WOFF2_WOFF2_OUT_H_ |
OLD | NEW |