Solved

line and paragraph spacing in print output

Posted on 1997-08-04
3
292 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
[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
3 Comments
 
LVL 4

Accepted Solution

by:
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.

0
 

Author Comment

by:veltkamp
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
   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
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.


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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