2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2012 Rik Cabanier (cabanier@adobe.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "platform/graphics/GraphicsTypes.h"
30 #include "wtf/Assertions.h"
31 #include "wtf/text/WTFString.h"
35 static const char* const compositeOperatorNames[] = {
51 static const char* const blendOperatorNames[] = {
69 const int numCompositeOperatorNames = WTF_ARRAY_LENGTH(compositeOperatorNames);
70 const int numBlendOperatorNames = WTF_ARRAY_LENGTH(blendOperatorNames);
72 bool parseCompositeAndBlendOperator(const String& s, CompositeOperator& op, WebBlendMode& blendOp)
74 for (int i = 0; i < numCompositeOperatorNames; i++) {
75 if (s == compositeOperatorNames[i]) {
76 op = static_cast<CompositeOperator>(i);
77 blendOp = WebBlendModeNormal;
82 for (int i = 0; i < numBlendOperatorNames; i++) {
83 if (s == blendOperatorNames[i]) {
84 blendOp = static_cast<WebBlendMode>(i);
85 op = CompositeSourceOver;
93 String compositeOperatorName(CompositeOperator op, WebBlendMode blendOp)
96 ASSERT(op < numCompositeOperatorNames);
98 if (blendOp != WebBlendModeNormal)
99 return blendOperatorNames[blendOp];
100 return compositeOperatorNames[op];
103 bool parseLineCap(const String& s, LineCap& cap)
120 String lineCapName(LineCap cap)
124 const char* const names[3] = { "butt", "round", "square" };
128 bool parseLineJoin(const String& s, LineJoin& join)
145 String lineJoinName(LineJoin join)
149 const char* const names[3] = { "miter", "round", "bevel" };
153 String textAlignName(TextAlign align)
157 const char* const names[5] = { "start", "end", "left", "center", "right" };
161 bool parseTextAlign(const String& s, TextAlign& align)
164 align = StartTextAlign;
168 align = EndTextAlign;
172 align = LeftTextAlign;
176 align = CenterTextAlign;
180 align = RightTextAlign;
186 String textBaselineName(TextBaseline baseline)
188 ASSERT(baseline >= 0);
189 ASSERT(baseline < 6);
190 const char* const names[6] = { "alphabetic", "top", "middle", "bottom", "ideographic", "hanging" };
191 return names[baseline];
194 bool parseTextBaseline(const String& s, TextBaseline& baseline)
196 if (s == "alphabetic") {
197 baseline = AlphabeticTextBaseline;
201 baseline = TopTextBaseline;
205 baseline = MiddleTextBaseline;
209 baseline = BottomTextBaseline;
212 if (s == "ideographic") {
213 baseline = IdeographicTextBaseline;
216 if (s == "hanging") {
217 baseline = HangingTextBaseline;