利用webkit生成网页截图 1

         最近需要对网页截图,试过很工具,大多只能支持静态页面(我需要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


据此,大致能看出内核与port各自的职责(稍后详解),我只要在自己的port中将所有的draw实现改成画到自己的画板(而不是窗口上)就算大功告成!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值