~ubuntu-branches/ubuntu/trusty/pdfmod/trusty

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Drawing.BarCodes/BarCode.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-06-18 03:44:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100618034446-bogifrsscpayp361
Tags: upstream-0.8.3
ImportĀ upstreamĀ versionĀ 0.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region PDFsharp - A .NET library for processing PDF
 
2
//
 
3
// Authors:
 
4
//   Klaus Potzesny (mailto:Klaus.Potzesny@pdfsharp.com)
 
5
//
 
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
 
7
//
 
8
// http://www.pdfsharp.com
 
9
// http://sourceforge.net/projects/pdfsharp
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a
 
12
// copy of this software and associated documentation files (the "Software"),
 
13
// to deal in the Software without restriction, including without limitation
 
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
// and/or sell copies of the Software, and to permit persons to whom the
 
16
// Software is furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included
 
19
// in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 
27
// DEALINGS IN THE SOFTWARE.
 
28
#endregion
 
29
 
 
30
using System;
 
31
using System.Diagnostics;
 
32
using System.ComponentModel;
 
33
using PdfSharp.Drawing;
 
34
 
 
35
namespace PdfSharp.Drawing.BarCodes
 
36
{
 
37
  /// <summary>
 
38
  /// Represents the base class of all bar codes.
 
39
  /// </summary>
 
40
  public abstract class BarCode : CodeBase
 
41
  {
 
42
    /// <summary>
 
43
    /// Initializes a new instance of the <see cref="BarCode"/> class.
 
44
    /// </summary>
 
45
    /// <param name="text"></param>
 
46
    /// <param name="size"></param>
 
47
    /// <param name="direction"></param>
 
48
    public BarCode(string text, XSize size, CodeDirection direction)
 
49
      : base(text, size, direction)
 
50
    {
 
51
      this.text = text;
 
52
      this.size = size;
 
53
      this.direction = direction;
 
54
    }
 
55
 
 
56
    /// <summary>
 
57
    /// Creates a bar code from the specified code type.
 
58
    /// </summary>
 
59
    public static BarCode FromType(CodeType type, string text, XSize size, CodeDirection direction)
 
60
    {
 
61
      switch (type)
 
62
      {
 
63
        case CodeType.Code2of5Interleaved:
 
64
          return new Code2of5Interleaved(text, size, direction);
 
65
 
 
66
        case CodeType.Code3of9Standard:
 
67
          return new Code3of9Standard(text, size, direction);
 
68
 
 
69
        default:
 
70
          throw new InvalidEnumArgumentException("type", (int)type, typeof(CodeType));
 
71
      }
 
72
    }
 
73
 
 
74
    /// <summary>
 
75
    /// Creates a bar code from the specified code type.
 
76
    /// </summary>
 
77
    public static BarCode FromType(CodeType type, string text, XSize size)
 
78
    {
 
79
      return FromType(type, text, size, CodeDirection.LeftToRight);
 
80
    }
 
81
 
 
82
    /// <summary>
 
83
    /// Creates a bar code from the specified code type.
 
84
    /// </summary>
 
85
    public static BarCode FromType(CodeType type, string text)
 
86
    {
 
87
      return FromType(type, text, XSize.Empty, CodeDirection.LeftToRight);
 
88
    }
 
89
 
 
90
    /// <summary>
 
91
    /// Creates a bar code from the specified code type.
 
92
    /// </summary>
 
93
    public static BarCode FromType(CodeType type)
 
94
    {
 
95
      return FromType(type, String.Empty, XSize.Empty, CodeDirection.LeftToRight);
 
96
    }
 
97
 
 
98
    /// <summary>
 
99
    /// When overridden in a derived class gets or sets the wide narrow ratio.
 
100
    /// </summary>
 
101
    public virtual double WideNarrowRatio 
 
102
    {
 
103
      get { return 0; }
 
104
      set { }
 
105
    }
 
106
 
 
107
    /// <summary>
 
108
    /// Gets or sets the location of the text next to the bar code.
 
109
    /// </summary>
 
110
    public TextLocation TextLocation
 
111
    {
 
112
      get { return this.textLocation; }
 
113
      set { this.textLocation = value; }
 
114
    }
 
115
    internal TextLocation textLocation;
 
116
 
 
117
    /// <summary>
 
118
    /// Gets or sets the length of the data that defines the bar code.
 
119
    /// </summary>
 
120
    public int DataLength
 
121
    {
 
122
      get { return this.dataLength; }
 
123
      set { this.dataLength = value; }
 
124
    }
 
125
    internal int dataLength;
 
126
 
 
127
    /// <summary>
 
128
    /// Gets or sets the optional start chararacter.
 
129
    /// </summary>
 
130
    public char StartChar
 
131
    {
 
132
      get { return this.startChar; }
 
133
      set { this.startChar = value; }
 
134
    }
 
135
    internal char startChar;
 
136
 
 
137
    /// <summary>
 
138
    /// Gets or sets the optional end chararacter.
 
139
    /// </summary>
 
140
    public char EndChar
 
141
    {
 
142
      get { return this.endChar; }
 
143
      set { this.endChar = value; }
 
144
    }
 
145
    internal char endChar;
 
146
 
 
147
    /// <summary>
 
148
    /// Gets or sets a value indicating whether the turbo bit is to be drawn.
 
149
    /// (A turbo bit is something special to Kern (computer output processing) company (as far as I know))
 
150
    /// </summary>
 
151
    public virtual bool TurboBit
 
152
    {
 
153
      get { return this.turboBit; }
 
154
      set { this.turboBit = value; }
 
155
    }
 
156
    internal bool turboBit = false;
 
157
 
 
158
    internal virtual void InitRendering(BarCodeRenderInfo info)
 
159
    {
 
160
      if (this.text == null)
 
161
        throw new InvalidOperationException(BcgSR.BarCodeNotSet);
 
162
 
 
163
      if (this.Size.IsEmpty)
 
164
        throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
 
165
    }
 
166
 
 
167
    /// <summary>
 
168
    /// When defined in a derived class renders the code.
 
169
    /// </summary>
 
170
    protected internal abstract void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position);
 
171
  }
 
172
}