titz
asked on
printing diffent fonts in one line
hi,
i have the following problem in D3 under WIN95 /98:
i will print some text, which consists of
different fonts, in one line.
i tried to care for the different text-height,
but the whole text doesn't stand in one line.
The diffence is very large by changing between fonts of
different pitch : variable and fixed.
below is an (simple) example for what i mean.
in the end should be printed in one(!!) line
ABCDEFABCDEF .
But the second part stands a little bit heigher
than the first.
var
a,b:Pchar;
fo1,fo2:Tfont;
il1,il2:integer;
ih1,ih2:integer;
size:Tsize;
x,y:integer;
zz:shortstring;
begin
a:='ABCDEF';
b:='ABCDEF';
fo1:=Tfont.create;
fo1.name:='Times';
fo1.size:=60;
fo1.pitch:=fpvariable;
fo2:=Tfont.create;
fo2.name:='COURIER';
fo2.size:=60;
fo2.pitch:=fpfixed;
x:=100;
y:=200;
printer.BeginDoc;
selectobject(printer.canva s.handle,f o1.handle) ;
gettextextentpoint32(print er.canvas. handle,a,s trlen(a),s ize);
il1:=size.cx;
ih1:=size.cy;
zz:=strpas(a);
printer.canvas.textout(x,y ,zz);
x:=x+il1;
selectobject(printer.canva s.handle,f o2.handle) ;
gettextextentpoint32(print er.canvas. handle,b,s trlen(b),s ize);
il2:=size.cx;
ih2:=size.cy;
zz:=strpas(b);
y:=y+ih1-ih2;
printer.canvas.textout(x,y ,zz);
printer.enddoc;
fo1.free;
fo2.free;
end;
What is the reason and what can i do ??
thanks
titz
i have the following problem in D3 under WIN95 /98:
i will print some text, which consists of
different fonts, in one line.
i tried to care for the different text-height,
but the whole text doesn't stand in one line.
The diffence is very large by changing between fonts of
different pitch : variable and fixed.
below is an (simple) example for what i mean.
in the end should be printed in one(!!) line
ABCDEFABCDEF .
But the second part stands a little bit heigher
than the first.
var
a,b:Pchar;
fo1,fo2:Tfont;
il1,il2:integer;
ih1,ih2:integer;
size:Tsize;
x,y:integer;
zz:shortstring;
begin
a:='ABCDEF';
b:='ABCDEF';
fo1:=Tfont.create;
fo1.name:='Times';
fo1.size:=60;
fo1.pitch:=fpvariable;
fo2:=Tfont.create;
fo2.name:='COURIER';
fo2.size:=60;
fo2.pitch:=fpfixed;
x:=100;
y:=200;
printer.BeginDoc;
selectobject(printer.canva
gettextextentpoint32(print
il1:=size.cx;
ih1:=size.cy;
zz:=strpas(a);
printer.canvas.textout(x,y
x:=x+il1;
selectobject(printer.canva
gettextextentpoint32(print
il2:=size.cx;
ih2:=size.cy;
zz:=strpas(b);
y:=y+ih1-ih2;
printer.canvas.textout(x,y
printer.enddoc;
fo1.free;
fo2.free;
end;
What is the reason and what can i do ??
thanks
titz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also consider printing through the TRichEdit component which seems to take care of the baseline problem.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
PrintButton: TButton;
procedure PrintButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.PrintButtonClick(Se nder: TObject);
var fo1, fo2 : TFont;
begin
//Font 1
fo1:=TFont.Create;
fo1.name:='Times';
fo1.size:=60;
fo1.pitch:=fpvariable;
//Font 2
fo2:=TFont.Create;
fo2.name:='COURIER';
fo2.size:=60;
fo2.pitch:=fpfixed;
with RichEdit1 do
begin
RichEdit1.Lines.Add('ABCDE FABCDEF');
//Change the first ABCDEF to font 1
SelStart := 0;
SelLength := 6;
SelAttributes.Assign(fo1);
//Change the second ABCDEF to font 2
SelStart := 6;
SelLength := 6;
SelAttributes.Assign(fo2);
//Print the text
Print('Document Title');
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
PrintButton: TButton;
procedure PrintButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.PrintButtonClick(Se
var fo1, fo2 : TFont;
begin
//Font 1
fo1:=TFont.Create;
fo1.name:='Times';
fo1.size:=60;
fo1.pitch:=fpvariable;
//Font 2
fo2:=TFont.Create;
fo2.name:='COURIER';
fo2.size:=60;
fo2.pitch:=fpfixed;
with RichEdit1 do
begin
RichEdit1.Lines.Add('ABCDE
//Change the first ABCDEF to font 1
SelStart := 0;
SelLength := 6;
SelAttributes.Assign(fo1);
//Change the second ABCDEF to font 2
SelStart := 6;
SelLength := 6;
SelAttributes.Assign(fo2);
//Print the text
Print('Document Title');
end;
end;
end.
Sorry for submitting my comment twice :-)
ASKER
thanks roadrunner,
that was what i was looking for !
titz
that was what i was looking for !
titz
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
PrintButton: TButton;
procedure PrintButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.PrintButtonClick(Se
var fo1, fo2 : TFont;
begin
//Font 1
fo1:=TFont.Create;
fo1.name:='Times';
fo1.size:=60;
fo1.pitch:=fpvariable;
//Font 2
fo2:=TFont.Create;
fo2.name:='COURIER';
fo2.size:=60;
fo2.pitch:=fpfixed;
with RichEdit1 do
begin
RichEdit1.Lines.Add('ABCDE
//Change the first ABCDEF to font 1
SelStart := 0;
SelLength := 6;
SelAttributes.Assign(fo1);
//Change the second ABCDEF to font 2
SelStart := 6;
SelLength := 6;
SelAttributes.Assign(fo2);
//Print the text
Print('Document Title');
end;
end;
end.