pub struct Layer<'p> {
page: &'p Page,
data: Rc<RefCell<LayerData>>,
}Expand description
A layer of a page of a PDF document.
Fields§
§page: &'p Page§data: Rc<RefCell<LayerData>>Implementations§
Source§impl<'p> Layer<'p>
impl<'p> Layer<'p>
fn new(page: &'p Page, data: Rc<RefCell<LayerData>>) -> Layer<'p>
Sourcepub fn layer(&self) -> LayerInternalId
pub fn layer(&self) -> LayerInternalId
Returns the underlying layer internal id for this layer.
Sourcepub fn next(&self) -> Layer<'p>
pub fn next(&self) -> Layer<'p>
Returns the next layer of this page.
If this layer is not the last layer, the existing next layer is used. If it is the last layer, a new layer is created and added to the page.
Sourcepub fn area(&self) -> Area<'p>
pub fn area(&self) -> Area<'p>
Returns a drawable area for this layer.
§Examples
use genpdfi_extended::render::Renderer;
use genpdfi_extended::Size;
let mut r = Renderer::new(Size::new(210.0, 297.0), "ex").expect("renderer");
let layer = r.get_page(0).unwrap().first_layer();
let mut area = layer.area();
area.set_size(Size::new(50.0, 40.0));
assert_eq!(area.size().width, genpdfi_extended::Mm::from(50.0));Sourcefn add_image(
&self,
image: &DynamicImage,
position: LayerPosition,
scale: Scale,
rotation: Rotation,
dpi: Option<f32>,
)
fn add_image( &self, image: &DynamicImage, position: LayerPosition, scale: Scale, rotation: Rotation, dpi: Option<f32>, )
Adds an image to this layer by converting it to a RawImage, storing it as an
XObject local to this layer, and emitting a UseXobject operation referencing the
reserved XObject id.
Notes:
- Images with alpha channels are ignored (alpha handling is not supported).
- The actual
XObjectis kept inLayerData::xobjectsuntil document serialization, at which point it is registered into the document resources so theUseXobjectop references a valid resource id.
Sourcefn add_svg(
&self,
svg: &ExternalXObject,
position: LayerPosition,
scale: Scale,
rotation: Rotation,
)
fn add_svg( &self, svg: &ExternalXObject, position: LayerPosition, scale: Scale, rotation: Rotation, )
Adds an SVG to this layer by storing it as an XObject and emitting a UseXobject operation.
This method embeds SVG vector graphics without rasterization, leveraging printpdf’s native SVG support. The SVG is stored as an XObject local to this layer and registered into the document resources during serialization.
§Arguments
svg- A parsed SVG ExternalXObject from printpdfposition- The position on the layer in layer coordinatesscale- Scaling factors for width and heightrotation- Clockwise rotation in degrees
§Notes
The SVG dimensions are taken from the ExternalXObject width and height fields. DPI does not apply to SVG as they are already vector-based.
fn add_line_shape<I>(&self, points: I)where
I: IntoIterator<Item = LayerPosition>,
fn set_fill_color(&self, color: Option<Color>)
fn set_outline_thickness(&self, thickness: Mm)
fn set_outline_color(&self, color: Color)
fn set_text_cursor(&self, cursor: LayerPosition)
fn begin_text_section(&self)
fn end_text_section(&self)
fn add_line_break(&self)
fn set_line_height(&self, line_height: Mm)
fn set_font(&self, font: &IndirectFontRef, font_size: u8)
Sourcefn write_positioned_codepoints<P, C, I>(
&self,
font: FontId,
positions: P,
codepoints: C,
chars: I,
)
fn write_positioned_codepoints<P, C, I>( &self, font: FontId, positions: P, codepoints: C, chars: I, )
Emits positioned codepoints with kerning for an external PDF font.
positions are the kerning/offset values expressed in thousandths of an em
(matching the convention used in the font kerning helper). Positive values move
the next glyph to the right, negative values to the left. codepoints are the
font-specific glyph ids, and chars is the original character sequence for
diagnostic/clarity purposes; the emitted op contains a (pos, glyph_id, char)
tuple for each glyph.
Sourcefn transform_position(&self, position: LayerPosition) -> UserSpacePosition
fn transform_position(&self, position: LayerPosition) -> UserSpacePosition
Transforms the given position that is relative to the upper left corner of the layer to a
position that is relative to the lower left corner of the layer (as used by printpdf).
Trait Implementations§
Auto Trait Implementations§
impl<'p> Freeze for Layer<'p>
impl<'p> !RefUnwindSafe for Layer<'p>
impl<'p> !Send for Layer<'p>
impl<'p> !Sync for Layer<'p>
impl<'p> Unpin for Layer<'p>
impl<'p> !UnwindSafe for Layer<'p>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.