/*
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.objects;
using System.Collections.Generic;
using System.Drawing;
namespace it.stefanochizzolini.clown.documents.contents.objects{
/**
<summary>'Append a cubic Bezier curve to the current path' operation
[PDF:1.6:4.4.1].</summary>
<remarks>Such curves are defined by four points:
the two endpoints (the current point and the final point)
and two control points (the first control point, associated to the current point,
and the second control point, associated to the final point).</remarks>
*/
public sealed class DrawCurve
: Operation
{
#region static
#region fields
/**
<summary>Specifies only the second control point
(the first control point coincides with initial point of the curve).</summary>
*/
public static readonly string FinalOperator = "v";
/**
<summary>Specifies both control points explicitly.</summary>
*/
public static readonly string FullOperator = "c";
/**
<summary>Specifies only the first control point
(the second control point coincides with final point of the curve).</summary>
*/
public static readonly string InitialOperator = "y";
#endregion
#endregion
#region dynamic
#region constructors
/**
<summary>Creates a fully-explicit curve.</summary>
<param name="point">Final endpoint.</param>
<param name="control1">First control point.</param>
<param name="control2">Second control point.</param>
*/
public DrawCurve(
PointF point,
PointF control1,
PointF control2
) : this(
point.X,
point.Y,
control1.X,
control1.Y,
control2.X,
control2.Y
)
{}
/**
<summary>Creates a fully-explicit curve.</summary>
*/
public DrawCurve(
double pointX,
double pointY,
double control1X,
double control1Y,
double control2X,
double control2Y
) : base(
FullOperator,
new List<PdfDirectObject>(
new PdfDirectObject[]
{
new PdfReal(control1X),
new PdfReal(control1Y),
new PdfReal(control2X),
new PdfReal(control2Y),
new PdfReal(pointX),
new PdfReal(pointY)
}
)
)
{}
/**
<summary>Creates a partially-explicit curve.</summary>
<param name="point">Final endpoint.</param>
<param name="control">Explicit control point.</param>
<param name="operator">Operator (either <code>InitialOperator</code> or <code>FinalOperator</code>).
It defines how to interpret the <code>control</code> parameter.</param>
*/
public DrawCurve(
PointF point,
PointF control,
string operator_
) : base(
operator_.Equals(InitialOperator) ? InitialOperator : FinalOperator,
new List<PdfDirectObject>(
new PdfDirectObject[]
{
new PdfReal(control.X),
new PdfReal(control.Y),
new PdfReal(point.X),
new PdfReal(point.Y)
}
)
)
{}
public DrawCurve(
string operator_,
List<PdfDirectObject> operands
) : base(operator_,operands)
{}
#endregion
#region interface
#region public
/**
<summary>Gets/Sets the first control point.</summary>
*/
public PointF? Control1
{
get
{
if(operator_.Equals(FinalOperator))
return null;
return new PointF(
(float)((IPdfNumber)operands[0]).RawValue,
(float)((IPdfNumber)operands[1]).RawValue
);
}
set
{
if(operator_.Equals(FinalOperator))
{operator_ = FullOperator;}
((IPdfNumber)operands[0]).RawValue = value.Value.X;
((IPdfNumber)operands[1]).RawValue = value.Value.Y;
}
}
/**
<summary>Gets/Sets the second control point.</summary>
*/
public PointF? Control2
{
get
{
if(operator_.Equals(InitialOperator))
return null;
if(operator_.Equals(FinalOperator))
return new PointF(
(float)((IPdfNumber)operands[0]).RawValue,
(float)((IPdfNumber)operands[1]).RawValue
);
// Full operator.
return new PointF(
(float)((IPdfNumber)operands[2]).RawValue,
(float)((IPdfNumber)operands[3]).RawValue
);
}
set
{
if(operator_.Equals(InitialOperator))
{operator_ = FullOperator;}
if(operator_.Equals(FinalOperator))
{
((IPdfNumber)operands[0]).Value = value.Value.X;
((IPdfNumber)operands[1]).Value = value.Value.Y;
}
else // Full operator.
{
((IPdfNumber)operands[2]).Value = value.Value.X;
((IPdfNumber)operands[3]).Value = value.Value.Y;
}
}
}
/**
<summary>Gets/Sets the final endpoint.</summary>
*/
public PointF Point
{
get
{
return new PointF(
(float)((IPdfNumber)operands[0]).RawValue,
(float)((IPdfNumber)operands[1]).RawValue
);
}
set
{
((IPdfNumber)operands[0]).Value = value.X;
((IPdfNumber)operands[1]).Value = value.Y;
}
}
#endregion
#endregion
#endregion
}
}
|