Changeset 87745 in webkit


Ignore:
Timestamp:
May 31, 2011 12:21:39 PM (13 years ago)
Author:
kevino@webkit.org
Message:

Reviewed by Kevin Ollivier.

[wx] Implement printing support for wxWidgets 2.9.x and above.

https://bugs.webkit.org/show_bug.cgi?id=61796

Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87744 r87745  
     12011-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
    1262011-05-31  Joseph Pecoraro  <joepeck@webkit.org>
    227
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r87336 r87745  
    473473
    474474#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();
    475478        bool inTransparencyLayer() const { return false; }
    476479#endif
  • trunk/Source/WebCore/platform/graphics/wx/FontWx.cpp

    r78852 r87745  
    7878    // will hopefully be folded into wx once the API has solidified.
    7979    // see platform/wx/wxcode/<platform> for the implementations.
     80    graphicsContext->save();
    8081    drawTextWithSpacing(graphicsContext, font, color, glyphBuffer, from, numGlyphs, point);
     82    graphicsContext->restore();
    8183}
    8284
  • trunk/Source/WebCore/platform/graphics/wx/GraphicsContextWx.cpp

    r86502 r87745  
    113113#endif
    114114    int mswDCStateID;
     115    FloatSize currentScale;
    115116    wxRegion gtkCurrentClipRgn;
    116117    wxRegion gtkPaintClipRgn;
     
    121122    mswDCStateID(0),
    122123    gtkCurrentClipRgn(wxRegion()),
    123     gtkPaintClipRgn(wxRegion())
     124    gtkPaintClipRgn(wxRegion()),
     125    currentScale(1.0, 1.0)
    124126{
    125127}
     
    217219        return;
    218220
     221    save();
    219222    m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
    220223    m_data->context->DrawRectangle(rect.x(), rect.y(), rect.width(), rect.height());
     224    restore();
    221225}
    222226
     
    230234    FloatPoint p2 = point2;
    231235   
     236    save();
    232237    m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
    233238    m_data->context->DrawLine(point1.x(), point1.y(), point2.x(), point2.y());
     239    restore();
    234240}
    235241
     
    240246        return;
    241247
     248    save();
    242249    m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
    243250    m_data->context->DrawEllipse(rect.x(), rect.y(), rect.width(), rect.height());
     251    restore();
    244252}
    245253
     
    249257        return;
    250258   
     259    save();
    251260    m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), strokeStyleToWxPenStyle(strokeStyle())));
    252261    m_data->context->DrawEllipticArc(rect.x(), rect.y(), rect.width(), rect.height(), startAngle, startAngle + angleSpan);
     262    restore();
    253263}
    254264
     
    261271        return;
    262272
     273    save();
    263274    wxPoint* polygon = new wxPoint[npoints];
    264275    for (size_t i = 0; i < npoints; i++)
     
    267278    m_data->context->DrawPolygon((int)npoints, polygon);
    268279    delete [] polygon;
     280    restore();
    269281}
    270282
     
    285297        return;
    286298
    287     savePlatformState();
     299    save();
    288300
    289301    m_data->context->SetPen(*wxTRANSPARENT_PEN);
     
    291303    m_data->context->DrawRectangle(rect.x(), rect.y(), rect.width(), rect.height());
    292304
    293     restorePlatformState();
     305    restore();
    294306}
    295307
     
    401413        return;
    402414
     415    save();
    403416    FloatPoint endPoint = origin + FloatSize(width, 0);
    404417    m_data->context->SetPen(wxPen(strokeColor(), strokeThickness(), wxSOLID));
    405418    m_data->context->DrawLine(origin.x(), origin.y(), endPoint.x(), endPoint.y());
     419    restore();
    406420}
    407421
     
    474488
    475489void GraphicsContext::scale(const FloatSize& scale)
    476 { 
     490{
    477491#if USE(WXGC)
    478492    if (m_data->context) {
    479493        wxGraphicsContext* gc = m_data->context->GetGraphicsContext();
    480494        gc->Scale(scale.width(), scale.height());
    481     }
    482 #endif
    483 }
    484 
    485 
     495        m_data->currentScale = scale;
     496    }
     497#endif
     498}
     499
     500FloatSize GraphicsContext::currentScale()
     501{
     502    return m_data->currentScale;
     503}
    486504FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode)
    487505{
  • trunk/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp

    r80287 r87745  
    2525
    2626#include "config.h"
     27
     28#include "AffineTransform.h"
    2729#include "GlyphBuffer.h"
    2830#include "GraphicsContext.h"
     
    8385    float x = point.x();
    8486
     87
    8588#if USE(WXGC)
    8689    // when going from GdiPlus -> Gdi, any GdiPlus transformations are lost
     
    97100    }
    98101    x += (int)xtrans;
    99     y += (int)ytrans;   
     102    y += (int)ytrans;
    100103#else
    101104    hdc = static_cast<HDC>(dc->GetHDC());
    102105#endif
    103106
     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    }
    104121    // ExtTextOut wants the offsets as an array of ints, so extract them
    105122    // from the glyph buffer
  • trunk/Source/WebKit/wx/ChangeLog

    r86584 r87745  
     12011-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
    1272011-05-13  Jon Lee  <jonlee@apple.com>
    228
  • trunk/Source/WebKit/wx/WebBrowserShell.cpp

    r64229 r87745  
    9494    EVT_MENU(ID_EDIT_COMMAND, wxWebBrowserShell::OnEditCommand)
    9595    EVT_MENU(ID_GET_EDIT_COMMAND_STATE, wxWebBrowserShell::OnGetEditCommandState)
     96    EVT_MENU(wxID_PRINT, wxWebBrowserShell::OnPrint)
    9697END_EVENT_TABLE()
    9798
     
    101102        m_checkBeforeLoad(false)
    102103{
    103 
    104104    // create a menu bar
    105105    wxMenu *fileMenu = new wxMenu;
     
    107107    fileMenu->Append(ID_LOADFILE, _T("Open File...\tCTRL+O"));
    108108    fileMenu->Append(ID_LOADURL, _("Open Location...\tCTRL+L"));
     109    fileMenu->AppendSeparator();
     110    fileMenu->Append(wxID_PRINT, _("Print..."));
    109111    fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit this program"));
    110112   
     
    113115    editMenu->Append(wxID_COPY, _T("Copy\tCTRL+C"));
    114116    editMenu->Append(wxID_PASTE, _T("Paste\tCTRL+V"));
    115    
     117
    116118    wxMenu* viewMenu = new wxMenu;
    117119    viewMenu->AppendRadioItem(ID_BROWSE, _("Browse"));
     
    397399    }
    398400}
     401
     402void wxWebBrowserShell::OnPrint(wxCommandEvent& myEvent)
     403{
     404    if (webview && webview->GetMainFrame())
     405        webview->GetMainFrame()->Print();
     406}
  • trunk/Source/WebKit/wx/WebBrowserShell.h

    r64229 r87745  
    7373    void OnBrowse(wxCommandEvent& event);
    7474    void OnEdit(wxCommandEvent& event);
     75    void OnPrint(wxCommandEvent& myEvent);
    7576   
    7677    void OnMakeTextLarger(wxCommandEvent& event);
  • trunk/Source/WebKit/wx/WebFrame.cpp

    r81600 r87745  
    3030#include "Element.h"
    3131#include "EventHandler.h"
     32#include "FloatRect.h"
    3233#include "Frame.h"
    3334#include "FrameLoader.h"
    3435#include "FrameView.h"
     36#include "GraphicsContext.h"
    3537#include "HitTestResult.h"
    3638#include "HostWindow.h"
     
    3941#include "Page.h"
    4042#include "PlatformString.h"
     43#include "PrintContext.h"
    4144#include "RenderTreeAsText.h"
    4245#include "RenderObject.h"
     
    6871#include "WebViewPrivate.h"
    6972
     73#include <algorithm>
     74
    7075#include <wx/defs.h>
     76#include <wx/dc.h>
    7177#include <wx/dcbuffer.h>
     78#include <wx/dcgraph.h>
     79#include <wx/graphics.h>
     80#include <wx/print.h>
     81#include <wx/printdlg.h>
    7282
    7383// Match Safari's min/max zoom sizes by default
     
    7585#define MaximumTextSizeMultiplier       3.0f
    7686#define TextSizeMultiplierRatio         1.2f
     87
     88using 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)
     93class wxWebFramePrintout : public wxPrintout {
     94public:
     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   
     169private:
     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
    77177
    78178wxWebFrame::wxWebFrame(wxWebView* container, wxWebFrame* parent, WebViewFrameData* data) :
     
    457557}
    458558
     559void 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
    459600wxWebViewDOMElementInfo wxWebFrame::HitTest(const wxPoint& pos) const
    460601{
  • trunk/Source/WebKit/wx/WebFrame.h

    r79953 r87745  
    116116    void Stop();
    117117    void Reload();
     118    void Print();
    118119   
    119120    bool CanGoBack();
Note: See TracChangeset for help on using the changeset viewer.