WebCore:
Add a Color(CGColorRef) constructor
Reviewed by Darin.
* platform/graphics/Color.h:
* platform/graphics/cg/ColorCG.cpp:
(WebCore::Color::Color): Added.
WebKit/win:
Take advantage of the new Color constructor that takes a CGColorRef
This lets us handle grayscale colors (which only have 2 components).
Reviewed by Darin.
* WebKitGraphics.cpp:
(DrawTextAtPoint):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28067
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2007-11-26 Adam Roben <aroben@apple.com>
+
+ Add a Color(CGColorRef) constructor
+
+ Reviewed by Darin.
+
+ * platform/graphics/Color.h:
+ * platform/graphics/cg/ColorCG.cpp:
+ (WebCore::Color::Color): Added.
+
2007-11-26 Adele Peterson <adele@apple.com>
Reviewed by Darin.
operator wxColour() const;
#endif
+#if PLATFORM(CG)
+ Color(CGColorRef);
+#endif
+
static bool parseHexColor(const String& name, RGBA32& rgb);
static const RGBA32 black = 0xFF000000;
namespace WebCore {
+Color::Color(CGColorRef color)
+{
+ if (!color) {
+ m_color = 0;
+ m_valid = false;
+ return;
+ }
+
+ size_t numComponents = CGColorGetNumberOfComponents(color);
+ const CGFloat* components = CGColorGetComponents(color);
+
+ float r = 0;
+ float g = 0;
+ float b = 0;
+ float a = 0;
+
+ switch (numComponents) {
+ case 2:
+ r = g = b = components[0];
+ a = components[1];
+ break;
+ case 4:
+ r = components[0];
+ g = components[1];
+ b = components[2];
+ a = components[3];
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ m_color = makeRGBA(r * 255, g * 255, b * 255, a * 255);
+}
+
#if !PLATFORM(MAC)
CGColorRef cgColor(const Color& c)
+2007-11-26 Adam Roben <aroben@apple.com>
+
+ Take advantage of the new Color constructor that takes a CGColorRef
+
+ This lets us handle grayscale colors (which only have 2 components).
+
+ Reviewed by Darin.
+
+ * WebKitGraphics.cpp:
+ (DrawTextAtPoint):
+
2007-11-26 Steve Falkenburg <sfalken@apple.com>
Build fix.
{
GraphicsContext context(cgContext);
- ASSERT(CGColorGetNumberOfComponents(color) == 4); // this code assumes the CGColorRef has 4 components
- const CGFloat* components = CGColorGetComponents(color);
- Color textColor((int)(components[0] * 255), (int)(components[1] * 255), (int)(components[2] * 255), (int)(components[3] * 255));
-
String drawString(text, length);
if (drawAsPassword)
drawString = drawString.impl()->secure(WebCore::bullet);
- WebCoreDrawTextAtPoint(context, drawString, point, makeFont(description), textColor, underlinedIndex);
+ WebCoreDrawTextAtPoint(context, drawString, point, makeFont(description), color, underlinedIndex);
}
void WebDrawText(WebTextRenderInfo* info)