• R/O
  • SSH
  • HTTPS

nes: 提交


Commit MetaInfo

修订版361 (tree)
时间2007-11-29 10:30:42
作者okasaka

Log Message

(Canvas) : Support CSS3COLOR keyword colors.

更改概述

差异

--- es/trunk/cmd/canvas.h (revision 360)
+++ es/trunk/cmd/canvas.h (revision 361)
@@ -57,8 +57,9 @@
5757
5858 #include <string.h>
5959 #include <es.h>
60+#include <es/color.h>
61+#include <es/classFactory.h>
6062 #include <es/handle.h>
61-#include <es/classFactory.h>
6263 #include <es/interlocked.h>
6364 #include <es/list.h>
6465 #include <es/ref.h>
@@ -83,47 +84,6 @@
8384
8485 ICurrentProcess* System();
8586
86-class Rgb
87-{
88- u32 rgba;
89-
90-public:
91- Rgb(u32 rgba = 0)
92- {
93- this->rgba = rgba;
94- }
95-
96- Rgb(u8 r, u8 g, u8 b, u8 a = 255)
97- {
98- rgba = (a << 24) | (b << 16) | (g << 8) | r;
99- }
100-
101- u8 getR()
102- {
103- return (u8) (rgba & 0xff);
104- }
105-
106- u8 getG() const
107- {
108- return (u8) ((rgba >> 8) & 0xff);
109- }
110-
111- u8 getB() const
112- {
113- return (u8) ((rgba >> 16) & 0xff);
114- }
115-
116- u8 getA() const
117- {
118- return (u8) ((rgba >> 24) & 0xff);
119- }
120-
121- operator u32() const
122- {
123- return rgba;
124- }
125-};
126-
12787 class CanvasPattern : public ICanvasPattern
12888 {
12989 Ref ref;
@@ -305,7 +265,7 @@
305265 {
306266 for (int i = 0; i < STYLE_MAX; i++)
307267 {
308- colorStyles[i] = 0; // [check] default?
268+ colorStyles[i] = 0xff000000;
309269 gradientStyles[i] = NULL;
310270 patternStyles[i] = NULL;
311271 }
@@ -370,8 +330,6 @@
370330 return styleStack.getLast();
371331 }
372332
373- static Rgb parseColor(const char* color);
374-
375333 public:
376334 Canvas(cairo_surface_t* surface, int screenWidth, int screenHeight);
377335 ~Canvas();
--- es/trunk/cmd/canvas.cpp (revision 360)
+++ es/trunk/cmd/canvas.cpp (revision 361)
@@ -150,62 +150,6 @@
150150 return cairo_image_surface_get_data (surface);
151151 }
152152
153-Rgb Canvas::
154-parseColor(const char* color)
155-{
156- int r;
157- int g;
158- int b;
159- float a;
160- int ret;
161- if (strnicmp(color, "rgba(", 5) == 0)
162- {
163- ret = sscanf(color + 4, "(%d,%d,%d,%f)", &r, &g, &b, &a);
164- if (ret == 4 &&
165- 0 <= r < 256 &&
166- 0 <= g < 256 &&
167- 0 <= b < 256 &&
168- 0.0 <= a <= 1.0)
169- {
170- float alpha = round(255.0 * a);
171- if (alpha < 0)
172- {
173- alpha = 0.0;
174- }
175- else if (255.0 < alpha)
176- {
177- alpha = 255.0;
178- }
179- return Rgb(r, g, b, alpha);
180- }
181- }
182- else if (strnicmp(color, "rgb(", 4) == 0)
183- {
184- ret = sscanf(color + 3, "(%d,%d,%d)", &r, &g, &b);
185- if (ret == 3 &&
186- 0 <= r < 256 &&
187- 0 <= g < 256 &&
188- 0 <= b < 256)
189- {
190- return Rgb(r, g, b);
191- }
192- }
193- else if (strnicmp(color, "#", 1) == 0 && strlen(color) == 7)
194- {
195- ret = sscanf(color, "#%2x%2x%2x", &r, &g, &b);
196- if (ret == 3 &&
197- 0 <= r < 256 &&
198- 0 <= g < 256 &&
199- 0 <= b < 256)
200- {
201- return Rgb(r, g, b);
202- }
203- }
204-
205- esThrow(EINVAL);
206- return 0;
207-}
208-
209153 void Canvas::
210154 applyStyle(u32 aWhichStyle)
211155 {
@@ -294,7 +238,7 @@
294238 Rgb rgba;
295239 try
296240 {
297- rgba = parseColor(color);
241+ rgba = Rgb(color);
298242 }
299243 catch (...)
300244 {
@@ -1092,7 +1036,7 @@
10921036 Rgb rgba;
10931037 try
10941038 {
1095- rgba = Canvas::parseColor(color);
1039+ rgba = Rgb(color);
10961040 }
10971041 catch (...)
10981042 {
--- es/trunk/esjs/scripts/figure.js (revision 360)
+++ es/trunk/esjs/scripts/figure.js (revision 361)
@@ -1,112 +1,112 @@
1-var c = ICanvasRenderingContext2D(root.lookup("/device/canvas"));
2-
3-// bar graph
4-var top = 50;
5-var bottom = 250;
6-
7-var width = 20;
8-var height;
9-var x;
10-var y;
11-
12-c.strokeStyle = "rgba(0, 0, 0, 1)";
13-
14-height = 100;
15-x = 100;
16-c.lineWidth = 3;
17-c.fillStyle = "rgba(255, 0, 0, 1)";
18-
19-c.fillRect(x, bottom - height, width, height);
20-
21-x += 50;
22-height = 200;
23-c.fillStyle = "rgba(0, 255, 0, 1)";
24-c.fillRect(x, bottom - height, width, height);
25-
26-x += 50;
27-height = 80;
28-c.fillStyle = "rgba(0, 0, 255, 1)";
29-c.fillRect(x, bottom - height, width, height);
30-
31-x += 50;
32-height = 50;
33-c.fillStyle = "rgba(255, 255, 0, 1)";
34-c.fillRect(x, bottom - height, width, height);
35-
36-x += 50;
37-height = 30;
38-c.fillStyle = "rgba(0, 255, 255, 1)";
39-c.fillRect(x, bottom - height, width, height);
40-
41-c.moveTo(80, top);
42-c.lineTo(80, bottom);
43-c.lineTo(350, bottom);
44-c.lineWidth = 4;
45-c.stroke();
46-
47-// circle graph
48-var r = 100; // radius
49-var cx = 180; // center
50-var cy = 450; // center
51-// angle
52-var s = 270/180;
53-var e = 120/180;
54-
55-c.fillStyle = "rgba(255, 0, 0, 1)";
56-c.beginPath();
57-c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
58-c.lineTo(cx, cy);
59-c.closePath();
60-c.fill();
61-
62-s = e;
63-e = 240/180;
64-c.fillStyle = "rgba(0, 255, 0, 1)";
65-c.beginPath();
66-c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
67-c.lineTo(cx, cy);
68-c.closePath();
69-c.fill();
70-
71-s = e;
72-e = 260/180;
73-c.fillStyle = "rgba(0, 0, 255, 1)";
74-c.beginPath();
75-c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
76-c.lineTo(cx, cy);
77-c.closePath();
78-c.fill();
79-
80-s = e;
81-e = 270/180;
82-c.fillStyle = "rgba(255, 255, 0, 1)";
83-c.beginPath();
84-c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
85-c.lineTo(cx, cy);
86-c.closePath();
87-c.fill();
88-
89-c.fillStyle = "rgba(255, 0, 0, 1)";
90-c.moveTo(512, 200);
91-c.textStyle = "36pt Italic Liberation Serif";
92-c.drawText("Hello, world.");
93-
94-c.fillStyle = "rgba(0, 255, 0, 1)";
95-c.moveTo(512, 250);
96-c.textStyle = "40pt Bold Liberation Sans";
97-c.drawText("Hello, world.");
98-
99-c.fillStyle = "rgba(0, 0, 255, 1)";
100-c.moveTo(512, 300);
101-c.textStyle = "48pt Liberation Mono";
102-c.drawText("Hello, world.");
103-
104-c.fillStyle = "rgba(128, 0, 128, 1)";
105-c.moveTo(512, 350);
106-c.textStyle = "48pt Sazanami Gothic";
107-c.drawText("こんにちは、世界。");
108-
109-c.fillStyle = "rgba(0, 128, 128, 1)";
110-c.moveTo(512, 400);
111-c.textStyle = "48pt Sazanami Mincho";
112-c.drawText("こんにちは、世界。");
1+var c = ICanvasRenderingContext2D(root.lookup("/device/canvas"));
2+
3+// bar graph
4+var top = 50;
5+var bottom = 250;
6+
7+var width = 20;
8+var height;
9+var x;
10+var y;
11+
12+c.strokeStyle = "rgb(0, 0, 0)";
13+
14+height = 100;
15+x = 100;
16+c.lineWidth = 3;
17+c.fillStyle = "rgb(255, 0, 0)";
18+
19+c.fillRect(x, bottom - height, width, height);
20+
21+x += 50;
22+height = 200;
23+c.fillStyle = "rgb(0, 255, 0)";
24+c.fillRect(x, bottom - height, width, height);
25+
26+x += 50;
27+height = 80;
28+c.fillStyle = "rgb(0, 0, 255)";
29+c.fillRect(x, bottom - height, width, height);
30+
31+x += 50;
32+height = 50;
33+c.fillStyle = "rgb(255, 255, 0)";
34+c.fillRect(x, bottom - height, width, height);
35+
36+x += 50;
37+height = 30;
38+c.fillStyle = "rgb(0, 255, 255)";
39+c.fillRect(x, bottom - height, width, height);
40+
41+c.moveTo(80, top);
42+c.lineTo(80, bottom);
43+c.lineTo(350, bottom);
44+c.lineWidth = 4;
45+c.stroke();
46+
47+// circle graph
48+var r = 100; // radius
49+var cx = 180; // center
50+var cy = 450; // center
51+// angle
52+var s = 270/180;
53+var e = 120/180;
54+
55+c.fillStyle = "rgb(255, 0, 0)";
56+c.beginPath();
57+c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
58+c.lineTo(cx, cy);
59+c.closePath();
60+c.fill();
61+
62+s = e;
63+e = 240/180;
64+c.fillStyle = "rgb(0, 255, 0)";
65+c.beginPath();
66+c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
67+c.lineTo(cx, cy);
68+c.closePath();
69+c.fill();
70+
71+s = e;
72+e = 260/180;
73+c.fillStyle = "rgb(0, 0, 255)";
74+c.beginPath();
75+c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
76+c.lineTo(cx, cy);
77+c.closePath();
78+c.fill();
79+
80+s = e;
81+e = 270/180;
82+c.fillStyle = "rgb(255, 255, 0)";
83+c.beginPath();
84+c.arc(cx, cy, r, Math.PI * s, Math.PI * e, 0);
85+c.lineTo(cx, cy);
86+c.closePath();
87+c.fill();
88+
89+c.fillStyle = "red";
90+c.moveTo(512, 200);
91+c.textStyle = "36pt Italic Liberation Serif";
92+c.drawText("Hello, world.");
93+
94+c.fillStyle = "lime";
95+c.moveTo(512, 250);
96+c.textStyle = "40pt Bold Liberation Sans";
97+c.drawText("Hello, world.");
98+
99+c.fillStyle = "blue";
100+c.moveTo(512, 300);
101+c.textStyle = "48pt Liberation Mono";
102+c.drawText("Hello, world.");
103+
104+c.fillStyle = "fuchsia";
105+c.moveTo(512, 350);
106+c.textStyle = "48pt Sazanami Gothic";
107+c.drawText("こんにちは、世界。");
108+
109+c.fillStyle = "aqua";
110+c.moveTo(512, 400);
111+c.textStyle = "48pt Sazanami Mincho";
112+c.drawText("こんにちは、世界。");
Show on old repository browser