Autor Beitrag
binco
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Di 17.10.06 13:54 
Ich habe mir ein kleines Programm geschrieben, welches am ende eine kleine Zusammenfassung ausdruckt. Nachdem ich mich durch verschiedene Drucken-Tutorials gequält habe, kann ich endlich auch direkt aus meinem Programm drucken.
Das Problem ist nur, wenn ich mit Textwidth die Breite ermittel, gibt mir Textwidth einen falschen Wert zurück, wenn ich font.style:=[fsbold] setze.

kleine Auszug aus meinem Prog:

ausblenden volle Höhe Diese Prozedur druckt mir einen Fließtext mit Zeilenumbruch, Seitenwechsel und Hintergrund und Textfarbe, wobei das erste übergebene Wort FETT-gedruckt wird.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
procedure TfrMain.druckenmithintergrundundersteswortfett(var x,y:integer;zeilenhoehe,breite,randlinks:integer;hintergrund,text:TColor;wert:string);
var i,j:integer;
    rect:TRect;
    tmp:string;
begin
printer.Canvas.Brush.Color:=hintergrund;
printer.Canvas.Font.Height:=zeilenhoehe div 2;
printer.Canvas.Font.Color:=text;
printer.Canvas.Font.Style:=[fsbold];
rect:=bounds(x,y,breite-2*randlinks,-zeilenhoehe);
printer.Canvas.FillRect(rect);
j:=1;
for i:= 1 to length(wert) do
begin
  if (wert[i]=' ') or (i=length(wert)) then
  begin
    tmp:=copy(wert,j,i-j+1);
    if (printer.Canvas.TextWidth(tmp)+x)>= (breite-randlinks) then
    begin
    y:=y-zeilenhoehe;
    x:=randlinks;
    rect:=bounds(x,y,breite-2*randlinks,-zeilenhoehe);
    printer.Canvas.FillRect(rect);
    end;
    printer.Canvas.TextOut(x,y-zeilenhoehe div 4,tmp);
    x:=x+printer.Canvas.TextWidth(tmp);
    j:=i+1;
    printer.Canvas.Font.Style:=[]
  end;
end;
end;

Der Wert, der von Textwidth() zurückgegeben wird entspricht dem Font.style:=[] und damit wird der letzte Buchstabe des ersten Wortes halb überschrieben.

Die Forensuche hat mir leider auch nicht weitergeholfen, weil sich die einzelnen beiträge wiedersprochen haben und nicht allgemein und ausführlich genug waren, damit ICH diese Ideen und Vorschläge umsetzen kann.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 17.10.06 14:12 
Du setzt ja auch in der Schleife auf "printer.Canvas.Font.Style:=[] "

Vielleicht erst nach der Schleife aufrufen ?

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
binco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Di 17.10.06 14:18 
Nein, denn es soll ja nur das erste Wort Fett gedruckt werden. Und beim ersten Aufruf ist font.style:=[fsbold]. Und genau dort tritt dann das Problem auf.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 17.10.06 14:20 
Wenn ich das richtig verstehe,setzt Du aber schon nach dem ersten Buchstaben auf "Font.Style:=[] "

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
binco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Di 17.10.06 14:30 
eigentlich nach dem ersten Leerzeichen. Das erste Wort wird auch in Fett ausgedruckt. Das verwunderliche ist, dass das Problem nur mit einem Hardware-Drucker auftritt. Wenn ich meinen PDF995-Drucker verwende, habe ich das Problem nicht.
binco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 18.10.06 10:27 
Kann mir denn keiner Helfen??? Bitte es ist dringend...
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mi 18.10.06 12:08 
Also eigentlich brauchst Du das TextWidth doch gar nicht, oder ?

Ich hätte das mal so gemacht :

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
//Erstes Wort in der Zeile "Fett" + Zeilenumbruch
procedure Drucken (RechterRand, LinkerRand : Integer; TheText : String; Printer : TPrinter);

   function GetNextWord (theText : String; Position : Integer) : String;
   begin
     delete(theText,1,Position);
     Result := copy(theText,1,pos(' ',theText));
   end;

var ErstesWort : Boolean ;
    i : Integer;
begin
  ErstesWort := True;
  with Printer.Canvas do
  begin
    MoveTo(LinkerRand,printer.Canvas.PenPos.Y);
    for i := 1 to length(theText) do
    begin
      if (theText[i] = ' ') and (i > 1) then ErstesWort := False;
      if ErstesWort then Font.Style := Font.Style + [fsBold]
        else Font.Style := Font.Style -[fsBold];
      if PenPos.x + TextWidth(GetNextWord(theText,i)) > RechterRand then
      begin
        MoveTo(LinkerRand,PenPos.Y + TextHeight(theText));
        ErstesWort := True;
      end else
      TextOut(PenPos.x,PenPos.y,theText[i]);
    end;
  end;
end;

//und der Aufruf mit: (wobei printer ein Object vom Typ TPrinter ist und im 
//FormCreate instanziert wird

procedure TForm1.Button1Click(Sender: TObject);
var    TheText : String;
begin
 theText := 'Hallo wie geht''s ? hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo ';
  with printer do
  begin
    BeginDoc;
    Drucken(2000,200,theText,printer);
    EndDoc;
  end;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
binco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 18.10.06 18:22 
Du benutz ja auch Textwidth in Zeile 22. Probier der Quelltext bei dir mal aus und nimm als Schriftart Arial font.height=50 und als erstes Wort 'Trainingsanforderungen:' oder etwas in vergleichbarer Länge.

Trotzdem Danke für die Mühe...

binco
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Do 19.10.06 06:32 
Aber nicht zum Festlegen der Druckposition, sondern nur zum Messen, ob das nächste Wort noch in die Zeile passt !


Habe mal folgendes probiert !

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
theText := 'Trainingsanforderungen ? hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo hallo ';
  with printer do
  begin
    BeginDoc;
    canvas.Font.Name := 'Arial';
    canvas.Font.Size := 12;
    canvas.Font.Height := 50;
    Drucken(2000,200,theText,printer);
    EndDoc;
  end;


Wobei das Height das Size natürlich aufhebt !

Funktioniert !!

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
binco Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Do 19.10.06 20:06 
Dann erst mal vielen Dank... Ich werd das bei gelegenheit einbauen und testen. (Komm heut leider nicht mehr dazu)