/*
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.bytes;
using it.stefanochizzolini.clown.objects;
using System;
using System.Collections.Generic;
using System.Text;
namespace it.stefanochizzolini.clown.documents.contents.objects{
/**
<summary>Content stream instruction [PDF:1.6:3.7.1].</summary>
*/
public class Operation
: ContentObject
{
#region static
#region interface
#region public
/**
<summary>Gets a specific operation.</summary>
<param name="operator_">Operator.</param>
<param name="operands">List of operands.</param>
<returns>Operation associated to the operator.</returns>
*/
public static Operation Get(
string operator_,
List<PdfDirectObject> operands
)
{
/*
NOTE: This is a factory method for any operation-derived object.
*/
if(operator_ == null)
return null;
if(operator_.Equals(SaveGraphicsState.OperatorKeyword)) return SaveGraphicsState.Value;
if(operator_.Equals(SetFont.OperatorKeyword)) return new SetFont(operands);
if(operator_.Equals(SetStrokeColor.OperatorKeyword)) return new SetStrokeColor(operands);
if(operator_.Equals(SetStrokeColorSpace.OperatorKeyword)) return new SetStrokeColorSpace(operands);
if(operator_.Equals(SetFillColor.OperatorKeyword)) return new SetFillColor(operands);
if(operator_.Equals(SetFillColorSpace.OperatorKeyword)) return new SetFillColorSpace(operands);
if(operator_.Equals(RestoreGraphicsState.OperatorKeyword)) return RestoreGraphicsState.Value;
if(operator_.Equals(BeginSubpath.OperatorKeyword)) return new BeginSubpath(operands);
if(operator_.Equals(CloseSubpath.OperatorKeyword)) return CloseSubpath.Value;
if(operator_.Equals(CloseStroke.OperatorKeyword)) return CloseStroke.Value;
if(operator_.Equals(Fill.OperatorKeyword)
|| operator_.Equals(Fill.ObsoleteOperatorKeyword)) return Fill.Value;
if(operator_.Equals(FillEvenOdd.OperatorKeyword)) return FillEvenOdd.Value;
if(operator_.Equals(Stroke.OperatorKeyword)) return Stroke.Value;
if(operator_.Equals(FillStroke.OperatorKeyword)) return FillStroke.Value;
if(operator_.Equals(FillStrokeEvenOdd.OperatorKeyword)) return FillStrokeEvenOdd.Value;
if(operator_.Equals(CloseFillStroke.OperatorKeyword)) return CloseFillStroke.Value;
if(operator_.Equals(CloseFillStrokeEvenOdd.OperatorKeyword)) return CloseFillStrokeEvenOdd.Value;
if(operator_.Equals(EndPathNoOp.OperatorKeyword)) return EndPathNoOp.Value;
if(operator_.Equals(ModifyClipPath.OperatorKeyword)) return ModifyClipPath.Value;
if(operator_.Equals(ModifyClipPathEvenOdd.OperatorKeyword)) return ModifyClipPathEvenOdd.Value;
if(operator_.Equals(TranslateTextToNextLine.OperatorKeyword)) return TranslateTextToNextLine.Value;
if(operator_.Equals(ShowText.OperatorKeyword)) return new ShowText(operands);
if(operator_.Equals(TranslateTextRelative.OperatorKeyword)) return new TranslateTextRelative(operands);
if(operator_.Equals(SetTextMatrix.OperatorKeyword)) return new SetTextMatrix(operands);
if(operator_.Equals(ModifyCTM.OperatorKeyword)) return new ModifyCTM(operands);
if(operator_.Equals(PaintXObject.OperatorKeyword)) return new PaintXObject(operands);
if(operator_.Equals(PaintShadingObject.OperatorKeyword)) return new PaintShadingObject(operands);
if(operator_.Equals(SetCharSpace.OperatorKeyword)) return new SetCharSpace(operands);
if(operator_.Equals(SetLineCap.OperatorKeyword)) return new SetLineCap(operands);
if(operator_.Equals(SetLineDash.OperatorKeyword)) return new SetLineDash(operands);
if(operator_.Equals(SetLineJoin.OperatorKeyword)) return new SetLineJoin(operands);
if(operator_.Equals(SetLineWidth.OperatorKeyword)) return new SetLineWidth(operands);
if(operator_.Equals(SetMiterLimit.OperatorKeyword)) return new SetMiterLimit(operands);
if(operator_.Equals(SetTextLead.OperatorKeyword)) return new SetTextLead(operands);
if(operator_.Equals(SetTextRise.OperatorKeyword)) return new SetTextRise(operands);
if(operator_.Equals(SetTextScale.OperatorKeyword)) return new SetTextScale(operands);
if(operator_.Equals(SetTextRenderMode.OperatorKeyword)) return new SetTextRenderMode(operands);
if(operator_.Equals(SetWordSpace.OperatorKeyword)) return new SetWordSpace(operands);
if(operator_.Equals(DrawLine.OperatorKeyword)) return new DrawLine(operands);
if(operator_.Equals(DrawRectangle.OperatorKeyword)) return new DrawRectangle(operands);
if(operator_.Equals(DrawCurve.FinalOperator)
|| operator_.Equals(DrawCurve.FullOperator)
|| operator_.Equals(DrawCurve.InitialOperator)) return new DrawCurve(operator_,operands);
if(operator_.Equals(EndInlineImage.OperatorKeyword)) return EndInlineImage.Value;
if(operator_.Equals(BeginText.OperatorKeyword)) return BeginText.Value;
if(operator_.Equals(EndText.OperatorKeyword)) return EndText.Value;
if(operator_.Equals(BeginMarkedContent.SimpleOperatorKeyword)) return new BeginMarkedContent((PdfName)operands[0]);
if(operator_.Equals(BeginMarkedContent.PropertyListOperatorKeyword)) return new BeginMarkedContent((PdfName)operands[0],operands[1]);
if(operator_.Equals(EndMarkedContent.OperatorKeyword)) return EndMarkedContent.Value;
if(operator_.Equals(BeginInlineImage.OperatorKeyword)) return BeginInlineImage.Value;
if(operator_.Equals(EndInlineImage.OperatorKeyword)) return EndInlineImage.Value;
// No explicit operation implementation available.
return new Operation(operator_,operands);
}
#endregion
#endregion
#endregion
#region dynamic
#region fields
protected string operator_;
protected List<PdfDirectObject> operands;
#endregion
#region constructors
public Operation(
string operator_
)
{this.operator_ = operator_;}
public Operation(
String operator_,
PdfDirectObject operand
)
{
this.operator_ = operator_;
this.operands = new List<PdfDirectObject>();
this.operands.Add(operand);
}
public Operation(
string operator_,
List<PdfDirectObject> operands
)
{
this.operator_ = operator_;
this.operands = operands;
}
#endregion
#region interface
#region public
public string Operator
{get{return operator_;}}
public List<PdfDirectObject> Operands
{get{return operands;}}
public override string ToString(
)
{
StringBuilder buffer = new StringBuilder();
// Begin.
buffer.Append("{");
// Operator.
buffer.Append(operator_);
// Operands.
if(operands != null)
{
buffer.Append(" [");
for(
int i = 0, count = operands.Count;
i < count;
i++
)
{
if(i > 0)
{buffer.Append(", ");}
buffer.Append(operands[i].ToString());
}
buffer.Append("]");
}
// End.
buffer.Append("}");
return buffer.ToString();
}
public override void WriteTo(
IOutputStream stream
)
{
if(operands != null)
{
foreach(PdfDirectObject operand in operands)
{operand.WriteTo(stream); stream.Write(" ");}
}
stream.Write(operator_); stream.Write("\n");
}
#endregion
#endregion
#endregion
}
}
|