OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkParsePaint.h" | 8 #include "SkParsePaint.h" |
9 #include "SkTSearch.h" | 9 #include "SkTSearch.h" |
10 #include "SkParse.h" | 10 #include "SkParse.h" |
11 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
12 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
13 | 13 |
14 static SkShader* inflate_shader(const SkDOM& dom, const SkDOM::Node* node) | 14 static SkShader* inflate_shader(const SkDOM& dom, const SkDOM::Node* node) |
15 { | 15 { |
16 if ((node = dom.getFirstChild(node, "shader")) == NULL) | 16 if ((node = dom.getFirstChild(node, "shader")) == nullptr) |
17 return NULL; | 17 return nullptr; |
18 | 18 |
19 const char* str; | 19 const char* str; |
20 | 20 |
21 if (dom.hasAttr(node, "type", "linear-gradient")) | 21 if (dom.hasAttr(node, "type", "linear-gradient")) |
22 { | 22 { |
23 SkColor colors[2]; | 23 SkColor colors[2]; |
24 SkPoint pts[2]; | 24 SkPoint pts[2]; |
25 | 25 |
26 colors[0] = colors[1] = SK_ColorBLACK; // need to initialized the alp
ha to opaque, since FindColor doesn't set it | 26 colors[0] = colors[1] = SK_ColorBLACK; // need to initialized the alp
ha to opaque, since FindColor doesn't set it |
27 if ((str = dom.findAttr(node, "c0")) != NULL && | 27 if ((str = dom.findAttr(node, "c0")) != nullptr && |
28 SkParse::FindColor(str, &colors[0]) && | 28 SkParse::FindColor(str, &colors[0]) && |
29 (str = dom.findAttr(node, "c1")) != NULL && | 29 (str = dom.findAttr(node, "c1")) != nullptr && |
30 SkParse::FindColor(str, &colors[1]) && | 30 SkParse::FindColor(str, &colors[1]) && |
31 dom.findScalars(node, "p0", &pts[0].fX, 2) && | 31 dom.findScalars(node, "p0", &pts[0].fX, 2) && |
32 dom.findScalars(node, "p1", &pts[1].fX, 2)) | 32 dom.findScalars(node, "p1", &pts[1].fX, 2)) |
33 { | 33 { |
34 SkShader::TileMode mode = SkShader::kClamp_TileMode; | 34 SkShader::TileMode mode = SkShader::kClamp_TileMode; |
35 int index; | 35 int index; |
36 | 36 |
37 if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror"))
>= 0) | 37 if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror"))
>= 0) |
38 mode = (SkShader::TileMode)index; | 38 mode = (SkShader::TileMode)index; |
39 return SkGradientShader::CreateLinear(pts, colors, NULL, 2, mode); | 39 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, mode)
; |
40 } | 40 } |
41 } | 41 } |
42 else if (dom.hasAttr(node, "type", "bitmap")) | 42 else if (dom.hasAttr(node, "type", "bitmap")) |
43 { | 43 { |
44 if ((str = dom.findAttr(node, "src")) == NULL) | 44 if ((str = dom.findAttr(node, "src")) == nullptr) |
45 return NULL; | 45 return nullptr; |
46 | 46 |
47 SkBitmap bm; | 47 SkBitmap bm; |
48 | 48 |
49 if (SkImageDecoder::DecodeFile(str, &bm)) | 49 if (SkImageDecoder::DecodeFile(str, &bm)) |
50 { | 50 { |
51 SkShader::TileMode mode = SkShader::kRepeat_TileMode; | 51 SkShader::TileMode mode = SkShader::kRepeat_TileMode; |
52 int index; | 52 int index; |
53 | 53 |
54 if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror"))
>= 0) | 54 if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror"))
>= 0) |
55 mode = (SkShader::TileMode)index; | 55 mode = (SkShader::TileMode)index; |
56 | 56 |
57 return SkShader::CreateBitmapShader(bm, mode, mode); | 57 return SkShader::CreateBitmapShader(bm, mode, mode); |
58 } | 58 } |
59 } | 59 } |
60 return NULL; | 60 return nullptr; |
61 } | 61 } |
62 | 62 |
63 void SkPaint_Inflate(SkPaint* paint, const SkDOM& dom, const SkDOM::Node* node) | 63 void SkPaint_Inflate(SkPaint* paint, const SkDOM& dom, const SkDOM::Node* node) |
64 { | 64 { |
65 SkASSERT(paint); | 65 SkASSERT(paint); |
66 SkASSERT(&dom); | 66 SkASSERT(&dom); |
67 SkASSERT(node); | 67 SkASSERT(node); |
68 | 68 |
69 SkScalar x; | 69 SkScalar x; |
70 | 70 |
(...skipping 29 matching lines...) Expand all Loading... |
100 } | 100 } |
101 | 101 |
102 int index = dom.findList(node, "text-anchor", "left,center,right"); | 102 int index = dom.findList(node, "text-anchor", "left,center,right"); |
103 if (index >= 0) | 103 if (index >= 0) |
104 paint->setTextAlign((SkPaint::Align)index); | 104 paint->setTextAlign((SkPaint::Align)index); |
105 | 105 |
106 SkShader* shader = inflate_shader(dom, node); | 106 SkShader* shader = inflate_shader(dom, node); |
107 if (shader) | 107 if (shader) |
108 paint->setShader(shader)->unref(); | 108 paint->setShader(shader)->unref(); |
109 } | 109 } |
OLD | NEW |