最近需要对网页截图,试过很工具,大多只能支持静态页面(我需要css、js、flash、cookie、html5等等统统支持),有个chrome插件 "WebPage Screenshot"功能是挺不错的,但这种模式应用于服务器端(搜索引擎系统)实在是太丑陋。
所以,想到利用webkit内核直接生成网页截图。
目前来看,关键点在这个类里面WebCore::GraphicsContext , 其头文件中定义了一系列的方法drawRect、drawLine、drawText、drawImage,具体实现由各平台的port来完成。webkit源码编译后会生成一个简单的浏览器--QtTestBrowser,所以,我从QT Port下手。
断点设到drawLine上,堆栈如下:
Breakpoint 1, WebCore::GraphicsContext::drawLine (this=0x7fff0057ccb0, point1=..., point2=...)
at ../../../../Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp:332
332 if (paintingDisabled())
(gdb) bt
#0 WebCore::GraphicsContext::drawLine (this=0x7fff0057ccb0, point1=..., point2=...)
at ../../../../Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp:332
#1 0x00007f228a26179e in WebCore::GraphicsContext::drawLineForText (this=0x7fff0057ccb0, origin=..., width=78)
at ../../../../Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp:896
#2 0x00007f228a05234b in WebCore::InlineTextBox::paintDecoration (this=0x2792e48, context=0x7fff0057ccb0, boxOrigin=...,
deco=1, shadow=0x0) at ../../../../Source/WebCore/rendering/InlineTextBox.cpp:960
#3 0x00007f228a05100f in WebCore::InlineTextBox::paint (this=0x2792e48, paintInfo=..., paintOffset=...)
at ../../../../Source/WebCore/rendering/InlineTextBox.cpp:749
#4 0x00007f228a0466ff in WebCore::InlineFlowBox::paint (this=0x2c5fcc8, paintInfo=..., paintOffset=..., lineTop=0,
lineBottom=17) at ../../../../Source/WebCore/rendering/InlineFlowBox.cpp:1069
#5 0x00007f228a0466ff in WebCore::InlineFlowBox::paint (this=0x2c5fc08, paintInfo=..., paintOffset=..., lineTop=0,
lineBottom=17) at ../../../../Source/WebCore/rendering/InlineFlowBox.cpp:1069
#6 0x00007f228a1d6a76 in WebCore::RootInlineBox::paint (this=0x2c5fc08, paintInfo=..., paintOffset=..., lineTop=0,
lineBottom=17) at ../../../../Source/WebCore/rendering/RootInlineBox.cpp:196
#7 0x00007f228a150884 in WebCore::RenderLineBoxList::paint (this=0x27681e8, renderer=0x2768148, paintInfo=...,
paintOffset=...) at ../../../../Source/WebCore/rendering/RenderLineBoxList.cpp:262
#8 0x00007f228a069789 in WebCore::RenderBlock::paintContents (this=0x2768148, paintInfo=..., paintOffset=...)
at ../../../../Source/WebCore/rendering/RenderBlock.cpp:2671
#9 0x00007f228a06a000 in WebCore::RenderBlock::paintObject (this=0x2768148, paintInfo=..., paintOffset=...)
at ../../../../Source/WebCore/rendering/RenderBlock.cpp:2781
#10 0x00007f228a06880b in WebCore::RenderBlock::paint (this=0x2768148, paintInfo=..., paintOffset=...)
at ../../../../Source/WebCore/rendering/RenderBlock.cpp:2526
#11 0x00007f228a069ae7 in WebCore::RenderBlock::paintChildren (this=0x2767f98, paintInfo=..., paintOffset=...)
at ../../../../Source/WebCore/rendering/RenderBlock.cpp:2715