Move public headers into a separate include/woff2 directory

This is a first step to make WOFF2 a shared library. Public headers are moved
in their own directory to make the public API clearer. This is similar to
the c/include/brotli/ directory in Brotli. "using" commands are also removed
from the public headers, so that callers won't have unexpected side effect
when including the files.
This commit is contained in:
Frédéric Wang
2017-10-02 20:05:19 +02:00
committed by Rod Sheeter
parent 914faa323d
commit 9b5a53b1d7
11 changed files with 15 additions and 20 deletions
+36
View File
@@ -0,0 +1,36 @@
/* Copyright 2014 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/* Library for converting WOFF2 format font files to their TTF versions. */
#ifndef WOFF2_WOFF2_DEC_H_
#define WOFF2_WOFF2_DEC_H_
#include <stddef.h>
#include <inttypes.h>
#include <woff2/output.h>
namespace woff2 {
// Compute the size of the final uncompressed font, or 0 on error.
size_t ComputeWOFF2FinalSize(const uint8_t *data, size_t length);
// Decompresses the font into the target buffer. The result_length should
// be the same as determined by ComputeFinalSize(). Returns true on successful
// decompression.
// DEPRECATED; please prefer the version that takes a WOFF2Out*
bool ConvertWOFF2ToTTF(uint8_t *result, size_t result_length,
const uint8_t *data, size_t length);
// Decompresses the font into out. Returns true on success.
// Works even if WOFF2Header totalSfntSize is wrong.
// Please prefer this API.
bool ConvertWOFF2ToTTF(const uint8_t *data, size_t length,
WOFF2Out* out);
} // namespace woff2
#endif // WOFF2_WOFF2_DEC_H_
+43
View File
@@ -0,0 +1,43 @@
/* Copyright 2014 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/* Library for converting WOFF2 format font files to their TTF versions. */
#ifndef WOFF2_WOFF2_ENC_H_
#define WOFF2_WOFF2_ENC_H_
#include <stddef.h>
#include <inttypes.h>
#include <string>
namespace woff2 {
struct WOFF2Params {
WOFF2Params() : extended_metadata(""), brotli_quality(11),
allow_transforms(true) {}
std::string extended_metadata;
int brotli_quality;
bool allow_transforms;
};
// Returns an upper bound on the size of the compressed file.
size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length);
size_t MaxWOFF2CompressedSize(const uint8_t* data, size_t length,
const std::string& extended_metadata);
// Compresses the font into the target buffer. *result_length should be at least
// the value returned by MaxWOFF2CompressedSize(), upon return, it is set to the
// actual compressed size. Returns true on successful compression.
bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
uint8_t *result, size_t *result_length);
bool ConvertTTFToWOFF2(const uint8_t *data, size_t length,
uint8_t *result, size_t *result_length,
const WOFF2Params& params);
} // namespace woff2
#endif // WOFF2_WOFF2_ENC_H_
+86
View File
@@ -0,0 +1,86 @@
/* Copyright 2016 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/* Output buffer for WOFF2 decompression. */
#ifndef WOFF2_WOFF2_OUT_H_
#define WOFF2_WOFF2_OUT_H_
#include <algorithm>
#include <cstring>
#include <memory>
#include <string>
namespace woff2 {
// Suggested max size for output.
const size_t kDefaultMaxSize = 30 * 1024 * 1024;
/**
* Output interface for the woff2 decoding.
*
* Writes to arbitrary offsets are supported to facilitate updating offset
* table and checksums after tables are ready. Reading the current size is
* supported so a 'loca' table can be built up while writing glyphs.
*
* By default limits size to kDefaultMaxSize.
*/
class WOFF2Out {
public:
virtual ~WOFF2Out(void) {}
// Append n bytes of data from buf.
// Return true if all written, false otherwise.
virtual bool Write(const void *buf, size_t n) = 0;
// Write n bytes of data from buf at offset.
// Return true if all written, false otherwise.
virtual bool Write(const void *buf, size_t offset, size_t n) = 0;
virtual size_t Size() = 0;
};
/**
* Expanding memory block for woff2 out. By default limited to kDefaultMaxSize.
*/
class WOFF2StringOut : public WOFF2Out {
public:
// Create a writer that writes its data to buf.
// buf->size() will grow to at most max_size
// buf may be sized (e.g. using EstimateWOFF2FinalSize) or empty.
explicit WOFF2StringOut(std::string* buf);
bool Write(const void *buf, size_t n) override;
bool Write(const void *buf, size_t offset, size_t n) override;
size_t Size() override { return offset_; }
size_t MaxSize() { return max_size_; }
void SetMaxSize(size_t max_size);
private:
std::string* buf_;
size_t max_size_;
size_t offset_;
};
/**
* Fixed memory block for woff2 out.
*/
class WOFF2MemoryOut : public WOFF2Out {
public:
// Create a writer that writes its data to buf.
WOFF2MemoryOut(uint8_t* buf, size_t buf_size);
bool Write(const void *buf, size_t n) override;
bool Write(const void *buf, size_t offset, size_t n) override;
size_t Size() override { return offset_; }
private:
uint8_t* buf_;
size_t buf_size_;
size_t offset_;
};
} // namespace woff2
#endif // WOFF2_WOFF2_OUT_H_