Knowledge Base Nr: 00111 laserdrucker.txt - http://www.swe-kaiser.de
Downloads:
PCL/HPGL Druckfunktionen zum Drucken mit Laserdruckern.
Waagerechte Textausgabe und Linien werden unterstützt.
Die Implementierung ist Oracle-Forms (PL/SQL) unter Linux.
Todo: - gedrehte Schriften
- verschiedene Schrifttypen
- 'Spiegelung' der Liniengrafik (Koordinatensystem wie Schrift)
- genauere Umrechnung von mm in andere Einheiten bzw. über Befehlssatz
- andere formate wie din a4
/********************************************/
/********* MODUL SPEZIFIKATION **************/
/********************************************/
PACKAGE PCL_SUPPORT IS
-- Koordinatensystem: links/unten = x/y = 0/0
FUNCTION PCL_Init(szFilename IN VARCHAR2, -- dateiname der druckdatei
nLandscape IN PLS_INTEGER) -- seitenorientierung 0:hoch 1:quer
RETURN PLS_INTEGER;
FUNCTION PCL_Close RETURN PLS_INTEGER; -- druckt die druckdatei
FUNCTION PCL_TextOut(nXPos IN NUMBER, -- x in mm
nYPos IN NUMBER, -- y in mm
szTxt IN VARCHAR2, -- text
nSize IN NUMBER, -- zeichengrösse in mm
nWidth IN NUMBER, -- strichstärke 1..8
nProp IN PLS_INTEGER) -- 0: nicht proportional 1: proportional
RETURN PLS_INTEGER;
FUNCTION PCL_BarcodeOut(nXPos IN NUMBER, -- x in mm
nYPos IN NUMBER, -- y in mm
szTxt IN VARCHAR2, -- barcode
nHeight IN NUMBER, -- hoehe barcode in mm
nDPI IN PLS_INTEGER) -- 300,150,100.75
RETURN PLS_INTEGER;
FUNCTION PCL_LineOut(nXPosFrom IN NUMBER,
nYPosFrom IN NUMBER,
nXPosTo IN NUMBER,
nYPosTo IN NUMBER,
nSize IN NUMBER)
RETURN PLS_INTEGER;
END;
/********************************************/
/********* MODUL IMLEMENTATION **************/
/********************************************/
PACKAGE BODY PCL_SUPPORT IS
-- modulglobale variablen:
v_filename VARCHAR2(256) := '-unbenannt-';
out_file TEXT_IO.FILE_TYPE;
-- modulinterne funktionen:
FUNCTION PCL_ToInch(nMM IN NUMBER)
RETURN PLS_INTEGER IS nInch PLS_INTEGER;
BEGIN
nInch := nMM * 28.35; -- mm in 1/720"
RETURN nInch;
END PCL_ToInch;
FUNCTION PCL_ToUnits(nMM IN NUMBER)
RETURN PLS_INTEGER IS nUnits PLS_INTEGER;
BEGIN
nUnits := nMM * 40; -- mm in 1/1016"
RETURN nUnits;
END PCL_ToUnits;
FUNCTION TO_PCL(nMM IN NUMBER)
RETURN VARCHAR2 IS sz VARCHAR2(10);
nInch NUMBER := 0;
BEGIN
nInch := PCL_ToInch(nMM);
sz := TO_CHAR(TRUNC(nInch));
RETURN sz;
END TO_PCL;
FUNCTION TO_HPGL(nMM IN NUMBER)
RETURN VARCHAR2 IS sz VARCHAR2(10);
nInch NUMBER := 0;
BEGIN
nInch := PCL_ToUnits(nMM);
sz := TO_CHAR(TRUNC(nInch));
RETURN sz;
END TO_HPGL;
FUNCTION TO_PT(nMM IN NUMBER)
RETURN VARCHAR2 IS sz VARCHAR2(10);
nPt NUMBER := 0;
BEGIN
/* anpassen!
if nMM < 2.0 then
nPt := 2;
elsif nMM < 4.0 then
nPt := 3;
elsif nMM < 6.0 then
nPT := 12;
elsif nMM < 15.0 then
nPT := 12;
elsif nMM < 20.0 then
nPT := 18;
elsif nMM < 40.0 then
nPT := 40;
else
sz := 'nSize nicht bekannt';
RETURN sz;
end if;
*/
sz := TO_CHAR(TRUNC(nMM*4.0)); --kommt grob hin
RETURN sz;
END TO_PT;
-- exportierte funktionen:
FUNCTION PCL_Init(szFilename IN VARCHAR2,
nLandscape IN PLS_INTEGER) -- seitenorientierung 0:hoch 1:quer
RETURN PLS_INTEGER IS RC PLS_INTEGER;
v_text VARCHAR2(128) := '';
BEGIN
v_filename := szFilename; --filename merken für barcodeausgabe und druckbefehl
v_text := 'E'; --reset
v_text := v_text || '(0N)0N'; --latin1 font (umlaute)
v_text := v_text || '&l' || TO_CHAR(nLandscape) || 'O'; --page-orientation
v_text := v_text || '&l26A'; --din A4
v_text := v_text || '&l20Z&l-320U'; --seitenraender
v_text := v_text || '*c5976Y*c213120X'; --seitengroesse
v_text := v_text || '(s4101T'; --schriftart CG TIMES
out_file := TEXT_IO.FOPEN(szFilename, 'w'); -- File öffnen
TEXT_IO.PUT(out_file, v_text);
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.NEW_LINE(out_file);
RETURN RC;
END PCL_Init;
FUNCTION PCL_Close RETURN PLS_INTEGER IS RC PLS_INTEGER;
v_text VARCHAR2(128) := '';
BEGIN
v_text := chr(12); --formfeed
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.PUT(out_file, v_text);
TEXT_IO.FCLOSE(out_file);
v_text := 'cp ./' || v_filename || ' /dev/lp0';
host (v_text, no_screen);
RETURN RC;
END PCL_Close;
FUNCTION PCL_TextOut(nXPos IN NUMBER,
nYPos IN NUMBER,
szTxt IN VARCHAR2,
nSize IN NUMBER, -- zeichengrösse in punkt 2..60
nWidth IN NUMBER, -- strichstärke 1..8
nProp IN PLS_INTEGER) -- 0: nicht proportional 1: proportional
RETURN PLS_INTEGER IS RC PLS_INTEGER;
v_text VARCHAR2(2048) := '';
BEGIN
v_text := '&a' || TO_PCL(nXPos) || 'H'; -- x
v_text := v_text || '&a' || TO_PCL(nYPos) || 'V'; -- y
v_text := v_text || '(s' || TO_CHAR(nProp) || 'P'; -- proportionalschrift
v_text := v_text || '(s' || TO_CHAR(nWidth) || 'B'; -- strichstärke
v_text := v_text || '(s' || TO_PT(nSize) || 'V'; -- zeichengrösse
v_text := v_text || szTxt;
TEXT_IO.PUT(out_file, v_text);
TEXT_IO.NEW_LINE(out_file);
RETURN RC;
END PCL_TextOut;
FUNCTION PCL_BarcodeOut(nXPos IN NUMBER, -- x in mm
nYPos IN NUMBER, -- y in mm
szTxt IN VARCHAR2, -- barcode
nHeight IN NUMBER, -- hoehe barcode in mm
nDPI IN PLS_INTEGER) -- 300,150,100.75
RETURN PLS_INTEGER IS RC PLS_INTEGER;
v_text VARCHAR2(128) := '';
BEGIN
TEXT_IO.FCLOSE(out_file); -- File für Ausgabe Barcode schliessen
--barcode mit host(code39) einfügen
v_text := 'code39 ' || v_filename || ' ' || szTxt;
v_text := v_text || ' ' || TO_CHAR(nXPos-5.0); --offset?!
v_text := v_text || ' ' || TO_CHAR(nYPos-5.0); --offset?!
v_text := v_text || ' ' || TO_CHAR(nHeight);
v_text := v_text || ' ' || TO_CHAR(nDPI);
host (v_text, no_screen);
out_file := TEXT_IO.FOPEN(v_filename, 'a'); -- File wieder öffnen
RETURN RC;
END PCL_BarcodeOut;
FUNCTION PCL_LineOut(nXPosFrom IN NUMBER,
nYPosFrom IN NUMBER,
nXPosTo IN NUMBER,
nYPosTo IN NUMBER,
nSize IN NUMBER)
RETURN PLS_INTEGER IS RC PLS_INTEGER;
v_text VARCHAR2(128) := '';
BEGIN
TEXT_IO.PUT(out_file, '%0B');
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.PUT(out_file, 'PW' || TO_CHAR(nSize, '0.99') || ',1;');
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.PUT(out_file, 'SP1;');
TEXT_IO.NEW_LINE(out_file);
--todo: 210 zum spiegeln entfernen
TEXT_IO.PUT(out_file, 'PA' || TO_HPGL(nXPosFrom) || ',' || TO_HPGL(210-nYPosFrom) || ';');
TEXT_IO.NEW_LINE(out_file);
--todo: 210 zum spiegeln entfernen
TEXT_IO.PUT(out_file, 'PD' || TO_HPGL(nXPosTo) || ',' || TO_HPGL(210-nYPosTo) || ';');
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.PUT(out_file, 'PU;');
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.PUT(out_file, '%0A');
TEXT_IO.NEW_LINE(out_file);
TEXT_IO.NEW_LINE(out_file);
RETURN RC;
END PCL_LineOut;
END;
/********************************************/
/********* ANWENDUNGSBEISPIEL ***************/
/********************************************/
begin
error := PCL_SUPPORT.PCL_INIT('Palkarte.dat',1); -- Dateinamen, 1=Quer/2=Hoch
-- Horizontale Linien
error := PCL_SUPPORT.PCL_LINEOUT(5,3,286,3,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(5,17,286,17,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(156,17,286,17,1.0);
error := PCL_SUPPORT.PCL_LINEOUT(5,36,156,36,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(5,60,156,60,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(5,69,286,69,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(156,69,286,69,1.0);
error := PCL_SUPPORT.PCL_LINEOUT(5,103,286,103,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(5,127,286,127,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(5,196,230,196,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(274,196,286,196,0.3);
-- Vertikale Linien
error := PCL_SUPPORT.PCL_LINEOUT(5,3,5,196,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(70,36,70,60,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(128,103,128,127,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(156,17,156,69,1.0);
error := PCL_SUPPORT.PCL_LINEOUT(212,127,212,196,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(286,3,286,196,0.3);
error := PCL_SUPPORT.PCL_LINEOUT(286,17,286,69,1.0);
-- Texte und Barcodes
error := PCL_SUPPORT.PCL_TEXTOUT(9,14,'Gummimischung',7,6,1); -- x-pos,y-pos,text/variable,höhe mm,strichstärke(1-8),1=proportional/0=nicht proportional
error := PCL_SUPPORT.PCL_TEXTOUT(216,13,'Palettenbegleitkarte',5,6,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,23,'Fertigungsauftragsnummer:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,30,v_fanr,5,0,1);
error := PCL_SUPPORT.PCL_BARCODEOUT(95,30,v_fanr,8,150); -- x-pos,y-pos,text,höhe mm,auflösung(300/150/100/75)dpi
error := PCL_SUPPORT.PCL_TEXTOUT(9,42,'Herstelldatum:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(72,42,'Verfalldatum:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,53,v_herstelldate,9,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(72,53,v_verfalldate,9,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(161,59,'In Prüfung',18,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,66,'Materialnummer:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(56,66,v_matnr,4,0,1);
error := PCL_SUPPORT.PCL_BARCODEOUT(95,67,v_matnr,6,150);
error := PCL_SUPPORT.PCL_TEXTOUT(9,75,'Materialbezeichnung:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,97,v_mischbez,17,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,122,v_matnr,15,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(130,108,'Chargen-',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(130,113,'nummer:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(194,123,'-',15,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(208,123,v_chnrn,15,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(215,138,'Kunde-Nr.:',4,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(244,140,v_kdnr,5,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(9,155,v_kdnam,15,0,1);
error := PCL_SUPPORT.PCL_TEXTOUT(232,208,v_aktdat,4,0,1);
error := PCL_SUPPORT.PCL_Close;
end;