Solved

Figuring out preview font size

Posted on 2003-11-23
7
706 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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