Bug 29861
Summary: | [Qt] Webkit print using the screen media type + Patch | ||
---|---|---|---|
Product: | WebKit | Reporter: | Tor Arne Vestbø <vestbo> |
Component: | Printing | Assignee: | QtWebKit Unassigned <webkit-qt-unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | Normal | CC: | hausmann, h.goebel, kenneth, kent.hansen |
Priority: | P2 | Keywords: | Qt |
Version: | 528+ (Nightly build) | ||
Hardware: | Other | ||
OS: | OS X 10.5 |
Tor Arne Vestbø
This bug report originated from issue QTBUG-3894
http://bugreports.qt.nokia.com/browse/QTBUG-3894
--- Description ---
At some times when, printing a page in webkit, especially to a virtual printer, you really want to print using the screen media type, and not the print media type after all. This patches adds support for this, in a not as clean as could be desired way.
Patch:
diff -ur qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/Frame.cpp qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/Frame.cpp
--- qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/Frame.cpp 2009-02-25 22:09:20.000000000 +0100
+++ qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/Frame.cpp 2009-03-14 10:11:45.000000000 +0100
@@ -726,13 +726,13 @@
view()->layout();
}
-void Frame::setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize)
+void Frame::setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize, bool usePrintMediaType)
{
if (!d->m_doc)
return;
d->m_doc->setPrinting(printing);
- view()->setMediaType(printing ? "print" : "screen");
+ view()->setMediaType((printing && usePrintMediaType) ? "print" : "screen");
d->m_doc->updateStyleSelector();
forceLayoutWithPageWidthRange(minPageWidth, maxPageWidth, adjustViewSize);
diff -ur qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/Frame.h qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/Frame.h
--- qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/Frame.h 2009-02-25 22:09:20.000000000 +0100
+++ qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/Frame.h 2009-03-14 10:11:52.000000000 +0100
@@ -125,7 +125,7 @@
void setUserStyleSheet(const String& styleSheetData);
#endif
- void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
+ void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize, bool usePrintMediaType=true);
bool inViewSourceMode() const;
void setInViewSourceMode(bool = true) const;
diff -ur qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/PrintContext.cpp qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/PrintContext.cpp
--- qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/PrintContext.cpp 2009-02-25 22:09:20.000000000 +0100
+++ qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/PrintContext.cpp 2009-03-14 10:12:43.000000000 +0100
@@ -93,7 +93,7 @@
} while (printedPagesHeight < docHeight);
}
-void PrintContext::begin(float width)
+void PrintContext::begin(float width, bool usePrintMediaType)
{
// By imaging to a width a little wider than the available pixels,
// thin pages will be scaled down a little, matching the way they
@@ -113,7 +113,7 @@
// FIXME: This will modify the rendering of the on-screen frame.
// Could lead to flicker during printing.
- m_frame->setPrinting(true, minLayoutWidth, maxLayoutWidth, true);
+ m_frame->setPrinting(true, minLayoutWidth, maxLayoutWidth, true, usePrintMediaType);
}
void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
diff -ur qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/PrintContext.h qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/PrintContext.h
--- qt-x11-opensource-src-4.5.0-old/src/3rdparty/webkit/WebCore/page/PrintContext.h 2009-02-25 22:09:20.000000000 +0100
+++ qt-x11-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/page/PrintContext.h 2009-03-14 10:12:19.000000000 +0100
@@ -40,7 +40,7 @@
void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight);
// TODO: eliminate width param
- void begin(float width);
+ void begin(float width, bool usePrintMediaType=true);
// TODO: eliminate width param
void spoolPage(GraphicsContext& ctx, int pageNumber, float width);
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Kent Hansen
OK, need to decide if we want to add this enhancement.
Simon Hausmann
Kenneth, I recall that you were recently talking about a similar patch for setting the media type. Is this a duplicate bug?
Kenneth Rohde Christiansen
(In reply to comment #2)
> Kenneth, I recall that you were recently talking about a similar patch for
> setting the media type. Is this a duplicate bug?
Why would you want to print with disaccordance to the spec? When printing you are supposed to use CSS according to the "print" media type.
I don't understand the use case.
h.goebel
This is very useful for making a "screenshot" of the web-page into a PDF. In this case you do not want to "print", but get the same result as displayed on screen.
This is a quite common case for documentation purposes, marketing, etc. The web is full of people looking for such a solution. There are quite a few add-ons for Firefox promising this -- but all of them are using some online-service.
Having such a feature in Webkit would be a great benefit.
Kenneth Rohde Christiansen
(In reply to comment #4)
> This is very useful for making a "screenshot" of the web-page into a PDF. In this case you do not want to "print", but get the same result as displayed on screen.
>
> This is a quite common case for documentation purposes, marketing, etc. The web is full of people looking for such a solution. There are quite a few add-ons for Firefox promising this -- but all of them are using some online-service.
>
> Having such a feature in Webkit would be a great benefit.
You do not need to print to make a screenshot, you an just paint to an image. Print might do more that what you want as it layouts with a given width.
h.goebel
Can you please point me so a example code painting to a PDF file then? Thanks a lot!
Alexey Proskuryakov
*** This bug has been marked as a duplicate of bug 25866 ***