├── .dockerignore ├── .github └── workflows │ ├── master-build-test.yml │ └── master-release-cratesio.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── Dockerfile.cratesio ├── LICENSE ├── README.md ├── SECURITY.md ├── build.rs ├── examples └── hello_world.rs ├── libharu ├── CMakeLists.txt ├── cmake │ └── modules │ │ ├── haru.cmake │ │ └── summary.cmake ├── include │ ├── .gitignore │ ├── hpdf.h │ ├── hpdf_3dmeasure.h │ ├── hpdf_annotation.h │ ├── hpdf_catalog.h │ ├── hpdf_conf.h │ ├── hpdf_config.h.cmake │ ├── hpdf_consts.h │ ├── hpdf_destination.h │ ├── hpdf_doc.h │ ├── hpdf_encoder.h │ ├── hpdf_encrypt.h │ ├── hpdf_encryptdict.h │ ├── hpdf_error.h │ ├── hpdf_exdata.h │ ├── hpdf_ext_gstate.h │ ├── hpdf_font.h │ ├── hpdf_fontdef.h │ ├── hpdf_gstate.h │ ├── hpdf_image.h │ ├── hpdf_info.h │ ├── hpdf_list.h │ ├── hpdf_mmgr.h │ ├── hpdf_namedict.h │ ├── hpdf_objects.h │ ├── hpdf_outline.h │ ├── hpdf_page_label.h │ ├── hpdf_pages.h │ ├── hpdf_pdfa.h │ ├── hpdf_streams.h │ ├── hpdf_types.h │ ├── hpdf_u3d.h │ ├── hpdf_utils.h │ └── hpdf_version.h └── src │ ├── .gitignore │ ├── CMakeLists.txt │ ├── hpdf_3dmeasure.c │ ├── hpdf_annotation.c │ ├── hpdf_array.c │ ├── hpdf_binary.c │ ├── hpdf_boolean.c │ ├── hpdf_catalog.c │ ├── hpdf_destination.c │ ├── hpdf_dict.c │ ├── hpdf_direct.c │ ├── hpdf_doc.c │ ├── hpdf_doc_png.c │ ├── hpdf_encoder.c │ ├── hpdf_encoder_cns.c │ ├── hpdf_encoder_cnt.c │ ├── hpdf_encoder_jp.c │ ├── hpdf_encoder_kr.c │ ├── hpdf_encoder_utf.c │ ├── hpdf_encrypt.c │ ├── hpdf_encryptdict.c │ ├── hpdf_error.c │ ├── hpdf_exdata.c │ ├── hpdf_ext_gstate.c │ ├── hpdf_font.c │ ├── hpdf_font_cid.c │ ├── hpdf_font_tt.c │ ├── hpdf_font_type1.c │ ├── hpdf_fontdef.c │ ├── hpdf_fontdef_base14.c │ ├── hpdf_fontdef_cid.c │ ├── hpdf_fontdef_cns.c │ ├── hpdf_fontdef_cnt.c │ ├── hpdf_fontdef_jp.c │ ├── hpdf_fontdef_kr.c │ ├── hpdf_fontdef_tt.c │ ├── hpdf_fontdef_type1.c │ ├── hpdf_gstate.c │ ├── hpdf_image.c │ ├── hpdf_image_ccitt.c │ ├── hpdf_image_png.c │ ├── hpdf_info.c │ ├── hpdf_list.c │ ├── hpdf_mmgr.c │ ├── hpdf_name.c │ ├── hpdf_namedict.c │ ├── hpdf_null.c │ ├── hpdf_number.c │ ├── hpdf_objects.c │ ├── hpdf_outline.c │ ├── hpdf_page_label.c │ ├── hpdf_page_operator.c │ ├── hpdf_pages.c │ ├── hpdf_pdfa.c │ ├── hpdf_real.c │ ├── hpdf_shading.c │ ├── hpdf_streams.c │ ├── hpdf_string.c │ ├── hpdf_u3d.c │ ├── hpdf_utils.c │ ├── hpdf_xref.c │ └── t4.h ├── libharu_ng.code-workspace └── src ├── document.rs ├── font.rs ├── haru_bindings.rs ├── haru_types.rs ├── image.rs ├── lib.rs └── page.rs /.dockerignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bastibense/libharu_ng/b5f2760e086676563dd7dd2257d1888b5dca733a/.dockerignore -------------------------------------------------------------------------------- /.github/workflows/master-build-test.yml: -------------------------------------------------------------------------------- 1 | name: Build and test 2 | 3 | on: 4 | push: 5 | branches: ['master'] 6 | 7 | env: 8 | CARGO_TERM_COLOR: always 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: Build docker image 18 | run: docker build -t libharu_ng . --build-arg="CRATESIO_TOKEN=${{ secrets.CRATESIO_TOKEN }}" 19 | -------------------------------------------------------------------------------- /.github/workflows/master-release-cratesio.yml: -------------------------------------------------------------------------------- 1 | name: Build, test and publish 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | env: 8 | CARGO_TERM_COLOR: always 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: Build docker image 18 | run: docker build -f Dockerfile.cratesio -t libharu_ng . --build-arg="CRATESIO_TOKEN=${{ secrets.CRATESIO_TOKEN }}" 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | test.pdf 3 | .DS_Store 4 | hello_world.pdf 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | bb@neo.de. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you find bugs, please open an issue. 2 | 3 | If you want to contribute code, please open a PR and an issue. 4 | 5 | Format your code with `rustfmt`. 6 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "cc" 7 | version = "1.2.1" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" 10 | dependencies = [ 11 | "shlex", 12 | ] 13 | 14 | [[package]] 15 | name = "cmake" 16 | version = "0.1.51" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" 19 | dependencies = [ 20 | "cc", 21 | ] 22 | 23 | [[package]] 24 | name = "libharu_ng" 25 | version = "1.0.10" 26 | dependencies = [ 27 | "cmake", 28 | ] 29 | 30 | [[package]] 31 | name = "shlex" 32 | version = "1.3.0" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 35 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | version = "1.0.10" 3 | name = "libharu_ng" 4 | description = "Easily generate PDFs from your Rust app" 5 | authors = ["Bastian Bense "] 6 | license = "MIT" 7 | readme = "README.md" 8 | repository = "https://github.com/bastibense/libharu_ng" 9 | homepage = "https://github.com/bastibense/libharu_ng" 10 | categories = ["external-ffi-bindings", "api-bindings"] 11 | 12 | edition = "2021" 13 | build = "build.rs" 14 | 15 | exclude = [ 16 | "*.code-workspace", 17 | ".github", 18 | ".gitignore", 19 | ".dockerignore", 20 | ".DS_Store", 21 | "Dockerfile", 22 | ] 23 | 24 | [build-dependencies] 25 | cmake = "0.1.50" 26 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This Dockerfile will build and test the library. 4 | # 5 | # Copyright (c) 2024, Bastian Bense 6 | # 7 | 8 | FROM rust:slim 9 | 10 | # Set the search path for the dynamic linker 11 | # This is required because libharu is installed in /usr/local/lib and the 12 | # rust docker image does not include this path in the search path. 13 | # 14 | ENV LD_LIBRARY_PATH=/usr/local/lib 15 | 16 | 17 | # Install dependencies 18 | # 19 | RUN apt-get update && apt-get install -y \ 20 | build-essential \ 21 | libpng-dev \ 22 | zlib1g-dev \ 23 | cmake \ 24 | && rm -rf /var/lib/apt/lists/* 25 | 26 | WORKDIR /app 27 | 28 | # Copy source code 29 | # 30 | COPY libharu libharu 31 | COPY src src 32 | COPY Cargo.toml Cargo.lock build.rs ./ 33 | 34 | # Build and test 35 | # 36 | RUN cargo build --release 37 | 38 | RUN cargo test --release --lib -------------------------------------------------------------------------------- /Dockerfile.cratesio: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This Dockerfile will build and test the library. 4 | # 5 | # Copyright (c) 2024, Bastian Bense 6 | # 7 | 8 | FROM rust:alpine 9 | 10 | # Set the search path for the dynamic linker 11 | # This is required because libharu is installed in /usr/local/lib and the 12 | # rust docker image does not include this path in the search path. 13 | # 14 | ENV LD_LIBRARY_PATH=/usr/local/lib 15 | 16 | ARG CRATESIO_TOKEN 17 | 18 | # Login with crates.io 19 | RUN cargo login ${CRATESIO_TOKEN} 20 | 21 | 22 | RUN apk add --no-cache \ 23 | build-base \ 24 | libpng-dev \ 25 | zlib-dev \ 26 | cmake 27 | 28 | WORKDIR /app 29 | 30 | # Copy source code 31 | # 32 | COPY libharu libharu 33 | COPY src src 34 | COPY Cargo.toml Cargo.lock build.rs README.md ./ 35 | 36 | # Build and test 37 | # 38 | RUN cargo build --release 39 | 40 | RUN cargo test --release 41 | 42 | RUN cargo publish -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Bastian Bense 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | See libharu for more copyright information. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libharu_ng 2 | 3 | ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/bastibense/libharu_ng/master-build-test.yml) 4 | ![Crates.io Downloads](https://img.shields.io/crates/d/libharu_ng) 5 | ![GitHub Stars](https://img.shields.io/github/stars/bastibense/libharu_ng) 6 | 7 | #### ⭐ Support this crate, be cool, [star this repository on GitHub](https://github.com/bastibense/libharu_ng)! :) 8 | 9 | ## What is it? 10 | 11 | Using `libharu_ng`, you can easily create PDF documents from Rust code. 12 | 13 | `libharu_ng` is a modern API wrapper for [libharu](http://libaru.org/) ([GitHub Repository](https://github.com/libharu/libharu_ng)). `libharu` is a C library for creating PDF files. This crate provides a modern and safe Rust API for generating PDFs without having to worry about the underlying C code. 14 | 15 | So, until there are mature pure-Rust alternatives for generating PDFs, `libharu_ng` is a good choice for generating PDFs from Rust code without having to use a headless browser or a commercial solution. 16 | 17 | ## `libharu` Version 18 | 19 | This crate uses the latest version of `libharu` (2.4.4) and will be updated to the latest version of `libharu` as soon as possible. 20 | 21 | ## Features 22 | 23 | ### Standard libharu Features 24 | 25 | - Create PDF documents. 26 | - Add pages to the document. 27 | - Add text to pages. 28 | - Supporting text-wrapping into a given rectangle. 29 | - Use built-in fonts or load custom fonts (TTF). 30 | - Add images to pages. 31 | - With support for JPEG and PNG images (including transparency). 32 | - Use custom page sizes. 33 | - Save and restore the graphics state. 34 | - Set password protection for the document. 35 | - Add shapes like lines, rectangles, circles, etc. to pages. 36 | - Add annotations to pages. 37 | - Add outlines to the document. 38 | - Add metadata to the document. 39 | - Compiles the libharu library from source, embedding it into your Rust project. 40 | 41 | ### Additional Features (provided by `libharu_ng`) 42 | 43 | - Simple functions for CTM transformations. 44 | - Rotate, Translate, Scale, etc. 45 | 46 | For more information about the features, please see the [libharu documentation](http://libharu.org). 47 | 48 | ## Requirements 49 | 50 | - libz (required at runtime) 51 | - libpng (required at runtime) 52 | - cmake (required for building the C library) 53 | 54 | ### On Ubuntu/Debian 55 | 56 | $ apt-get install build-essential cmake libpng-dev libz3-dev 57 | 58 | ### On macOS (Homebrew) 59 | 60 | $ brew install cmake libpng zlib 61 | 62 | ## Usage 63 | 64 | To use `libharu` in your Rust project, run the command line, in your Rust project directory: 65 | 66 | ```bash 67 | $ cargo add libharu_ng 68 | ``` 69 | 70 | ## Example 71 | 72 | ```rust 73 | // Example is work in progress. 74 | 75 | use libharu_ng::prelude::*; 76 | 77 | fn main() -> Result<(), HaruError> { 78 | let doc = PdfDocument::new(); 79 | let fnt = doc.get_font("Helvetica", None)?; 80 | 81 | doc.add_page()? 82 | .begin_text()? 83 | .move_text_pos(220.0, 20.0)? 84 | .set_font_and_size(fnt, 24.0)? 85 | .show_text("Hello World")? 86 | .end_text()?; 87 | 88 | doc.save_to_file("./test.pdf")?; 89 | 90 | Ok(()) 91 | } 92 | ``` 93 | 94 | # Motivation 95 | 96 | The main motivation behind `libharu_ng` is to provide a simple and modern API for generating PDFs from Rust code. 97 | 98 | One of the requirements was fine-grained control over the content of the PDF document and minimal dependencies and size/performance overhead. 99 | 100 | There are a number of alternatives for generating PDFs from Rust code, each with their own advantages and disadvantages: 101 | 102 | This crate, as is, will try to compile the `libharu` library from source, embedding it into your Rust project. This means that you don't have to install any additional dependencies on your system, and you don't have to worry about the `libharu` version on your system. If you have problems with the embedded `libharu` version, please open an issue. 103 | 104 | # Contributing 105 | 106 | Contributions are welcome. Please open an issue before submitting a pull request. 107 | 108 | # License 109 | 110 | - This project is licensed under the MIT license. 111 | - Haru is distributed under the ZLIB/LIBPNG License. 112 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 1.x.x | :white_check_mark: | 11 | 12 | ## Reporting a Vulnerability 13 | 14 | If you find a security issue, please open an issue. 15 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023-2024 Bastian Bense 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | // Contact: Bastian Bense, bb@neosw.de 22 | 23 | fn main() { 24 | // let dst = cmake::build("libharu"); 25 | 26 | let outdir = std::env::var("OUT_DIR").unwrap(); 27 | 28 | let dst = cmake::Config::new("libharu") 29 | .define("CMAKE_INSTALL_PREFIX", outdir) 30 | .build(); 31 | 32 | // add /opt/homebrew/opt to search 33 | println!("cargo:rustc-link-search=/opt/homebrew/opt/libpng/lib"); 34 | println!("cargo:rustc-link-search=/opt/homebrew/opt/zlib/lib"); 35 | 36 | println!("cargo:rustc-link-search={}", dst.display()); 37 | println!("cargo:rustc-link-lib=static=hpdf"); 38 | println!("cargo:rustc-link-lib=dylib=png"); 39 | println!("cargo:rustc-link-lib=dylib=z"); 40 | } 41 | -------------------------------------------------------------------------------- /examples/hello_world.rs: -------------------------------------------------------------------------------- 1 | use libharu_ng::{libharu_version, prelude::*}; 2 | 3 | /// Hello World example. 4 | /// 5 | /// This example will create a new PDF file named `hello_world.pdf` in the current directory. 6 | /// 7 | 8 | fn main() -> Result<(), HaruError> { 9 | println!("libharu version: {}", libharu_version()); 10 | 11 | let doc = PdfDocument::new(); 12 | let fnt = doc.get_font("Helvetica", None)?; 13 | 14 | doc.add_page()? 15 | .begin_text()? 16 | .move_text_pos(220.0, 20.0)? 17 | .set_font_and_size(fnt, 24.0)? 18 | .show_text("Hello World")? 19 | .end_text()?; 20 | 21 | doc.save_to_file("./test.pdf")?; 22 | 23 | Ok(()) 24 | } 25 | -------------------------------------------------------------------------------- /libharu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/include/hpdf_version.h HPDF_VERSION_H_CONTENTS REGEX " HPDF_(MAJOR|MINOR|BUGFIX)_VERSION ") 4 | string(REGEX MATCH "MAJOR_VERSION [0-9]+" HPDF_MAJOR_VERSION ${HPDF_VERSION_H_CONTENTS}) 5 | string(REGEX MATCH "MINOR_VERSION [0-9]+" HPDF_MINOR_VERSION ${HPDF_VERSION_H_CONTENTS}) 6 | string(REGEX MATCH "BUGFIX_VERSION [0-9]+" HPDF_BUGFIX_VERSION ${HPDF_VERSION_H_CONTENTS}) 7 | string(REGEX MATCH "[0-9]+" HPDF_MAJOR_VERSION ${HPDF_MAJOR_VERSION}) 8 | string(REGEX MATCH "[0-9]+" HPDF_MINOR_VERSION ${HPDF_MINOR_VERSION}) 9 | string(REGEX MATCH "[0-9]+" HPDF_BUGFIX_VERSION ${HPDF_BUGFIX_VERSION}) 10 | 11 | project(libharu 12 | VERSION ${HPDF_MAJOR_VERSION}.${HPDF_MINOR_VERSION}.${HPDF_BUGFIX_VERSION} 13 | DESCRIPTION "libHaru is a free, cross platform, open source library for generating PDF files." 14 | LANGUAGES C) 15 | 16 | include(GNUInstallDirs) 17 | 18 | 19 | # Location where the haru cmake build system first looks for cmake modules 20 | set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) 21 | 22 | # ======================================================================= 23 | # command line options 24 | # ======================================================================= 25 | option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) 26 | option(LIBHPDF_EXAMPLES "Build libharu examples" OFF) 27 | option(LIBHPDF_DEBUG "Enable HPDF Debug") 28 | option(LIBHPDF_DEBUG_TRACE "Enable HPDF Debug trace") 29 | 30 | # Enable exceptions on linux if required 31 | # (eg if you are using libharu in a C++ environment, 32 | # and you want your error-callback to throw an exception, 33 | # you will need to enable this for the exception to be 34 | # able to throw through the libharu callstack). 35 | if (CMAKE_COMPILER_IS_GNUCC OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")) 36 | option (LIBHPDF_ENABLE_EXCEPTIONS "Enable exceptions" NO) 37 | if (LIBHPDF_ENABLE_EXCEPTIONS) 38 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions") 39 | endif (LIBHPDF_ENABLE_EXCEPTIONS) 40 | endif () 41 | 42 | include_directories(${PROJECT_SOURCE_DIR}/include) 43 | 44 | # ======================================================================= 45 | # look for headers and libraries 46 | # ======================================================================= 47 | include(haru) 48 | include(summary) 49 | 50 | # check zlib availability 51 | find_package(ZLIB) 52 | 53 | # check png availability 54 | find_package(PNG) 55 | 56 | # Find math library, sometimes needs to be explicitly linked against 57 | find_library(M_LIB m) 58 | 59 | # ======================================================================= 60 | # configure header files, add compiler flags 61 | # ======================================================================= 62 | # add definitions and directories to include 63 | #if(CMAKE_COMPILER_IS_GNUCC) 64 | # add_definitions("-Wall") 65 | #endif(CMAKE_COMPILER_IS_GNUCC) 66 | if(MSVC_VERSION GREATER 1399) 67 | add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE) 68 | endif(MSVC_VERSION GREATER 1399) 69 | 70 | # Will export symbols to a .lib file on Windows 71 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1) 72 | 73 | # Just set to 1, we'll assume they are always available. 74 | # If not, then someone will have to add some tests in here to correctly determine 75 | # the headers existence. 76 | set (LIBHPDF_STDC_HEADERS 1) 77 | 78 | # support all of the different variations of LIBPNG defines in HARU 79 | set (LIBHPDF_HAVE_LIBPNG ${PNG_FOUND}) 80 | 81 | # support different zlib defines 82 | set (LIBHPDF_HAVE_ZLIB ${ZLIB_FOUND}) 83 | 84 | # create hpdf_config.h 85 | configure_file( 86 | ${PROJECT_SOURCE_DIR}/include/hpdf_config.h.cmake 87 | ${PROJECT_BINARY_DIR}/include/hpdf_config.h 88 | ) 89 | include_directories(${PROJECT_BINARY_DIR}/include) 90 | 91 | # ======================================================================= 92 | # create library and demos 93 | # ======================================================================= 94 | add_subdirectory(src) 95 | if(LIBHPDF_EXAMPLES) 96 | add_subdirectory(demo) 97 | endif(LIBHPDF_EXAMPLES) 98 | 99 | # ======================================================================= 100 | # installation configuration 101 | # ======================================================================= 102 | set( 103 | haru_HDRS 104 | include/hpdf.h 105 | include/hpdf_types.h 106 | include/hpdf_consts.h 107 | include/hpdf_annotation.h 108 | include/hpdf_catalog.h 109 | include/hpdf_conf.h 110 | include/hpdf_destination.h 111 | include/hpdf_doc.h 112 | include/hpdf_encoder.h 113 | include/hpdf_encrypt.h 114 | include/hpdf_encryptdict.h 115 | include/hpdf_error.h 116 | include/hpdf_ext_gstate.h 117 | include/hpdf_font.h 118 | include/hpdf_fontdef.h 119 | include/hpdf_gstate.h 120 | include/hpdf_image.h 121 | include/hpdf_info.h 122 | include/hpdf_list.h 123 | include/hpdf_mmgr.h 124 | include/hpdf_namedict.h 125 | include/hpdf_objects.h 126 | include/hpdf_outline.h 127 | include/hpdf_pages.h 128 | include/hpdf_page_label.h 129 | include/hpdf_streams.h 130 | include/hpdf_u3d.h 131 | include/hpdf_utils.h 132 | include/hpdf_pdfa.h 133 | include/hpdf_3dmeasure.h 134 | include/hpdf_exdata.h 135 | include/hpdf_version.h 136 | ${PROJECT_BINARY_DIR}/include/hpdf_config.h 137 | ) 138 | 139 | # install header files 140 | install(FILES ${haru_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 141 | 142 | # install various files 143 | #install(FILES README.md CHANGES INSTALL DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/libharu) 144 | #install(DIRECTORY bindings DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/libharu) 145 | 146 | # ======================================================================= 147 | # print out some information 148 | # ======================================================================= 149 | summary() 150 | -------------------------------------------------------------------------------- /libharu/cmake/modules/haru.cmake: -------------------------------------------------------------------------------- 1 | # cmake/modules/haru.cmake 2 | # 3 | # Copyright (C) 2008 Werner Smekal 4 | # 5 | # check if headers exist 6 | # Need these modules to do subsequent checks. 7 | include(CheckIncludeFiles) 8 | 9 | # ======================================================================= 10 | # check header availability 11 | # ======================================================================= 12 | # check if header file exists 13 | check_include_files(dlfcn.h LIBHPDF_HAVE_DLFCN_H) 14 | check_include_files(inttypes.h LIBHPDF_HAVE_INTTYPES_H) 15 | check_include_files(memory.h LIBHPDF_HAVE_MEMORY_H) 16 | check_include_files(stdint.h LIBHPDF_HAVE_STDINT_H) 17 | check_include_files(stdlib.h LIBHPDF_HAVE_STDLIB_H) 18 | check_include_files(strings.h LIBHPDF_HAVE_STRINGS_H) 19 | check_include_files(string.h LIBHPDF_HAVE_STRING_H) 20 | check_include_files(sys/stat.h LIBHPDF_HAVE_SYS_STAT_H) 21 | check_include_files(sys/types.h LIBHPDF_HAVE_SYS_TYPES_H) 22 | check_include_files(unistd.h LIBHPDF_HAVE_UNISTD_H) 23 | 24 | 25 | # ======================================================================= 26 | # additional library support 27 | # ======================================================================= 28 | # On windows systems the math library is not separated so do not specify 29 | # it unless you are on a non-windows system. 30 | if(NOT WIN32) 31 | find_library(MATH_LIB NAMES m PATHS /usr/local/lib /usr/lib) 32 | if(NOT MATH_LIB) 33 | message(FATAL_ERROR "Cannot find required math library") 34 | endif(NOT MATH_LIB) 35 | else(NOT WIN32) 36 | set(MATH_LIB) 37 | endif(NOT WIN32) 38 | -------------------------------------------------------------------------------- /libharu/cmake/modules/summary.cmake: -------------------------------------------------------------------------------- 1 | # cmake/modules/summary.cmake 2 | # 3 | # Copyright (C) 2008 Werner Smekal 4 | # 5 | # Macro for outputting all the most important CMake variables for haru 6 | 7 | # ======================================================================= 8 | # print summary of configuration to screen 9 | # ======================================================================= 10 | 11 | macro(summary) 12 | set(_output_results " 13 | Summary of CMake build system results for the haru library 14 | 15 | Install location variables which can be set by the user: 16 | CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} 17 | CMAKE_INSTALL_EXEC_PREFIX ${CMAKE_INSTALL_EXEC_PREFIX} 18 | CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR} 19 | CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR} 20 | CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR} 21 | 22 | Other important CMake variables: 23 | 24 | CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME} 25 | UNIX: ${UNIX} 26 | WIN32: ${WIN32} 27 | APPLE: ${APPLE} 28 | MSVC: ${MSVC} (MSVC_VERSION: ${MSVC_VERSION}) 29 | MINGW: ${MINGW} 30 | MSYS: ${MSYS} 31 | CYGWIN: ${CYGWIN} 32 | BORLAND: ${BORLAND} 33 | WATCOM: ${WATCOM} 34 | 35 | CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE} 36 | CMAKE_C_COMPILER CMAKE_C_FLAGS: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} 37 | 38 | Library options: 39 | LIBHPDF_SHARED: ${LIBHPDF_SHARED} 40 | LIBHPDF_STATIC: ${LIBHPDF_STATIC} 41 | LIBHPDF_EXAMPLES: ${LIBHPDF_EXAMPLES} 42 | DEVPAK: ${DEVPAK} 43 | 44 | Optional libraries: 45 | HAVE_ZLIB: ${LIBHPDF_HAVE_ZLIB} 46 | HAVE_LIBPNG: ${LIBHPDF_HAVE_LIBPNG} 47 | ") 48 | message("${_output_results}") 49 | endmacro(summary) 50 | -------------------------------------------------------------------------------- /libharu/include/.gitignore: -------------------------------------------------------------------------------- 1 | hpdf_config.h.in* 2 | hpdf_config.h 3 | config.h.in* 4 | config.h 5 | Makefile.in 6 | stamp-h1 7 | Makefile 8 | *.lo 9 | *.la 10 | .deps 11 | .libs 12 | *.o 13 | *.a 14 | -------------------------------------------------------------------------------- /libharu/include/hpdf_3dmeasure.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_annotation.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_3DMEASURE_H 19 | #define _HPDF_3DMEASURE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /*------ HPDF_3DMeasure -----------------------------------------------------*/ 29 | 30 | 31 | HPDF_3DMeasure 32 | HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr, 33 | HPDF_Xref xref, 34 | HPDF_Point3D firstanchorpoint, 35 | HPDF_Point3D textanchorpoint 36 | ); 37 | 38 | HPDF_3DMeasure 39 | HPDF_PD33DMeasure_New(HPDF_MMgr mmgr, 40 | HPDF_Xref xref, 41 | HPDF_Point3D annotationPlaneNormal, 42 | HPDF_Point3D firstAnchorPoint, 43 | HPDF_Point3D secondAnchorPoint, 44 | HPDF_Point3D leaderLinesDirection, 45 | HPDF_Point3D measurementValuePoint, 46 | HPDF_Point3D textYDirection, 47 | HPDF_REAL value, 48 | const char* unitsString 49 | ); 50 | 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif /* __cplusplus */ 55 | 56 | #endif /* _HPDF_3DMEASURE_H */ 57 | 58 | -------------------------------------------------------------------------------- /libharu/include/hpdf_annotation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_annotation.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_ANNOTATION_H 19 | #define _HPDF_ANNOTATION_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /*------ HPDF_Annotation -----------------------------------------------------*/ 29 | 30 | 31 | HPDF_Annotation 32 | HPDF_Annotation_New (HPDF_MMgr mmgr, 33 | HPDF_Xref xref, 34 | HPDF_AnnotType type, 35 | HPDF_Rect rect); 36 | 37 | HPDF_Annotation 38 | HPDF_WidgetAnnot_New (HPDF_MMgr mmgr, 39 | HPDF_Xref xref, 40 | HPDF_Rect rect); 41 | 42 | HPDF_Annotation 43 | HPDF_LinkAnnot_New (HPDF_MMgr mmgr, 44 | HPDF_Xref xref, 45 | HPDF_Rect rect, 46 | HPDF_Destination dst); 47 | 48 | 49 | HPDF_Annotation 50 | HPDF_URILinkAnnot_New (HPDF_MMgr mmgr, 51 | HPDF_Xref xref, 52 | HPDF_Rect rect, 53 | const char *uri); 54 | 55 | 56 | HPDF_Annotation 57 | HPDF_3DAnnot_New (HPDF_MMgr mmgr, 58 | HPDF_Xref xref, 59 | HPDF_Rect rect, 60 | HPDF_BOOL tb, 61 | HPDF_BOOL np, 62 | HPDF_U3D u3d, 63 | HPDF_Image ap); 64 | 65 | HPDF_Annotation 66 | HPDF_MarkupAnnot_New (HPDF_MMgr mmgr, 67 | HPDF_Xref xref, 68 | HPDF_Rect rect, 69 | const char *text, 70 | HPDF_Encoder encoder, 71 | HPDF_AnnotType subtype); 72 | 73 | HPDF_Annotation 74 | HPDF_PopupAnnot_New (HPDF_MMgr mmgr, 75 | HPDF_Xref xref, 76 | HPDF_Rect rect, 77 | HPDF_Annotation parent); 78 | 79 | HPDF_Annotation 80 | HPDF_StampAnnot_New (HPDF_MMgr mmgr, 81 | HPDF_Xref xref, 82 | HPDF_Rect rect, 83 | HPDF_StampAnnotName name, 84 | const char* text, 85 | HPDF_Encoder encoder); 86 | 87 | HPDF_Annotation 88 | HPDF_ProjectionAnnot_New (HPDF_MMgr mmgr, 89 | HPDF_Xref xref, 90 | HPDF_Rect rect, 91 | const char* text, 92 | HPDF_Encoder encoder); 93 | 94 | HPDF_BOOL 95 | HPDF_Annotation_Validate (HPDF_Annotation annot); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif /* __cplusplus */ 100 | 101 | #endif /* _HPDF_ANNOTATION_H */ 102 | 103 | -------------------------------------------------------------------------------- /libharu/include/hpdf_catalog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_catalog.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_CATALOG_H 19 | #define _HPDF_CATALOG_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef HPDF_Dict HPDF_Catalog; 28 | 29 | HPDF_Catalog 30 | HPDF_Catalog_New (HPDF_MMgr mmgr, 31 | HPDF_Xref xref); 32 | 33 | 34 | HPDF_NameDict 35 | HPDF_Catalog_GetNames (HPDF_Catalog catalog); 36 | 37 | 38 | HPDF_STATUS 39 | HPDF_Catalog_SetNames (HPDF_Catalog catalog, 40 | HPDF_NameDict dict); 41 | 42 | 43 | HPDF_Pages 44 | HPDF_Catalog_GetRoot (HPDF_Catalog catalog); 45 | 46 | 47 | HPDF_PageLayout 48 | HPDF_Catalog_GetPageLayout (HPDF_Catalog catalog); 49 | 50 | 51 | HPDF_STATUS 52 | HPDF_Catalog_SetPageLayout (HPDF_Catalog catalog, 53 | HPDF_PageLayout layout); 54 | 55 | 56 | HPDF_PageMode 57 | HPDF_Catalog_GetPageMode (HPDF_Catalog catalog); 58 | 59 | 60 | HPDF_STATUS 61 | HPDF_Catalog_SetPageMode (HPDF_Catalog catalog, 62 | HPDF_PageMode mode); 63 | 64 | 65 | HPDF_STATUS 66 | HPDF_Catalog_SetOpenAction (HPDF_Catalog catalog, 67 | HPDF_Destination open_action); 68 | 69 | 70 | HPDF_STATUS 71 | HPDF_Catalog_AddPageLabel (HPDF_Catalog catalog, 72 | HPDF_UINT page_num, 73 | HPDF_Dict page_label); 74 | 75 | 76 | HPDF_UINT 77 | HPDF_Catalog_GetViewerPreference (HPDF_Catalog catalog); 78 | 79 | 80 | HPDF_STATUS 81 | HPDF_Catalog_SetViewerPreference (HPDF_Catalog catalog, 82 | HPDF_UINT value); 83 | 84 | 85 | HPDF_BOOL 86 | HPDF_Catalog_Validate (HPDF_Catalog catalog); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif /* __cplusplus */ 91 | 92 | #endif /* _HPDF_CATALOG_H */ 93 | 94 | -------------------------------------------------------------------------------- /libharu/include/hpdf_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_conf.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_CONF_H 19 | #define _HPDF_CONF_H 20 | 21 | #include 22 | #include 23 | #if defined(_MSC_VER) 24 | #ifndef _USE_MATH_DEFINES 25 | #define _USE_MATH_DEFINES 1 26 | #endif /* _USE_MATH_DEFINES */ 27 | #endif 28 | #ifndef __USE_XOPEN 29 | #define __USE_XOPEN /* for M_PI */ 30 | #endif /* __USE_XOPEN */ 31 | #include 32 | 33 | /*----------------------------------------------------------------------------*/ 34 | /*----- standard C library functions -----------------------------------------*/ 35 | 36 | #define HPDF_FOPEN fopen 37 | #define HPDF_FCLOSE fclose 38 | #define HPDF_FREAD fread 39 | #define HPDF_FWRITE fwrite 40 | #define HPDF_FFLUSH fflush 41 | #define HPDF_FSEEK fseek 42 | #define HPDF_FTELL ftell 43 | #define HPDF_FEOF feof 44 | #define HPDF_FERROR ferror 45 | #define HPDF_MALLOC malloc 46 | #define HPDF_FREE free 47 | #define HPDF_FILEP FILE* 48 | #define HPDF_TIME time 49 | #define HPDF_PRINTF printf 50 | #define HPDF_SIN sin 51 | #define HPDF_COS cos 52 | 53 | /*----------------------------------------------------------------------------*/ 54 | /*----- parameters in relation to performance --------------------------------*/ 55 | 56 | /* default buffer size of memory-stream-object */ 57 | #define HPDF_STREAM_BUF_SIZ 4096 58 | 59 | /* default array size of list-object */ 60 | #define HPDF_DEF_ITEMS_PER_BLOCK 20 61 | 62 | /* default array size of cross-reference-table */ 63 | #define HPDF_DEFALUT_XREF_ENTRY_NUM 1024 64 | 65 | /* default array size of widths-table of cid-fontdef */ 66 | #define HPDF_DEF_CHAR_WIDTHS_NUM 128 67 | 68 | /* default array size of page-list-tablef */ 69 | #define HPDF_DEF_PAGE_LIST_NUM 256 70 | 71 | /* default array size of range-table of cid-fontdef */ 72 | #define HPDF_DEF_RANGE_TBL_NUM 128 73 | 74 | /* default buffer size of memory-pool-object */ 75 | #define HPDF_MPOOL_BUF_SIZ 8192 76 | #define HPDF_MIN_MPOOL_BUF_SIZ 256 77 | #define HPDF_MAX_MPOOL_BUF_SIZ 1048576 78 | 79 | /* alignment size of memory-pool-object 80 | */ 81 | #define HPDF_ALINMENT_SIZ sizeof(int) 82 | 83 | #define G3CODES 84 | 85 | #endif /* _HPDF_CONF_H */ 86 | 87 | -------------------------------------------------------------------------------- /libharu/include/hpdf_config.h.cmake: -------------------------------------------------------------------------------- 1 | /* Define to 1 if you have the header file. */ 2 | #cmakedefine LIBHPDF_HAVE_DLFCN_H 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #cmakedefine LIBHPDF_HAVE_INTTYPES_H 6 | 7 | /* Define to 1 if you have the `png' library (-lpng). */ 8 | #cmakedefine LIBHPDF_HAVE_LIBPNG 9 | 10 | /* Define to 1 if you have the `z' library (-lz). */ 11 | #cmakedefine LIBHPDF_HAVE_ZLIB 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #cmakedefine LIBHPDF_HAVE_MEMORY_H 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #cmakedefine LIBHPDF_HAVE_STDINT_H 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #cmakedefine LIBHPDF_HAVE_STDLIB_H 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #cmakedefine LIBHPDF_HAVE_STRINGS_H 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #cmakedefine LIBHPDF_HAVE_STRING_H 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #cmakedefine LIBHPDF_HAVE_SYS_STAT_H 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #cmakedefine LIBHPDF_HAVE_SYS_TYPES_H 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #cmakedefine LIBHPDF_HAVE_UNISTD_H 36 | 37 | /* debug build */ 38 | #cmakedefine LIBHPDF_DEBUG 39 | 40 | /* debug trace enabled */ 41 | #cmakedefine LIBHPDF_DEBUG_TRACE 42 | 43 | /* Define to the address where bug reports for this package should be sent. */ 44 | #cmakedefine LIBHPDF_PACKAGE_BUGREPORT "@LIBHPDF_PACKAGE_BUGREPORT@" 45 | 46 | /* Define to the full name of this package. */ 47 | #cmakedefine LIBHPDF_PACKAGE_NAME "@LIBHPDF_PACKAGE_NAME@" 48 | 49 | /* Define to the full name and version of this package. */ 50 | #cmakedefine LIBHPDF_PACKAGE_STRING "@LIBHPDF_PACKAGE_STRING@" 51 | 52 | /* Define to the one symbol short name of this package. */ 53 | #cmakedefine LIBHPDF_PACKAGE_TARNAME "@LIBHPDF_PACKAGE_TARNAME@" 54 | 55 | /* Define to the version of this package. */ 56 | #cmakedefine LIBHPDF_PACKAGE_VERSION "@LIBHPDF_PACKAGE_VERSION@" 57 | 58 | /* Define to 1 if you have the ANSI C header files. */ 59 | #cmakedefine LIBHPDF_STDC_HEADERS 60 | 61 | /* Define to `unsigned int' if does not define. */ 62 | #cmakedefine LIBHPDF_size_t @LIBHPDF_size_t@ 63 | -------------------------------------------------------------------------------- /libharu/include/hpdf_destination.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_destination.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_DESTINATION_H 19 | #define _HPDF_DESTINATION_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /*----- HPDF_Destination -----------------------------------------------------*/ 29 | 30 | HPDF_Destination 31 | HPDF_Destination_New (HPDF_MMgr mmgr, 32 | HPDF_Page target, 33 | HPDF_Xref xref); 34 | 35 | 36 | HPDF_BOOL 37 | HPDF_Destination_Validate (HPDF_Destination dst); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif /* __cplusplus */ 42 | 43 | #endif /* _HPDF_DESTINATION_H */ 44 | 45 | -------------------------------------------------------------------------------- /libharu/include/hpdf_doc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_doc.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | 19 | #ifndef _HPDF_DOC_H 20 | #define _HPDF_DOC_H 21 | 22 | #define HPDF_SIG_BYTES 0x41504446L 23 | 24 | #include "hpdf_catalog.h" 25 | #include "hpdf_image.h" 26 | #include "hpdf_pages.h" 27 | #include "hpdf_outline.h" 28 | #include "hpdf_ext_gstate.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define HPDF_VER_DEFAULT HPDF_VER_12 35 | 36 | typedef struct _HPDF_Doc_Rec { 37 | HPDF_UINT32 sig_bytes; 38 | HPDF_PDFVer pdf_version; 39 | 40 | HPDF_MMgr mmgr; 41 | HPDF_Catalog catalog; 42 | HPDF_Outline outlines; 43 | HPDF_Xref xref; 44 | HPDF_Pages root_pages; 45 | HPDF_Pages cur_pages; 46 | HPDF_Page cur_page; 47 | HPDF_List page_list; 48 | HPDF_Error_Rec error; 49 | HPDF_Dict info; 50 | HPDF_Dict trailer; 51 | 52 | HPDF_List font_mgr; 53 | HPDF_BYTE ttfont_tag[6]; 54 | 55 | /* list for loaded fontdefs */ 56 | HPDF_List fontdef_list; 57 | 58 | /* list for loaded encodings */ 59 | HPDF_List encoder_list; 60 | 61 | HPDF_Encoder cur_encoder; 62 | 63 | /* default compression mode */ 64 | HPDF_BOOL compression_mode; 65 | 66 | HPDF_BOOL encrypt_on; 67 | HPDF_EncryptDict encrypt_dict; 68 | 69 | HPDF_Encoder def_encoder; 70 | 71 | HPDF_UINT page_per_pages; 72 | HPDF_UINT cur_page_num; 73 | 74 | /* buffer for saving into memory stream */ 75 | HPDF_Stream stream; 76 | } HPDF_Doc_Rec; 77 | 78 | typedef struct _HPDF_Doc_Rec *HPDF_Doc; 79 | 80 | 81 | HPDF_Encoder 82 | HPDF_Doc_FindEncoder (HPDF_Doc pdf, 83 | const char *encoding_name); 84 | 85 | 86 | HPDF_FontDef 87 | HPDF_Doc_FindFontDef (HPDF_Doc pdf, 88 | const char *font_name); 89 | 90 | 91 | HPDF_Font 92 | HPDF_Doc_FindFont (HPDF_Doc pdf, 93 | const char *font_name, 94 | const char *encoding_name); 95 | 96 | 97 | HPDF_BOOL 98 | HPDF_Doc_Validate (HPDF_Doc pdf); 99 | 100 | 101 | /*----- page handling -------------------------------------------------------*/ 102 | 103 | HPDF_Pages 104 | HPDF_Doc_GetCurrentPages (HPDF_Doc pdf); 105 | 106 | 107 | HPDF_Pages 108 | HPDF_Doc_AddPagesTo (HPDF_Doc pdf, 109 | HPDF_Pages parent); 110 | 111 | 112 | HPDF_STATUS 113 | HPDF_Doc_SetCurrentPages (HPDF_Doc pdf, 114 | HPDF_Pages pages); 115 | 116 | 117 | HPDF_STATUS 118 | HPDF_Doc_SetCurrentPage (HPDF_Doc pdf, 119 | HPDF_Page page); 120 | 121 | 122 | 123 | 124 | /*----- font handling -------------------------------------------------------*/ 125 | 126 | HPDF_FontDef 127 | HPDF_GetFontDef (HPDF_Doc pdf, 128 | const char *font_name); 129 | 130 | 131 | HPDF_STATUS 132 | HPDF_Doc_RegisterFontDef (HPDF_Doc pdf, 133 | HPDF_FontDef fontdef); 134 | 135 | 136 | /*----- encoding handling ---------------------------------------------------*/ 137 | 138 | HPDF_STATUS 139 | HPDF_Doc_RegisterEncoder (HPDF_Doc pdf, 140 | HPDF_Encoder encoder); 141 | 142 | 143 | 144 | /*----- encryptio------------------------------------------------------------*/ 145 | 146 | HPDF_STATUS 147 | HPDF_Doc_SetEncryptOn (HPDF_Doc pdf); 148 | 149 | 150 | HPDF_STATUS 151 | HPDF_Doc_SetEncryptOff (HPDF_Doc pdf); 152 | 153 | 154 | HPDF_STATUS 155 | HPDF_Doc_PrepareEncryption (HPDF_Doc pdf); 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif /* __cplusplus */ 160 | 161 | #endif /* _HPDF_DOC_H */ 162 | 163 | -------------------------------------------------------------------------------- /libharu/include/hpdf_encrypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_encrypt.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | *------------------------------------------------------------------------------ 17 | * 18 | * The code implements MD5 message-digest algorithm is based on the code 19 | * written by Colin Plumb. 20 | * The copyright of it is as follows. 21 | * 22 | * This code implements the MD5 message-digest algorithm. 23 | * The algorithm is due to Ron Rivest. This code was 24 | * written by Colin Plumb in 1993, no copyright is claimed. 25 | * This code is in the public domain; do with it what you wish. 26 | * 27 | * Equivalent code is available from RSA Data Security, Inc. 28 | * This code has been tested against that, and is equivalent, 29 | * except that you don't need to include two pages of legalese 30 | * with every copy. 31 | * 32 | * To compute the message digest of a chunk of bytes, declare an 33 | * MD5Context structure, pass it to MD5Init, call MD5Update as 34 | * needed on buffers full of bytes, and then call MD5Final, which 35 | * will fill a supplied 16-byte array with the digest. 36 | * 37 | *---------------------------------------------------------------------------*/ 38 | 39 | #ifndef HPDF_ENCRYPT_H 40 | #define HPDF_ENCRYPT_H 41 | 42 | #include "hpdf_mmgr.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | /*----------------------------------------------------------------------------*/ 49 | /*----- encrypt-dict ---------------------------------------------------------*/ 50 | 51 | #define HPDF_ID_LEN 16 52 | #define HPDF_PASSWD_LEN 32 53 | #define HPDF_ENCRYPT_KEY_MAX 16 54 | #define HPDF_MD5_KEY_LEN 16 55 | #define HPDF_PERMISSION_PAD 0xFFFFFFC0 56 | #define HPDF_ARC4_BUF_SIZE 256 57 | 58 | 59 | typedef struct HPDF_MD5Context 60 | { 61 | HPDF_UINT32 buf[4]; 62 | HPDF_UINT32 bits[2]; 63 | HPDF_BYTE in[64]; 64 | } HPDF_MD5_CTX; 65 | 66 | 67 | typedef struct _HPDF_ARC4_Ctx_Rec { 68 | HPDF_BYTE idx1; 69 | HPDF_BYTE idx2; 70 | HPDF_BYTE state[HPDF_ARC4_BUF_SIZE]; 71 | } HPDF_ARC4_Ctx_Rec; 72 | 73 | 74 | typedef struct _HPDF_Encrypt_Rec *HPDF_Encrypt; 75 | 76 | typedef struct _HPDF_Encrypt_Rec { 77 | HPDF_EncryptMode mode; 78 | 79 | /* key_len must be a multiple of 8, and between 40 to 128 */ 80 | HPDF_UINT key_len; 81 | 82 | /* owner-password (not encrypted) */ 83 | HPDF_BYTE owner_passwd[HPDF_PASSWD_LEN]; 84 | 85 | /* user-password (not encrypted) */ 86 | HPDF_BYTE user_passwd[HPDF_PASSWD_LEN]; 87 | 88 | /* owner-password (encrypted) */ 89 | HPDF_BYTE owner_key[HPDF_PASSWD_LEN]; 90 | 91 | /* user-password (encrypted) */ 92 | HPDF_BYTE user_key[HPDF_PASSWD_LEN]; 93 | 94 | HPDF_INT permission; 95 | HPDF_BYTE encrypt_id[HPDF_ID_LEN]; 96 | HPDF_BYTE encryption_key[HPDF_MD5_KEY_LEN + 5]; 97 | HPDF_BYTE md5_encryption_key[HPDF_MD5_KEY_LEN]; 98 | HPDF_ARC4_Ctx_Rec arc4ctx; 99 | } HPDF_Encrypt_Rec; 100 | 101 | 102 | void 103 | HPDF_MD5Init (struct HPDF_MD5Context *ctx); 104 | 105 | 106 | void 107 | HPDF_MD5Update (struct HPDF_MD5Context *ctx, 108 | const HPDF_BYTE *buf, 109 | HPDF_UINT32 len); 110 | 111 | 112 | void 113 | HPDF_MD5Final (HPDF_BYTE digest[16], 114 | struct HPDF_MD5Context *ctx); 115 | 116 | void 117 | HPDF_PadOrTrancatePasswd (const char *pwd, 118 | HPDF_BYTE *new_pwd); 119 | 120 | 121 | void 122 | HPDF_Encrypt_Init (HPDF_Encrypt attr); 123 | 124 | 125 | void 126 | HPDF_Encrypt_CreateUserKey (HPDF_Encrypt attr); 127 | 128 | 129 | void 130 | HPDF_Encrypt_CreateOwnerKey (HPDF_Encrypt attr); 131 | 132 | 133 | void 134 | HPDF_Encrypt_CreateEncryptionKey (HPDF_Encrypt attr); 135 | 136 | 137 | void 138 | HPDF_Encrypt_InitKey (HPDF_Encrypt attr, 139 | HPDF_UINT32 object_id, 140 | HPDF_UINT16 gen_no); 141 | 142 | 143 | void 144 | HPDF_Encrypt_Reset (HPDF_Encrypt attr); 145 | 146 | 147 | void 148 | HPDF_Encrypt_CryptBuf (HPDF_Encrypt attr, 149 | const HPDF_BYTE *src, 150 | HPDF_BYTE *dst, 151 | HPDF_UINT len); 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif /* __cplusplus */ 156 | 157 | #endif /* _HPDF_ENCRYPT_H */ 158 | 159 | 160 | -------------------------------------------------------------------------------- /libharu/include/hpdf_encryptdict.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_encryptdict.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_ENCRYPTDICT_H 19 | #define _HPDF_ENCRYPTDICT_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*---------------------------------------------------------------------------*/ 28 | /*------ HPDF_EncryptDict ---------------------------------------------------*/ 29 | 30 | HPDF_EncryptDict 31 | HPDF_EncryptDict_New (HPDF_MMgr mmgr, 32 | HPDF_Xref xref); 33 | 34 | 35 | void 36 | HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict, 37 | HPDF_Dict info, 38 | HPDF_Xref xref); 39 | 40 | 41 | void 42 | HPDF_EncryptDict_OnFree (HPDF_Dict obj); 43 | 44 | 45 | HPDF_STATUS 46 | HPDF_EncryptDict_SetPassword (HPDF_EncryptDict dict, 47 | const char *owner_passwd, 48 | const char *user_passwd); 49 | 50 | 51 | HPDF_BOOL 52 | HPDF_EncryptDict_Validate (HPDF_EncryptDict dict); 53 | 54 | 55 | HPDF_STATUS 56 | HPDF_EncryptDict_Prepare (HPDF_EncryptDict dict, 57 | HPDF_Dict info, 58 | HPDF_Xref xref); 59 | 60 | 61 | HPDF_Encrypt 62 | HPDF_EncryptDict_GetAttr (HPDF_EncryptDict dict); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif /* __cplusplus */ 67 | 68 | #endif /* _HPDF_ENCRYPTDICT_H */ 69 | 70 | -------------------------------------------------------------------------------- /libharu/include/hpdf_exdata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_annotation.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_EXDATA_H 19 | #define _HPDF_EXDATA_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /*------ HPDF_ExData -----------------------------------------------------*/ 29 | 30 | HPDF_ExData 31 | HPDF_3DAnnotExData_New(HPDF_MMgr mmgr, 32 | HPDF_Xref xref ); 33 | 34 | 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /* __cplusplus */ 39 | 40 | #endif /* _HPDF_EXDATA_H */ 41 | 42 | -------------------------------------------------------------------------------- /libharu/include/hpdf_ext_gstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_ext_gstate.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_EXT_GSTATE_H 19 | #define _HPDF_EXT_GSTATE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | HPDF_Dict 28 | HPDF_ExtGState_New (HPDF_MMgr mmgr, 29 | HPDF_Xref xref); 30 | 31 | 32 | HPDF_BOOL 33 | HPDF_ExtGState_Validate (HPDF_ExtGState ext_gstate); 34 | 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /* __cplusplus */ 39 | 40 | #endif /* _HPDF_EXT_GSTATE_H */ 41 | 42 | -------------------------------------------------------------------------------- /libharu/include/hpdf_font.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_font.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_FONT_H 19 | #define _HPDF_FONT_H 20 | 21 | #include "hpdf_fontdef.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*----- Writing Mode ---------------------------------------------------------*/ 30 | 31 | typedef enum _HPDF_FontType { 32 | HPDF_FONT_TYPE1 = 0, 33 | HPDF_FONT_TRUETYPE, 34 | HPDF_FONT_TYPE3, 35 | HPDF_FONT_TYPE0_CID, 36 | HPDF_FONT_TYPE0_TT, 37 | HPDF_FONT_CID_TYPE0, 38 | HPDF_FONT_CID_TYPE2, 39 | HPDF_FONT_MMTYPE1 40 | } HPDF_FontType; 41 | 42 | 43 | typedef HPDF_Dict HPDF_Font; 44 | 45 | 46 | typedef HPDF_TextWidth 47 | (*HPDF_Font_TextWidths_Func) (HPDF_Font font, 48 | const HPDF_BYTE *text, 49 | HPDF_UINT len); 50 | 51 | 52 | typedef HPDF_UINT 53 | (*HPDF_Font_MeasureText_Func) (HPDF_Font font, 54 | const HPDF_BYTE *text, 55 | HPDF_UINT len, 56 | HPDF_REAL width, 57 | HPDF_REAL fontsize, 58 | HPDF_REAL charspace, 59 | HPDF_REAL wordspace, 60 | HPDF_BOOL wordwrap, 61 | HPDF_REAL *real_width); 62 | 63 | 64 | typedef struct _HPDF_FontAttr_Rec *HPDF_FontAttr; 65 | 66 | typedef struct _HPDF_FontAttr_Rec { 67 | HPDF_FontType type; 68 | HPDF_WritingMode writing_mode; 69 | HPDF_Font_TextWidths_Func text_width_fn; 70 | HPDF_Font_MeasureText_Func measure_text_fn; 71 | HPDF_FontDef fontdef; 72 | HPDF_Encoder encoder; 73 | 74 | /* if the encoding-type is HPDF_ENCODER_TYPE_SINGLE_BYTE, the width of 75 | * each characters are cashed in 'widths'. 76 | * when HPDF_ENCODER_TYPE_DOUBLE_BYTE the width is calculate each time. 77 | */ 78 | HPDF_INT16* widths; 79 | HPDF_BYTE* used; 80 | 81 | HPDF_Xref xref; 82 | HPDF_Font descendant_font; 83 | HPDF_Dict map_stream; 84 | HPDF_Dict cmap_stream; 85 | } HPDF_FontAttr_Rec; 86 | 87 | 88 | HPDF_Font 89 | HPDF_Type1Font_New (HPDF_MMgr mmgr, 90 | HPDF_FontDef fontdef, 91 | HPDF_Encoder encoder, 92 | HPDF_Xref xref); 93 | 94 | HPDF_Font 95 | HPDF_TTFont_New (HPDF_MMgr mmgr, 96 | HPDF_FontDef fontdef, 97 | HPDF_Encoder encoder, 98 | HPDF_Xref xref); 99 | 100 | HPDF_Font 101 | HPDF_Type0Font_New (HPDF_MMgr mmgr, 102 | HPDF_FontDef fontdef, 103 | HPDF_Encoder encoder, 104 | HPDF_Xref xref); 105 | 106 | 107 | HPDF_BOOL 108 | HPDF_Font_Validate (HPDF_Font font); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif /* __cplusplus */ 113 | 114 | #endif /* _HPDF_FONT_H */ 115 | 116 | -------------------------------------------------------------------------------- /libharu/include/hpdf_gstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_gstate.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_GSTATE_H 19 | #define _HPDF_GSTATE_H 20 | 21 | #include "hpdf_font.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*------ graphic state stack -------------------------------------------------*/ 30 | 31 | typedef struct _HPDF_GState_Rec *HPDF_GState; 32 | 33 | typedef struct _HPDF_GState_Rec { 34 | HPDF_TransMatrix trans_matrix; 35 | HPDF_REAL line_width; 36 | HPDF_LineCap line_cap; 37 | HPDF_LineJoin line_join; 38 | HPDF_REAL miter_limit; 39 | HPDF_DashMode dash_mode; 40 | HPDF_REAL flatness; 41 | 42 | HPDF_REAL char_space; 43 | HPDF_REAL word_space; 44 | HPDF_REAL h_scalling; 45 | HPDF_REAL text_leading; 46 | HPDF_TextRenderingMode rendering_mode; 47 | HPDF_REAL text_rise; 48 | 49 | HPDF_ColorSpace cs_fill; 50 | HPDF_ColorSpace cs_stroke; 51 | HPDF_RGBColor rgb_fill; 52 | HPDF_RGBColor rgb_stroke; 53 | HPDF_CMYKColor cmyk_fill; 54 | HPDF_CMYKColor cmyk_stroke; 55 | HPDF_REAL gray_fill; 56 | HPDF_REAL gray_stroke; 57 | 58 | HPDF_Font font; 59 | HPDF_REAL font_size; 60 | HPDF_WritingMode writing_mode; 61 | 62 | HPDF_GState prev; 63 | HPDF_UINT depth; 64 | } HPDF_GState_Rec; 65 | 66 | /*----------------------------------------------------------------------------*/ 67 | /*----------------------------------------------------------------------------*/ 68 | 69 | HPDF_GState 70 | HPDF_GState_New (HPDF_MMgr mmgr, 71 | HPDF_GState current); 72 | 73 | 74 | HPDF_GState 75 | HPDF_GState_Free (HPDF_MMgr mmgr, 76 | HPDF_GState gstate); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif /* __cplusplus */ 81 | 82 | #endif /* _HPDF_GSTATE_H */ 83 | 84 | -------------------------------------------------------------------------------- /libharu/include/hpdf_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_image.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_IMAGE_H 19 | #define _HPDF_IMAGE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | HPDF_Image 28 | HPDF_Image_Load1BitImageFromMem (HPDF_MMgr mmgr, 29 | const HPDF_BYTE *buf, 30 | HPDF_Xref xref, 31 | HPDF_UINT width, 32 | HPDF_UINT height, 33 | HPDF_UINT line_width, 34 | HPDF_BOOL top_is_first 35 | ); 36 | 37 | 38 | #ifdef LIBHPDF_HAVE_LIBPNG 39 | 40 | HPDF_Image 41 | HPDF_Image_LoadPngImage (HPDF_MMgr mmgr, 42 | HPDF_Stream png_data, 43 | HPDF_Xref xref, 44 | HPDF_BOOL delayed_loading); 45 | 46 | #endif 47 | 48 | HPDF_Image 49 | HPDF_Image_LoadJpegImage (HPDF_MMgr mmgr, 50 | HPDF_Stream jpeg_data, 51 | HPDF_Xref xref); 52 | 53 | HPDF_Image 54 | HPDF_Image_LoadJpegImageFromMem (HPDF_MMgr mmgr, 55 | const HPDF_BYTE *buf, 56 | HPDF_UINT size, 57 | HPDF_Xref xref); 58 | 59 | HPDF_Image 60 | HPDF_Image_LoadRawImage (HPDF_MMgr mmgr, 61 | HPDF_Stream stream, 62 | HPDF_Xref xref, 63 | HPDF_UINT width, 64 | HPDF_UINT height, 65 | HPDF_ColorSpace color_space); 66 | 67 | 68 | HPDF_Image 69 | HPDF_Image_LoadRawImageFromMem (HPDF_MMgr mmgr, 70 | const HPDF_BYTE *buf, 71 | HPDF_Xref xref, 72 | HPDF_UINT width, 73 | HPDF_UINT height, 74 | HPDF_ColorSpace color_space, 75 | HPDF_UINT bits_per_component); 76 | 77 | 78 | HPDF_BOOL 79 | HPDF_Image_Validate (HPDF_Image image); 80 | 81 | 82 | HPDF_STATUS 83 | HPDF_Image_SetMask (HPDF_Image image, 84 | HPDF_BOOL mask); 85 | 86 | HPDF_STATUS 87 | HPDF_Image_SetColorSpace (HPDF_Image image, 88 | HPDF_Array colorspace); 89 | 90 | HPDF_STATUS 91 | HPDF_Image_SetRenderingIntent (HPDF_Image image, 92 | const char* intent); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif /* __cplusplus */ 97 | 98 | #endif /* _HPDF_XOBJECTS_H */ 99 | 100 | -------------------------------------------------------------------------------- /libharu/include/hpdf_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_info.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | 19 | #ifndef _HPDF_INFO_H 20 | #define _HPDF_INFO_H 21 | 22 | #include "hpdf_objects.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | HPDF_STATUS 30 | HPDF_Info_SetInfoAttr (HPDF_Dict info, 31 | HPDF_InfoType type, 32 | const char *value, 33 | HPDF_Encoder encoder); 34 | 35 | 36 | const char* 37 | HPDF_Info_GetInfoAttr (HPDF_Dict info, 38 | HPDF_InfoType type); 39 | 40 | 41 | HPDF_STATUS 42 | HPDF_Info_SetInfoDateAttr (HPDF_Dict info, 43 | HPDF_InfoType type, 44 | HPDF_Date value); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif /* __cplusplus */ 49 | 50 | #endif /* _HPDF_INFO_H */ 51 | 52 | -------------------------------------------------------------------------------- /libharu/include/hpdf_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_list.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_LIST_H 19 | #define _HPDF_LIST_H 20 | 21 | #include "hpdf_error.h" 22 | #include "hpdf_mmgr.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef struct _HPDF_List_Rec *HPDF_List; 29 | 30 | typedef struct _HPDF_List_Rec { 31 | HPDF_MMgr mmgr; 32 | HPDF_Error error; 33 | HPDF_UINT block_siz; 34 | HPDF_UINT items_per_block; 35 | HPDF_UINT count; 36 | void **obj; 37 | } HPDF_List_Rec; 38 | 39 | 40 | HPDF_List 41 | HPDF_List_New (HPDF_MMgr mmgr, 42 | HPDF_UINT items_per_block); 43 | 44 | 45 | void 46 | HPDF_List_Free (HPDF_List list); 47 | 48 | 49 | HPDF_STATUS 50 | HPDF_List_Add (HPDF_List list, 51 | void *item); 52 | 53 | 54 | HPDF_STATUS 55 | HPDF_List_Insert (HPDF_List list, 56 | void *target, 57 | void *item); 58 | 59 | 60 | HPDF_STATUS 61 | HPDF_List_Remove (HPDF_List list, 62 | void *item); 63 | 64 | 65 | void* 66 | HPDF_List_RemoveByIndex (HPDF_List list, 67 | HPDF_UINT index); 68 | 69 | 70 | void* 71 | HPDF_List_ItemAt (HPDF_List list, 72 | HPDF_UINT index); 73 | 74 | 75 | HPDF_INT32 76 | HPDF_List_Find (HPDF_List list, 77 | void *item); 78 | 79 | 80 | void 81 | HPDF_List_Clear (HPDF_List list); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif /* __cplusplus */ 86 | 87 | #endif /* _HPDF_LIST_H */ 88 | 89 | -------------------------------------------------------------------------------- /libharu/include/hpdf_mmgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_mmgr.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_MMGR_H 19 | #define _HPDF_MMGR_H 20 | 21 | #include "hpdf_types.h" 22 | #include "hpdf_error.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef struct _HPDF_MPool_Node_Rec *HPDF_MPool_Node; 29 | 30 | typedef struct _HPDF_MPool_Node_Rec { 31 | HPDF_BYTE* buf; 32 | HPDF_UINT size; 33 | HPDF_UINT used_size; 34 | HPDF_MPool_Node next_node; 35 | } HPDF_MPool_Node_Rec; 36 | 37 | 38 | typedef struct _HPDF_MMgr_Rec *HPDF_MMgr; 39 | 40 | typedef struct _HPDF_MMgr_Rec { 41 | HPDF_Error error; 42 | HPDF_Alloc_Func alloc_fn; 43 | HPDF_Free_Func free_fn; 44 | HPDF_MPool_Node mpool; 45 | HPDF_UINT buf_size; 46 | 47 | #ifdef HPDF_MEM_DEBUG 48 | HPDF_UINT alloc_cnt; 49 | HPDF_UINT free_cnt; 50 | #endif 51 | } HPDF_MMgr_Rec; 52 | 53 | 54 | /* HPDF_mpool_new 55 | * 56 | * create new HPDF_mpool object. when memory allocation goes wrong, 57 | * it returns NULL and error handling function will be called. 58 | * if buf_size is non-zero, mmgr is configured to be using memory-pool 59 | */ 60 | HPDF_MMgr 61 | HPDF_MMgr_New (HPDF_Error error, 62 | HPDF_UINT buf_size, 63 | HPDF_Alloc_Func alloc_fn, 64 | HPDF_Free_Func free_fn); 65 | 66 | 67 | void 68 | HPDF_MMgr_Free (HPDF_MMgr mmgr); 69 | 70 | 71 | void* 72 | HPDF_GetMem (HPDF_MMgr mmgr, 73 | HPDF_UINT size); 74 | 75 | 76 | void 77 | HPDF_FreeMem (HPDF_MMgr mmgr, 78 | void *aptr); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif /* __cplusplus */ 83 | 84 | #endif /* _HPDF_MMGR_H */ 85 | 86 | -------------------------------------------------------------------------------- /libharu/include/hpdf_namedict.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_namedict.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_NAMEDICT_H 19 | #define _HPDF_NAMEDICT_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | HPDF_NameDict 29 | HPDF_NameDict_New (HPDF_MMgr mmgr, 30 | HPDF_Xref xref); 31 | 32 | HPDF_NameTree 33 | HPDF_NameDict_GetNameTree (HPDF_NameDict namedict, 34 | HPDF_NameDictKey key); 35 | 36 | HPDF_STATUS 37 | HPDF_NameDict_SetNameTree (HPDF_NameDict namedict, 38 | HPDF_NameDictKey key, 39 | HPDF_NameTree tree); 40 | 41 | HPDF_BOOL 42 | HPDF_NameDict_Validate (HPDF_NameDict namedict); 43 | 44 | 45 | /*------- NameTree -------*/ 46 | 47 | HPDF_NameTree 48 | HPDF_NameTree_New (HPDF_MMgr mmgr, 49 | HPDF_Xref xref); 50 | 51 | HPDF_STATUS 52 | HPDF_NameTree_Add (HPDF_NameTree tree, 53 | HPDF_String name, 54 | void *obj); 55 | 56 | HPDF_BOOL 57 | HPDF_NameTree_Validate (HPDF_NameTree tree); 58 | 59 | 60 | /*------- EmbeddedFile -------*/ 61 | 62 | HPDF_EmbeddedFile 63 | HPDF_EmbeddedFile_New (HPDF_MMgr mmgr, 64 | HPDF_Xref xref, 65 | const char *file); 66 | 67 | HPDF_BOOL 68 | HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile); 69 | 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif /* __cplusplus */ 74 | 75 | #endif /* _HPDF_NAMEDICT_H */ 76 | 77 | -------------------------------------------------------------------------------- /libharu/include/hpdf_outline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_outline.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_OUTLINE_H 19 | #define _HPDF_OUTLINE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*----- HPDF_Outline ---------------------------------------------------------*/ 30 | 31 | HPDF_Outline 32 | HPDF_OutlineRoot_New (HPDF_MMgr mmgr, 33 | HPDF_Xref xref); 34 | 35 | 36 | HPDF_Outline 37 | HPDF_Outline_New (HPDF_MMgr mmgr, 38 | HPDF_Outline parent, 39 | const char *title, 40 | HPDF_Encoder encoder, 41 | HPDF_Xref xref); 42 | 43 | 44 | HPDF_Outline 45 | HPDF_Outline_GetFirst (HPDF_Outline outline); 46 | 47 | 48 | HPDF_Outline 49 | HPDF_Outline_GetLast (HPDF_Outline outline); 50 | 51 | 52 | HPDF_Outline 53 | HPDF_Outline_GetPrev(HPDF_Outline outline); 54 | 55 | 56 | HPDF_Outline 57 | HPDF_Outline_GetNext (HPDF_Outline outline); 58 | 59 | 60 | HPDF_Outline 61 | HPDF_Outline_GetParent (HPDF_Outline outline); 62 | 63 | 64 | HPDF_BOOL 65 | HPDF_Outline_GetOpened (HPDF_Outline outline); 66 | 67 | 68 | 69 | HPDF_BOOL 70 | HPDF_Outline_Validate (HPDF_Outline obj); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif /* __cplusplus */ 75 | 76 | #endif /* _HPDF_OUTLINE_H */ 77 | 78 | -------------------------------------------------------------------------------- /libharu/include/hpdf_page_label.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_page_label.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_PAGE_LABEL_H 19 | #define _HPDF_PAGE_LABEL_H 20 | 21 | #include "hpdf.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | HPDF_Dict 28 | HPDF_PageLabel_New (HPDF_Doc pdf, 29 | HPDF_PageNumStyle style, 30 | HPDF_INT first_page, 31 | const char *prefix); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /* __cplusplus */ 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /libharu/include/hpdf_pages.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_pages.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_PAGES_H 19 | #define _HPDF_PAGES_H 20 | 21 | #include "hpdf_gstate.h" 22 | #include "hpdf_ext_gstate.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*----- HPDF_Pages -----------------------------------------------------------*/ 30 | 31 | HPDF_Pages 32 | HPDF_Pages_New (HPDF_MMgr mmgr, 33 | HPDF_Pages parent, 34 | HPDF_Xref xref); 35 | 36 | 37 | HPDF_BOOL 38 | HPDF_Pages_Validate (HPDF_Pages pages); 39 | 40 | 41 | HPDF_STATUS 42 | HPDF_Pages_AddKids (HPDF_Pages parent, 43 | HPDF_Dict kid); 44 | 45 | 46 | HPDF_STATUS 47 | HPDF_Page_InsertBefore (HPDF_Page page, 48 | HPDF_Page target); 49 | 50 | 51 | typedef struct _HPDF_PageAttr_Rec *HPDF_PageAttr; 52 | 53 | typedef struct _HPDF_PageAttr_Rec { 54 | HPDF_Pages parent; 55 | HPDF_Dict fonts; 56 | HPDF_Dict xobjects; 57 | HPDF_Dict ext_gstates; 58 | HPDF_Dict shadings; 59 | HPDF_GState gstate; 60 | HPDF_Point str_pos; 61 | HPDF_Point cur_pos; 62 | HPDF_Point text_pos; 63 | HPDF_TransMatrix text_matrix; 64 | HPDF_UINT16 gmode; 65 | HPDF_Dict contents; 66 | HPDF_Stream stream; 67 | HPDF_Xref xref; 68 | HPDF_UINT compression_mode; 69 | HPDF_PDFVer *ver; 70 | } HPDF_PageAttr_Rec; 71 | 72 | 73 | /*----------------------------------------------------------------------------*/ 74 | /*----- HPDF_Page ------------------------------------------------------------*/ 75 | 76 | HPDF_BOOL 77 | HPDF_Page_Validate (HPDF_Page page); 78 | 79 | 80 | HPDF_Page 81 | HPDF_Page_New (HPDF_MMgr mmgr, 82 | HPDF_Xref xref); 83 | 84 | 85 | void* 86 | HPDF_Page_GetInheritableItem (HPDF_Page page, 87 | const char *key, 88 | HPDF_UINT16 obj_class); 89 | 90 | 91 | const char* 92 | HPDF_Page_GetXObjectName (HPDF_Page page, 93 | HPDF_XObject xobj); 94 | 95 | 96 | const char* 97 | HPDF_Page_GetLocalFontName (HPDF_Page page, 98 | HPDF_Font font); 99 | 100 | 101 | const char* 102 | HPDF_Page_GetExtGStateName (HPDF_Page page, 103 | HPDF_ExtGState gstate); 104 | 105 | const char* 106 | HPDF_Page_GetShadingName (HPDF_Page page, 107 | HPDF_Shading shading); 108 | 109 | 110 | HPDF_Box 111 | HPDF_Page_GetMediaBox (HPDF_Page page); 112 | 113 | 114 | HPDF_STATUS 115 | HPDF_Page_SetBoxValue (HPDF_Page page, 116 | const char *name, 117 | HPDF_UINT index, 118 | HPDF_REAL value); 119 | 120 | 121 | void 122 | HPDF_Page_SetFilter (HPDF_Page page, 123 | HPDF_UINT filter); 124 | 125 | 126 | HPDF_STATUS 127 | HPDF_Page_CheckState (HPDF_Page page, 128 | HPDF_UINT mode); 129 | 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif /* __cplusplus */ 134 | 135 | #endif /* _HPDF_PAGES_H */ 136 | 137 | -------------------------------------------------------------------------------- /libharu/include/hpdf_pdfa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_pdfa.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_PDFA_H 19 | #define _HPDF_PDFA_H 20 | 21 | #include "hpdf_doc.h" 22 | #include "hpdf_objects.h" 23 | 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | HPDF_STATUS 31 | HPDF_PDFA_AppendOutputIntents(HPDF_Doc pdf, const char *iccname, HPDF_Dict iccdict); 32 | 33 | HPDF_STATUS 34 | HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf, 35 | HPDF_PDFAType pdfatype); 36 | 37 | HPDF_STATUS 38 | HPDF_PDFA_GenerateID(HPDF_Doc); 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /libharu/include/hpdf_streams.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_streams.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | * 2005.12.20 Created. 17 | * 18 | */ 19 | 20 | #ifndef _HPDF_STREAMS_H 21 | #define _HPDF_STREAMS_H 22 | 23 | #include "hpdf_list.h" 24 | #include "hpdf_encrypt.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | #define HPDF_STREAM_SIG_BYTES 0x5354524DL 32 | 33 | typedef enum _HPDF_StreamType { 34 | HPDF_STREAM_UNKNOWN = 0, 35 | HPDF_STREAM_CALLBACK, 36 | HPDF_STREAM_FILE, 37 | HPDF_STREAM_MEMORY 38 | } HPDF_StreamType; 39 | 40 | #define HPDF_STREAM_FILTER_NONE 0x0000 41 | #define HPDF_STREAM_FILTER_ASCIIHEX 0x0100 42 | #define HPDF_STREAM_FILTER_ASCII85 0x0200 43 | #define HPDF_STREAM_FILTER_FLATE_DECODE 0x0400 44 | #define HPDF_STREAM_FILTER_DCT_DECODE 0x0800 45 | #define HPDF_STREAM_FILTER_CCITT_DECODE 0x1000 46 | 47 | typedef enum _HPDF_WhenceMode { 48 | HPDF_SEEK_SET = 0, 49 | HPDF_SEEK_CUR, 50 | HPDF_SEEK_END 51 | } HPDF_WhenceMode; 52 | 53 | typedef struct _HPDF_Stream_Rec *HPDF_Stream; 54 | 55 | typedef HPDF_STATUS 56 | (*HPDF_Stream_Write_Func) (HPDF_Stream stream, 57 | const HPDF_BYTE *ptr, 58 | HPDF_UINT siz); 59 | 60 | 61 | typedef HPDF_STATUS 62 | (*HPDF_Stream_Read_Func) (HPDF_Stream stream, 63 | HPDF_BYTE *ptr, 64 | HPDF_UINT *siz); 65 | 66 | 67 | typedef HPDF_STATUS 68 | (*HPDF_Stream_Seek_Func) (HPDF_Stream stream, 69 | HPDF_INT pos, 70 | HPDF_WhenceMode mode); 71 | 72 | 73 | typedef HPDF_INT32 74 | (*HPDF_Stream_Tell_Func) (HPDF_Stream stream); 75 | 76 | 77 | typedef void 78 | (*HPDF_Stream_Free_Func) (HPDF_Stream stream); 79 | 80 | 81 | typedef HPDF_UINT32 82 | (*HPDF_Stream_Size_Func) (HPDF_Stream stream); 83 | 84 | 85 | typedef struct _HPDF_MemStreamAttr_Rec *HPDF_MemStreamAttr; 86 | 87 | 88 | typedef struct _HPDF_MemStreamAttr_Rec { 89 | HPDF_List buf; 90 | HPDF_UINT buf_siz; 91 | HPDF_UINT w_pos; 92 | HPDF_BYTE *w_ptr; 93 | HPDF_UINT r_ptr_idx; 94 | HPDF_UINT r_pos; 95 | HPDF_BYTE *r_ptr; 96 | } HPDF_MemStreamAttr_Rec; 97 | 98 | 99 | typedef struct _HPDF_Stream_Rec { 100 | HPDF_UINT32 sig_bytes; 101 | HPDF_StreamType type; 102 | HPDF_MMgr mmgr; 103 | HPDF_Error error; 104 | HPDF_UINT size; 105 | HPDF_Stream_Write_Func write_fn; 106 | HPDF_Stream_Read_Func read_fn; 107 | HPDF_Stream_Seek_Func seek_fn; 108 | HPDF_Stream_Free_Func free_fn; 109 | HPDF_Stream_Tell_Func tell_fn; 110 | HPDF_Stream_Size_Func size_fn; 111 | void* attr; 112 | } HPDF_Stream_Rec; 113 | 114 | 115 | 116 | HPDF_Stream 117 | HPDF_MemStream_New (HPDF_MMgr mmgr, 118 | HPDF_UINT buf_siz); 119 | 120 | 121 | HPDF_BYTE* 122 | HPDF_MemStream_GetBufPtr (HPDF_Stream stream, 123 | HPDF_UINT index, 124 | HPDF_UINT *length); 125 | 126 | 127 | HPDF_UINT 128 | HPDF_MemStream_GetBufSize (HPDF_Stream stream); 129 | 130 | 131 | HPDF_UINT 132 | HPDF_MemStream_GetBufCount (HPDF_Stream stream); 133 | 134 | 135 | HPDF_STATUS 136 | HPDF_MemStream_Rewrite (HPDF_Stream stream, 137 | HPDF_BYTE *buf, 138 | HPDF_UINT size); 139 | 140 | 141 | void 142 | HPDF_MemStream_FreeData (HPDF_Stream stream); 143 | 144 | 145 | HPDF_STATUS 146 | HPDF_Stream_WriteToStream (HPDF_Stream src, 147 | HPDF_Stream dst, 148 | HPDF_UINT filter, 149 | HPDF_Encrypt e); 150 | 151 | 152 | HPDF_Stream 153 | HPDF_FileReader_New (HPDF_MMgr mmgr, 154 | const char *fname); 155 | 156 | 157 | HPDF_Stream 158 | HPDF_FileWriter_New (HPDF_MMgr mmgr, 159 | const char *fname); 160 | 161 | 162 | HPDF_Stream 163 | HPDF_CallbackReader_New (HPDF_MMgr mmgr, 164 | HPDF_Stream_Read_Func read_fn, 165 | HPDF_Stream_Seek_Func seek_fn, 166 | HPDF_Stream_Tell_Func tell_fn, 167 | HPDF_Stream_Size_Func size_fn, 168 | void* data); 169 | 170 | 171 | HPDF_Stream 172 | HPDF_CallbackWriter_New (HPDF_MMgr mmgr, 173 | HPDF_Stream_Write_Func write_fn, 174 | void* data); 175 | 176 | 177 | void 178 | HPDF_Stream_Free (HPDF_Stream stream); 179 | 180 | 181 | HPDF_STATUS 182 | HPDF_Stream_WriteChar (HPDF_Stream stream, 183 | char value); 184 | 185 | 186 | HPDF_STATUS 187 | HPDF_Stream_WriteStr (HPDF_Stream stream, 188 | const char *value); 189 | 190 | 191 | HPDF_STATUS 192 | HPDF_Stream_WriteUChar (HPDF_Stream stream, 193 | HPDF_BYTE value); 194 | 195 | 196 | HPDF_STATUS 197 | HPDF_Stream_WriteInt (HPDF_Stream stream, 198 | HPDF_INT value); 199 | 200 | 201 | HPDF_STATUS 202 | HPDF_Stream_WriteUInt (HPDF_Stream stream, 203 | HPDF_UINT value); 204 | 205 | 206 | HPDF_STATUS 207 | HPDF_Stream_WriteReal (HPDF_Stream stream, 208 | HPDF_REAL value); 209 | 210 | 211 | HPDF_STATUS 212 | HPDF_Stream_Write (HPDF_Stream stream, 213 | const HPDF_BYTE *ptr, 214 | HPDF_UINT size); 215 | 216 | 217 | HPDF_STATUS 218 | HPDF_Stream_Read (HPDF_Stream stream, 219 | HPDF_BYTE *ptr, 220 | HPDF_UINT *size); 221 | 222 | HPDF_STATUS 223 | HPDF_Stream_ReadLn (HPDF_Stream stream, 224 | char *s, 225 | HPDF_UINT *size); 226 | 227 | 228 | HPDF_INT32 229 | HPDF_Stream_Tell (HPDF_Stream stream); 230 | 231 | 232 | HPDF_STATUS 233 | HPDF_Stream_Seek (HPDF_Stream stream, 234 | HPDF_INT pos, 235 | HPDF_WhenceMode mode); 236 | 237 | 238 | HPDF_BOOL 239 | HPDF_Stream_EOF (HPDF_Stream stream); 240 | 241 | 242 | HPDF_UINT32 243 | HPDF_Stream_Size (HPDF_Stream stream); 244 | 245 | HPDF_STATUS 246 | HPDF_Stream_Flush (HPDF_Stream stream); 247 | 248 | 249 | HPDF_STATUS 250 | HPDF_Stream_WriteEscapeName (HPDF_Stream stream, 251 | const char *value); 252 | 253 | 254 | HPDF_STATUS 255 | HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream, 256 | const char *text, 257 | HPDF_UINT len); 258 | 259 | 260 | HPDF_STATUS 261 | HPDF_Stream_WriteEscapeText (HPDF_Stream stream, 262 | const char *text); 263 | 264 | 265 | HPDF_STATUS 266 | HPDF_Stream_WriteBinary (HPDF_Stream stream, 267 | const HPDF_BYTE *data, 268 | HPDF_UINT len, 269 | HPDF_Encrypt e); 270 | 271 | 272 | HPDF_STATUS 273 | HPDF_Stream_Validate (HPDF_Stream stream); 274 | 275 | 276 | #ifdef __cplusplus 277 | } 278 | #endif /* __cplusplus */ 279 | 280 | #endif /* _HPDF_STREAMS_H */ 281 | -------------------------------------------------------------------------------- /libharu/include/hpdf_u3d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_u3d.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_U3D_H 19 | #define _HPDF_U3D_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | HPDF_EXPORT(HPDF_JavaScript) HPDF_CreateJavaScript(HPDF_Doc pdf, const char *code); 28 | HPDF_EXPORT(HPDF_JavaScript) HPDF_LoadJSFromFile (HPDF_Doc pdf, const char *filename); 29 | 30 | 31 | HPDF_EXPORT(HPDF_U3D) HPDF_LoadU3DFromFile (HPDF_Doc pdf, const char *filename); 32 | HPDF_EXPORT(HPDF_Image) HPDF_LoadU3DFromMem (HPDF_Doc pdf, const HPDF_BYTE *buffer, HPDF_UINT size); 33 | HPDF_EXPORT(HPDF_Dict) HPDF_Create3DView (HPDF_MMgr mmgr, const char *name); 34 | HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_Add3DView(HPDF_U3D u3d, HPDF_Dict view); 35 | HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_SetDefault3DView(HPDF_U3D u3d, const char *name); 36 | HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_AddOnInstanciate(HPDF_U3D u3d, HPDF_JavaScript javaScript); 37 | HPDF_EXPORT(HPDF_Dict) HPDF_3DView_CreateNode(HPDF_Dict view, const char *name); 38 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DViewNode_SetOpacity(HPDF_Dict node, HPDF_REAL opacity); 39 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DViewNode_SetVisibility(HPDF_Dict node, HPDF_BOOL visible); 40 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DViewNode_SetMatrix(HPDF_Dict node, HPDF_3DMatrix Mat3D); 41 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_AddNode(HPDF_Dict view, HPDF_Dict node); 42 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetLighting(HPDF_Dict view, const char *scheme); 43 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetBackgroundColor(HPDF_Dict view, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b); 44 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetPerspectiveProjection(HPDF_Dict view, HPDF_REAL fov); 45 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetOrthogonalProjection(HPDF_Dict view, HPDF_REAL mag); 46 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCamera(HPDF_Dict view, HPDF_REAL coox, HPDF_REAL cooy, HPDF_REAL cooz, HPDF_REAL c2cx, HPDF_REAL c2cy, HPDF_REAL c2cz, HPDF_REAL roo, HPDF_REAL roll); 47 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCameraByMatrix(HPDF_Dict view, HPDF_3DMatrix Mat3D, HPDF_REAL co); 48 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCrossSectionOn(HPDF_Dict view, HPDF_Point3D center, HPDF_REAL Roll, HPDF_REAL Pitch, HPDF_REAL opacity, HPDF_BOOL showintersection); 49 | HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCrossSectionOff(HPDF_Dict view); 50 | 51 | HPDF_Dict 52 | HPDF_3DView_New ( HPDF_MMgr mmgr, 53 | HPDF_Xref xref, 54 | HPDF_U3D u3d, 55 | const char *name); 56 | #ifdef __cplusplus 57 | } 58 | #endif /* __cplusplus */ 59 | 60 | #endif /* _HPDF_U3D_H */ 61 | 62 | -------------------------------------------------------------------------------- /libharu/include/hpdf_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- fpdf_utils.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_UTILS_H 19 | #define _HPDF_UTILS_H 20 | 21 | #include "hpdf_config.h" 22 | #include "hpdf_types.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /* __cplusplus */ 27 | 28 | HPDF_INT 29 | HPDF_AToI (const char* s); 30 | 31 | 32 | HPDF_DOUBLE 33 | HPDF_AToF (const char* s); 34 | 35 | 36 | char* 37 | HPDF_IToA (char* s, 38 | HPDF_INT32 val, 39 | char* eptr); 40 | 41 | 42 | char* 43 | HPDF_IToA2 (char *s, 44 | HPDF_UINT32 val, 45 | HPDF_UINT len); 46 | 47 | 48 | char* 49 | HPDF_FToA (char *s, 50 | HPDF_REAL val, 51 | char *eptr); 52 | 53 | 54 | HPDF_BYTE* 55 | HPDF_MemCpy (HPDF_BYTE* out, 56 | const HPDF_BYTE* in, 57 | HPDF_UINT n); 58 | 59 | 60 | HPDF_BYTE* 61 | HPDF_StrCpy (char* out, 62 | const char* in, 63 | char* eptr); 64 | 65 | 66 | HPDF_INT 67 | HPDF_MemCmp (const HPDF_BYTE* s1, 68 | const HPDF_BYTE* s2, 69 | HPDF_UINT n); 70 | 71 | 72 | HPDF_INT 73 | HPDF_StrCmp (const char* s1, 74 | const char* s2); 75 | 76 | 77 | const char* 78 | HPDF_StrStr (const char *s1, 79 | const char *s2, 80 | HPDF_UINT maxlen); 81 | 82 | 83 | void* 84 | HPDF_MemSet (void* s, 85 | HPDF_BYTE c, 86 | HPDF_UINT n); 87 | 88 | 89 | HPDF_UINT 90 | HPDF_StrLen (const char* s, 91 | HPDF_INT maxlen); 92 | 93 | 94 | HPDF_Box 95 | HPDF_ToBox (HPDF_INT16 left, 96 | HPDF_INT16 bottom, 97 | HPDF_INT16 right, 98 | HPDF_INT16 top); 99 | 100 | 101 | HPDF_Point 102 | HPDF_ToPoint (HPDF_INT16 x, 103 | HPDF_INT16 y); 104 | 105 | 106 | HPDF_Rect 107 | HPDF_ToRect (HPDF_REAL left, 108 | HPDF_REAL bottom, 109 | HPDF_REAL right, 110 | HPDF_REAL top); 111 | 112 | 113 | void 114 | HPDF_UInt16Swap (HPDF_UINT16 *value); 115 | 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif /* __cplusplus */ 120 | 121 | #define HPDF_NEEDS_ESCAPE(c) (c < 0x20 || \ 122 | c > 0x7e || \ 123 | c == '\\' || \ 124 | c == '%' || \ 125 | c == '#' || \ 126 | c == '/' || \ 127 | c == '(' || \ 128 | c == ')' || \ 129 | c == '<' || \ 130 | c == '>' || \ 131 | c == '[' || \ 132 | c == ']' || \ 133 | c == '{' || \ 134 | c == '}' ) \ 135 | 136 | #define HPDF_IS_WHITE_SPACE(c) (c == 0x00 || \ 137 | c == 0x09 || \ 138 | c == 0x0A || \ 139 | c == 0x0C || \ 140 | c == 0x0D || \ 141 | c == 0x20 ) \ 142 | 143 | /*----------------------------------------------------------------------------*/ 144 | /*----- macros for debug -----------------------------------------------------*/ 145 | 146 | #ifdef LIBHPDF_DEBUG_TRACE 147 | #ifndef HPDF_PTRACE_ON 148 | #define HPDF_PTRACE_ON 149 | #endif /* HPDF_PTRACE_ON */ 150 | #endif /* LIBHPDF_DEBUG_TRACE */ 151 | 152 | #ifdef HPDF_PTRACE_ON 153 | #define HPDF_PTRACE(ARGS) HPDF_PRINTF ARGS 154 | #else 155 | #define HPDF_PTRACE(ARGS) /* do nothing */ 156 | #endif /* HPDF_PTRACE */ 157 | 158 | #ifdef LIBHPDF_DEBUG 159 | #define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) HPDF_PrintBinary(BUF, LEN, CAPTION) 160 | #else 161 | #define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) /* do nothing */ 162 | #endif 163 | 164 | #endif /* _HPDF_UTILS_H */ 165 | 166 | -------------------------------------------------------------------------------- /libharu/include/hpdf_version.h: -------------------------------------------------------------------------------- 1 | #define HPDF_MAJOR_VERSION 2 2 | #define HPDF_MINOR_VERSION 4 3 | #define HPDF_BUGFIX_VERSION 4 4 | #define HPDF_EXTRA_VERSION "" 5 | 6 | #define hpdf_vquote(x) #x 7 | #define hpdf_vexp(x) hpdf_vquote(x) 8 | 9 | #define HPDF_VERSION_TEXT (hpdf_vexp(HPDF_MAJOR_VERSION) "." hpdf_vexp(HPDF_MINOR_VERSION) "." hpdf_vexp(HPDF_BUGFIX_VERSION) HPDF_EXTRA_VERSION) 10 | #define HPDF_VERSION_ID ((HPDF_MAJOR_VERSION) * 10000 + (HPDF_MINOR_VERSION) * 100 + (HPDF_BUGFIX_VERSION)) 11 | -------------------------------------------------------------------------------- /libharu/src/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | Makefile 3 | *.lo 4 | *.la 5 | .deps 6 | .libs 7 | *.o 8 | *.a 9 | stamp-h1 10 | -------------------------------------------------------------------------------- /libharu/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # src/CMakeLists.txt 2 | # 3 | # Copyright (C) 2008 Werner Smekal 4 | # 5 | # create library 6 | # ======================================================================= 7 | # libhpdf source files 8 | # ======================================================================= 9 | set( 10 | LIBHPDF_SRCS 11 | hpdf_annotation.c 12 | hpdf_array.c 13 | hpdf_binary.c 14 | hpdf_boolean.c 15 | hpdf_catalog.c 16 | hpdf_destination.c 17 | hpdf_dict.c 18 | hpdf_direct.c 19 | hpdf_doc_png.c 20 | hpdf_doc.c 21 | hpdf_encoder_cns.c 22 | hpdf_encoder_cnt.c 23 | hpdf_encoder_jp.c 24 | hpdf_encoder_kr.c 25 | hpdf_encoder_utf.c 26 | hpdf_encoder.c 27 | hpdf_encrypt.c 28 | hpdf_encryptdict.c 29 | hpdf_error.c 30 | hpdf_ext_gstate.c 31 | hpdf_font_cid.c 32 | hpdf_font_tt.c 33 | hpdf_font_type1.c 34 | hpdf_font.c 35 | hpdf_fontdef_base14.c 36 | hpdf_fontdef_cid.c 37 | hpdf_fontdef_cns.c 38 | hpdf_fontdef_cnt.c 39 | hpdf_fontdef_jp.c 40 | hpdf_fontdef_kr.c 41 | hpdf_fontdef_tt.c 42 | hpdf_fontdef_type1.c 43 | hpdf_fontdef.c 44 | hpdf_gstate.c 45 | hpdf_image_ccitt.c 46 | hpdf_image_png.c 47 | hpdf_image.c 48 | hpdf_info.c 49 | hpdf_list.c 50 | hpdf_mmgr.c 51 | hpdf_name.c 52 | hpdf_namedict.c 53 | hpdf_null.c 54 | hpdf_number.c 55 | hpdf_objects.c 56 | hpdf_outline.c 57 | hpdf_page_label.c 58 | hpdf_page_operator.c 59 | hpdf_pages.c 60 | hpdf_real.c 61 | hpdf_shading.c 62 | hpdf_streams.c 63 | hpdf_string.c 64 | hpdf_u3d.c 65 | hpdf_utils.c 66 | hpdf_xref.c 67 | hpdf_pdfa.c 68 | hpdf_3dmeasure.c 69 | hpdf_exdata.c 70 | hpdf_encoder_utf.c 71 | ) 72 | 73 | # ======================================================================= 74 | # create hpdf library 75 | # ======================================================================= 76 | add_library(hpdf STATIC ${LIBHPDF_SRCS}) 77 | set_target_properties(hpdf PROPERTIES 78 | SOVERSION ${HPDF_MAJOR_VERSION}.${HPDF_MINOR_VERSION} 79 | VERSION ${HPDF_MAJOR_VERSION}.${HPDF_MINOR_VERSION}.${HPDF_BUGFIX_VERSION} 80 | ) 81 | if (PNG_FOUND) 82 | include_directories (${PNG_INCLUDE_DIRS}) 83 | target_link_libraries (hpdf ${PNG_LIBRARIES}) 84 | endif() 85 | if (ZLIB_FOUND) 86 | include_directories (${ZLIB_INCLUDE_DIRS}) 87 | target_link_libraries (hpdf ${ZLIB_LIBRARIES}) 88 | endif() 89 | 90 | # Math library 91 | if(UNIX AND NOT APPLE) 92 | target_link_libraries (hpdf ${M_LIB}) 93 | endif() 94 | 95 | install( 96 | TARGETS hpdf 97 | ARCHIVE DESTINATION . 98 | LIBRARY DESTINATION . 99 | RUNTIME DESTINATION . 100 | ) 101 | -------------------------------------------------------------------------------- /libharu/src/hpdf_3dmeasure.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_annotation.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_info.h" 21 | #include "hpdf_3dmeasure.h" 22 | #include "hpdf.h" 23 | 24 | /*----------------------------------------------------------------------------*/ 25 | /*------ HPDF_3DMeasure -----------------------------------------------------*/ 26 | 27 | HPDF_STATUS 28 | HPDF_Dict_AddPoint3D(HPDF_Dict dict, const char* key, HPDF_Point3D point) 29 | { 30 | HPDF_Array array; 31 | HPDF_STATUS ret = HPDF_OK; 32 | array = HPDF_Array_New (dict->mmgr); 33 | if (!array) 34 | return HPDF_Error_GetCode ( dict->error); 35 | 36 | if (HPDF_Dict_Add (dict, key, array) != HPDF_OK) 37 | return HPDF_Error_GetCode ( dict->error); 38 | 39 | ret += HPDF_Array_AddReal(array, point.x); 40 | ret += HPDF_Array_AddReal(array, point.y); 41 | ret += HPDF_Array_AddReal(array, point.z); 42 | 43 | return ret; 44 | } 45 | 46 | 47 | 48 | 49 | HPDF_3DMeasure 50 | HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr, 51 | HPDF_Xref xref, 52 | HPDF_Point3D firstanchorpoint, 53 | HPDF_Point3D textanchorpoint 54 | ) 55 | { 56 | HPDF_3DMeasure measure; 57 | HPDF_STATUS ret = HPDF_OK; 58 | 59 | 60 | HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n")); 61 | 62 | measure = HPDF_Dict_New (mmgr); 63 | if (!measure) 64 | return NULL; 65 | 66 | if (HPDF_Xref_Add (xref, measure) != HPDF_OK) 67 | return NULL; 68 | 69 | ret += HPDF_Dict_AddPoint3D(measure, "A1", firstanchorpoint); 70 | ret += HPDF_Dict_AddPoint3D(measure, "TP", textanchorpoint); 71 | 72 | ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure"); 73 | ret += HPDF_Dict_AddName (measure, "Subtype", "3DC"); 74 | 75 | if (ret != HPDF_OK) 76 | return NULL; 77 | 78 | return measure; 79 | } 80 | 81 | 82 | 83 | HPDF_EXPORT(HPDF_STATUS) 84 | HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure, 85 | HPDF_RGBColor color) 86 | { 87 | HPDF_Array array; 88 | HPDF_STATUS ret = HPDF_OK; 89 | 90 | array = HPDF_Array_New (measure->mmgr); 91 | if (!array) 92 | return HPDF_Error_GetCode (measure->error); 93 | 94 | ret = HPDF_Dict_Add (measure, "C", array); 95 | if (ret != HPDF_OK) 96 | return ret; 97 | 98 | ret += HPDF_Array_AddName(array, "DeviceRGB"); 99 | ret += HPDF_Array_AddReal(array, color.r); 100 | ret += HPDF_Array_AddReal(array, color.g); 101 | ret += HPDF_Array_AddReal(array, color.b); 102 | 103 | return ret; 104 | } 105 | 106 | 107 | HPDF_EXPORT(HPDF_STATUS) 108 | HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure, 109 | HPDF_REAL textsize) 110 | { 111 | HPDF_STATUS ret = HPDF_OK; 112 | 113 | ret = HPDF_Dict_AddReal(measure, "TS", textsize); 114 | 115 | return ret; 116 | } 117 | 118 | 119 | HPDF_EXPORT(HPDF_STATUS) 120 | HPDF_3DMeasure_SetName(HPDF_3DMeasure measure, 121 | const char* name) 122 | { 123 | HPDF_STATUS ret = HPDF_OK; 124 | HPDF_String s; 125 | 126 | s = HPDF_String_New (measure->mmgr, name, 0); 127 | if (!s) 128 | return HPDF_Error_GetCode ( measure->error); 129 | 130 | ret = HPDF_Dict_Add(measure, "TRL", s); 131 | 132 | return ret; 133 | } 134 | 135 | HPDF_EXPORT(HPDF_STATUS) 136 | HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure, 137 | HPDF_INT32 x, 138 | HPDF_INT32 y) 139 | { 140 | HPDF_Array array; 141 | HPDF_STATUS ret = HPDF_OK; 142 | 143 | array = HPDF_Array_New (measure->mmgr); 144 | if (!array) 145 | return HPDF_Error_GetCode (measure->error); 146 | 147 | ret = HPDF_Dict_Add (measure, "TB", array); 148 | if (ret != HPDF_OK) 149 | return ret; 150 | 151 | ret += HPDF_Array_AddNumber(array, x); 152 | ret += HPDF_Array_AddNumber(array, y); 153 | 154 | return ret; 155 | } 156 | 157 | HPDF_EXPORT(HPDF_STATUS) 158 | HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure, 159 | const char* text, 160 | HPDF_Encoder encoder) 161 | { 162 | HPDF_STATUS ret = HPDF_OK; 163 | HPDF_String s; 164 | 165 | s = HPDF_String_New (measure->mmgr, text, encoder); 166 | if (!s) 167 | return HPDF_Error_GetCode ( measure->error); 168 | 169 | ret = HPDF_Dict_Add(measure, "UT", s); 170 | 171 | return ret; 172 | } 173 | 174 | HPDF_EXPORT(HPDF_STATUS) 175 | HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure, 176 | HPDF_Annotation projectionanotation) 177 | { 178 | HPDF_STATUS ret = HPDF_OK; 179 | 180 | ret = HPDF_Dict_Add(measure, "S", projectionanotation); 181 | 182 | return ret; 183 | } 184 | 185 | 186 | HPDF_3DMeasure 187 | HPDF_PD33DMeasure_New(HPDF_MMgr mmgr, 188 | HPDF_Xref xref, 189 | HPDF_Point3D annotationPlaneNormal, 190 | HPDF_Point3D firstAnchorPoint, 191 | HPDF_Point3D secondAnchorPoint, 192 | HPDF_Point3D leaderLinesDirection, 193 | HPDF_Point3D measurementValuePoint, 194 | HPDF_Point3D textYDirection, 195 | HPDF_REAL value, 196 | const char* unitsString 197 | ) 198 | { 199 | HPDF_3DMeasure measure; 200 | HPDF_STATUS ret = HPDF_OK; 201 | HPDF_String s; 202 | 203 | HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n")); 204 | 205 | measure = HPDF_Dict_New (mmgr); 206 | if (!measure) 207 | return NULL; 208 | 209 | if (HPDF_Xref_Add (xref, measure) != HPDF_OK) 210 | return NULL; 211 | 212 | ret += HPDF_Dict_AddPoint3D(measure, "AP", annotationPlaneNormal); 213 | ret += HPDF_Dict_AddPoint3D(measure, "A1", firstAnchorPoint); 214 | ret += HPDF_Dict_AddPoint3D(measure, "A2", secondAnchorPoint); 215 | ret += HPDF_Dict_AddPoint3D(measure, "D1", leaderLinesDirection); 216 | ret += HPDF_Dict_AddPoint3D(measure, "TP", measurementValuePoint); 217 | ret += HPDF_Dict_AddPoint3D(measure, "TY", textYDirection); 218 | 219 | ret += HPDF_Dict_AddReal(measure, "V", value); 220 | 221 | s = HPDF_String_New (measure->mmgr, unitsString, 0); 222 | if (!s) 223 | return NULL; 224 | 225 | ret = HPDF_Dict_Add(measure, "U", s); 226 | 227 | ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure"); 228 | ret += HPDF_Dict_AddName (measure, "Subtype", "PD3"); 229 | 230 | if (ret != HPDF_OK) 231 | return NULL; 232 | 233 | return measure; 234 | } 235 | 236 | -------------------------------------------------------------------------------- /libharu/src/hpdf_binary.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_binary.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_objects.h" 21 | 22 | 23 | HPDF_Binary 24 | HPDF_Binary_New (HPDF_MMgr mmgr, 25 | HPDF_BYTE *value, 26 | HPDF_UINT len) 27 | { 28 | HPDF_Binary obj; 29 | 30 | obj = HPDF_GetMem (mmgr, sizeof(HPDF_Binary_Rec)); 31 | 32 | if (obj) { 33 | HPDF_MemSet(&obj->header, 0, sizeof(HPDF_Obj_Header)); 34 | obj->header.obj_class = HPDF_OCLASS_BINARY; 35 | 36 | obj->mmgr = mmgr; 37 | obj->error = mmgr->error; 38 | obj->value = NULL; 39 | obj->len = 0; 40 | if (HPDF_Binary_SetValue (obj, value, len) != HPDF_OK) { 41 | HPDF_FreeMem (mmgr, obj); 42 | return NULL; 43 | } 44 | } 45 | 46 | return obj; 47 | } 48 | 49 | HPDF_STATUS 50 | HPDF_Binary_Write (HPDF_Binary obj, 51 | HPDF_Stream stream, 52 | HPDF_Encrypt e) 53 | { 54 | HPDF_STATUS ret; 55 | 56 | if (obj->len == 0) 57 | return HPDF_Stream_WriteStr (stream, "<>"); 58 | 59 | if ((ret = HPDF_Stream_WriteChar (stream, '<')) != HPDF_OK) 60 | return ret; 61 | 62 | if (e) 63 | HPDF_Encrypt_Reset (e); 64 | 65 | if ((ret = HPDF_Stream_WriteBinary (stream, obj->value, obj->len, e)) != 66 | HPDF_OK) 67 | return ret; 68 | 69 | return HPDF_Stream_WriteChar (stream, '>'); 70 | } 71 | 72 | 73 | HPDF_STATUS 74 | HPDF_Binary_SetValue (HPDF_Binary obj, 75 | HPDF_BYTE *value, 76 | HPDF_UINT len) 77 | { 78 | if (len > HPDF_LIMIT_MAX_STRING_LEN) 79 | return HPDF_SetError (obj->error, HPDF_BINARY_LENGTH_ERR, 0); 80 | 81 | if (obj->value) { 82 | HPDF_FreeMem (obj->mmgr, obj->value); 83 | obj->len = 0; 84 | } 85 | 86 | obj->value = HPDF_GetMem (obj->mmgr, len); 87 | if (!obj->value) 88 | return HPDF_Error_GetCode (obj->error); 89 | 90 | HPDF_MemCpy (obj->value, value, len); 91 | obj->len = len; 92 | 93 | return HPDF_OK; 94 | } 95 | 96 | 97 | void 98 | HPDF_Binary_Free (HPDF_Binary obj) 99 | { 100 | if (!obj) 101 | return; 102 | 103 | if (obj->value) 104 | HPDF_FreeMem (obj->mmgr, obj->value); 105 | 106 | HPDF_FreeMem (obj->mmgr, obj); 107 | } 108 | 109 | HPDF_UINT 110 | HPDF_Binary_GetLen (HPDF_Binary obj) 111 | { 112 | return obj->len; 113 | } 114 | 115 | HPDF_BYTE* 116 | HPDF_Binary_GetValue (HPDF_Binary obj) 117 | { 118 | return obj->value; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /libharu/src/hpdf_boolean.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_boolean.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_utils.h" 19 | #include "hpdf_objects.h" 20 | 21 | HPDF_Boolean 22 | HPDF_Boolean_New (HPDF_MMgr mmgr, 23 | HPDF_BOOL value) 24 | { 25 | HPDF_Boolean obj = HPDF_GetMem (mmgr, sizeof(HPDF_Boolean_Rec)); 26 | 27 | if (obj) { 28 | HPDF_MemSet(&obj->header, 0, sizeof(HPDF_Obj_Header)); 29 | obj->header.obj_class = HPDF_OCLASS_BOOLEAN; 30 | obj->value = value; 31 | } 32 | 33 | return obj; 34 | } 35 | 36 | 37 | HPDF_STATUS 38 | HPDF_Boolean_Write (HPDF_Boolean obj, 39 | HPDF_Stream stream) 40 | { 41 | HPDF_STATUS ret; 42 | 43 | if (obj->value) 44 | ret = HPDF_Stream_WriteStr (stream, "true"); 45 | else 46 | ret = HPDF_Stream_WriteStr (stream, "false"); 47 | 48 | return ret; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /libharu/src/hpdf_direct.c: -------------------------------------------------------------------------------- 1 | #include "hpdf_conf.h" 2 | #include "hpdf_utils.h" 3 | #include "hpdf_objects.h" 4 | 5 | 6 | HPDF_Direct 7 | HPDF_Direct_New (HPDF_MMgr mmgr, 8 | HPDF_BYTE *value, 9 | HPDF_UINT len) 10 | { 11 | HPDF_Direct obj; 12 | 13 | obj = HPDF_GetMem (mmgr, sizeof(HPDF_Direct_Rec)); 14 | 15 | if (obj) { 16 | HPDF_MemSet(&obj->header, 0, sizeof(HPDF_Obj_Header)); 17 | obj->header.obj_class = HPDF_OCLASS_DIRECT; 18 | 19 | obj->mmgr = mmgr; 20 | obj->error = mmgr->error; 21 | obj->value = NULL; 22 | obj->len = 0; 23 | if (HPDF_Direct_SetValue (obj, value, len) != HPDF_OK) { 24 | HPDF_FreeMem (mmgr, obj); 25 | return NULL; 26 | } 27 | } 28 | 29 | return obj; 30 | } 31 | 32 | HPDF_STATUS 33 | HPDF_Direct_Write (HPDF_Direct obj, 34 | HPDF_Stream stream) 35 | { 36 | return HPDF_Stream_Write(stream, obj->value, obj->len); 37 | } 38 | 39 | 40 | HPDF_STATUS 41 | HPDF_Direct_SetValue (HPDF_Direct obj, 42 | HPDF_BYTE *value, 43 | HPDF_UINT len) 44 | { 45 | if (len > HPDF_LIMIT_MAX_STRING_LEN) 46 | return HPDF_SetError (obj->error, HPDF_BINARY_LENGTH_ERR, 0); 47 | 48 | if (obj->value) { 49 | HPDF_FreeMem (obj->mmgr, obj->value); 50 | obj->len = 0; 51 | } 52 | 53 | obj->value = HPDF_GetMem (obj->mmgr, len); 54 | if (!obj->value) 55 | return HPDF_Error_GetCode (obj->error); 56 | 57 | HPDF_MemCpy (obj->value, value, len); 58 | obj->len = len; 59 | 60 | return HPDF_OK; 61 | } 62 | 63 | 64 | void 65 | HPDF_Direct_Free (HPDF_Direct obj) 66 | { 67 | if (!obj) 68 | return; 69 | 70 | if (obj->value) 71 | HPDF_FreeMem (obj->mmgr, obj->value); 72 | 73 | HPDF_FreeMem (obj->mmgr, obj); 74 | } 75 | -------------------------------------------------------------------------------- /libharu/src/hpdf_doc_png.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_doc_png.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | 19 | #include "hpdf_conf.h" 20 | #include "hpdf_utils.h" 21 | #include "hpdf.h" 22 | #include "hpdf_image.h" 23 | 24 | 25 | #ifdef LIBHPDF_HAVE_LIBPNG 26 | static HPDF_Image 27 | LoadPngImageFromStream (HPDF_Doc pdf, 28 | HPDF_Stream imagedata, 29 | HPDF_BOOL delayed_loading); 30 | 31 | HPDF_EXPORT(HPDF_Image) 32 | HPDF_LoadPngImageFromMem (HPDF_Doc pdf, 33 | const HPDF_BYTE *buffer, 34 | HPDF_UINT size) 35 | { 36 | HPDF_Stream imagedata; 37 | HPDF_Image image; 38 | 39 | HPDF_PTRACE ((" HPDF_LoadPngImageFromFile\n")); 40 | 41 | if (!HPDF_HasDoc (pdf)) { 42 | return NULL; 43 | } 44 | 45 | /* create file stream */ 46 | imagedata = HPDF_MemStream_New (pdf->mmgr, size); 47 | 48 | if (!HPDF_Stream_Validate (imagedata)) { 49 | HPDF_RaiseError (&pdf->error, HPDF_INVALID_STREAM, 0); 50 | return NULL; 51 | } 52 | 53 | if (HPDF_Stream_Write (imagedata, buffer, size) != HPDF_OK) { 54 | HPDF_Stream_Free (imagedata); 55 | return NULL; 56 | } 57 | 58 | image = LoadPngImageFromStream (pdf, imagedata, HPDF_FALSE); 59 | 60 | /* destroy file stream */ 61 | HPDF_Stream_Free (imagedata); 62 | 63 | if (!image) { 64 | HPDF_CheckError (&pdf->error); 65 | } 66 | 67 | return image; 68 | 69 | } 70 | 71 | 72 | HPDF_EXPORT(HPDF_Image) 73 | HPDF_LoadPngImageFromFile (HPDF_Doc pdf, 74 | const char *filename) 75 | { 76 | HPDF_Stream imagedata; 77 | HPDF_Image image; 78 | 79 | HPDF_PTRACE ((" HPDF_LoadPngImageFromFile\n")); 80 | 81 | if (!HPDF_HasDoc (pdf)) 82 | return NULL; 83 | 84 | /* create file stream */ 85 | imagedata = HPDF_FileReader_New (pdf->mmgr, filename); 86 | 87 | if (HPDF_Stream_Validate (imagedata)) 88 | image = LoadPngImageFromStream (pdf, imagedata, HPDF_FALSE); 89 | else 90 | image = NULL; 91 | 92 | /* destroy file stream */ 93 | if (imagedata) 94 | HPDF_Stream_Free (imagedata); 95 | 96 | if (!image) 97 | HPDF_CheckError (&pdf->error); 98 | 99 | return image; 100 | } 101 | 102 | /* delaied loading version of HPDF_LoadPngImageFromFile */ 103 | HPDF_EXPORT(HPDF_Image) 104 | HPDF_LoadPngImageFromFile2 (HPDF_Doc pdf, 105 | const char *filename) 106 | { 107 | HPDF_Stream imagedata; 108 | HPDF_Image image; 109 | HPDF_String fname; 110 | 111 | HPDF_PTRACE ((" HPDF_LoadPngImageFromFile\n")); 112 | 113 | if (!HPDF_HasDoc (pdf)) 114 | return NULL; 115 | 116 | /* check whether file name is valid or not. */ 117 | imagedata = HPDF_FileReader_New (pdf->mmgr, filename); 118 | 119 | if (HPDF_Stream_Validate (imagedata)) 120 | image = LoadPngImageFromStream (pdf, imagedata, HPDF_TRUE); 121 | else 122 | image = NULL; 123 | 124 | /* destroy file stream */ 125 | if (imagedata) 126 | HPDF_Stream_Free (imagedata); 127 | 128 | if (!image) { 129 | HPDF_CheckError (&pdf->error); 130 | return NULL; 131 | } 132 | 133 | /* add file-name to image dictionary as a hidden entry. 134 | * it is used when the image data is needed. 135 | */ 136 | fname = HPDF_String_New (pdf->mmgr, filename, NULL); 137 | if (!fname) { 138 | HPDF_CheckError (&pdf->error); 139 | return NULL; 140 | } 141 | 142 | fname->header.obj_id |= HPDF_OTYPE_HIDDEN; 143 | 144 | if ((HPDF_Dict_Add (image, "_FILE_NAME", fname)) != HPDF_OK) { 145 | HPDF_CheckError (&pdf->error); 146 | return NULL; 147 | } 148 | 149 | return image; 150 | } 151 | 152 | static HPDF_Image 153 | LoadPngImageFromStream (HPDF_Doc pdf, 154 | HPDF_Stream imagedata, 155 | HPDF_BOOL delayed_loading) 156 | { 157 | HPDF_Image image; 158 | HPDF_Dict smask; 159 | 160 | HPDF_PTRACE ((" HPDF_LoadPngImageFromStream\n")); 161 | 162 | image = HPDF_Image_LoadPngImage (pdf->mmgr, imagedata, pdf->xref, 163 | delayed_loading); 164 | 165 | if (image && (pdf->compression_mode & HPDF_COMP_IMAGE)) { 166 | image->filter = HPDF_STREAM_FILTER_FLATE_DECODE; 167 | 168 | // is there an alpha layer? then compress it also 169 | smask = HPDF_Dict_GetItem(image, "SMask", HPDF_OCLASS_DICT); 170 | if (smask) smask->filter = HPDF_STREAM_FILTER_FLATE_DECODE; 171 | } 172 | 173 | return image; 174 | } 175 | 176 | #else 177 | static HPDF_Image 178 | LoadPngImageFromStream (HPDF_Doc pdf, 179 | HPDF_Stream imagedata, 180 | HPDF_BOOL delayed_loading) 181 | { 182 | HPDF_SetError (&pdf->error, HPDF_UNSUPPORTED_FUNC, 0); 183 | HPDF_UNUSED (delayed_loading); 184 | HPDF_UNUSED (imagedata); 185 | 186 | return NULL; 187 | } 188 | 189 | #endif /* LIBHPDF_HAVE_PNGLIB */ 190 | -------------------------------------------------------------------------------- /libharu/src/hpdf_encryptdict.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_encryptdict.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include 19 | #include "hpdf_conf.h" 20 | #include "hpdf_utils.h" 21 | #include "hpdf_objects.h" 22 | #include "hpdf_encryptdict.h" 23 | #include "hpdf_info.h" 24 | #ifndef HPDF_UNUSED 25 | #define HPDF_UNUSED(a) ((void)(a)) 26 | #endif 27 | 28 | HPDF_EncryptDict 29 | HPDF_EncryptDict_New (HPDF_MMgr mmgr, 30 | HPDF_Xref xref) 31 | { 32 | HPDF_Encrypt attr; 33 | HPDF_EncryptDict dict; 34 | 35 | HPDF_PTRACE((" HPDF_EncryptDict_New\n")); 36 | 37 | dict = HPDF_Dict_New (mmgr); 38 | if (!dict) 39 | return NULL; 40 | 41 | dict->header.obj_class |= HPDF_OSUBCLASS_ENCRYPT; 42 | dict->free_fn = HPDF_EncryptDict_OnFree; 43 | 44 | attr = HPDF_GetMem (dict->mmgr, sizeof(HPDF_Encrypt_Rec)); 45 | if (!attr) { 46 | HPDF_Dict_Free (dict); 47 | return NULL; 48 | } 49 | 50 | dict->attr = attr; 51 | HPDF_Encrypt_Init (attr); 52 | 53 | if (HPDF_Xref_Add (xref, dict) != HPDF_OK) 54 | return NULL; 55 | 56 | return dict; 57 | } 58 | 59 | 60 | void 61 | HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict, 62 | HPDF_Dict info, 63 | HPDF_Xref xref) 64 | { 65 | HPDF_MD5_CTX ctx; 66 | HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr; 67 | 68 | /* use the result of 'time' function to get random value. 69 | * when debugging, 'time' value is ignored. 70 | */ 71 | #ifndef LIBHPDF_DEBUG 72 | time_t t = HPDF_TIME (NULL); 73 | #endif /* LIBHPDF_DEBUG */ 74 | 75 | HPDF_MD5Init (&ctx); 76 | HPDF_UNUSED (xref); 77 | HPDF_UNUSED (info); 78 | 79 | #ifndef LIBHPDF_DEBUG 80 | HPDF_MD5Update(&ctx, (HPDF_BYTE *)&t, sizeof(t)); 81 | 82 | /* create File Identifier from elements of Into dictionary. */ 83 | if (info) { 84 | const char *s; 85 | HPDF_UINT len; 86 | 87 | /* Author */ 88 | s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_AUTHOR); 89 | if ((len = HPDF_StrLen (s, -1)) > 0) 90 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len); 91 | 92 | /* Creator */ 93 | s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_CREATOR); 94 | if ((len = HPDF_StrLen (s, -1)) > 0) 95 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len); 96 | 97 | /* Producer */ 98 | s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_PRODUCER); 99 | if ((len = HPDF_StrLen (s, -1)) > 0) 100 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len); 101 | 102 | /* Title */ 103 | s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_TITLE); 104 | if ((len = HPDF_StrLen (s, -1)) > 0) 105 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len); 106 | 107 | /* Subject */ 108 | s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_SUBJECT); 109 | if ((len = HPDF_StrLen (s, -1)) > 0) 110 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len); 111 | 112 | /* Keywords */ 113 | s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_KEYWORDS); 114 | if ((len = HPDF_StrLen (s, -1)) > 0) 115 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len); 116 | 117 | HPDF_MD5Update(&ctx, (const HPDF_BYTE *)&(xref->entries->count), 118 | sizeof(HPDF_UINT32)); 119 | 120 | } 121 | #endif 122 | HPDF_MD5Final(attr->encrypt_id, &ctx); 123 | } 124 | 125 | 126 | HPDF_STATUS 127 | HPDF_EncryptDict_Prepare (HPDF_EncryptDict dict, 128 | HPDF_Dict info, 129 | HPDF_Xref xref) 130 | { 131 | HPDF_STATUS ret; 132 | HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr; 133 | HPDF_Binary user_key; 134 | HPDF_Binary owner_key; 135 | 136 | HPDF_PTRACE((" HPDF_EncryptDict_Prepare\n")); 137 | 138 | HPDF_EncryptDict_CreateID (dict, info, xref); 139 | HPDF_Encrypt_CreateOwnerKey (attr); 140 | HPDF_Encrypt_CreateEncryptionKey (attr); 141 | HPDF_Encrypt_CreateUserKey (attr); 142 | 143 | owner_key = HPDF_Binary_New (dict->mmgr, attr->owner_key, HPDF_PASSWD_LEN); 144 | if (!owner_key) 145 | return HPDF_Error_GetCode (dict->error); 146 | 147 | if ((ret = HPDF_Dict_Add (dict, "O", owner_key)) != HPDF_OK) 148 | return ret; 149 | 150 | user_key = HPDF_Binary_New (dict->mmgr, attr->user_key, HPDF_PASSWD_LEN); 151 | if (!user_key) 152 | return HPDF_Error_GetCode (dict->error); 153 | 154 | if ((ret = HPDF_Dict_Add (dict, "U", user_key)) != HPDF_OK) 155 | return ret; 156 | 157 | ret += HPDF_Dict_AddName (dict, "Filter", "Standard"); 158 | 159 | if (attr->mode == HPDF_ENCRYPT_R2) { 160 | ret += HPDF_Dict_AddNumber (dict, "V", 1); 161 | ret += HPDF_Dict_AddNumber (dict, "R", 2); 162 | } else if (attr->mode == HPDF_ENCRYPT_R3) { 163 | ret += HPDF_Dict_AddNumber (dict, "V", 2); 164 | ret += HPDF_Dict_AddNumber (dict, "R", 3); 165 | ret += HPDF_Dict_AddNumber (dict, "Length", attr->key_len * 8); 166 | } 167 | 168 | ret += HPDF_Dict_AddNumber (dict, "P", attr->permission); 169 | 170 | if (ret != HPDF_OK) 171 | return HPDF_Error_GetCode (dict->error); 172 | 173 | return HPDF_OK; 174 | } 175 | 176 | 177 | void 178 | HPDF_EncryptDict_OnFree (HPDF_Dict obj) 179 | { 180 | HPDF_Encrypt attr = (HPDF_Encrypt)obj->attr; 181 | 182 | HPDF_PTRACE((" HPDF_EncryptDict_OnFree\n")); 183 | 184 | if (attr) 185 | HPDF_FreeMem (obj->mmgr, attr); 186 | } 187 | 188 | 189 | HPDF_STATUS 190 | HPDF_EncryptDict_SetPassword (HPDF_EncryptDict dict, 191 | const char *owner_passwd, 192 | const char *user_passwd) 193 | { 194 | HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr; 195 | 196 | HPDF_PTRACE((" HPDF_EncryptDict_SetPassword\n")); 197 | 198 | if (HPDF_StrLen(owner_passwd, 2) == 0) 199 | return HPDF_SetError(dict->error, HPDF_ENCRYPT_INVALID_PASSWORD, 0); 200 | 201 | if (owner_passwd && user_passwd && 202 | HPDF_StrCmp (owner_passwd, user_passwd) == 0) 203 | return HPDF_SetError(dict->error, HPDF_ENCRYPT_INVALID_PASSWORD, 0); 204 | 205 | HPDF_PadOrTrancatePasswd (owner_passwd, attr->owner_passwd); 206 | HPDF_PadOrTrancatePasswd (user_passwd, attr->user_passwd); 207 | 208 | return HPDF_OK; 209 | } 210 | 211 | 212 | HPDF_BOOL 213 | HPDF_EncryptDict_Validate (HPDF_EncryptDict dict) 214 | { 215 | HPDF_Obj_Header *header = (HPDF_Obj_Header *)dict; 216 | 217 | HPDF_PTRACE((" HPDF_EncryptDict_Validate\n")); 218 | 219 | if (!dict || !dict->attr) 220 | return HPDF_FALSE; 221 | 222 | if (header->obj_class != (HPDF_OCLASS_DICT | HPDF_OSUBCLASS_ENCRYPT)) 223 | return HPDF_FALSE; 224 | 225 | return HPDF_TRUE; 226 | } 227 | 228 | 229 | HPDF_Encrypt 230 | HPDF_EncryptDict_GetAttr (HPDF_EncryptDict dict) 231 | { 232 | HPDF_Obj_Header *header = (HPDF_Obj_Header *)dict; 233 | 234 | HPDF_PTRACE((" HPDF_EncryptDict_GetAttr\n")); 235 | 236 | if (dict && dict->attr && 237 | (header->obj_class == (HPDF_OCLASS_DICT | HPDF_OSUBCLASS_ENCRYPT))) 238 | return (HPDF_Encrypt)dict->attr; 239 | 240 | return NULL; 241 | } 242 | 243 | 244 | -------------------------------------------------------------------------------- /libharu/src/hpdf_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_error.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_error.h" 21 | #include "hpdf_consts.h" 22 | #include "hpdf.h" 23 | 24 | #ifndef HPDF_STDCALL 25 | #ifdef HPDF_DLL_MAKE 26 | #define HPDF_STDCALL __stdcall 27 | #else 28 | #ifdef HPDF_DLL 29 | #define HPDF_STDCALL __stdcall 30 | #else 31 | #define HPDF_STDCALL 32 | #endif 33 | #endif 34 | #endif 35 | 36 | void 37 | HPDF_CopyError (HPDF_Error dst, 38 | HPDF_Error src); 39 | 40 | 41 | void 42 | HPDF_Error_Init (HPDF_Error error, 43 | void *user_data) 44 | { 45 | HPDF_MemSet(error, 0, sizeof(HPDF_Error_Rec)); 46 | 47 | error->user_data = user_data; 48 | } 49 | 50 | HPDF_STATUS 51 | HPDF_Error_GetCode (HPDF_Error error) 52 | { 53 | return error->error_no; 54 | } 55 | 56 | HPDF_STATUS 57 | HPDF_Error_GetDetailCode (HPDF_Error error) 58 | { 59 | return error->detail_no; 60 | } 61 | 62 | void 63 | HPDF_CopyError (HPDF_Error dst, 64 | HPDF_Error src) 65 | { 66 | dst->error_no = src->error_no; 67 | dst->detail_no = src->detail_no; 68 | dst->error_fn = src->error_fn; 69 | dst->user_data = src->user_data; 70 | } 71 | 72 | HPDF_STATUS 73 | HPDF_SetError (HPDF_Error error, 74 | HPDF_STATUS error_no, 75 | HPDF_STATUS detail_no) 76 | { 77 | HPDF_PTRACE((" HPDF_SetError: error_no=0x%04X " 78 | "detail_no=0x%04X\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no)); 79 | 80 | error->error_no = error_no; 81 | error->detail_no = detail_no; 82 | 83 | return error_no; 84 | } 85 | 86 | 87 | HPDF_EXPORT(HPDF_STATUS) 88 | HPDF_CheckError (HPDF_Error error) 89 | { 90 | HPDF_PTRACE((" HPDF_CheckError: error_no=0x%04X detail_no=0x%04X\n", 91 | (HPDF_UINT)error->error_no, (HPDF_UINT)error->detail_no)); 92 | 93 | if (error->error_no != HPDF_OK && error->error_fn) 94 | error->error_fn (error->error_no, error->detail_no, error->user_data); 95 | 96 | return error->error_no; 97 | } 98 | 99 | 100 | HPDF_STATUS 101 | HPDF_RaiseError (HPDF_Error error, 102 | HPDF_STATUS error_no, 103 | HPDF_STATUS detail_no) 104 | { 105 | HPDF_SetError (error, error_no, detail_no); 106 | 107 | return HPDF_CheckError (error); 108 | } 109 | 110 | 111 | void 112 | HPDF_Error_Reset (HPDF_Error error) 113 | { 114 | error->error_no = HPDF_NOERROR; 115 | error->detail_no = HPDF_NOERROR; 116 | } 117 | 118 | 119 | -------------------------------------------------------------------------------- /libharu/src/hpdf_exdata.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_annotation.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_info.h" 21 | #include "hpdf_exdata.h" 22 | #include "hpdf.h" 23 | 24 | /*----------------------------------------------------------------------------*/ 25 | /*------ HPDF_ExData -----------------------------------------------------*/ 26 | 27 | 28 | 29 | HPDF_ExData 30 | HPDF_3DAnnotExData_New(HPDF_MMgr mmgr, 31 | HPDF_Xref xref) 32 | { 33 | HPDF_ExData exdata; 34 | HPDF_STATUS ret = HPDF_OK; 35 | 36 | 37 | HPDF_PTRACE((" HPDF_ExData_New\n")); 38 | 39 | exdata = HPDF_Dict_New (mmgr); 40 | if (!exdata) 41 | return NULL; 42 | 43 | if (HPDF_Xref_Add (xref, exdata) != HPDF_OK) 44 | return NULL; 45 | 46 | ret += HPDF_Dict_AddName (exdata, "Type", "ExData"); 47 | ret += HPDF_Dict_AddName (exdata, "Subtype", "3DM"); 48 | 49 | if (ret != HPDF_OK) 50 | return NULL; 51 | 52 | return exdata; 53 | } 54 | 55 | 56 | 57 | HPDF_EXPORT(HPDF_STATUS) 58 | HPDF_3DAnnotExData_Set3DMeasurement(HPDF_ExData exdata, 59 | HPDF_3DMeasure measure) 60 | { 61 | HPDF_STATUS ret = HPDF_OK; 62 | 63 | ret = HPDF_Dict_Add (exdata, "M3DREF", measure); 64 | if (ret != HPDF_OK) 65 | return ret; 66 | 67 | return ret; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /libharu/src/hpdf_ext_gstate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_ext_gstate.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_ext_gstate.h" 21 | #include "hpdf.h" 22 | 23 | static const char * const HPDF_BM_NAMES[] = { 24 | "Normal", 25 | "Multiply", 26 | "Screen", 27 | "Overlay", 28 | "Darken", 29 | "Lighten", 30 | "ColorDodge", 31 | "ColorBurn", 32 | "HardLight", 33 | "SoftLight", 34 | "Difference", 35 | "Exclusion" 36 | }; 37 | 38 | 39 | HPDF_BOOL 40 | HPDF_ExtGState_Validate (HPDF_ExtGState ext_gstate) 41 | { 42 | if (!ext_gstate || (ext_gstate->header.obj_class != 43 | (HPDF_OSUBCLASS_EXT_GSTATE | HPDF_OCLASS_DICT) && 44 | ext_gstate->header.obj_class != 45 | (HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT))) 46 | return HPDF_FALSE; 47 | 48 | return HPDF_TRUE; 49 | } 50 | 51 | 52 | HPDF_STATUS 53 | ExtGState_Check (HPDF_ExtGState ext_gstate) 54 | { 55 | if (!HPDF_ExtGState_Validate (ext_gstate)) 56 | return HPDF_INVALID_OBJECT; 57 | 58 | if (ext_gstate->header.obj_class == 59 | (HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT)) 60 | return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_READ_ONLY, 61 | 0); 62 | 63 | return HPDF_OK; 64 | } 65 | 66 | 67 | HPDF_Dict 68 | HPDF_ExtGState_New (HPDF_MMgr mmgr, 69 | HPDF_Xref xref) 70 | { 71 | HPDF_Dict obj = HPDF_Dict_New (mmgr); 72 | 73 | HPDF_PTRACE ((" HPDF_ExtGState_New\n")); 74 | 75 | if (!obj) 76 | return NULL; 77 | 78 | if (HPDF_Xref_Add (xref, obj) != HPDF_OK) 79 | return NULL; 80 | 81 | if (HPDF_Dict_AddName (obj, "Type", "ExtGState") != HPDF_OK) 82 | return NULL; 83 | 84 | obj->header.obj_class |= HPDF_OSUBCLASS_EXT_GSTATE; 85 | 86 | return obj; 87 | } 88 | 89 | 90 | HPDF_EXPORT(HPDF_STATUS) 91 | HPDF_ExtGState_SetAlphaStroke (HPDF_ExtGState ext_gstate, 92 | HPDF_REAL value) 93 | { 94 | HPDF_STATUS ret = ExtGState_Check (ext_gstate); 95 | 96 | if (ret != HPDF_OK) 97 | return ret; 98 | 99 | if (value < 0 || value > 1.0f) 100 | return HPDF_RaiseError (ext_gstate->error, 101 | HPDF_EXT_GSTATE_OUT_OF_RANGE, 0); 102 | 103 | return HPDF_Dict_AddReal (ext_gstate, "CA", value); 104 | } 105 | 106 | 107 | HPDF_EXPORT(HPDF_STATUS) 108 | HPDF_ExtGState_SetAlphaFill (HPDF_ExtGState ext_gstate, 109 | HPDF_REAL value) 110 | { 111 | HPDF_STATUS ret = ExtGState_Check (ext_gstate); 112 | 113 | if (ret != HPDF_OK) 114 | return ret; 115 | 116 | if (value < 0 || value > 1.0f) 117 | return HPDF_RaiseError (ext_gstate->error, 118 | HPDF_EXT_GSTATE_OUT_OF_RANGE, 0); 119 | 120 | return HPDF_Dict_AddReal (ext_gstate, "ca", value); 121 | } 122 | 123 | 124 | HPDF_EXPORT(HPDF_STATUS) 125 | HPDF_ExtGState_SetBlendMode (HPDF_ExtGState ext_gstate, 126 | HPDF_BlendMode bmode) 127 | { 128 | HPDF_STATUS ret = ExtGState_Check (ext_gstate); 129 | 130 | if (ret != HPDF_OK) 131 | return ret; 132 | 133 | if ((int)bmode < 0 || (int)bmode > (int)HPDF_BM_EOF) 134 | return HPDF_RaiseError (ext_gstate->error, 135 | HPDF_EXT_GSTATE_OUT_OF_RANGE, 0); 136 | 137 | return HPDF_Dict_AddName (ext_gstate, "BM", HPDF_BM_NAMES[(int)bmode]); 138 | } 139 | 140 | /* 141 | HPDF_STATUS 142 | HPDF_ExtGState_SetStrokeAdjustment (HPDF_ExtGState ext_gstate, 143 | HPDF_BOOL value) 144 | { 145 | HPDF_STATUS ret = ExtGState_Check (ext_gstate); 146 | 147 | if (ret != HPDF_OK) 148 | return ret; 149 | 150 | return HPDF_Dict_AddBoolean (ext_gstate, "SA", value); 151 | } 152 | */ 153 | 154 | -------------------------------------------------------------------------------- /libharu/src/hpdf_font.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_font.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf.h" 21 | 22 | 23 | HPDF_EXPORT(HPDF_TextWidth) 24 | HPDF_Font_TextWidth (HPDF_Font font, 25 | const HPDF_BYTE *text, 26 | HPDF_UINT len) 27 | { 28 | HPDF_TextWidth tw = {0, 0, 0, 0}; 29 | HPDF_FontAttr attr; 30 | 31 | HPDF_PTRACE ((" HPDF_Font_TextWidth\n")); 32 | 33 | if (!HPDF_Font_Validate(font)) 34 | return tw; 35 | 36 | if (len > HPDF_LIMIT_MAX_STRING_LEN) { 37 | HPDF_RaiseError (font->error, HPDF_STRING_OUT_OF_RANGE, 0); 38 | return tw; 39 | } 40 | 41 | attr = (HPDF_FontAttr)font->attr; 42 | 43 | if (!attr->text_width_fn) { 44 | HPDF_SetError (font->error, HPDF_INVALID_OBJECT, 0); 45 | return tw; 46 | } 47 | 48 | tw = attr->text_width_fn (font, text, len); 49 | 50 | return tw; 51 | } 52 | 53 | 54 | HPDF_EXPORT(HPDF_UINT) 55 | HPDF_Font_MeasureText (HPDF_Font font, 56 | const HPDF_BYTE *text, 57 | HPDF_UINT len, 58 | HPDF_REAL width, 59 | HPDF_REAL font_size, 60 | HPDF_REAL char_space, 61 | HPDF_REAL word_space, 62 | HPDF_BOOL wordwrap, 63 | HPDF_REAL *real_width) 64 | { 65 | HPDF_FontAttr attr; 66 | 67 | HPDF_PTRACE ((" HPDF_Font_MeasureText\n")); 68 | 69 | if (!HPDF_Font_Validate(font)) 70 | return 0; 71 | 72 | if (len > HPDF_LIMIT_MAX_STRING_LEN) { 73 | HPDF_RaiseError (font->error, HPDF_STRING_OUT_OF_RANGE, 0); 74 | return 0; 75 | } 76 | 77 | attr = (HPDF_FontAttr)font->attr; 78 | 79 | if (!attr->measure_text_fn) { 80 | HPDF_RaiseError (font->error, HPDF_INVALID_OBJECT, 0); 81 | return 0; 82 | } 83 | 84 | return attr->measure_text_fn (font, text, len, width, font_size, 85 | char_space, word_space, wordwrap, real_width); 86 | } 87 | 88 | 89 | HPDF_EXPORT(const char*) 90 | HPDF_Font_GetFontName (HPDF_Font font) 91 | { 92 | HPDF_FontAttr attr; 93 | 94 | HPDF_PTRACE((" HPDF_Font_GetFontName\n")); 95 | 96 | if (!HPDF_Font_Validate(font)) 97 | return NULL; 98 | 99 | attr = (HPDF_FontAttr)font->attr; 100 | 101 | return attr->fontdef->base_font; 102 | } 103 | 104 | 105 | HPDF_EXPORT(const char*) 106 | HPDF_Font_GetEncodingName (HPDF_Font font) 107 | { 108 | HPDF_FontAttr attr; 109 | 110 | HPDF_PTRACE((" HPDF_Font_GetEncodingName\n")); 111 | 112 | if (!HPDF_Font_Validate(font)) 113 | return NULL; 114 | 115 | attr = (HPDF_FontAttr)font->attr; 116 | 117 | return attr->encoder->name; 118 | } 119 | 120 | 121 | HPDF_EXPORT(HPDF_INT) 122 | HPDF_Font_GetUnicodeWidth (HPDF_Font font, 123 | HPDF_UNICODE code) 124 | { 125 | HPDF_FontAttr attr; 126 | HPDF_FontDef fontdef; 127 | 128 | HPDF_PTRACE((" HPDF_Font_GetUnicodeWidth\n")); 129 | 130 | if (!HPDF_Font_Validate(font)) 131 | return 0; 132 | 133 | attr = (HPDF_FontAttr)font->attr; 134 | fontdef = attr->fontdef; 135 | 136 | if (fontdef->type == HPDF_FONTDEF_TYPE_TYPE1) { 137 | return HPDF_Type1FontDef_GetWidth (fontdef, code); 138 | } else if (fontdef->type == HPDF_FONTDEF_TYPE_TRUETYPE) { 139 | return HPDF_TTFontDef_GetCharWidth (fontdef, code); 140 | } else if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { 141 | HPDF_CMapEncoderAttr encoder_attr = 142 | (HPDF_CMapEncoderAttr)attr->encoder->attr; 143 | HPDF_UINT l, h; 144 | 145 | for (l = 0; l <= 255; l++) { 146 | for (h = 0; h < 255; h++) { 147 | if (code == encoder_attr->unicode_map[l][h]) { 148 | HPDF_UINT16 cid = encoder_attr->cid_map[l][h]; 149 | 150 | return HPDF_CIDFontDef_GetCIDWidth (fontdef, cid); 151 | } 152 | } 153 | } 154 | } 155 | 156 | HPDF_PTRACE((" HPDF_Font_GetUnicodeWidth not found (0x%04X)\n", code)); 157 | 158 | return 0; 159 | } 160 | 161 | 162 | HPDF_EXPORT(HPDF_Box) 163 | HPDF_Font_GetBBox (HPDF_Font font) 164 | { 165 | HPDF_Box bbox = {0, 0, 0, 0}; 166 | 167 | HPDF_PTRACE((" HPDF_Font_GetBBox\n")); 168 | if (HPDF_Font_Validate(font)) 169 | return ((HPDF_FontAttr)font->attr)->fontdef->font_bbox; 170 | 171 | return bbox; 172 | } 173 | 174 | HPDF_EXPORT(HPDF_INT) 175 | HPDF_Font_GetAscent (HPDF_Font font) 176 | { 177 | HPDF_PTRACE((" HPDF_Font_GetAscent\n")); 178 | 179 | if (HPDF_Font_Validate(font)) 180 | return ((HPDF_FontAttr)font->attr)->fontdef->ascent; 181 | 182 | return 0; 183 | } 184 | 185 | HPDF_EXPORT(HPDF_INT) 186 | HPDF_Font_GetDescent (HPDF_Font font) 187 | { 188 | HPDF_PTRACE((" HPDF_Font_GetDescent\n")); 189 | 190 | if (HPDF_Font_Validate(font)) 191 | return ((HPDF_FontAttr)font->attr)->fontdef->descent; 192 | 193 | return 0; 194 | } 195 | 196 | HPDF_EXPORT(HPDF_UINT) 197 | HPDF_Font_GetXHeight (HPDF_Font font) 198 | { 199 | HPDF_PTRACE((" HPDF_Font_GetXHeight\n")); 200 | 201 | if (HPDF_Font_Validate(font)) 202 | return ((HPDF_FontAttr)font->attr)->fontdef->x_height; 203 | 204 | return 0; 205 | } 206 | 207 | HPDF_EXPORT(HPDF_UINT) 208 | HPDF_Font_GetCapHeight (HPDF_Font font) 209 | { 210 | HPDF_PTRACE((" HPDF_Font_GetCapHeight\n")); 211 | 212 | if (HPDF_Font_Validate(font)) 213 | return ((HPDF_FontAttr)font->attr)->fontdef->cap_height; 214 | 215 | return 0; 216 | } 217 | 218 | 219 | HPDF_BOOL 220 | HPDF_Font_Validate (HPDF_Font font) 221 | { 222 | HPDF_PTRACE((" HPDF_Font_Validate\n")); 223 | 224 | if (!font || !font->attr || font->header.obj_class != 225 | (HPDF_OSUBCLASS_FONT | HPDF_OCLASS_DICT)) 226 | return HPDF_FALSE; 227 | 228 | return HPDF_TRUE; 229 | } 230 | 231 | 232 | -------------------------------------------------------------------------------- /libharu/src/hpdf_fontdef.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_fontdef.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_fontdef.h" 21 | 22 | void 23 | HPDF_FontDef_Cleanup (HPDF_FontDef fontdef) 24 | { 25 | if (!fontdef) 26 | return; 27 | 28 | HPDF_PTRACE ((" HPDF_FontDef_Cleanup\n")); 29 | 30 | if (fontdef->clean_fn) 31 | fontdef->clean_fn (fontdef); 32 | 33 | fontdef->descriptor = NULL; 34 | } 35 | 36 | void 37 | HPDF_FontDef_Free (HPDF_FontDef fontdef) 38 | { 39 | if (!fontdef) 40 | return; 41 | 42 | HPDF_PTRACE ((" HPDF_FontDef_Free\n")); 43 | 44 | if (fontdef->free_fn) 45 | fontdef->free_fn (fontdef); 46 | HPDF_FreeMem (fontdef->mmgr, fontdef); 47 | } 48 | 49 | HPDF_BOOL 50 | HPDF_FontDef_Validate (HPDF_FontDef fontdef) 51 | { 52 | HPDF_PTRACE ((" HPDF_FontDef_Validate\n")); 53 | 54 | if (!fontdef || fontdef->sig_bytes != HPDF_FONTDEF_SIG_BYTES) 55 | return HPDF_FALSE; 56 | else 57 | return HPDF_TRUE; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /libharu/src/hpdf_fontdef_cid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_fontdef_cid.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_fontdef.h" 21 | 22 | void 23 | HPDF_CIDFontDef_FreeWidth (HPDF_FontDef fontdef); 24 | 25 | 26 | void 27 | HPDF_CIDFontDef_FreeFunc (HPDF_FontDef fontdef); 28 | 29 | 30 | /*----------------------------------------------------------------------*/ 31 | /*----- HPDF_CIDFontDef ------------------------------------------------*/ 32 | 33 | void 34 | HPDF_CIDFontDef_FreeWidth (HPDF_FontDef fontdef) 35 | { 36 | HPDF_CIDFontDefAttr attr = (HPDF_CIDFontDefAttr)fontdef->attr; 37 | HPDF_UINT i; 38 | 39 | HPDF_PTRACE ((" HPDF_FontDef_Validate\n")); 40 | 41 | for (i = 0; i < attr->widths->count; i++) { 42 | HPDF_CID_Width *w = 43 | (HPDF_CID_Width *)HPDF_List_ItemAt (attr->widths, i); 44 | 45 | HPDF_FreeMem (fontdef->mmgr, w); 46 | } 47 | 48 | HPDF_List_Free (attr->widths); 49 | attr->widths = NULL; 50 | 51 | fontdef->valid = HPDF_FALSE; 52 | } 53 | 54 | 55 | HPDF_FontDef 56 | HPDF_CIDFontDef_New (HPDF_MMgr mmgr, 57 | char *name, 58 | HPDF_FontDef_InitFunc init_fn) 59 | { 60 | HPDF_FontDef fontdef; 61 | HPDF_CIDFontDefAttr fontdef_attr; 62 | 63 | HPDF_PTRACE ((" HPDF_CIDFontDef_New\n")); 64 | 65 | if (!mmgr) 66 | return NULL; 67 | 68 | fontdef = HPDF_GetMem (mmgr, sizeof(HPDF_FontDef_Rec)); 69 | if (!fontdef) 70 | return NULL; 71 | 72 | HPDF_MemSet (fontdef, 0, sizeof(HPDF_FontDef_Rec)); 73 | fontdef->sig_bytes = HPDF_FONTDEF_SIG_BYTES; 74 | HPDF_StrCpy (fontdef->base_font, name, fontdef->base_font + 75 | HPDF_LIMIT_MAX_NAME_LEN); 76 | fontdef->mmgr = mmgr; 77 | fontdef->error = mmgr->error; 78 | fontdef->type = HPDF_FONTDEF_TYPE_UNINITIALIZED; 79 | fontdef->free_fn = HPDF_CIDFontDef_FreeFunc; 80 | fontdef->init_fn = init_fn; 81 | fontdef->valid = HPDF_FALSE; 82 | fontdef_attr = HPDF_GetMem (mmgr, sizeof(HPDF_CIDFontDefAttr_Rec)); 83 | if (!fontdef_attr) { 84 | HPDF_FreeMem (fontdef->mmgr, fontdef); 85 | return NULL; 86 | } 87 | 88 | fontdef->attr = fontdef_attr; 89 | HPDF_MemSet ((HPDF_BYTE *)fontdef_attr, 0, 90 | sizeof(HPDF_CIDFontDefAttr_Rec)); 91 | 92 | fontdef_attr->widths = HPDF_List_New (mmgr, HPDF_DEF_CHAR_WIDTHS_NUM); 93 | if (!fontdef_attr->widths) { 94 | HPDF_FreeMem (fontdef->mmgr, fontdef); 95 | HPDF_FreeMem (fontdef->mmgr, fontdef_attr); 96 | return NULL; 97 | } 98 | 99 | fontdef->missing_width = 500; 100 | fontdef_attr->DW = 1000; 101 | fontdef_attr->DW2[0] = 880; 102 | fontdef_attr->DW2[1] = -1000; 103 | 104 | return fontdef; 105 | } 106 | 107 | 108 | HPDF_INT16 109 | HPDF_CIDFontDef_GetCIDWidth (HPDF_FontDef fontdef, 110 | HPDF_UINT16 cid) 111 | { 112 | HPDF_CIDFontDefAttr attr = (HPDF_CIDFontDefAttr)fontdef->attr; 113 | HPDF_UINT i; 114 | 115 | HPDF_PTRACE ((" HPDF_CIDFontDef_GetCIDWidth\n")); 116 | 117 | for (i = 0; i < attr->widths->count; i++) { 118 | HPDF_CID_Width *w = (HPDF_CID_Width *)HPDF_List_ItemAt (attr->widths, 119 | i); 120 | 121 | if (w->cid == cid) 122 | return w->width; 123 | } 124 | 125 | /* Not found in pdf_cid_width array. */ 126 | return attr->DW; 127 | } 128 | 129 | void 130 | HPDF_CIDFontDef_FreeFunc (HPDF_FontDef fontdef) 131 | { 132 | HPDF_CIDFontDefAttr attr = (HPDF_CIDFontDefAttr)fontdef->attr; 133 | 134 | HPDF_PTRACE ((" HPDF_CIDFontDef_FreeFunc\n")); 135 | 136 | HPDF_CIDFontDef_FreeWidth (fontdef); 137 | HPDF_FreeMem (fontdef->mmgr, attr); 138 | } 139 | 140 | 141 | HPDF_STATUS 142 | HPDF_CIDFontDef_AddWidth (HPDF_FontDef fontdef, 143 | const HPDF_CID_Width *widths) 144 | { 145 | HPDF_CIDFontDefAttr attr = (HPDF_CIDFontDefAttr)fontdef->attr; 146 | 147 | HPDF_PTRACE ((" HPDF_CIDFontDef_AddWidth\n")); 148 | 149 | while (widths->cid != 0xFFFF) { 150 | HPDF_CID_Width *w = HPDF_GetMem (fontdef->mmgr, 151 | sizeof (HPDF_CID_Width)); 152 | HPDF_STATUS ret; 153 | 154 | if (!w) 155 | return fontdef->error->error_no; 156 | 157 | w->cid = widths->cid; 158 | w->width = widths->width; 159 | 160 | if ((ret = HPDF_List_Add (attr->widths, w)) != HPDF_OK) { 161 | HPDF_FreeMem (fontdef->mmgr, w); 162 | 163 | return ret; 164 | } 165 | 166 | widths++; 167 | } 168 | 169 | return HPDF_OK; 170 | } 171 | 172 | 173 | HPDF_STATUS 174 | HPDF_CIDFontDef_ChangeStyle (HPDF_FontDef fontdef, 175 | HPDF_BOOL bold, 176 | HPDF_BOOL italic) 177 | { 178 | HPDF_PTRACE ((" HPDF_CIDFontDef_ChangeStyle\n")); 179 | 180 | if (!fontdef || !fontdef->attr) 181 | return HPDF_INVALID_FONTDEF_DATA; 182 | 183 | if (bold) { 184 | fontdef->stemv *= 2; 185 | fontdef->flags |= HPDF_FONT_FOURCE_BOLD; 186 | } 187 | 188 | if (italic) { 189 | fontdef->italic_angle -= 11; 190 | fontdef->flags |= HPDF_FONT_ITALIC; 191 | } 192 | 193 | return HPDF_OK; 194 | } 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /libharu/src/hpdf_fontdef_cnt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_fontdef_cnt.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf.h" 21 | 22 | /*----------------------------------------------------------------------------*/ 23 | 24 | static const HPDF_CID_Width MING_LIU_W_ARRAY[] = { 25 | {668, 500}, 26 | {669, 500}, 27 | {670, 500}, 28 | {671, 500}, 29 | {672, 500}, 30 | {673, 500}, 31 | {674, 500}, 32 | {675, 500}, 33 | {676, 500}, 34 | {677, 500}, 35 | {678, 500}, 36 | {679, 500}, 37 | {680, 500}, 38 | {681, 500}, 39 | {682, 500}, 40 | {683, 500}, 41 | {684, 500}, 42 | {685, 500}, 43 | {686, 500}, 44 | {687, 500}, 45 | {688, 500}, 46 | {689, 500}, 47 | {690, 500}, 48 | {691, 500}, 49 | {692, 500}, 50 | {693, 500}, 51 | {694, 500}, 52 | {696, 500}, 53 | {697, 500}, 54 | {698, 500}, 55 | {699, 500}, 56 | {814, 500}, 57 | {815, 500}, 58 | {816, 500}, 59 | {817, 500}, 60 | {818, 500}, 61 | {819, 500}, 62 | {820, 500}, 63 | {821, 500}, 64 | {822, 500}, 65 | {823, 500}, 66 | {824, 500}, 67 | {825, 500}, 68 | {826, 500}, 69 | {827, 500}, 70 | {828, 500}, 71 | {829, 500}, 72 | {830, 500}, 73 | {831, 500}, 74 | {832, 500}, 75 | {833, 500}, 76 | {834, 500}, 77 | {835, 500}, 78 | {836, 500}, 79 | {837, 500}, 80 | {838, 500}, 81 | {839, 500}, 82 | {840, 500}, 83 | {841, 500}, 84 | {842, 500}, 85 | {843, 500}, 86 | {844, 500}, 87 | {845, 500}, 88 | {846, 500}, 89 | {847, 500}, 90 | {848, 500}, 91 | {849, 500}, 92 | {850, 500}, 93 | {851, 500}, 94 | {852, 500}, 95 | {853, 500}, 96 | {854, 500}, 97 | {855, 500}, 98 | {856, 500}, 99 | {857, 500}, 100 | {858, 500}, 101 | {859, 500}, 102 | {860, 500}, 103 | {861, 500}, 104 | {862, 500}, 105 | {863, 500}, 106 | {864, 500}, 107 | {865, 500}, 108 | {866, 500}, 109 | {867, 500}, 110 | {868, 500}, 111 | {869, 500}, 112 | {870, 500}, 113 | {871, 500}, 114 | {872, 500}, 115 | {873, 500}, 116 | {874, 500}, 117 | {875, 500}, 118 | {876, 500}, 119 | {877, 500}, 120 | {878, 500}, 121 | {879, 500}, 122 | {880, 500}, 123 | {881, 500}, 124 | {882, 500}, 125 | {883, 500}, 126 | {884, 500}, 127 | {885, 500}, 128 | {886, 500}, 129 | {887, 500}, 130 | {888, 500}, 131 | {889, 500}, 132 | {890, 500}, 133 | {891, 500}, 134 | {892, 500}, 135 | {893, 500}, 136 | {894, 500}, 137 | {895, 500}, 138 | {896, 500}, 139 | {897, 500}, 140 | {898, 500}, 141 | {899, 500}, 142 | {900, 500}, 143 | {901, 500}, 144 | {902, 500}, 145 | {903, 500}, 146 | {904, 500}, 147 | {905, 500}, 148 | {906, 500}, 149 | {907, 500}, 150 | {7716, 500}, 151 | {0xFFFF, 0} 152 | }; 153 | 154 | 155 | static HPDF_STATUS 156 | MingLiU_Init (HPDF_FontDef fontdef) 157 | { 158 | HPDF_STATUS ret; 159 | 160 | HPDF_PTRACE ((" HPDF_FontDef_MingLiU_Init\n")); 161 | 162 | fontdef->ascent = 800; 163 | fontdef->descent = -199; 164 | fontdef->cap_height = 769; 165 | fontdef->font_bbox = HPDF_ToBox(0, -199, 1000, 800); 166 | fontdef->flags = HPDF_FONT_SYMBOLIC + HPDF_FONT_FIXED_WIDTH + 167 | HPDF_FONT_SERIF; 168 | fontdef->italic_angle = 0; 169 | fontdef->stemv = 78; 170 | if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, MING_LIU_W_ARRAY)) != 171 | HPDF_OK) { 172 | return ret; 173 | } 174 | 175 | fontdef->type = HPDF_FONTDEF_TYPE_CID; 176 | fontdef->valid = HPDF_TRUE; 177 | 178 | return HPDF_OK; 179 | } 180 | 181 | 182 | static HPDF_STATUS 183 | MingLiU_Bold_Init (HPDF_FontDef fontdef) 184 | { 185 | HPDF_STATUS ret = MingLiU_Init (fontdef); 186 | 187 | if (ret != HPDF_OK) 188 | return ret; 189 | 190 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_TRUE, HPDF_FALSE); 191 | } 192 | 193 | 194 | static HPDF_STATUS 195 | MingLiU_Italic_Init (HPDF_FontDef fontdef) 196 | { 197 | HPDF_STATUS ret = MingLiU_Init (fontdef); 198 | 199 | if (ret != HPDF_OK) 200 | return ret; 201 | 202 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_FALSE, HPDF_TRUE); 203 | } 204 | 205 | static HPDF_STATUS 206 | MingLiU_BoldItalic_Init (HPDF_FontDef fontdef) 207 | { 208 | HPDF_STATUS ret = MingLiU_Init (fontdef); 209 | 210 | if (ret != HPDF_OK) 211 | return ret; 212 | 213 | return HPDF_CIDFontDef_ChangeStyle (fontdef, HPDF_TRUE, HPDF_TRUE); 214 | } 215 | 216 | 217 | HPDF_EXPORT(HPDF_STATUS) 218 | HPDF_UseCNTFonts (HPDF_Doc pdf) 219 | { 220 | HPDF_FontDef fontdef; 221 | HPDF_STATUS ret; 222 | 223 | if (!HPDF_HasDoc (pdf)) 224 | return HPDF_INVALID_DOCUMENT; 225 | 226 | /* MingLiU */ 227 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MingLiU", 228 | MingLiU_Init); 229 | 230 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) 231 | return ret; 232 | 233 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MingLiU,Bold", 234 | MingLiU_Bold_Init); 235 | 236 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) 237 | return ret; 238 | 239 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MingLiU,Italic", 240 | MingLiU_Italic_Init); 241 | 242 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) 243 | return ret; 244 | 245 | fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MingLiU,BoldItalic", 246 | MingLiU_BoldItalic_Init); 247 | 248 | if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) 249 | return ret; 250 | 251 | return HPDF_OK; 252 | } 253 | 254 | -------------------------------------------------------------------------------- /libharu/src/hpdf_gstate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_gstate.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_gstate.h" 21 | 22 | HPDF_GState 23 | HPDF_GState_New (HPDF_MMgr mmgr, 24 | HPDF_GState current) 25 | { 26 | HPDF_GState gstate; 27 | 28 | if (current && current->depth >= HPDF_LIMIT_MAX_GSTATE) { 29 | HPDF_SetError (mmgr->error, HPDF_EXCEED_GSTATE_LIMIT, 0); 30 | 31 | return NULL; 32 | } 33 | 34 | gstate = HPDF_GetMem (mmgr, sizeof(HPDF_GState_Rec)); 35 | if (!gstate) 36 | return NULL; 37 | 38 | if (current) { 39 | gstate->trans_matrix = current->trans_matrix; 40 | gstate->line_width = current->line_width; 41 | gstate->line_cap = current->line_cap; 42 | gstate->line_join = current->line_join; 43 | gstate->miter_limit = current->miter_limit; 44 | gstate->dash_mode = current->dash_mode; 45 | gstate->flatness = current->flatness; 46 | 47 | gstate->char_space = current->char_space; 48 | gstate->word_space = current->word_space; 49 | gstate->h_scalling = current->h_scalling; 50 | gstate->text_leading = current->text_leading; 51 | gstate->rendering_mode = current->rendering_mode; 52 | gstate->text_rise = current->text_rise; 53 | 54 | gstate->cs_stroke = current->cs_stroke; 55 | gstate->cs_fill = current->cs_fill; 56 | gstate->rgb_fill = current->rgb_fill; 57 | gstate->rgb_stroke = current->rgb_stroke; 58 | gstate->cmyk_fill = current->cmyk_fill; 59 | gstate->cmyk_stroke = current->cmyk_stroke; 60 | gstate->gray_fill = current->gray_fill; 61 | gstate->gray_stroke = current->gray_stroke; 62 | 63 | gstate->font = current->font; 64 | gstate->font_size = current->font_size; 65 | gstate->writing_mode = current->writing_mode; 66 | 67 | gstate->prev = current; 68 | gstate->depth = current->depth + 1; 69 | } else { 70 | HPDF_TransMatrix DEF_MATRIX = {1, 0, 0, 1, 0, 0}; 71 | HPDF_RGBColor DEF_RGB_COLOR = {0, 0, 0}; 72 | HPDF_CMYKColor DEF_CMYK_COLOR = {0, 0, 0, 0}; 73 | HPDF_DashMode DEF_DASH_MODE = {{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, 0.0f, 0.0f}; 74 | 75 | gstate->trans_matrix = DEF_MATRIX; 76 | gstate->line_width = HPDF_DEF_LINEWIDTH; 77 | gstate->line_cap = HPDF_DEF_LINECAP; 78 | gstate->line_join = HPDF_DEF_LINEJOIN; 79 | gstate->miter_limit = HPDF_DEF_MITERLIMIT; 80 | gstate->dash_mode = DEF_DASH_MODE; 81 | gstate->flatness = HPDF_DEF_FLATNESS; 82 | 83 | gstate->char_space = HPDF_DEF_CHARSPACE; 84 | gstate->word_space = HPDF_DEF_WORDSPACE; 85 | gstate->h_scalling = HPDF_DEF_HSCALING; 86 | gstate->text_leading = HPDF_DEF_LEADING; 87 | gstate->rendering_mode = HPDF_DEF_RENDERING_MODE; 88 | gstate->text_rise = HPDF_DEF_RISE; 89 | 90 | gstate->cs_stroke = HPDF_CS_DEVICE_GRAY; 91 | gstate->cs_fill = HPDF_CS_DEVICE_GRAY; 92 | gstate->rgb_fill = DEF_RGB_COLOR; 93 | gstate->rgb_stroke = DEF_RGB_COLOR; 94 | gstate->cmyk_fill = DEF_CMYK_COLOR; 95 | gstate->cmyk_stroke = DEF_CMYK_COLOR; 96 | gstate->gray_fill = 0; 97 | gstate->gray_stroke = 0; 98 | 99 | gstate->font = NULL; 100 | gstate->font_size = 0; 101 | gstate->writing_mode = HPDF_WMODE_HORIZONTAL; 102 | 103 | gstate->prev = NULL; 104 | gstate->depth = 1; 105 | } 106 | 107 | return gstate; 108 | } 109 | 110 | HPDF_GState 111 | HPDF_GState_Free (HPDF_MMgr mmgr, 112 | HPDF_GState gstate) 113 | { 114 | HPDF_GState current = NULL; 115 | 116 | if (gstate) { 117 | current = gstate->prev; 118 | HPDF_FreeMem (mmgr, gstate); 119 | } 120 | 121 | return current; 122 | } 123 | 124 | -------------------------------------------------------------------------------- /libharu/src/hpdf_info.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_info.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_info.h" 21 | 22 | static const char * const HPDF_INFO_ATTR_NAMES[] = { 23 | "CreationDate", 24 | "ModDate", 25 | "Author", 26 | "Creator", 27 | "Producer", 28 | "Title", 29 | "Subject", 30 | "Keywords", 31 | "Trapped", 32 | "GTS_PDFXVersion", 33 | NULL 34 | }; 35 | 36 | 37 | static const char* 38 | InfoTypeToName (HPDF_InfoType type); 39 | 40 | 41 | /*---------------------------------------------------------------------------*/ 42 | 43 | static const char* 44 | InfoTypeToName (HPDF_InfoType type) 45 | { 46 | HPDF_UINT idx = (HPDF_UINT)type; 47 | 48 | return HPDF_INFO_ATTR_NAMES[idx]; 49 | } 50 | 51 | 52 | HPDF_STATUS 53 | HPDF_Info_SetInfoAttr (HPDF_Dict info, 54 | HPDF_InfoType type, 55 | const char *value, 56 | HPDF_Encoder encoder) 57 | { 58 | const char* name = InfoTypeToName (type); 59 | 60 | HPDF_PTRACE((" HPDF_Info_SetInfoAttr\n")); 61 | 62 | if (type <= HPDF_INFO_MOD_DATE) 63 | return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0); 64 | 65 | if (type == HPDF_INFO_TRAPPED) 66 | return HPDF_Dict_AddName(info, name, value); 67 | 68 | return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, value, 69 | encoder)); 70 | } 71 | 72 | 73 | const char* 74 | HPDF_Info_GetInfoAttr (HPDF_Dict info, 75 | HPDF_InfoType type) 76 | { 77 | const char* name = InfoTypeToName (type); 78 | HPDF_String s; 79 | 80 | HPDF_PTRACE((" HPDF_Info_GetInfoAttr\n")); 81 | 82 | if (!info) 83 | return NULL; 84 | 85 | s = HPDF_Dict_GetItem (info, name, HPDF_OCLASS_STRING); 86 | 87 | if (!s) 88 | return NULL; 89 | else 90 | return (const char *)(s->value); 91 | } 92 | 93 | 94 | HPDF_STATUS 95 | HPDF_Info_SetInfoDateAttr (HPDF_Dict info, 96 | HPDF_InfoType type, 97 | HPDF_Date value) 98 | { 99 | char tmp[HPDF_DATE_TIME_STR_LEN + 1]; 100 | char* ptmp; 101 | const char* name = InfoTypeToName (type); 102 | 103 | HPDF_PTRACE((" HPDF_Info_SetInfoDateAttr\n")); 104 | 105 | if (type > HPDF_INFO_MOD_DATE) 106 | return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0); 107 | 108 | HPDF_MemSet (tmp, 0, HPDF_DATE_TIME_STR_LEN + 1); 109 | if (value.month < 1 || 12 < value.month || 110 | value.day < 1 || 111 | 23 < value.hour || 112 | 59 < value.minutes || 113 | 59 < value.seconds || 114 | (value.ind != '+' && value.ind != '-' && value.ind != 'Z' && 115 | value.ind != ' ') || 116 | 23 < value.off_hour || 117 | 59 < value.off_minutes) { 118 | return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0); 119 | } 120 | 121 | switch (value.month) { 122 | case 1: 123 | case 3: 124 | case 5: 125 | case 7: 126 | case 8: 127 | case 10: 128 | case 12: 129 | if (value.day > 31) 130 | return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0); 131 | 132 | break; 133 | case 4: 134 | case 6: 135 | case 9: 136 | case 11: 137 | if (value.day > 30) 138 | return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0); 139 | 140 | break; 141 | case 2: 142 | if (value.day > 29 || (value.day == 29 && 143 | (value.year % 4 != 0 || 144 | (value.year % 100 == 0 && value.year % 400 != 0)))) 145 | return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0); 146 | 147 | break; 148 | default: 149 | return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0); 150 | } 151 | 152 | ptmp = (char *)HPDF_MemCpy ((HPDF_BYTE *)tmp, (HPDF_BYTE *)"D:", 2); 153 | ptmp = HPDF_IToA2 (ptmp, value.year, 5); 154 | ptmp = HPDF_IToA2 (ptmp, value.month, 3); 155 | ptmp = HPDF_IToA2 (ptmp, value.day, 3); 156 | ptmp = HPDF_IToA2 (ptmp, value.hour, 3); 157 | ptmp = HPDF_IToA2 (ptmp, value.minutes, 3); 158 | ptmp = HPDF_IToA2 (ptmp, value.seconds, 3); 159 | if (value.ind != ' ') { 160 | *ptmp++ = value.ind; 161 | ptmp = HPDF_IToA2 (ptmp, value.off_hour, 3); 162 | *ptmp++ = '\''; 163 | ptmp = HPDF_IToA2 (ptmp, value.off_minutes, 3); 164 | *ptmp++ = '\''; 165 | } 166 | *ptmp = 0; 167 | 168 | return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, tmp, 169 | NULL)); 170 | } 171 | 172 | 173 | -------------------------------------------------------------------------------- /libharu/src/hpdf_mmgr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_mmgr.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_consts.h" 20 | #include "hpdf_mmgr.h" 21 | #include "hpdf_utils.h" 22 | 23 | #ifndef HPDF_STDCALL 24 | #ifdef HPDF_DLL_MAKE 25 | #define HPDF_STDCALL __stdcall 26 | #else 27 | #ifdef HPDF_DLL 28 | #define HPDF_STDCALL __stdcall 29 | #else 30 | #define HPDF_STDCALL 31 | #endif 32 | #endif 33 | #endif 34 | 35 | static void * HPDF_STDCALL 36 | InternalGetMem (HPDF_UINT size); 37 | 38 | static void HPDF_STDCALL 39 | InternalFreeMem (void* aptr); 40 | 41 | 42 | HPDF_MMgr 43 | HPDF_MMgr_New (HPDF_Error error, 44 | HPDF_UINT buf_size, 45 | HPDF_Alloc_Func alloc_fn, 46 | HPDF_Free_Func free_fn) 47 | { 48 | HPDF_MMgr mmgr; 49 | 50 | HPDF_PTRACE((" HPDF_MMgr_New\n")); 51 | 52 | if (alloc_fn) 53 | mmgr = (HPDF_MMgr)alloc_fn (sizeof(HPDF_MMgr_Rec)); 54 | else 55 | mmgr = (HPDF_MMgr)InternalGetMem (sizeof(HPDF_MMgr_Rec)); 56 | 57 | HPDF_PTRACE(("+%p mmgr-new\n", mmgr)); 58 | 59 | if (mmgr != NULL) { 60 | /* initialize mmgr object */ 61 | mmgr->error = error; 62 | 63 | 64 | #ifdef HPDF_MEM_DEBUG 65 | mmgr->alloc_cnt = 0; 66 | mmgr->free_cnt = 0; 67 | #endif 68 | /* 69 | * if alloc_fn and free_fn are specified, these function is 70 | * used. if not, default function (maybe these will be "malloc" and 71 | * "free") is used. 72 | */ 73 | if (alloc_fn && free_fn) { 74 | mmgr->alloc_fn = alloc_fn; 75 | mmgr->free_fn = free_fn; 76 | } else { 77 | mmgr->alloc_fn = InternalGetMem; 78 | mmgr->free_fn = InternalFreeMem; 79 | } 80 | 81 | /* 82 | * if buf_size parameter is specified, this object is configured 83 | * to be using memory-pool. 84 | * 85 | */ 86 | if (!buf_size) 87 | mmgr->mpool = NULL; 88 | else { 89 | HPDF_MPool_Node node; 90 | 91 | node = (HPDF_MPool_Node)mmgr->alloc_fn (sizeof(HPDF_MPool_Node_Rec) + 92 | buf_size); 93 | 94 | HPDF_PTRACE(("+%p mmgr-node-new\n", node)); 95 | 96 | if (node == NULL) { 97 | HPDF_SetError (error, HPDF_FAILD_TO_ALLOC_MEM, HPDF_NOERROR); 98 | 99 | mmgr->free_fn(mmgr); 100 | mmgr = NULL; 101 | } else { 102 | mmgr->mpool = node; 103 | node->buf = (HPDF_BYTE *)node + sizeof(HPDF_MPool_Node_Rec); 104 | node->size = buf_size; 105 | node->used_size = 0; 106 | node->next_node = NULL; 107 | } 108 | 109 | #ifdef HPDF_MEM_DEBUG 110 | if (mmgr) { 111 | mmgr->alloc_cnt += 1; 112 | } 113 | #endif 114 | } 115 | 116 | if (mmgr) { 117 | mmgr->buf_size = buf_size; 118 | } 119 | } else 120 | HPDF_SetError(error, HPDF_FAILD_TO_ALLOC_MEM, HPDF_NOERROR); 121 | 122 | return mmgr; 123 | } 124 | 125 | void 126 | HPDF_MMgr_Free (HPDF_MMgr mmgr) 127 | { 128 | HPDF_MPool_Node node; 129 | 130 | HPDF_PTRACE((" HPDF_MMgr_Free\n")); 131 | 132 | if (mmgr == NULL) 133 | return; 134 | 135 | node = mmgr->mpool; 136 | 137 | /* delete all nodes recursively */ 138 | while (node != NULL) { 139 | HPDF_MPool_Node tmp = node; 140 | node = tmp->next_node; 141 | 142 | HPDF_PTRACE(("-%p mmgr-node-free\n", tmp)); 143 | mmgr->free_fn (tmp); 144 | 145 | #ifdef HPDF_MEM_DEBUG 146 | mmgr->free_cnt++; 147 | #endif 148 | 149 | } 150 | 151 | #ifdef HPDF_MEM_DEBUG 152 | HPDF_PRINTF ("# HPDF_MMgr alloc-cnt=%u, free-cnt=%u\n", 153 | mmgr->alloc_cnt, mmgr->free_cnt); 154 | 155 | if (mmgr->alloc_cnt != mmgr->free_cnt) 156 | HPDF_PRINTF ("# ERROR #\n"); 157 | #endif 158 | 159 | HPDF_PTRACE(("-%p mmgr-free\n", mmgr)); 160 | mmgr->free_fn (mmgr); 161 | } 162 | 163 | void* 164 | HPDF_GetMem (HPDF_MMgr mmgr, 165 | HPDF_UINT size) 166 | { 167 | void * ptr; 168 | 169 | if (mmgr->mpool) { 170 | HPDF_MPool_Node node = mmgr->mpool; 171 | 172 | #ifdef HPDF_ALINMENT_SIZ 173 | size = (size + (HPDF_ALINMENT_SIZ - 1)) / HPDF_ALINMENT_SIZ; 174 | size *= HPDF_ALINMENT_SIZ; 175 | #endif 176 | 177 | if (node->size - node->used_size >= size) { 178 | ptr = (HPDF_BYTE*)node->buf + node->used_size; 179 | node->used_size += size; 180 | return ptr; 181 | } else { 182 | HPDF_UINT tmp_buf_siz = (mmgr->buf_size < size) ? size : 183 | mmgr->buf_size; 184 | 185 | node = (HPDF_MPool_Node)mmgr->alloc_fn (sizeof(HPDF_MPool_Node_Rec) 186 | + tmp_buf_siz); 187 | HPDF_PTRACE(("+%p mmgr-new-node\n", node)); 188 | 189 | if (!node) { 190 | HPDF_SetError (mmgr->error, HPDF_FAILD_TO_ALLOC_MEM, 191 | HPDF_NOERROR); 192 | return NULL; 193 | } 194 | 195 | node->size = tmp_buf_siz; 196 | } 197 | 198 | node->next_node = mmgr->mpool; 199 | mmgr->mpool = node; 200 | node->used_size = size; 201 | node->buf = (HPDF_BYTE*)node + sizeof(HPDF_MPool_Node_Rec); 202 | ptr = node->buf; 203 | } else { 204 | ptr = mmgr->alloc_fn (size); 205 | HPDF_PTRACE(("+%p mmgr-alloc_fn size=%u\n", ptr, size)); 206 | 207 | if (ptr == NULL) 208 | HPDF_SetError (mmgr->error, HPDF_FAILD_TO_ALLOC_MEM, HPDF_NOERROR); 209 | } 210 | 211 | #ifdef HPDF_MEM_DEBUG 212 | if (ptr) 213 | mmgr->alloc_cnt++; 214 | #endif 215 | 216 | return ptr; 217 | } 218 | 219 | void 220 | HPDF_FreeMem (HPDF_MMgr mmgr, 221 | void *aptr) 222 | { 223 | if (!aptr) 224 | return; 225 | 226 | if (!mmgr->mpool) { 227 | HPDF_PTRACE(("-%p mmgr-free-mem\n", aptr)); 228 | mmgr->free_fn(aptr); 229 | 230 | #ifdef HPDF_MEM_DEBUG 231 | mmgr->free_cnt++; 232 | #endif 233 | } 234 | 235 | return; 236 | } 237 | 238 | static void * HPDF_STDCALL 239 | InternalGetMem (HPDF_UINT size) 240 | { 241 | return HPDF_MALLOC (size); 242 | } 243 | 244 | static void HPDF_STDCALL 245 | InternalFreeMem (void* aptr) 246 | { 247 | HPDF_FREE (aptr); 248 | } 249 | 250 | 251 | -------------------------------------------------------------------------------- /libharu/src/hpdf_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_name.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_objects.h" 21 | 22 | 23 | HPDF_Name 24 | HPDF_Name_New (HPDF_MMgr mmgr, 25 | const char *value) 26 | { 27 | HPDF_Name obj; 28 | 29 | obj = HPDF_GetMem (mmgr, sizeof(HPDF_Name_Rec)); 30 | 31 | if (obj) { 32 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); 33 | obj->header.obj_class = HPDF_OCLASS_NAME; 34 | obj->error = mmgr->error; 35 | if (HPDF_Name_SetValue (obj, value) == HPDF_NAME_INVALID_VALUE) { 36 | HPDF_FreeMem (mmgr, obj); 37 | return NULL; 38 | } 39 | } 40 | 41 | return obj; 42 | } 43 | 44 | 45 | HPDF_STATUS 46 | HPDF_Name_Write (HPDF_Name obj, 47 | HPDF_Stream stream) 48 | { 49 | return HPDF_Stream_WriteEscapeName (stream, obj->value); 50 | } 51 | 52 | 53 | HPDF_STATUS 54 | HPDF_Name_SetValue (HPDF_Name obj, 55 | const char *value) 56 | { 57 | if (!value || value[0] == 0) 58 | return HPDF_SetError (obj->error, HPDF_NAME_INVALID_VALUE, 0); 59 | 60 | if (HPDF_StrLen (value, HPDF_LIMIT_MAX_NAME_LEN + 1) > 61 | HPDF_LIMIT_MAX_NAME_LEN) 62 | return HPDF_SetError (obj->error, HPDF_NAME_OUT_OF_RANGE, 0); 63 | 64 | HPDF_StrCpy (obj->value, value, obj->value + HPDF_LIMIT_MAX_NAME_LEN); 65 | 66 | return HPDF_OK; 67 | } 68 | 69 | const char* 70 | HPDF_Name_GetValue (HPDF_Name obj) 71 | { 72 | return (const char *)obj->value; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /libharu/src/hpdf_namedict.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_namedict.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_consts.h" 21 | #include "hpdf_namedict.h" 22 | 23 | #ifndef HPDF_UNUSED 24 | #define HPDF_UNUSED(a) ((void)(a)) 25 | #endif 26 | 27 | static const char * const HPDF_NAMEDICT_KEYS[] = { 28 | "EmbeddedFiles" 29 | }; 30 | 31 | HPDF_NameDict 32 | HPDF_NameDict_New (HPDF_MMgr mmgr, 33 | HPDF_Xref xref) 34 | { 35 | HPDF_NameDict ndict; 36 | 37 | HPDF_PTRACE((" HPDF_NameDict_New\n")); 38 | 39 | ndict = HPDF_Dict_New (mmgr); 40 | if (!ndict) 41 | return NULL; 42 | 43 | if (HPDF_Xref_Add (xref, ndict) != HPDF_OK) 44 | return NULL; 45 | 46 | ndict->header.obj_class |= HPDF_OSUBCLASS_NAMEDICT; 47 | 48 | return ndict; 49 | } 50 | 51 | HPDF_NameTree 52 | HPDF_NameDict_GetNameTree (HPDF_NameDict namedict, 53 | HPDF_NameDictKey key) 54 | { 55 | if (!namedict) 56 | return NULL; 57 | return HPDF_Dict_GetItem (namedict, HPDF_NAMEDICT_KEYS[key], HPDF_OCLASS_DICT); 58 | } 59 | 60 | HPDF_STATUS 61 | HPDF_NameDict_SetNameTree (HPDF_NameDict namedict, 62 | HPDF_NameDictKey key, 63 | HPDF_NameTree ntree) 64 | { 65 | return HPDF_Dict_Add (namedict, HPDF_NAMEDICT_KEYS[key], ntree); 66 | } 67 | 68 | HPDF_BOOL 69 | HPDF_NameDict_Validate (HPDF_NameDict namedict) 70 | { 71 | if (!namedict) 72 | return HPDF_FALSE; 73 | 74 | if (namedict->header.obj_class != (HPDF_OSUBCLASS_NAMEDICT | 75 | HPDF_OCLASS_DICT)) { 76 | HPDF_SetError (namedict->error, HPDF_INVALID_OBJECT, 0); 77 | return HPDF_FALSE; 78 | } 79 | 80 | return HPDF_TRUE; 81 | } 82 | 83 | 84 | /*------- NameTree -------*/ 85 | 86 | HPDF_NameTree 87 | HPDF_NameTree_New (HPDF_MMgr mmgr, 88 | HPDF_Xref xref) 89 | { 90 | HPDF_STATUS ret = HPDF_OK; 91 | HPDF_NameTree ntree; 92 | HPDF_Array items; 93 | 94 | HPDF_PTRACE((" HPDF_NameTree_New\n")); 95 | 96 | ntree = HPDF_Dict_New (mmgr); 97 | if (!ntree) 98 | return NULL; 99 | 100 | if (HPDF_Xref_Add (xref, ntree) != HPDF_OK) 101 | return NULL; 102 | 103 | ntree->header.obj_class |= HPDF_OSUBCLASS_NAMETREE; 104 | 105 | items = HPDF_Array_New (mmgr); 106 | if (!ntree) 107 | return NULL; 108 | 109 | ret += HPDF_Dict_Add (ntree, "Names", items); 110 | if (ret != HPDF_OK) 111 | return NULL; 112 | 113 | return ntree; 114 | } 115 | 116 | HPDF_STATUS 117 | HPDF_NameTree_Add (HPDF_NameTree tree, 118 | HPDF_String name, 119 | void *obj) 120 | { 121 | HPDF_Array items; 122 | HPDF_INT32 i, icount; 123 | 124 | if (!tree || !name) 125 | return HPDF_INVALID_PARAMETER; 126 | 127 | items = HPDF_Dict_GetItem (tree, "Names", HPDF_OCLASS_ARRAY); 128 | if (!items) 129 | return HPDF_INVALID_OBJECT; 130 | 131 | /* "The keys shall be sorted in lexical order" -- 7.9.6, Name Trees. 132 | * Since we store keys sorted, it's best to do a linear insertion sort 133 | * Find the first element larger than 'key', and insert 'key' and then 134 | * 'obj' into the items. */ 135 | 136 | icount = HPDF_Array_Items(items); 137 | 138 | for( i = 0; i < icount; i += 2 ) { 139 | HPDF_String elem = HPDF_Array_GetItem( items, i, HPDF_OCLASS_STRING ); 140 | if( HPDF_String_Cmp( name, elem ) < 0 ) { 141 | HPDF_Array_Insert( items, elem, name ); 142 | HPDF_Array_Insert( items, elem, obj ); 143 | return HPDF_OK; 144 | } 145 | } 146 | 147 | /* Items list is empty */ 148 | HPDF_Array_Add(items, name); 149 | HPDF_Array_Add(items, obj); 150 | return HPDF_OK; 151 | } 152 | 153 | HPDF_BOOL 154 | HPDF_NameTree_Validate (HPDF_NameTree nametree) 155 | { 156 | if (!nametree) 157 | return HPDF_FALSE; 158 | 159 | if (nametree->header.obj_class != (HPDF_OSUBCLASS_NAMETREE | 160 | HPDF_OCLASS_DICT)) { 161 | HPDF_SetError (nametree->error, HPDF_INVALID_OBJECT, 0); 162 | return HPDF_FALSE; 163 | } 164 | 165 | return HPDF_TRUE; 166 | } 167 | 168 | 169 | /*------- EmbeddedFile -------*/ 170 | 171 | HPDF_EmbeddedFile 172 | HPDF_EmbeddedFile_New (HPDF_MMgr mmgr, 173 | HPDF_Xref xref, 174 | const char *file) 175 | { 176 | HPDF_STATUS ret = HPDF_OK; 177 | HPDF_Dict ef; /* the dictionary for the embedded file: /Type /EF */ 178 | HPDF_String name; /* the name of the file: /F (name) */ 179 | HPDF_Dict eff; /* ef has an /EF <> key - this is it */ 180 | HPDF_Dict filestream; /* the stream that /EF <> refers to */ 181 | HPDF_Stream stream; 182 | 183 | ef = HPDF_Dict_New (mmgr); 184 | if (!ef) 185 | return NULL; 186 | if (HPDF_Xref_Add (xref, ef) != HPDF_OK) 187 | return NULL; 188 | 189 | filestream = HPDF_DictStream_New (mmgr, xref); 190 | if (!filestream) 191 | return NULL; 192 | stream = HPDF_FileReader_New (mmgr, file); 193 | if (!stream) 194 | return NULL; 195 | HPDF_Stream_Free(filestream->stream); 196 | filestream->stream = stream; 197 | filestream->filter = HPDF_STREAM_FILTER_FLATE_DECODE; 198 | 199 | eff = HPDF_Dict_New (mmgr); 200 | if (!eff) 201 | return NULL; 202 | 203 | name = HPDF_String_New (mmgr, file, NULL); 204 | if (!name) 205 | return NULL; 206 | 207 | ret += HPDF_Dict_AddName (ef, "Type", "F"); 208 | ret += HPDF_Dict_Add (ef, "F", name); 209 | ret += HPDF_Dict_Add (ef, "EF", eff); 210 | ret += HPDF_Dict_Add (eff, "F", filestream); 211 | 212 | if (ret != HPDF_OK) 213 | return NULL; 214 | 215 | return ef; 216 | } 217 | 218 | HPDF_BOOL 219 | HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile) 220 | { 221 | HPDF_UNUSED (emfile); 222 | return HPDF_TRUE; 223 | } 224 | -------------------------------------------------------------------------------- /libharu/src/hpdf_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_null.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_utils.h" 19 | #include "hpdf_objects.h" 20 | 21 | 22 | HPDF_Null 23 | HPDF_Null_New (HPDF_MMgr mmgr) 24 | { 25 | HPDF_Null obj = HPDF_GetMem (mmgr, sizeof(HPDF_Null_Rec)); 26 | 27 | if (obj) { 28 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); 29 | obj->header.obj_class = HPDF_OCLASS_NULL; 30 | } 31 | 32 | return obj; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /libharu/src/hpdf_number.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_number.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_utils.h" 19 | #include "hpdf_objects.h" 20 | 21 | 22 | HPDF_Number 23 | HPDF_Number_New (HPDF_MMgr mmgr, 24 | HPDF_INT32 value) 25 | { 26 | HPDF_Number obj = HPDF_GetMem (mmgr, sizeof(HPDF_Number_Rec)); 27 | 28 | if (obj) { 29 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); 30 | obj->header.obj_class = HPDF_OCLASS_NUMBER; 31 | obj->value = value; 32 | } 33 | 34 | return obj; 35 | } 36 | 37 | 38 | HPDF_STATUS 39 | HPDF_Number_Write (HPDF_Number obj, 40 | HPDF_Stream stream) 41 | { 42 | return HPDF_Stream_WriteInt (stream, obj->value); 43 | } 44 | 45 | 46 | void 47 | HPDF_Number_SetValue (HPDF_Number obj, 48 | HPDF_INT32 value) 49 | { 50 | obj->value =value; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /libharu/src/hpdf_objects.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_objects.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_objects.h" 21 | 22 | void 23 | HPDF_Obj_Free (HPDF_MMgr mmgr, 24 | void *obj) 25 | { 26 | HPDF_Obj_Header *header; 27 | 28 | HPDF_PTRACE((" HPDF_Obj_Free\n")); 29 | 30 | if (!obj) 31 | return; 32 | 33 | header = (HPDF_Obj_Header *)obj; 34 | 35 | if (!(header->obj_id & HPDF_OTYPE_INDIRECT)) 36 | HPDF_Obj_ForceFree (mmgr, obj); 37 | } 38 | 39 | 40 | void 41 | HPDF_Obj_ForceFree (HPDF_MMgr mmgr, 42 | void *obj) 43 | { 44 | HPDF_Obj_Header *header; 45 | 46 | HPDF_PTRACE((" HPDF_Obj_ForceFree\n")); 47 | 48 | if (!obj) 49 | return; 50 | 51 | header = (HPDF_Obj_Header *)obj; 52 | 53 | HPDF_PTRACE((" HPDF_Obj_ForceFree obj=0x%08X obj_id=0x%08X " 54 | "obj_class=0x%08X\n", 55 | (HPDF_UINT)obj, (HPDF_UINT)(header->obj_id), 56 | (HPDF_UINT)(header->obj_class))); 57 | 58 | switch (header->obj_class & HPDF_OCLASS_ANY) { 59 | case HPDF_OCLASS_STRING: 60 | HPDF_String_Free (obj); 61 | break; 62 | case HPDF_OCLASS_BINARY: 63 | HPDF_Binary_Free (obj); 64 | break; 65 | case HPDF_OCLASS_ARRAY: 66 | HPDF_Array_Free (obj); 67 | break; 68 | case HPDF_OCLASS_DICT: 69 | HPDF_Dict_Free (obj); 70 | break; 71 | case HPDF_OCLASS_DIRECT: 72 | HPDF_Direct_Free (obj); 73 | break; 74 | default: 75 | HPDF_FreeMem (mmgr, obj); 76 | } 77 | } 78 | 79 | HPDF_STATUS 80 | HPDF_Obj_Write (void *obj, 81 | HPDF_Stream stream, 82 | HPDF_Encrypt e) 83 | { 84 | HPDF_Obj_Header *header = (HPDF_Obj_Header *)obj; 85 | 86 | HPDF_PTRACE((" HPDF_Obj_Write\n")); 87 | 88 | if (header->obj_id & HPDF_OTYPE_HIDDEN) { 89 | HPDF_PTRACE(("#HPDF_Obj_Write obj=0x%08X skipped\n", (HPDF_UINT)obj)); 90 | return HPDF_OK; 91 | } 92 | 93 | if (header->obj_class == HPDF_OCLASS_PROXY) { 94 | char buf[HPDF_SHORT_BUF_SIZ]; 95 | char *pbuf = buf; 96 | char *eptr = buf + HPDF_SHORT_BUF_SIZ - 1; 97 | HPDF_Proxy p = obj; 98 | 99 | header = (HPDF_Obj_Header*)p->obj; 100 | 101 | pbuf = HPDF_IToA (pbuf, header->obj_id & 0x00FFFFFF, eptr); 102 | *pbuf++ = ' '; 103 | pbuf = HPDF_IToA (pbuf, header->gen_no, eptr); 104 | HPDF_StrCpy(pbuf, " R", eptr); 105 | 106 | return HPDF_Stream_WriteStr(stream, buf); 107 | } 108 | 109 | return HPDF_Obj_WriteValue(obj, stream, e); 110 | } 111 | 112 | HPDF_STATUS 113 | HPDF_Obj_WriteValue (void *obj, 114 | HPDF_Stream stream, 115 | HPDF_Encrypt e) 116 | { 117 | HPDF_Obj_Header *header; 118 | HPDF_STATUS ret; 119 | 120 | HPDF_PTRACE((" HPDF_Obj_WriteValue\n")); 121 | 122 | header = (HPDF_Obj_Header *)obj; 123 | 124 | HPDF_PTRACE((" HPDF_Obj_WriteValue obj=0x%08X obj_class=0x%04X\n", 125 | (HPDF_UINT)obj, (HPDF_UINT)header->obj_class)); 126 | 127 | switch (header->obj_class & HPDF_OCLASS_ANY) { 128 | case HPDF_OCLASS_NAME: 129 | ret = HPDF_Name_Write (obj, stream); 130 | break; 131 | case HPDF_OCLASS_NUMBER: 132 | ret = HPDF_Number_Write (obj, stream); 133 | break; 134 | case HPDF_OCLASS_REAL: 135 | ret = HPDF_Real_Write (obj, stream); 136 | break; 137 | case HPDF_OCLASS_STRING: 138 | ret = HPDF_String_Write (obj, stream, e); 139 | break; 140 | case HPDF_OCLASS_BINARY: 141 | ret = HPDF_Binary_Write (obj, stream, e); 142 | break; 143 | case HPDF_OCLASS_ARRAY: 144 | ret = HPDF_Array_Write (obj, stream, e); 145 | break; 146 | case HPDF_OCLASS_DICT: 147 | ret = HPDF_Dict_Write (obj, stream, e); 148 | break; 149 | case HPDF_OCLASS_BOOLEAN: 150 | ret = HPDF_Boolean_Write (obj, stream); 151 | break; 152 | case HPDF_OCLASS_DIRECT: 153 | ret = HPDF_Direct_Write (obj, stream); 154 | break; 155 | case HPDF_OCLASS_NULL: 156 | ret = HPDF_Stream_WriteStr (stream, "null"); 157 | break; 158 | default: 159 | ret = HPDF_ERR_UNKNOWN_CLASS; 160 | } 161 | 162 | return ret; 163 | } 164 | 165 | HPDF_Proxy 166 | HPDF_Proxy_New (HPDF_MMgr mmgr, 167 | void *obj) 168 | { 169 | HPDF_Proxy p = HPDF_GetMem (mmgr, sizeof(HPDF_Proxy_Rec)); 170 | 171 | HPDF_PTRACE((" HPDF_Proxy_New\n")); 172 | 173 | if (p) { 174 | HPDF_MemSet (&p->header, 0, sizeof(HPDF_Obj_Header)); 175 | p->header.obj_class = HPDF_OCLASS_PROXY; 176 | p->obj = obj; 177 | } 178 | 179 | return p; 180 | } 181 | 182 | -------------------------------------------------------------------------------- /libharu/src/hpdf_page_label.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_page_label.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_page_label.h" 21 | 22 | HPDF_Dict 23 | HPDF_PageLabel_New (HPDF_Doc pdf, 24 | HPDF_PageNumStyle style, 25 | HPDF_INT first_page, 26 | const char *prefix) 27 | { 28 | HPDF_Dict obj = HPDF_Dict_New (pdf->mmgr); 29 | 30 | HPDF_PTRACE ((" HPDF_PageLabel_New\n")); 31 | 32 | if (!obj) 33 | return NULL; 34 | 35 | switch (style) { 36 | case HPDF_PAGE_NUM_STYLE_DECIMAL: 37 | if (HPDF_Dict_AddName (obj, "S", "D") != HPDF_OK) 38 | goto Fail; 39 | break; 40 | case HPDF_PAGE_NUM_STYLE_UPPER_ROMAN: 41 | if (HPDF_Dict_AddName (obj, "S", "R") != HPDF_OK) 42 | goto Fail; 43 | break; 44 | case HPDF_PAGE_NUM_STYLE_LOWER_ROMAN: 45 | if (HPDF_Dict_AddName (obj, "S", "r") != HPDF_OK) 46 | goto Fail; 47 | break; 48 | case HPDF_PAGE_NUM_STYLE_UPPER_LETTERS: 49 | if (HPDF_Dict_AddName (obj, "S", "A") != HPDF_OK) 50 | goto Fail; 51 | break; 52 | case HPDF_PAGE_NUM_STYLE_LOWER_LETTERS: 53 | if (HPDF_Dict_AddName (obj, "S", "a") != HPDF_OK) 54 | goto Fail; 55 | break; 56 | default: 57 | HPDF_SetError (&pdf->error, HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE, 58 | (HPDF_STATUS)style); 59 | goto Fail; 60 | } 61 | 62 | if (prefix && prefix[0] != 0) 63 | if (HPDF_Dict_Add (obj, "P", HPDF_String_New (pdf->mmgr, prefix, 64 | pdf->def_encoder)) != HPDF_OK) 65 | goto Fail; 66 | 67 | if (first_page != 0) 68 | if (HPDF_Dict_AddNumber (obj, "St", first_page) != HPDF_OK) 69 | goto Fail; 70 | 71 | return obj; 72 | 73 | Fail: 74 | HPDF_Dict_Free (obj); 75 | return NULL; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /libharu/src/hpdf_real.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_real.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include "hpdf_conf.h" 19 | #include "hpdf_utils.h" 20 | #include "hpdf_objects.h" 21 | 22 | 23 | HPDF_Real 24 | HPDF_Real_New (HPDF_MMgr mmgr, 25 | HPDF_REAL value) 26 | { 27 | HPDF_Real obj = HPDF_GetMem (mmgr, sizeof(HPDF_Real_Rec)); 28 | 29 | if (obj) { 30 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); 31 | obj->header.obj_class = HPDF_OCLASS_REAL; 32 | obj->error = mmgr->error; 33 | HPDF_Real_SetValue (obj, value); 34 | } 35 | 36 | return obj; 37 | } 38 | 39 | 40 | HPDF_STATUS 41 | HPDF_Real_Write (HPDF_Real obj, 42 | HPDF_Stream stream) 43 | { 44 | return HPDF_Stream_WriteReal (stream, obj->value); 45 | } 46 | 47 | 48 | HPDF_STATUS 49 | HPDF_Real_SetValue (HPDF_Real obj, 50 | HPDF_REAL value) 51 | { 52 | HPDF_STATUS ret = HPDF_OK; 53 | 54 | if (value > HPDF_LIMIT_MAX_REAL) 55 | return HPDF_SetError (obj->error, HPDF_REAL_OUT_OF_RANGE, 0); 56 | 57 | if (value < HPDF_LIMIT_MIN_REAL) 58 | return HPDF_SetError (obj->error, HPDF_REAL_OUT_OF_RANGE, 0); 59 | 60 | obj->value =value; 61 | 62 | return ret; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /libharu/src/hpdf_shading.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_shading.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * Copyright (c) 2017 Kitware 9 | * 10 | * Permission to use, copy, modify, distribute and sell this software 11 | * and its documentation for any purpose is hereby granted without fee, 12 | * provided that the above copyright notice appear in all copies and 13 | * that both that copyright notice and this permission notice appear 14 | * in supporting documentation. 15 | * It is provided "as is" without express or implied warranty. 16 | * 17 | */ 18 | 19 | #include "hpdf.h" 20 | #include "hpdf_utils.h" 21 | 22 | #include "assert.h" 23 | 24 | typedef struct _RGBVertex 25 | { 26 | HPDF_UINT8 EdgeFlag; 27 | HPDF_UINT32 X; 28 | HPDF_UINT32 Y; 29 | HPDF_UINT8 RGB[3]; 30 | } RGBVertex; 31 | 32 | static const char *COL_CMYK = "DeviceCMYK"; 33 | static const char *COL_RGB = "DeviceRGB"; 34 | static const char *COL_GRAY = "DeviceGray"; 35 | 36 | /* bbox is filled with xMin, xMax, yMin, yMax */ 37 | static HPDF_BOOL _GetDecodeArrayVertexValues(HPDF_Shading shading, 38 | HPDF_REAL *bbox) 39 | { 40 | HPDF_Array decodeArray; 41 | HPDF_Real r; 42 | int i; 43 | 44 | if (!shading) { 45 | return HPDF_FALSE; 46 | } 47 | 48 | decodeArray = (HPDF_Array)(HPDF_Dict_GetItem(shading, "Decode", 49 | HPDF_OCLASS_ARRAY)); 50 | if (!decodeArray) { 51 | return HPDF_FALSE; 52 | } 53 | 54 | for (i = 0; i < 4; ++i) 55 | { 56 | r = HPDF_Array_GetItem(decodeArray, i, HPDF_OCLASS_REAL); 57 | if (!r) { 58 | return HPDF_FALSE; 59 | } 60 | 61 | bbox[i] = r->value; 62 | } 63 | 64 | return HPDF_TRUE; 65 | } 66 | 67 | static void UINT32Swap (HPDF_UINT32 *value) 68 | { 69 | HPDF_BYTE b[4]; 70 | 71 | HPDF_MemCpy (b, (HPDF_BYTE *)value, 4); 72 | *value = (HPDF_UINT32)((HPDF_UINT32)b[0] << 24 | 73 | (HPDF_UINT32)b[1] << 16 | 74 | (HPDF_UINT32)b[2] << 8 | 75 | (HPDF_UINT32)b[3]); 76 | } 77 | 78 | /* Encode a position coordinate for writing */ 79 | static HPDF_UINT32 _EncodeValue(HPDF_REAL x, HPDF_REAL xMin, HPDF_REAL xMax) 80 | { 81 | HPDF_DOUBLE norm = (x - xMin) / (xMax - xMin); 82 | HPDF_DOUBLE max = (HPDF_DOUBLE)(0xFFFFFFFF); 83 | HPDF_UINT32 enc = (HPDF_UINT32)(norm * max); 84 | UINT32Swap(&enc); 85 | return enc; 86 | } 87 | 88 | HPDF_EXPORT(HPDF_Shading) 89 | HPDF_Shading_New (HPDF_Doc pdf, 90 | HPDF_ShadingType type, 91 | HPDF_ColorSpace colorSpace, 92 | HPDF_REAL xMin, HPDF_REAL xMax, 93 | HPDF_REAL yMin, HPDF_REAL yMax) 94 | { 95 | HPDF_Shading shading; 96 | HPDF_Array decodeArray; 97 | HPDF_STATUS ret = HPDF_OK; 98 | int i; 99 | 100 | HPDF_PTRACE((" HPDF_Shading_New\n")); 101 | 102 | if (!HPDF_HasDoc(pdf)) { 103 | return NULL; 104 | } 105 | 106 | /* Validate shading type: */ 107 | switch (type) 108 | { 109 | case HPDF_SHADING_FREE_FORM_TRIANGLE_MESH: 110 | break; 111 | 112 | default: 113 | HPDF_SetError (pdf->mmgr->error, HPDF_INVALID_SHADING_TYPE, 0); 114 | return NULL; 115 | } 116 | 117 | decodeArray = HPDF_Array_New(pdf->mmgr); 118 | if (!decodeArray) { 119 | return NULL; 120 | } 121 | 122 | /* X-range */ 123 | ret += HPDF_Array_AddReal(decodeArray, xMin); 124 | ret += HPDF_Array_AddReal(decodeArray, xMax); 125 | 126 | /* Y-range */ 127 | ret += HPDF_Array_AddReal(decodeArray, yMin); 128 | ret += HPDF_Array_AddReal(decodeArray, yMax); 129 | 130 | const char *colName = NULL; 131 | switch (colorSpace) { 132 | case HPDF_CS_DEVICE_RGB: 133 | colName = COL_RGB; 134 | for (i = 0; i < 3; ++i) { 135 | ret += HPDF_Array_AddReal(decodeArray, 0.0); 136 | ret += HPDF_Array_AddReal(decodeArray, 1.0); 137 | } 138 | break; 139 | 140 | default: 141 | HPDF_SetError(pdf->mmgr->error, HPDF_INVALID_COLOR_SPACE, 0); 142 | return NULL; 143 | } 144 | 145 | if (ret != HPDF_OK) { 146 | return NULL; 147 | } 148 | 149 | shading = HPDF_DictStream_New(pdf->mmgr, pdf->xref); 150 | if (!shading) { 151 | return NULL; 152 | } 153 | 154 | shading->header.obj_class |= HPDF_OSUBCLASS_SHADING; 155 | ret += HPDF_Dict_AddNumber(shading, "ShadingType", type); 156 | ret += HPDF_Dict_AddName(shading, "ColorSpace", colName); 157 | 158 | switch (type) 159 | { 160 | case HPDF_SHADING_FREE_FORM_TRIANGLE_MESH: 161 | ret += HPDF_Dict_AddNumber(shading, "BitsPerCoordinate", 32); 162 | ret += HPDF_Dict_AddNumber(shading, "BitsPerComponent", 8); 163 | ret += HPDF_Dict_AddNumber(shading, "BitsPerFlag", 8); 164 | ret += HPDF_Dict_Add(shading, "Decode", decodeArray); 165 | break; 166 | 167 | default: 168 | HPDF_SetError (pdf->mmgr->error, HPDF_INVALID_SHADING_TYPE, 0); 169 | return NULL; 170 | } 171 | 172 | if (ret != HPDF_OK) { 173 | return NULL; 174 | } 175 | 176 | return shading; 177 | } 178 | 179 | HPDF_EXPORT(HPDF_STATUS) 180 | HPDF_Shading_AddVertexRGB(HPDF_Shading shading, 181 | HPDF_Shading_FreeFormTriangleMeshEdgeFlag edgeFlag, 182 | HPDF_REAL x, HPDF_REAL y, 183 | HPDF_UINT8 r, HPDF_UINT8 g, HPDF_UINT8 b) 184 | { 185 | HPDF_STATUS ret = HPDF_OK; 186 | RGBVertex vert; 187 | float bbox[4]; 188 | 189 | HPDF_PTRACE((" HPDF_Shading_AddVertexRGB\n")); 190 | 191 | if (!shading) { 192 | return HPDF_INVALID_OBJECT; 193 | } 194 | 195 | if (_GetDecodeArrayVertexValues(shading, bbox) != HPDF_TRUE) { 196 | return HPDF_SetError(shading->error, HPDF_INVALID_OBJECT, 0); 197 | } 198 | 199 | vert.EdgeFlag = (HPDF_UINT8)edgeFlag; 200 | vert.X = _EncodeValue(x, bbox[0], bbox[1]); 201 | vert.Y = _EncodeValue(y, bbox[2], bbox[3]); 202 | vert.RGB[0] = r; 203 | vert.RGB[1] = g; 204 | vert.RGB[2] = b; 205 | 206 | ret = HPDF_Stream_Write(shading->stream, 207 | (HPDF_BYTE*)(&vert.EdgeFlag), sizeof(vert.EdgeFlag)); 208 | if (ret != HPDF_OK) 209 | { 210 | return ret; 211 | } 212 | 213 | ret = HPDF_Stream_Write(shading->stream, 214 | (HPDF_BYTE*)(&vert.X), sizeof(vert.X)); 215 | if (ret != HPDF_OK) 216 | { 217 | return ret; 218 | } 219 | 220 | ret = HPDF_Stream_Write(shading->stream, 221 | (HPDF_BYTE*)(&vert.Y), sizeof(vert.Y)); 222 | if (ret != HPDF_OK) 223 | { 224 | return ret; 225 | } 226 | 227 | ret = HPDF_Stream_Write(shading->stream, 228 | (HPDF_BYTE*)(&vert.RGB), sizeof(vert.RGB)); 229 | 230 | return ret; 231 | } 232 | -------------------------------------------------------------------------------- /libharu/src/hpdf_string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_string.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #include 19 | #include "hpdf_conf.h" 20 | #include "hpdf_utils.h" 21 | #include "hpdf_objects.h" 22 | 23 | static const HPDF_BYTE UNICODE_HEADER[] = { 24 | 0xFE, 0xFF 25 | }; 26 | 27 | 28 | HPDF_String 29 | HPDF_String_New (HPDF_MMgr mmgr, 30 | const char *value, 31 | HPDF_Encoder encoder) 32 | { 33 | HPDF_String obj; 34 | 35 | HPDF_PTRACE((" HPDF_String_New\n")); 36 | 37 | obj = (HPDF_String)HPDF_GetMem (mmgr, sizeof(HPDF_String_Rec)); 38 | if (obj) { 39 | HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header)); 40 | obj->header.obj_class = HPDF_OCLASS_STRING; 41 | 42 | obj->mmgr = mmgr; 43 | obj->error = mmgr->error; 44 | obj->encoder = encoder; 45 | obj->value = NULL; 46 | obj->len = 0; 47 | 48 | if (HPDF_String_SetValue (obj, value) != HPDF_OK) { 49 | HPDF_FreeMem (obj->mmgr, obj); 50 | return NULL; 51 | } 52 | } 53 | 54 | return obj; 55 | } 56 | 57 | 58 | HPDF_STATUS 59 | HPDF_String_SetValue (HPDF_String obj, 60 | const char *value) 61 | { 62 | HPDF_UINT len; 63 | HPDF_STATUS ret = HPDF_OK; 64 | 65 | HPDF_PTRACE((" HPDF_String_SetValue\n")); 66 | 67 | if (obj->value) { 68 | HPDF_FreeMem (obj->mmgr, obj->value); 69 | obj->len = 0; 70 | } 71 | 72 | len = HPDF_StrLen(value, HPDF_LIMIT_MAX_STRING_LEN + 1); 73 | 74 | if (len > HPDF_LIMIT_MAX_STRING_LEN) 75 | return HPDF_SetError (obj->error, HPDF_STRING_OUT_OF_RANGE, 0); 76 | 77 | obj->value = HPDF_GetMem (obj->mmgr, len + 1); 78 | if (!obj->value) 79 | return HPDF_Error_GetCode (obj->error); 80 | 81 | HPDF_StrCpy ((char *)obj->value, value, (char *)obj->value + len); 82 | obj->len = len; 83 | 84 | return ret; 85 | } 86 | 87 | void 88 | HPDF_String_Free (HPDF_String obj) 89 | { 90 | if (!obj) 91 | return; 92 | 93 | HPDF_PTRACE((" HPDF_String_Free\n")); 94 | 95 | HPDF_FreeMem (obj->mmgr, obj->value); 96 | HPDF_FreeMem (obj->mmgr, obj); 97 | } 98 | 99 | 100 | HPDF_STATUS 101 | HPDF_String_Write (HPDF_String obj, 102 | HPDF_Stream stream, 103 | HPDF_Encrypt e) 104 | { 105 | HPDF_STATUS ret; 106 | 107 | /* 108 | * When encoder is not NULL, text is changed to unicode using encoder, 109 | * and it outputs by HPDF_write_binary method. 110 | */ 111 | 112 | HPDF_PTRACE((" HPDF_String_Write\n")); 113 | 114 | if (e) 115 | HPDF_Encrypt_Reset (e); 116 | 117 | if (obj->encoder == NULL) { 118 | if (e) { 119 | if ((ret = HPDF_Stream_WriteChar (stream, '<')) != HPDF_OK) 120 | return ret; 121 | 122 | if ((ret = HPDF_Stream_WriteBinary (stream, obj->value, 123 | HPDF_StrLen ((char *)obj->value, -1), e)) != HPDF_OK) 124 | return ret; 125 | 126 | return HPDF_Stream_WriteChar (stream, '>'); 127 | } else { 128 | return HPDF_Stream_WriteEscapeText (stream, (char *)obj->value); 129 | } 130 | } else { 131 | HPDF_BYTE* src = obj->value; 132 | HPDF_BYTE buf[HPDF_TEXT_DEFAULT_LEN * 2]; 133 | HPDF_UINT tmp_len = 0; 134 | HPDF_BYTE* pbuf = buf; 135 | HPDF_INT32 len = obj->len; 136 | HPDF_ParseText_Rec parse_state; 137 | HPDF_UINT i; 138 | 139 | if ((ret = HPDF_Stream_WriteChar (stream, '<')) != HPDF_OK) 140 | return ret; 141 | 142 | if ((ret = HPDF_Stream_WriteBinary (stream, UNICODE_HEADER, 2, e)) 143 | != HPDF_OK) 144 | return ret; 145 | 146 | HPDF_Encoder_SetParseText (obj->encoder, &parse_state, src, len); 147 | 148 | for (i = 0; (HPDF_INT32)i < len; i++) { 149 | HPDF_BYTE b = src[i]; 150 | HPDF_UNICODE tmp_unicode; 151 | HPDF_ByteType btype = HPDF_Encoder_ByteType (obj->encoder, 152 | &parse_state); 153 | 154 | if (tmp_len >= HPDF_TEXT_DEFAULT_LEN - 1) { 155 | if ((ret = HPDF_Stream_WriteBinary (stream, buf, 156 | tmp_len * 2, e)) != HPDF_OK) 157 | return ret; 158 | 159 | tmp_len = 0; 160 | pbuf = buf; 161 | } 162 | 163 | if (btype != HPDF_BYTE_TYPE_TRAIL) { 164 | if (btype == HPDF_BYTE_TYPE_LEAD) { 165 | HPDF_BYTE b2 = src[i + 1]; 166 | HPDF_UINT16 char_code = (HPDF_UINT16)((HPDF_UINT) b * 256 + b2); 167 | 168 | tmp_unicode = HPDF_Encoder_ToUnicode (obj->encoder, 169 | char_code); 170 | } else { 171 | tmp_unicode = HPDF_Encoder_ToUnicode (obj->encoder, b); 172 | } 173 | 174 | HPDF_UInt16Swap (&tmp_unicode); 175 | HPDF_MemCpy (pbuf, (HPDF_BYTE*)&tmp_unicode, 2); 176 | pbuf += 2; 177 | tmp_len++; 178 | } 179 | } 180 | 181 | if (tmp_len > 0) { 182 | if ((ret = HPDF_Stream_WriteBinary (stream, buf, tmp_len * 2, e)) 183 | != HPDF_OK) 184 | return ret; 185 | } 186 | 187 | if ((ret = HPDF_Stream_WriteChar (stream, '>')) != HPDF_OK) 188 | return ret; 189 | } 190 | 191 | return HPDF_OK; 192 | } 193 | 194 | 195 | HPDF_INT32 196 | HPDF_String_Cmp (HPDF_String s1, 197 | HPDF_String s2) 198 | { 199 | HPDF_INT32 res; 200 | HPDF_UINT minLen; 201 | 202 | minLen = s1->len; 203 | if( s1->len > s2->len ) { 204 | minLen = s2->len; 205 | } 206 | 207 | res = memcmp( s1->value, s2->value, minLen ); 208 | if( res == 0 ) { 209 | if( s1->len < s2->len ) res = -1; 210 | if( s1->len > s2->len ) res = +1; 211 | } 212 | 213 | return res; 214 | } 215 | -------------------------------------------------------------------------------- /libharu_ng.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": {} 8 | } 9 | -------------------------------------------------------------------------------- /src/font.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023-2024 Bastian Bense 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | // Contact: Bastian Bense, bb@neosw.de 22 | 23 | //! The Font module. 24 | //! 25 | //! For more information about using fonts in Haru, see the [] 26 | //! 27 | //! ## Implementation status: 28 | //! 29 | //! - [x] HPDF_Font_GetFontName() 30 | //! - [x] HPDF_Font_GetEncodingName() 31 | //! - [x] HPDF_Font_GetUnicodeWidth() 32 | //! - [x] HPDF_Font_GetBBox() 33 | //! - [x] HPDF_Font_GetAscent() 34 | //! - [x] HPDF_Font_GetDescent() 35 | //! - [x] HPDF_Font_GetXHeight() 36 | //! - [x] HPDF_Font_GetCapHeight() 37 | //! - [x] HPDF_Font_TextWidth() 38 | //! - [ ] HPDF_Font_MeasureText() 39 | //! 40 | 41 | use crate::{haru_bindings as hb, HpdfBox}; 42 | 43 | /// The font object. 44 | /// 45 | #[derive(Debug, Copy, Clone)] 46 | pub struct PdfFont { 47 | /// The reference to the haru font. 48 | pub font_ref: hb::HPDF_Font, 49 | } 50 | 51 | impl PdfFont { 52 | /// HPDF_Font_GetFontName() gets the name of the font. 53 | /// 54 | pub fn get_font_name(&self) -> String { 55 | let name = unsafe { hb::HPDF_Font_GetFontName(self.font_ref) }; 56 | let name = unsafe { std::ffi::CStr::from_ptr(name) }; 57 | name.to_str().unwrap().to_string() 58 | } 59 | 60 | /// HPDF_Font_GetEncodingName() gets the encoding name of the font. 61 | /// 62 | pub fn get_encoding_name(&self) -> String { 63 | let name = unsafe { hb::HPDF_Font_GetEncodingName(self.font_ref) }; 64 | let name = unsafe { std::ffi::CStr::from_ptr(name) }; 65 | name.to_str().unwrap().to_string() 66 | } 67 | 68 | /// HPDF_Font_GetUnicodeWidth() gets the width of a Unicode character 69 | /// in a specific font. Actual width of the character on the page 70 | /// can be calculated as follows: 71 | /// 72 | /// ```c 73 | /// char_width = HPDF_Font_GetUnicodeWidth (font, UNICODE); 74 | /// float actual_width = char_width * FONT_SIZE / 1000; 75 | /// ```` 76 | /// 77 | /// FIXME: Replace ex. C code with Rust code. 78 | /// 79 | pub fn get_unicode_width(&self, code: u16) -> i32 { 80 | unsafe { hb::HPDF_Font_GetUnicodeWidth(self.font_ref, code) } 81 | } 82 | 83 | /// HPDF_Font_GetBBox() gets the bounding box of the font. 84 | /// 85 | /// When HPDF_Font_GetBox() succeed, it returns the HPDF_Box struct specifying the font bounding box. Otherwise, it returns a HPDF_Box struct of {0, 0, 0, 0}. 86 | /// 87 | /// API: HPDF_Box HPDF_Font_GetBBox 88 | 89 | pub fn get_b_box(&self) -> HpdfBox { 90 | unsafe { HpdfBox::from(hb::HPDF_Font_GetBBox(self.font_ref)) } 91 | } 92 | 93 | /// HPDF_Font_GetAscent() gets the vertical ascent of the font. 94 | /// 95 | pub fn get_ascent(&self) -> i32 { 96 | unsafe { hb::HPDF_Font_GetAscent(self.font_ref) } 97 | } 98 | 99 | /// HPDF_Font_GetDescent() gets the vertical descent of the font. 100 | /// 101 | pub fn get_descent(&self) -> i32 { 102 | unsafe { hb::HPDF_Font_GetDescent(self.font_ref) } 103 | } 104 | 105 | /// HPDF_Font_GetXHeight() gets the distance from the baseline of lowercase letters. 106 | /// 107 | pub fn get_x_height(&self) -> u32 { 108 | unsafe { hb::HPDF_Font_GetXHeight(self.font_ref) } 109 | } 110 | 111 | /// HPDF_Font_GetCapHeight() gets the distance from the baseline of uppercase letters. 112 | /// 113 | pub fn get_cap_height(&self) -> u32 { 114 | unsafe { hb::HPDF_Font_GetCapHeight(self.font_ref) } 115 | } 116 | 117 | /// HPDF_Font_TextWidth() gets total width of the text, number of charactors and number of the words. 118 | /// 119 | /// When HPDF_Font_TextWidth() succeed, it returns a HPDF_TextWidth struct including calculation result. Otherwise, it returns a HPDF_TextWidth struct whose attributes are all ZERO. 120 | /// 121 | pub fn text_width(&self, text: &str) -> hb::HPDF_TextWidth { 122 | let text = std::ffi::CString::new(text).unwrap(); 123 | unsafe { 124 | hb::HPDF_Font_TextWidth( 125 | self.font_ref, 126 | text.as_ptr() as *const u8, 127 | text.as_bytes().len() as u32, 128 | ) 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/image.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023-2024 Bastian Bense 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | // Contact: Bastian Bense, bb@neosw.de 22 | 23 | //! The image struct and related functions. 24 | //! 25 | 26 | use crate::{haru_bindings as hb, prelude::HaruError}; 27 | 28 | /// The image object. 29 | /// 30 | #[derive(Debug)] 31 | pub struct PdfImage { 32 | /// The reference to the haru image. 33 | pub image_ref: hb::HPDF_Image, 34 | } 35 | 36 | impl PdfImage { 37 | /// get_width() returns the width of the image. 38 | /// 39 | /// Api: HPDF_Image_GetWidth 40 | /// 41 | pub fn get_width(&self) -> Result { 42 | let result = unsafe { hb::HPDF_Image_GetWidth(self.image_ref) }; 43 | match result { 44 | 0 => Err(HaruError::from(0)), 45 | _ => Ok(result), 46 | } 47 | } 48 | 49 | /// get_height() returns the height of the image. 50 | /// 51 | /// Api: HPDF_Image_GetHeight 52 | /// 53 | pub fn get_height(&self) -> Result { 54 | let result = unsafe { hb::HPDF_Image_GetHeight(self.image_ref) }; 55 | match result { 56 | 0 => Err(HaruError::from(0)), 57 | _ => Ok(result), 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023-2024 Bastian Bense 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in all 11 | // copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | // SOFTWARE. 20 | // 21 | // Contact: Bastian Bense, bb@neosw.de 22 | 23 | //! Rust bindings for libharu. 24 | //! 25 | //! libharu is a free, cross platform, open source library for generating PDF files. 26 | //! 27 | //! This crate provides a high level API for creating PDF files. 28 | //! 29 | 30 | mod haru_bindings; 31 | 32 | pub mod document; 33 | pub mod font; 34 | pub mod haru_types; 35 | pub mod image; 36 | pub mod page; 37 | 38 | /// The prelude module. 39 | /// 40 | pub mod prelude { 41 | pub use crate::document::*; 42 | pub use crate::font::*; 43 | pub use crate::haru_types::*; 44 | pub use crate::image::*; 45 | pub use crate::page::*; 46 | } 47 | 48 | /// The error callback function type 49 | pub type ErrorCallback = 50 | extern "C" fn(error_no: i32, detail_no: i32, user_data: *mut std::ffi::c_void); 51 | 52 | pub struct HpdfBox { 53 | pub left: f32, 54 | pub bottom: f32, 55 | pub right: f32, 56 | pub top: f32, 57 | } 58 | 59 | /// Conversion from HPDF_Box to HpdfBox 60 | /// 61 | impl From for HpdfBox { 62 | fn from(hpdf_box: haru_bindings::HPDF_Box) -> Self { 63 | HpdfBox { 64 | left: hpdf_box.left, 65 | bottom: hpdf_box.bottom, 66 | right: hpdf_box.right, 67 | top: hpdf_box.top, 68 | } 69 | } 70 | } 71 | 72 | /// Returns the version of the libharu library. 73 | /// The version is a string in the format "major.minor.patch". 74 | /// 75 | pub fn libharu_version() -> String { 76 | let version = unsafe { haru_bindings::HPDF_GetVersion() }; 77 | let version = unsafe { std::ffi::CStr::from_ptr(version) }; 78 | version.to_str().unwrap().to_string() 79 | } 80 | 81 | /// Test which prints the version. 82 | /// 83 | #[cfg(test)] 84 | mod tests { 85 | use super::*; 86 | 87 | #[test] 88 | fn test_libharu_version() { 89 | let version = libharu_version(); 90 | println!("libharu version: {}", version); 91 | } 92 | } 93 | --------------------------------------------------------------------------------