Link to home
Start Free TrialLog in
Avatar of peetah
peetah

asked on

Delphi 5 - formatting text onto a page

I am very much a beginner programmer using Delphi5.  The app I am trying to complete is to create a graphical representation of a label before it is copied to a text file and sent to a novell print queue.  The user has up to 7 individual lines that they can choose to have text on and for each of those lines, they can have 1 of 5 text styles; be centred, l/j or r/j; and have different text widths and heights.  What I need is a way of stretching the text for the display.  I have tried using the text as a label, but have had no luck displaying it properly.  The only other thought that I have is to create each line as a bitmap, and then using some form of stretching it to size.

Any other thoughts would be most appreciated.  I can email the project to anybody who wants to see what I am actually doing.

REMEMBER TO SPEAK SLOWLY AND CLEARLY AS I AM A NEWBIE!!

Many thanks
Peter
Avatar of Kunfufaresi
Kunfufaresi

Hello,

You can do it by creating a canvas then use textout to write text on it and later save it as bitmap or whatever format you need.

Kunfu Faresi
--snip--
var
  Bitmap : tbitmap;

begin
  Bitmap := TBitmap.Create;

  Bitmap.Width := 300;
  Bitmap.Height := 100;
 
  Bitmap.Canvas.Font.Name  := 'Arial';
  Bitmap.Canvas.Font.Color := RGB(0,255,0);
  Bitmap.Canvas.Font.Style := [];
  Bitmap.Canvas.Font.Style + [fsBold];
//  Bitmap.Canvas.Font.Style + [fsItalic];  you can use some "if ..then" to add these styles
//  Bitmap.Canvas.Font.Style + [fsUnderline];
  Bitmap.Canvas.Font.Size := 12;
  Bitmap.Canvas.brush.Style := bsClear; // make it transparent background if you want text to be on top of image
  Bitmap.Canvas.TextOut(Rect( 10, 10, ' Hello World!');
  Bitmap.SaveToFile('c:\temp.bmp');
end;
--snip--  

This should do it. Write one line of text into a bitmap, just increase the font size and initial size of graphic to get higher resolution. screens are ususally 72-75dpi, so you can do the math of 17" screen with 1024 resolution about how much you need for a 300dpi printing. the font size can be doubled the same way, if you want 12dpi on 72 then it should be around 48 on 300 dpi, and image width should be 1200 for this example.

Kunfu Faresi
Also about alignment, you would have to use TextRect instead of textOut. Also you will need to to get width using TextExtent function, then you can center for instance by saying disply x position of text is (width of paper/2)-(width of text/2), left align is just make x=1, and right align is x=width of paper - width of text
Avatar of peetah

ASKER

The problem that I have is that the user may choose to increase the width of the font, but not the height.  I am writing to a text file (simple writeln) to be interpreted by the printer using EPL1 print language.  The format of the output file is:

Ap1,p2,p3,p4,p5,p6,p7,"TEXT"

A is a constant
p1 is x position on the label (to be calculated by the app depending on font, width, and alignment)
p2 is y position on the label (to be calculated by the app depending on top of the previous line - height of previous text - line spacer)
p3 is rotation (not changed in my app)
p4 is font selection 1 = 12x20 dots }
                            2 = 16x28        }
                            3 = 20x36        }  All fonts are fixed size, not proportional.
                            4 = 24x44        }
                            5 = 48x80        }
p5 is width multiplier (1-6)
p6 is vertical multiplier (1-9)
p7 is normal or reversed text
"TEXT" is the text from the TEdit field

As an example a line may be:

Axxx,yyy,0,2,2,3,"Hello"

This means that the characters are going to be 32x84 (font 2 16x28, width multiplier 2, height multiplier 3).

Each line could be different and the problem is in the drawing of the label reflecting this.  If it was a DOS app, then the screen font is pretty easy, but it is trying to do it under Windows without creating a new font.

I hope I have expanded what I need properly.

Peter
Avatar of peetah

ASKER

Just re-read it again - what I need a way of representing the font with different sizes and alignments on the screen only - in a kind of MS Office 'Print Preview'.  When it prints, it doesn't use printer drivers, but saves it as a text-file with each line as Ap1,p2,p3,p4,p5,p6,p6"TEXT" and copies it to the print queue.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peetah

ASKER

Whew!

It's going to take me a while to digest this!  When I follow it fully I will respond.

Many, many thanks
Peter