Re: [Gambas-user] Example for printing on printer
Brought to you by:
gambas
From: <eil...@t-...> - 2004-06-14 13:58:13
|
Hello Hans-Martin, look at this code. It's not ready, you will have to convert the string into ASCII before being able to print öäü etc. (with convert$, see my discussion with Benoit). And it's from a typewriting app I am writing currently, so don't be surprised about the specialties.... :-) Grüße Rolf SUB DruckenText() DIM t$ AS String DIM x$ AS String DIM i AS Integer DIM meldung AS Integer IF NOT angefangen THEN RETURN randOben = 300 randLinks = 300 draw.Begin(printer) IF gestoppt THEN 'Kopfzeile mit den Angaben drucken draw.font.Name = "Courier" draw.font.Size = 11 draw.font.Bold = TRUE draw.Text(DruckenKopf$(), randLinks, randOben/2) draw.Line(randLinks, randOben, printer.Width-(randLinks*2),randOben) END IF draw.Font.Name = "Courier" draw.Font.Size = 12 draw.Font.Bold = FALSE druckZhoehe = draw.TextHeight("gO") zeilenBreite = 65 t$ = TextArea1.Text druckZeile = 0 FOR i = 1 TO Len(t$) SELECT CASE Asc(Mid$(t$,i,1)) CASE 10 DruckenAbsatz(x$) x$="" CASE ELSE x$ = x$ & Mid$(t$,i,1) END SELECT NEXT IF Len(x$) > 0 THEN DruckenAbsatz(x$) END IF draw.End END PRIVATE SUB DruckenAbsatz(text$ AS String) DIM x$ AS String DIM po AS Integer DIM x AS Integer IF Len(text$) <= 67 THEN INC druckZeile DruckenZeilennummer(druckZeile) draw.Text(text$, randLinks, randOben + (druckZeile * DruckZhoehe) ) ELSE DO x$ = Left$(text$, 67) 'erstmal abschneiden IF Len(text$) <= 67 THEN 'ein Rest ist geblieben: 'Rest so drucken: INC druckZeile DruckenZeilennummer(druckZeile) draw.Text(x$, randLinks, randOben + (druckZeile * DruckZhoehe) ) 'Absatz zu Ende RETURN END IF IF Mid$(text$, 68, 1) = " " THEN 'ein Leerzeichen folgt: 'gleich drucken INC druckZeile DruckenZeilennummer(druckZeile) draw.Text(x$, randLinks, randOben + (druckZeile * DruckZhoehe) ) 'vorn abschneiden text$ = Right$(text$, -67) 'nÀchsten Wortanfang suchen DO IF Left$(text$, 1) = " " THEN text$ = Right$(text$, -1) END IF LOOP UNTIL Left$(text$, 1) <> " " ELSE IF Right$(x$, 1)= " " THEN 'ein Leerzeichen ist am Ende: 'gleich drucken INC druckZeile DruckenZeilennummer(druckZeile) draw.Text(x$, randLinks, randOben + (druckZeile * DruckZhoehe) ) 'vorn abschneiden text$ = Right$(text$, -67) 'nÀchsten Wortanfang suchen DO IF Left$(text$, 1) = " " THEN text$ = Right$(text$, -1) END IF LOOP UNTIL Left$(text$, 1) <> " " ELSE 'kein Leerzeichen, Wort: 'zurÃŒckgehen bis Leerzeichen po=67 DO WHILE po > 0 DEC po LOOP UNTIL Mid$(text$, po, 1) = " " IF po=0 THEN 'kein Leerzeichen gefunden: 'gleich drucken INC druckZeile DruckenZeilennummer(druckZeile) draw.Text(x$, randLinks, randOben + (druckZeile * DruckZhoehe) ) 'vorn abschneiden text$ = Right$(text$, -67) ELSE 'Leerzeichen gefunden: 'bis dahin abschneiden x$=Left$(text$, po) 'das StÃŒck drucken INC druckZeile DruckenZeilennummer(druckZeile) draw.Text(x$, randLinks, randOben + (druckZeile * DruckZhoehe) ) 'das StÃŒck abschneiden text$ = Mid$(text$, po+1) END IF END IF LOOP END IF END SUB DruckenZeilennummer(zeile AS Integer) draw.font.Size = 10 draw.Text(CStr(druckZeile), randLinks/2, randOben + (druckZeile * DruckZhoehe) + 5 ) draw.font.Size = 12 END FUNCTION DruckenKopf$() AS String DIM t$ AS String INC KopieNr IF KopieNr > 1 THEN t$="Kopie " & Str$(KopieNr) & " - " END IF t$ = t$ & Tippername$ & " [" t$ = t$ & CStr(Now) & "] " RETURN t$ END |