Changeset 47360 in webkit
- Timestamp:
- Aug 17, 2009 7:19:13 AM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r47359 r47360 1 2009-08-13 Mike Fenton <mike.fenton@torchmobile.com> 2 3 Reviewed by Adam Treat. 4 5 Style fixes based on cpp_style.py and WebKit Style guide for 6 GraphicsContextCG.cpp 7 8 https://bugs.webkit.org/show_bug.cgi?id=28268 9 10 * platform/graphics/cg/GraphicsContextCG.cpp: 11 (WebCore::GraphicsContext::drawLine): 12 (WebCore::GraphicsContext::drawEllipse): 13 (WebCore::GraphicsContext::strokeArc): 14 (WebCore::GraphicsContext::drawConvexPolygon): 15 (WebCore::GraphicsContext::applyStrokePattern): 16 (WebCore::GraphicsContext::drawPath): 17 (WebCore::GraphicsContext::clipOut): 18 (WebCore::GraphicsContext::clipOutEllipseInRect): 19 (WebCore::GraphicsContext::addInnerRoundedRectClip): 20 (WebCore::GraphicsContext::clipToImageBuffer): 21 (WebCore::GraphicsContext::setPlatformShadow): 22 (WebCore::GraphicsContext::setLineCap): 23 (WebCore::GraphicsContext::setLineJoin): 24 (WebCore::GraphicsContext::roundToDevicePixels): 25 (WebCore::GraphicsContext::drawLineForText): 26 (WebCore::GraphicsContext::setURLForRect): 27 (WebCore::GraphicsContext::setImageInterpolationQuality): 28 (WebCore::GraphicsContext::imageInterpolationQuality): 29 (WebCore::GraphicsContext::setPlatformTextDrawingMode): 30 (WebCore::GraphicsContext::setCompositeOperation): 31 1 32 2009-08-13 Mike Fenton <mike.fenton@torchmobile.com> 2 33 -
trunk/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
r44170 r47360 29 29 #include "GraphicsContext.h" 30 30 31 #include "TransformationMatrix.h"32 31 #include "FloatConversion.h" 32 #include "GraphicsContextPlatformPrivateCG.h" 33 33 #include "GraphicsContextPrivate.h" 34 #include "GraphicsContextPlatformPrivateCG.h"35 34 #include "ImageBuffer.h" 36 35 #include "KURL.h" 37 36 #include "Path.h" 38 37 #include "Pattern.h" 38 #include "TransformationMatrix.h" 39 39 40 #include <CoreGraphics/CGBitmapContext.h> 40 41 #include <CoreGraphics/CGPDFContext.h> … … 179 180 int patWidth = 0; 180 181 switch (strokeStyle()) { 181 182 183 184 185 186 187 188 189 190 } 191 192 CGContextRef context = platformContext(); 193 182 case NoStroke: 183 case SolidStroke: 184 break; 185 case DottedStroke: 186 patWidth = (int)width; 187 break; 188 case DashedStroke: 189 patWidth = 3 * (int)width; 190 break; 191 } 192 193 CGContextRef context = platformContext(); 194 194 195 if (shouldAntialias()) 195 196 CGContextSetShouldAntialias(context, false); … … 222 223 patternOffset = 1.0f; 223 224 else { 224 bool evenNumberOfSegments = numSegments % 2 == 0;225 bool evenNumberOfSegments = !(numSegments % 2); 225 226 if (remainder) 226 227 evenNumberOfSegments = !evenNumberOfSegments; … … 236 237 } 237 238 } 238 239 239 240 const CGFloat dottedLine[2] = { patWidth, patWidth }; 240 241 CGContextSetLineDash(context, patternOffset, dottedLine, 2); … … 249 250 if (patWidth) 250 251 CGContextRestoreGState(context); 251 252 252 253 if (shouldAntialias()) 253 254 CGContextSetShouldAntialias(context, true); … … 264 265 if (paintingDisabled()) 265 266 return; 266 267 267 268 CGContextRef context = platformContext(); 268 269 CGContextBeginPath(context); … … 276 277 277 278 void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan) 278 { 279 { 279 280 if (paintingDisabled() || strokeStyle() == NoStroke || strokeThickness() <= 0.0f) 280 281 return; 281 282 282 283 CGContextRef context = platformContext(); 283 284 CGContextSaveGState(context); 284 285 CGContextBeginPath(context); 285 286 CGContextSetShouldAntialias(context, false); 286 287 287 288 int x = rect.x(); 288 289 int y = rect.y(); … … 291 292 float scaleFactor = h / w; 292 293 float reverseScaleFactor = w / h; 293 294 294 295 if (w != h) 295 296 scale(FloatSize(1, scaleFactor)); 296 297 297 298 float hRadius = w / 2; 298 299 float vRadius = h / 2; … … 305 306 if (w != h) 306 307 scale(FloatSize(1, reverseScaleFactor)); 307 308 308 309 309 float width = strokeThickness(); 310 310 int patWidth = 0; 311 311 312 312 switch (strokeStyle()) { 313 314 315 316 317 318 319 320 321 } 322 313 case DottedStroke: 314 patWidth = (int)(width / 2); 315 break; 316 case DashedStroke: 317 patWidth = 3 * (int)(width / 2); 318 break; 319 default: 320 break; 321 } 322 323 323 if (patWidth) { 324 324 // Example: 80 pixels with a width of 30 pixels. … … 330 330 else // We are elliptical and will have to estimate the distance 331 331 distance = static_cast<int>((piFloat * sqrtf((hRadius * hRadius + vRadius * vRadius) / 2.0f)) / 2.0f); 332 332 333 333 int remainder = distance % patWidth; 334 334 int coverage = distance - remainder; … … 340 340 patternOffset = 1.0f; 341 341 else { 342 bool evenNumberOfSegments = numSegments % 2 == 0;342 bool evenNumberOfSegments = !(numSegments % 2); 343 343 if (remainder) 344 344 evenNumberOfSegments = !evenNumberOfSegments; … … 354 354 } 355 355 } 356 356 357 357 const CGFloat dottedLine[2] = { patWidth, patWidth }; 358 358 CGContextSetLineDash(context, patternOffset, dottedLine, 2); … … 360 360 361 361 CGContextStrokePath(context); 362 362 363 363 CGContextRestoreGState(context); 364 364 } … … 376 376 if (antialiased != shouldAntialias()) 377 377 CGContextSetShouldAntialias(context, antialiased); 378 378 379 379 CGContextBeginPath(context); 380 380 CGContextMoveToPoint(context, points[0].x(), points[0].y()); … … 384 384 385 385 drawPath(); 386 386 387 387 if (antialiased != shouldAntialias()) 388 388 CGContextSetShouldAntialias(context, shouldAntialias()); … … 392 392 { 393 393 CGContextRef cgContext = platformContext(); 394 394 395 395 CGPatternRef platformPattern = m_common->state.strokePattern.get()->createPlatformPattern(getCTM()); 396 396 if (!platformPattern) … … 464 464 return; 465 465 } 466 466 467 467 if (state.fillColorSpace == PatternColorSpace) 468 468 applyFillPattern(); … … 600 600 if (paintingDisabled()) 601 601 return; 602 602 603 603 CGRect rects[2] = { CGContextGetClipBoundingBox(platformContext()), rect }; 604 604 CGContextBeginPath(platformContext()); … … 611 611 if (paintingDisabled()) 612 612 return; 613 613 614 614 CGContextBeginPath(platformContext()); 615 615 CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext())); … … 640 640 clip(rect); 641 641 CGContextRef context = platformContext(); 642 642 643 643 // Add outer ellipse 644 644 CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height())); … … 646 646 CGContextAddEllipseInRect(context, CGRectMake(rect.x() + thickness, rect.y() + thickness, 647 647 rect.width() - (thickness * 2), rect.height() - (thickness * 2))); 648 648 649 649 CGContextEOClip(context); 650 650 } … … 654 654 if (paintingDisabled()) 655 655 return; 656 656 657 657 CGContextTranslateCTM(platformContext(), rect.x(), rect.y() + rect.height()); 658 658 CGContextScaleCTM(platformContext(), 1, -1); … … 735 735 CGContextSetShadowWithColor(context, 736 736 CGSizeMake(width, height), 737 blurRadius, 737 blurRadius, 738 738 colorCG); 739 739 CGColorRelease(colorCG); … … 800 800 return; 801 801 switch (cap) { 802 803 804 805 806 807 808 809 810 802 case ButtCap: 803 CGContextSetLineCap(platformContext(), kCGLineCapButt); 804 break; 805 case RoundCap: 806 CGContextSetLineCap(platformContext(), kCGLineCapRound); 807 break; 808 case SquareCap: 809 CGContextSetLineCap(platformContext(), kCGLineCapSquare); 810 break; 811 811 } 812 812 } … … 822 822 return; 823 823 switch (join) { 824 825 826 827 828 829 830 831 832 824 case MiterJoin: 825 CGContextSetLineJoin(platformContext(), kCGLineJoinMiter); 826 break; 827 case RoundJoin: 828 CGContextSetLineJoin(platformContext(), kCGLineJoinRound); 829 break; 830 case BevelJoin: 831 CGContextSetLineJoin(platformContext(), kCGLineJoinBevel); 832 break; 833 833 } 834 834 } … … 859 859 if (paintingDisabled()) 860 860 return; 861 861 862 862 CGContextBeginPath(platformContext()); 863 863 CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext())); … … 910 910 FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect) 911 911 { 912 // It is not enough just to round to pixels in device space. The rotation part of the 912 // It is not enough just to round to pixels in device space. The rotation part of the 913 913 // affine transform matrix to device space can mess with this conversion if we have a 914 // rotating image like the hands of the world clock widget. We just need the scale, so 914 // rotating image like the hands of the world clock widget. We just need the scale, so 915 915 // we get the affine transform matrix and extract the scale. 916 916 … … 935 935 deviceLowerRight.x = roundf(deviceLowerRight.x); 936 936 deviceLowerRight.y = roundf(deviceLowerRight.y); 937 937 938 938 // Don't let the height or width round to 0 unless either was originally 0 939 if (deviceOrigin.y == deviceLowerRight.y && rect.height() != 0)939 if (deviceOrigin.y == deviceLowerRight.y && rect.height()) 940 940 deviceLowerRight.y += 1; 941 if (deviceOrigin.x == deviceLowerRight.x && rect.width() != 0)941 if (deviceOrigin.x == deviceLowerRight.x && rect.width()) 942 942 deviceLowerRight.x += 1; 943 943 … … 985 985 } 986 986 } 987 987 988 988 if (fillColor() != strokeColor()) 989 989 setCGFillColor(platformContext(), strokeColor()); … … 991 991 if (fillColor() != strokeColor()) 992 992 setCGFillColor(platformContext(), fillColor()); 993 993 994 994 if (restoreAntialiasMode) 995 995 CGContextSetShouldAntialias(platformContext(), true); … … 1000 1000 if (paintingDisabled()) 1001 1001 return; 1002 1002 1003 1003 CFURLRef urlRef = link.createCFURL(); 1004 1004 if (urlRef) { 1005 1005 CGContextRef context = platformContext(); 1006 1006 1007 1007 // Get the bounding box to handle clipping. 1008 1008 CGRect box = CGContextGetClipBoundingBox(context); … … 1023 1023 if (paintingDisabled()) 1024 1024 return; 1025 1025 1026 1026 CGInterpolationQuality quality = kCGInterpolationDefault; 1027 1027 switch (mode) { 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1028 case InterpolationDefault: 1029 quality = kCGInterpolationDefault; 1030 break; 1031 case InterpolationNone: 1032 quality = kCGInterpolationNone; 1033 break; 1034 case InterpolationLow: 1035 quality = kCGInterpolationLow; 1036 break; 1037 1038 // Fall through to InterpolationHigh if kCGInterpolationMedium is not available 1039 case InterpolationMedium: 1040 1040 #if HAVE(CG_INTERPOLATION_MEDIUM) 1041 1042 1041 quality = kCGInterpolationMedium; 1042 break; 1043 1043 #endif 1044 1045 1046 1044 case InterpolationHigh: 1045 quality = kCGInterpolationHigh; 1046 break; 1047 1047 } 1048 1048 CGContextSetInterpolationQuality(platformContext(), quality); … … 1056 1056 CGInterpolationQuality quality = CGContextGetInterpolationQuality(platformContext()); 1057 1057 switch (quality) { 1058 1059 1060 1061 1062 1063 1058 case kCGInterpolationDefault: 1059 return InterpolationDefault; 1060 case kCGInterpolationNone: 1061 return InterpolationNone; 1062 case kCGInterpolationLow: 1063 return InterpolationLow; 1064 1064 #if HAVE(CG_INTERPOLATION_MEDIUM) 1065 1066 1065 case kCGInterpolationMedium: 1066 return InterpolationMedium; 1067 1067 #endif 1068 1069 1068 case kCGInterpolationHigh: 1069 return InterpolationHigh; 1070 1070 } 1071 1071 return InterpolationDefault; … … 1080 1080 CGContextRef context = platformContext(); 1081 1081 switch (mode) { 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1082 case cTextInvisible: // Invisible 1083 CGContextSetTextDrawingMode(context, kCGTextInvisible); 1084 break; 1085 case cTextFill: // Fill 1086 CGContextSetTextDrawingMode(context, kCGTextFill); 1087 break; 1088 case cTextStroke: // Stroke 1089 CGContextSetTextDrawingMode(context, kCGTextStroke); 1090 break; 1091 case 3: // Fill | Stroke 1092 CGContextSetTextDrawingMode(context, kCGTextFillStroke); 1093 break; 1094 case cTextClip: // Clip 1095 CGContextSetTextDrawingMode(context, kCGTextClip); 1096 break; 1097 case 5: // Fill | Clip 1098 CGContextSetTextDrawingMode(context, kCGTextFillClip); 1099 break; 1100 case 6: // Stroke | Clip 1101 CGContextSetTextDrawingMode(context, kCGTextStrokeClip); 1102 break; 1103 case 7: // Fill | Stroke | Clip 1104 CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip); 1105 break; 1106 default: 1107 break; 1108 1108 } 1109 1109 } … … 1139 1139 #ifndef BUILDING_ON_TIGER // Tiger's setCompositeOperation() is defined in GraphicsContextMac.mm. 1140 1140 void GraphicsContext::setCompositeOperation(CompositeOperator mode) 1141 { 1142 if (paintingDisabled()) 1143 return; 1144 1145 CGBlendMode target = kCGBlendModeNormal; 1141 { 1142 if (paintingDisabled()) 1143 return; 1144 1145 CGBlendMode target = kCGBlendModeNormal; 1146 1146 switch (mode) { 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 target = kCGBlendModeSourceAtop;1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1147 case CompositeClear: 1148 target = kCGBlendModeClear; 1149 break; 1150 case CompositeCopy: 1151 target = kCGBlendModeCopy; 1152 break; 1153 case CompositeSourceOver: 1154 //kCGBlendModeNormal 1155 break; 1156 case CompositeSourceIn: 1157 target = kCGBlendModeSourceIn; 1158 break; 1159 case CompositeSourceOut: 1160 target = kCGBlendModeSourceOut; 1161 break; 1162 case CompositeSourceAtop: 1163 target = kCGBlendModeSourceAtop; 1164 break; 1165 case CompositeDestinationOver: 1166 target = kCGBlendModeDestinationOver; 1167 break; 1168 case CompositeDestinationIn: 1169 target = kCGBlendModeDestinationIn; 1170 break; 1171 case CompositeDestinationOut: 1172 target = kCGBlendModeDestinationOut; 1173 break; 1174 case CompositeDestinationAtop: 1175 target = kCGBlendModeDestinationAtop; 1176 break; 1177 case CompositeXOR: 1178 target = kCGBlendModeXOR; 1179 break; 1180 case CompositePlusDarker: 1181 target = kCGBlendModePlusDarker; 1182 break; 1183 case CompositeHighlight: 1184 // currently unsupported 1185 break; 1186 case CompositePlusLighter: 1187 target = kCGBlendModePlusLighter; 1188 break; 1189 1189 } 1190 1190 CGContextSetBlendMode(platformContext(), target);
Note: See TracChangeset
for help on using the changeset viewer.