Solved

Need an example for SetTextJustification API call

Posted on 1998-06-12
2
812 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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now