[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Figuring out preview font size

Posted on 2003-11-23
7
Medium Priority
?
713 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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
Course of the Month20 days, 2 hours left to enroll

872 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