Solved

Need an example for SetTextJustification API call

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 86
creating manifest for my dll that called from activex 6 98
indy Tmemory stream non latin charcter issue 2 98
Performance of SQL statement 37 97
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

21 Experts available now in Live!

Get 1:1 Help Now