Solved

Need an example for SetTextJustification API call

Posted on 1998-06-12
2
822 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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