use crate::{deref, Array, Namespace, RdfCollectionType, Struct};
pub struct PdfAExtSchemaWriter<'a, 'n: 'a> {
stc: Struct<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtSchemaWriter<'a, 'n> {
fn start(stc: Struct<'a, 'n>) -> Self {
Self { stc }
}
pub fn namespace(&mut self, namespace: Namespace<'n>) -> &mut Self {
self.schema(&format!("{} schema", namespace.name()));
self.namespace_uri(namespace.url());
self.prefix(namespace.prefix());
self
}
fn schema(&mut self, schema: &str) -> &mut Self {
self.stc.element("schema", Namespace::PdfASchema).value(schema);
self
}
fn namespace_uri(&mut self, uri: &str) -> &mut Self {
self.stc.element("namespaceURI", Namespace::PdfASchema).value(uri);
self
}
fn prefix(&mut self, prefix: &str) -> &mut Self {
self.stc.element("prefix", Namespace::PdfASchema).value(prefix);
self
}
pub fn properties(&mut self) -> PdfAExtPropertiesWriter<'_, 'n> {
PdfAExtPropertiesWriter::start(
self.stc
.element("property", Namespace::PdfASchema)
.array(RdfCollectionType::Seq),
)
}
pub fn value_types(&mut self) -> PdfAExtTypesWriter<'_, 'n> {
PdfAExtTypesWriter::start(
self.stc
.element("valueType", Namespace::PdfASchema)
.array(RdfCollectionType::Seq),
)
}
}
deref!('a, 'n, PdfAExtSchemaWriter<'a, 'n> => Struct<'a, 'n>, stc);
pub struct PdfAExtPropertyWriter<'a, 'n: 'a> {
stc: Struct<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtPropertyWriter<'a, 'n> {
fn start(stc: Struct<'a, 'n>) -> Self {
Self { stc }
}
pub fn name(&mut self, name: &str) -> &mut Self {
self.stc.element("name", Namespace::PdfAProperty).value(name);
self
}
pub fn value_type(&mut self, value_type: &str) -> &mut Self {
self.stc
.element("valueType", Namespace::PdfAProperty)
.value(value_type);
self
}
pub fn category(&mut self, internal: bool) -> &mut Self {
self.stc
.element("category", Namespace::PdfAProperty)
.value(if internal { "internal" } else { "external" });
self
}
pub fn description(&mut self, description: &str) -> &mut Self {
self.stc
.element("description", Namespace::PdfAProperty)
.value(description);
self
}
}
deref!('a, 'n, PdfAExtPropertyWriter<'a, 'n> => Struct<'a, 'n>, stc);
pub struct PdfAExtTypeWriter<'a, 'n: 'a> {
stc: Struct<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtTypeWriter<'a, 'n> {
fn start(stc: Struct<'a, 'n>) -> Self {
Self { stc }
}
pub fn name(&mut self, name: &str) -> &mut Self {
self.stc.element("type", Namespace::PdfAType).value(name);
self
}
pub fn namespace(&mut self, namespace: Namespace<'n>) -> &mut Self {
self.namespace_uri(namespace.url());
self.prefix(namespace.prefix());
self
}
pub fn namespace_uri(&mut self, uri: &str) -> &mut Self {
self.stc.element("namespaceURI", Namespace::PdfAType).value(uri);
self
}
pub fn prefix(&mut self, prefix: &str) -> &mut Self {
self.stc.element("prefix", Namespace::PdfAType).value(prefix);
self
}
pub fn description(&mut self, description: &str) -> &mut Self {
self.stc
.element("description", Namespace::PdfAType)
.value(description);
self
}
pub fn fields(&mut self) -> PdfAExtTypeFieldsWriter<'_, 'n> {
PdfAExtTypeFieldsWriter::start(
self.stc
.element("field", Namespace::PdfAType)
.array(RdfCollectionType::Seq),
)
}
}
deref!('a, 'n, PdfAExtTypeWriter<'a, 'n> => Struct<'a, 'n>, stc);
pub struct PdfAExtTypeFieldWriter<'a, 'n: 'a> {
stc: Struct<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtTypeFieldWriter<'a, 'n> {
fn start(stc: Struct<'a, 'n>) -> Self {
Self { stc }
}
pub fn name(&mut self, name: &str) -> &mut Self {
self.stc.element("name", Namespace::PdfAField).value(name);
self
}
pub fn value_type(&mut self, value_type: &str) -> &mut Self {
self.stc.element("valueType", Namespace::PdfAField).value(value_type);
self
}
pub fn description(&mut self, description: &str) -> &mut Self {
self.stc
.element("description", Namespace::PdfAField)
.value(description);
self
}
}
deref!('a, 'n, PdfAExtTypeFieldWriter<'a, 'n> => Struct<'a, 'n>, stc);
pub struct PdfAExtTypeFieldsWriter<'a, 'n: 'a> {
array: Array<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtTypeFieldsWriter<'a, 'n> {
fn start(array: Array<'a, 'n>) -> Self {
Self { array }
}
pub fn add_field(&mut self) -> PdfAExtTypeFieldWriter<'_, 'n> {
PdfAExtTypeFieldWriter::start(self.array.element().obj())
}
}
deref!('a, 'n, PdfAExtTypeFieldsWriter<'a, 'n> => Array<'a, 'n>, array);
pub struct PdfAExtPropertiesWriter<'a, 'n: 'a> {
array: Array<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtPropertiesWriter<'a, 'n> {
fn start(array: Array<'a, 'n>) -> Self {
Self { array }
}
pub fn add_property(&mut self) -> PdfAExtPropertyWriter<'_, 'n> {
PdfAExtPropertyWriter::start(self.array.element().obj())
}
}
deref!('a, 'n, PdfAExtPropertiesWriter<'a, 'n> => Array<'a, 'n>, array);
pub struct PdfAExtTypesWriter<'a, 'n: 'a> {
array: Array<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtTypesWriter<'a, 'n> {
fn start(array: Array<'a, 'n>) -> Self {
Self { array }
}
pub fn add_value_type(&mut self) -> PdfAExtTypeWriter<'_, 'n> {
PdfAExtTypeWriter::start(self.array.element().obj())
}
}
pub struct PdfAExtSchemasWriter<'a, 'n: 'a> {
array: Array<'a, 'n>,
}
impl<'a, 'n: 'a> PdfAExtSchemasWriter<'a, 'n> {
pub(crate) fn start(array: Array<'a, 'n>) -> Self {
Self { array }
}
pub fn add_schema(&mut self) -> PdfAExtSchemaWriter<'_, 'n> {
PdfAExtSchemaWriter::start(self.array.element().obj())
}
pub fn pdfaid(&mut self, corrigendum: bool) -> &mut Self {
{
let mut schema = self.add_schema();
schema.namespace(Namespace::PdfAId);
let mut properties = schema.properties();
properties
.add_property()
.category(true)
.description("Part of PDF/A standard")
.name("part")
.value_type("Integer");
properties
.add_property()
.category(true)
.description("Amendment of PDF/A standard")
.name("amd")
.value_type("Text");
if corrigendum {
properties
.add_property()
.category(true)
.description("Corrigendum of PDF/A standard")
.name("corr")
.value_type("Text");
}
properties
.add_property()
.category(true)
.description("Conformance level of PDF/A standard")
.name("conformance")
.value_type("Text");
}
self
}
pub fn pdf(&mut self) -> AdobePdfDescsWriter<'_, 'n> {
AdobePdfDescsWriter::start(self.add_schema())
}
pub fn xmp(&mut self) -> XmpDescsWriter<'_, 'n> {
XmpDescsWriter::start(self.add_schema())
}
pub fn xmp_media_management(&mut self) -> XmpMMDescsWriter<'_, 'n> {
XmpMMDescsWriter::start(self.add_schema())
}
pub fn paged_text(&mut self) -> PagedTextDescsWriter<'_, 'n> {
PagedTextDescsWriter::start(self.add_schema())
}
pub fn resource_event(&mut self) -> ResourceEventDescsWriter<'_, 'n> {
ResourceEventDescsWriter::start(self.add_schema())
}
pub fn thumbnail(&mut self) -> ThumbnailSchemaWriter<'_, 'n> {
ThumbnailSchemaWriter::start(self.add_schema())
}
}
deref!('a, 'n, PdfAExtSchemasWriter<'a, 'n> => Array<'a, 'n>, array);
pub struct XmpPropertiesWriter<'a, 'n: 'a> {
props: PdfAExtPropertiesWriter<'a, 'n>,
}
impl<'a, 'n: 'a> XmpPropertiesWriter<'a, 'n> {
fn start(props: PdfAExtPropertiesWriter<'a, 'n>) -> Self {
Self { props }
}
pub fn describe_label(&mut self) -> &mut Self {
self.add_property()
.category(false)
.description("A user-defined label for the resource")
.name("Label")
.value_type("Text");
self
}
pub fn describe_rating(&mut self) -> &mut Self {
self.add_property()
.category(false)
.description("A user-assigned rating of the resource")
.name("Rating")
.value_type("Integer");
self
}
pub fn describe_all(mut self) {
self.describe_label().describe_rating();
}
}
deref!('a, 'n, XmpPropertiesWriter<'a, 'n> => PdfAExtPropertiesWriter<'a, 'n>, props);
pub struct XmpDescsWriter<'a, 'n: 'a> {
schema: PdfAExtSchemaWriter<'a, 'n>,
}
impl<'a, 'n: 'a> XmpDescsWriter<'a, 'n> {
fn start(mut schema: PdfAExtSchemaWriter<'a, 'n>) -> Self {
schema.namespace(Namespace::Xmp);
Self { schema }
}
pub fn properties(&mut self) -> XmpPropertiesWriter<'_, 'n> {
XmpPropertiesWriter::start(self.schema.properties())
}
}
deref!('a, 'n, XmpDescsWriter<'a, 'n> => PdfAExtSchemaWriter<'a, 'n>, schema);
pub struct XmpMMPropertiesWriter<'a, 'n: 'a> {
props: PdfAExtPropertiesWriter<'a, 'n>,
}
impl<'a, 'n: 'a> XmpMMPropertiesWriter<'a, 'n> {
fn start(props: PdfAExtPropertiesWriter<'a, 'n>) -> Self {
Self { props }
}
pub fn describe_instance_id(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("UUID based identifier for specific incarnation of a document")
.name("InstanceID")
.value_type("Text");
self
}
pub fn describe_ingredients(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("List of ingredients that were used to create a document")
.name("Ingredients")
.value_type("ResourceRef");
self
}
pub fn describe_original_doc_id(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("UUID based identifier for original document from which a document is derived")
.name("OriginalDocumentID")
.value_type("Text");
self
}
pub fn describe_pantry(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("List of ingredients that were used to create a document")
.name("Pantry")
.value_type("ResourceRef");
self
}
pub fn describe_all(mut self) {
self.describe_instance_id()
.describe_ingredients()
.describe_original_doc_id()
.describe_pantry();
}
}
deref!('a, 'n, XmpMMPropertiesWriter<'a, 'n> => PdfAExtPropertiesWriter<'a, 'n>, props);
pub struct XmpMMDescsWriter<'a, 'n: 'a> {
schema: PdfAExtSchemaWriter<'a, 'n>,
}
impl<'a, 'n: 'a> XmpMMDescsWriter<'a, 'n> {
fn start(mut schema: PdfAExtSchemaWriter<'a, 'n>) -> Self {
schema.namespace(Namespace::XmpMedia);
Self { schema }
}
pub fn properties(&mut self) -> XmpMMPropertiesWriter<'_, 'n> {
XmpMMPropertiesWriter::start(self.schema.properties())
}
}
deref!('a, 'n, XmpMMDescsWriter<'a, 'n> => PdfAExtSchemaWriter<'a, 'n>, schema);
pub struct AdobePdfPropertiesWriter<'a, 'n: 'a> {
props: PdfAExtPropertiesWriter<'a, 'n>,
}
impl<'a, 'n: 'a> AdobePdfPropertiesWriter<'a, 'n> {
fn start(props: PdfAExtPropertiesWriter<'a, 'n>) -> Self {
Self { props }
}
pub fn describe_keywords(&mut self) -> &mut Self {
self.add_property()
.category(false)
.description("Keywords associated with the document")
.name("Keywords")
.value_type("Text");
self
}
pub fn describe_pdf_version(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description(
"Version of the PDF specification to which the document conforms",
)
.name("PDFVersion")
.value_type("Text");
self
}
pub fn describe_producer(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Name of the application that created the PDF document")
.name("Producer")
.value_type("Text");
self
}
pub fn describe_trapped(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Whether the document has been trapped")
.name("Trapped")
.value_type("Text");
self
}
pub fn describe_all(mut self) {
self.describe_keywords()
.describe_pdf_version()
.describe_producer()
.describe_trapped();
}
}
deref!('a, 'n, AdobePdfPropertiesWriter<'a, 'n> => PdfAExtPropertiesWriter<'a, 'n>, props);
pub struct AdobePdfDescsWriter<'a, 'n: 'a> {
schema: PdfAExtSchemaWriter<'a, 'n>,
}
impl<'a, 'n: 'a> AdobePdfDescsWriter<'a, 'n> {
fn start(mut schema: PdfAExtSchemaWriter<'a, 'n>) -> Self {
schema.namespace(Namespace::AdobePdf);
Self { schema }
}
pub fn properties(&mut self) -> AdobePdfPropertiesWriter<'_, 'n> {
AdobePdfPropertiesWriter::start(self.schema.properties())
}
}
deref!('a, 'n, AdobePdfDescsWriter<'a, 'n> => PdfAExtSchemaWriter<'a, 'n>, schema);
pub struct PagedTextDescsWriter<'a, 'n: 'a> {
schema: PdfAExtSchemaWriter<'a, 'n>,
}
impl<'a, 'n: 'a> PagedTextDescsWriter<'a, 'n> {
fn start(mut schema: PdfAExtSchemaWriter<'a, 'n>) -> Self {
schema.namespace(Namespace::AdobePdf);
Self { schema }
}
pub fn properties(&mut self) -> PagedTextPropertiesWriter<'_, 'n> {
PagedTextPropertiesWriter::start(self.schema.properties())
}
}
deref!('a, 'n, PagedTextDescsWriter<'a, 'n> => PdfAExtSchemaWriter<'a, 'n>, schema);
pub struct PagedTextPropertiesWriter<'a, 'n: 'a> {
props: PdfAExtPropertiesWriter<'a, 'n>,
}
impl<'a, 'n: 'a> PagedTextPropertiesWriter<'a, 'n> {
fn start(props: PdfAExtPropertiesWriter<'a, 'n>) -> Self {
Self { props }
}
pub fn describe_keywords(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Colorants / swatches used in the document and its children")
.name("Colorants")
.value_type("Colorant");
self
}
pub fn describe_fonts(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Fonts used in the document and its children")
.name("Fonts")
.value_type("Font");
self
}
pub fn describe_plate_names(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Plate names used in the document and its children")
.name("PlateNames")
.value_type("Text");
self
}
pub fn describe_all(mut self) {
self.describe_keywords().describe_fonts().describe_plate_names();
}
}
deref!('a, 'n, PagedTextPropertiesWriter<'a, 'n> => PdfAExtPropertiesWriter<'a, 'n>, props);
pub struct ResourceEventDescsWriter<'a, 'n: 'a> {
schema: PdfAExtSchemaWriter<'a, 'n>,
}
impl<'a, 'n: 'a> ResourceEventDescsWriter<'a, 'n> {
fn start(mut schema: PdfAExtSchemaWriter<'a, 'n>) -> Self {
schema.namespace(Namespace::XmpResourceEvent);
Self { schema }
}
pub fn properties(&mut self) -> ResourceEventPropertiesWriter<'_, 'n> {
ResourceEventPropertiesWriter::start(self.schema.properties())
}
}
deref!('a, 'n, ResourceEventDescsWriter<'a, 'n> => PdfAExtSchemaWriter<'a, 'n>, schema);
pub struct ResourceEventPropertiesWriter<'a, 'n: 'a> {
props: PdfAExtPropertiesWriter<'a, 'n>,
}
impl<'a, 'n: 'a> ResourceEventPropertiesWriter<'a, 'n> {
fn start(props: PdfAExtPropertiesWriter<'a, 'n>) -> Self {
Self { props }
}
pub fn describe_changed(&mut self) -> &mut Self {
self.add_property()
.category(false)
.description("semicolon-delimited list of the parts of the resource that were changed since the previous event history")
.name("changed")
.value_type("Text");
self
}
}
deref!('a, 'n, ResourceEventPropertiesWriter<'a, 'n> => PdfAExtPropertiesWriter<'a, 'n>, props);
pub struct ThumbnailSchemaWriter<'a, 'n: 'a> {
schema: PdfAExtSchemaWriter<'a, 'n>,
}
impl<'a, 'n: 'a> ThumbnailSchemaWriter<'a, 'n> {
fn start(mut schema: PdfAExtSchemaWriter<'a, 'n>) -> Self {
schema.namespace(Namespace::XmpImage);
Self { schema }
}
pub fn properties(&mut self) -> ThumbnailPropertiesWriter<'_, 'n> {
ThumbnailPropertiesWriter::start(self.schema.properties())
}
}
deref!('a, 'n, ThumbnailSchemaWriter<'a, 'n> => PdfAExtSchemaWriter<'a, 'n>, schema);
pub struct ThumbnailPropertiesWriter<'a, 'n: 'a> {
props: PdfAExtPropertiesWriter<'a, 'n>,
}
impl<'a, 'n: 'a> ThumbnailPropertiesWriter<'a, 'n> {
fn start(props: PdfAExtPropertiesWriter<'a, 'n>) -> Self {
Self { props }
}
pub fn describe_height(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Height of the image in pixels")
.name("height")
.value_type("Integer");
self
}
pub fn describe_image(&mut self) -> &mut Self {
self.add_property()
.category(false)
.description("Thumbnail image data in base64 encoding")
.name("image")
.value_type("Text");
self
}
pub fn describe_width(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("Width of the image in pixels")
.name("width")
.value_type("Integer");
self
}
pub fn describe_format(&mut self) -> &mut Self {
self.add_property()
.category(true)
.description("The image encoding, i.e. JPEG")
.name("format")
.value_type("Closed Choice");
self
}
pub fn describe_all(mut self) {
self.describe_height()
.describe_image()
.describe_width()
.describe_format();
}
}
deref!('a, 'n, ThumbnailPropertiesWriter<'a, 'n> => PdfAExtPropertiesWriter<'a, 'n>, props);