From 9b5a53b1d7bf52f51c9a3691f4664453d4805ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Mon, 2 Oct 2017 20:05:19 +0200 Subject: [PATCH] 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. --- Makefile | 2 +- src/woff2_dec.h => include/woff2/decode.h | 2 +- src/woff2_enc.h => include/woff2/encode.h | 7 ++----- src/woff2_out.h => include/woff2/output.h | 8 ++------ src/convert_woff2ttf_fuzzer.cc | 2 +- src/convert_woff2ttf_fuzzer_new_entry.cc | 2 +- src/woff2_compress.cc | 2 +- src/woff2_dec.cc | 2 +- src/woff2_decompress.cc | 2 +- src/woff2_enc.cc | 2 +- src/woff2_out.cc | 4 +++- 11 files changed, 15 insertions(+), 20 deletions(-) rename src/woff2_dec.h => include/woff2/decode.h (97%) rename src/woff2_enc.h => include/woff2/encode.h (92%) rename src/woff2_out.h => include/woff2/output.h (95%) diff --git a/Makefile b/Makefile index 3b732c9..35e611e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ OS := $(shell uname) -CPPFLAGS = -I./brotli/c/include/ -I./src +CPPFLAGS = -I./brotli/c/include/ -I./src -I./include AR ?= ar CC ?= gcc diff --git a/src/woff2_dec.h b/include/woff2/decode.h similarity index 97% rename from src/woff2_dec.h rename to include/woff2/decode.h index bc90feb..6ef3b8e 100644 --- a/src/woff2_dec.h +++ b/include/woff2/decode.h @@ -11,7 +11,7 @@ #include #include -#include "./woff2_out.h" +#include namespace woff2 { diff --git a/src/woff2_enc.h b/include/woff2/encode.h similarity index 92% rename from src/woff2_enc.h rename to include/woff2/encode.h index d4cbd23..34b7722 100644 --- a/src/woff2_enc.h +++ b/include/woff2/encode.h @@ -13,16 +13,13 @@ #include #include -using std::string; - - namespace woff2 { struct WOFF2Params { WOFF2Params() : extended_metadata(""), brotli_quality(11), allow_transforms(true) {} - string extended_metadata; + std::string extended_metadata; int brotli_quality; bool allow_transforms; }; @@ -30,7 +27,7 @@ struct WOFF2Params { // 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 string& extended_metadata); + 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 diff --git a/src/woff2_out.h b/include/woff2/output.h similarity index 95% rename from src/woff2_out.h rename to include/woff2/output.h index 7ac59af..c325f67 100644 --- a/src/woff2_out.h +++ b/include/woff2/output.h @@ -13,16 +13,12 @@ #include #include #include -#include "./port.h" namespace woff2 { // Suggested max size for output. const size_t kDefaultMaxSize = 30 * 1024 * 1024; -using std::string; - - /** * Output interface for the woff2 decoding. * @@ -55,7 +51,7 @@ class WOFF2StringOut : public WOFF2Out { // 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(string* buf); + 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; @@ -63,7 +59,7 @@ class WOFF2StringOut : public WOFF2Out { size_t MaxSize() { return max_size_; } void SetMaxSize(size_t max_size); private: - string* buf_; + std::string* buf_; size_t max_size_; size_t offset_; }; diff --git a/src/convert_woff2ttf_fuzzer.cc b/src/convert_woff2ttf_fuzzer.cc index 3fdd15b..2d977a3 100644 --- a/src/convert_woff2ttf_fuzzer.cc +++ b/src/convert_woff2ttf_fuzzer.cc @@ -1,7 +1,7 @@ #include #include -#include "woff2_dec.h" +#include // Entry point for LibFuzzer. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/src/convert_woff2ttf_fuzzer_new_entry.cc b/src/convert_woff2ttf_fuzzer_new_entry.cc index 75114a9..5ad9336 100644 --- a/src/convert_woff2ttf_fuzzer_new_entry.cc +++ b/src/convert_woff2ttf_fuzzer_new_entry.cc @@ -1,5 +1,5 @@ #include -#include "woff2_dec.h" +#include extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t data_size) { // Decode using newer entry pattern. diff --git a/src/woff2_compress.cc b/src/woff2_compress.cc index e28e267..80e3108 100644 --- a/src/woff2_compress.cc +++ b/src/woff2_compress.cc @@ -9,7 +9,7 @@ #include #include "file.h" -#include "./woff2_enc.h" +#include int main(int argc, char **argv) { diff --git a/src/woff2_dec.cc b/src/woff2_dec.cc index fd0d407..8186c8e 100644 --- a/src/woff2_dec.cc +++ b/src/woff2_dec.cc @@ -6,7 +6,7 @@ /* Library for converting WOFF2 format font files to their TTF versions. */ -#include "./woff2_dec.h" +#include #include #include diff --git a/src/woff2_decompress.cc b/src/woff2_decompress.cc index f3b4567..de088b9 100644 --- a/src/woff2_decompress.cc +++ b/src/woff2_decompress.cc @@ -10,7 +10,7 @@ #include #include "./file.h" -#include "./woff2_dec.h" +#include int main(int argc, char **argv) { diff --git a/src/woff2_enc.cc b/src/woff2_enc.cc index cff37dc..ec00878 100644 --- a/src/woff2_enc.cc +++ b/src/woff2_enc.cc @@ -6,7 +6,7 @@ /* Library for converting TTF format font files to their WOFF2 versions. */ -#include "./woff2_enc.h" +#include #include #include diff --git a/src/woff2_out.cc b/src/woff2_out.cc index 4a4d8cc..8ab3268 100644 --- a/src/woff2_out.cc +++ b/src/woff2_out.cc @@ -6,7 +6,9 @@ /* Output buffer for WOFF2 decompression. */ -#include "./woff2_out.h" +#include + +using std::string; namespace woff2 {