lazbarcodes: Mode 2 of Maxicode working.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8227 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-03-24 22:17:32 +00:00
parent 3c2efad7b9
commit 482be29d78
5 changed files with 639 additions and 19 deletions

View File

@ -488,7 +488,7 @@ object MainForm: TMainForm
Height = 293
Top = 35
Width = 152
PageIndex = 0
PageIndex = 2
BorderSpacing.Left = 16
TabOrder = 7
object pgOptions_QR: TPage
@ -550,6 +550,405 @@ object MainForm: TMainForm
TabOrder = 0
end
end
object pgOptions_Maxicode: TPage
object rgMaxicode_Mode: TRadioGroup
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = pgOptions_Maxicode
AnchorSideRight.Control = pgOptions_Maxicode
AnchorSideRight.Side = asrBottom
Left = 0
Height = 88
Top = 0
Width = 152
Anchors = [akTop, akLeft, akRight]
AutoFill = True
Caption = 'Mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 68
ClientWidth = 148
Columns = 2
ItemIndex = 0
Items.Strings = (
'auto'
'Mode 2'
'Mode 3'
'Mode 4'
'Mode 5'
'Mode 6'
)
OnClick = rgMaxicode_ModeClick
TabOrder = 0
end
object lblMaxicode_Postcode: TLabel
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = rgMaxicode_Mode
AnchorSideTop.Side = asrBottom
Left = 0
Height = 15
Top = 104
Width = 52
BorderSpacing.Top = 16
Caption = 'Post code'
ParentColor = False
end
object edMaxicode_Postcode: TEdit
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = lblMaxicode_Postcode
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = pgOptions_Maxicode
AnchorSideRight.Side = asrBottom
Left = 0
Height = 23
Top = 119
Width = 152
Anchors = [akTop, akLeft, akRight]
OnChange = edMaxicode_PostcodeChange
TabOrder = 1
TextHint = 'Enter postcode here'
end
object lblMaxicode_CountryCode: TLabel
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = edMaxicode_Postcode
AnchorSideTop.Side = asrBottom
Left = 0
Height = 15
Top = 150
Width = 128
BorderSpacing.Top = 8
Caption = 'Country code (ISO 3166)'
ParentColor = False
end
object cbMaxicode_CountryCode: TComboBox
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = lblMaxicode_CountryCode
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = pgOptions_Maxicode
AnchorSideRight.Side = asrBottom
Left = 0
Height = 23
Top = 167
Width = 152
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
ItemHeight = 15
Items.Strings = (
'004 - AFGHANISTAN'
'248 - ALAND ISLANDS'
'008 - ALBANIA'
'012 - ALGERIA'
'016 - AMERICAN SAMOA'
'020 - ANDORRA'
'024 - ANGOLA'
'660 - ANGUILLA'
'010 - ANTARCTICA'
'028 - ANTIGUA AND BARBUDA'
'032 - ARGENTINA'
'051 - ARMENIA'
'053 - ARUBA'
'036 - AUSTRALIA'
'040- AUSTRIA'
'031 - AZERBAIJAN'
'044 - BAHAMAS'
'048 - BAHRAIN'
'050 - BANGLADESH'
'052 - BARBADOS'
'112 - BELARUS'
'056 - BELGIUM'
'084 - BELIZE'
'204 - BENIN'
'060 - BERMUDA'
'064 - BHUTAN'
'068 - BOLIVIA'
'070 - BOSNIA AND HERZEGOVINA'
'072 - BOTSWANA'
'074 - BOUVET ISLAND'
'076 - BRAZIL'
'086 - BRITISH INDIAN OCEAN TERRITORY'
'096 - BRUNEI DARUSSALAM'
'100 - BULGARIA'
'854 - BURKINA FASO'
'108 - BURUNDI'
'116 - CAMBODIA'
'120 - CAMEROON'
'124 - CANADA'
'132 - CAPE VERDE'
'136 - CAYMAN ISLANDS'
'140 - CENTRAL AFRICAN REPUBLIC'
'148 - CHAD'
'152- CHILE'
'156 - CHINA'
'162 - CHRISTMAS ISLAND'
'166 - COCOS (KEELING) ISLANDS'
'170 - COLOMBIA'
'174 - COMOROS'
'178 - CONGO'
'180 - CONGO, THE DEMOCRATIC REPUBLIC OF THE'
'184 - COOK ISLANDS'
'188 - COSTA RICA'
'384 - COTE D''IVOIRE'
'191 - CROATIA'
'192 - CUBA'
'196 - CYPRUS'
'203 - CZECH REPUBLIC'
'208 - DENMARK'
'262 - DJIBOUTI'
'212 - DOMINICA'
'214 - DOMINICAN REPUBLIC'
'218 - ECUADOR'
'818 - EGYPT'
'222 - EL SALVADOR'
'226 - EQUATORIAL GUINEA'
'232 - ERITREA'
'233 - ESTONIA'
'231 - ETHIOPIA'
'238 - FALKLAND ISLANDS (MALVINAS)'
'234 - FAROE ISLANDS'
'242 - FIJI'
'246 - FINLAND'
'250 - FRANCE'
'254 - FRENCH GUIANA'
'258 - FRENCH POLYNESIA'
'260 - FRENCH SOUTHERN TERRITORIES'
'266 - GABON'
'270 - GAMBIA'
'268 - GEORGIA'
'276 - GERMANY'
'288 - GHANA'
'292 - GIBRALTAR'
'300 - GREECE'
'304 - GREENLAND'
'308 - GRENADA'
'312 - GUADELOUPE'
'316 - GUAM'
'320 - GUATEMALA'
'831 - GUERNSEY'
'324 - GUINEA'
'624 - GUINEA-BISSAU'
'328 - GUYANA'
'332 - HAITI'
'334 - HEARD ISLAND AND MCDONALD ISLANDS'
'336 - HOLY SEE (VATICAN CITY STATE)'
'340 - HONDURAS'
'344 - HONG KONG'
'348 - HUNGARY'
'352 - ICELAND'
'356 - INDIA'
'360 - INDONESIA'
'364 - IRAN (ISLAMIC REPUBLIC OF)'
'368 - IRAQ'
'372 - IRELAND'
'833 - ISLE OF MAN'
'376 - ISRAEL'
'380 - ITALY'
'388 - JAMAICA'
'392 - JAPAN'
'832 - JERSEY'
'400 - JORDAN'
'398 - KAZAKHSTAN'
'404 - KENYA'
'296 - KIRIBATI'
'408 - KOREA, DEMOCRATIC PEOPLE''S REPUBLIC OF'
'410 - KOREA, REPUBLIC OF'
'414 - KUWAIT'
'417 - KYRGYZSTAN'
'418 - LAO PEOPLE''S DEMOCRATIC REPUBLIC'
'428 - LATVIA'
'422 - LEBANON'
'426 - LESOTHO'
'430 - LIBERIA'
'434 - LIBYAN ARAB JAMAHIRIYA'
'438 - LIECHTENSTEIN'
'440 - LITHUANIA'
'442 - LUXEMBOURG'
'446 - MACAO'
'807 - MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF'
'450 - MADAGASCAR'
'454 - MALAWI'
'458 - MALAYSIA'
'462 - MALDIVES'
'466 - MALI'
'470 - MALTA'
'584 - MARSHALL ISLANDS'
'474 - MARTINIQUE'
'478 - MAURITANIA'
'480 - MAURITIUS'
'175 - MAYOTTE'
'484 - MEXICO'
'583 - MICRONESIA, FEDERATED STATES OF'
'498 - MOLDOVA, REPUBLIC OF'
'492 - MONACO'
'496 - MONGOLIA'
'499 - MONTENEGRO'
'500 - MONTSERRAT'
'504 - MOROCCO'
'508 - MOZAMBIQUE'
'104 - MYANMAR'
'516 - NAMIBIA'
'520 - NAURU'
'524 - NEPAL'
'528 - NETHERLANDS'
'530 - NETHERLANDS ANTILLES'
'540 - NEW CALEDONIA'
'554 - NEW ZEALAND'
'558 - NICARAGUA'
'562 - NIGER'
'566 - NIGERIA'
'570 - NIUE'
'574 - NORFOLK ISLAND'
'580 - NORTHERN MARIANA ISLANDS'
'578 - NORWAY'
'512 - OMAN'
'586 - PAKISTAN'
'585 - PALAU'
'275 - PALESTINIAN TERRITORY, OCCUPIED'
'591 - PANAMA'
'598 - PAPUA NEW GUINEA'
'600 - PARAGUAY'
'604 - PERU'
'608 - PHILIPPINES'
'612 - PITCAIRN'
'616 - POLAND'
'620 - PORTUGAL'
'630 - PUERTO RICO'
'634 - QATAR'
'638 - REUNION'
'642 - ROMANIA'
'643 - RUSSIAN FEDERATION'
'646 - RWANDA'
'654 - SAINT HELENA'
'659 - SAINT KITTS AND NEVIS'
'662 - SAINT LUCIA'
'666 - SAINT PIERRE AND MIQUELON'
'670 - SAINT VINCENT AND THE GRENADINES'
'882 - SAMOA'
'674 - SAN MARINO'
'678 - SAO TOME AND PRINCIPE'
'682 - SAUDI ARABIA'
'686 - SENEGAL'
'688 - SERBIA'
'690 - SEYCHELLES'
'694 - SIERRA LEONE'
'702 - SINGAPORE'
'703 - SLOVAKIA'
'705 - SLOVENIA'
'090 - SOLOMON ISLANDS'
'706 - SOMALIA'
'710 - SOUTH AFRICA'
'239 - SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS'
'724 - SPAIN'
'144 - SRI LANKA'
'736 - SUDAN'
'740 - SURINAME'
'744 - SVALBARD AND JAN MAYEN'
'654 - ST. HELENA'
'666 - ST. PIERRE AND MIQUELON'
'748 - SWAZILAND'
'752 - SWEDEN'
'756 - SWITZERLAND'
'760 - SYRIAN ARAB REPUBLIC'
'158 - TAIWAN, PROVINCE OF CHINA'
'762 - TAJIKISTAN'
'834 - TANZANIA, UNITED REPUBLIC OF'
'764 - THAILAND'
'626 - TIMOR-LESTE'
'768 - TOGO'
'772 - TOKELAU'
'776 - TONGA'
'780 - TRINIDAD AND TOBAGO'
'788 - TUNISIA'
'792 - TURKEY'
'795 - TURKMENISTAN'
'796 - TURKS AND CAICOS ISLANDS'
'798 - TUVALU'
'800 - UGANDA'
'804 - UKRAINE'
'784 - UNITED ARAB EMIRATES'
'826 - UNITED KINGDOM'
'840 - UNITED STATES'
'581 - UNITED STATES MINOR OUTLYING ISLANDS'
'858 - URUGUAY'
'860 - UZBEKISTAN'
'548 - VANUATU'
'336 - VATICAN CITY STATE (HOLY SEE)'
'862 - VENEZUELA'
'704 - VIET NAM'
'092 - VIRGIN ISLANDS (BRITISH)'
'850 - VIRGIN ISLANDS (U.S.)'
'876 - WALLIS AND FUTUNA'
'732 - WESTERN SAHARA'
'887 - YEMEN'
'891 - YUGOSLAVIA'
'894 - ZAMBIA'
'716 - ZIMBABWE'
)
OnChange = cbMaxicode_CountryCodeChange
TabOrder = 2
TextHint = 'Select item'
end
object lblMaxicode_ServiceCode: TLabel
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = cbMaxicode_CountryCode
AnchorSideTop.Side = asrBottom
Left = 0
Height = 15
Top = 198
Width = 66
BorderSpacing.Top = 8
Caption = 'Service code'
ParentColor = False
end
object edMaxicode_ServiceCode: TEdit
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = lblMaxicode_ServiceCode
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = pgOptions_Maxicode
AnchorSideRight.Side = asrBottom
Left = 0
Height = 23
Top = 215
Width = 152
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
MaxLength = 3
OnChange = edMaxicode_ServiceCodeChange
TabOrder = 3
TextHint = 'Enter carrier-specific service code'
end
object lblMaxicode_Primary: TLabel
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = edMaxicode_ServiceCode
AnchorSideTop.Side = asrBottom
Left = 0
Height = 15
Top = 246
Width = 64
BorderSpacing.Top = 8
Caption = 'Primary text'
ParentColor = False
end
object edMaxicode_Primary: TEdit
AnchorSideLeft.Control = pgOptions_Maxicode
AnchorSideTop.Control = lblMaxicode_Primary
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = pgOptions_Maxicode
AnchorSideRight.Side = asrBottom
Left = 0
Height = 23
Top = 263
Width = 152
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 2
Enabled = False
OnChange = edMaxicode_PrimaryChange
TabOrder = 4
end
end
end
end
object BarcodePanel: TPanel
@ -600,7 +999,7 @@ object MainForm: TMainForm
end
object SaveDialog1: TSaveDialog
OnTypeChange = SaveDialogTypeChange
Left = 681
Top = 210
Left = 568
Top = 240
end
end

View File

@ -26,12 +26,20 @@ type
clbForeground: TColorButton;
cmbBearerBarsBox: TComboBox;
clbBackground: TColorButton;
cbMaxicode_CountryCode: TComboBox;
edMaxicode_Primary: TEdit;
edMaxicode_ServiceCode: TEdit;
edMaxicode_Postcode: TEdit;
edText: TEdit;
FontDialog: TFontDialog;
gbGeometry: TGroupBox;
gbShow: TGroupBox;
gbChecksum: TGroupBox;
gbColors: TGroupBox;
lblMaxicode_Primary: TLabel;
lblMaxicode_ServiceCode: TLabel;
lblMaxicode_CountryCode: TLabel;
lblMaxicode_Postcode: TLabel;
lblWhiteSpaceWidth: TLabel;
lblScale: TLabel;
lblError: TLabel;
@ -39,11 +47,13 @@ type
lblText: TLabel;
lblSymbolHeight: TLabel;
nbOptions: TNotebook;
pgOptions_Maxicode: TPage;
pgOptions_Plessey: TPage;
pgOptions_QR: TPage;
Panel1: TPanel;
Panel2: TPanel;
BarcodePanel: TPanel;
rgMaxicode_Mode: TRadioGroup;
rgPlessey_Checkchar: TRadioGroup;
rgQR_ECCLevel: TRadioGroup;
SaveDialog1: TSaveDialog;
@ -62,9 +72,14 @@ type
procedure btnSampleTextClick(Sender: TObject);
procedure btnSaveToFileClick(Sender: TObject);
procedure cbAutoSizeChange(Sender: TObject);
procedure cbMaxicode_CountryCodeChange(Sender: TObject);
procedure cbRecommendedSymbolSizeChange(Sender: TObject);
procedure edMaxicode_PostcodeChange(Sender: TObject);
procedure edMaxicode_PrimaryChange(Sender: TObject);
procedure edMaxicode_ServiceCodeChange(Sender: TObject);
procedure edTextChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure rgMaxicode_ModeClick(Sender: TObject);
procedure rgPlessey_CheckcharClick(Sender: TObject);
procedure rgQR_ECCLevelClick(Sender: TObject);
procedure SaveDialogTypeChange(Sender: TObject);
@ -263,6 +278,18 @@ begin
end;
end;
procedure TMainForm.cbMaxicode_CountryCodeChange(Sender: TObject);
var
s: String;
begin
if FBarcode is TBarcodeMaxicode then
begin
s := cbMaxicode_Countrycode.Items[cbMaxicode_Countrycode.ItemIndex];
TBarcodeMaxicode(FBarcode).CountryCode := StrToInt(Copy(s, 1, 3));
edMaxicode_Primary.Text := TBarcodeMaxicode(FBarcode).Primary;
end;
end;
procedure TMainForm.cbRecommendedSymbolSizeChange(Sender: TObject);
begin
seScale.Enabled := not cbRecommendedSymbolSize.Checked;
@ -293,12 +320,66 @@ begin
end;
end;
procedure TMainForm.edMaxicode_PostcodeChange(Sender: TObject);
begin
if FBarcode is TBarcodeMaxicode then
begin
TBarcodeMaxicode(FBarcode).Postcode := edMaxicode_Postcode.Text;
edMaxicode_Primary.Text := TBarcodeMaxicode(FBarcode).Primary;
end;
end;
procedure TMainForm.edMaxicode_PrimaryChange(Sender: TObject);
begin
if FBarcode is TBarcodeMaxicode then
begin
TBarcodeMaxicode(FBarcode).Primary := edMaxicode_Primary.Text;
edMaxicode_Primary.Text := TBarcodeMaxicode(FBarcode).Primary;
end;
end;
procedure TMainForm.edMaxicode_ServiceCodeChange(Sender: TObject);
begin
if FBarcode is TBarcodeMaxicode then
begin
TBarcodeMaxicode(FBarcode).Servicecode := StrToInt(edMaxicode_Servicecode.Text);
edMaxicode_Primary.Text := TBarcodeMaxicode(FBarcode).Primary;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
nbOptions.PageIndex := -1;
PopulateBarcodesTree;
end;
procedure TMainForm.rgMaxicode_ModeClick(Sender: TObject);
begin
if FBarcode is TBarcodeMaxicode then
begin
case rgMaxicode_Mode.ItemIndex of
-1: exit;
0: TBarcodeMaxicode(FBarcode).Mode := mcmAuto;
1: TBarcodeMaxicode(FBarcode).Mode := mcmMode2;
2: TBarcodeMaxicode(FBarcode).Mode := mcmMode3;
3: TBarcodeMaxicode(FBarcode).Mode := mcmMode4;
4: TBarcodeMaxicode(FBarcode).Mode := mcmMode5;
5: TBarcodeMaxicode(FBarcode).Mode := mcmMode6;
else raise Exception.Create('Mode not supported.');
end;
edMaxicode_Primary.Text := TBarcodeMaxicode(FBarcode).Primary;
end;
edMaxicode_Postcode.Visible := rgMaxicode_Mode.ItemIndex in [0, 1, 2];
lblMaxicode_Postcode.Visible := edMaxicode_Postcode.Visible;
cbMaxicode_Countrycode.Visible := edMaxicode_Postcode.Visible;
lblMaxicode_Countrycode.Visible := edMaxicode_Postcode.Visible;
edMaxicode_ServiceCode.Visible := edMaxicode_Postcode.Visible;
lblMaxicode_ServiceCode.Visible := edMaxicode_Postcode.Visible;
edMaxicode_Primary.Visible := edMaxicode_Postcode.Visible;
lblMaxicode_Primary.Visible := edMaxicode_Postcode.Visible;
end;
procedure TMainForm.rgPlessey_CheckcharClick(Sender: TObject);
begin
if FBarcode is TBarcodePlessey then
@ -488,6 +569,9 @@ begin
else
if (FBarcode is TBarcodeQR) then
nbOptions.PageIndex := pgOptions_QR.PageIndex
else
if (FBarcode is TBarcodeMaxiCode) then
nbOptions.PageIndex := pgOptions_Maxicode.PageIndex
else
nbOptions.PageIndex := -1;

View File

@ -515,7 +515,10 @@ begin
if _set[i] = 6 then
begin
// Number compression
for j := 0 to 9 do
// 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);
@ -580,9 +583,10 @@ begin
end;
{ Format structured primary for Mode 2 }
procedure maxi_do_primary_2(APostCode: String; ACountry, AService: Integer);
function maxi_do_primary_2(APostCode: String; ACountry, AService: Integer): Boolean;
var
postcode_length, postcode_number: Integer;
postcode_number: Integer;
postcode_length: Integer;
i: Integer;
begin
for i := 1 to Length(APostCode) do
@ -592,9 +596,13 @@ begin
break;
end;
postcode_length := Length(APostCode);
postcode_number := StrToInt(APostCode);
postcode_length := Length(APostcode);
if (APostCode = '') or not TryStrToInt(APostCode, postcode_number) then
begin
Result := false;
exit;
end;
maxi_codeword[0] := ((postcode_number and $03) shl 4) or 2;
maxi_codeword[1] := ((postcode_number and $fc) shr 2);
maxi_codeword[2] := ((postcode_number and $3f00) shr 8);
@ -605,6 +613,8 @@ begin
maxi_codeword[7] := (ACountry and $fc) shr 2;
maxi_codeword[8] := ((ACountry and $300) shr 8) or ((AService and $f) shl 2);
maxi_codeword[9] := ((AService and $3f0) shr 4);
Result := true;
end;
(*
procedure maxi_do_primary_2(APostCode: TCharDynArray; ACountry, AService: Integer);
@ -707,7 +717,8 @@ end;
*)
function maxicode(ASymbol: PZintSymbol; ASource: PByte; ALength: Integer): Integer;
var
i, j, mode, countrycode, service, lp: Integer;
i, j, mode, countrycode, service: Integer;
lp: Integer = 0;
block: Integer = 0;
bit: Integer = 0;
bit_pattern: array[0..6] of integer;
@ -731,7 +742,7 @@ begin
FillChar(maxi_codeword[0], SizeOf(maxi_codeword), 0);
{ mode is not specified }
if (mode = -1) then
if (mode <= 0) then
begin
lp := StrLen(ASymbol^.Primary);
if lp = 0 then
@ -762,10 +773,10 @@ begin
if (mode = 2) or (mode = 3) then
begin
if lp = 0 then // Mode set manually means: lp doesn't get set
lp := System.StrLen(PChar(ASymbol^.Primary));
lp := Length(ASymbol^.GetPrimary);
if lp <> 15 then
begin
ASymbol^.SetErrorText('Invalid Primary String');
ASymbol^.SetErrorText('Primary String Length Error (15 characters needed).');
Result := ERROR_INVALID_DATA;
exit;
end;
@ -807,14 +818,31 @@ begin
postcode[7] := #0;
*)
SetLength(countrystr, 3);
Move(ASymbol^.Primary[9], countrystr[1], 3);
countrycode := StrToInt(countrystr);
if not TryStrToInt(countrystr, countrycode) or (countrycode < 0) then
begin
ASymbol^.SetErrorText('Invalid country code.');
Result := ERROR_INVALID_DATA;
exit;
end;
SetLength(servicestr, 3);
Move(ASymbol^.Primary[12], servicestr[1], 3);
service := StrToInt(servicestr);
if not TryStrToInt(servicestr, service) then
begin
ASymbol^.SetErrorText('Invalid service code.');
Result := ERROR_INVALID_DATA;
exit;
end;
case mode of
2: maxi_do_primary_2(postcode, countrycode, service);
2: if not maxi_do_primary_2(postcode, countrycode, service) then
begin
ASymbol^.SetErrorText('Invalid post code.');
Result := ERROR_INVALID_DATA;
exit;
end;
3: maxi_do_primary_3(postcode, countrycode, service);
else ;
end;

View File

@ -605,12 +605,21 @@ type
{ TBarcodeMaxiCode }
TBarcodeMaxicodeMode = (mcmAuto=-1, mcmMode2=2, mcmMode3=3, mcmMode4=4, mcmMode5=5, mcmMode6);
TBarcodeMaxicodeMode = (mcmAuto=0, mcmMode2=2, mcmMode3=3, mcmMode4=4, mcmMode5=5, mcmMode6=6);
TBarcodeMaxiCode = class(TSimpleBarcode)
private
FMode: TBarcodeMaxicodeMode;
FPostcode: String;
FPrimary: String;
FCountryCode: Integer;
FServiceCode: Integer;
function GetPrimary: String;
procedure SetCountryCode(AValue: Integer);
procedure SetMode(AValue: TBarcodeMaxicodeMode);
procedure SetPostCode(AValue: String);
procedure SetPrimary(AValue: String);
procedure SetServiceCode(AValue: Integer);
protected
function CalcFactor(AWidth, AHeight: Integer): Integer; override;
procedure CalcSize(AFactor: Integer;
@ -627,6 +636,10 @@ type
constructor Create(AOwner: TComponent); override;
published
property Mode: TBarcodeMaxicodeMode read FMode write SetMode default mcmAuto;
property Primary: String read GetPrimary write SetPrimary;
property Postcode: String read FPostCode write SetPostcode;
property CountryCode: Integer read FCountryCode write SetCountryCode default 0;
property ServiceCode: Integer read FServiceCode write SetServiceCode default 0;
end;
@ -3322,11 +3335,36 @@ begin
Result.CY := 88;
end;
function TBarcodeMaxiCode.GetPrimary: String;
var
postcodeStr, countrycodeStr, serviceCodeStr: String;
postcodeLen: Integer;
begin
case FMode of
mcmAuto:
Result := FPrimary;
mcmMode2, mcmMode3:
begin
if FMode = mcmMode2 then
postcodeLen := 9
else
postcodeLen := 6;
postcodestr := FPostcode + StringOfChar(' ', postcodeLen - Length(FPostCode));
countrycodestr := FormatFloat('000', FCountryCode);
servicecodestr := FormatFloat('000', FServiceCode);
Result := postcodestr + countrycodestr + servicecodestr;
end;
else
Result := '';
end;
end;
function TBarcodeMaxiCode.InternalGenerate: Integer;
begin
FSymbol^.option_1 := ord(FMode);
//Move(FText[1], FSymbol^.Primary[0], Length(FText));
if FMode in [mcmAuto, mcmMode2, mcmMode3] then
FSymbol^.SetPrimary(GetPrimary);
Result := maxicode(FSymbol, @FText[1], Length(FText));
end;
@ -3423,6 +3461,18 @@ begin
*)
end;
procedure TBarcodeMaxicode.SetCountryCode(AValue: Integer);
begin
if AValue = FCountryCode then exit;
if (AValue > 0) and (AValue < 1000) then
begin
FCountryCode := AValue;
if FMode in [mcmMode2, mcmMode3] then
GenerateAndInvalidate;
end else
raise Exception.Create('Maxicode country code must be > 0 and < 1000');
end;
procedure TBarcodeMaxicode.SetMode(AValue: TBarcodeMaxicodeMode);
begin
if FMode = AValue then exit;
@ -3430,6 +3480,34 @@ begin
GenerateAndInvalidate;
end;
procedure TBarcodeMaxicode.SetPostcode(AValue: String);
begin
if AValue = FPostcode then exit;
FPostcode := AValue;
if FMode in [mcmMode2, mcmMode3] then
GenerateAndInvalidate;
end;
procedure TBarcodeMaxicode.SetPrimary(AValue: String);
begin
if AValue = FPrimary then exit;
FPrimary := AValue;
if FMode = mcmAuto then
GenerateAndInvalidate;
end;
procedure TBarcodeMaxicode.SetServiceCode(AValue: Integer);
begin
if AValue = FServiceCode then exit;
if (AValue > 0) and (AValue < 1000) then
begin
FServiceCode := AValue;
if FMode in [mcmMode2, mcmMode3] then
GenerateAndInvalidate;
end else
raise Exception.Create('Maxicode Service code must be > 0 and < 1000');
end;
procedure TBarcodeMaxiCode.SetRecommendedSymbolSizeParams;
begin
FScale := 4;

View File

@ -156,6 +156,9 @@ type
procedure SetText(const AText: String);
function GetErrorText: String;
procedure SetErrorText(const AErrTxt: String);
// Maxicode only:
function GetPrimary: String;
procedure SetPrimary(const AText: String);
end;
PZintSymbol = ^zint_symbol;
@ -297,6 +300,23 @@ begin
end;
end;
function zint_symbol.GetPrimary: String;
var
i: Integer;
begin
Result := '';
SetLength(Result, Length(primary));
for i := 0 to High(primary) do
begin
if primary[i] = #0 then
begin
SetLength(Result, i);
exit;
end;
Result[i+1] := primary[i];
end;
end;
function zint_symbol.GetText: String;
var
i: Integer;
@ -325,6 +345,17 @@ begin
errtxt[i-1] := AErrTxt[i];
end;
procedure zint_symbol.SetPrimary(const AText: String);
var
i, n: Integer;
begin
n := Length(AText);
if n > 128 then n := 128;
FillChar(primary, 128, 0);
for i := 1 to n do
primary[i-1] := AText[i];
end;
procedure zint_symbol.SetText(const AText: String);
var
i, n: Integer;