[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

line and paragraph spacing in print output

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
  • 2
1 Solution
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.

veltkampAuthor Commented:
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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now