{
* Copyright 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Original Author: Sean Owen
* Delphi Implementation by K. Gossens
}
unit ZXing.OneD.EANManufacturerOrgSupport;
interface
uses
System.SysUtils,
System.Classes,
System.Generics.Collections,
System.Math,
ZXing.OneD.UPCEANExtension2Support,
ZXing.OneD.UPCEANExtension5Support,
ZXing.Reader,
ZXing.BinaryBitmap,
ZXing.ReadResult,
ZXing.DecodeHintType,
ZXing.ResultMetadataType,
ZXing.ResultPoint,
ZXing.Common.BitArray,
ZXing.Common.Detector.MathUtils;
type
//
/// Records EAN prefix to GS1 Member Organization, where the member organization
/// correlates strongly with a country. This is an imperfect means of identifying
/// a country of origin by EAN-13 barcode value. See
///
/// http://en.wikipedia.org/wiki/List_of_GS1_country_codes.
///
TEANManufacturerOrgSupport = class sealed
private
var
ranges: TList>;
countryIdentifiers: TStringList;
procedure add(const range: TArray; const id: string);
procedure initIfNeeded;
public
constructor Create;
destructor Destroy; override;
function lookupCountryIdentifier(const productCode: String): String;
end;
implementation
{ TEANManufacturerOrgSupport }
constructor TEANManufacturerOrgSupport.Create;
begin
ranges := TList < TArray < Integer >>.Create;
countryIdentifiers := TStringList.Create;
end;
destructor TEANManufacturerOrgSupport.Destroy;
begin
countryIdentifiers.Free;
ranges.Free;
inherited;
end;
function TEANManufacturerOrgSupport.lookupCountryIdentifier(const productCode
: String): String;
var
i, prefix, max: Integer;
range: TArray;
start, ending: Integer;
begin
Result := '';
initIfNeeded;
prefix := Integer.Parse(productCode.Substring(0, 3));
max := ranges.Count;
for i := 0 to Pred(max) do
begin
range := ranges[i];
start := range[0];
if (prefix < start) then
exit;
if (Length(range) = 1) then
ending := start
else
ending := range[1];
if (prefix <= ending) then
begin
Result := countryIdentifiers[i];
break;
end;
end;
end;
procedure TEANManufacturerOrgSupport.add(const range: TArray;
const id: string);
begin
ranges.add(range);
countryIdentifiers.add(id);
end;
procedure TEANManufacturerOrgSupport.initIfNeeded;
begin
if (ranges.Count = 0) then
begin
add(TArray.Create(0, 19), 'US/CA');
add(TArray.Create(30, 39), 'US');
add(TArray.Create(60, 139), 'US/CA');
add(TArray.Create(300, 379), 'FR');
add(TArray.Create(380), 'BG');
add(TArray.Create(383), 'SI');
add(TArray.Create(385), 'HR');
add(TArray.Create(387), 'BA');
add(TArray.Create(400, 440), 'DE');
add(TArray.Create(450, 459), 'JP');
add(TArray.Create(460, 469), 'RU');
add(TArray.Create(471), 'TW');
add(TArray.Create(474), 'EE');
add(TArray.Create(475), 'LV');
add(TArray.Create(476), 'AZ');
add(TArray.Create(477), 'LT');
add(TArray.Create(478), 'UZ');
add(TArray.Create(479), 'LK');
add(TArray.Create(480), 'PH');
add(TArray.Create(481), 'BY');
add(TArray.Create(482), 'UA');
add(TArray.Create(484), 'MD');
add(TArray.Create(485), 'AM');
add(TArray.Create(486), 'GE');
add(TArray.Create(487), 'KZ');
add(TArray.Create(489), 'HK');
add(TArray.Create(490, 499), 'JP');
add(TArray.Create(500, 509), 'GB');
add(TArray.Create(520), 'GR');
add(TArray.Create(528), 'LB');
add(TArray.Create(529), 'CY');
add(TArray.Create(531), 'MK');
add(TArray.Create(535), 'MT');
add(TArray.Create(539), 'IE');
add(TArray.Create(540, 549), 'BE/LU');
add(TArray.Create(560), 'PT');
add(TArray.Create(569), 'IS');
add(TArray.Create(570, 579), 'DK');
add(TArray.Create(590), 'PL');
add(TArray.Create(594), 'RO');
add(TArray.Create(599), 'HU');
add(TArray.Create(600, 601), 'ZA');
add(TArray.Create(603), 'GH');
add(TArray.Create(608), 'BH');
add(TArray.Create(609), 'MU');
add(TArray.Create(611), 'MA');
add(TArray.Create(613), 'DZ');
add(TArray.Create(616), 'KE');
add(TArray.Create(618), 'CI');
add(TArray.Create(619), 'TN');
add(TArray.Create(621), 'SY');
add(TArray.Create(622), 'EG');
add(TArray.Create(624), 'LY');
add(TArray.Create(625), 'JO');
add(TArray.Create(626), 'IR');
add(TArray.Create(627), 'KW');
add(TArray.Create(628), 'SA');
add(TArray.Create(629), 'AE');
add(TArray.Create(640, 649), 'FI');
add(TArray.Create(690, 695), 'CN');
add(TArray.Create(700, 709), 'NO');
add(TArray.Create(729), 'IL');
add(TArray.Create(730, 739), 'SE');
add(TArray.Create(740), 'GT');
add(TArray.Create(741), 'SV');
add(TArray.Create(742), 'HN');
add(TArray.Create(743), 'NI');
add(TArray.Create(744), 'CR');
add(TArray.Create(745), 'PA');
add(TArray.Create(746), 'DO');
add(TArray.Create(750), 'MX');
add(TArray.Create(754, 755), 'CA');
add(TArray.Create(759), 'VE');
add(TArray.Create(760, 769), 'CH');
add(TArray.Create(770), 'CO');
add(TArray.Create(773), 'UY');
add(TArray.Create(775), 'PE');
add(TArray.Create(777), 'BO');
add(TArray.Create(779), 'AR');
add(TArray.Create(780), 'CL');
add(TArray.Create(784), 'PY');
add(TArray.Create(785), 'PE');
add(TArray.Create(786), 'EC');
add(TArray.Create(789, 790), 'BR');
add(TArray.Create(800, 839), 'IT');
add(TArray.Create(840, 849), 'ES');
add(TArray.Create(850), 'CU');
add(TArray.Create(858), 'SK');
add(TArray.Create(859), 'CZ');
add(TArray.Create(860), 'YU');
add(TArray.Create(865), 'MN');
add(TArray.Create(867), 'KP');
add(TArray.Create(868, 869), 'TR');
add(TArray.Create(870, 879), 'NL');
add(TArray.Create(880), 'KR');
add(TArray.Create(885), 'TH');
add(TArray.Create(888), 'SG');
add(TArray.Create(890), 'IN');
add(TArray.Create(893), 'VN');
add(TArray.Create(896), 'PK');
add(TArray.Create(899), 'ID');
add(TArray.Create(900, 919), 'AT');
add(TArray.Create(930, 939), 'AU');
add(TArray.Create(940, 949), 'AZ');
add(TArray.Create(955), 'MY');
add(TArray.Create(958), 'MO');
end;
end;
end.