1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{
ffi, Annot, AnnotMapping, Color, FindFlags, FormFieldMapping, ImageMapping, LinkMapping,
PSFile, PageTransition, PrintFlags, Rectangle, SelectionStyle, TextAttributes,
};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
///
///
/// ## Properties
///
///
/// #### `label`
/// The label of the page or [`None`]. See also [`Page::label()`][crate::Page::label()]
///
/// Readable
#[doc(alias = "PopplerPage")]
pub struct Page(Object<ffi::PopplerPage>);
match fn {
type_ => || ffi::poppler_page_get_type(),
}
}
impl Page {
/// Adds annotation `annot` to `self`.
/// ## `annot`
/// a [`Annot`][crate::Annot] to add
#[doc(alias = "poppler_page_add_annot")]
pub fn add_annot(&self, annot: &impl IsA<Annot>) {
unsafe {
ffi::poppler_page_add_annot(self.to_glib_none().0, annot.as_ref().to_glib_none().0);
}
}
/// Finds `text` in `self` with the default options ([`FindFlags::DEFAULT`][crate::FindFlags::DEFAULT]) and
/// returns a `GList` of rectangles for each occurrence of the text on the page.
/// The coordinates are in PDF points.
/// ## `text`
/// the text to search for (UTF-8 encoded)
///
/// # Returns
///
/// a `GList` of [`Rectangle`][crate::Rectangle],
#[doc(alias = "poppler_page_find_text")]
pub fn find_text(&self, text: &str) -> Vec<Rectangle> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_find_text(
self.to_glib_none().0,
text.to_glib_none().0,
))
}
}
/// Finds `text` in `self` with the given [`FindFlags`][crate::FindFlags] options and
/// returns a `GList` of rectangles for each occurrence of the text on the page.
/// The coordinates are in PDF points.
///
/// When [`FindFlags::MULTILINE`][crate::FindFlags::MULTILINE] is passed in `options`, matches may span more than
/// one line. In this case, the returned list will contain one [`Rectangle`][crate::Rectangle]
/// for each part of a match. The function [`Rectangle::find_get_match_continued()`][crate::Rectangle::find_get_match_continued()]
/// will return [`true`] for all rectangles belonging to the same match, except for
/// the last one. If a hyphen was ignored at the end of the part of the match,
/// [`Rectangle::find_get_ignored_hyphen()`][crate::Rectangle::find_get_ignored_hyphen()] will return [`true`] for that
/// rectangle.
///
/// Note that currently matches spanning more than two lines are not found.
/// (This limitation may be lifted in a future version.)
///
/// Note also that currently finding multi-line matches backwards is not
/// implemented; if you pass [`FindFlags::BACKWARDS`][crate::FindFlags::BACKWARDS] and [`FindFlags::MULTILINE`][crate::FindFlags::MULTILINE]
/// together, [`FindFlags::MULTILINE`][crate::FindFlags::MULTILINE] will be ignored.
/// ## `text`
/// the text to search for (UTF-8 encoded)
/// ## `options`
/// find options
///
/// # Returns
///
/// a newly allocated list
/// of newly allocated [`Rectangle`][crate::Rectangle]. Free with `g_list_free_full()` using `poppler_rectangle_free()`.
#[doc(alias = "poppler_page_find_text_with_options")]
pub fn find_text_with_options(&self, text: &str, options: FindFlags) -> Vec<Rectangle> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_find_text_with_options(
self.to_glib_none().0,
text.to_glib_none().0,
options.into_glib(),
))
}
}
/// Returns a list of [`AnnotMapping`][crate::AnnotMapping] items that map from a location on
/// `self` to a [`Annot`][crate::Annot]. This list must be freed with
/// `poppler_page_free_annot_mapping()` when done.
///
/// # Returns
///
/// A `GList` of [`AnnotMapping`][crate::AnnotMapping]
#[doc(alias = "poppler_page_get_annot_mapping")]
#[doc(alias = "get_annot_mapping")]
pub fn annot_mapping(&self) -> Vec<AnnotMapping> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_annot_mapping(
self.to_glib_none().0,
))
}
}
#[doc(alias = "poppler_page_get_bounding_box")]
pub fn get_bounding_box(&self, rect: &mut Rectangle) -> bool {
unsafe {
from_glib(ffi::poppler_page_get_bounding_box(
self.to_glib_none().0,
rect.to_glib_none_mut().0,
))
}
}
/// Returns the duration of `self`
///
/// # Returns
///
/// duration in seconds of `self` or -1.
#[doc(alias = "poppler_page_get_duration")]
#[doc(alias = "get_duration")]
pub fn duration(&self) -> f64 {
unsafe { ffi::poppler_page_get_duration(self.to_glib_none().0) }
}
/// Returns a list of [`FormFieldMapping`][crate::FormFieldMapping] items that map from a
/// location on `self` to a form field. This list must be freed
/// with `poppler_page_free_form_field_mapping()` when done.
///
/// # Returns
///
/// A `GList` of [`FormFieldMapping`][crate::FormFieldMapping]
#[doc(alias = "poppler_page_get_form_field_mapping")]
#[doc(alias = "get_form_field_mapping")]
pub fn form_field_mapping(&self) -> Vec<FormFieldMapping> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_form_field_mapping(
self.to_glib_none().0,
))
}
}
/// Returns a cairo surface for the image of the `self`
/// ## `image_id`
/// The image identifier
///
/// # Returns
///
/// A cairo surface for the image
#[doc(alias = "poppler_page_get_image")]
#[doc(alias = "get_image")]
pub fn image(&self, image_id: i32) -> Option<cairo::Surface> {
unsafe { from_glib_full(ffi::poppler_page_get_image(self.to_glib_none().0, image_id)) }
}
/// Returns a list of [`ImageMapping`][crate::ImageMapping] items that map from a
/// location on `self` to an image of the page. This list must be freed
/// with `poppler_page_free_image_mapping()` when done.
///
/// # Returns
///
/// A `GList` of [`ImageMapping`][crate::ImageMapping]
#[doc(alias = "poppler_page_get_image_mapping")]
#[doc(alias = "get_image_mapping")]
pub fn image_mapping(&self) -> Vec<ImageMapping> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_image_mapping(
self.to_glib_none().0,
))
}
}
/// Returns the index of `self`
///
/// # Returns
///
/// index value of `self`
#[doc(alias = "poppler_page_get_index")]
#[doc(alias = "get_index")]
pub fn index(&self) -> i32 {
unsafe { ffi::poppler_page_get_index(self.to_glib_none().0) }
}
/// Returns the label of `self`. Note that page labels
/// and page indices might not coincide.
///
/// # Returns
///
/// a new allocated string containing the label of `self`,
/// or [`None`] if `self` doesn't have a label
#[doc(alias = "poppler_page_get_label")]
#[doc(alias = "get_label")]
pub fn label(&self) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::poppler_page_get_label(self.to_glib_none().0)) }
}
/// Returns a list of [`LinkMapping`][crate::LinkMapping] items that map from a
/// location on `self` to a `PopplerAction`. This list must be freed
/// with `poppler_page_free_link_mapping()` when done.
///
/// # Returns
///
/// A `GList` of [`LinkMapping`][crate::LinkMapping]
#[doc(alias = "poppler_page_get_link_mapping")]
#[doc(alias = "get_link_mapping")]
pub fn link_mapping(&self) -> Vec<LinkMapping> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_link_mapping(
self.to_glib_none().0,
))
}
}
/// Returns a region containing the area that would be rendered by
/// [`render_selection()`][Self::render_selection()].
/// The returned region must be freed with `cairo_region_destroy()`
/// ## `scale`
/// scale specified as pixels per point
/// ## `style`
/// a [`SelectionStyle`][crate::SelectionStyle]
/// ## `selection`
/// start and end point of selection as a rectangle
///
/// # Returns
///
/// a cairo_region_t
#[doc(alias = "poppler_page_get_selected_region")]
#[doc(alias = "get_selected_region")]
pub fn selected_region(
&self,
scale: f64,
style: SelectionStyle,
selection: &mut Rectangle,
) -> Option<cairo::Region> {
unsafe {
from_glib_full(ffi::poppler_page_get_selected_region(
self.to_glib_none().0,
scale,
style.into_glib(),
selection.to_glib_none_mut().0,
))
}
}
/// Retrieves the contents of the specified `selection` as text.
/// ## `style`
/// a [`SelectionStyle`][crate::SelectionStyle]
/// ## `selection`
/// the [`Rectangle`][crate::Rectangle] including the text
///
/// # Returns
///
/// a pointer to the contents of the `selection`
/// as a string
#[doc(alias = "poppler_page_get_selected_text")]
#[doc(alias = "get_selected_text")]
pub fn selected_text(
&self,
style: SelectionStyle,
selection: &mut Rectangle,
) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::poppler_page_get_selected_text(
self.to_glib_none().0,
style.into_glib(),
selection.to_glib_none_mut().0,
))
}
}
/// Gets the size of `self` at the current scale and rotation.
///
/// # Returns
///
///
/// ## `width`
/// return location for the width of `self`
///
/// ## `height`
/// return location for the height of `self`
#[doc(alias = "poppler_page_get_size")]
#[doc(alias = "get_size")]
pub fn size(&self) -> (f64, f64) {
unsafe {
let mut width = std::mem::MaybeUninit::uninit();
let mut height = std::mem::MaybeUninit::uninit();
ffi::poppler_page_get_size(
self.to_glib_none().0,
width.as_mut_ptr(),
height.as_mut_ptr(),
);
(width.assume_init(), height.assume_init())
}
}
/// Retrieves the text of `self`.
///
/// # Returns
///
/// a pointer to the text of the `self`
/// as a string
#[doc(alias = "poppler_page_get_text")]
#[doc(alias = "get_text")]
pub fn text(&self) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::poppler_page_get_text(self.to_glib_none().0)) }
}
/// Obtains the attributes of the text as a `GList` of [`TextAttributes`][crate::TextAttributes].
/// This list must be freed with `poppler_page_free_text_attributes()` when done.
///
/// Each list element is a [`TextAttributes`][crate::TextAttributes] struct where start_index and
/// end_index indicates the range of text (as returned by [`text()`][Self::text()])
/// to which text attributes apply.
///
/// See also [`text_attributes_for_area()`][Self::text_attributes_for_area()]
///
/// # Returns
///
/// A `GList` of [`TextAttributes`][crate::TextAttributes]
#[doc(alias = "poppler_page_get_text_attributes")]
#[doc(alias = "get_text_attributes")]
pub fn text_attributes(&self) -> Vec<TextAttributes> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_text_attributes(
self.to_glib_none().0,
))
}
}
/// Obtains the attributes of the text in `area` as a `GList` of [`TextAttributes`][crate::TextAttributes].
/// This list must be freed with `poppler_page_free_text_attributes()` when done.
///
/// Each list element is a [`TextAttributes`][crate::TextAttributes] struct where start_index and
/// end_index indicates the range of text (as returned by [`text_for_area()`][Self::text_for_area()])
/// to which text attributes apply.
/// ## `area`
/// a [`Rectangle`][crate::Rectangle]
///
/// # Returns
///
/// A `GList` of [`TextAttributes`][crate::TextAttributes]
#[doc(alias = "poppler_page_get_text_attributes_for_area")]
#[doc(alias = "get_text_attributes_for_area")]
pub fn text_attributes_for_area(&self, area: &mut Rectangle) -> Vec<TextAttributes> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::poppler_page_get_text_attributes_for_area(
self.to_glib_none().0,
area.to_glib_none_mut().0,
))
}
}
/// Retrieves the text of `self` contained in `area`.
/// ## `area`
/// a [`Rectangle`][crate::Rectangle]
///
/// # Returns
///
/// a pointer to the text as a string
#[doc(alias = "poppler_page_get_text_for_area")]
#[doc(alias = "get_text_for_area")]
pub fn text_for_area(&self, area: &mut Rectangle) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::poppler_page_get_text_for_area(
self.to_glib_none().0,
area.to_glib_none_mut().0,
))
}
}
/// Get the embedded thumbnail for the specified page. If the document
/// doesn't have an embedded thumbnail for the page, this function
/// returns [`None`].
///
/// # Returns
///
/// the tumbnail as a cairo_surface_t or [`None`] if the document
/// doesn't have a thumbnail for this page.
#[doc(alias = "poppler_page_get_thumbnail")]
#[doc(alias = "get_thumbnail")]
pub fn thumbnail(&self) -> Option<cairo::Surface> {
unsafe { from_glib_full(ffi::poppler_page_get_thumbnail(self.to_glib_none().0)) }
}
/// Returns [`true`] if `self` has a thumbnail associated with it. It also
/// fills in `width` and `height` with the width and height of the
/// thumbnail. The values of width and height are not changed if no
/// appropriate thumbnail exists.
///
/// # Returns
///
/// [`true`], if `self` has a thumbnail associated with it.
///
/// ## `width`
/// return location for width
///
/// ## `height`
/// return location for height
#[doc(alias = "poppler_page_get_thumbnail_size")]
#[doc(alias = "get_thumbnail_size")]
pub fn thumbnail_size(&self) -> Option<(i32, i32)> {
unsafe {
let mut width = std::mem::MaybeUninit::uninit();
let mut height = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::poppler_page_get_thumbnail_size(
self.to_glib_none().0,
width.as_mut_ptr(),
height.as_mut_ptr(),
));
if ret {
Some((width.assume_init(), height.assume_init()))
} else {
None
}
}
}
/// Returns the transition effect of `self`
///
/// # Returns
///
/// a [`PageTransition`][crate::PageTransition] or [`None`].
#[doc(alias = "poppler_page_get_transition")]
#[doc(alias = "get_transition")]
pub fn transition(&self) -> Option<PageTransition> {
unsafe { from_glib_full(ffi::poppler_page_get_transition(self.to_glib_none().0)) }
}
/// Removes annotation `annot` from `self`
/// ## `annot`
/// a [`Annot`][crate::Annot] to remove
#[doc(alias = "poppler_page_remove_annot")]
pub fn remove_annot(&self, annot: &impl IsA<Annot>) {
unsafe {
ffi::poppler_page_remove_annot(self.to_glib_none().0, annot.as_ref().to_glib_none().0);
}
}
/// Render the page to the given cairo context. This function
/// is for rendering a page that will be displayed. If you want
/// to render a page that will be printed use
/// [`render_for_printing()`][Self::render_for_printing()] instead. Please see the documentation
/// for that function for the differences between rendering to the screen and
/// rendering to a printer.
/// ## `cairo`
/// cairo context to render to
#[doc(alias = "poppler_page_render")]
pub fn render(&self, cairo: &cairo::Context) {
unsafe {
ffi::poppler_page_render(self.to_glib_none().0, mut_override(cairo.to_glib_none().0));
}
}
/// Render the page to the given cairo context for printing with
/// [`PrintFlags::ALL`][crate::PrintFlags::ALL] flags selected. If you want a different set of flags,
/// use [`render_for_printing_with_options()`][Self::render_for_printing_with_options()].
///
/// The difference between [`render()`][Self::render()] and this function is that some
/// things get rendered differently between screens and printers:
///
/// `<itemizedlist>`
/// `<listitem>`
/// PDF annotations get rendered according to their [`AnnotFlag`][crate::AnnotFlag] value.
/// For example, [`AnnotFlag::PRINT`][crate::AnnotFlag::PRINT] refers to whether an annotation
/// is printed or not, whereas [`AnnotFlag::NO_VIEW`][crate::AnnotFlag::NO_VIEW] refers to whether
/// an annotation is invisible when displaying to the screen.
/// `</listitem>`
/// `<listitem>`
/// PDF supports "hairlines" of width 0.0, which often get rendered as
/// having a width of 1 device pixel. When displaying on a screen, Cairo
/// may render such lines wide so that they are hard to see, and Poppler
/// makes use of PDF's Stroke Adjust graphics parameter to make the lines
/// easier to see. However, when printing, Poppler is able to directly use a
/// printer's pixel size instead.
/// `</listitem>`
/// `<listitem>`
/// Some advanced features in PDF may require an image to be rasterized
/// before sending off to a printer. This may produce raster images which
/// exceed Cairo's limits. The "printing" functions will detect this condition
/// and try to down-scale the intermediate surfaces as appropriate.
/// `</listitem>`
/// `</itemizedlist>`
/// ## `cairo`
/// cairo context to render to
#[doc(alias = "poppler_page_render_for_printing")]
pub fn render_for_printing(&self, cairo: &cairo::Context) {
unsafe {
ffi::poppler_page_render_for_printing(
self.to_glib_none().0,
mut_override(cairo.to_glib_none().0),
);
}
}
/// Render the page to the given cairo context for printing
/// with the specified options
///
/// See the documentation for [`render_for_printing()`][Self::render_for_printing()] for the
/// differences between rendering to the screen and rendering to a printer.
/// ## `cairo`
/// cairo context to render to
/// ## `options`
/// print options
#[doc(alias = "poppler_page_render_for_printing_with_options")]
pub fn render_for_printing_with_options(&self, cairo: &cairo::Context, options: PrintFlags) {
unsafe {
ffi::poppler_page_render_for_printing_with_options(
self.to_glib_none().0,
mut_override(cairo.to_glib_none().0),
options.into_glib(),
);
}
}
/// Render the selection specified by `selection` for `self` to
/// the given cairo context. The selection will be rendered, using
/// `glyph_color` for the glyphs and `background_color` for the selection
/// background.
///
/// If non-NULL, `old_selection` specifies the selection that is already
/// rendered to `cairo`, in which case this function will (some day)
/// only render the changed part of the selection.
/// ## `cairo`
/// cairo context to render to
/// ## `selection`
/// start and end point of selection as a rectangle
/// ## `old_selection`
/// previous selection
/// ## `style`
/// a [`SelectionStyle`][crate::SelectionStyle]
/// ## `glyph_color`
/// color to use for drawing glyphs
/// ## `background_color`
/// color to use for the selection background
#[doc(alias = "poppler_page_render_selection")]
pub fn render_selection(
&self,
cairo: &cairo::Context,
selection: &mut Rectangle,
old_selection: &mut Rectangle,
style: SelectionStyle,
glyph_color: &mut Color,
background_color: &mut Color,
) {
unsafe {
ffi::poppler_page_render_selection(
self.to_glib_none().0,
mut_override(cairo.to_glib_none().0),
selection.to_glib_none_mut().0,
old_selection.to_glib_none_mut().0,
style.into_glib(),
glyph_color.to_glib_none_mut().0,
background_color.to_glib_none_mut().0,
);
}
}
/// Render the page on a postscript file
/// ## `ps_file`
/// the PopplerPSFile to render to
#[doc(alias = "poppler_page_render_to_ps")]
pub fn render_to_ps(&self, ps_file: &PSFile) {
unsafe {
ffi::poppler_page_render_to_ps(self.to_glib_none().0, ps_file.to_glib_none().0);
}
}
#[doc(alias = "label")]
pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_label_trampoline<F: Fn(&Page) + 'static>(
this: *mut ffi::PopplerPage,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::label\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_label_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}