### Example: Generate libwoff2enc.pc Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt This example illustrates the generation of the pkg-config file for the libwoff2enc library. It lists its dependencies (`libbrotlienc` and `libwoff2common`) and specifies the library name and version. ```cmake generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libwoff2enc.pc" NAME libwoff2enc DESCRIPTION "WOFF2 encoder library" URL "https://github.com/google/woff2" VERSION "${WOFF2_VERSION}" DEPENDS libbrotlienc DEPENDS_PRIVATE libwoff2common LIBRARIES woff2enc) ``` -------------------------------- ### Example: Generate libwoff2common.pc Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt This example demonstrates calling the `generate_pkg_config` function to create the pkg-config file for the libwoff2common library. It specifies the output file name, name, description, URL, version, and the library itself. ```cmake generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libwoff2common.pc" NAME libwoff2common DESCRIPTION "Shared data used by libwoff2 and libwoff2dec libraries" URL "https://github.com/google/woff2" VERSION "${WOFF2_VERSION}" LIBRARIES woff2common) ``` -------------------------------- ### Install Project Targets and Headers via CMake Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt Defines installation paths for executables, libraries, and header files. Ensure CMAKE_INSTALL variables are defined before execution. ```cmake if (NOT BUILD_SHARED_LIBS) install( TARGETS woff2_decompress woff2_compress woff2_info RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) endif() install( TARGETS woff2common woff2dec woff2enc ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ) install( DIRECTORY include/woff2 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libwoff2common.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libwoff2dec.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libwoff2enc.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ``` -------------------------------- ### Example: Generate libwoff2dec.pc Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt This example shows how to generate the pkg-config file for the libwoff2dec library. It includes its direct dependency (`libbrotlidec`) and private dependency (`libwoff2common`), along with its version and library name. ```cmake generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libwoff2dec.pc" NAME libwoff2dec DESCRIPTION "WOFF2 decoder library" URL "https://github.com/google/woff2" VERSION "${WOFF2_VERSION}" DEPENDS libbrotlidec DEPENDS_PRIVATE libwoff2common LIBRARIES woff2dec) ``` -------------------------------- ### Build WOFF2 with CMake Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/README.md Build process for systems with Brotli already installed, using CMake for configuration. ```bash git clone https://github.com/google/woff2.git cd woff2 mkdir out cd out cmake .. make make install ``` -------------------------------- ### Generate Pkg-Config Path Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt This function determines the correct path for pkg-config variables like libdir and includedir, ensuring they are relative to the installation prefix if specified. It handles cases where the provided path is a subdirectory of a known prefix. ```cmake function(generate_pkg_config_path outvar path) string(LENGTH "${path}" path_length) set(path_args ${ARGV}) list(REMOVE_AT path_args 0 1) list(LENGTH path_args path_args_remaining) set("${outvar}" "${path}") while(path_args_remaining GREATER 1) list(GET path_args 0 name) list(GET path_args 1 value) get_filename_component(value_full "${value}" ABSOLUTE) string(LENGTH "${value}" value_length) if(path_length EQUAL value_length AND path STREQUAL value) set("${outvar}" "\${${name}}") break() elseif(path_length GREATER value_length) # We might be in a subdirectory of the value, but we have to be # careful about a prefix matching but not being a subdirectory # (for example, /usr/lib64 is not a subdirectory of /usr/lib). # We'll do this by making sure the next character is a directory # separator. string(SUBSTRING "${path}" ${value_length} 1 sep) if(sep STREQUAL "/") string(SUBSTRING "${path}" 0 ${value_length} s) if(s STREQUAL value) string(SUBSTRING "${path}" "${value_length}" -1 suffix) set("${outvar}" "\${${name}}${suffix}") break() endif() endif() endif() list(REMOVE_AT path_args 0 1) list(LENGTH path_args path_args_remaining) endwhile() set("${outvar}" "${${outvar}}" PARENT_SCOPE) endfunction(generate_pkg_config_path) ``` -------------------------------- ### Build WOFF2 with make Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/README.md Standard build process for Unix-style environments using the provided makefile. ```bash git clone --recursive https://github.com/google/woff2.git cd woff2 make clean all ``` -------------------------------- ### Run Woofwoof Tests Source: https://github.com/bearcove/woofwoof/blob/main/README.md Execute the test suite to verify the compression and decompression functionality. This involves compressing a real font, checking its signature, and decompressing it. ```bash cargo test ``` -------------------------------- ### Build WOFF2 with static linkage Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/README.md Configure the build to use static libraries instead of the default shared libraries. ```bash cd woff2 mkdir out-static cmake -DBUILD_SHARED_LIBS=OFF .. make make install ``` -------------------------------- ### Add woofwoof to Cargo.toml Source: https://context7.com/bearcove/woofwoof/llms.txt Configure your project's dependencies by adding the woofwoof crate to your Cargo.toml file. No external C libraries are required. ```toml [dependencies] woofwoof = "1.0" ``` -------------------------------- ### Compress and decompress fonts Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/README.md Basic usage commands for the woff2_compress and woff2_decompress binaries. ```bash woff2_compress myfont.ttf woff2_decompress myfont.woff2 ``` -------------------------------- ### Generate Pkg-Config File Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt This function generates a .pc file for pkg-config. It takes various arguments to define the package's metadata, dependencies, libraries, and compiler flags. It uses `generate_pkg_config_path` to resolve library and include directories. ```cmake function(generate_pkg_config output_file) set (options) set (oneValueArgs NAME DESCRIPTION URL VERSION PREFIX LIBDIR INCLUDEDIR) set (multiValueArgs DEPENDS DEPENDS_PRIVATE CFLAGS LIBRARIES) cmake_parse_arguments(GEN_PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) unset (options) unset (oneValueArgs) unset (multiValueArgs) if(NOT GEN_PKG_PREFIX) set(GEN_PKG_PREFIX "${CMAKE_INSTALL_PREFIX}") endif() if(NOT GEN_PKG_LIBDIR) set(GEN_PKG_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}") endif() generate_pkg_config_path(GEN_PKG_LIBDIR "${GEN_PKG_LIBDIR}" prefix "${GEN_PKG_PREFIX}") if(NOT GEN_PKG_INCLUDEDIR) set(GEN_PKG_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}") endif() generate_pkg_config_path(GEN_PKG_INCLUDEDIR "${GEN_PKG_INCLUDEDIR}" prefix "${GEN_PKG_PREFIX}") file(WRITE "${output_file}" "prefix=${GEN_PKG_PREFIX}\n") file(APPEND "${output_file}" "libdir=${GEN_PKG_LIBDIR}\n") file(APPEND "${output_file}" "includedir=${GEN_PKG_INCLUDEDIR}\n") file(APPEND "${output_file}" "\n") if(GEN_PKG_NAME) file(APPEND "${output_file}" "Name: ${GEN_PKG_NAME}\n") else() file(APPEND "${output_file}" "Name: ${CMAKE_PROJECT_NAME}\n") endif() if(GEN_PKG_DESCRIPTION) file(APPEND "${output_file}" "Description: ${GEN_PKG_DESCRIPTION}\n") endif() if(GEN_PKG_URL) file(APPEND "${output_file}" "URL: ${GEN_PKG_URL}\n") endif() if(GEN_PKG_VERSION) file(APPEND "${output_file}" "Version: ${GEN_PKG_VERSION}\n") endif() if(GEN_PKG_DEPENDS) file(APPEND "${output_file}" "Requires: ${GEN_PKG_DEPENDS}\n") endif() if(GEN_PKG_DEPENDS_PRIVATE) file(APPEND "${output_file}" "Requires.private:") foreach(lib ${GEN_PKG_DEPENDS_PRIVATE}) file(APPEND "${output_file}" " ${lib}") endforeach() file(APPEND "${output_file}" "\n") endif() if(GEN_PKG_LIBRARIES) set(libs) file(APPEND "${output_file}" "Libs: -L\${libdir}") foreach(lib ${GEN_PKG_LIBRARIES}) file(APPEND "${output_file}" " -l${lib}") endforeach() file(APPEND "${output_file}" "\n") endif() file(APPEND "${output_file}" "Cflags: -I\${includedir}") if(GEN_PKG_CFLAGS) foreach(cflag ${GEN_PKG_CFLAGS}) file(APPEND "${output_file}" " ${cflag}") endforeach() endif() file(APPEND "${output_file}" "\n") endfunction(generate_pkg_config) ``` -------------------------------- ### WOFF2 CMake Build Configuration Source: https://github.com/bearcove/woofwoof/blob/main/vendor/woff2/CMakeLists.txt The primary CMake configuration file for building the woff2 project, including dependency management and target definitions. ```cmake # Copyright 2017 Igalia S.L. All Rights Reserved. # # Distributed under MIT license. # See file LICENSE for detail or copy at https://opensource.org/licenses/MIT # Ubuntu 12.04 LTS has CMake 2.8.7, and is an important target since # several CI services, such as Travis and Drone, use it. Solaris 11 # has 2.8.6, and it's not difficult to support if you already have to # support 2.8.7. cmake_minimum_required(VERSION 2.8.6) project(woff2) include(GNUInstallDirs) # Build options option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(CANONICAL_PREFIXES "Canonical prefixes" OFF) option(NOISY_LOGGING "Noisy logging" ON) # Version information set(WOFF2_VERSION 1.0.2) # When building shared libraries it is important to set the correct rpath # See https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir) if ("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") endif() # Find Brotli dependencies set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(BrotliDec) if (NOT BROTLIDEC_FOUND) message(FATAL_ERROR "librotlidec is needed to build woff2.") endif () find_package(BrotliEnc) if (NOT BROTLIENC_FOUND) message(FATAL_ERROR "librotlienc is needed to build woff2.") endif () # Set compiler flags if (NOT CANONICAL_PREFIXES) add_definitions(-no-canonical-prefixes) endif () if (NOISY_LOGGING) add_definitions(-DFONT_COMPRESSION_BIN) endif () add_definitions(-D__STDC_FORMAT_MACROS) set(COMMON_FLAGS -fno-omit-frame-pointer) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") add_definitions(-DOS_MACOSX) else () set(COMMON_FLAGS "${COMMON_FLAG} -fno-omit-frame-pointer") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAG}") set(CMAKE_CXX_STANDARD 11) # Set search path for our private/public headers as well as Brotli headers include_directories("src" "include" "${BROTLIDEC_INCLUDE_DIRS}" "${BROTLIENC_INCLUDE_DIRS}") # Common part used by decoder and encoder add_library(woff2common src/table_tags.cc src/variable_length.cc src/woff2_common.cc) # WOFF2 Decoder add_library(woff2dec src/woff2_dec.cc src/woff2_out.cc) target_link_libraries(woff2dec woff2common "${BROTLIDEC_LIBRARIES}") add_executable(woff2_decompress src/woff2_decompress.cc) target_link_libraries(woff2_decompress woff2dec) # WOFF2 Encoder add_library(woff2enc src/font.cc src/glyph.cc src/normalize.cc src/transform.cc src/woff2_enc.cc) target_link_libraries(woff2enc woff2common "${BROTLIENC_LIBRARIES}") add_executable(woff2_compress src/woff2_compress.cc) target_link_libraries(woff2_compress woff2enc) # WOFF2 info add_executable(woff2_info src/woff2_info.cc) target_link_libraries(woff2_info woff2common) foreach(lib woff2common woff2dec woff2enc) set_target_properties(${lib} PROPERTIES SOVERSION ${WOFF2_VERSION} VERSION ${WOFF2_VERSION} POSITION_INDEPENDENT_CODE TRUE) endforeach() # Fuzzer libraries add_library(convert_woff2ttf_fuzzer STATIC src/convert_woff2ttf_fuzzer.cc) target_link_libraries(convert_woff2ttf_fuzzer woff2dec) add_library(convert_woff2ttf_fuzzer_new_entry STATIC src/convert_woff2ttf_fuzzer_new_entry.cc) target_link_libraries(convert_woff2ttf_fuzzer_new_entry woff2dec) ``` -------------------------------- ### Compress TTF/OTF to WOFF2 using woofwoof Source: https://context7.com/bearcove/woofwoof/llms.txt Compresses font data to WOFF2 format. Supports optional XML metadata, brotli quality levels (0-11), and font-specific transforms. Recommended to use quality 8-11 and enable transforms for optimal results. ```rust use woofwoof::compress; fn main() -> Result<(), Box> { // Read a TTF font file let ttf_data = std::fs::read("fonts/Roboto.ttf")?; println!("Original TTF size: {} bytes", ttf_data.len()); // Compress to WOFF2 with quality 8 and font transforms enabled // Parameters: data, metadata (empty string for none), quality (0-11), transform (bool) let woff2_data = compress(&ttf_data, "", 8, true) .expect("WOFF2 compression failed"); // Verify the WOFF2 signature (first 4 bytes should be "wOF2") assert_eq!(&woff2_data[0..4], b"wOF2", "Invalid WOFF2 signature"); // Save the compressed font std::fs::write("fonts/Roboto.woff2", &woff2_data)?; println!("Compressed WOFF2 size: {} bytes", woff2_data.len()); println!("Compression ratio: {:.1}%", (woff2_data.len() as f64 / ttf_data.len() as f64) * 100.0); // Example with higher quality for maximum compression let woff2_max = compress(&ttf_data, "", 11, true) .expect("High quality compression failed"); println!("Max quality WOFF2 size: {} bytes", woff2_max.len()); // Example with XML metadata let metadata = r###" "###; let woff2_with_meta = compress(&ttf_data, metadata, 8, true) .expect("Compression with metadata failed"); println!("WOFF2 with metadata: {} bytes", woff2_with_meta.len()); // Example without font transforms (not recommended, larger output) let woff2_no_transform = compress(&ttf_data, "", 8, false) .expect("Compression without transforms failed"); println!("WOFF2 without transforms: {} bytes", woff2_no_transform.len()); Ok(()) } ``` -------------------------------- ### Compress and Decompress TTF Font to WOFF2 Source: https://context7.com/bearcove/woofwoof/llms.txt Reads a TTF font, compresses it to WOFF2 format with specified quality, writes the WOFF2 file, decompresses it back to TTF, and writes the roundtripped TTF file. Note that the decompressed font may differ in byte size but is semantically equivalent. ```rust use woofwoof::{compress, decompress}; use std::path::Path; fn process_font(input_path: &str) -> Result<(), Box> { let input = Path::new(input_path); let stem = input.file_stem().unwrap().to_str().unwrap(); // Read original TTF font let ttf = std::fs::read(input_path)?; println!("Original TTF: {} bytes", ttf.len()); // Compress to WOFF2 (quality 8 is good balance of speed/size) let woff2 = compress(&ttf, "", 8, true) .ok_or("Compression failed")?; // Verify WOFF2 magic bytes assert_eq!(&woff2[0..4], b"wOF2"); let woff2_path = format!("{}.woff2", stem); std::fs::write(&woff2_path, &woff2)?; println!("Wrote {} ({} bytes)", woff2_path, woff2.len()); // Decompress back to TTF let roundtripped = decompress(&woff2) .ok_or("Decompression failed")?; let roundtrip_path = format!("{}-roundtripped.ttf", stem); std::fs::write(&roundtrip_path, &roundtripped)?; println!("Wrote {} ({} bytes)", roundtrip_path, roundtripped.len()); // Note: roundtripped font may differ in bytes but is semantically equivalent println!("Size difference from original: {} bytes", roundtripped.len() as i64 - ttf.len() as i64); Ok(()) } fn main() { process_font("tests/Roboto.ttf").expect("Font processing failed"); } ``` -------------------------------- ### compress Source: https://github.com/bearcove/woofwoof/blob/main/README.md Compresses a TTF or OTF font file into the WOFF2 format. ```APIDOC ## compress(data, metadata, quality, transform) ### Description Compress a TTF/OTF font to WOFF2 format. ### Parameters - **data** (Vec) - Required - The TTF or OTF font data - **metadata** (String) - Required - Optional extended metadata (XML string, usually empty "") - **quality** (i32) - Required - Brotli compression quality (0-11, recommended: 8-11) - **transform** (bool) - Required - Whether to apply font-specific transforms (recommended: true) ### Response - **Success Response** (Option>) - Returns the compressed WOFF2 data if successful, otherwise None. ``` -------------------------------- ### Compress and Decompress TTF/OTF to WOFF2 in Rust Source: https://github.com/bearcove/woofwoof/blob/main/README.md Use these functions to compress font files to WOFF2 format and decompress them back. Ensure proper error handling for compression and decompression operations. ```rust use woofwoof::{compress, decompress}; // Compress TTF/OTF to WOFF2 let ttf_data = std::fs::read("font.ttf")?; let woff2_data = compress(&ttf_data, "", 8, true) .expect("compression failed"); // Decompress WOFF2 back to TTF/OTF let roundtripped = decompress(&woff2_data) .expect("decompression failed"); ``` -------------------------------- ### Compress TTF/OTF to WOFF2 Source: https://context7.com/bearcove/woofwoof/llms.txt Compresses TTF or OTF font files to WOFF2 format using Google's woff2 library and brotli compression. Supports optional metadata, adjustable brotli quality, and font-specific transforms. ```APIDOC ## compress - Compress TTF/OTF to WOFF2 ### Description Compresses a TTF or OTF font file to WOFF2 format using Google's woff2 library for font-specific table transformations and brotli for compression. The function accepts the raw font bytes, optional XML metadata, a brotli quality level (0-11, where 8-11 is recommended for production), and a boolean to enable font-specific transforms (recommended: true). Returns `Option>` containing the WOFF2 data on success. ### Method POST (conceptual, as this is a library function) ### Endpoint N/A (Library Function) ### Parameters #### Function Arguments - **data** (Vec) - Required - Raw bytes of the TTF/OTF font file. - **metadata** (str) - Optional - XML string containing metadata. - **quality** (u8) - Optional - Brotli compression quality level (0-11). Recommended: 8-11. - **transform** (bool) - Optional - Whether to enable font-specific transforms. Recommended: true. ### Request Example ```rust use woofwoof::compress; fn main() -> Result<(), Box> { let ttf_data = std::fs::read("fonts/Roboto.ttf")?; let woff2_data = compress(&ttf_data, "", 8, true)?; std::fs::write("fonts/Roboto.woff2", &woff2_data)?; Ok(()) } ``` ### Response #### Success Response - **WOFF2 Data** (Option>) - Contains the compressed WOFF2 font data if successful. ``` -------------------------------- ### Decompress WOFF2 to TTF/OTF using woofwoof Source: https://context7.com/bearcove/woofwoof/llms.txt Decompresses WOFF2 font data back to TTF/OTF format. It's recommended to verify the WOFF2 signature before decompression. The decompressed font may not be byte-identical but will be semantically equivalent. ```rust use woofwoof::decompress; fn main() -> Result<(), Box> { // Read a WOFF2 font file let woff2_data = std::fs::read("fonts/Roboto.woff2")?; println!("WOFF2 size: {} bytes", woff2_data.len()); // Verify it's a valid WOFF2 file before decompression if woff2_data.len() < 4 || &woff2_data[0..4] != b"wOF2" { panic!("Invalid WOFF2 file: missing signature"); } // Decompress to TTF/OTF format let ttf_data = decompress(&woff2_data) .expect("WOFF2 decompression failed"); // Save the decompressed font std::fs::write("fonts/Roboto-decompressed.ttf", &ttf_data)?; println!("Decompressed TTF size: {} bytes", ttf_data.len()); // Handle decompression errors gracefully let invalid_data = vec![0u8; 100]; match decompress(&invalid_data) { Some(data) => println!("Decompressed {} bytes", data.len()), None => println!("Decompression failed: invalid WOFF2 data"), } Ok(()) } ``` -------------------------------- ### Decompress WOFF2 to TTF/OTF Source: https://context7.com/bearcove/woofwoof/llms.txt Decompresses WOFF2 font files back to their original TTF/OTF format. The function takes WOFF2 compressed data and returns the decompressed font data. ```APIDOC ## decompress - Decompress WOFF2 to TTF/OTF ### Description Decompresses a WOFF2 font file back to its original TTF/OTF format. The function takes the WOFF2 compressed data and returns `Option>` containing the decompressed font. Note that the roundtripped font may not be byte-identical to the original due to WOFF2's font table transformations, but it will be semantically equivalent and fully functional. ### Method POST (conceptual, as this is a library function) ### Endpoint N/A (Library Function) ### Parameters #### Function Arguments - **data** (Vec) - Required - Raw bytes of the WOFF2 font file. ### Request Example ```rust use woofwoof::decompress; fn main() -> Result<(), Box> { let woff2_data = std::fs::read("fonts/Roboto.woff2")?; let ttf_data = decompress(&woff2_data)?; std::fs::write("fonts/Roboto-decompressed.ttf", &ttf_data)?; Ok(()) } ``` ### Response #### Success Response - **TTF/OTF Data** (Option>) - Contains the decompressed TTF/OTF font data if successful. ``` -------------------------------- ### decompress Source: https://github.com/bearcove/woofwoof/blob/main/README.md Decompresses a WOFF2 font file back into its original TTF or OTF format. ```APIDOC ## decompress(data) ### Description Decompress a WOFF2 font back to TTF/OTF format. ### Parameters - **data** (Vec) - Required - The WOFF2 font data ### Response - **Success Response** (Option>) - Returns the decompressed TTF/OTF data if successful, otherwise None. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.