Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/pdf-annotation-core/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
pdf_data::AnnotationAction,
shapes, widget_control,
};
use pdf_graphics::{point::Point, rect::Rect, size::Size, viewport::PageViewport};
use pdf_graphics::{point::Point, rect::Rect, viewport::PageViewport};
use pdf_optional_content::OptionalContentState;

/// The shared field a widget is bound to; `None` for other kinds.
Expand Down Expand Up @@ -90,8 +90,8 @@ pub(crate) fn project(
subtype: annotation.content.subtype_name().into_owned(),
unsupported: unsupported_reason(annotation, field),
bounds: device_regions(annotation, &bounds, viewport)?,
origin: Point::new(bounds.left, bounds.top),
size: Size::new(bounds.width(), bounds.height()),
origin: bounds.origin(),
size: bounds.size(),
transform: viewport.local_frame(Point::new(bounds.left, bounds.bottom))?,
no_zoom: annotation.metadata.no_zoom(),
no_rotate: annotation.metadata.no_rotate(),
Expand Down
2 changes: 1 addition & 1 deletion crates/pdf-annotation-core/src/source_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn text_note(
Ok(TextNote {
properties: Some(Box::new(v.clone())),
style: Some(style.clone()),
anchor: Point::new(rect.left, rect.top),
anchor: rect.origin(),
text: source.contents()?,
color: style.rgba_color()?,
})
Expand Down
3 changes: 1 addition & 2 deletions crates/pdf-annotation-core/src/source_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use crate::error::ValidationError;
use crate::fields::TextMode;
use crate::kind::SourceLayout;
use crate::models::Point;
use crate::pdf_data::*;
use pdf_graphics::rect::Rect;

Expand Down Expand Up @@ -94,7 +93,7 @@ impl SourceAnnotation {
.copied(),
_ => None,
};
let anchor = first_ink_point.unwrap_or_else(|| Point::new(rect.left, rect.top));
let anchor = first_ink_point.unwrap_or_else(|| rect.origin());
Some(SourceLayout { rect, anchor })
}

Expand Down
12 changes: 11 additions & 1 deletion crates/pdf-graphics/src/rect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{point::Point, transform::Transform};
use crate::{point::Point, size::Size, transform::Transform};

/// An axis-aligned rectangle whose edge coordinate type defaults to `f32`.
#[derive(Debug, Default, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -74,6 +74,16 @@ impl Rect<f32> {
self.bottom - self.top
}

/// Returns the top-left corner `(left, top)`.
pub fn origin(&self) -> Point {
Point::new(self.left, self.top)
}

/// Returns the width and height as a [`Size`].
pub fn size(&self) -> Size {
Size::new(self.width(), self.height())
}

/// Returns whether this rectangle has finite edges and finite, positive dimensions.
pub fn is_valid(&self) -> bool {
[
Expand Down
Loading