Skip to content
40 changes: 40 additions & 0 deletions crates/data/src/raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,46 @@ pub fn is_pdf_name(name: &str) -> bool {
/// Whether this build reads PDF pages (the `pdf` feature, #2336).
pub const PDF_PAGES: bool = cfg!(feature = "pdf");

/// What a PDF layer's subdataset puts between its page and its PDF layer's name ("1#Mapa / Rios");
/// nothing follows it for the content in no layer (#3442).
pub const PDF_LAYER_MARK: char = '#';
/// The name of the layer holding what a PDF page draws whatever its PDF layers.
pub const PDF_OUTSIDE: &str = "Not in a PDF layer";

/// One of a PDF page's layers (optional content groups, #3442), drawn alone.
pub struct PdfLayer {
/// Its group's name, after the names of those it is nested in ("Mapa / Rios").
pub name: String,
/// Whether the PDF shows it when opened.
pub visible: bool,
/// The page and layer that read it again, as a PDF's subdataset ("1#Mapa / Rios").
pub subdataset: String,
/// Its drawing: red, green, blue and alpha, transparent where it has nothing.
pub raster: Raster,
}

/// A PDF page's layers, the top first, and what is said of them all.
#[derive(Default)]
pub struct PdfLayers {
pub layers: Vec<PdfLayer>,
pub lost: crate::loss::Notes,
/// The page as one picture, drawn from the same read of the file, when it has no layers or
/// none could be drawn.
pub picture: Option<Raster>,
}

/// Page `page` of the PDF at `path` as its PDF layers, placed by its coordinates: none when it
/// has none, and in a build without the `pdf` feature, where it isn't read as a picture either.
pub fn read_pdf_layers(path: &Path, page: Option<&str>) -> Result<PdfLayers> {
#[cfg(feature = "pdf")]
return pdf::read_layers_file(path, page);
#[cfg(not(feature = "pdf"))]
{
let _ = (path, page);
Ok(PdfLayers::default())
}
}

/// Why a PDF isn't read in a build without the `pdf` feature (the browser, phones).
pub const PDF_ELSEWHERE: &str = "PDFs are read in the desktop app, the command line and Python, not here: open it there";

Expand Down
Loading
Loading