line and paragraph spacing in print output

Posted on 1997-08-04
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
  • 2

Accepted Solution

davmarc earned 200 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 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

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
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…

821 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