pub struct Config {
pub width: u32,
pub height: u32,
pub scale: f32,
pub format: OutputFormat,
pub color_scheme: ColorScheme,
pub auto_height: bool,
pub background: [u8; 4],
}Expand description
Configuration for HTML rendering.
Use the builder pattern to construct a configuration:
use hyper_render::{Config, OutputFormat, ColorScheme};
let config = Config::new()
.width(1200)
.height(800)
.scale(2.0)
.format(OutputFormat::Pdf)
.color_scheme(ColorScheme::Dark);Fields§
§width: u32Width of the viewport in pixels.
height: u32Height of the viewport in pixels.
For PDF output, this may be adjusted based on content length
if auto_height is enabled.
scale: f32Scale factor for rendering (e.g., 2.0 for retina displays).
format: OutputFormatOutput format (PNG or PDF).
color_scheme: ColorSchemeColor scheme preference (light or dark mode).
auto_height: boolWhether to automatically adjust height based on content.
When enabled, the renderer will compute the actual content height and use that instead of the configured height.
background: [u8; 4]Background color as RGBA (default: white).
Implementations§
Source§impl Config
impl Config
Sourcepub const MIN_DIMENSION: u32 = 16
pub const MIN_DIMENSION: u32 = 16
Minimum supported width/height in pixels.
Very small dimensions can cause overflow issues in the underlying rendering engine.
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new configuration with default values.
Defaults:
- Width: 800px
- Height: 600px
- Scale: 1.0
- Format: PNG
- Color scheme: Light
Sourcepub fn width(self, width: u32) -> Self
pub fn width(self, width: u32) -> Self
Set the viewport width in pixels.
§Example
use hyper_render::Config;
let config = Config::new().width(1920);
assert_eq!(config.width, 1920);Sourcepub fn height(self, height: u32) -> Self
pub fn height(self, height: u32) -> Self
Set the viewport height in pixels.
§Example
use hyper_render::Config;
let config = Config::new().height(1080);
assert_eq!(config.height, 1080);Sourcepub fn size(self, width: u32, height: u32) -> Self
pub fn size(self, width: u32, height: u32) -> Self
Set both width and height at once.
§Example
use hyper_render::Config;
let config = Config::new().size(1920, 1080);
assert_eq!(config.width, 1920);
assert_eq!(config.height, 1080);Sourcepub fn scale(self, scale: f32) -> Self
pub fn scale(self, scale: f32) -> Self
Set the scale factor for rendering.
Use 2.0 for retina/HiDPI displays to get crisp output.
§Example
use hyper_render::Config;
let config = Config::new().scale(2.0);
assert_eq!(config.scale, 2.0);Sourcepub fn format(self, format: OutputFormat) -> Self
pub fn format(self, format: OutputFormat) -> Self
Set the output format.
§Example
use hyper_render::{Config, OutputFormat};
let config = Config::new().format(OutputFormat::Pdf);Sourcepub fn color_scheme(self, scheme: ColorScheme) -> Self
pub fn color_scheme(self, scheme: ColorScheme) -> Self
Set the color scheme preference.
This affects CSS media queries like prefers-color-scheme.
§Example
use hyper_render::{Config, ColorScheme};
let config = Config::new().color_scheme(ColorScheme::Dark);Sourcepub fn auto_height(self, auto: bool) -> Self
pub fn auto_height(self, auto: bool) -> Self
Enable automatic height detection.
When enabled, the renderer will compute the actual content height and use that instead of the configured height. This is useful for rendering full-page content.
§Example
use hyper_render::Config;
let config = Config::new().auto_height(true);Sourcepub fn background(self, rgba: [u8; 4]) -> Self
pub fn background(self, rgba: [u8; 4]) -> Self
Set the background color as RGBA values.
§Example
use hyper_render::Config;
// Transparent background
let config = Config::new().background([0, 0, 0, 0]);
// Light gray background
let config = Config::new().background([240, 240, 240, 255]);Sourcepub fn transparent(self) -> Self
pub fn transparent(self) -> Self
Set a transparent background.
Shorthand for .background([0, 0, 0, 0]).
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the configuration.
Returns an error if any configuration values are invalid:
- Width must be at least 16
- Height must be at least 16
- Scale must be greater than 0
This is called automatically by the render functions.
§Example
use hyper_render::Config;
let config = Config::new().width(0);
assert!(config.validate().is_err());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
Source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
Source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.