unit PrinterLib;

interface

function DemPrinterCreator(model: ansistring): Integer;
function DemPortOpen(portSetting: ansistring): Integer;
function DemPortClose(): Integer;
function DemDerectIO(writedata: PByte; writeNum: Integer;
  readdata: PByte; readNum: Integer; var preadNum: Integer): Integer;

function AddLabel(offSet: Integer; height: Integer; qty: Integer): Integer;
function SetAlign(align: Integer): Integer;
function AddText(rotate: Integer; fontType: Integer; fontSize: Integer;
  xPos: Integer; yPos: Integer; data: ansistring): Integer;
function AddBarCode(rotate: Integer; codetype: Integer; width: Integer;
  ratio: Integer; height: Integer; xPos: Integer; yPos: Integer;
  data: ansistring): Integer;
function AddBarCodeText(enable: Integer; fontType: Integer; fontSize: Integer;
  offSet: Integer): Integer;
function AddQRCode(rotate: Integer; xPos: Integer; yPos: Integer;
  model: Integer; unitWidth: Integer; eccLevel: Integer; data: ansistring): Integer;
function AddPDF417(rotate: Integer; xPos: Integer; yPos: Integer;
  xDots: Integer; yDots: Integer; columns: Integer; rows: Integer;
  eccLevel: Integer; data: ansistring): Integer;
function AddBox(xPos: Integer; yPos: Integer; endXPos: Integer;
  endYPos: Integer; thickness: Integer): Integer;
function AddLine(xPos: Integer; yPos: Integer; endXPos: Integer;
  endYPos: Integer; thickness: Integer): Integer;
function AddImage(rotate: Integer; xPos: Integer; yPos: Integer;
  imagePath: ansistring): Integer;
function SetFontSize(width: Integer; height: Integer): Integer;
function SetDensity(density: Integer): Integer;
function SetSpeed(speed: Integer): Integer;
function SetTextSpacing(spacing: Integer): Integer;
function SetLeftMargin(margin: Integer): Integer;
function SetTextBold(bold: Integer): Integer;
function SetTextUnderline(underline: Integer): Integer;
function Abort(): Integer;
function DemPrint(): Integer;
function NextLabelPos(): Integer;
function PreFeed(distance: Integer): Integer;
function PostFeed(distance: Integer): Integer;

var
  //Rotate
  ROTATE_NONE :Integer=0;
  ROTATE_90 :Integer=1;
  ROTATE_180 :Integer=2;
  ROTATE_270 :Integer=3;
  // BarCode Type
  SYMBOL_128: Integer = 0;
  SYMBOL_128A: Integer = 1;
  SYMBOL_128B: Integer = 2;
  SYMBOL_128C: Integer = 3;
  SYMBOL_128E: Integer = 4;
  SYMBOL_39: Integer = 5;
  SYMBOL_39C: Integer = 6;
  SYMBOL_93: Integer = 7;
  SYMBOL_CODEBAR: Integer = 8;
  SYMBOL_CODEBAR16: Integer = 9;
  SYMBOL_EAN13: Integer = 10;
  SYMBOL_EAN132: Integer = 11;
  SYMBOL_EAN135: Integer = 12;
  SYMBOL_EAN8: Integer = 13;
  SYMBOL_EAN82: Integer = 14;
    Result: Integer = -1;
  // Error Code
  E_SUCCESS: Integer = 0;
  E_BAD_HANDLE: Integer = -6;

  // ecc level
  ECC_LEVEL_L:Integer=0;
  ECC_LEVEL_M:Integer=1;
  ECC_LEVEL_Q:Integer=2;
  ECC_LEVEL_H:Integer=3;


  // printer
  printer: Pointer;
  errorNo: Integer = 0;

implementation

function PrinterCreator(printer: PPointer; model: ansistring): Integer; cdecl;
  external 'CPCL_SDK.dll';
function PrinterCreatorS(model: string): Pointer; cdecl;
  external 'CPCL_SDK.dll';
function PortOpen(printer: Pointer; portSetting: ansistring): Integer; cdecl;
  external 'CPCL_SDK.dll';
function PortClose(printer: Pointer): Integer; cdecl; external 'CPCL_SDK.dll';
function PrinterDestroy(printer: Pointer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function DerectIO(printer: Pointer; writedata: PByte; writeNum: Integer;
  readdata: PByte; readNum: Integer; var preadNum: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';

function CPCL_AddLabel(printer: PPointer; offSet: Integer; height: Integer;
  qty: Integer): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_SetAlign(printer: PPointer; align: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_AddText(printer: PPointer; rotate: Integer; fontType: Integer;
  fontSize: Integer; xPos: Integer; yPos: Integer; data: ansistring): Integer;
  cdecl; external 'CPCL_SDK.dll';
function CPCL_AddBarCode(printer: PPointer; rotate: Integer; codetype: Integer;
  width: Integer; ratio: Integer; height: Integer; xPos: Integer; yPos: Integer;
  data: ansistring): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_AddBarCodeText(printer: PPointer; enable: Integer;
  fontType: Integer; fontSize: Integer; offSet: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_AddQRCode(printer: PPointer; rotate: Integer; xPos: Integer;
  yPos: Integer; model: Integer; unitWidth: Integer; eccLevel: Integer;
  data: ansistring): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_AddPDF417(printer: PPointer; rotate: Integer; xPos: Integer;
  yPos: Integer; xDots: Integer; yDots: Integer; columns: Integer;
  rows: Integer; eccLevel: Integer; data: ansistring): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_AddBox(printer: PPointer; xPos: Integer; yPos: Integer;
  endXPos: Integer; endYPos: Integer; thickness: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_AddLine(printer: PPointer; xPos: Integer; yPos: Integer;
  endXPos: Integer; endYPos: Integer; thickness: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_AddImage(printer: PPointer; rotate: Integer; xPos: Integer;
  yPos: Integer; imagePath: ansistring): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_AddImageData(printer: PPointer; rotate: Integer;
  widthBytes: Integer; height: Integer; xPos: Integer; yPos: Integer;
  data: ansistring): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_SetFontSize(printer: PPointer; width: Integer; height: Integer)
  : Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_SetDensity(printer: PPointer; density: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_SetSpeed(printer: PPointer; speed: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_SetTextSpacing(printer: PPointer; spacing: Integer): Integer;
  cdecl; external 'CPCL_SDK.dll';
function CPCL_SetLeftMargin(printer: PPointer; margin: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_SetTextBold(printer: PPointer; bold: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_SetTextUnderline(printer: PPointer; underline: Integer): Integer;
  cdecl; external 'CPCL_SDK.dll';
function CPCL_Abort(printer: PPointer): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_Print(printer: PPointer): Integer; cdecl; external 'CPCL_SDK.dll';
function CPCL_NextLabelPos(printer: PPointer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_PreFeed(printer: PPointer; distance: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';
function CPCL_PostFeed(printer: PPointer; distance: Integer): Integer; cdecl;
  external 'CPCL_SDK.dll';

function DemPrinterCreator(model: ansistring): Integer;
begin
  printer := nil;
  errorNo := PrinterCreator(@printer, model);
  if (E_SUCCESS = errorNo) then
  begin
    Result := errorNo;
  end
  else
  begin
    Result := errorNo;
  end;
end;

function DemPortOpen(portSetting: ansistring): Integer;
begin
  if (printer <> PtrToNil) then
  begin
    Result := PortOpen(printer, portSetting);
  end
  else
  begin
    Result := E_BAD_HANDLE;
  end;
end;

function DemPortClose(): Integer;
begin
  Result := PortClose(printer);
  Result := PrinterDestroy(printer);
end;

function DemDerectIO(writedata: PByte; writeNum: Integer;
  readdata: PByte; readNum: Integer; var preadNum: Integer): Integer;
  BEGIN
        Result :=DerectIO(printer,writedata,writeNum,readdata,readNum,preadNum);
  END;

function AddLabel(offSet: Integer; height: Integer; qty: Integer): Integer;
begin
  Result := CPCL_AddLabel(printer, offSet, height, qty);
end;

function SetAlign(align: Integer): Integer;
begin
  Result := CPCL_SetAlign(printer, align);
end;

function AddText(rotate: Integer; fontType: Integer; fontSize: Integer;
  xPos: Integer; yPos: Integer; data: ansistring): Integer;
begin
  Result := CPCL_AddText(printer, rotate, fontType, fontSize, xPos,
    yPos, data);
end;

function AddBarCode(rotate: Integer; codetype: Integer; width: Integer;
  ratio: Integer; height: Integer; xPos: Integer; yPos: Integer;
  data: ansistring): Integer;
begin
  Result := CPCL_AddBarCode(printer, rotate, codetype, width, ratio, height,
    xPos, yPos, data);
end;

function AddQRCode(rotate: Integer; xPos: Integer; yPos: Integer;
  model: Integer; unitWidth: Integer; eccLevel: Integer; data: ansistring): Integer;
begin
  Result := CPCL_AddQRCode(printer, rotate, xPos, yPos, model, unitWidth,
    eccLevel, data);
end;

function AddBarCodeText(enable: Integer; fontType: Integer; fontSize: Integer;
  offSet: Integer): Integer;
begin
  Result := CPCL_AddBarCodeText(printer, enable, fontType, fontSize, offSet);
end;

function AddPDF417(rotate: Integer; xPos: Integer; yPos: Integer;
  xDots: Integer; yDots: Integer; columns: Integer; rows: Integer;
  eccLevel: Integer; data: ansistring): Integer;
begin
  Result := CPCL_AddPDF417(printer, rotate, xPos, yPos, xDots, yDots, columns,
    rows, eccLevel, data);
end;

function AddBox(xPos: Integer; yPos: Integer; endXPos: Integer;
  endYPos: Integer; thickness: Integer): Integer;
begin
  Result := CPCL_AddBox(printer, xPos, yPos, endXPos, endYPos, thickness);
end;

function AddLine(xPos: Integer; yPos: Integer; endXPos: Integer;
  endYPos: Integer; thickness: Integer): Integer;
begin
  Result := CPCL_AddLine(printer, xPos, yPos, endXPos, endYPos, thickness);
end;

function AddImage(rotate: Integer; xPos: Integer; yPos: Integer;
  imagePath: ansistring): Integer;
begin
  Result := CPCL_AddImage(printer, rotate, xPos, yPos, imagePath);
end;

function SetFontSize(width: Integer; height: Integer): Integer;
begin
  Result := CPCL_SetFontSize(printer, width, height);
end;

function SetDensity(density: Integer): Integer;
begin
  Result := CPCL_SetDensity(printer, density);
end;

function SetSpeed(speed: Integer): Integer;
begin
  Result := CPCL_SetSpeed(printer, speed);
end;

function SetTextSpacing(spacing: Integer): Integer;
begin
  Result := CPCL_SetTextSpacing(printer, spacing);
end;

function SetLeftMargin(margin: Integer): Integer;
begin
  Result := CPCL_SetLeftMargin(printer, margin);
end;

function SetTextBold(bold: Integer): Integer;
begin
  Result := CPCL_SetTextBold(printer, bold);
end;

function SetTextUnderline(underline: Integer): Integer;
begin
  Result := CPCL_SetTextUnderline(printer, underline);
end;

function Abort(): Integer;
begin
  Result := CPCL_Abort(printer);
end;

function DemPrint(): Integer;
begin
  Result := CPCL_Print(printer)
end;

function NextLabelPos(): Integer;
begin
  Result := CPCL_NextLabelPos(printer)
end;

function PreFeed(distance: Integer): Integer;
begin
  Result := CPCL_PreFeed(printer, distance);
end;

function PostFeed(distance: Integer): Integer;
begin
  Result := CPCL_PostFeed(printer, distance);
end;

end.
