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


line and paragraph spacing in print output

Posted on 1997-08-04
Medium Priority
Last Modified: 2013-11-20
I would like my printed output to handle variable line spacing (i.e.,leading) and paragraph spacing (extra blank space before and after each paragraph).  I am currently using a CEditView to handle the printing process.  I have looked at the CEditView source and think I could do this by adjusting the starting location of the textout rectangle but this seems unduly messy.  I also looked at adjusting the value of GetTextExtent but how do I poke a new TextExtent back into the GC?

I also looked at the code for the CPageInfo class in the book "MFC Extensions"(??) and that helped me with other aspects of the page layout but stopped short of providing guidence on spacing between lines and/or paragraphs.

The functionality I am looking for is similar to the way Word handles paragraph formating.  Any suggestions and pointers to code examples would be greatly appreciated.

Thanks for your time!
Dave Veltkamp
Question by:veltkamp
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

Accepted Solution

davmarc earned 600 total points
ID: 1303023
You might want to evaluate the possibility of printing through a CRichEditView, it has some support for paragraphs.

If you need more customizability you'll end up writing the GDI printing code yourself. In this case, the CEditView source code would be a good starting point - cut and paste what you need from the MFC sources and add the your code.
CPageInfo will not be of much help in my opinion.

A third option is to buy an OCX or similar providing full word processor features.

Davide Marcato.


Author Comment

ID: 1303024
Thanks...but my question is really directed at the details in how to implement spacing adjustments.

If we look at the CEditView implementation :

In CEditView::PrintInsideRect()
   // calculate text & tab metrics
   int cyChar = tm.tmHeight + tm.tmExternalLeading
 ? is this the best place to adjust the line spacing to give the
 ? option of having space other than the default between lines --
 ? For example: if I want double spaced lines do I do
 ?    int cyChar = tm.tmHeight + (2 * tm.tmExternalLeading);
 ? or is there some better way?

On paragraph spacing I think I need a little more help.  Specifically:
1) What is the default (i.e., standard) character used to       delineate paragraph breaks?
2) Assuming that my text is mostly "plain text" (only new line      char. at the end of paragraphs and not at end of each line),     can I just use the CEditView::EndOfLine and adjust (add space)
   when this is true?
   UINT nIndexEnd = EndOfLine(lpszText, nIndexStop, nIndex);
   if (nIndex == nIndexEnd)
      y += (cyChar + MyExtraParagraphSpace);
3) Is there a better way to do this?

Sorry I wasn't more specific in my original post...I didn't want to limit myself to the CEditView code if there was a better solution.

By the way, could you point me to a few commercial sources for word processing functionality tools that I could investigate

Dave Veltkamp

Expert Comment

ID: 1303025
Ok, I'll try to asnwer your points in more detail.

Yes, generally the height of a line is the sum of the height of the font chars and the external space between the current and the next line.
My suggested code is something like:
  float interlineSpaceFactor = 2.0; /* or what else */
  int cyChar = tm.tmHeight + interlineSpaceFactor * tm.tmExternalLeading;
Using a float value for the factor allows you to control better the amount of space between the lines. For the sake of completeness, define the factor as const if applicable.

1) I think there is not a real standard here. WordPad seems to use just the carriage-return, HTML uses <P> and </P>, Word IMO organizes the text in a more complicated fashion internally but starts from carriage-returns as well.

2) I didn't test it but it seems to me it could work. Give it a try and asnwer yourself.

3) In my opinion you could obtain more flexibility only with a much more complicated handling, redesigning the whole printing code...is it worth it? You are the only one who can answer.

CEditView maybe is not the best solution possible, but it provides a decent printing system with a reasonably low amount of code.

Commercial products: I saw VisualWriter (produced by Visual Components) some time ago and found it a very nice product. The latest version number is 3.0 and it is ditributed as an OCX.
In a local component store you'll certainly find other alternatives.

I wrote quite a long reply. I think I deserve a good grade now :-))

Davide Marcato.


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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

730 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