Skip to main content

HtmlBase

Struct HtmlBase 

Source
pub(crate) struct HtmlBase {
    pub(crate) content: XmlTree,
    pub(crate) engine: Engine,
    pub(crate) pages: Vec<Page>,
    pub(crate) parent: PathBuf,
    pub(crate) size: usize,
    pub(crate) viewer_stylesheet: PathBuf,
    pub(crate) user_stylesheet: PathBuf,
    pub(crate) ignore_document_css: bool,
}
Expand description

Parser-independent rendering state shared by HtmlDocument and Html5Document.

Owns the parsed XmlTree, the layout Engine, a lazily-built page cache, and the stylesheet configuration. Neither parser-specific logic nor the raw source text belongs here — those live in the concrete document types that compose this struct.

Fields§

§content: XmlTree

The parsed document tree.

§engine: Engine

Layout engine responsible for building draw commands and rendering pages.

§pages: Vec<Page>

Lazily built list of pages. Cleared whenever layout parameters change.

§parent: PathBuf

Directory used to resolve relative resource paths (images, stylesheets).

§size: usize

Byte size of the source content, used as a proxy for pages_count.

§viewer_stylesheet: PathBuf

Path to the viewer stylesheet (typically css/html.css).

§user_stylesheet: PathBuf

Path to the user stylesheet (typically css/html-user.css).

§ignore_document_css: bool

When true, <style> and <link rel=stylesheet> tags in the document are ignored during page building.

Implementations§

Source§

impl HtmlBase

Source

pub(crate) fn new( content: XmlTree, size: usize, parent: PathBuf, viewer_stylesheet: PathBuf, user_stylesheet: PathBuf, ) -> Self

Creates a new HtmlBase from an already-parsed tree and configuration.

Source

pub(crate) fn page_index(&mut self, offset: usize) -> Option<usize>

Returns the zero-based index of the page that contains offset, or None if no page contains it.

Triggers a full build_pages pass the first time it is called after the page cache has been cleared.

Resolves a URI containing a fragment (e.g. chapter.html#intro) to the document offset of the element with the matching id attribute.

Returns None if the URI has no # or no element with the given id is found. Results are written into cache so repeated lookups for the same URI are free.

Source

fn cache_uris( &mut self, node: NodeRef<'_>, name: &str, cache: &mut FxHashMap<String, usize>, )

Recursively walks the tree rooted at node and inserts an entry into cache for every element that carries an id attribute, mapping "name#id" to the element’s offset.

Source

pub(crate) fn build_pages(&mut self) -> Vec<Page>

Builds the complete list of pages from the current document tree and engine settings.

Stylesheets are loaded in priority order:

  1. The default viewer stylesheet (css/html.css).
  2. A custom viewer stylesheet if one has been set and differs from the default.
  3. The user stylesheet.
  4. Inline <style> elements and <link rel=stylesheet> references found in the document <head>, unless ignore_document_css is set.

Returns a non-empty list; if the engine produces no draw commands a single fallback page anchored at offset 0 is returned.

Source

pub(crate) fn resolve_location(&mut self, loc: Location) -> Option<usize>

Resolves a Location to a concrete document offset, triggering font loading and page building as needed.

  • Exact(offset) — snaps to the first draw command on the page containing offset.
  • Previous(offset) / Next(offset) — steps one page back or forward.
  • LocalUri / Uri — resolves a URI fragment anchor.

Returns None when the location cannot be resolved (e.g. already on the first page for Previous, or no element with the given id).

Source

pub(crate) fn words( &mut self, loc: Location, ) -> Option<(Vec<BoundedText>, usize)>

Returns all text spans on the page identified by loc, together with the resolved page offset.

Source

pub(crate) fn images(&mut self, loc: Location) -> Option<(Vec<Boundary>, usize)>

Returns all image bounding rectangles on the page identified by loc, together with the resolved page offset.

Returns all tappable link spans on the page identified by loc, together with the resolved page offset.

Both text and image draw commands are included when they carry a URI.

Source

pub(crate) fn pixmap( &mut self, loc: Location, scale: f32, samples: usize, ) -> Option<(Pixmap, usize)>

Renders the page identified by loc to a Pixmap at the given scale factor and returns it together with the resolved page offset.

Source

pub(crate) fn metadata(&self, key: &str) -> Option<String>

Reads the content attribute of the first <meta name="key"> element found in the document <head>, decoding any HTML entities.

Auto Trait Implementations§

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more