Skip to main content

rpdfium_graphics/
lib.rs

1// Derived from PDFium's core/fxge/ types
2// Original: Copyright 2014 The PDFium Authors
3// Licensed under BSD-3-Clause / Apache-2.0
4// See pdfium-upstream/LICENSE for the original license.
5
6#![forbid(unsafe_code)]
7#![doc = "2D graphics foundation types for rpdfium — a faithful Rust port of PDFium."]
8//!
9//! Provides type definitions used across the rendering pipeline:
10//! path operations, color spaces, blend modes, clipping, bitmaps,
11//! and text rendering modes.
12//!
13//! This crate contains only type definitions for Phase 1. The actual
14//! rendering implementation (`tiny-skia` integration) is in `rpdfium-render`
15//! (Phase 2).
16
17pub mod cfx_color;
18pub mod cfx_dibitmap;
19pub mod cfx_path;
20pub mod cfx_textrenderoptions;
21pub mod clip;
22
23// Re-export all types at the crate root.
24pub use cfx_color::{BlendMode, Color, ColorSpaceFamily};
25pub use cfx_dibitmap::{Bitmap, BitmapFormat};
26pub use cfx_path::{
27    DashPattern, FillRule, LineCapStyle, LineJoinStyle, PathOp, PathStyle, bounding_box,
28    bounding_box_for_stroke_path, get_bounding_box, get_bounding_box_for_stroke_path, get_rect,
29    is_rect, rect_if_axis_aligned,
30};
31pub use cfx_textrenderoptions::TextRenderingMode;
32pub use clip::ClipPath;
33
34/// Reference to an image object for deferred decoding.
35///
36/// Images are not decoded until rendering time. This reference identifies
37/// the PDF object containing the image data.
38#[derive(Debug, Clone, PartialEq, Eq, Hash)]
39pub struct ImageRef {
40    /// The PDF object ID of the image XObject.
41    pub object_id: rpdfium_core::ObjectId,
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_all_types_accessible() {
50        let _ = PathOp::Close;
51        let _ = FillRule::default();
52        let _ = LineCapStyle::default();
53        let _ = LineJoinStyle::default();
54        let _ = DashPattern::default();
55        let _ = PathStyle::default();
56        let _ = BlendMode::default();
57        let _ = Color::default();
58        let _ = ColorSpaceFamily::DeviceRGB;
59        let _ = TextRenderingMode::default();
60        let _ = ClipPath::default();
61        let _ = BitmapFormat::Rgba32;
62    }
63
64    #[test]
65    fn test_types_are_send_sync() {
66        fn assert_send_sync<T: Send + Sync>() {}
67        assert_send_sync::<PathOp>();
68        assert_send_sync::<PathStyle>();
69        assert_send_sync::<BlendMode>();
70        assert_send_sync::<Color>();
71        assert_send_sync::<TextRenderingMode>();
72        assert_send_sync::<ClipPath>();
73        assert_send_sync::<Bitmap>();
74        assert_send_sync::<ImageRef>();
75    }
76
77    #[test]
78    fn test_image_ref_equality() {
79        let a = ImageRef {
80            object_id: rpdfium_core::ObjectId {
81                number: 1,
82                generation: 0,
83            },
84        };
85        let b = a.clone();
86        assert_eq!(a, b);
87    }
88}