/*
Copyright 2006,2007,2008 Stefano Chizzolini. http://clown.stefanochizzolini.it
Contributors:
* Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it)
This file should be part of the source code distribution of "PDF Clown library"
(the Program): see the accompanying README files for more info.
This Program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later version.
This Program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY, either expressed or implied; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
You should have received a copy of the GNU General Public License along with this
Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
Redistribution and use, with or without modification, are permitted provided that such
redistributions retain the above copyright notice, license and disclaimer, along with
this list of conditions.
*/
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents;
using it.stefanochizzolini.clown.documents.contents.composition;
using it.stefanochizzolini.clown.documents.contents.objects;
using it.stefanochizzolini.clown.files;
using it.stefanochizzolini.clown.objects;
using System;
using System.Drawing;
namespace it.stefanochizzolini.clown.documents.contents.xObjects{
/**
<summary>Form external object [PDF:1.6:4.9].</summary>
*/
public class FormXObject
: XObject,
IContentContext
{
#region dynamic
#region constructors
/**
<summary>Creates a new form within the given document context, using default resources.</summary>
*/
public FormXObject(
Document context
) : this(
context,
null
)
{}
/**
<summary>Creates a new form within the given document context, using custom resources.</summary>
*/
public FormXObject(
Document context,
Resources resources
) : base(context)
{
PdfDictionary header = BaseDataObject.Header;
header[PdfName.Subtype] = PdfName.Form;
header[PdfName.BBox] = new PdfRectangle(0,0,0,0);
// No resources collection?
/* NOTE: Resources collection is mandatory. */
if(resources == null)
{resources = new Resources(context);}
header[PdfName.Resources] = resources.BaseObject;
}
internal FormXObject(
PdfDirectObject baseObject
) : base(baseObject)
{}
#endregion
#region interface
#region public
public override object Clone(
Document context
)
{throw new NotImplementedException();}
public override double[] GetMatrix(
)
{
/*
NOTE: Form-space-to-user-space matrix is identity [1 0 0 1 0 0] by default,
but may be adjusted by setting the Matrix entry in the form dictionary [PDF:1.6:4.9].
*/
PdfArray matrix = (PdfArray)File.Resolve(
BaseDataObject.Header[PdfName.Matrix]
);
if(matrix == null)
{
return new double[]
{
1, // a.
0, // b.
0, // c.
1, // d.
0, // e.
0 // f.
};
}
else
{
return new double[]
{
((IPdfNumber)matrix[0]).RawValue, // a.
((IPdfNumber)matrix[1]).RawValue, // b.
((IPdfNumber)matrix[2]).RawValue, // c.
((IPdfNumber)matrix[3]).RawValue, // d.
((IPdfNumber)matrix[4]).RawValue, // e.
((IPdfNumber)matrix[5]).RawValue // f.
};
}
}
public override Size Size
{
get
{
PdfArray box = (PdfArray)File.Resolve(
BaseDataObject.Header[PdfName.BBox]
);
return new Size(
(int)((IPdfNumber)box[2]).RawValue,
(int)((IPdfNumber)box[3]).RawValue
);
}
set
{
PdfDirectObject box = BaseDataObject.Header[PdfName.BBox];
PdfArray boxObject = (PdfArray)File.Resolve(box);
((IPdfNumber)boxObject[2]).RawValue = value.Width;
((IPdfNumber)boxObject[3]).RawValue = value.Height;
File.Update(box);
}
}
#endregion
#region internal
#region IContentContext
public PdfArray Box
{
get
{
return (PdfArray)File.Resolve(BaseDataObject.Header[PdfName.BBox]); // Required [PDF:1.6:4.9.1].
}
}
public Contents Contents
{
get
{
return new Contents(
BaseObject,
((PdfReference)BaseObject).IndirectObject,
this
);
}
}
/**
<summary>Gets/Sets the resources associated to the form.</summary>
*/
public Resources Resources
{
get
{
return new Resources(
BaseDataObject.Header[PdfName.Resources],
((PdfReference)BaseObject).IndirectObject
);
}
set
{BaseDataObject.Header[PdfName.Resources] = value.BaseObject;}
}
#region IContentEntity
public ContentObject ToInlineObject(
PrimitiveFilter context
)
{throw new NotImplementedException();}
public XObject ToXObject(
Document context
)
{throw new NotImplementedException();}
#endregion
#endregion
#endregion
#endregion
#endregion
}
}
|