15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Desperately seeking help with printing, HELP!

Donald C. Asonye -- donald@menudo.uh.edu
Tuesday, November 26, 1996

Environment: Visual C++ 4.0, Windows NT 3.51

Hi all,

I desperately need help with printing.  I posted my problems
here and the newsgroups, but I did not receive any response.

I am having lots of problems printing from an MDI application
with CEditView.  If the document has more than 720 lines, the
framework prints only some of the text.  It won't even display
blank pages.  If you have more than 2000 lines, it prints only
9 pages, and the rest of the document is printed as blank
pages.  However, all the text is viewable inside the view.
That is, the user can see everything.  The problem is with
printing and previewing.

I have managed to get some things working.  I have now
implemented my own printing.  Since the text that I display
contains tabs, I have to use CDC::TabbedTextOut() to get
things lined up.  I have tried using every mapping mode that I
can see.  The main problem now is that the text is coming out
larger than the font that I created.

// the following was done in OnInitialUpdate.
//m_nFontHeight is 12.
// call GetDC()
	m_fontDisplay.CreateFont(m_nFontHeight, 0, 0, 0, FW_BLACK,
	0, 0, 0, 
	0,0,0,0,
	FIXED_PITCH| FF_MODERN, 
	NULL);

SetFont(&m_fontDisplay);	  
pDC->SelectObject(&m_fontDisplay);
pDC->SetMapMode(MM_TEXT);

// dc released
// view is filled with text.

// view is ok, and text is displayed correctly.


// I set up a tab stop array.

In my OnPrint() function I have the following:

The mapping mode is MM_LOENGLISH; I tried many many others
with the same result.  Here is my output call:

pDC->TabbedTextOut(0,
		-(nHeight * nCurLine),
		strLine, // CString Object
		m_nTabStops, // = 7
		m_arrayTabs, // array of tabstops
		m_nOrigin);
// nHeight is tm.tmHeight + tm.tmExternalLeading;
// tm being a TEXTMETRIC variable and I called
// pDC->GetTextMetrics(&tm);

I have tried the above with and without the tabstop and origin
of 0.  All efforts failed.  The major problem is not with tabs.
The text that is printed is bigger than the font I specified.
I have tried creating a font in OnBeginPrinting() and deleting
the font in OnEndPrinting().  It all failed.  The font is just
like the font I created above, fixed font of height 12.  I
even tried:

m_pfontPrinter->CreateFont(12,0,0,0,FW_BLACK, // I ALSO TRIED FW_NORMAL
                        0,0,0, 
			DEFAULT_CHARSET, 
			OUT_CHARACTER_PRECIS, 
			CLIP_CHARACTER_PRECIS,
			DEFAULT_QUALITY,
			FIXED_PITCH | FF_MODERN,
			NULL); // I also tried "Courier New"

Then inside OnPrint() I called SelectObject:

CFont* pfontOld = pDC->SelectObject(m_pfontPrinter);
pDC->SetMapMode(MM_LOENGLISH);  // I tried other modes also

Called all my pDC->TabbedTextOut(...);

pDC->SelectObject(pfontOld);
// end of function.

It still did not work.  I get Output with text much larger
than point 12.  It comes out with lines being cut off.  If the
font would be the size that I want (the size that is used on
the view display), I would be done with this project.  What am
I doing wrong?  How can I get the font to be smaller.  

I am desperately seeking some help here, and I'd be greatful
to anyone who can help me with this.  Thanks in advance.

-- 
Donald
**************************************************
*  Cry if you wanna cry.  If it helps you see.   *
*  If it clears your eyes.  -Sound Garden        *
**************************************************
Email    :mailto:donald@uh.edu 
Samples  :ftp://ftp.hpc.uh.edu/pub/donald
WWW      :http://www.uh.edu/~dasonye



Mike Smolinski -- smolinsk@mpr.ca
Thursday, November 28, 1996

> 
> Environment: Visual C++ 4.0, Windows NT 3.51
> 
> Hi all,
> 
> I desperately need help with printing.  I posted my problems
> here and the newsgroups, but I did not receive any response.
> 
> I am having lots of problems printing from an MDI application
> with CEditView.  If the document has more than 720 lines, the
> framework prints only some of the text.  It won't even display
> blank pages.  If you have more than 2000 lines, it prints only
> 9 pages, and the rest of the document is printed as blank
> pages.  However, all the text is viewable inside the view.
> That is, the user can see everything.  The problem is with
> printing and previewing.
> 
> I have managed to get some things working.  I have now
> implemented my own printing.  Since the text that I display
> contains tabs, I have to use CDC::TabbedTextOut() to get
> things lined up.  I have tried using every mapping mode that I
> can see.  The main problem now is that the text is coming out
> larger than the font that I created.
> 
 
Have you tried the Logical TWIPS method?  It worked for me when I had a
similar sizing problem.  I can't remember all the details, but it is outlined
in the Petzold book called "Inside Visual C++ 1.5".

If you don't have access to this book, let me know and I'll post the 
information for you.

Hope this helps...

Mike

---
Give me ambiguity or give me something else.
---
	



dhpeek -- dhpeek@acslink.net.au
Saturday, November 30, 1996

----------
> From: Donald C. Asonye 
> Environment: Visual C++ 4.0, Windows NT 3.51
> 
> // the following was done in OnInitialUpdate.
> //m_nFontHeight is 12.
> // call GetDC()
> 	m_fontDisplay.CreateFont(m_nFontHeight, 0, 0, 0, FW_BLACK,
> 	0, 0, 0, 
> 	0,0,0,0,
> 	FIXED_PITCH| FF_MODERN, 
> 	NULL);
> 
> SetFont(&m_fontDisplay);	  
> pDC->SelectObject(&m_fontDisplay);
> pDC->SetMapMode(MM_TEXT);

MFC uses two different font objects, one for printing and another for
screen display. You should use SetPrinterFont() as well as SetFont(). You
are changing your display font, but the OnPrint() handler is using the
printer font, which you have not set to the new font.

Here's how I do it, and it works well:

if (m_fontPrint)
     m_fontPrint.DeleteObject();  // <<<<< you must do this

if (m_fontPrint.CreateFont(...) ) // add in your parameters
{
   // Always re-initialize before each printer font change
   // I have found that it fixes all sorts of strange effects
   SetPrinterFont(NULL);
   SetPrinterFont(&m_fontPrint);
}

Hope this helps,

My first posting to this list.
Dennis Peek 







Charles N. Johnson -- charlej9@mail.idt.net
Thursday, November 28, 1996

Donald:

Rather than CreateFont() did you try CreatePointFont()? Assuming that pDC
is the device context for your printer

BOOL success = m_pfontPrinter->CreatePointFont(120, "Arial", pDC);
if (success == TRUE)
{
	// do your work
}
else
{
	// trap errors here
}

[quote mode on...]

BOOL CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, CDC* pDC =
NULL);

	Return Value
Nonzero if successful, otherwise 0. 

	Parameters

nPointSize   
Requested font height in tenths of a point. (For instance, pass 120 to
request a 12-point font.) 

lpszFaceName   
A CString or pointer to a null-terminated string that specifies the
typeface name of the font. The length of this string must not exceed 30
characters. The Windows EnumFontFamilies function can be used to enumerate
all currently available fonts. If lpszFaceName is NULL, the GDI uses a
device-independent typeface. 

pDC   
Pointer to the CDC object to be used to convert the height in nPointSize to
logical units. If NULL, a screen device context is used for the conversion.

Remarks
This function provides a simple way to create a font of a specified
typeface and point size. It automatically converts the height in nPointSize
to logical units using the CDC object pointed to by pDC. When you finish
with the CFont object created by the CreatePointFont function, first select
the font out of the device context, then delete the CFont object.

[quote mode off...]

This would appear to let Win95/NT make the decisions about fonts, perhaps
this would simplify things?

But, then, what do *I* know...   :-)

Cheers--
Charles

----------
> From: Donald C. Asonye 
> To: mfc-l@netcom.com
> Subject: Desperately seeking help with printing, HELP!
> Date: Tuesday, November 26, 1996 8:45 PM
> 
> Environment: Visual C++ 4.0, Windows NT 3.51
> 
> Hi all,
> 
> I desperately need help with printing.  I posted my problems
> here and the newsgroups, but I did not receive any response.
> 
> I am having lots of problems printing from an MDI application
> with CEditView.  If the document has more than 720 lines, the
> framework prints only some of the text.  It won't even display
> blank pages.  If you have more than 2000 lines, it prints only
> 9 pages, and the rest of the document is printed as blank
> pages.  However, all the text is viewable inside the view.
> That is, the user can see everything.  The problem is with
> printing and previewing.
> 
> I have managed to get some things working.  I have now
> implemented my own printing.  Since the text that I display
> contains tabs, I have to use CDC::TabbedTextOut() to get
> things lined up.  I have tried using every mapping mode that I
> can see.  The main problem now is that the text is coming out
> larger than the font that I created.
> 
> // the following was done in OnInitialUpdate.
> //m_nFontHeight is 12.
> // call GetDC()
> 	m_fontDisplay.CreateFont(m_nFontHeight, 0, 0, 0, FW_BLACK,
> 	0, 0, 0, 
> 	0,0,0,0,
> 	FIXED_PITCH| FF_MODERN, 
> 	NULL);
> 
> SetFont(&m_fontDisplay);	  
> pDC->SelectObject(&m_fontDisplay);
> pDC->SetMapMode(MM_TEXT);
> 
> // dc released
> // view is filled with text.
> 
> // view is ok, and text is displayed correctly.
> 
> 
> // I set up a tab stop array.
> 
> In my OnPrint() function I have the following:
> 
> The mapping mode is MM_LOENGLISH; I tried many many others
> with the same result.  Here is my output call:
> 
> pDC->TabbedTextOut(0,
> 		-(nHeight * nCurLine),
> 		strLine, // CString Object
> 		m_nTabStops, // = 7
> 		m_arrayTabs, // array of tabstops
> 		m_nOrigin);
> // nHeight is tm.tmHeight + tm.tmExternalLeading;
> // tm being a TEXTMETRIC variable and I called
> // pDC->GetTextMetrics(&tm);
> 
> I have tried the above with and without the tabstop and origin
> of 0.  All efforts failed.  The major problem is not with tabs.
> The text that is printed is bigger than the font I specified.
> I have tried creating a font in OnBeginPrinting() and deleting
> the font in OnEndPrinting().  It all failed.  The font is just
> like the font I created above, fixed font of height 12.  I
> even tried:
> 
> m_pfontPrinter->CreateFont(12,0,0,0,FW_BLACK, // I ALSO TRIED FW_NORMAL
>                         0,0,0, 
> 			DEFAULT_CHARSET, 
> 			OUT_CHARACTER_PRECIS, 
> 			CLIP_CHARACTER_PRECIS,
> 			DEFAULT_QUALITY,
> 			FIXED_PITCH | FF_MODERN,
> 			NULL); // I also tried "Courier New"
> 
> Then inside OnPrint() I called SelectObject:
> 
> CFont* pfontOld = pDC->SelectObject(m_pfontPrinter);
> pDC->SetMapMode(MM_LOENGLISH);  // I tried other modes also
> 
> Called all my pDC->TabbedTextOut(...);
> 
> pDC->SelectObject(pfontOld);
> // end of function.
> 
> It still did not work.  I get Output with text much larger
> than point 12.  It comes out with lines being cut off.  If the
> font would be the size that I want (the size that is used on
> the view display), I would be done with this project.  What am
> I doing wrong?  How can I get the font to be smaller.  
> 
> I am desperately seeking some help here, and I'd be greatful
> to anyone who can help me with this.  Thanks in advance.
> 
> -- 
> Donald
> **************************************************
> *  Cry if you wanna cry.  If it helps you see.   *
> *  If it clears your eyes.  -Sound Garden        *
> **************************************************
> Email    :mailto:donald@uh.edu 
> Samples  :ftp://ftp.hpc.uh.edu/pub/donald
> WWW      :http://www.uh.edu/~dasonye



Carl Gunther -- cgunther@ix.netcom.com
Saturday, November 30, 1996

Sorry I don't have time for a more thorough reply, but,
if you want your printed fonts to look about the same height as
what's on the screen, the following code might help:

#define SCREEN_FONT_SIZE 12

CFont fixedFont;

if(pDC->IsPrinting()) {

  CMainFrame* pMainFrame = (CMainFrame *) (((CMyApp *) 								   
AfxGetApp())->m_pMainWnd);
  CDC* pMainDC = pMainFrame->GetWindowDC();
  int screenPixelsY = pMainDC->GetDeviceCaps(LOGPIXELSY);
  pMainFrame->ReleaseDC(pMainDC);
  int printFontSize = (SCREEN_FONT_SIZE * 			  		
pDC->GetDeviceCaps(LOGPIXELSY)) / screenPixelsY;
  fixedFont.CreateFont(-(printFontSize), 0, 0, 0, FW_NORMAL, FALSE, 
			FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
         	        CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
            	        FIXED_PITCH | FF_MODERN | TMPF_TRUETYPE, 			
"Courier New");
}
else {
  fixedFont.CreateFont(-(SCREEN_FONT_SIZE), 0, 0, 0, FW_NORMAL, FALSE, 
			FALSE, 0,
  	                ANSI_CHARSET, OUT_DEFAULT_PRECIS,
         	        CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
            	        FIXED_PITCH | FF_MODERN | TMPF_TRUETYPE, 		
"Courier New");
}




Donald C. Asonye wrote:
> 
> Environment: Visual C++ 4.0, Windows NT 3.51
> 
> Hi all,
> 
> I desperately need help with printing.  I posted my problems
> here and the newsgroups, but I did not receive any response.
> 
> I am having lots of problems printing from an MDI application
> with CEditView.  If the document has more than 720 lines, the
> framework prints only some of the text.  It won't even display
> blank pages.  If you have more than 2000 lines, it prints only
> 9 pages, and the rest of the document is printed as blank
> pages.  However, all the text is viewable inside the view.
> That is, the user can see everything.  The problem is with
> printing and previewing.
> 
> I have managed to get some things working.  I have now
> implemented my own printing.  Since the text that I display
> contains tabs, I have to use CDC::TabbedTextOut() to get
> things lined up.  I have tried using every mapping mode that I
> can see.  The main problem now is that the text is coming out
> larger than the font that I created.
> 
> // the following was done in OnInitialUpdate.
> //m_nFontHeight is 12.
> // call GetDC()
>         m_fontDisplay.CreateFont(m_nFontHeight, 0, 0, 0, FW_BLACK,
>         0, 0, 0,
>         0,0,0,0,
>         FIXED_PITCH| FF_MODERN,
>         NULL);
> 
> SetFont(&m_fontDisplay);
> pDC->SelectObject(&m_fontDisplay);
> pDC->SetMapMode(MM_TEXT);
> 
> // dc released
> // view is filled with text.
> 
> // view is ok, and text is displayed correctly.
> 
> // I set up a tab stop array.
> 
> In my OnPrint() function I have the following:
> 
> The mapping mode is MM_LOENGLISH; I tried many many others
> with the same result.  Here is my output call:
> 
> pDC->TabbedTextOut(0,
>                 -(nHeight * nCurLine),
>                 strLine, // CString Object
>                 m_nTabStops, // = 7
>                 m_arrayTabs, // array of tabstops
>                 m_nOrigin);
> // nHeight is tm.tmHeight + tm.tmExternalLeading;
> // tm being a TEXTMETRIC variable and I called
> // pDC->GetTextMetrics(&tm);
> 
> I have tried the above with and without the tabstop and origin
> of 0.  All efforts failed.  The major problem is not with tabs.
> The text that is printed is bigger than the font I specified.
> I have tried creating a font in OnBeginPrinting() and deleting
> the font in OnEndPrinting().  It all failed.  The font is just
> like the font I created above, fixed font of height 12.  I
> even tried:
> 
> m_pfontPrinter->CreateFont(12,0,0,0,FW_BLACK, // I ALSO TRIED FW_NORMAL
>                         0,0,0,
>                         DEFAULT_CHARSET,
>                         OUT_CHARACTER_PRECIS,
>                         CLIP_CHARACTER_PRECIS,
>                         DEFAULT_QUALITY,
>                         FIXED_PITCH | FF_MODERN,
>                         NULL); // I also tried "Courier New"
> 
> Then inside OnPrint() I called SelectObject:
> 
> CFont* pfontOld = pDC->SelectObject(m_pfontPrinter);
> pDC->SetMapMode(MM_LOENGLISH);  // I tried other modes also
> 
> Called all my pDC->TabbedTextOut(...);
> 
> pDC->SelectObject(pfontOld);
> // end of function.
> 
> It still did not work.  I get Output with text much larger
> than point 12.  It comes out with lines being cut off.  If the
> font would be the size that I want (the size that is used on
> the view display), I would be done with this project.  What am
> I doing wrong?  How can I get the font to be smaller.
> 
> I am desperately seeking some help here, and I'd be greatful
> to anyone who can help me with this.  Thanks in advance.
> 
> --
> Donald
> **************************************************
> *  Cry if you wanna cry.  If it helps you see.   *
> *  If it clears your eyes.  -Sound Garden        *
> **************************************************
> Email    :mailto:donald@uh.edu
> Samples  :ftp://ftp.hpc.uh.edu/pub/donald
> WWW      :http://www.uh.edu/~dasonye

-- 
Check out the extensive Website of the Labor/Community Strategy Center
at http://www.igc.apc.org/lctr/

Check out the Website of Songs for Social Change
at http://globalvisions.org/cl/sfsc/

Copyright 1996 Carl E. Gunther.  Permission to reproduce this message
in text form for not-for-profit purposes freely granted provided that 
the preceeding copyright notice is retained.





| Вернуться в корень Архива |