Trait rckive_genpdf::Element
source · pub trait Element {
fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style
) -> Result<RenderResult, Error>;
fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>
where
Self: Sized,
{ ... }
fn padded(self, padding: impl Into<Margins>) -> PaddedElement<Self>
where
Self: Sized,
{ ... }
fn styled(self, style: impl Into<Style>) -> StyledElement<Self>
where
Self: Sized,
{ ... }
}
Expand description
An element of a PDF document.
This trait is implemented by all elements that can be added to a Document
. Implementors
have to define the render
method that writes the content of this element to the generated
PDF document.
See the Rendering Process section of the crate documentation for more information on the rendering process.
Required Methods§
sourcefn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style
) -> Result<RenderResult, Error>
fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style
) -> Result<RenderResult, Error>
Renders this element to the given area using the given style and font cache.
For an overview over the rendering process, see the Rendering Process section of the crate documentation.
This method is called once for every element that has been added to a Document
once
the render
or render_to_file
methods have been called. If this method is
called, it should print the element’s content to the given area. If the content does not
fit in the given area, it should set the has_more
flag of the returned
RenderResult
. It will then be called again with a new area on a new page until it
returns a RenderResult
with has_more == false
. Regardless of whether the content
fitted in the area or not, the size
field of the RenderResult
must always be set to
the size of the area that has been used, starting at the origin of the provided area.
The following guarantuees are made by rckive_genpdf
’s elements and must be followed by
implementations of this trait:
- There is only one rendering process per element instance. This means that the first call to this method is always the start of the rendering process, and subsequent calls are always continuations of the same rendering process. This means that the element does not have to reset its state after it has processed all content, and it is allowed to drop content that has already been rendered.
- If a call to this method returns an
Err
value, it will not be called again. - After the first call, the method will only be called again if the
has_more
of the lastRenderResult
was set to true. - If none of the element’s content could be fitted in the provided area, the size of the
RenderResult
must be(0, 0)
. If the size is non-zero, this method must return aRenderResult
withhas_more == false
after a finite number of calls.
Provided Methods§
sourcefn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
Draws a frame around this element using the given line style.