package org.verapdf.model.pdlayer;

import org.verapdf.model.baselayer.Object;
import org.verapdf.model.coslayer.CosDict;
import org.verapdf.model.coslayer.CosStream;
import org.verapdf.model.coslayer.CosReal;
import org.verapdf.model.coslayer.CosRenderingIntent;

import org.verapdf.model.operator.Operator;
import org.verapdf.model.external.ICCOutputProfile;
import org.verapdf.model.external.ICCInputProfile;
import org.verapdf.model.external.FontProgram;
import org.verapdf.model.external.CMapFile;
import org.verapdf.model.xmplayer.XMPPackage;


% base class for all PD layer objects	
type PDObject extends Object {
	
}

% the class corresponding to the high level PDF document structure 
type PDDocument extends PDObject {
	% the array of output intents of the document
	link outputIntents: PDOutputIntent*;
	% the collection of all document pages
	link pages: PDPage+;
	% document level metadata
	link metadata: PDMetadata?;
	% Interactive Form Dictionary (AcroForm entry in the Catalog)
	link AcroForm: PDAcroForm?;
	% additional actions defined for the document (AA entry in the Catalog)
	link AA: PDAction*;
	% document open action (OpenAction entry in the Catalog)
	link OpenAction: PDAction?;
	% document outlines (Outlines entry in the Catalog)
	link Outlines: PDOutline*;
}

% the object representing PDF page	
type PDPage extends PDObject {
	% all page annotations
	link annots: PDAnnot*;
	% document level action
	link action: PDAction?;
	% page content stream
	link contentStream: PDContentStream;
	% group attributes dictionary
	link Group: PDGroup?;
}

% the object representing content stream together with the resource dictionary
type PDContentStream extends PDObject {
	% all operators in the content stream
	link operators: Operator*;
}

% PDF resource object
type PDResource extends PDObject {

}

% Color space object
type PDColorSpace extends PDResource {
	% number of components
	property nrComponents: Integer;
}

% DeviceGray color space
type PDDeviceGray extends PDColorSpace {

}

% DeviceRGB color space
type PDDeviceRGB extends PDColorSpace {

}

% DeviceCMYK color space
type PDDeviceCMYK extends PDColorSpace {

}

% ICCBased color space
type PDICCBased extends PDColorSpace {
	% embedded ICC profile
	link iccProfile: ICCInputProfile;
}

% Lab color space
type PDLab extends PDColorSpace {

}

% CalGray color space
type PDCalGray extends PDColorSpace {

}

% CalRGB color space
type PDCalRGB extends PDColorSpace {

}

% Separation color space
type PDSeparation extends PDColorSpace {
	% alternate color space
	link alternate: PDColorSpace;
}

% DeviceN color space
type PDDeviceN extends PDColorSpace {
	% alternate color space
	link alternate: PDColorSpace;
}

% Indexed color space
type PDIndexed extends PDColorSpace {
	% base color space
	link base: PDColorSpace;
}

% generic Pattern type
type PDPattern extends PDColorSpace {

}

% tiling Pattern
type PDTilingPattern extends PDPattern {
	% content stream of the pattern
	link contentStream: PDContentStream;
}

% shading Pattern
type PDShadingPattern extends PDPattern {
	% shading object
	link shading: PDShading;
}

% PDF font dictionary
type PDFont extends PDResource {
	% font type (Type entry)
	property Type: String;
	% font subtype (Subtype entry)
	property Subtype: String;
	% base font name (BaseFont entry)
	property BaseFont: String;
	% true if the font flags in the font descriptor dictionary mark indicate that the font is symbolic (the entry /Flags has bit 3 set to 1 and bit 6 set to 0)
	property isSymbolic: Boolean;
	% embedded font program for Type 1, TrueType or CID Font
	link fontFile: FontProgram?;
}

% One of the simple font types (Type 1, TrueType, Type 3)
type PDSimpleFont extends PDFont {
	% true if the font is one of the 14 standard fonts defined in PDF 1.4 Reference
	property isStandard: Boolean;
	% FirstChar entry; null if LastChar entry is not present or has invalid type
	property FirstChar: Integer;
	% LastChar entry; null if LastChar entry is not present or has invalid type
	property LastChar: Integer;
	% The size of the Widths array; null if the Widths array is not present or has invalid type
	property Widths_size: Integer;
	% String representation of the font encoding: 
	% - null if the /Encoding entry is not present in the font dictionary
	% - if /Encoding entry in the font dictionary if of Name type, then the value of this entry;
	% - if /Encoding entry is a dictionary, which does not contain /Differences array, then the value of /BaseEncoding entry in this dictionary (or null, if /BaseEncoding is also not present)
	% - the string "Custom", of the /Encoding entry is a dictionary containing /Differences key
	property Encoding: String;
}

% TrueType font dictionary
type PDTrueTypeFont extends PDSimpleFont {

}

% Type1 font dictionary
type PDType1Font extends PDSimpleFont {
	% the value of the CharSet entry in the font descriptor dictionary
	property CharSet: String;
}

% Type3 font dictionary
type PDType3Font extends PDSimpleFont {
	% character strings
	link charStrings: PDContentStream*;
}

% CID Font dictionary
type PDCIDFont extends PDFont {
	% string representation of the CIDtoGIDMap entry ("Identity", or "Custom" in case of stream value)
	property CIDToGIDMap: String;
	% link to the stream containing the value of the CIDSet entry in the CID font descriptor dictionary
	link CIDSet: CosStream?;
}

% Type0 font dictionary
type PDType0Font extends PDFont {
	% True if Registry and Ordering keys of the corresponding CMap and CIDFont are compatible
	property areRegistryOrderingCompatible: Boolean;
	% link to the descendant CIDFont
	link DescendantFonts: PDCIDFont;
	% font CMap (Encoding entry)
	link Encoding: PDCMap;
}

% CMap dictionary or one of the predefined CMap names
type PDCMap extends PDObject {
	% name of the CMap (or the value of one of the predefined CMap's)
	property CMapName: String;
	% link to the embedded CMap file for an non-standard CMap
	link embeddedFile: CMapFile?;
}

% XObject resource
type PDXObject extends PDResource {
	% subtype of the XObject resource (Image, Form, PS)
	property Subtype: String;
	% link to the OPI dictionary (OPI key in the XObject dictionary)
	link OPI: CosDict?;
	% link to the soft mask image (SMask key)
	% according to the PDF Specification this key may be present only in the Image dictionary, 
	% but ISO 19005-1:2005/Cor.2:2011 forbids SMask key for all XObject dictionaries
	link SMask: PDXObject?;
}

% Image XObject
type PDXImage extends PDXObject {
	% image color space
	link imageCS: PDColorSpace;
	% Interpolate key in the image dictionary
	property Interpolate: Boolean;
	% image alternates (Alternates key in Image dictionary)
	link Alternates: PDXImage*;
	% color rendering intent
	link Intent: CosRenderingIntent?;
}

% Inline image object
type PDInlineImage extends PDXImage {
	% The SPACE-separated list of stream filters (abbreviated)
	property F: String;
}

% Form XObject
type PDXForm extends PDXObject {
	% value of the Subtype2 key
	property Subtype2: String;
	% link to the PostScript stream (PS key in PDF 1.0)
	link PS: CosStream?;
	% link to the reference XObject (Ref key in the form XObject dictionary)
	link Ref: CosDict?;
	% form content
	link contentStream: PDContentStream;
	% link to the group attributes dictionary
	link Group: PDGroup;
}

% Group attributes dictionary
type PDGroup extends PDObject {
	% group subtype (S key)
	property S: String;
	% link to color space
	link colorSpace: PDColorSpace;
}

% ExtGState dictionary
type PDExtGState extends PDResource {
	% String representation of the TR key ("Identity" or "Custom")
	property TR: String;
	% String representation of the TR2 key ("Identity", "Default" or "Custom")
	property TR2: String;
	% String representation of the SMask key ("None" or "Custom")
	property SMask: String;
	% blend mode
	property BM: String;
	% fill alpha
	property ca: Decimal;
	% stroke alpha
	property CA: Decimal;
	% the rendering intent
	link RI: CosRenderingIntent?;
	% font size
	link fontSize: CosReal?;
}

% Shading resource
type PDShading extends PDResource {
	% shading color space
	link colorSpace: PDColorSpace;
}

% annotation object	
type PDAnnot extends PDObject {
	% annotation subtype
	property Subtype: String;
	% annotation opacity (CA key)
	property CA: Decimal;
	% annotation flags
	property F: Integer;
	% SPACE-separated list of all keys in the annotation's appearance dictionary (AP key)
	property AP: String;
	% the value of the /FT entry (Field type), in case this is the widget annotation representing the form field, or null,  if this entry is not present
	property FT: String;
	% the type of the normal appearance entry (/N key) in the annotation appearance dictionary (/AP key) or null, if the normal appearance is not present
	property N_type: String;
	% normal appearance stream (N key in the appearance dictionary) of the annotation
	link appearance: PDContentStream?;
	% link to the annotation's color
	link C: CosReal*;
	% link to the annotation's interior color
	link IC: CosReal*;
	% link to the action associated with the annotation (A entry)
	link A: PDAction?;
	% link to the additional actions defined for the annotation (AA entry)
	link AA: PDAction*;
}

% Interactive form dictionary
type PDAcroForm extends PDObject {
	% NeedAppearances flag
	property NeedAppearances: Boolean;
	% all interactive form fields in the document
	link formFields: PDFormField*;
}

% Interactive form field
type PDFormField extends PDObject {
	% Field type
	property FT: String;
	% link to the additional actions defined in the interactive form field dictionary (AA entry)
	link AA: PDAction*;	
}
	
% the PDF action object
type PDAction extends PDObject {
	% action subtype
	property S: String;
	% next action (Next entry in the action dictionary)
	link Next: PDAction?;
}

% the Named action object
type PDNamedAction extends PDAction {
	% name of the action
	property N: String;
}

% the GoTo action object
type PDGoToAction extends PDAction {
	% link to the destination to jump to
	link D: CosReal*;
}

% the GoToRemote action object
type PDGoToRemoteAction extends PDGoToAction {

}

% the XMP Metadata stream
type PDMetadata extends PDObject {
	% XMPPackage for PDMetadata in CosDict or XMPMainPackage for PDMetadata in PDDocument
	link XMPPackage: XMPPackage;
	% link to the CosStream contains this metadata
	link stream: CosStream;
	% value of the Filter key in the metadata stream dictionary
	property Filter: String;
}

% the output intent dictionary
type PDOutputIntent extends PDObject {
	% string representation of the indirect link to the ICC output profile
	property destOutputProfileRef: String;
	% destination output profile
	link destProfile: ICCOutputProfile?;
}

% the outline (or bookmark) dictionary
type PDOutline extends PDObject {
	% link to the associated action object (A entry in the outline dictionary)
	link A: PDAction?;
}
