Changeset 87745 in webkit
- Timestamp:
- May 31, 2011 12:21:39 PM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87744 r87745 1 2011-05-31 Robin Dunn <robin@alldunn.com> 2 3 Reviewed by Kevin Ollivier. 4 5 [wx] Implement printing support for wxWidgets 2.9.x and above. 6 7 https://bugs.webkit.org/show_bug.cgi?id=61796 8 9 * platform/graphics/GraphicsContext.h: 10 * platform/graphics/wx/FontWx.cpp: 11 (WebCore::Font::drawGlyphs): 12 * platform/graphics/wx/GraphicsContextWx.cpp: 13 (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate): 14 (WebCore::GraphicsContext::drawRect): 15 (WebCore::GraphicsContext::drawLine): 16 (WebCore::GraphicsContext::drawEllipse): 17 (WebCore::GraphicsContext::strokeArc): 18 (WebCore::GraphicsContext::drawConvexPolygon): 19 (WebCore::GraphicsContext::fillRect): 20 (WebCore::GraphicsContext::drawLineForText): 21 (WebCore::GraphicsContext::scale): 22 (WebCore::GraphicsContext::currentScale): 23 * platform/wx/wxcode/win/non-kerned-drawing.cpp: 24 (WebCore::drawTextWithSpacing): 25 1 26 2011-05-31 Joseph Pecoraro <joepeck@webkit.org> 2 27 -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r87336 r87745 473 473 474 474 #if PLATFORM(WX) 475 // This is needed because of a bug whereby getting an HDC from a GDI+ context 476 // loses the scale operations applied to the context. 477 FloatSize currentScale(); 475 478 bool inTransparencyLayer() const { return false; } 476 479 #endif -
trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp
r78852 r87745 78 78 // will hopefully be folded into wx once the API has solidified. 79 79 // see platform/wx/wxcode/<platform> for the implementations. 80 graphicsContext->save(); 80 81 drawTextWithSpacing(graphicsContext, font, color, glyphBuffer, from, numGlyphs, point); 82 graphicsContext->restore(); 81 83 } 82 84 -
trunk/Source/WebCore/platform/graphics/wx/GraphicsContextWx.cpp
r86502 r87745 113 113 #endif 114 114 int mswDCStateID; 115 FloatSize currentScale; 115 116 wxRegion gtkCurrentClipRgn; 116 117 wxRegion gtkPaintClipRgn; … … 121 122 mswDCStateID(0), 122 123 gtkCurrentClipRgn(wxRegion()), 123 gtkPaintClipRgn(wxRegion()) 124 gtkPaintClipRgn(wxRegion()), 125 currentScale(1.0, 1.0) 124 126 { 125 127 } … … 217 219 return; 218 220 221 save(); 219 222 m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle()))); 220 223 m_data->context->DrawRectangle(rect.x(), rect.y(), rect.width(), rect.height()); 224 restore(); 221 225 } 222 226 … … 230 234 FloatPoint p2 = point2; 231 235 236 save(); 232 237 m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle()))); 233 238 m_data->context->DrawLine(point1.x(), point1.y(), point2.x(), point2.y()); 239 restore(); 234 240 } 235 241 … … 240 246 return; 241 247 248 save(); 242 249 m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle()))); 243 250 m_data->context->DrawEllipse(rect.x(), rect.y(), rect.width(), rect.height()); 251 restore(); 244 252 } 245 253 … … 249 257 return; 250 258 259 save(); 251 260 m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle()))); 252 261 m_data->context->DrawEllipticArc(rect.x(), rect.y(), rect.width(), rect.height(), startAngle, startAngle + angleSpan); 262 restore(); 253 263 } 254 264 … … 261 271 return; 262 272 273 save(); 263 274 wxPoint* polygon = new wxPoint[npoints]; 264 275 for (size_t i = 0; i < npoints; i++) … … 267 278 m_data->context->DrawPolygon((int)npoints, polygon); 268 279 delete [] polygon; 280 restore(); 269 281 } 270 282 … … 285 297 return; 286 298 287 save PlatformState();299 save(); 288 300 289 301 m_data->context->SetPen(*wxTRANSPARENT_PEN); … … 291 303 m_data->context->DrawRectangle(rect.x(), rect.y(), rect.width(), rect.height()); 292 304 293 restore PlatformState();305 restore(); 294 306 } 295 307 … … 401 413 return; 402 414 415 save(); 403 416 FloatPoint endPoint = origin + FloatSize(width, 0); 404 417 m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), wxSOLID)); 405 418 m_data->context->DrawLine(origin.x(), origin.y(), endPoint.x(), endPoint.y()); 419 restore(); 406 420 } 407 421 … … 474 488 475 489 void GraphicsContext::scale(const FloatSize& scale) 476 { 490 { 477 491 #if USE(WXGC) 478 492 if (m_data->context) { 479 493 wxGraphicsContext* gc = m_data->context->GetGraphicsContext(); 480 494 gc->Scale(scale.width(), scale.height()); 481 } 482 #endif 483 } 484 485 495 m_data->currentScale = scale; 496 } 497 #endif 498 } 499 500 FloatSize GraphicsContext::currentScale() 501 { 502 return m_data->currentScale; 503 } 486 504 FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode) 487 505 { -
trunk/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp
r80287 r87745 25 25 26 26 #include "config.h" 27 28 #include "AffineTransform.h" 27 29 #include "GlyphBuffer.h" 28 30 #include "GraphicsContext.h" … … 83 85 float x = point.x(); 84 86 87 85 88 #if USE(WXGC) 86 89 // when going from GdiPlus -> Gdi, any GdiPlus transformations are lost … … 97 100 } 98 101 x += (int)xtrans; 99 y += (int)ytrans; 102 y += (int)ytrans; 100 103 #else 101 104 hdc = static_cast<HDC>(dc->GetHDC()); 102 105 #endif 103 106 107 // if the context has been scaled, we must manually re-apply that scale 108 // to the HDC. 109 FloatSize scale = graphicsContext->currentScale(); 110 if (scale != FloatSize(1.0, 1.0)) { 111 SetGraphicsMode(hdc, GM_ADVANCED); 112 XFORM xForm; 113 xForm.eM11 = scale.width(); 114 xForm.eM12 = 0.0; 115 xForm.eM21 = 0.0; 116 xForm.eM22 = scale.height(); 117 xForm.eDx = 0.0; 118 xForm.eDy = 0.0; 119 SetWorldTransform(hdc, &xForm); 120 } 104 121 // ExtTextOut wants the offsets as an array of ints, so extract them 105 122 // from the glyph buffer -
trunk/Source/WebKit/wx/ChangeLog
r86584 r87745 1 2011-05-31 Robin Dunn <robin@alldunn.com> 2 3 Reviewed by Kevin Ollivier. 4 5 [wx] Implement printing support for wxWidgets 2.9.x and above. 6 7 https://bugs.webkit.org/show_bug.cgi?id=61796 8 9 * WebBrowserShell.cpp: 10 (wxWebBrowserShell::wxWebBrowserShell): 11 (wxWebBrowserShell::OnPrint): 12 * WebBrowserShell.h: 13 * WebFrame.cpp: 14 (wxWebFramePrintout::wxWebFramePrintout): 15 (wxWebFramePrintout::GetPageCount): 16 (wxWebFramePrintout::SetFirstPage): 17 (wxWebFramePrintout::SetLastPage): 18 (wxWebFramePrintout::InitializeWithPageSize): 19 (wxWebFramePrintout::OnBeginPrinting): 20 (wxWebFramePrintout::GetPageInfo): 21 (wxWebFramePrintout::HasPage): 22 (wxWebFramePrintout::OnPrintPage): 23 (wxWebFramePrintout::OnEndPrinting): 24 (wxWebFrame::Print): 25 * WebFrame.h: 26 1 27 2011-05-13 Jon Lee <jonlee@apple.com> 2 28 -
trunk/Source/WebKit/wx/WebBrowserShell.cpp
r64229 r87745 94 94 EVT_MENU(ID_EDIT_COMMAND, wxWebBrowserShell::OnEditCommand) 95 95 EVT_MENU(ID_GET_EDIT_COMMAND_STATE, wxWebBrowserShell::OnGetEditCommandState) 96 EVT_MENU(wxID_PRINT, wxWebBrowserShell::OnPrint) 96 97 END_EVENT_TABLE() 97 98 … … 101 102 m_checkBeforeLoad(false) 102 103 { 103 104 104 // create a menu bar 105 105 wxMenu *fileMenu = new wxMenu; … … 107 107 fileMenu->Append(ID_LOADFILE, _T("Open File...\tCTRL+O")); 108 108 fileMenu->Append(ID_LOADURL, _("Open Location...\tCTRL+L")); 109 fileMenu->AppendSeparator(); 110 fileMenu->Append(wxID_PRINT, _("Print...")); 109 111 fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit this program")); 110 112 … … 113 115 editMenu->Append(wxID_COPY, _T("Copy\tCTRL+C")); 114 116 editMenu->Append(wxID_PASTE, _T("Paste\tCTRL+V")); 115 117 116 118 wxMenu* viewMenu = new wxMenu; 117 119 viewMenu->AppendRadioItem(ID_BROWSE, _("Browse")); … … 397 399 } 398 400 } 401 402 void wxWebBrowserShell::OnPrint(wxCommandEvent& myEvent) 403 { 404 if (webview && webview->GetMainFrame()) 405 webview->GetMainFrame()->Print(); 406 } -
trunk/Source/WebKit/wx/WebBrowserShell.h
r64229 r87745 73 73 void OnBrowse(wxCommandEvent& event); 74 74 void OnEdit(wxCommandEvent& event); 75 void OnPrint(wxCommandEvent& myEvent); 75 76 76 77 void OnMakeTextLarger(wxCommandEvent& event); -
trunk/Source/WebKit/wx/WebFrame.cpp
r81600 r87745 30 30 #include "Element.h" 31 31 #include "EventHandler.h" 32 #include "FloatRect.h" 32 33 #include "Frame.h" 33 34 #include "FrameLoader.h" 34 35 #include "FrameView.h" 36 #include "GraphicsContext.h" 35 37 #include "HitTestResult.h" 36 38 #include "HostWindow.h" … … 39 41 #include "Page.h" 40 42 #include "PlatformString.h" 43 #include "PrintContext.h" 41 44 #include "RenderTreeAsText.h" 42 45 #include "RenderObject.h" … … 68 71 #include "WebViewPrivate.h" 69 72 73 #include <algorithm> 74 70 75 #include <wx/defs.h> 76 #include <wx/dc.h> 71 77 #include <wx/dcbuffer.h> 78 #include <wx/dcgraph.h> 79 #include <wx/graphics.h> 80 #include <wx/print.h> 81 #include <wx/printdlg.h> 72 82 73 83 // Match Safari's min/max zoom sizes by default … … 75 85 #define MaximumTextSizeMultiplier 3.0f 76 86 #define TextSizeMultiplierRatio 1.2f 87 88 using namespace std; 89 90 // we need wxGraphicsContext and wxPrinterDC to work together, 91 // which requires wx 2.9.x. 92 #if wxCHECK_VERSION(2, 9, 1) 93 class wxWebFramePrintout : public wxPrintout { 94 public: 95 wxWebFramePrintout(WebCore::Frame* frame) : 96 m_frame(frame), 97 m_printContext(frame), 98 m_pageWidth(0.0), 99 m_fromPage(1), 100 m_toPage(1) 101 { 102 } 103 104 int GetPageCount() { return m_printContext.pageCount(); } 105 void SetFirstPage(int page) { m_fromPage = page; } 106 void SetLastPage(int page) { m_toPage = page; } 107 108 void InitializeWithPageSize(wxRect pageRect) 109 { 110 double mmToPixelsX = (double)wxGetDisplaySize().GetWidth() / 111 (double)wxGetDisplaySizeMM().GetWidth(); 112 double mmToPixelsY = (double)wxGetDisplaySize().GetHeight() / 113 (double)wxGetDisplaySizeMM().GetHeight(); 114 // convert mm to pixels 115 pageRect.x = pageRect.x * mmToPixelsX; 116 pageRect.y = pageRect.y * mmToPixelsY; 117 pageRect.width = pageRect.width * mmToPixelsX; 118 pageRect.height = pageRect.height * mmToPixelsY; 119 120 m_pageWidth = pageRect.width; 121 m_printContext.begin(m_pageWidth); 122 123 float pageHeight = pageRect.height; 124 m_printContext.computePageRects(WebCore::FloatRect(pageRect), /* headerHeight */ 0, /* footerHeight */ 0, /* userScaleFactor */ 1.0, pageHeight); 125 } 126 127 void OnBeginPrinting() 128 { 129 wxPrinterDC* pdc = dynamic_cast<wxPrinterDC*>(GetDC()); 130 pdc->SetMapMode(wxMM_POINTS); 131 } 132 133 void GetPageInfo(int *minPage, int *maxPage, int *pageFrom, int *pageTo) 134 { 135 if (minPage) 136 *minPage = 1; 137 if (maxPage) 138 *maxPage = m_printContext.pageCount(); 139 if (pageFrom) 140 *pageFrom = m_fromPage; 141 if (pageTo) 142 *pageTo = m_toPage; 143 } 144 145 bool HasPage(int pageNum) 146 { 147 return pageNum <= m_printContext.pageCount() && pageNum >= m_fromPage && pageNum <= m_toPage; 148 } 149 150 bool OnPrintPage(int pageNum) 151 { 152 wxPrinterDC* pdc = dynamic_cast<wxPrinterDC*>(GetDC()); 153 154 wxGCDC gcdc(*pdc); 155 if (!gcdc.IsOk()) 156 return false; 157 158 WebCore::GraphicsContext ctx(&gcdc); 159 m_printContext.spoolPage(ctx, pageNum - 1, m_pageWidth); 160 161 return true; 162 } 163 164 void OnEndPrinting() 165 { 166 m_printContext.end(); 167 } 168 169 private: 170 float m_pageWidth; 171 int m_fromPage; 172 int m_toPage; 173 WebCore::Frame *m_frame; 174 WebCore::PrintContext m_printContext; 175 }; 176 #endif 77 177 78 178 wxWebFrame::wxWebFrame(wxWebView* container, wxWebFrame* parent, WebViewFrameData* data) : … … 457 557 } 458 558 559 void wxWebFrame::Print() 560 { 561 #if wxCHECK_VERSION(2, 9, 1) 562 if (!m_impl->frame) 563 return; 564 565 wxPrintDialogData printdata; 566 printdata.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER); 567 printdata.GetPrintData().SetPaperId(wxPAPER_LETTER); 568 printdata.GetPrintData().SetNoCopies(1); 569 570 wxPageSetupDialogData pageSetup(printdata.GetPrintData()); 571 572 wxRect paperSize = pageSetup.GetPaperSize(); 573 #ifdef __WXMSW__ 574 // On Windows, the paper size apparently includes the non-printable areas of the page. 575 // Guesstimate the printable page margins until we find a better solution. 576 paperSize.Deflate(15, 15); 577 #endif 578 wxWebFramePrintout* printout = new wxWebFramePrintout(m_impl->frame); 579 printout->InitializeWithPageSize(paperSize); 580 581 printdata.SetMinPage(1); 582 printdata.SetMaxPage(printout->GetPageCount()); 583 printdata.SetFromPage(1); 584 printdata.SetToPage(printout->GetPageCount()); 585 586 wxPrintDialog dialog(0, &printdata); 587 if (dialog.ShowModal() == wxID_OK) { 588 wxPrintDialogData data(dialog.GetPrintDialogData()); 589 printout->SetFirstPage(data.GetFromPage()); 590 printout->SetLastPage(data.GetToPage()); 591 wxPrinter printer(&data); 592 593 printer.Print(0, printout, false); 594 } 595 #else 596 wxFAIL_MSG(wxT("Printing is only supported in wxWidgets 2.9.1 and above.")); 597 #endif 598 } 599 459 600 wxWebViewDOMElementInfo wxWebFrame::HitTest(const wxPoint& pos) const 460 601 { -
trunk/Source/WebKit/wx/WebFrame.h
r79953 r87745 116 116 void Stop(); 117 117 void Reload(); 118 void Print(); 118 119 119 120 bool CanGoBack();
Note: See TracChangeset
for help on using the changeset viewer.