📄 kwqpainter.cpp
字号:
CFbsBitGc* gContext = NULL;
if (data->iGc) {
gContext = &data->iGc->Gc();
}
int npoints = _npoints != -1 ? _npoints : _points.size()-index;
// test for zero width
if (npoints==4 && ( (_points[index+0].y()==_points[index+1].y() && _points[index+2].y()==_points[index+3].y()) ||
(_points[index+0].x()==_points[index+3].x() && _points[index+1].x()==_points[index+2].x()) ))
return;
TPoint* points = new TPoint[npoints];
for (int i = 0; i < npoints; i++) {
points[i] = xForm(TPoint(_points[index+i].x(), _points[index+i].y()));
}
if (fill && data->state.brush.style() != NoBrush) {
_setColorFromBrush();
}
if (data->state.pen.style() != NoPen) {
_setColorFromPen();
}
if (gContext) {
if (fill) {
// qt and symbian coordinate systems are different
// ###hack, this relies on the order of points used in khtml
if (npoints==4) {
points[1].iY--;
points[2].iY--;
points[2].iX--;
points[3].iX--;
if (points[0].iY>points[3].iY)
points[0].iY--;
if (points[1].iX>points[0].iX)
points[1].iX--;
if (points[2].iY<points[1].iY)
points[2].iY++;
if (points[3].iX<points[2].iX)
points[3].iX++;
}
gContext->DrawPolygon(points, npoints, CGraphicsContext::EAlternate);
}
else {
gContext->DrawPolyLine(points, npoints);
}
}
delete[] points;
}
void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix)
{
drawPixmap( p.x(), p.y(), pix.width(), pix.height(), pix, 0, 0, pix.width(), pix.height(), 0 );
}
void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix, const QRect &r)
{
drawPixmap( p.x(), p.y(), pix.width(), pix.height(), pix, r.top(), r.left(), r.width(), r.height(), 0 );
}
void QPainter::drawPixmap( int x, int y, const QPixmap & pix,
int sx, int sy, int sw, int sh, int compositeOperator)
{
drawPixmap( x, y, pix.width(), pix.height(), pix, sx, sy, sw, sh, 0 );
}
void QPainter::drawPixmap( int x, int y, int w, int h, const QPixmap& pixmap,
int sx, int sy, int sw, int sh, int compositeOperator)
{
if (data->state.paintingDisabled)
return;
if( pixmap.isNull() ) return;
if (sw == -1)
sw = pixmap.width();
if (sh == -1)
sh = pixmap.height();
if (w == -1)
w = pixmap.width();
if (h == -1)
h = pixmap.height();
MWebCoreImageRenderer* renderer = (const_cast<QPixmap&>(pixmap)).image();
renderer->DrawImageInRect( *data->iGc, xForm(TRect( x, y, x+w, y+h )), xForm(TRect( sx, sy, sx+sw, sy+sh ) ));
}
// NEED_IMPLEMENTATION
/*struct CompositeOperator
{
const char *name;
NSCompositingOperation value;
};
#define NUM_COMPOSITE_OPERATORS 14
struct CompositeOperator compositeOperators[NUM_COMPOSITE_OPERATORS] = {
{ "clear", NSCompositeClear },
{ "copy", NSCompositeCopy },
{ "source-over", NSCompositeSourceOver },
{ "source-in", NSCompositeSourceIn },
{ "source-out", NSCompositeSourceOut },
{ "source-atop", NSCompositeSourceAtop },
{ "destination-over", NSCompositeDestinationOver },
{ "destination-in", NSCompositeDestinationIn },
{ "destination-out", NSCompositeDestinationOut },
{ "destination-atop", NSCompositeDestinationAtop },
{ "xor", NSCompositeXOR },
{ "darker", NSCompositePlusDarker },
{ "highlight", NSCompositeHighlight },
{ "lighter", NSCompositePlusLighter }
};
int QPainter::getCompositeOperation(CGContextRef context)
{
return (int)[[WebCoreImageRendererFactory sharedFactory] CGCompositeOperationInContext:context];
}
void QPainter::setCompositeOperation (CGContextRef context, QString op)
{
[[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperationFromString:op.getNSString() inContext:context];
}
void QPainter::setCompositeOperation (CGContextRef context, int op)
{
[[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperation:op inContext:context];
}
int QPainter::compositeOperatorFromString (QString aString)
{
NSCompositingOperation op = NSCompositeSourceOver;
if (aString.length()) {
const char *operatorString = aString.ascii();
int i;
for (i = 0; i < NUM_COMPOSITE_OPERATORS; i++) {
if (strcasecmp (operatorString, compositeOperators[i].name) == 0) {
return compositeOperators[i].value;
}
}
}
return (int)op;
}
*/
void QPainter::drawPixmap(const QPoint &p, const QPixmap &pix, const QRect &r, const QString &compositeOperator)
{
// FIXME NOKIA: compositeOperator is not used here
drawPixmap(p.x(), p.y(), pix, r.x(), r.y(), r.width(), r.height() ); //compositeOperatorFromString(compositeOperator));
}
/*
void QPainter::drawPixmap( int x, int y, const QPixmap &pixmap,
int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
{
drawPixmap (x, y, sw, sh, pixmap, sx, sy, sw, sh, compositeOperator, context);
}
void QPainter::drawPixmap( int x, int y, int w, int h, const QPixmap &pixmap,
int sx, int sy, int sw, int sh, int compositeOperator, CGContextRef context)
{
if (data->state.paintingDisabled)
return;
if (sw == -1)
sw = pixmap.width();
if (sh == -1)
sh = pixmap.height();
if (w == -1)
w = pixmap.width();
if (h == -1)
h = pixmap.height();
NSRect inRect = NSMakeRect(x, y, w, h);
NSRect fromRect = NSMakeRect(sx, sy, sw, sh);
KWQ_BLOCK_EXCEPTIONS;
[pixmap.imageRenderer drawImageInRect:inRect
fromRect:fromRect compositeOperator:(NSCompositingOperation)compositeOperator context:context];
KWQ_UNBLOCK_EXCEPTIONS;
imageRenderer->drawImageInRect( TRect( x,y,w,h ), TRect( sx,sy,sw,sh ) );
}
void QPainter::drawTiledPixmap( int x, int y, int w, int h,
const QPixmap &pixmap, int sx, int sy, CGContextRef context)
{
if (data->state.paintingDisabled)
return;
NOT IMPLEMETNED: MWebCoreImageRenderer disabled tiled bitmap rendering
KWQ_BLOCK_EXCEPTIONS;
[pixmap.imageRenderer tileInRect:NSMakeRect(x, y, w, h) fromPoint:NSMakePoint(sx, sy) context:context];
KWQ_UNBLOCK_EXCEPTIONS;
}
*/
void QPainter::drawTiledPixmap( int x, int y, int w, int h,
const QPixmap &pixmap, int sx, int sy)
{
if (data->state.paintingDisabled)
return;
if( pixmap.isNull() ) return;
MWebCoreImageRenderer* renderer = (const_cast<QPixmap&>(pixmap)).image();
renderer->TileInRect( *data->iGc, xForm(TRect( x, y, x+w, y+h )), xForm(TPoint( sx, sy ) ));
}
void QPainter::drawText(int x, int y, int tabWidth, int xpos, int, int, int alignmentFlags, const QString &qstring)
{
if (data->state.paintingDisabled)
return;
// Avoid allocations, use stack array to pass font families. Normally these
// css fallback lists are small <= 3.
CREATE_FAMILY_ARRAY(data->state.font, families);
const TText* str = (const TText*)qstring.unicode();
TWebCoreTextRun run(str, qstring.length(), 0, qstring.length());
TWebCoreTextStyle style;
style.iTextColor = data->state.pen.color().Rgb();
style.iRtl = EFalse;
style.iVisuallyOrdered = EFalse;
style.iLetterSpacing = 0;
style.iWordSpacing = 0;
style.iSmallCaps = EFalse;
style.iFamilies = families;
style.iPadding = 0;
style.iTabWidth = tabWidth;
style.iXpos = xpos;
if (alignmentFlags & Qt::AlignRight)
x -= data->state.font.Renderer()->WidthForRun(run, style);
TWebCoreTextGeometry geometry;
geometry.iPoint = xForm(TPoint(x, y));
data->state.font.Renderer()->DrawRun(*data->iGc, run, style, geometry);
}
void QPainter::drawText(int x, int y, int tabWidth, int xpos, const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor, QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
{
if (data->state.paintingDisabled || len <= 0)
return;
// Avoid allocations, use stack array to pass font families. Normally these
// css fallback lists are small <= 3.
CREATE_FAMILY_ARRAY(data->state.font, families);
if (from < 0)
from = 0;
if (to < 0)
to = len;
TWebCoreTextRun run((const TText *)str, len, from, to);
TWebCoreTextStyle style;
style.iTextColor = data->state.pen.color().Rgb();
style.iBackgroundColor = backgroundColor.isValid() ? backgroundColor.Rgb() :style.iBackgroundColor ;
style.iRtl = d == RTL ? ETrue : EFalse;
style.iVisuallyOrdered = visuallyOrdered;
style.iLetterSpacing = letterSpacing;
style.iWordSpacing = wordSpacing;
style.iSmallCaps = smallCaps;
style.iFamilies = families;
style.iPadding = toAdd;
style.iTabWidth = tabWidth;
style.iXpos = xpos;
TWebCoreTextGeometry geometry;
geometry.iPoint = xForm(TPoint(x, y));
data->state.font.Renderer()->DrawRun(*data->iGc, run, style, geometry);
}
void QPainter::drawHighlightForText(int x, int y, int h, int tabWidth, int xpos,
const QChar *str, int len, int from, int to, int toAdd, const QColor &backgroundColor,
QPainter::TextDirection d, bool visuallyOrdered, int letterSpacing, int wordSpacing, bool smallCaps)
{
if (data->state.paintingDisabled || len <= 0)
return;
int scaledHeight = 0;
if(data->iGc) {
TInt z(data->iGc->View().ScalingFactor());
scaledHeight = h*z/100;
}
// Avoid allocations, use stack array to pass font families. Normally these
// css fallback lists are small <= 3.
CREATE_FAMILY_ARRAY(data->state.font, families);
if (from < 0)
from = 0;
if (to < 0)
to = len;
TWebCoreTextRun run((const TText *)str, len, from, to);
TWebCoreTextStyle style;
style.iTextColor = data->state.pen.color().Rgb();
style.iBackgroundColor = backgroundColor.isValid() ? backgroundColor.Rgb() : TRgb(255,255, 255)/*white*/;
style.iRtl = d == RTL ? ETrue : EFalse;
style.iVisuallyOrdered = visuallyOrdered;
style.iLetterSpacing = letterSpacing;
style.iWordSpacing = wordSpacing;
style.iSmallCaps = smallCaps;
style.iFamilies = families;
style.iPadding = toAdd;
style.iTabWidth = tabWidth;
style.iXpos = xpos;
TWebCoreTextGeometry geometry;
geometry.iPoint = xForm(TPoint(x, y));
geometry.iSelectionHeight = scaledHeight;
geometry.iUseFontMetricsForSelectionYAndHeight = EFalse;
data->state.font.Renderer()->DrawHighlightForRun(*data->iGc, run, style, geometry);
}
void QPainter::drawLineForText(int x, int y, int yOffset, int width)
{
if (data->state.paintingDisabled)
return;
TRgb color = data->state.pen.color().Rgb();
TPoint point = xForm(TPoint(x,y));
if(data->iGc) {
TInt z(data->iGc->View().ScalingFactor());
data->state.font.Renderer()->DrawLineForCharacters(*data->iGc, point, yOffset*z/100, width*z/100, color);
}
}
QColor QPainter::selectedTextBackgroundColor() const
{
QColor secondarySelectedControlColor = QColor("gray");
QColor selectedTextBackgroundColor = QColor("blue");
return _usesInactiveTextBackgroundColor ? secondarySelectedControlColor:selectedTextBackgroundColor;
}
void QPainter::_fillRect(float x, float y, float w, float h, const QColor& col)
{
CFbsBitGc* gContext = NULL;
if(data->iGc) {
gContext = &data->iGc->Gc();
}
if (gContext && w>0 && h>0) {
gContext->SetPenStyle(CGraphicsContext::ENullPen);
gContext->SetBrushColor(col.Rgb());
gContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
TRect t(x, y, (x+w), (y+h));
t = xForm(t);
if (t.Width()==0)
t.iBr.iX++;
if (t.Height()==0)
t.iBr.iY++;
gContext->DrawRect(t);
}
}
void QPainter::fillRect(const QRect &rect, const QBrush &brush)
{
fillRect(rect.left(), rect.top(), rect.width(), rect.height(), brush);
}
void QPainter::fillRect(int x, int y, int w, int h, const QBrush &brush)
{
if (data->state.paintingDisabled)
return;
CFbsBitGc* gContext = NULL;
if(data->iGc) {
gContext = &data->iGc->Gc();
}
if (brush.style() == SolidPattern)
{
setBrush(brush);
_setColorFromBrush();
if (gContext) {
gContext->SetPenStyle(CGraphicsContext::ENullPen);
}
TRect t = TRect(x, y, (x+w), (y+h));
if (gContext) {
gContext->DrawRect(xForm(t));
}
}
}
void QPainter::addClip(const QRect &rect)
{
CFbsBitGc* gContext = NULL;
if (data->iGc)
data->iGc->SetClippingRect(xForm(rect.Rect()));
}
Qt::RasterOp QPainter::rasterOp() const
{
return CopyROP;
}
void QPainter::setRasterOp(RasterOp)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -