Layer

Struct Layer 

Source
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>

Source

fn new(page: &'p Page, data: Rc<RefCell<LayerData>>) -> Layer<'p>

Source

pub fn layer(&self) -> LayerInternalId

Returns the underlying layer internal id for this layer.

Source

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.

Source

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));
Source

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 XObject is kept in LayerData::xobjects until document serialization, at which point it is registered into the document resources so the UseXobject op references a valid resource id.
Source

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 printpdf
  • position - The position on the layer in layer coordinates
  • scale - Scaling factors for width and height
  • rotation - 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.

Source

fn add_line_shape<I>(&self, points: I)
where I: IntoIterator<Item = LayerPosition>,

Source

fn set_fill_color(&self, color: Option<Color>)

Source

fn set_outline_thickness(&self, thickness: Mm)

Source

fn set_outline_color(&self, color: Color)

Source

fn set_text_cursor(&self, cursor: LayerPosition)

Source

fn begin_text_section(&self)

Source

fn end_text_section(&self)

Source

fn add_line_break(&self)

Source

fn set_line_height(&self, line_height: Mm)

Source

fn set_font(&self, font: &IndirectFontRef, font_size: u8)

Source

fn write_positioned_codepoints<P, C, I>( &self, font: FontId, positions: P, codepoints: C, chars: I, )
where P: IntoIterator<Item = i64>, C: IntoIterator<Item = u16>, I: IntoIterator<Item = char>,

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.

Source

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).

Source

pub fn add_annotation(&self, rect: (f32, f32, f32, f32), uri: String)

Adds a link annotation to the layer. Annotations are stored separately and added to the page during PDF post-processing.

Trait Implementations§

Source§

impl<'p> Clone for Layer<'p>

Source§

fn clone(&self) -> Layer<'p>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V