aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-13 18:28:21 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-13 18:28:21 +0000
commit2055454a4edd00aff7f03f36559440a6a63f7500 (patch)
tree5c7455a276f11f9a239ee1b63c36121d59958666 /experimental
parent7a4b9fab286c3c02cca433c2ca36ebd35377de46 (diff)
Add handling alpha values in RRGGBBAA formatted styles.
BUG= R=robertphillips@google.com Author: jcgregorio@google.com Review URL: https://codereview.chromium.org/136553006 git-svn-id: http://skia.googlecode.com/svn/trunk@13052 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r--experimental/SkV8Example/JsContext.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/experimental/SkV8Example/JsContext.cpp b/experimental/SkV8Example/JsContext.cpp
index 5778172f27..047147dc82 100644
--- a/experimental/SkV8Example/JsContext.cpp
+++ b/experimental/SkV8Example/JsContext.cpp
@@ -158,13 +158,14 @@ void JsContext::SetStyle(Local<String> name, Local<Value> value,
const PropertyCallbackInfo<void>& info,
SkPaint& style) {
Local<String> s = value->ToString();
- if (s->Length() != 7) {
+ if (s->Length() != 7 && s->Length() != 9) {
info.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
- info.GetIsolate(), "Invalid fill style format."));
+ info.GetIsolate(),
+ "Invalid fill style format length."));
return;
}
- char buf[8];
+ char buf[10];
s->WriteUtf8(buf, sizeof(buf));
if (buf[0] != '#') {
@@ -174,8 +175,14 @@ void JsContext::SetStyle(Local<String> name, Local<Value> value,
return;
}
+ // Colors can be RRGGBBAA, but SkColor uses ARGB.
long color = strtol(buf+1, NULL, 16);
- style.setColor(SkColorSetA(SkColor(color), SK_AlphaOPAQUE));
+ uint32_t alpha = SK_AlphaOPAQUE;
+ if (s->Length() == 9) {
+ alpha = color & 0xFF;
+ color >>= 8;
+ }
+ style.setColor(SkColorSetA(SkColor(color), alpha));
}
void JsContext::GetFillStyle(Local<String> name,