/*
Copyright 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.bytes;
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.objects;
using System;
using System.IO;
namespace it.stefanochizzolini.clown.documents.fileSpecs{
/**
<summary>Reference to the contents of another file (file specification) [PDF:1.6:3.10.2].</summary>
*/
public class FileSpec
: PdfObjectWrapper<PdfDictionary>
{
#region dynamic
#region constructors
public FileSpec(
Document context
) : base(
context.File,
new PdfDictionary(
new PdfName[]
{PdfName.Type},
new PdfDirectObject[]
{PdfName.Filespec}
)
)
{}
public FileSpec(
EmbeddedFile embeddedFile,
string name
) : this(embeddedFile.Document)
{
Name = name;
EmbeddedFile = embeddedFile;
}
internal FileSpec(
PdfDirectObject baseObject,
PdfIndirectObject container
) : base(baseObject,container)
{}
#endregion
#region interface
#region public
public override object Clone(
Document context
)
{throw new NotImplementedException();}
/**
<summary>Gets/Sets the related files.</summary>
*/
public RelatedFiles Dependencies
{
get
{return GetDependencies(PdfName.F);}
set
{SetDependencies(PdfName.F,value);}
}
/**
<summary>Gets/Sets the description of the file.</summary>
*/
public string Description
{
get
{
/*
NOTE: 'Desc' entry may be undefined.
*/
PdfTextString descriptionObject = (PdfTextString)BaseDataObject[PdfName.Desc];
if(descriptionObject == null)
return null;
return (string)descriptionObject.Value;
}
set
{BaseDataObject[PdfName.Desc] = new PdfTextString(value);}
}
/**
<summary>Gets/Sets the embedded file.</summary>
*/
public EmbeddedFile EmbeddedFile
{
get
{return GetEmbeddedFile(PdfName.F);}
set
{SetEmbeddedFile(PdfName.F,value);}
}
/**
<summary>Gets/Sets the Mac OS-specific related files.</summary>
*/
public RelatedFiles MacDependencies
{
get
{return GetDependencies(PdfName.Mac);}
set
{SetDependencies(PdfName.Mac,value);}
}
/**
<summary>Gets/Sets the Mac OS-specific embedded file.</summary>
*/
public EmbeddedFile MacEmbeddedFile
{
get
{return GetEmbeddedFile(PdfName.Mac);}
set
{SetEmbeddedFile(PdfName.Mac,value);}
}
/**
<summary>Gets/Sets the Mac OS-specific file name.</summary>
*/
public string MacName
{
get
{return GetName(PdfName.Mac);}
set
{SetName(PdfName.Mac,value);}
}
/**
<summary>Gets/Sets the file name.</summary>
*/
public string Name
{
get
{return GetName(PdfName.F);}
set
{SetName(PdfName.F,value);}
}
/**
<summary>Gets/Sets the Unix-specific related files.</summary>
*/
public RelatedFiles UnixDependencies
{
get
{return GetDependencies(PdfName.Unix);}
set
{SetDependencies(PdfName.Unix,value);}
}
/**
<summary>Gets/Sets the Unix-specific embedded file.</summary>
*/
public EmbeddedFile UnixEmbeddedFile
{
get
{return GetEmbeddedFile(PdfName.Unix);}
set
{SetEmbeddedFile(PdfName.Unix,value);}
}
/**
<summary>Gets/Sets the Unix-specific file name.</summary>
*/
public string UnixName
{
get
{return GetName(PdfName.Unix);}
set
{SetName(PdfName.Unix,value);}
}
/**
<summary>Gets/Sets the Windows-specific related files.</summary>
*/
public RelatedFiles WinDependencies
{
get
{return GetDependencies(PdfName.DOS);}
set
{SetDependencies(PdfName.DOS,value);}
}
/**
<summary>Gets/Sets the Windows-specific embedded file.</summary>
*/
public EmbeddedFile WinEmbeddedFile
{
get
{return GetEmbeddedFile(PdfName.DOS);}
set
{SetEmbeddedFile(PdfName.DOS,value);}
}
/**
<summary>Gets/Sets the Windows-specific file name.</summary>
*/
public string WinName
{
get
{return GetName(PdfName.DOS);}
set
{SetName(PdfName.DOS,value);}
}
#endregion
#region private
/**
<summary>Gets the related files associated to the given key.</summary>
*/
private RelatedFiles GetDependencies(
PdfName key
)
{
/*
NOTE: 'RF' entry may be undefined.
*/
PdfDictionary dependenciesObject = (PdfDictionary)BaseDataObject[PdfName.RF];
if(dependenciesObject == null)
return null;
/*
NOTE: key entry may be undefined.
*/
PdfReference dependencyFilesObject = (PdfReference)dependenciesObject[key];
if(dependencyFilesObject == null)
return null;
return new RelatedFiles(dependencyFilesObject,Container);
}
/**
<summary>Gets the embedded file associated to the given key.</summary>
*/
private EmbeddedFile GetEmbeddedFile(
PdfName key
)
{
/*
NOTE: 'EF' entry may be undefined.
*/
PdfDictionary embeddedFilesObject = (PdfDictionary)BaseDataObject[PdfName.EF];
if(embeddedFilesObject == null)
return null;
/*
NOTE: key entry may be undefined.
*/
PdfReference embeddedFileObject = (PdfReference)embeddedFilesObject[key];
if(embeddedFileObject == null)
return null;
return new EmbeddedFile(embeddedFileObject);
}
/**
<summary>Gets the file name associated to the given key.</summary>
*/
private string GetName(
PdfName key
)
{
/*
NOTE: key entry may be undefined.
*/
PdfString nameObject = (PdfString)BaseDataObject[key];
if(nameObject == null)
return null;
return (string)nameObject.Value;
}
private void SetDependencies(
PdfName key,
RelatedFiles value
)
{
/*
NOTE: 'RF' entry may be undefined.
*/
PdfDictionary dependenciesObject = (PdfDictionary)BaseDataObject[PdfName.RF];
if(dependenciesObject == null)
{
dependenciesObject = new PdfDictionary();
BaseDataObject[PdfName.RF] = dependenciesObject;
}
dependenciesObject[key] = value.BaseObject;
}
private void SetEmbeddedFile(
PdfName key,
EmbeddedFile value
)
{
/*
NOTE: 'EF' entry may be undefined.
*/
PdfDictionary embeddedFilesObject = (PdfDictionary)BaseDataObject[PdfName.EF];
if(embeddedFilesObject == null)
{
embeddedFilesObject = new PdfDictionary();
BaseDataObject[PdfName.EF] = embeddedFilesObject;
}
embeddedFilesObject[key] = value.BaseObject;
}
private void SetName(
PdfName key,
string value
)
{BaseDataObject[key] = new PdfString(value);}
#endregion
#endregion
#endregion
}
}
|