pdfium_render/pdf/
appearance_mode.rs

1//! Defines the [PdfAppearanceMode] enum, which specifies the type of appearance stream
2//! that should apply to a given `PdfPageAnnotation` or `PdfFormField` object.
3
4use crate::bindgen::{
5    FPDF_ANNOT_APPEARANCEMODE_DOWN, FPDF_ANNOT_APPEARANCEMODE_NORMAL,
6    FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
7};
8use crate::error::PdfiumError;
9use std::os::raw::c_int;
10
11/// The type of appearance stream that should apply to a given `PdfPageAnnotation` or
12/// `PdfFormField` object.
13#[derive(Copy, Clone, Debug, PartialEq)]
14pub enum PdfAppearanceMode {
15    Normal = FPDF_ANNOT_APPEARANCEMODE_NORMAL as isize,
16    RollOver = FPDF_ANNOT_APPEARANCEMODE_ROLLOVER as isize,
17    Down = FPDF_ANNOT_APPEARANCEMODE_DOWN as isize,
18}
19
20impl PdfAppearanceMode {
21    #[allow(dead_code)] // We don't currently use the from_pdfium() function, but we expect to in future
22    #[inline]
23    pub(crate) fn from_pdfium(value: u32) -> Result<Self, PdfiumError> {
24        match value {
25            FPDF_ANNOT_APPEARANCEMODE_NORMAL => Ok(PdfAppearanceMode::Normal),
26            FPDF_ANNOT_APPEARANCEMODE_ROLLOVER => Ok(PdfAppearanceMode::RollOver),
27            FPDF_ANNOT_APPEARANCEMODE_DOWN => Ok(PdfAppearanceMode::Down),
28            _ => Err(PdfiumError::UnknownAppearanceMode),
29        }
30    }
31
32    #[inline]
33    pub(crate) fn as_pdfium(&self) -> c_int {
34        (match self {
35            PdfAppearanceMode::Normal => FPDF_ANNOT_APPEARANCEMODE_NORMAL,
36            PdfAppearanceMode::RollOver => FPDF_ANNOT_APPEARANCEMODE_ROLLOVER,
37            PdfAppearanceMode::Down => FPDF_ANNOT_APPEARANCEMODE_DOWN,
38        }) as c_int
39    }
40}