Changeset 21517 in webkit
- Timestamp:
- May 16, 2007 6:53:52 AM (17 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r21516 r21517 1 2007-05-16 Zack Rusin <zrusin@trolltech.com> 2 3 Reviewed by Lars. 4 5 Implement bigger parts of the Canvas element in the 6 Qt port. Gradients and patterns are missing. 7 8 * WebCore/html/CanvasRenderingContext2D.cpp: 9 * WebCore/html/CanvasStyle.cpp: 10 * WebCore/html/HTMLCanvasElement.cpp: 11 * WebCore/html/HTMLCanvasElement: 12 1 13 2007-05-16 Zack Rusin <zrusin@trolltech.com> 2 14 -
trunk/WebCore/html/CanvasRenderingContext2D.cpp
r21294 r21517 1 1 /* 2 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2007 Trolltech ASA 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 44 45 #include <wtf/MathExtras.h> 45 46 47 #if PLATFORM(QT) 48 #include <QPainter> 49 #include <QPixmap> 50 #include <QPainterPath> 51 #endif 52 46 53 namespace WebCore { 47 54 … … 446 453 CGContextFillPath(c->platformContext()); 447 454 } 455 #elif PLATFORM(QT) 456 QPainterPath* path = state().m_path.platformPath(); 457 QPainter* p = static_cast<QPainter*>(c->platformContext()); 458 willDraw(path->controlPointRect()); 459 if (state().m_fillStyle->gradient()) { 460 fprintf(stderr, "FIXME: CanvasRenderingContext2D::fill\n"); 461 } else { 462 if (state().m_fillStyle->pattern()) 463 applyFillPattern(); 464 p->fillPath(*path, p->brush()); 465 } 448 466 #endif 449 467 } … … 477 495 CGContextStrokePath(c->platformContext()); 478 496 } 497 #elif PLATFORM(QT) 498 QPainterPath* path = state().m_path.platformPath(); 499 QPainter* p = static_cast<QPainter*>(c->platformContext()); 500 willDraw(path->controlPointRect()); 501 if (state().m_strokeStyle->gradient()) { 502 fprintf(stderr, "FIXME: CanvasRenderingContext2D::stroke\n"); 503 } else { 504 if (state().m_strokeStyle->pattern()) 505 applyStrokePattern(); 506 p->strokePath(*path, p->pen()); 507 } 479 508 #endif 480 509 … … 534 563 applyFillPattern(); 535 564 CGContextFillRect(c->platformContext(), rect); 565 } 566 #elif PLATFORM(QT) 567 QRectF rect(x, y, width, height); 568 willDraw(rect); 569 QPainter* p = static_cast<QPainter*>(c->platformContext()); 570 if (state().m_fillStyle->gradient()) { 571 fprintf(stderr, "FIXME: Canvas gradients\n"); 572 } else { 573 if (state().m_fillStyle->pattern()) 574 applyFillPattern(); 575 p->fillRect(rect, p->brush()); 536 576 } 537 577 #endif … … 853 893 854 894 CGImageRelease(platformImage); 895 #elif PLATFORM(QT) 896 QPixmap px = canvas->createPlatformImage(); 897 if (px.isNull()) 898 return; 899 willDraw(dstRect); 900 QPainter* painter = static_cast<QPainter*>(c->platformContext()); 901 painter->drawPixmap(dstRect, px, srcRect); 855 902 #endif 856 903 } … … 927 974 CGImageRelease(image); 928 975 return pattern; 929 #else 976 #elif PLATFORM(QT) 977 fprintf(stderr, "FIXME: CanvasRenderingContext2D::createPattern patterns not implemented\n"); 978 #endif 930 979 return 0; 931 #endif932 980 } 933 981 … … 976 1024 977 1025 state().m_strokeStylePatternTransform = m; 1026 #elif PLATFORM(QT) 1027 fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyStrokePattern\n"); 978 1028 #endif 979 1029 state().m_appliedStrokePattern = true; … … 1010 1060 1011 1061 state().m_fillStylePatternTransform = m; 1062 #elif PLATFORM(QT) 1063 fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyStrokePattern\n"); 1012 1064 #endif 1013 1065 state().m_appliedFillPattern = true; -
trunk/WebCore/html/CanvasStyle.cpp
r16952 r21517 1 1 /* 2 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2007 Trolltech ASA 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 #include <wtf/PassRefPtr.h> 34 35 36 #if PLATFORM(QT) 37 #include <QPainter> 38 #include <QBrush> 39 #include <QPen> 40 #include <QColor> 41 #endif 42 35 43 namespace WebCore { 36 44 … … 79 87 if (!context) 80 88 return; 89 #if PLATFORM(QT) 90 QPainter* p = static_cast<QPainter*>(context->platformContext()); 91 #endif 81 92 switch (m_type) { 82 93 case ColorString: { … … 89 100 (color & 0xFF) / 255.0, 90 101 ((color >> 24) & 0xFF) / 255.0); 102 #elif PLATFORM(QT) 103 p->setPen(QPen(QColor(QRgb(color)))); 91 104 #endif 92 105 break; … … 101 114 (color & 0xFF) / 255.0, 102 115 m_alpha); 103 #endif 104 break; 105 } 106 case GrayLevel: 116 #elif PLATFORM(QT) 117 QColor clr = QColor(QRgb(color)); 118 clr.setAlphaF(m_alpha); 119 p->setPen(clr); 120 #endif 121 break; 122 } 123 case GrayLevel: { 107 124 // FIXME: Do this through platform-independent GraphicsContext API. 108 125 #if PLATFORM(CG) 109 126 CGContextSetGrayStrokeColor(context->platformContext(), m_grayLevel, m_alpha); 110 #endif 111 break; 112 case RGBA: 127 #elif PLATFORM(QT) 128 QColor clr; 129 clr.setRgbF(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha); 130 p->setPen(clr); 131 #endif 132 break; 133 } 134 case RGBA: { 113 135 // FIXME: Do this through platform-independent GraphicsContext API. 114 136 #if PLATFORM(CG) 115 137 CGContextSetRGBStrokeColor(context->platformContext(), m_red, m_green, m_blue, m_alpha); 116 #endif 117 break; 118 case CMYKA: 138 #elif PLATFORM(QT) 139 QColor clr; clr.setRgbF(m_red, m_green, m_blue, m_alpha); 140 p->setPen(clr); 141 #endif 142 break; 143 } 144 case CMYKA: { 119 145 // FIXME: Do this through platform-independent GraphicsContext API. 120 146 #if PLATFORM(CG) 121 147 CGContextSetCMYKStrokeColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha); 122 #endif 123 break; 148 #elif PLATFORM(QT) 149 QColor clr; 150 clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha); 151 p->setPen(clr); 152 #endif 153 break; 154 } 124 155 case Gradient: 125 156 case ImagePattern: … … 132 163 if (!context) 133 164 return; 165 #if PLATFORM(QT) 166 QPainter* p = static_cast<QPainter*>(context->platformContext()); 167 #endif 134 168 switch (m_type) { 135 169 case ColorString: { … … 142 176 (color & 0xFF) / 255.0, 143 177 ((color >> 24) & 0xFF) / 255.0); 178 #elif PLATFORM(QT) 179 p->setBrush(QColor(QRgb(color))); 144 180 #endif 145 181 break; … … 154 190 (color & 0xFF) / 255.0, 155 191 m_alpha); 156 #endif 157 break; 158 } 159 case GrayLevel: 192 #elif PLATFORM(QT) 193 QColor clr = QColor(QRgb(color)); 194 clr.setAlphaF(m_alpha); 195 p->setBrush(clr); 196 #endif 197 break; 198 } 199 case GrayLevel: { 160 200 // FIXME: Do this through platform-independent GraphicsContext API. 161 201 #if PLATFORM(CG) 162 202 CGContextSetGrayFillColor(context->platformContext(), m_grayLevel, m_alpha); 163 #endif 164 break; 165 case RGBA: 203 #elif PLATFORM(QT) 204 QColor clr; clr.setRgbF(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha); 205 p->setBrush(clr); 206 #endif 207 break; 208 } 209 case RGBA: { 166 210 // FIXME: Do this through platform-independent GraphicsContext API. 167 211 #if PLATFORM(CG) 168 212 CGContextSetRGBFillColor(context->platformContext(), m_red, m_green, m_blue, m_alpha); 169 #endif 170 break; 171 case CMYKA: 213 #elif PLATFORM(QT) 214 QColor clr; clr.setRgbF(m_red, m_green, m_blue, m_alpha); 215 p->setBrush(clr); 216 #endif 217 break; 218 } 219 case CMYKA: { 172 220 // FIXME: Do this through platform-independent GraphicsContext API. 173 221 #if PLATFORM(CG) 174 222 CGContextSetCMYKFillColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha); 175 #endif 176 break; 223 #elif PLATFORM(QT) 224 QColor clr; 225 clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha); 226 p->setBrush(clr); 227 #endif 228 break; 229 } 177 230 case Gradient: 178 231 case ImagePattern: -
trunk/WebCore/html/HTMLCanvasElement.cpp
r21211 r21517 39 39 #include "RenderHTMLCanvas.h" 40 40 #include "Settings.h" 41 42 #if PLATFORM(QT) 43 #include <QPainter> 44 #include <QPixmap> 45 #endif 46 41 47 #include <math.h> 48 42 49 43 50 namespace WebCore { … … 59 66 , m_createdDrawingContext(false) 60 67 , m_data(0) 68 #if PLATFORM(QT) 69 , m_painter(0) 70 #endif 61 71 , m_drawingContext(0) 62 72 { … … 67 77 if (m_2DContext) 68 78 m_2DContext->detachCanvas(); 79 #if PLATFORM(CG) 69 80 fastFree(m_data); 81 #elif PLATFORM(QT) 82 delete m_painter; 83 delete m_data; 84 #endif 70 85 delete m_drawingContext; 71 86 } … … 151 166 bool hadDrawingContext = m_createdDrawingContext; 152 167 m_createdDrawingContext = false; 168 #if PLATFORM(QT) 153 169 fastFree(m_data); 170 #elif PLATFORM(QT) 171 delete m_painter; 172 delete m_data; 173 #endif 154 174 m_data = 0; 155 175 delete m_drawingContext; … … 174 194 CGImageRelease(image); 175 195 } 196 #elif PLATFORM(QT) 197 if (m_data) { 198 if (m_painter->isActive()) 199 m_painter->end(); 200 static_cast<QPainter*>(p->platformContext())->drawPixmap(r, *m_data); 201 } 176 202 #endif 177 203 } … … 199 225 if (bytesPerRow / 4 != w) // check for overflow 200 226 return; 227 #if PLATFORM(CG) 201 228 m_data = fastCalloc(h, bytesPerRow); 229 #elif PLATFORM(QT) 230 m_data = new QPixmap(w, h); 231 #endif 202 232 if (!m_data) 203 233 return; … … 209 239 m_drawingContext = new GraphicsContext(bitmapContext); 210 240 CGContextRelease(bitmapContext); 241 #elif PLATFORM(QT) 242 m_data->fill(Qt::white); 243 m_painter = new QPainter(m_data); 244 m_drawingContext = new GraphicsContext(m_painter); 211 245 #endif 212 246 } … … 235 269 return CGBitmapContextCreateImage(contextRef); 236 270 } 237 238 #endif 239 240 } 271 #elif PLATFORM(QT) 272 QPixmap HTMLCanvasElement::createPlatformImage() const 273 { 274 if (m_data) 275 return *m_data; 276 return QPixmap(); 277 } 278 279 #endif 280 281 } -
trunk/WebCore/html/HTMLCanvasElement.h
r20170 r21517 34 34 typedef struct CGContext* CGContextRef; 35 35 typedef struct CGImage* CGImageRef; 36 #elif PLATFORM(QT) 37 class QPixmap; 38 class QPainter; 36 39 #endif 37 40 … … 71 74 #if PLATFORM(CG) 72 75 CGImageRef createPlatformImage() const; 76 #elif PLATFORM(QT) 77 QPixmap createPlatformImage() const; 73 78 #endif 74 79 … … 86 91 87 92 mutable bool m_createdDrawingContext; 93 #if PLATFORM(CG) 88 94 mutable void* m_data; 95 #elif PLATFORM(QT) 96 mutable QPixmap* m_data; 97 mutable QPainter* m_painter; 98 #endif 89 99 mutable GraphicsContext* m_drawingContext; 90 100 };
Note: See TracChangeset
for help on using the changeset viewer.