Solved

Figuring out preview font size

Posted on 2003-11-23
7
704 Views
Last Modified: 2013-12-03
HI there,

I'm working on a report designer. Here's the problem:

the user chooses a paper format A4 (210mm by 297mm)
the user places a text "Test1" on the paper.
the user specifies that the text shuld be shown with Times New Roman size 10.
the user zooms the paper, making the width of paper 420 pixles.

My question is now - how many pixels wide should the text be  ?

best regards
NetGeek
0
Comment
Question by:NetGeek
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 9822978
You can let windows do the scaling of things when you use function like:

BOOL SetWindowExtEx(
    HDC hdc,      // handle of device context
    int nXExtent,      // new horizontal window extent  
    int nYExtent,      // new vertical window extent
    LPSIZE lpSize       // original window extent
   );

or SetViewPortExtEx

Regards Jacco
0
 

Author Comment

by:NetGeek
ID: 9823044
hmm, could you explain that in a bit more detail ? which values should i put as the different parameters ?

NetGeek
0
 
LVL 10

Accepted Solution

by:
Jacco earned 500 total points
ID: 9837579
It is even simpler when using metafiles. I cooked up a sample.

Try sizing the form.

Regards Jacco

procedure TForm1.FormCreate(Sender: TObject);
var
  sz: SIZE;
begin
  FMetafile := TMetafile.Create;
  FMetaFile.Width  := Printer.PageWidth;
  FMetaFile.Height := Printer.PageHeight;
  FCanvas := TMetafileCanvas.Create(FMetafile, Printer.Handle);
  FCanvas.Font.PixelsPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
  FCanvas.Brush.Color := clWhite;
  FCanvas.Brush.Style := bsSolid;
  FCanvas.Rectangle(0, 0, Printer.PageWidth, Printer.PageHeight);
  FCanvas.Font.Name := 'Times New Roman';
  FCanvas.Font.Size := 10;
  FCanvas.TextOut(10, 10, 'Font Size 10');
  FCanvas.Font.Name := 'Times New Roman';
  FCanvas.Font.Size := 36;
  FCanvas.TextOut(10, 100, 'Font Size 36');
  FCanvas.Font.Size := 72;
  FCanvas.TextOut(10, 400, 'Font Size 72');
  FCanvas.Brush.Color := clBlue;
  FCanvas.Brush.Style := bsSolid;
  FCanvas.Ellipse(200, 1000, 500, 1900);
  FCanvas.Free;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
  lRect: TRect;
  liOffset: Integer;
begin
  if (Width / Height) > (210 / 297) then
  begin
    // use full height center width
    liOffset := Width div 2 - Round(Height * 210 / 297) div 2;
    lRect := Rect(liOffset, 0, liOffset + Round(Height * 210 / 297), Height);
  end else begin
    // use full width center height
    liOffset := Height div 2 - Round(Width * 297 / 210) div 2;
    lRect := Rect(0, liOffset, Width, liOffset + Round(Width * 297 / 210));
  end;
  PaintBox1.Canvas.StretchDraw(lRect, FMetafile);
end;

procedure TForm1.btnSaveClick(Sender: TObject);
begin
  FMetaFile.SaveToFile('d:\wmf.wmf');
end;

procedure TForm1.btnPrintClick(Sender: TObject);
begin
  Printer.BeginDoc;
  Printer.Canvas.Draw(0, 0, FMetaFile);
  Printer.EndDoc;
end;
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:Jacco
ID: 9837603
Forgot to say:

Make a form with two buttons and a alClient PaintBox like this.

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    btnSave: TButton;
    btnPrint: TButton;
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
  private
    { Private declarations }
    FMetaFile: TMetafile;
    FCanvas: TMetafileCanvas;
  public
    { Public declarations }
  end;
0
 

Author Comment

by:NetGeek
ID: 9846514
looks very interesting, I'll check it out first thing monday morning

NetGeek
0
 

Author Comment

by:NetGeek
ID: 9849105
that was just perfect, you even wrote my preview funktion for me :)

Thank you very much
Net Geek
0
 
LVL 10

Expert Comment

by:Jacco
ID: 9851857
You are welcome :-) Thanks for the points. If you want to preview at for example 100 or 200 percent you can try using a TScrollBox setting the VertScrollBar.Range and HorzScrollBar.Range property to higher values and having a TPaintBox aligned alClient on it.

Regards Jacco
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now