Solved

line and paragraph spacing in print output

Posted on 1997-08-04
3
276 Views
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
0
Comment
Question by:veltkamp
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
davmarc earned 200 total points
Comment Utility
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.

0
 

Author Comment

by:veltkamp
Comment Utility
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
   TEXTMETRIC tm;
   pDC->GetTextMetrics(&tm);
   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

Thanks,
Dave Veltkamp
   
0
 
LVL 4

Expert Comment

by:davmarc
Comment Utility
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.


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

13 Experts available now in Live!

Get 1:1 Help Now