You've already forked lazarus-ccr
LazBarCodes: Improved compatibility with previous version 1.0.4
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8694 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Description Value="Provides barcode 1D and 2D generation based in the 'C' zint library."/>
|
<Description Value="Provides barcode 1D and 2D generation based in the 'C' zint library."/>
|
||||||
<Version Major="2"/>
|
<Version Major="2" Release="1"/>
|
||||||
<Files Count="2">
|
<Files Count="2">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="..\src\ubarcodes.pas"/>
|
<Filename Value="..\src\ubarcodes.pas"/>
|
||||||
|
@ -28,7 +28,7 @@ Change to BSD-license is done for backend and therefore for ZINT shared library
|
|||||||
the frontends and Qt4-backend the GPL is still valid. Since BSD-license is GPL-compatible
|
the frontends and Qt4-backend the GPL is still valid. Since BSD-license is GPL-compatible
|
||||||
this gives the possibility to include ZINT library in own products or link against it from
|
this gives the possibility to include ZINT library in own products or link against it from
|
||||||
own software."/>
|
own software."/>
|
||||||
<Version Major="2"/>
|
<Version Major="2" Release="1"/>
|
||||||
<Files Count="23">
|
<Files Count="23">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="..\src\zint\zint.pp"/>
|
<Filename Value="..\src\zint\zint.pp"/>
|
||||||
|
@ -673,7 +673,8 @@ begin
|
|||||||
TBarcodeMaxicode
|
TBarcodeMaxicode
|
||||||
]);
|
]);
|
||||||
|
|
||||||
RegisterPropertyEditor(TypeInfo(TCaption), TLazBarcodeCustomText, 'Text', TCaptionPropertyEditor);
|
RegisterPropertyEditor(TypeInfo(TCaption), TLazBarcodeCustomText, 'Text', TCaptionPropertyEditor);
|
||||||
|
RegisterPropertyToSkip(TLazBarcodeCustomBase, 'StrictSize', 'Deprecated', '');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ColorToChars(AColor: TColor): TColorChars;
|
function ColorToChars(AColor: TColor): TColorChars;
|
||||||
@ -1437,7 +1438,7 @@ begin
|
|||||||
|
|
||||||
// Start drawing, clear background
|
// Start drawing, clear background
|
||||||
ADrawer.BeginDrawing;
|
ADrawer.BeginDrawing;
|
||||||
|
|
||||||
// Draw the lines (bars, bearing bars, box)
|
// Draw the lines (bars, bearing bars, box)
|
||||||
line := FSymbol^.Rendered^.lines;
|
line := FSymbol^.Rendered^.lines;
|
||||||
while Assigned(line) do begin
|
while Assigned(line) do begin
|
||||||
@ -1449,7 +1450,7 @@ begin
|
|||||||
);
|
);
|
||||||
line := line^.next;
|
line := line^.next;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Draw the text
|
// Draw the text
|
||||||
if FShowHumanReadableText then begin
|
if FShowHumanReadableText then begin
|
||||||
str := FSymbol^.Rendered^.strings;
|
str := FSymbol^.Rendered^.strings;
|
||||||
@ -1458,7 +1459,7 @@ begin
|
|||||||
str := str^.next;
|
str := str^.next;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Finish drawing
|
// Finish drawing
|
||||||
ADrawer.EndDrawing;
|
ADrawer.EndDrawing;
|
||||||
end;
|
end;
|
||||||
@ -1525,9 +1526,10 @@ var
|
|||||||
drawer: TCanvasBarcodeDrawer;
|
drawer: TCanvasBarcodeDrawer;
|
||||||
begin
|
begin
|
||||||
if FSymbol^.Rendered = nil then
|
if FSymbol^.Rendered = nil then
|
||||||
raise Exception.Create('Bar code must have been rendered before drawing.');
|
Render(ARect.Width, ARect.Height);
|
||||||
|
// raise Exception.Create('Bar code must have been rendered before drawing.');
|
||||||
|
|
||||||
drawer := TCanvasBarcodeDrawer.Create(ATargetCanvas, ARect.Width, ARect.Height);
|
drawer := TCanvasBarcodeDrawer.Create(ATargetCanvas, ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
|
||||||
try
|
try
|
||||||
DrawBarcode(drawer, 1.0);
|
DrawBarcode(drawer, 1.0);
|
||||||
finally
|
finally
|
||||||
@ -3020,6 +3022,11 @@ begin
|
|||||||
FShowHumanReadableText := false;
|
FShowHumanReadableText := false;
|
||||||
FSymbolHeight := 0;
|
FSymbolHeight := 0;
|
||||||
FWhiteSpaceWidth := 0;
|
FWhiteSpaceWidth := 0;
|
||||||
|
if (Width = 0) or (Height = 0) then
|
||||||
|
begin
|
||||||
|
Width := 88;
|
||||||
|
Height := 88;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Calculates the pixel multiplication factor to fill the entire control as much
|
{ Calculates the pixel multiplication factor to fill the entire control as much
|
||||||
@ -3027,7 +3034,7 @@ end;
|
|||||||
pixels}
|
pixels}
|
||||||
function TBarcodeSquare.CalcFactor(AWidth, AHeight: Integer): Integer;
|
function TBarcodeSquare.CalcFactor(AWidth, AHeight: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
if FSymbol^.Width = 0 then
|
if (FSymbol = nil) or (FSymbol^.Width = 0) then
|
||||||
Result := 1
|
Result := 1
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -3045,6 +3052,9 @@ procedure TBarcodeSquare.CalcSize(AFactor: Integer; out ATotalWidth, ATotalHeigh
|
|||||||
ASymbolWidth, ASymbolHeight, ATextWidth, ATextHeight,
|
ASymbolWidth, ASymbolHeight, ATextWidth, ATextHeight,
|
||||||
ABorderWidth, AWhitespaceWidth: Integer);
|
ABorderWidth, AWhitespaceWidth: Integer);
|
||||||
begin
|
begin
|
||||||
|
if FSymbol = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
ABorderWidth := FMargin;
|
ABorderWidth := FMargin;
|
||||||
AWhiteSpaceWidth := 0;
|
AWhiteSpaceWidth := 0;
|
||||||
|
|
||||||
@ -3072,13 +3082,22 @@ var
|
|||||||
factor: Integer;
|
factor: Integer;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
if FScale = 0 then
|
if FSymbol = nil then
|
||||||
factor := CalcFactor(ClientWidth, ClientHeight)
|
with GetControlClassDefaultSize do
|
||||||
|
begin
|
||||||
|
PreferredWidth := CX;
|
||||||
|
PreferredHeight := CY;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
factor := FScale;
|
begin
|
||||||
CalcSize(factor, wtot, htot, wsym, hsym, wtxt, htxt, wb, wws);
|
if FScale = 0 then
|
||||||
PreferredWidth := wtot;
|
factor := CalcFactor(ClientWidth, ClientHeight)
|
||||||
PreferredHeight := htot;
|
else
|
||||||
|
factor := FScale;
|
||||||
|
CalcSize(factor, wtot, htot, wsym, hsym, wtxt, htxt, wb, wws);
|
||||||
|
PreferredWidth := wtot;
|
||||||
|
PreferredHeight := htot;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TBarcodeSquare.GetControlClassDefaultSize: TSize;
|
class function TBarcodeSquare.GetControlClassDefaultSize: TSize;
|
||||||
|
@ -21,8 +21,11 @@ type
|
|||||||
FFontStyle: TFontStyles;
|
FFontStyle: TFontStyles;
|
||||||
FWidth: Double;
|
FWidth: Double;
|
||||||
FHeight: Double;
|
FHeight: Double;
|
||||||
|
FLeft: Double;
|
||||||
|
FTop: Double;
|
||||||
public
|
public
|
||||||
constructor Create(AWidth, AHeight: Double);
|
constructor Create(AWidth, AHeight: Double);
|
||||||
|
constructor Create(ALeft, ATop, ARight, ABottom: Double);
|
||||||
procedure BeginDrawing; virtual; abstract;
|
procedure BeginDrawing; virtual; abstract;
|
||||||
procedure EndDrawing; virtual; abstract;
|
procedure EndDrawing; virtual; abstract;
|
||||||
procedure DrawBar(x1, y1, x2, y2: Double); virtual; abstract;
|
procedure DrawBar(x1, y1, x2, y2: Double); virtual; abstract;
|
||||||
@ -49,6 +52,7 @@ type
|
|||||||
property Canvas: TCanvas read FCanvas;
|
property Canvas: TCanvas read FCanvas;
|
||||||
public
|
public
|
||||||
constructor Create(ACanvas: TCanvas; AWidth, AHeight: Double);
|
constructor Create(ACanvas: TCanvas; AWidth, AHeight: Double);
|
||||||
|
constructor Create(ACanvas: TCanvas; ALeft, ATop, ARight, ABottom: Double);
|
||||||
procedure BeginDrawing; override;
|
procedure BeginDrawing; override;
|
||||||
procedure EndDrawing; override;
|
procedure EndDrawing; override;
|
||||||
procedure DrawBar(x1, y1, x2, y2: double); override;
|
procedure DrawBar(x1, y1, x2, y2: double); override;
|
||||||
@ -67,6 +71,7 @@ type
|
|||||||
FFormatSettings: TFormatSettings;
|
FFormatSettings: TFormatSettings;
|
||||||
public
|
public
|
||||||
constructor Create(AWidth, AHeight: Double; const ATitle: String);
|
constructor Create(AWidth, AHeight: Double; const ATitle: String);
|
||||||
|
constructor Create(ALeft, ATop, ARight, ABottom: Double; const ATitle: String);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure SaveToFile(const AFileName: String);
|
procedure SaveToFile(const AFileName: String);
|
||||||
procedure SaveToStream(const AStream: TStream);
|
procedure SaveToStream(const AStream: TStream);
|
||||||
@ -116,7 +121,7 @@ const
|
|||||||
HEXAGON: array[0..5] of TDblPoint = ( // 0
|
HEXAGON: array[0..5] of TDblPoint = ( // 0
|
||||||
(X: 0.0; Y: HH), // / \
|
(X: 0.0; Y: HH), // / \
|
||||||
(X:-1.0; Y: H), // 1 5
|
(X:-1.0; Y: H), // 1 5
|
||||||
(X:-1.0; Y:-H), // | |
|
(X:-1.0; Y:-H), // | |
|
||||||
(X: 0.0; Y:-HH), // 2 4
|
(X: 0.0; Y:-HH), // 2 4
|
||||||
(X: 1.0; Y:-H), // \ /
|
(X: 1.0; Y:-H), // \ /
|
||||||
(X: 1.0; Y: H) // 3
|
(X: 1.0; Y: H) // 3
|
||||||
@ -124,12 +129,35 @@ const
|
|||||||
|
|
||||||
{ TBasicBarcodeDrawer }
|
{ TBasicBarcodeDrawer }
|
||||||
|
|
||||||
constructor TBasicBarcodeDrawer.Create(AWidth, AHeight: Double);
|
constructor TBasicBarcodeDrawer.Create(AWidth, AHeight: Double);
|
||||||
|
begin
|
||||||
|
Create(0.0, 0.0, AWidth, AHeight);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// The origin of the coordinate system is in the top/left corner.
|
||||||
|
constructor TBasicBarcodeDrawer.Create(ALeft, ATop, ARight, ABottom: Double);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
FWidth := AWidth;
|
if ALeft < ARight then
|
||||||
FHeight := AHeight;
|
begin
|
||||||
|
FLeft := ALeft;
|
||||||
|
FWidth := ARight - ALeft;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
FLeft := ARight;
|
||||||
|
FWidth := ALeft - ARight;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if ATop < ABottom then
|
||||||
|
begin
|
||||||
|
FTop := ATop;
|
||||||
|
FHeight := ABottom - ATop;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
FTop := ABottom;
|
||||||
|
FHeight := ATop - ABottom;
|
||||||
|
end;
|
||||||
|
|
||||||
FBarColor := clBlack;
|
FBarColor := clBlack;
|
||||||
FTextColor := clBlack;
|
FTextColor := clBlack;
|
||||||
@ -147,13 +175,20 @@ begin
|
|||||||
FCanvas := ACanvas;
|
FCanvas := ACanvas;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TCanvasBarcodeDrawer.Create(ACanvas: TCanvas;
|
||||||
|
ALeft, ATop, ARight, ABottom: Double);
|
||||||
|
begin
|
||||||
|
inherited Create(ALeft, ATop, ARight, ABottom);
|
||||||
|
FCanvas := ACanvas;
|
||||||
|
end;
|
||||||
|
|
||||||
// Fill the background
|
// Fill the background
|
||||||
procedure TCanvasBarcodeDrawer.BeginDrawing;
|
procedure TCanvasBarcodeDrawer.BeginDrawing;
|
||||||
begin
|
begin
|
||||||
FCanvas.Pen.Style := psClear;
|
FCanvas.Pen.Style := psClear;
|
||||||
FCanvas.Brush.Color := FBackColor;
|
FCanvas.Brush.Color := FBackColor;
|
||||||
FCanvas.Brush.Style := bsSolid;
|
FCanvas.Brush.Style := bsSolid;
|
||||||
FCanvas.FillRect(0, 0, round(FWidth), round(FHeight));
|
FCanvas.FillRect(round(FLeft), round(FTop), round(FLeft + FWidth), round(FTop + FHeight));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCanvasBarcodeDrawer.EndDrawing;
|
procedure TCanvasBarcodeDrawer.EndDrawing;
|
||||||
@ -165,7 +200,7 @@ procedure TCanvasBarcodeDrawer.DrawBar(x1, y1, x2, y2: double);
|
|||||||
begin
|
begin
|
||||||
FCanvas.Brush.Color := FBarColor;
|
FCanvas.Brush.Color := FBarColor;
|
||||||
FCanvas.Brush.Style := bsSolid;
|
FCanvas.Brush.Style := bsSolid;
|
||||||
FCanvas.FillRect(round(x1), round(y1), round(x2), round(y2));
|
FCanvas.FillRect(round(FLeft + x1), round(FTop + y1), round(FLeft + x2), round(FTop + y2));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCanvasBarcodeDrawer.DrawCenteredText(x, y: double; const AText: String);
|
procedure TCanvasBarcodeDrawer.DrawCenteredText(x, y: double; const AText: String);
|
||||||
@ -178,7 +213,7 @@ begin
|
|||||||
FCanvas.Font.Color := FTextColor;
|
FCanvas.Font.Color := FTextColor;
|
||||||
FCanvas.Brush.Style := bsClear;
|
FCanvas.Brush.Style := bsClear;
|
||||||
w := FCanvas.TextWidth(AText);
|
w := FCanvas.TextWidth(AText);
|
||||||
FCanvas.TextOut(round(x - w/2), round(y), AText);
|
FCanvas.TextOut(round(FLeft + x - w/2), round(FTop + y), AText);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCanvasBarcodeDrawer.DrawHexagon(x, y, wx: Double);
|
procedure TCanvasBarcodeDrawer.DrawHexagon(x, y, wx: Double);
|
||||||
@ -186,6 +221,8 @@ var
|
|||||||
P: array[0..5] of TPoint;
|
P: array[0..5] of TPoint;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
x := FLeft + x;
|
||||||
|
y := FTop + y;
|
||||||
for i := 0 to 5 do
|
for i := 0 to 5 do
|
||||||
P[i] := Point(round(x + HEXAGON[i].X * wx), round(y + HEXAGON[i].Y * wx));
|
P[i] := Point(round(x + HEXAGON[i].X * wx), round(y + HEXAGON[i].Y * wx));
|
||||||
FCanvas.Brush.Color := FBarColor;
|
FCanvas.Brush.Color := FBarColor;
|
||||||
@ -208,7 +245,9 @@ begin
|
|||||||
FCanvas.Pen.Width := round(rInner - rOuter);
|
FCanvas.Pen.Width := round(rInner - rOuter);
|
||||||
|
|
||||||
r := (rOuter + rInner) / 2;
|
r := (rOuter + rInner) / 2;
|
||||||
FCanvas.Ellipse(round(x+r), round(y+r), round(x-r), round(y-r));
|
x := FLeft + x;
|
||||||
|
y := FTop + y;
|
||||||
|
FCanvas.Ellipse(round(x + r), round(y + r), round(x - r), round(y - r));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +255,13 @@ end;
|
|||||||
|
|
||||||
constructor TTextBarcodeDrawer.Create(AWidth, AHeight: Double; const ATitle: String);
|
constructor TTextBarcodeDrawer.Create(AWidth, AHeight: Double; const ATitle: String);
|
||||||
begin
|
begin
|
||||||
inherited Create(AWidth, AHeight);
|
Create(0.0, 0.0, AWidth, AHeight, ATitle);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TTextBarcodeDrawer.Create(ALeft, ATop, ARight, ABottom: Double;
|
||||||
|
const ATitle: String);
|
||||||
|
begin
|
||||||
|
inherited Create(ALeft, ATop, ARight, ABottom);
|
||||||
FTitle := ATitle;
|
FTitle := ATitle;
|
||||||
FList := TStringList.Create;
|
FList := TStringList.Create;
|
||||||
FFormatSettings := DefaultFormatSettings;
|
FFormatSettings := DefaultFormatSettings;
|
||||||
@ -283,7 +328,7 @@ procedure TSvgBarcodeDrawer.DrawBar(x1, y1, x2, y2: Double);
|
|||||||
begin
|
begin
|
||||||
FList.Add(Format(
|
FList.Add(Format(
|
||||||
' <rect x="%.3fmm" y="%.3fmm" width="%.3fmm" height="%.3fmm" fill="#%s" />', [
|
' <rect x="%.3fmm" y="%.3fmm" width="%.3fmm" height="%.3fmm" fill="#%s" />', [
|
||||||
x1, y1, x2-x1, y2-y1, SvgColor(FBarColor)],
|
FLeft + x1, FTop + y1, x2-x1, y2-y1, SvgColor(FBarColor)],
|
||||||
FFormatSettings
|
FFormatSettings
|
||||||
));
|
));
|
||||||
end;
|
end;
|
||||||
@ -295,7 +340,7 @@ begin
|
|||||||
y := y + FFontSize / 72 * 25.4; // Convert Fontsize (pts) to mm
|
y := y + FFontSize / 72 * 25.4; // Convert Fontsize (pts) to mm
|
||||||
FList.Add(Format(
|
FList.Add(Format(
|
||||||
' <text x="%.3fmm" y="%.3fmm" text-anchor="middle" font-family="%s" font-size="%.1fpt" fill="#%s">%s</text>', [
|
' <text x="%.3fmm" y="%.3fmm" text-anchor="middle" font-family="%s" font-size="%.1fpt" fill="#%s">%s</text>', [
|
||||||
x, y, FFontName, 1.0*FFontSize, SvgColor(FTextColor), AText],
|
FLeft + x, FTop + y, FFontName, 1.0*FFontSize, SvgColor(FTextColor), AText],
|
||||||
FFormatSettings
|
FFormatSettings
|
||||||
));
|
));
|
||||||
end;
|
end;
|
||||||
@ -305,6 +350,8 @@ var
|
|||||||
P: array[0..5] of TDblPoint;
|
P: array[0..5] of TDblPoint;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
x := FLeft + x;
|
||||||
|
y := FTop + y;
|
||||||
for i := 0 to 5 do
|
for i := 0 to 5 do
|
||||||
begin
|
begin
|
||||||
P[i].X := x + HEXAGON[i].X * wx;
|
P[i].X := x + HEXAGON[i].X * wx;
|
||||||
@ -322,7 +369,7 @@ procedure TSvgBarcodeDrawer.DrawRing(x, y, rOuter, rInner: Double);
|
|||||||
begin
|
begin
|
||||||
FList.Add(Format(
|
FList.Add(Format(
|
||||||
' <circle cx="%.3fmm" cy="%.3fmm" r="%.3fmm" stroke-width="%.3fmm" stroke="%s" fill="none" />', [
|
' <circle cx="%.3fmm" cy="%.3fmm" r="%.3fmm" stroke-width="%.3fmm" stroke="%s" fill="none" />', [
|
||||||
x, y, (rOuter + rInner)/2, abs(rOuter - rInner), SvgColor(FBarColor)],
|
FLeft + x, FTop + y, (rOuter + rInner)/2, abs(rOuter - rInner), SvgColor(FBarColor)],
|
||||||
FFormatSettings
|
FFormatSettings
|
||||||
));
|
));
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user