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 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
51 Ewk_Text_Style* ewkTextStyleCreate(int underlineState, int italicState, int boldState, const WebCore::IntPoint& startPoint, const WebCore::IntPoint& endPoint, const String& bgColor, const String& color)
53 Ewk_Text_Style* textStyle = new Ewk_Text_Style;
55 textStyle->underlineState = static_cast<Ewk_Text_Style_State>(underlineState);
56 textStyle->italicState = static_cast<Ewk_Text_Style_State>(italicState);
57 textStyle->boldState = static_cast<Ewk_Text_Style_State>(boldState);
59 textStyle->position.startPoint.x = startPoint.x();
60 textStyle->position.startPoint.y = startPoint.y();
61 textStyle->position.endPoint.x = endPoint.x();
62 textStyle->position.endPoint.y = endPoint.y();
64 // for example - rgba(255, 255, 255, 255)
65 // for example - rgb(255, 255, 255)
66 if (equalIgnoringCase(bgColor.left(3), "rgb")) {
67 size_t startPos = bgColor.find("(");
68 size_t endPos = bgColor.find(")");
70 String value = bgColor.substring(startPos + 1, endPos - startPos - 1);
71 Vector<String> colorValues;
72 value.split(",", colorValues);
73 textStyle->bgColor.r = colorValues[0].toInt();
74 textStyle->bgColor.g = colorValues[1].toInt();
75 textStyle->bgColor.b = colorValues[2].toInt();
76 if (equalIgnoringCase(bgColor.left(4), "rgba"))
77 textStyle->bgColor.a = colorValues[3].toInt();
79 textStyle->bgColor.a = 255;
82 if (equalIgnoringCase(color.left(3), "rgb")) {
83 size_t startPos = color.find("(");
84 size_t endPos = color.find(")");
86 String value = color.substring(startPos + 1, endPos - startPos - 1);
87 Vector<String> colorValues;
88 value.split(",", colorValues);
89 textStyle->color.r = colorValues[0].toInt();
90 textStyle->color.g = colorValues[1].toInt();
91 textStyle->color.b = colorValues[2].toInt();
92 if (equalIgnoringCase(color.left(4), "rgba"))
93 textStyle->color.a = colorValues[3].toInt();
95 textStyle->color.a = 255;
101 void ewkTextStyleDelete(Ewk_Text_Style* textStyle)
103 EINA_SAFETY_ON_NULL_RETURN(textStyle);
109 Ewk_Text_Style_State ewk_text_style_underline_get(Ewk_Text_Style* textStyle)
111 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
112 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
114 return textStyle->underlineState;
116 return EWK_TEXT_STYLE_STATE_FALSE;
120 Ewk_Text_Style_State ewk_text_style_italic_get(Ewk_Text_Style* textStyle)
122 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
123 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
125 return textStyle->italicState;
127 return EWK_TEXT_STYLE_STATE_FALSE;
131 Ewk_Text_Style_State ewk_text_style_bold_get(Ewk_Text_Style* textStyle)
133 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
134 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
136 return textStyle->boldState;
138 return EWK_TEXT_STYLE_STATE_FALSE;
142 Eina_Bool ewk_text_style_position_get(Ewk_Text_Style* textStyle, Evas_Point* startPoint, Evas_Point* endPoint)
144 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
145 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
147 startPoint->x = textStyle->position.startPoint.x;
148 startPoint->y = textStyle->position.startPoint.y;
150 endPoint->x = textStyle->position.endPoint.x;
151 endPoint->y = textStyle->position.endPoint.y;
159 Eina_Bool ewk_text_style_bg_color_get(Ewk_Text_Style* textStyle, int* r, int* g, int* b, int* a)
161 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
162 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
165 *r = textStyle->bgColor.r;
167 *g = textStyle->bgColor.g;
169 *b = textStyle->bgColor.b;
171 *a = textStyle->bgColor.a;
179 Eina_Bool ewk_text_style_color_get(Ewk_Text_Style* textStyle, int* r, int* g, int* b, int* a)
181 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
182 EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
185 *r = textStyle->color.r;
187 *g = textStyle->color.g;
189 *b = textStyle->color.b;
191 *a = textStyle->color.a;