Solved

Need an example for SetTextJustification API call

Posted on 1998-06-12
2
816 Views
Last Modified: 2008-02-01
"The SetTextJustification function can be used to align a line that contains multiple runs in different fonts. In this case, the line must be created piecemeal by aligning and writing each run separately. " 

Can anyone give me an example for the above application of SetTextJustification ?!

Thanx in advance.

Levente
slv@mcse.hu
0
Comment
Question by:Levente
2 Comments
 
LVL 5

Accepted Solution

by:
inter earned 300 total points
ID: 1352522
Hi again,
As stated above single SetTextJustification call is not enough to adjust for text containing several different font sizes. Since we can select one FONT at a time on a canvas we should compute each runs length, number of spaces etc...Lets explore it with an example:

Suppose we have the following line (where the chars in [] will be bold and the others will be normal)
  Str := 'Hello this is normal [and this is bold]'
In this case we should first dive the string into to
  NormStr := 'Hello this is normal '
  BoldStr := '[and this is bold]'

  BreakCnt := CountBreaks(Str);
  // We should determine the length of each run seperately after applying font change
  NormLen := Canvas.TextWidth(NormStr);
  // Apply formatting for bold text and measure it
  Canvas.Font.Style := Canvas.Font.Style + [fsBold];
  BoldLen := Canvas.TextWidth(BoldStr);
  //restore
  Canvas.Font.Style := Canvas.Font.Style - [fsBold];
  //Now we have total length of the formatted text. Assuming that the WitdhOfLine is
  //known we can set and output the text
  SetTextJustification(Canvas.Handle, WidthOfLine - (NormLen+BoldLen), BreakCnt);
  // Output the normal text
  Canvas.TextOut(X,Y,NormStr);
  // before chaning style get new with of the previous text for computing starting point
  // corretly
  NormLen := Canvas.TextWidth(NormStr);
  Canvas.Font.Style := Canvas.Font.Style + [fsBold];
  Canvas.TextOut(X + NormLen, Y, BoldStr);
  // DONE!

Seems it is compicated. However, if we represent the lines and paragraphs with proper data structures(lists of objects etc) we can do this itteratively.

Regards, (there may be some mistakes above but the idea is there)
Igor
0
 

Author Comment

by:Levente
ID: 1352523
Hi Igor,

Thanx for your help. It works and it is great. Even more I understood the basic idea. Thanks for your work. Excelent.

Levente
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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