mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 22:14:25 +02:00
* Add clipping
git-svn-id: trunk@37308 -
This commit is contained in:
parent
e6daa40259
commit
d4deaa39ca
@ -31,6 +31,7 @@ Type
|
|||||||
TFPDrawBarCode = Class
|
TFPDrawBarCode = Class
|
||||||
private
|
private
|
||||||
FCanvas: TFPCustomCanvas;
|
FCanvas: TFPCustomCanvas;
|
||||||
|
FClipping: Boolean;
|
||||||
FEncoding: TBarcodeEncoding;
|
FEncoding: TBarcodeEncoding;
|
||||||
FImage: TFPCustomImage;
|
FImage: TFPCustomImage;
|
||||||
FRect: TRect;
|
FRect: TRect;
|
||||||
@ -71,6 +72,8 @@ Type
|
|||||||
Property Encoding : TBarcodeEncoding Read FEncoding Write SetEncoding;
|
Property Encoding : TBarcodeEncoding Read FEncoding Write SetEncoding;
|
||||||
// Text to draw.
|
// Text to draw.
|
||||||
Property Text : String Read FText Write FText;
|
Property Text : String Read FText Write FText;
|
||||||
|
// If true, the barcode will be clipped if it falls outside rect.
|
||||||
|
Property Clipping : Boolean Read FClipping Write FClipping;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function DrawBarCode(Img : TFPCustomImage; S : String; E : TBarcodeEncoding; aWidth : Integer = 1; AWeight : Double = 2.0) : Boolean;
|
Function DrawBarCode(Img : TFPCustomImage; S : String; E : TBarcodeEncoding; aWidth : Integer = 1; AWeight : Double = 2.0) : Boolean;
|
||||||
@ -191,9 +194,8 @@ Function TFPDrawBarCode.Draw : Boolean;
|
|||||||
|
|
||||||
Var
|
Var
|
||||||
Cnv : TFPCustomCanvas;
|
Cnv : TFPCustomCanvas;
|
||||||
i: integer;
|
I,L,MaxWidth, W, H : integer;
|
||||||
xOffset: integer;
|
xOffset: integer;
|
||||||
w, h: integer;
|
|
||||||
BarRect : TRect;
|
BarRect : TRect;
|
||||||
BP : TBarParams;
|
BP : TBarParams;
|
||||||
Data : TBarTypeArray;
|
Data : TBarTypeArray;
|
||||||
@ -210,7 +212,10 @@ begin
|
|||||||
Cnv.Brush.Style:=bsSolid;
|
Cnv.Brush.Style:=bsSolid;
|
||||||
Cnv.FillRect(Rect);
|
Cnv.FillRect(Rect);
|
||||||
Cnv.Pen.Width := 1;
|
Cnv.Pen.Width := 1;
|
||||||
for i:=0 to Length(Data)-1 do
|
I:=0;
|
||||||
|
L:=Length(Data);
|
||||||
|
MaxWidth:=Rect.Right-Rect.Left;
|
||||||
|
While (I<L) and (Not Clipping or (XOffset<MaxWidth)) do
|
||||||
begin
|
begin
|
||||||
BP:=BarTypeToBarParams(Data[i]);
|
BP:=BarTypeToBarParams(Data[i]);
|
||||||
case BP.c of
|
case BP.c of
|
||||||
@ -226,8 +231,10 @@ begin
|
|||||||
BarRect.Top:=Rect.Top;
|
BarRect.Top:=Rect.Top;
|
||||||
BarRect.Bottom:=Rect.Top+H;
|
BarRect.Bottom:=Rect.Top+H;
|
||||||
BarRect.Right:=BarRect.Left + W-1;
|
BarRect.Right:=BarRect.Left + W-1;
|
||||||
Cnv.FillRect(BarRect);
|
if (Not Clipping or (BarRect.Right<=MaxWidth)) then
|
||||||
|
Cnv.FillRect(BarRect);
|
||||||
xOffset:=xOffset + W;
|
xOffset:=xOffset + W;
|
||||||
|
Inc(I);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user