2 Copyright (C) 2011 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "ewk_text_style.h"
23 #include <WebCore/IntPoint.h>
25 struct _Ewk_Text_Style {
26 Ewk_Text_Style_State underlineState;
27 Ewk_Text_Style_State italicState;
28 Ewk_Text_Style_State boldState;
31 Evas_Point startPoint;
50 Eina_Bool hasComposition;
53 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
54 Ewk_Text_Style* ewkTextStyleCreate(const EditorState editorState, const WebCore::IntPoint& startPoint, const WebCore::IntPoint& endPoint)
56 Ewk_Text_Style* textStyle = new Ewk_Text_Style;
58 textStyle->underlineState = static_cast<Ewk_Text_Style_State>(editorState.underlineState);
59 textStyle->italicState = static_cast<Ewk_Text_Style_State>(editorState.italicState);
60 textStyle->boldState = static_cast<Ewk_Text_Style_State>(editorState.boldState);
62 textStyle->position.startPoint.x = startPoint.x();
63 textStyle->position.startPoint.y = startPoint.y();
64 textStyle->position.endPoint.x = endPoint.x();
65 textStyle->position.endPoint.y = endPoint.y();
67 // for example - rgba(255, 255, 255, 255)
68 // for example - rgb(255, 255, 255)
69 if (equalIgnoringCase(editorState.bgColor.left(3), "rgb")) {
70 size_t startPos = editorState.bgColor.find("(");
71 size_t endPos = editorState.bgColor.find(")");
73 String value = editorState.bgColor.substring(startPos + 1, endPos - startPos - 1);
74 Vector<String> colorValues;
75 value.split(",", colorValues);
76 textStyle->bgColor.r = colorValues[0].toInt();
77 textStyle->bgColor.g = colorValues[1].toInt();
78 textStyle->bgColor.b = colorValues[2].toInt();
79 if (equalIgnoringCase(editorState.bgColor.left(4), "rgba"))
80 textStyle->bgColor.a = colorValues[3].toInt();
82 textStyle->bgColor.a = 255;
85 if (equalIgnoringCase(editorState.color.left(3), "rgb")) {
86 size_t startPos = editorState.color.find("(");
87 size_t endPos = editorState.color.find(")");
89 String value = editorState.color.substring(startPos + 1, endPos - startPos - 1);
90 Vector<String> colorValues;
91 value.split(",", colorValues);
92 textStyle->color.r = colorValues[0].toInt();
93 textStyle->color.g = colorValues[1].toInt();
94 textStyle->color.b = colorValues[2].toInt();
95 if (equalIgnoringCase(editorState.color.left(4), "rgba"))
96 textStyle->color.a = colorValues[3].toInt();
98 textStyle->color.a = 255;
101 textStyle->fontSize = eina_stringshare_add(editorState.fontSize.utf8().data());
102 textStyle->hasComposition = editorState.hasComposition;
107 void ewkTextStyleDelete(Ewk_Text_Style* textStyle)
109 EINA_SAFETY_ON_NULL_RETURN(textStyle);
111 if (textStyle->fontSize)
112 eina_stringshare_del(textStyle->fontSize);
118 Ewk_Text_Style_State ewk_text_style_underline_get(Ewk_Text_Style* textStyle)
120 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
121 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
123 return textStyle->underlineState;
125 return EWK_TEXT_STYLE_STATE_FALSE;
129 Ewk_Text_Style_State ewk_text_style_italic_get(Ewk_Text_Style* textStyle)
131 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
132 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
134 return textStyle->italicState;
136 return EWK_TEXT_STYLE_STATE_FALSE;
140 Ewk_Text_Style_State ewk_text_style_bold_get(Ewk_Text_Style* textStyle)
142 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
143 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
145 return textStyle->boldState;
147 return EWK_TEXT_STYLE_STATE_FALSE;
151 Eina_Bool ewk_text_style_position_get(Ewk_Text_Style* textStyle, Evas_Point* startPoint, Evas_Point* endPoint)
153 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
154 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
156 startPoint->x = textStyle->position.startPoint.x;
157 startPoint->y = textStyle->position.startPoint.y;
159 endPoint->x = textStyle->position.endPoint.x;
160 endPoint->y = textStyle->position.endPoint.y;
168 Eina_Bool ewk_text_style_bg_color_get(Ewk_Text_Style* textStyle, int* r, int* g, int* b, int* a)
170 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
171 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
174 *r = textStyle->bgColor.r;
176 *g = textStyle->bgColor.g;
178 *b = textStyle->bgColor.b;
180 *a = textStyle->bgColor.a;
188 Eina_Bool ewk_text_style_color_get(Ewk_Text_Style* textStyle, int* r, int* g, int* b, int* a)
190 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
191 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
194 *r = textStyle->color.r;
196 *g = textStyle->color.g;
198 *b = textStyle->color.b;
200 *a = textStyle->color.a;
208 const char* ewk_text_style_font_size_get(Ewk_Text_Style* textStyle)
210 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, 0);
211 return textStyle->fontSize;
214 Eina_Bool ewk_text_style_has_composition_get(Ewk_Text_Style* textStyle)
216 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
217 return textStyle->hasComposition;