Struct rckive_genpdf::render::Area
source · pub struct Area<'p> { /* private fields */ }
Expand description
A view on an area of a PDF layer that can be drawn on.
This struct provides access to the drawing methods of a printpdf::PdfLayerReference
. It
is defined by the layer that is drawn on and the origin and the size of the area.
Implementations§
source§impl<'p> Area<'p>
impl<'p> Area<'p>
sourcepub fn next_layer(&self) -> Self
pub fn next_layer(&self) -> Self
Returns a copy of this area on the next layer of the page.
If this area is not on the last layer, the existing next layer is used. If it is on the last layer, a new layer is created and added to the page.
sourcepub fn add_margins(&mut self, margins: impl Into<Margins>)
pub fn add_margins(&mut self, margins: impl Into<Margins>)
Reduces the size of the drawable area by the given margins.
sourcepub fn add_offset(&mut self, offset: impl Into<Position>)
pub fn add_offset(&mut self, offset: impl Into<Position>)
Adds the given offset to the area, reducing the drawable area.
sourcepub fn set_height(&mut self, height: Mm)
pub fn set_height(&mut self, height: Mm)
Sets the height of this area.
sourcepub fn split_horizontally(&self, weights: &[usize]) -> Vec<Area<'p>>
pub fn split_horizontally(&self, weights: &[usize]) -> Vec<Area<'p>>
Splits this area horizontally using the given weights.
The returned vector has the same number of elements as the provided slice. The width of the i-th area is width * weights[i] / total_weight, where width is the width of this area, and total_weight is the sum of all given weights.
sourcepub fn add_image(
&self,
image: &DynamicImage,
position: Position,
scale: Scale,
rotation: Rotation,
dpi: Option<f64>
)
pub fn add_image(
&self,
image: &DynamicImage,
position: Position,
scale: Scale,
rotation: Rotation,
dpi: Option<f64>
)
Inserts an image into the document.
Only available if the images
feature is enabled.
The position is assumed to be relative to the upper left hand corner of the area.
Your position will need to compensate for rotation/scale/dpi. Using Image
’s
render functionality will do this for you and is the recommended way to
insert an image into an Area.
sourcepub fn draw_line<I>(&self, points: I, line_style: LineStyle)where
I: IntoIterator<Item = Position>,
pub fn draw_line<I>(&self, points: I, line_style: LineStyle)where
I: IntoIterator<Item = Position>,
Draws a line with the given points and the given line style.
The points are relative to the upper left corner of the area.
sourcepub fn print_str<S: AsRef<str>>(
&self,
font_cache: &FontCache,
position: Position,
style: Style,
s: S
) -> Result<bool, Error>
pub fn print_str<S: AsRef<str>>(
&self,
font_cache: &FontCache,
position: Position,
style: Style,
s: S
) -> Result<bool, Error>
Tries to draw the given string at the given position and returns true
if the area was
large enough to draw the string.
The font cache must contain the PDF font for the font set in the style. The position is relative to the upper left corner of the area.
sourcepub fn text_section<'f>(
&self,
font_cache: &'f FontCache,
position: Position,
metrics: Metrics
) -> Option<TextSection<'f, 'p>>
pub fn text_section<'f>(
&self,
font_cache: &'f FontCache,
position: Position,
metrics: Metrics
) -> Option<TextSection<'f, 'p>>
Creates a new text section at the given position if the text section fits in this area.
The given style is only used to calculate the line height of the section. The position is relative to the upper left corner of the area. The font cache must contain the PDF font for all fonts printed with the text section.