Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add barcode rendering #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@
<Compile Include="..\MigraDoc.Rendering\Rendering\Area.cs">
<Link>Rendering\Area.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BarcodeFormatInfo.cs">
<Link>Rendering\BarcodeFormatInfo.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BarcodeRenderer.cs">
<Link>Rendering\BarcodeRenderer.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BarcodeRenderInfo.cs">
<Link>Rendering\BarcodeRenderInfo.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BordersRenderer.cs">
<Link>Rendering\BordersRenderer.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@
<Compile Include="..\MigraDoc.Rendering\Rendering\Area.cs">
<Link>Rendering\Area.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BarcodeFormatInfo.cs">
<Link>Rendering\BarcodeFormatInfo.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BarcodeRenderer.cs">
<Link>Rendering\BarcodeRenderer.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BarcodeRenderInfo.cs">
<Link>Rendering\BarcodeRenderInfo.cs</Link>
</Compile>
<Compile Include="..\MigraDoc.Rendering\Rendering\BordersRenderer.cs">
<Link>Rendering\BordersRenderer.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions MigraDoc/src/MigraDoc.Rendering/MigraDoc.Rendering.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<Compile Include="Rendering.UnitTest\TestTable.cs" />
<Compile Include="Rendering.UnitTest\ValueDumper.cs" />
<Compile Include="Rendering\Area.cs" />
<Compile Include="Rendering\BarcodeFormatInfo.cs" />
<Compile Include="Rendering\BarcodeRenderer.cs" />
<Compile Include="Rendering\BarcodeRenderInfo.cs" />
<Compile Include="Rendering\BordersRenderer.cs" />
<Compile Include="Rendering\ChartFormatInfo.cs" />
<Compile Include="Rendering\ChartRenderer.cs" />
Expand Down
51 changes: 51 additions & 0 deletions MigraDoc/src/MigraDoc.Rendering/Rendering/BarcodeFormatInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#region MigraDoc - Creating Documents on the Fly
//
// Authors:
// Klaus Potzesny (mailto:[email protected])
//
// Contributors:
// Adam Brengesjö (mailto:[email protected])
//
// Copyright (c) 2001-2009 empira Software GmbH, Cologne (Germany)
//
// http://www.pdfsharp.com
// http://www.migradoc.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion

using System;
using PdfSharp.Drawing;

namespace MigraDoc.Rendering
{
/// <summary>
/// Formatting information for an barcode.
/// </summary>
internal class BarcodeFormatInfo : ShapeFormatInfo
{
internal BarcodeFormatInfo()
{
}

internal XUnit Width;
internal XUnit Height;
}
}
54 changes: 54 additions & 0 deletions MigraDoc/src/MigraDoc.Rendering/Rendering/BarcodeRenderInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#region MigraDoc - Creating Documents on the Fly
//
// Authors:
// Klaus Potzesny (mailto:[email protected])
//
// Contributors:
// Adam Brengesjö (mailto:[email protected])
//
// Copyright (c) 2001-2009 empira Software GmbH, Cologne (Germany)
//
// http://www.pdfsharp.com
// http://www.migradoc.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion

using System;

namespace MigraDoc.Rendering
{
/// <summary>
/// Represents rendering information for barcodes.
/// </summary>
internal class BarcodeRenderInfo : ShapeRenderInfo
{
public BarcodeRenderInfo()
{
}

public override FormatInfo FormatInfo
{
get { return _formatInfo ?? (_formatInfo = new BarcodeFormatInfo()); }
internal set { _formatInfo = (BarcodeFormatInfo)value; }
}
BarcodeFormatInfo _formatInfo;
}
}
117 changes: 117 additions & 0 deletions MigraDoc/src/MigraDoc.Rendering/Rendering/BarcodeRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#region MigraDoc - Creating Documents on the Fly
//
// Authors:
// Klaus Potzesny (mailto:[email protected])
// Adam Brengesjö (mailto:[email protected])
//
// Copyright (c) 2001-2009 empira Software GmbH, Cologne (Germany)
//
// http://www.pdfsharp.com
// http://www.migradoc.com
// http://sourceforge.net/projects/pdfsharp
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion

using PdfSharp.Drawing;
using PdfSharp.Drawing.BarCodes;
using MigraDoc.DocumentObjectModel.Shapes;

namespace MigraDoc.Rendering
{
/// <summary>
/// Renders images.
/// </summary>
internal class BarcodeRenderer : ShapeRenderer
{
internal BarcodeRenderer(XGraphics gfx, Barcode barcode, FieldInfos fieldInfos)
: base(gfx, barcode, fieldInfos)
{
_barcode = barcode;
BarcodeRenderInfo renderInfo = new BarcodeRenderInfo();
renderInfo.DocumentObject = _shape;
_renderInfo = renderInfo;
}

internal BarcodeRenderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
: base(gfx, renderInfo, fieldInfos)
{
_barcode = (Barcode)renderInfo.DocumentObject;
}

internal override void Format(Area area, FormatInfo previousFormatInfo)
{
BarcodeFormatInfo formatInfo = (BarcodeFormatInfo)_renderInfo.FormatInfo;

formatInfo.Height = _barcode.Height.Point;
formatInfo.Width = _barcode.Width.Point;

base.Format(area, previousFormatInfo);
}

protected override XUnit ShapeHeight
{
get
{
BarcodeFormatInfo formatInfo = (BarcodeFormatInfo)_renderInfo.FormatInfo;
return formatInfo.Height + _lineFormatRenderer.GetWidth();
}
}

protected override XUnit ShapeWidth
{
get
{
BarcodeFormatInfo formatInfo = (BarcodeFormatInfo)_renderInfo.FormatInfo;
return formatInfo.Width + _lineFormatRenderer.GetWidth();
}
}

internal override void Render()
{
RenderFilling();

BarcodeFormatInfo formatInfo = (BarcodeFormatInfo)_renderInfo.FormatInfo;
Area contentArea = _renderInfo.LayoutInfo.ContentArea;
XRect destRect = new XRect(contentArea.X, contentArea.Y, formatInfo.Width, formatInfo.Height);

BarCode gfxBarcode = null;

if (_barcode.Type == BarcodeType.Barcode39)
gfxBarcode = new Code3of9Standard(_barcode.Code);
else if (_barcode.Type == BarcodeType.Barcode25i)
gfxBarcode = new Code2of5Interleaved();

// if gfxBarcode is null, the barcode type is not supported
if (gfxBarcode != null)
{
if (_barcode.Text)
gfxBarcode.TextLocation = TextLocation.Below;
gfxBarcode.Direction = CodeDirection.LeftToRight;
gfxBarcode.Size = new XSize(ShapeWidth, ShapeHeight);

_gfx.DrawBarCode(gfxBarcode, XBrushes.Black, destRect.Location);
}

RenderLine();
}

Barcode _barcode;
}
}
8 changes: 6 additions & 2 deletions MigraDoc/src/MigraDoc.Rendering/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer
renderer = new ChartRenderer(gfx, (Chart)documentObject, fieldInfos);
else if (documentObject is Image)
renderer = new ImageRenderer(gfx, (Image)documentObject, fieldInfos);
else if (documentObject is Barcode)
renderer = new BarcodeRenderer(gfx, (Barcode)documentObject, fieldInfos);

if (renderer != null)
if (renderer != null)
renderer._documentRenderer = documentRenderer;

return renderer;
Expand Down Expand Up @@ -194,8 +196,10 @@ internal static Renderer Create(XGraphics gfx, DocumentRenderer documentRenderer
// renderer = new ChartRenderer(gfx, renderInfo, fieldInfos);
else if (renderInfo.DocumentObject is Image)
renderer = new ImageRenderer(gfx, renderInfo, fieldInfos);
else if (renderInfo.DocumentObject is Barcode)
renderer = new BarcodeRenderer(gfx, renderInfo, fieldInfos);

if (renderer != null)
if (renderer != null)
renderer._documentRenderer = documentRenderer;

return renderer;
Expand Down
2 changes: 1 addition & 1 deletion PDFsharp