-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- increased reliablitity of the scanner
- Loading branch information
Showing
8 changed files
with
228 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// | ||
// Author: | ||
// Michael Göricke | ||
// | ||
// Copyright (c) 2023 | ||
// | ||
// This file is part of FocalMaster. | ||
// | ||
// The FocalMaster is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 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; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see<http://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
using System.IO; | ||
|
||
namespace FocalCompiler | ||
{ | ||
internal class EmfBarcodeGenerator : BarcodeGenerator | ||
{ | ||
private const float TopBorder = 0; | ||
private const float LeftBorder = 0; | ||
private const float ZeroBarWidth = 2; | ||
private const float OneBarWidth = 2 * ZeroBarWidth; | ||
private const float GapBarWidth = ZeroBarWidth; | ||
private const float BarHeight = 33; | ||
private const double RowsPerPage = 19; | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
private string imageBaseFilename; | ||
private Metafile metafile; | ||
private Graphics graphics; | ||
private int currentPage; | ||
private int currentRowOnPage; | ||
private float currentY; | ||
private float currentX; | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
public bool GenerateEmf(string focal, string outputBaseFilename) | ||
{ | ||
imageBaseFilename = Path.Combine(Path.GetDirectoryName(outputBaseFilename), Path.GetFileNameWithoutExtension(outputBaseFilename)); | ||
currentPage = 1; | ||
|
||
return Generate(focal, false); | ||
} | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
protected override void Save() | ||
{ | ||
if (graphics == null) | ||
{ | ||
return; | ||
} | ||
|
||
graphics.Dispose(); | ||
metafile.Dispose(); | ||
|
||
graphics = null; | ||
metafile = null; | ||
} | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
private void InitImage() | ||
{ | ||
Bitmap bitmap = new Bitmap(16, 16); | ||
Graphics referenceGraphics = Graphics.FromImage(bitmap); | ||
IntPtr referenceHdc = referenceGraphics.GetHdc(); | ||
|
||
metafile = new Metafile(imageBaseFilename + "-" + currentPage.ToString() + ".emf", referenceHdc, EmfType.EmfOnly); | ||
|
||
referenceGraphics.ReleaseHdc(referenceHdc); | ||
referenceGraphics.Dispose(); | ||
bitmap.Dispose(); | ||
|
||
graphics = Graphics.FromImage(metafile); | ||
|
||
currentY = TopBorder; | ||
currentRowOnPage = 0; | ||
} | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
protected override void BeginBarcodeRow(int currentRow, int fromLine, int toLine) | ||
{ | ||
if (graphics == null) | ||
{ | ||
InitImage(); | ||
} | ||
|
||
string s = string.Format("Row {0} ({1} - {2})", currentRow, fromLine, toLine); | ||
|
||
Font drawFont = new Font("Arial", 9); | ||
SolidBrush drawBrush = new SolidBrush(Color.Black); | ||
|
||
graphics.DrawString(s, drawFont, drawBrush, new PointF(LeftBorder, currentY + 3)); | ||
|
||
currentY += drawFont.Height + 2; | ||
currentX = LeftBorder; | ||
} | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
protected override void EndBarcodeRow() | ||
{ | ||
currentY += BarHeight; | ||
currentRowOnPage++; | ||
|
||
if (currentRowOnPage >= RowsPerPage) | ||
{ | ||
Save(); | ||
currentPage++; | ||
} | ||
} | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
protected override void AddZeroBar() | ||
{ | ||
graphics.FillRectangle(Brushes.Black, currentX, currentY, ZeroBarWidth, BarHeight); | ||
|
||
currentX += ZeroBarWidth + GapBarWidth; | ||
} | ||
|
||
///////////////////////////////////////////////////////////// | ||
|
||
protected override void AddOneBar() | ||
{ | ||
graphics.FillRectangle(Brushes.Black, currentX, currentY, OneBarWidth, BarHeight); | ||
|
||
currentX += OneBarWidth + GapBarWidth; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.