Solved

Figuring out preview font size

Posted on 2003-11-23
7
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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