Skip to main content

esoc_gfx/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! # esoc-gfx
3//!
4//! Low-level 2D vector graphics engine for esoc-chart.
5//! SVG output with zero dependencies; optional PNG via resvg.
6
7#![warn(missing_docs)]
8#![deny(unsafe_code)]
9#![allow(clippy::format_push_string)]
10
11#[allow(deprecated)]
12pub mod backend;
13pub mod canvas;
14pub mod color;
15#[allow(deprecated)]
16pub mod element;
17pub mod error;
18pub mod geom;
19pub mod layer;
20#[allow(deprecated)]
21pub mod palette;
22pub mod path;
23pub mod scene_svg;
24#[allow(deprecated)]
25pub mod style;
26pub mod text;
27pub mod transform;
28
29/// Build resvg/usvg options with system fonts loaded.
30#[cfg(feature = "png")]
31pub(crate) fn usvg_options_with_fonts() -> resvg::usvg::Options<'static> {
32    let mut opt = resvg::usvg::Options::default();
33    let fontdb = opt.fontdb_mut();
34    fontdb.load_system_fonts();
35    opt
36}
37
38/// Convenience re-exports.
39pub mod prelude {
40    pub use crate::backend::svg::{render_svg, save_svg, SvgBackend};
41    pub use crate::backend::RenderBackend;
42    pub use crate::canvas::Canvas;
43    #[allow(deprecated)]
44    pub use crate::color::Color;
45    pub use crate::element::{DrawElement, Element};
46    pub use crate::error::{GfxError, Result};
47    pub use crate::geom::{Point, Rect, Size};
48    pub use crate::layer::Layer;
49    pub use crate::palette::Palette;
50    pub use crate::path::PathBuilder;
51    pub use crate::style::{DashPattern, Fill, FontStyle, Stroke, TextAnchor};
52    pub use crate::text::{HeuristicTextMeasurer, TextMeasurer};
53    pub use crate::transform::{AxisTransform, CoordinateTransform, ViewportTransform};
54
55    #[cfg(feature = "png")]
56    pub use crate::backend::png::{save_png, PngBackend};
57}