From 0a4d094a388af995bda9c10ed29ae151a6585c17 Mon Sep 17 00:00:00 2001 From: alexsch Date: Mon, 23 Jul 2012 17:41:43 +0400 Subject: [PATCH] 7185512: The printout doesn't match image on screen. Reviewed-by: serb, bagiras --- .../native/sun/windows/awt_TextArea.cpp | 37 +--------------- .../native/sun/windows/awt_TextComponent.cpp | 44 +++++++++++++++++++ .../native/sun/windows/awt_TextComponent.h | 1 + 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/windows/native/sun/windows/awt_TextArea.cpp b/src/windows/native/sun/windows/awt_TextArea.cpp index dd56f2357..829e03a87 100644 --- a/src/windows/native/sun/windows/awt_TextArea.cpp +++ b/src/windows/native/sun/windows/awt_TextArea.cpp @@ -131,48 +131,13 @@ AwtTextArea::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { MsgRouting mr = mrDoDefault; switch (message) { - case WM_PRINTCLIENT: - { - FORMATRANGE fr; - HDC hPrinterDC = (HDC)wParam; - int nHorizRes = ::GetDeviceCaps(hPrinterDC, HORZRES); - int nVertRes = ::GetDeviceCaps(hPrinterDC, VERTRES); - int nLogPixelsX = ::GetDeviceCaps(hPrinterDC, LOGPIXELSX); - int nLogPixelsY = ::GetDeviceCaps(hPrinterDC, LOGPIXELSY); - - // Ensure the printer DC is in MM_TEXT mode. - ::SetMapMode ( hPrinterDC, MM_TEXT ); - - // Rendering to the same DC we are measuring. - ::ZeroMemory(&fr, sizeof(fr)); - fr.hdc = fr.hdcTarget = hPrinterDC; - // Set up the page. - fr.rcPage.left = fr.rcPage.top = 0; - fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440; // in twips - fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440; - fr.rc.left = fr.rcPage.left; - fr.rc.top = fr.rcPage.top; - fr.rc.right = fr.rcPage.right; - fr.rc.bottom = fr.rcPage.bottom; - - // start printing from the first visible line - LRESULT nLine = SendMessage(EM_GETFIRSTVISIBLELINE, 0, 0); - LONG startCh = static_cast(SendMessage(EM_LINEINDEX, - (WPARAM)nLine, 0)); - fr.chrg.cpMin = startCh; - fr.chrg.cpMax = -1; - - SendMessage(EM_FORMATRANGE, TRUE, (LPARAM)&fr); - } - - break; case EM_SETCHARFORMAT: case WM_SETFONT: SetIgnoreEnChange(TRUE); break; } - retValue = AwtComponent::WindowProc(message, wParam, lParam); + retValue = AwtTextComponent::WindowProc(message, wParam, lParam); switch (message) { case EM_SETCHARFORMAT: diff --git a/src/windows/native/sun/windows/awt_TextComponent.cpp b/src/windows/native/sun/windows/awt_TextComponent.cpp index 5ba2efca8..f16ba6c34 100644 --- a/src/windows/native/sun/windows/awt_TextComponent.cpp +++ b/src/windows/native/sun/windows/awt_TextComponent.cpp @@ -215,6 +215,50 @@ done: return c; } +LRESULT +AwtTextComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { + + switch (message) { + case WM_PRINTCLIENT: + { + FORMATRANGE fr; + HDC hPrinterDC = (HDC)wParam; + int nHorizRes = ::GetDeviceCaps(hPrinterDC, HORZRES); + int nVertRes = ::GetDeviceCaps(hPrinterDC, VERTRES); + int nLogPixelsX = ::GetDeviceCaps(hPrinterDC, LOGPIXELSX); + int nLogPixelsY = ::GetDeviceCaps(hPrinterDC, LOGPIXELSY); + + // Ensure the printer DC is in MM_TEXT mode. + ::SetMapMode ( hPrinterDC, MM_TEXT ); + + // Rendering to the same DC we are measuring. + ::ZeroMemory(&fr, sizeof(fr)); + fr.hdc = fr.hdcTarget = hPrinterDC; + // Set up the page. + fr.rcPage.left = fr.rcPage.top = 0; + fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440; // in twips + fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440; + fr.rc.left = fr.rcPage.left; + fr.rc.top = fr.rcPage.top; + fr.rc.right = fr.rcPage.right; + fr.rc.bottom = fr.rcPage.bottom; + + // start printing from the first visible line + LRESULT nLine = SendMessage(EM_GETFIRSTVISIBLELINE, 0, 0); + LONG startCh = static_cast(SendMessage(EM_LINEINDEX, + (WPARAM)nLine, 0)); + fr.chrg.cpMin = startCh; + fr.chrg.cpMax = -1; + + SendMessage(EM_FORMATRANGE, TRUE, (LPARAM)&fr); + } + + break; + } + + return AwtComponent::WindowProc(message, wParam, lParam); +} + LONG AwtTextComponent::EditGetCharFromPos(POINT& pt) { return static_cast(SendMessage(EM_CHARFROMPOS, 0, reinterpret_cast(&pt))); diff --git a/src/windows/native/sun/windows/awt_TextComponent.h b/src/windows/native/sun/windows/awt_TextComponent.h index 118b9743b..e50219cd2 100644 --- a/src/windows/native/sun/windows/awt_TextComponent.h +++ b/src/windows/native/sun/windows/awt_TextComponent.h @@ -50,6 +50,7 @@ public: static AwtTextComponent* Create(jobject self, jobject parent, BOOL isMultiline); virtual LPCTSTR GetClassName(); + LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); int RemoveCR(WCHAR *pStr); -- GitLab