Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need an example for SetTextJustification API call

Posted on 1998-06-12
2
Medium Priority
?
843 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 1200 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

670 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