?
Solved

Figuring out preview font size

Posted on 2003-11-23
7
Medium Priority
?
712 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
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…
Suggested Courses

650 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