• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "GraphicsTypes.h"
28 
29 #include "PlatformString.h"
30 #include <wtf/Assertions.h>
31 
32 namespace WebCore {
33 
34 static const char* const compositeOperatorNames[] = {
35     "clear",
36     "copy",
37     "source-over",
38     "source-in",
39     "source-out",
40     "source-atop",
41     "destination-over",
42     "destination-in",
43     "destination-out",
44     "destination-atop",
45     "xor",
46     "darker",
47     "highlight",
48     "lighter"
49 };
50 const int numCompositeOperatorNames = sizeof(compositeOperatorNames) / sizeof(compositeOperatorNames[0]);
51 
parseCompositeOperator(const String & s,CompositeOperator & op)52 bool parseCompositeOperator(const String& s, CompositeOperator& op)
53 {
54     for (int i = 0; i < numCompositeOperatorNames; i++)
55         if (s == compositeOperatorNames[i]) {
56             op = static_cast<CompositeOperator>(i);
57             return true;
58         }
59     return false;
60 }
61 
compositeOperatorName(CompositeOperator op)62 String compositeOperatorName(CompositeOperator op)
63 {
64     ASSERT(op >= 0);
65     ASSERT(op < numCompositeOperatorNames);
66     return compositeOperatorNames[op];
67 }
68 
parseLineCap(const String & s,LineCap & cap)69 bool parseLineCap(const String& s, LineCap& cap)
70 {
71     if (s == "butt") {
72         cap = ButtCap;
73         return true;
74     }
75     if (s == "round") {
76         cap = RoundCap;
77         return true;
78     }
79     if (s == "square") {
80         cap = SquareCap;
81         return true;
82     }
83     return false;
84 }
85 
lineCapName(LineCap cap)86 String lineCapName(LineCap cap)
87 {
88     ASSERT(cap >= 0);
89     ASSERT(cap < 3);
90     const char* const names[3] = { "butt", "round", "square" };
91     return names[cap];
92 }
93 
parseLineJoin(const String & s,LineJoin & join)94 bool parseLineJoin(const String& s, LineJoin& join)
95 {
96     if (s == "miter") {
97         join = MiterJoin;
98         return true;
99     }
100     if (s == "round") {
101         join = RoundJoin;
102         return true;
103     }
104     if (s == "bevel") {
105         join = BevelJoin;
106         return true;
107     }
108     return false;
109 }
110 
lineJoinName(LineJoin join)111 String lineJoinName(LineJoin join)
112 {
113     ASSERT(join >= 0);
114     ASSERT(join < 3);
115     const char* const names[3] = { "miter", "round", "bevel" };
116     return names[join];
117 }
118 
textAlignName(TextAlign align)119 String textAlignName(TextAlign align)
120 {
121     ASSERT(align >= 0);
122     ASSERT(align < 5);
123     const char* const names[5] = { "start", "end", "left", "center", "right" };
124     return names[align];
125 }
126 
parseTextAlign(const String & s,TextAlign & align)127 bool parseTextAlign(const String& s, TextAlign& align)
128 {
129     if (s == "start") {
130         align = StartTextAlign;
131         return true;
132     }
133     if (s == "end") {
134         align = EndTextAlign;
135         return true;
136     }
137     if (s == "left") {
138         align = LeftTextAlign;
139         return true;
140     }
141     if (s == "center") {
142         align = CenterTextAlign;
143         return true;
144     }
145     if (s == "right") {
146         align = RightTextAlign;
147         return true;
148     }
149     return false;
150 }
151 
textBaselineName(TextBaseline baseline)152 String textBaselineName(TextBaseline baseline)
153 {
154     ASSERT(baseline >= 0);
155     ASSERT(baseline < 6);
156     const char* const names[6] = { "alphabetic", "top", "middle", "bottom", "ideographic", "hanging" };
157     return names[baseline];
158 }
159 
parseTextBaseline(const String & s,TextBaseline & baseline)160 bool parseTextBaseline(const String& s, TextBaseline& baseline)
161 {
162     if (s == "alphabetic") {
163         baseline = AlphabeticTextBaseline;
164         return true;
165     }
166     if (s == "top") {
167         baseline = TopTextBaseline;
168         return true;
169     }
170     if (s == "middle") {
171         baseline = MiddleTextBaseline;
172         return true;
173     }
174     if (s == "bottom") {
175         baseline = BottomTextBaseline;
176         return true;
177     }
178     if (s == "ideographic") {
179         baseline = IdeographicTextBaseline;
180         return true;
181     }
182     if (s == "hanging") {
183         baseline = HangingTextBaseline;
184         return true;
185     }
186     return false;
187 }
188 
189 }
190