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: XmlTreeThe parsed document tree.
engine: EngineLayout engine responsible for building draw commands and rendering pages.
pages: Vec<Page>Lazily built list of pages. Cleared whenever layout parameters change.
parent: PathBufDirectory used to resolve relative resource paths (images, stylesheets).
size: usizeByte size of the source content, used as a proxy for pages_count.
viewer_stylesheet: PathBufPath to the viewer stylesheet (typically css/html.css).
user_stylesheet: PathBufPath to the user stylesheet (typically css/html-user.css).
ignore_document_css: boolWhen true, <style> and <link rel=stylesheet> tags in the document
are ignored during page building.
Implementations§
Source§impl HtmlBase
impl HtmlBase
Sourcepub(crate) fn new(
content: XmlTree,
size: usize,
parent: PathBuf,
viewer_stylesheet: PathBuf,
user_stylesheet: PathBuf,
) -> Self
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.
Sourcepub(crate) fn page_index(&mut self, offset: usize) -> Option<usize>
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.
Sourcefn resolve_link(
&mut self,
uri: &str,
cache: &mut FxHashMap<String, usize>,
) -> Option<usize>
fn resolve_link( &mut self, uri: &str, cache: &mut FxHashMap<String, usize>, ) -> Option<usize>
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.
Sourcefn cache_uris(
&mut self,
node: NodeRef<'_>,
name: &str,
cache: &mut FxHashMap<String, usize>,
)
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.
Sourcepub(crate) fn build_pages(&mut self) -> Vec<Page> ⓘ
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:
- The default viewer stylesheet (
css/html.css). - A custom viewer stylesheet if one has been set and differs from the default.
- The user stylesheet.
- Inline
<style>elements and<link rel=stylesheet>references found in the document<head>, unlessignore_document_cssis set.
Returns a non-empty list; if the engine produces no draw commands a single fallback page anchored at offset 0 is returned.
Sourcepub(crate) fn resolve_location(&mut self, loc: Location) -> Option<usize>
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 containingoffset.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).
Sourcepub(crate) fn words(
&mut self,
loc: Location,
) -> Option<(Vec<BoundedText>, usize)>
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.
Sourcepub(crate) fn images(&mut self, loc: Location) -> Option<(Vec<Boundary>, usize)>
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.
Sourcepub(crate) fn links(
&mut self,
loc: Location,
) -> Option<(Vec<BoundedText>, usize)>
pub(crate) fn links( &mut self, loc: Location, ) -> Option<(Vec<BoundedText>, usize)>
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.
Auto Trait Implementations§
impl Freeze for HtmlBase
impl RefUnwindSafe for HtmlBase
impl !Send for HtmlBase
impl !Sync for HtmlBase
impl Unpin for HtmlBase
impl UnsafeUnpin for HtmlBase
impl UnwindSafe for HtmlBase
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more