📄 kwqpainter.cpp
字号:
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, 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;
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, 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;
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,
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;
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)
{
QBrush old = this->brush();
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)
{
}
void QPainter::setPaintingDisabled(bool f)
{
data->state.paintingDisabled = f;
}
bool QPainter::paintingDisabled() const
{
return data->state.paintingDisabled;
}
//CGContextRef QPainter::currentContext()
//{
// return (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
//}
void QPainter::beginTransparencyLayer(float opacity)
{
/* [NSGraphicsContext saveGraphicsState];
CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
CGContextSetAlpha(context, opacity);
CGContextBeginTransparencyLayer(context, 0);*/
}
void QPainter::endTransparencyLayer()
{
/* CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
CGContextEndTransparencyLayer(context);
[NSGraphicsContext restoreGraphicsState];*/
}
void QPainter::setShadow(int x, int y, int blur, const QColor& color)
{
// Check for an invalid color, as this means that the color was not set for the shadow
// and we should therefore just use the default shadow color.
/* CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
if (!color.isValid())
CGContextSetShadow(context, CGSizeMake(x,-y), blur); // y is flipped.
else {
NSColor* deviceColor = [color.getNSColor() colorUsingColorSpaceName: @"NSDeviceRGBColorSpace"];
float red = [deviceColor redComponent];
float green = [deviceColor greenComponent];
float blue = [deviceColor blueComponent];
float alpha = [deviceColor alphaComponent];
const float components[] = { red, green, blue, alpha };
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef color = CGColorCreate(colorSpace, components);
CGColorSpaceRelease(colorSpace);
CGContextSetShadowWithColor(context,
CGSizeMake(x,-y), // y is flipped.
blur,
color);
CGColorRelease(color);
}*/
}
void QPainter::clearShadow()
{
/* CGContextRef context = (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL);*/
}
void QPainter::initFocusRing(int width, int offset)
{
/* if (!_drawsFocusRing)
return;
clearFocusRing();
data->focusRingWidth = width;
data->hasFocusRingColor = false;
data->focusRingOffset = offset;
data->focusRingPath = KWQRetainNSRelease([[NSBezierPath alloc] init]);
[data->focusRingPath setWindingRule:NSNonZeroWindingRule];*/
}
void QPainter::initFocusRing(int width, int offset, const QColor &color)
{
/* if (!_drawsFocusRing)
return;
initFocusRing(width, offset);
data->hasFocusRingColor = true;
data->focusRingColor = color;*/
}
void QPainter::addFocusRingRect(int x, int y, int width, int height)
{
/*if (!_drawsFocusRing)
return;
ASSERT(data->focusRingPath);
NSRect rect = NSMakeRect(x, y, width, height);
int offset = (data->focusRingWidth-1)/2 + data->focusRingOffset;
rect = NSInsetRect(rect, -offset, -offset);
[data->focusRingPath appendBezierPathWithRect:rect];*/
}
void QPainter::drawFocusRing()
{
/* if (!_drawsFocusRing)
return;
ASSERT(data->focusRingPath);
if (data->state.paintingDisabled)
return;
if ([data->focusRingPath elementCount] == 0) {
ERROR("Request to draw focus ring with no control points");
return;
}
NSRect bounds = [data->focusRingPath bounds];
if (!NSIsEmptyRect(bounds)) {
int radius = (data->focusRingWidth-1)/2;
NSColor *color = data->hasFocusRingColor ? data->focusRingColor.getNSColor() : nil;
[NSGraphicsContext saveGraphicsState];
[[WebCoreGraphicsBridge sharedBridge] setFocusRingStyle:NSFocusRingOnly radius:radius color:color];
[data->focusRingPath fill];
[NSGraphicsContext restoreGraphicsState];
}*/
}
void QPainter::clearFocusRing()
{
/* if (data->focusRingPath) {
KWQRelease(data->focusRingPath);
data->focusRingPath = nil;
}*/
}
TPoint QPainter::xForm ( const TPoint & p ) const {
TInt z(data->iGc->View().ScalingFactor());
return TPoint(p.iX*z/100,p.iY*z/100);
};
TRect QPainter::xForm ( const TRect & r ) const {
return TRect(xForm(r.iTl),xForm(r.iBr));
};
TSize QPainter::xForm ( const TSize & s ) const {
TInt z(data->iGc->View().ScalingFactor());
return TSize(s.iWidth*z/100,s.iHeight*z/100);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -