lazbarcode: Some refactoring towards more pascal-like code of Maxicode.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8230 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-03-25 18:02:50 +00:00
parent 1d32139e44
commit 630fa53693
2 changed files with 11 additions and 51 deletions

View File

@ -19,7 +19,7 @@ interface
uses
Sysutils, zint;
function maxicode(ASymbol: PZintSymbol; ASource: PByte; ALength: Integer): Integer;
function maxicode(ASymbol: PZintSymbol; ASource: String): Integer;
implementation
@ -515,9 +515,7 @@ begin
if _set[i] = 6 then
begin
// Number compression
// SetLength(substring, 10);
SetLength(substring, 9);
// for j := 0 to 9 do
for j := 0 to 8 do
substring[j+1] := char(_char[i+j]);
value := StrToInt(substring);
@ -592,7 +590,7 @@ begin
for i := 1 to Length(APostCode) do
if not (APostCode[i] in ['0'..'9']) then
begin
SetLength(APostCode, i-1);
Result := false;
break;
end;
@ -715,7 +713,7 @@ begin
maxi_codeword[9] := ((AService and $3f0) shr 4);
end;
*)
function maxicode(ASymbol: PZintSymbol; ASource: PByte; ALength: Integer): Integer;
function maxicode(ASymbol: PZintSymbol; ASource: String): Integer;
var
i, j, mode, countrycode, service: Integer;
lp: Integer = 0;
@ -726,18 +724,11 @@ var
postcode: String = '';
countrystr: string[3];
servicestr: string[3];
local_source: array of char = nil;
P: PChar;
local_source: String;
begin
mode := ASymbol^.Option_1;
SetLength(local_source, ALength+1);
P := PChar(ASource);
for i:=0 to ALength-1 do begin
local_source[i] := P^;
inc(P);
end;
local_source[ALength] := #0;
local_source := ASource;
FillChar(maxi_codeword[0], SizeOf(maxi_codeword), 0);
@ -790,8 +781,7 @@ begin
exit;
end;
SetLength(postcode, 9);
Move(ASymbol^.Primary, postcode[1], 9);
postcode := Copy(ASymbol^.GetPrimary, 1, 9);
if mode = 2 then
begin
@ -803,23 +793,8 @@ begin
end;
end else
SetLength(postcode, 6);
(*
Move(ASymbol^.Primary, postcode, 9);
postcode[0] := #0;
if (mode = 2) then
begin
for i := 0 to 9 do
if postcode[i] = ' ' then
postcode[i] := #0;
end else
if (mode = 3) then
postcode[7] := #0;
*)
SetLength(countrystr, 3);
Move(ASymbol^.Primary[9], countrystr[1], 3);
countrystr := Copy(ASymbol^.GetPrimary, 10, 3);
if not TryStrToInt(countrystr, countrycode) or (countrycode < 0) then
begin
ASymbol^.SetErrorText('Invalid country code.');
@ -827,8 +802,7 @@ begin
exit;
end;
SetLength(servicestr, 3);
Move(ASymbol^.Primary[12], servicestr[1], 3);
servicestr := Copy(ASymbol^.GetPrimary, 13, 3);
if not TryStrToInt(servicestr, service) then
begin
ASymbol^.SetErrorText('Invalid service code.');
@ -849,7 +823,7 @@ begin
end else
maxi_codeword[0] := mode;
i := maxi_text_process(mode, @local_source[0], ALength);
i := maxi_text_process(mode, @local_source[1], Length(local_source));
if (i = ERROR_TOO_LONG) then
begin
ASymbol^.SetErrorText('Input data too long.');

View File

@ -3387,23 +3387,9 @@ begin
if FMode in [mcmAuto, mcmMode2, mcmMode3] then
FSymbol^.SetPrimary(FPrimary);
Result := maxicode(FSymbol, @FText[1], Length(FText));
Result := maxicode(FSymbol, FText);
end;
(*
function TBarcodeMaxiCode.InternalGenerate: Integer;
var
txt: array of byte;
begin
FSymbol^.option_1 := ord(FMode);
setLength(txt, Length(FText)+1);
Move(FText[1], txt[0], Length(txt));
txt[Length(txt)] := 0;
Result := maxicode(FSymbol, txt, Length(FText));
end;
*)
procedure TBarcodeMaxiCode.RenderSymbol(xLeft, yTop, ASymbolWidth, ASymbolHeight,
{%H-}ATextHeight, AFactor: Integer);
var