CalloutNote.cs :  » PDF » PDF-Clown » it » stefanochizzolini » clown » documents » interaction » annotations » 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 » interaction » annotations » CalloutNote.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.documents;
using it.stefanochizzolini.clown.objects;

using System;
using System.Collections.Generic;
using System.Drawing;

namespace it.stefanochizzolini.clown.documents.interaction.annotations{
  /**
    <summary>Free text annotation [PDF:1.6:8.4.5].</summary>
    <remarks>It displays text directly on the page. Unlike an ordinary text annotation,
    a free text annotation has no open or closed state;
    instead of being displayed in a pop-up window, the text is always visible.</remarks>
  */
  public class CalloutNote
    : Annotation
  {
    #region types
    /**
      <summary>Callout line [PDF:1.6:8.4.5].</summary>
    */
    public class LineObject
      : PdfObjectWrapper<PdfArray>
    {
      #region dynamic
      #region fields
      private Page page;
      #endregion

      #region constructors
      public LineObject(
        Page page,
        PointF start,
        PointF end
        ) : base(
          page.File,
          new PdfArray()
          )
      {
        this.page = page;

        PdfArray baseDataObject = BaseDataObject;
        double pageHeight = ((IPdfNumber)page.Box[3]).RawValue;
        baseDataObject.Add(new PdfReal(start.X));
        baseDataObject.Add(new PdfReal(pageHeight - start.Y));
        baseDataObject.Add(new PdfReal(end.X));
        baseDataObject.Add(new PdfReal(pageHeight - end.Y));
      }

      public LineObject(
        Page page,
        PointF start,
        PointF knee,
        PointF end
        ) : base(
          page.File,
          new PdfArray()
          )
      {
        this.page = page;

        PdfArray baseDataObject = BaseDataObject;
        double pageHeight = ((IPdfNumber)page.Box[3]).RawValue;
        baseDataObject.Add(new PdfReal(start.X));
        baseDataObject.Add(new PdfReal(pageHeight - start.Y));
        baseDataObject.Add(new PdfReal(knee.X));
        baseDataObject.Add(new PdfReal(pageHeight - knee.Y));
        baseDataObject.Add(new PdfReal(end.X));
        baseDataObject.Add(new PdfReal(pageHeight - end.Y));
      }

      internal LineObject(
        PdfDirectObject baseObject,
        PdfIndirectObject container
        ) : base(baseObject,container)
      {}
      #endregion

      #region interface
      #region public
      public override object Clone(
        Document context
        )
      {throw new NotImplementedException();}

      public PointF End
      {
        get
        {
          PdfArray coordinates = BaseDataObject;
          if(coordinates.Count < 6)
            return new PointF(
              (float)((IPdfNumber)coordinates[2]).RawValue,
              (float)(((IPdfNumber)page.Box[3]).RawValue - ((IPdfNumber)coordinates[3]).RawValue)
              );
          else
            return new PointF(
              (float)((IPdfNumber)coordinates[4]).RawValue,
              (float)(((IPdfNumber)page.Box[3]).RawValue - ((IPdfNumber)coordinates[5]).RawValue)
              );
        }
      }

      public PointF? Knee
      {
        get
        {
          PdfArray coordinates = BaseDataObject;
          if(coordinates.Count < 6)
            return null;

          return new PointF(
            (float)((IPdfNumber)coordinates[2]).RawValue,
            (float)(((IPdfNumber)page.Box[3]).RawValue - ((IPdfNumber)coordinates[3]).RawValue)
            );
        }
      }

      public PointF Start
      {
        get
        {
          PdfArray coordinates = BaseDataObject;

          return new PointF(
            (float)((IPdfNumber)coordinates[0]).RawValue,
            (float)(((IPdfNumber)page.Box[3]).RawValue - ((IPdfNumber)coordinates[1]).RawValue)
            );
        }
      }
      #endregion
      #endregion
      #endregion
    }

    /**
      <summary>Text justification [PDF:1.6:8.4.5].</summary>
    */
    public enum JustificationEnum
    {
      /**
        <summary>Left.</summary>
      */
      Left,
      /**
        <summary>Center.</summary>
      */
      Center,
      /**
        <summary>Right.</summary>
      */
      Right
    };
    #endregion

    #region static
    #region fields
    private static readonly Dictionary<JustificationEnum,PdfInteger> JustificationEnumCodes;
    #endregion

    #region constructors
    static CalloutNote()
    {
      JustificationEnumCodes = new Dictionary<JustificationEnum,PdfInteger>();
      JustificationEnumCodes[JustificationEnum.Left] = new PdfInteger(0);
      JustificationEnumCodes[JustificationEnum.Center] = new PdfInteger(1);
      JustificationEnumCodes[JustificationEnum.Right] = new PdfInteger(2);
    }
    #endregion

    #region interface
    #region private
    /**
      <summary>Gets the code corresponding to the given value.</summary>
    */
    private static PdfInteger ToCode(
      JustificationEnum value
      )
    {return JustificationEnumCodes[value];}

    /**
      <summary>Gets the justification corresponding to the given value.</summary>
    */
    private static JustificationEnum ToJustificationEnum(
      PdfInteger value
      )
    {
      foreach(KeyValuePair<JustificationEnum,PdfInteger> justification in JustificationEnumCodes)
      {
        if(justification.Value.Equals(value))
          return justification.Key;
      }
      return JustificationEnum.Left;
    }
    #endregion
    #endregion
    #endregion

    #region dynamic
    #region constructors
    public CalloutNote(
      Page page,
      RectangleF box,
      string text
      ) : base(
        page.Document,
        PdfName.FreeText,
        box,
        page
        )
    {Text = text;}

    public CalloutNote(
      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 justification to be used in displaying the annotation's text.</summary>
    */
    public JustificationEnum Justification
    {
      get
      {return ToJustificationEnum((PdfInteger)BaseDataObject[PdfName.Q]);}
      set
      {BaseDataObject[PdfName.Q] = ToCode(value);}
    }

    /**
      <summary>Gets/Sets the callout line attached to the free text annotation.</summary>
    */
    public LineObject Line
    {
      get
      {
        /*
          NOTE: 'CL' entry may be undefined.
        */
        PdfArray calloutLineObject = (PdfArray)BaseDataObject[PdfName.CL];
        if(calloutLineObject == null)
          return null;

        return new LineObject(calloutLineObject,Container);
      }
      set
      {BaseDataObject[PdfName.CL] = value.BaseObject;}
    }
    #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.