1
#region PDFsharp - A .NET library for processing PDF
4
// Klaus Potzesny (mailto:Klaus.Potzesny@pdfsharp.com)
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
8
// http://www.pdfsharp.com
9
// http://sourceforge.net/projects/pdfsharp
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:
18
// The above copyright notice and this permission notice shall be included
19
// in all copies or substantial portions of the Software.
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.
31
using System.Diagnostics;
32
using System.ComponentModel;
33
using PdfSharp.Drawing;
35
namespace PdfSharp.Drawing.BarCodes
38
/// Represents the base class of all bar codes.
40
public abstract class BarCode : CodeBase
43
/// Initializes a new instance of the <see cref="BarCode"/> class.
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)
53
this.direction = direction;
57
/// Creates a bar code from the specified code type.
59
public static BarCode FromType(CodeType type, string text, XSize size, CodeDirection direction)
63
case CodeType.Code2of5Interleaved:
64
return new Code2of5Interleaved(text, size, direction);
66
case CodeType.Code3of9Standard:
67
return new Code3of9Standard(text, size, direction);
70
throw new InvalidEnumArgumentException("type", (int)type, typeof(CodeType));
75
/// Creates a bar code from the specified code type.
77
public static BarCode FromType(CodeType type, string text, XSize size)
79
return FromType(type, text, size, CodeDirection.LeftToRight);
83
/// Creates a bar code from the specified code type.
85
public static BarCode FromType(CodeType type, string text)
87
return FromType(type, text, XSize.Empty, CodeDirection.LeftToRight);
91
/// Creates a bar code from the specified code type.
93
public static BarCode FromType(CodeType type)
95
return FromType(type, String.Empty, XSize.Empty, CodeDirection.LeftToRight);
99
/// When overridden in a derived class gets or sets the wide narrow ratio.
101
public virtual double WideNarrowRatio
108
/// Gets or sets the location of the text next to the bar code.
110
public TextLocation TextLocation
112
get { return this.textLocation; }
113
set { this.textLocation = value; }
115
internal TextLocation textLocation;
118
/// Gets or sets the length of the data that defines the bar code.
120
public int DataLength
122
get { return this.dataLength; }
123
set { this.dataLength = value; }
125
internal int dataLength;
128
/// Gets or sets the optional start chararacter.
130
public char StartChar
132
get { return this.startChar; }
133
set { this.startChar = value; }
135
internal char startChar;
138
/// Gets or sets the optional end chararacter.
142
get { return this.endChar; }
143
set { this.endChar = value; }
145
internal char endChar;
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))
151
public virtual bool TurboBit
153
get { return this.turboBit; }
154
set { this.turboBit = value; }
156
internal bool turboBit = false;
158
internal virtual void InitRendering(BarCodeRenderInfo info)
160
if (this.text == null)
161
throw new InvalidOperationException(BcgSR.BarCodeNotSet);
163
if (this.Size.IsEmpty)
164
throw new InvalidOperationException(BcgSR.EmptyBarCodeSize);
168
/// When defined in a derived class renders the code.
170
protected internal abstract void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position);