Skip to main content

Config

Struct Config 

Source
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: u32

Width of the viewport in pixels.

§height: u32

Height of the viewport in pixels.

For PDF output, this may be adjusted based on content length if auto_height is enabled.

§scale: f32

Scale factor for rendering (e.g., 2.0 for retina displays).

§format: OutputFormat

Output format (PNG or PDF).

§color_scheme: ColorScheme

Color scheme preference (light or dark mode).

§auto_height: bool

Whether 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

Source

pub const MIN_DIMENSION: u32 = 16

Minimum supported width/height in pixels.

Very small dimensions can cause overflow issues in the underlying rendering engine.

Source

pub fn new() -> Self

Create a new configuration with default values.

Defaults:

  • Width: 800px
  • Height: 600px
  • Scale: 1.0
  • Format: PNG
  • Color scheme: Light
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub fn format(self, format: OutputFormat) -> Self

Set the output format.

§Example
use hyper_render::{Config, OutputFormat};

let config = Config::new().format(OutputFormat::Pdf);
Source

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);
Source

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);
Source

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]);
Source

pub fn transparent(self) -> Self

Set a transparent background.

Shorthand for .background([0, 0, 0, 0]).

Source

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§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,