DrawCurve.cs :  » PDF » PDF-Clown » it » stefanochizzolini » clown » documents » contents » objects » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » PDF Clown 
PDF Clown » it » stefanochizzolini » clown » documents » contents » objects » DrawCurve.cs
/*
  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
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.