pdfColor.cs :  » PDF » SharpPDF » sharpPDF » 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 » SharpPDF 
SharpPDF » sharpPDF » pdfColor.cs
using System;

using sharpPDF.Exceptions;
using sharpPDF.Enumerators;

namespace sharpPDF{
  /// <summary>
  /// A Class that implements a PDF color.
  /// </summary>
  public class pdfColor : ICloneable
  {
    private string _rColor;
    private string _gColor;
    private string _bColor;

    #region Standard_Colors

    /// <summary>
    /// No Color
    /// </summary>
    public readonly static pdfColor NoColor = new pdfColor("","","");
    /// <summary>
    /// Black Color
    /// </summary>
    public readonly static pdfColor Black = new pdfColor("0","0","0");
    /// <summary>
    /// White Color
    /// </summary>
    public readonly static pdfColor White = new pdfColor("1","1","1");
    /// <summary>
    /// Red Color
    /// </summary>
    public readonly static pdfColor Red = new pdfColor("1","0","0");
    /// <summary>
    /// Light Red Color
    /// </summary>
    public readonly static pdfColor LightRed = new pdfColor("1",".75",".75");
    /// <summary>
    /// Dark Red Color
    /// </summary>
    public readonly static pdfColor DarkRed = new pdfColor(".5","0","0");
    /// <summary>
    /// Orange Color
    /// </summary>
    public readonly static pdfColor Orange = new pdfColor("1",".5","0");
    /// <summary>
    /// Light Orange Color
    /// </summary>
    public readonly static pdfColor LightOrange = new pdfColor("1",".75","0");
    /// <summary>
    /// Dark Orange Color
    /// </summary>
    public readonly static pdfColor DarkOrange = new pdfColor("1",".25","0");
    /// <summary>
    /// Yellow Color
    /// </summary>
    public readonly static pdfColor Yellow = new pdfColor("1","1",".25");
    /// <summary>
    /// Light Yellow Color
    /// </summary>
    public readonly static pdfColor LightYellow = new pdfColor("1","1",".75");
    /// <summary>
    /// Dark Yellow Color
    /// </summary>
    public readonly static pdfColor DarkYellow = new pdfColor("1","1","0");
    /// <summary>
    /// Blue Color
    /// </summary>
    public readonly static pdfColor Blue = new pdfColor("0","0","1");
    /// <summary>
    /// Light Blue Color
    /// </summary>
    public readonly static pdfColor LightBlue = new pdfColor(".1",".3",".75");
    /// <summary>
    /// Dark Blue Color
    /// </summary>
    public static pdfColor DarkBlue = new pdfColor("0","0",".5");
    /// <summary>
    /// Green Color
    /// </summary>
    public readonly static pdfColor Green = new pdfColor("0","1","0");
    /// <summary>
    /// Light Green Color
    /// </summary>
    public readonly static pdfColor LightGreen = new pdfColor(".75","1",".75");
    /// <summary>
    /// Dark Green Color
    /// </summary>
    public readonly static pdfColor DarkGreen = new pdfColor("0",".5","0");
    /// <summary>
    /// Cyan Color
    /// </summary>
    public readonly static pdfColor Cyan = new pdfColor("0",".5","1");
    /// <summary>
    /// Light Cyan Color
    /// </summary>
    public readonly static pdfColor LightCyan = new pdfColor(".2",".8","1");
    /// <summary>
    /// Dark Cyan Color
    /// </summary>
    public readonly static pdfColor DarkCyan = new pdfColor("0",".4",".8");
    /// <summary>
    /// Purple Color
    /// </summary>
    public readonly static pdfColor Purple = new pdfColor(".5","0","1");
    /// <summary>
    /// Light Purple Color
    /// </summary>
    public readonly static pdfColor LightPurple = new pdfColor(".75",".45",".95");
    /// <summary>
    /// Dark Purple Color
    /// </summary>
    public readonly static pdfColor DarkPurple = new pdfColor(".4",".1",".5");
    /// <summary>
    /// Gray Color
    /// </summary>
    public readonly static pdfColor Gray = new pdfColor(".5",".5",".5");
    /// <summary>
    /// Light Gray Color
    /// </summary>
    public readonly static pdfColor LightGray = new pdfColor(".75",".75",".75");
    /// <summary>
    /// Dark Gray Color
    /// </summary>
    public readonly static pdfColor DarkGray = new pdfColor(".25",".25",".25");    

    #endregion

    /// <summary>
    /// R property of RGB color
    /// </summary>
    internal string rColor
    {
      get
      {
        return _rColor;
      }
    }

    /// <summary>
    /// G property of RGB color
    /// </summary>
    internal string gColor
    {
      get
      {
        return _gColor;
      }
    }

    /// <summary>
    /// B property of RGB color
    /// </summary>
    internal string bColor
    {
      get
      {
        return _bColor;
      }        
    }

    /// <summary>
    /// Class's constructor
    /// </summary>
    /// <param name="HEXColor">Hex Color</param>
    public pdfColor(string HEXColor) 
    {
      _rColor = formatColorComponent(int.Parse(HEXColor.Substring(0,2), System.Globalization.NumberStyles.HexNumber));
      _gColor = formatColorComponent(int.Parse(HEXColor.Substring(2,2), System.Globalization.NumberStyles.HexNumber));
      _bColor = formatColorComponent(int.Parse(HEXColor.Substring(4,2), System.Globalization.NumberStyles.HexNumber));      
    }

    /// <summary>
    /// Class's constructor
    /// </summary>
    /// <param name="rColor">Red component of the color</param>
    /// <param name="gColor">Green component of the color</param>
    /// <param name="bColor">Blue component of the color</param>
    public pdfColor(int rColor, int gColor, int bColor)
    {
      _rColor = formatColorComponent(rColor);
      _gColor = formatColorComponent(gColor);
      _bColor = formatColorComponent(bColor);
    }

    /// <summary>
    /// Internal constructor for the creation of the standard colors
    /// </summary>
    /// <param name="rColor">Red component of the color</param>
    /// <param name="gColor">Green component of the color</param>
    /// <param name="bColor">Blue component of the color</param>
    internal pdfColor(string rColor, string gColor, string bColor)
    {
      _rColor = rColor;
      _gColor = gColor;
      _bColor = bColor;
    }

    /// <summary>
    /// Method that formats a int color value with the pdf color format
    /// </summary>
    /// <param name="colorValue">Component of the color</param>
    /// <returns>Formatted component of the color</returns>
    private string formatColorComponent(int colorValue)
    {
      int colorComponent;
      colorComponent = Convert.ToInt32(Math.Round(((Convert.ToSingle(colorValue) / 255) * 100)));
      string resultValue;      
      if (colorComponent == 0 || colorComponent < 0)
      {
        resultValue = "0";
      }
      else if (colorComponent < 100) 
      {        
        resultValue = "." + colorComponent.ToString();
        if (resultValue[resultValue.Length - 1] == '0') 
        {
          resultValue = resultValue.Substring(0,resultValue.Length - 1);
        }
      } 
      else 
      {
        resultValue = "1";
      }
      return resultValue;
    }

    /// <summary>
    /// Method that validates the color
    /// </summary>
    /// <returns>Boolean value that represents the validity of the color</returns>
    internal bool isColor()
    {
      return (_rColor != "" && _gColor != "" && _bColor != "");
    }

    #region ICloneable
    
    /// <summary>
    /// Method that clones the pdfColorObject
    /// </summary>
    /// <returns>Cloned Object</returns>
    public object Clone()
    {
      return new pdfColor(this._rColor, this._gColor, this._bColor);
    }

    #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.