1 #include "evas_font_private.h"
2
3 #define PROPS_CHANGE(Props) Props->changed = EINA_TRUE;
4
5
6 /* X11 colors
7 * https://gitlab.freedesktop.org/xorg/xserver/blob/master/os/oscolor.c
8 */
9
10 typedef struct _Color_Name_Value Color_Name_Value;
11
12 struct _Color_Name_Value
13 {
14 char *name;
15 /*color name will not exceed 255 byte*/
16 unsigned char name_len;
17 unsigned char r;
18 unsigned char g;
19 unsigned char b;
20 };
21
22 #define COLOR_NAME(name,r,g,b) {name,(unsigned char)strlen(name),r,g,b}
23
24 /**
25 * @internal
26 * @var color_name_value_sorted[]
27 * This array consists of Color Name Value structure sorted by name string
28 * And new added value must be placed sorted position
29 */
30
31 static const Color_Name_Value color_name_value_sorted[] = {
32 COLOR_NAME("aliceblue",240,248,255),
33 COLOR_NAME("antiquewhite",250,235,215),
34 COLOR_NAME("antiquewhite1",255,239,219),
35 COLOR_NAME("antiquewhite2",238,223,204),
36 COLOR_NAME("antiquewhite3",205,192,176),
37 COLOR_NAME("antiquewhite4",139,131,120),
38 COLOR_NAME("aqua",0,255,255),
39 COLOR_NAME("aquamarine",127,255,212),
40 COLOR_NAME("aquamarine1",127,255,212),
41 COLOR_NAME("aquamarine2",118,238,198),
42 COLOR_NAME("aquamarine3",102,205,170),
43 COLOR_NAME("aquamarine4",69,139,116),
44 COLOR_NAME("azure",240,255,255),
45 COLOR_NAME("azure1",240,255,255),
46 COLOR_NAME("azure2",224,238,238),
47 COLOR_NAME("azure3",193,205,205),
48 COLOR_NAME("azure4",131,139,139),
49 COLOR_NAME("beige",245,245,220),
50 COLOR_NAME("bisque",255,228,196),
51 COLOR_NAME("bisque1",255,228,196),
52 COLOR_NAME("bisque2",238,213,183),
53 COLOR_NAME("bisque3",205,183,158),
54 COLOR_NAME("bisque4",139,125,107),
55 COLOR_NAME("black",0,0,0),
56 COLOR_NAME("blanchedalmond",255,235,205),
57 COLOR_NAME("blue",0,0,255),
58 COLOR_NAME("blueviolet",138,43,226),
59 COLOR_NAME("blue1",0,0,255),
60 COLOR_NAME("blue2",0,0,238),
61 COLOR_NAME("blue3",0,0,205),
62 COLOR_NAME("blue4",0,0,139),
63 COLOR_NAME("brown",165,42,42),
64 COLOR_NAME("brown1",255,64,64),
65 COLOR_NAME("brown2",238,59,59),
66 COLOR_NAME("brown3",205,51,51),
67 COLOR_NAME("brown4",139,35,35),
68 COLOR_NAME("burlywood",222,184,135),
69 COLOR_NAME("burlywood1",255,211,155),
70 COLOR_NAME("burlywood2",238,197,145),
71 COLOR_NAME("burlywood3",205,170,125),
72 COLOR_NAME("burlywood4",139,115,85),
73 COLOR_NAME("cadetblue",95,158,160),
74 COLOR_NAME("cadetblue1",152,245,255),
75 COLOR_NAME("cadetblue2",142,229,238),
76 COLOR_NAME("cadetblue3",122,197,205),
77 COLOR_NAME("cadetblue4",83,134,139),
78 COLOR_NAME("chartreuse",127,255,0),
79 COLOR_NAME("chartreuse1",127,255,0),
80 COLOR_NAME("chartreuse2",118,238,0),
81 COLOR_NAME("chartreuse3",102,205,0),
82 COLOR_NAME("chartreuse4",69,139,0),
83 COLOR_NAME("chocolate",210,105,30),
84 COLOR_NAME("chocolate1",255,127,36),
85 COLOR_NAME("chocolate2",238,118,33),
86 COLOR_NAME("chocolate3",205,102,29),
87 COLOR_NAME("chocolate4",139,69,19),
88 COLOR_NAME("coral",255,127,80),
89 COLOR_NAME("coral1",255,114,86),
90 COLOR_NAME("coral2",238,106,80),
91 COLOR_NAME("coral3",205,91,69),
92 COLOR_NAME("coral4",139,62,47),
93 COLOR_NAME("cornflowerblue",100,149,237),
94 COLOR_NAME("cornsilk",255,248,220),
95 COLOR_NAME("cornsilk1",255,248,220),
96 COLOR_NAME("cornsilk2",238,232,205),
97 COLOR_NAME("cornsilk3",205,200,177),
98 COLOR_NAME("cornsilk4",139,136,120),
99 COLOR_NAME("crimson",220,20,60),
100 COLOR_NAME("cyan",0,255,255),
101 COLOR_NAME("cyan1",0,255,255),
102 COLOR_NAME("cyan2",0,238,238),
103 COLOR_NAME("cyan3",0,205,205),
104 COLOR_NAME("cyan4",0,139,139),
105 COLOR_NAME("darkblue",0,0,139),
106 COLOR_NAME("darkcyan",0,139,139),
107 COLOR_NAME("darkgoldenrod",184,134,11),
108 COLOR_NAME("darkgray",169,169,169),
109 COLOR_NAME("darkgreen",0,100,0),
110 COLOR_NAME("darkgrey",169,169,169),
111 COLOR_NAME("darkkhaki",189,183,107),
112 COLOR_NAME("darkmagenta",139,0,139),
113 COLOR_NAME("darkolivegreen",85,107,47),
114 COLOR_NAME("darkorange",255,140,0),
115 COLOR_NAME("darkorchid",153,50,204),
116 COLOR_NAME("darkred",139,0,0),
117 COLOR_NAME("darksalmon",233,150,122),
118 COLOR_NAME("darkseagreen",143,188,143),
119 COLOR_NAME("darkslateblue",72,61,139),
120 COLOR_NAME("darkslategray",47,79,79),
121 COLOR_NAME("darkslategrey",47,79,79),
122 COLOR_NAME("darkturquoise",0,206,209),
123 COLOR_NAME("darkviolet",148,0,211),
124 COLOR_NAME("darkgoldenrod1",255,185,15),
125 COLOR_NAME("darkgoldenrod2",238,173,14),
126 COLOR_NAME("darkgoldenrod3",205,149,12),
127 COLOR_NAME("darkgoldenrod4",139,101,8),
128 COLOR_NAME("darkolivegreen1",202,255,112),
129 COLOR_NAME("darkolivegreen2",188,238,104),
130 COLOR_NAME("darkolivegreen3",162,205,90),
131 COLOR_NAME("darkolivegreen4",110,139,61),
132 COLOR_NAME("darkorange1",255,127,0),
133 COLOR_NAME("darkorange2",238,118,0),
134 COLOR_NAME("darkorange3",205,102,0),
135 COLOR_NAME("darkorange4",139,69,0),
136 COLOR_NAME("darkorchid1",191,62,255),
137 COLOR_NAME("darkorchid2",178,58,238),
138 COLOR_NAME("darkorchid3",154,50,205),
139 COLOR_NAME("darkorchid4",104,34,139),
140 COLOR_NAME("darkseagreen1",193,255,193),
141 COLOR_NAME("darkseagreen2",180,238,180),
142 COLOR_NAME("darkseagreen3",155,205,155),
143 COLOR_NAME("darkseagreen4",105,139,105),
144 COLOR_NAME("darkslategray1",151,255,255),
145 COLOR_NAME("darkslategray2",141,238,238),
146 COLOR_NAME("darkslategray3",121,205,205),
147 COLOR_NAME("darkslategray4",82,139,139),
148 COLOR_NAME("deeppink",255,20,147),
149 COLOR_NAME("deepskyblue",0,191,255),
150 COLOR_NAME("deeppink1",255,20,147),
151 COLOR_NAME("deeppink2",238,18,137),
152 COLOR_NAME("deeppink3",205,16,118),
153 COLOR_NAME("deeppink4",139,10,80),
154 COLOR_NAME("deepskyblue1",0,191,255),
155 COLOR_NAME("deepskyblue2",0,178,238),
156 COLOR_NAME("deepskyblue3",0,154,205),
157 COLOR_NAME("deepskyblue4",0,104,139),
158 COLOR_NAME("dimgray",105,105,105),
159 COLOR_NAME("dimgrey",105,105,105),
160 COLOR_NAME("dodgerblue",30,144,255),
161 COLOR_NAME("dodgerblue1",30,144,255),
162 COLOR_NAME("dodgerblue2",28,134,238),
163 COLOR_NAME("dodgerblue3",24,116,205),
164 COLOR_NAME("dodgerblue4",16,78,139),
165 COLOR_NAME("firebrick",178,34,34),
166 COLOR_NAME("firebrick1",255,48,48),
167 COLOR_NAME("firebrick2",238,44,44),
168 COLOR_NAME("firebrick3",205,38,38),
169 COLOR_NAME("firebrick4",139,26,26),
170 COLOR_NAME("floralwhite",255,250,240),
171 COLOR_NAME("forestgreen",34,139,34),
172 COLOR_NAME("fuchsia",255,0,255),
173 COLOR_NAME("gainsboro",220,220,220),
174 COLOR_NAME("ghostwhite",248,248,255),
175 COLOR_NAME("gold",255,215,0),
176 COLOR_NAME("gold1",255,215,0),
177 COLOR_NAME("gold2",238,201,0),
178 COLOR_NAME("gold3",205,173,0),
179 COLOR_NAME("gold4",139,117,0),
180 COLOR_NAME("goldenrod",218,165,32),
181 COLOR_NAME("goldenrod1",255,193,37),
182 COLOR_NAME("goldenrod2",238,180,34),
183 COLOR_NAME("goldenrod3",205,155,29),
184 COLOR_NAME("goldenrod4",139,105,20),
185 COLOR_NAME("gray",190,190,190),
186 COLOR_NAME("gray0",0,0,0),
187 COLOR_NAME("gray1",3,3,3),
188 COLOR_NAME("gray10",26,26,26),
189 COLOR_NAME("gray100",255,255,255),
190 COLOR_NAME("gray11",28,28,28),
191 COLOR_NAME("gray12",31,31,31),
192 COLOR_NAME("gray13",33,33,33),
193 COLOR_NAME("gray14",36,36,36),
194 COLOR_NAME("gray15",38,38,38),
195 COLOR_NAME("gray16",41,41,41),
196 COLOR_NAME("gray17",43,43,43),
197 COLOR_NAME("gray18",46,46,46),
198 COLOR_NAME("gray19",48,48,48),
199 COLOR_NAME("gray2",5,5,5),
200 COLOR_NAME("gray20",51,51,51),
201 COLOR_NAME("gray21",54,54,54),
202 COLOR_NAME("gray22",56,56,56),
203 COLOR_NAME("gray23",59,59,59),
204 COLOR_NAME("gray24",61,61,61),
205 COLOR_NAME("gray25",64,64,64),
206 COLOR_NAME("gray26",66,66,66),
207 COLOR_NAME("gray27",69,69,69),
208 COLOR_NAME("gray28",71,71,71),
209 COLOR_NAME("gray29",74,74,74),
210 COLOR_NAME("gray3",8,8,8),
211 COLOR_NAME("gray30",77,77,77),
212 COLOR_NAME("gray31",79,79,79),
213 COLOR_NAME("gray32",82,82,82),
214 COLOR_NAME("gray33",84,84,84),
215 COLOR_NAME("gray34",87,87,87),
216 COLOR_NAME("gray35",89,89,89),
217 COLOR_NAME("gray36",92,92,92),
218 COLOR_NAME("gray37",94,94,94),
219 COLOR_NAME("gray38",97,97,97),
220 COLOR_NAME("gray39",99,99,99),
221 COLOR_NAME("gray4",10,10,10),
222 COLOR_NAME("gray40",102,102,102),
223 COLOR_NAME("gray41",105,105,105),
224 COLOR_NAME("gray42",107,107,107),
225 COLOR_NAME("gray43",110,110,110),
226 COLOR_NAME("gray44",112,112,112),
227 COLOR_NAME("gray45",115,115,115),
228 COLOR_NAME("gray46",117,117,117),
229 COLOR_NAME("gray47",120,120,120),
230 COLOR_NAME("gray48",122,122,122),
231 COLOR_NAME("gray49",125,125,125),
232 COLOR_NAME("gray5",13,13,13),
233 COLOR_NAME("gray50",127,127,127),
234 COLOR_NAME("gray51",130,130,130),
235 COLOR_NAME("gray52",133,133,133),
236 COLOR_NAME("gray53",135,135,135),
237 COLOR_NAME("gray54",138,138,138),
238 COLOR_NAME("gray55",140,140,140),
239 COLOR_NAME("gray56",143,143,143),
240 COLOR_NAME("gray57",145,145,145),
241 COLOR_NAME("gray58",148,148,148),
242 COLOR_NAME("gray59",150,150,150),
243 COLOR_NAME("gray6",15,15,15),
244 COLOR_NAME("gray60",153,153,153),
245 COLOR_NAME("gray61",156,156,156),
246 COLOR_NAME("gray62",158,158,158),
247 COLOR_NAME("gray63",161,161,161),
248 COLOR_NAME("gray64",163,163,163),
249 COLOR_NAME("gray65",166,166,166),
250 COLOR_NAME("gray66",168,168,168),
251 COLOR_NAME("gray67",171,171,171),
252 COLOR_NAME("gray68",173,173,173),
253 COLOR_NAME("gray69",176,176,176),
254 COLOR_NAME("gray7",18,18,18),
255 COLOR_NAME("gray70",179,179,179),
256 COLOR_NAME("gray71",181,181,181),
257 COLOR_NAME("gray72",184,184,184),
258 COLOR_NAME("gray73",186,186,186),
259 COLOR_NAME("gray74",189,189,189),
260 COLOR_NAME("gray75",191,191,191),
261 COLOR_NAME("gray76",194,194,194),
262 COLOR_NAME("gray77",196,196,196),
263 COLOR_NAME("gray78",199,199,199),
264 COLOR_NAME("gray79",201,201,201),
265 COLOR_NAME("gray8",20,20,20),
266 COLOR_NAME("gray80",204,204,204),
267 COLOR_NAME("gray81",207,207,207),
268 COLOR_NAME("gray82",209,209,209),
269 COLOR_NAME("gray83",212,212,212),
270 COLOR_NAME("gray84",214,214,214),
271 COLOR_NAME("gray85",217,217,217),
272 COLOR_NAME("gray86",219,219,219),
273 COLOR_NAME("gray87",222,222,222),
274 COLOR_NAME("gray88",224,224,224),
275 COLOR_NAME("gray89",227,227,227),
276 COLOR_NAME("gray9",23,23,23),
277 COLOR_NAME("gray90",229,229,229),
278 COLOR_NAME("gray91",232,232,232),
279 COLOR_NAME("gray92",235,235,235),
280 COLOR_NAME("gray93",237,237,237),
281 COLOR_NAME("gray94",240,240,240),
282 COLOR_NAME("gray95",242,242,242),
283 COLOR_NAME("gray96",245,245,245),
284 COLOR_NAME("gray97",247,247,247),
285 COLOR_NAME("gray98",250,250,250),
286 COLOR_NAME("gray99",252,252,252),
287 COLOR_NAME("green",0,255,0),
288 COLOR_NAME("greenyellow",173,255,47),
289 COLOR_NAME("green1",0,255,0),
290 COLOR_NAME("green2",0,238,0),
291 COLOR_NAME("green3",0,205,0),
292 COLOR_NAME("green4",0,139,0),
293 COLOR_NAME("grey",190,190,190),
294 COLOR_NAME("grey0",0,0,0),
295 COLOR_NAME("grey1",3,3,3),
296 COLOR_NAME("grey10",26,26,26),
297 COLOR_NAME("grey100",255,255,255),
298 COLOR_NAME("grey11",28,28,28),
299 COLOR_NAME("grey12",31,31,31),
300 COLOR_NAME("grey13",33,33,33),
301 COLOR_NAME("grey14",36,36,36),
302 COLOR_NAME("grey15",38,38,38),
303 COLOR_NAME("grey16",41,41,41),
304 COLOR_NAME("grey17",43,43,43),
305 COLOR_NAME("grey18",46,46,46),
306 COLOR_NAME("grey19",48,48,48),
307 COLOR_NAME("grey2",5,5,5),
308 COLOR_NAME("grey20",51,51,51),
309 COLOR_NAME("grey21",54,54,54),
310 COLOR_NAME("grey22",56,56,56),
311 COLOR_NAME("grey23",59,59,59),
312 COLOR_NAME("grey24",61,61,61),
313 COLOR_NAME("grey25",64,64,64),
314 COLOR_NAME("grey26",66,66,66),
315 COLOR_NAME("grey27",69,69,69),
316 COLOR_NAME("grey28",71,71,71),
317 COLOR_NAME("grey29",74,74,74),
318 COLOR_NAME("grey3",8,8,8),
319 COLOR_NAME("grey30",77,77,77),
320 COLOR_NAME("grey31",79,79,79),
321 COLOR_NAME("grey32",82,82,82),
322 COLOR_NAME("grey33",84,84,84),
323 COLOR_NAME("grey34",87,87,87),
324 COLOR_NAME("grey35",89,89,89),
325 COLOR_NAME("grey36",92,92,92),
326 COLOR_NAME("grey37",94,94,94),
327 COLOR_NAME("grey38",97,97,97),
328 COLOR_NAME("grey39",99,99,99),
329 COLOR_NAME("grey4",10,10,10),
330 COLOR_NAME("grey40",102,102,102),
331 COLOR_NAME("grey41",105,105,105),
332 COLOR_NAME("grey42",107,107,107),
333 COLOR_NAME("grey43",110,110,110),
334 COLOR_NAME("grey44",112,112,112),
335 COLOR_NAME("grey45",115,115,115),
336 COLOR_NAME("grey46",117,117,117),
337 COLOR_NAME("grey47",120,120,120),
338 COLOR_NAME("grey48",122,122,122),
339 COLOR_NAME("grey49",125,125,125),
340 COLOR_NAME("grey5",13,13,13),
341 COLOR_NAME("grey50",127,127,127),
342 COLOR_NAME("grey51",130,130,130),
343 COLOR_NAME("grey52",133,133,133),
344 COLOR_NAME("grey53",135,135,135),
345 COLOR_NAME("grey54",138,138,138),
346 COLOR_NAME("grey55",140,140,140),
347 COLOR_NAME("grey56",143,143,143),
348 COLOR_NAME("grey57",145,145,145),
349 COLOR_NAME("grey58",148,148,148),
350 COLOR_NAME("grey59",150,150,150),
351 COLOR_NAME("grey6",15,15,15),
352 COLOR_NAME("grey60",153,153,153),
353 COLOR_NAME("grey61",156,156,156),
354 COLOR_NAME("grey62",158,158,158),
355 COLOR_NAME("grey63",161,161,161),
356 COLOR_NAME("grey64",163,163,163),
357 COLOR_NAME("grey65",166,166,166),
358 COLOR_NAME("grey66",168,168,168),
359 COLOR_NAME("grey67",171,171,171),
360 COLOR_NAME("grey68",173,173,173),
361 COLOR_NAME("grey69",176,176,176),
362 COLOR_NAME("grey7",18,18,18),
363 COLOR_NAME("grey70",179,179,179),
364 COLOR_NAME("grey71",181,181,181),
365 COLOR_NAME("grey72",184,184,184),
366 COLOR_NAME("grey73",186,186,186),
367 COLOR_NAME("grey74",189,189,189),
368 COLOR_NAME("grey75",191,191,191),
369 COLOR_NAME("grey76",194,194,194),
370 COLOR_NAME("grey77",196,196,196),
371 COLOR_NAME("grey78",199,199,199),
372 COLOR_NAME("grey79",201,201,201),
373 COLOR_NAME("grey8",20,20,20),
374 COLOR_NAME("grey80",204,204,204),
375 COLOR_NAME("grey81",207,207,207),
376 COLOR_NAME("grey82",209,209,209),
377 COLOR_NAME("grey83",212,212,212),
378 COLOR_NAME("grey84",214,214,214),
379 COLOR_NAME("grey85",217,217,217),
380 COLOR_NAME("grey86",219,219,219),
381 COLOR_NAME("grey87",222,222,222),
382 COLOR_NAME("grey88",224,224,224),
383 COLOR_NAME("grey89",227,227,227),
384 COLOR_NAME("grey9",23,23,23),
385 COLOR_NAME("grey90",229,229,229),
386 COLOR_NAME("grey91",232,232,232),
387 COLOR_NAME("grey92",235,235,235),
388 COLOR_NAME("grey93",237,237,237),
389 COLOR_NAME("grey94",240,240,240),
390 COLOR_NAME("grey95",242,242,242),
391 COLOR_NAME("grey96",245,245,245),
392 COLOR_NAME("grey97",247,247,247),
393 COLOR_NAME("grey98",250,250,250),
394 COLOR_NAME("grey99",252,252,252),
395 COLOR_NAME("honeydew",240,255,240),
396 COLOR_NAME("honeydew1",240,255,240),
397 COLOR_NAME("honeydew2",224,238,224),
398 COLOR_NAME("honeydew3",193,205,193),
399 COLOR_NAME("honeydew4",131,139,131),
400 COLOR_NAME("hotpink",255,105,180),
401 COLOR_NAME("hotpink1",255,110,180),
402 COLOR_NAME("hotpink2",238,106,167),
403 COLOR_NAME("hotpink3",205,96,144),
404 COLOR_NAME("hotpink4",139,58,98),
405 COLOR_NAME("indianred",205,92,92),
406 COLOR_NAME("indianred1",255,106,106),
407 COLOR_NAME("indianred2",238,99,99),
408 COLOR_NAME("indianred3",205,85,85),
409 COLOR_NAME("indianred4",139,58,58),
410 COLOR_NAME("indigo",75,0,130),
411 COLOR_NAME("ivory",255,255,240),
412 COLOR_NAME("ivory1",255,255,240),
413 COLOR_NAME("ivory2",238,238,224),
414 COLOR_NAME("ivory3",205,205,193),
415 COLOR_NAME("ivory4",139,139,131),
416 COLOR_NAME("khaki",240,230,140),
417 COLOR_NAME("khaki1",255,246,143),
418 COLOR_NAME("khaki2",238,230,133),
419 COLOR_NAME("khaki3",205,198,115),
420 COLOR_NAME("khaki4",139,134,78),
421 COLOR_NAME("lavender",230,230,250),
422 COLOR_NAME("lavenderblush",255,240,245),
423 COLOR_NAME("lavenderblush1",255,240,245),
424 COLOR_NAME("lavenderblush2",238,224,229),
425 COLOR_NAME("lavenderblush3",205,193,197),
426 COLOR_NAME("lavenderblush4",139,131,134),
427 COLOR_NAME("lawngreen",124,252,0),
428 COLOR_NAME("lemonchiffon",255,250,205),
429 COLOR_NAME("lemonchiffon1",255,250,205),
430 COLOR_NAME("lemonchiffon2",238,233,191),
431 COLOR_NAME("lemonchiffon3",205,201,165),
432 COLOR_NAME("lemonchiffon4",139,137,112),
433 COLOR_NAME("lightblue",173,216,230),
434 COLOR_NAME("lightcoral",240,128,128),
435 COLOR_NAME("lightcyan",224,255,255),
436 COLOR_NAME("lightgoldenrod",238,221,130),
437 COLOR_NAME("lightgoldenrodyellow",250,250,210),
438 COLOR_NAME("lightgray",211,211,211),
439 COLOR_NAME("lightgreen",144,238,144),
440 COLOR_NAME("lightgrey",211,211,211),
441 COLOR_NAME("lightpink",255,182,193),
442 COLOR_NAME("lightsalmon",255,160,122),
443 COLOR_NAME("lightseagreen",32,178,170),
444 COLOR_NAME("lightskyblue",135,206,250),
445 COLOR_NAME("lightslateblue",132,112,255),
446 COLOR_NAME("lightslategray",119,136,153),
447 COLOR_NAME("lightslategrey",119,136,153),
448 COLOR_NAME("lightsteelblue",176,196,222),
449 COLOR_NAME("lightyellow",255,255,224),
450 COLOR_NAME("lightblue1",191,239,255),
451 COLOR_NAME("lightblue2",178,223,238),
452 COLOR_NAME("lightblue3",154,192,205),
453 COLOR_NAME("lightblue4",104,131,139),
454 COLOR_NAME("lightcyan1",224,255,255),
455 COLOR_NAME("lightcyan2",209,238,238),
456 COLOR_NAME("lightcyan3",180,205,205),
457 COLOR_NAME("lightcyan4",122,139,139),
458 COLOR_NAME("lightgoldenrod1",255,236,139),
459 COLOR_NAME("lightgoldenrod2",238,220,130),
460 COLOR_NAME("lightgoldenrod3",205,190,112),
461 COLOR_NAME("lightgoldenrod4",139,129,76),
462 COLOR_NAME("lightpink1",255,174,185),
463 COLOR_NAME("lightpink2",238,162,173),
464 COLOR_NAME("lightpink3",205,140,149),
465 COLOR_NAME("lightpink4",139,95,101),
466 COLOR_NAME("lightsalmon1",255,160,122),
467 COLOR_NAME("lightsalmon2",238,149,114),
468 COLOR_NAME("lightsalmon3",205,129,98),
469 COLOR_NAME("lightsalmon4",139,87,66),
470 COLOR_NAME("lightskyblue1",176,226,255),
471 COLOR_NAME("lightskyblue2",164,211,238),
472 COLOR_NAME("lightskyblue3",141,182,205),
473 COLOR_NAME("lightskyblue4",96,123,139),
474 COLOR_NAME("lightsteelblue1",202,225,255),
475 COLOR_NAME("lightsteelblue2",188,210,238),
476 COLOR_NAME("lightsteelblue3",162,181,205),
477 COLOR_NAME("lightsteelblue4",110,123,139),
478 COLOR_NAME("lightyellow1",255,255,224),
479 COLOR_NAME("lightyellow2",238,238,209),
480 COLOR_NAME("lightyellow3",205,205,180),
481 COLOR_NAME("lightyellow4",139,139,122),
482 COLOR_NAME("lime",0,255,0),
483 COLOR_NAME("limegreen",50,205,50),
484 COLOR_NAME("linen",250,240,230),
485 COLOR_NAME("magenta",255,0,255),
486 COLOR_NAME("magenta1",255,0,255),
487 COLOR_NAME("magenta2",238,0,238),
488 COLOR_NAME("magenta3",205,0,205),
489 COLOR_NAME("magenta4",139,0,139),
490 COLOR_NAME("maroon",176,48,96),
491 COLOR_NAME("maroon1",255,52,179),
492 COLOR_NAME("maroon2",238,48,167),
493 COLOR_NAME("maroon3",205,41,144),
494 COLOR_NAME("maroon4",139,28,98),
495 COLOR_NAME("mediumaquamarine",102,205,170),
496 COLOR_NAME("mediumblue",0,0,205),
497 COLOR_NAME("mediumorchid",186,85,211),
498 COLOR_NAME("mediumpurple",147,112,219),
499 COLOR_NAME("mediumseagreen",60,179,113),
500 COLOR_NAME("mediumslateblue",123,104,238),
501 COLOR_NAME("mediumspringgreen",0,250,154),
502 COLOR_NAME("mediumturquoise",72,209,204),
503 COLOR_NAME("mediumvioletred",199,21,133),
504 COLOR_NAME("mediumorchid1",224,102,255),
505 COLOR_NAME("mediumorchid2",209,95,238),
506 COLOR_NAME("mediumorchid3",180,82,205),
507 COLOR_NAME("mediumorchid4",122,55,139),
508 COLOR_NAME("mediumpurple1",171,130,255),
509 COLOR_NAME("mediumpurple2",159,121,238),
510 COLOR_NAME("mediumpurple3",137,104,205),
511 COLOR_NAME("mediumpurple4",93,71,139),
512 COLOR_NAME("midnightblue",25,25,112),
513 COLOR_NAME("mintcream",245,255,250),
514 COLOR_NAME("mistyrose",255,228,225),
515 COLOR_NAME("mistyrose1",255,228,225),
516 COLOR_NAME("mistyrose2",238,213,210),
517 COLOR_NAME("mistyrose3",205,183,181),
518 COLOR_NAME("mistyrose4",139,125,123),
519 COLOR_NAME("moccasin",255,228,181),
520 COLOR_NAME("navajowhite",255,222,173),
521 COLOR_NAME("navajowhite1",255,222,173),
522 COLOR_NAME("navajowhite2",238,207,161),
523 COLOR_NAME("navajowhite3",205,179,139),
524 COLOR_NAME("navajowhite4",139,121,94),
525 COLOR_NAME("navy",0,0,128),
526 COLOR_NAME("navyblue",0,0,128),
527 COLOR_NAME("oldlace",253,245,230),
528 COLOR_NAME("olive",128,128,0),
529 COLOR_NAME("olivedrab",107,142,35),
530 COLOR_NAME("olivedrab1",192,255,62),
531 COLOR_NAME("olivedrab2",179,238,58),
532 COLOR_NAME("olivedrab3",154,205,50),
533 COLOR_NAME("olivedrab4",105,139,34),
534 COLOR_NAME("orange",255,165,0),
535 COLOR_NAME("orangered",255,69,0),
536 COLOR_NAME("orange1",255,165,0),
537 COLOR_NAME("orange2",238,154,0),
538 COLOR_NAME("orange3",205,133,0),
539 COLOR_NAME("orange4",139,90,0),
540 COLOR_NAME("orangered1",255,69,0),
541 COLOR_NAME("orangered2",238,64,0),
542 COLOR_NAME("orangered3",205,55,0),
543 COLOR_NAME("orangered4",139,37,0),
544 COLOR_NAME("orchid",218,112,214),
545 COLOR_NAME("orchid1",255,131,250),
546 COLOR_NAME("orchid2",238,122,233),
547 COLOR_NAME("orchid3",205,105,201),
548 COLOR_NAME("orchid4",139,71,137),
549 COLOR_NAME("palegoldenrod",238,232,170),
550 COLOR_NAME("palegreen",152,251,152),
551 COLOR_NAME("paleturquoise",175,238,238),
552 COLOR_NAME("palevioletred",219,112,147),
553 COLOR_NAME("palegreen1",154,255,154),
554 COLOR_NAME("palegreen2",144,238,144),
555 COLOR_NAME("palegreen3",124,205,124),
556 COLOR_NAME("palegreen4",84,139,84),
557 COLOR_NAME("paleturquoise1",187,255,255),
558 COLOR_NAME("paleturquoise2",174,238,238),
559 COLOR_NAME("paleturquoise3",150,205,205),
560 COLOR_NAME("paleturquoise4",102,139,139),
561 COLOR_NAME("palevioletred1",255,130,171),
562 COLOR_NAME("palevioletred2",238,121,159),
563 COLOR_NAME("palevioletred3",205,104,137),
564 COLOR_NAME("palevioletred4",139,71,93),
565 COLOR_NAME("papayawhip",255,239,213),
566 COLOR_NAME("peachpuff",255,218,185),
567 COLOR_NAME("peachpuff1",255,218,185),
568 COLOR_NAME("peachpuff2",238,203,173),
569 COLOR_NAME("peachpuff3",205,175,149),
570 COLOR_NAME("peachpuff4",139,119,101),
571 COLOR_NAME("peru",205,133,63),
572 COLOR_NAME("pink",255,192,203),
573 COLOR_NAME("pink1",255,181,197),
574 COLOR_NAME("pink2",238,169,184),
575 COLOR_NAME("pink3",205,145,158),
576 COLOR_NAME("pink4",139,99,108),
577 COLOR_NAME("plum",221,160,221),
578 COLOR_NAME("plum1",255,187,255),
579 COLOR_NAME("plum2",238,174,238),
580 COLOR_NAME("plum3",205,150,205),
581 COLOR_NAME("plum4",139,102,139),
582 COLOR_NAME("powderblue",176,224,230),
583 COLOR_NAME("purple",160,32,240),
584 COLOR_NAME("purple1",155,48,255),
585 COLOR_NAME("purple2",145,44,238),
586 COLOR_NAME("purple3",125,38,205),
587 COLOR_NAME("purple4",85,26,139),
588 COLOR_NAME("rebeccapurple",102,51,153),
589 COLOR_NAME("red",255,0,0),
590 COLOR_NAME("red1",255,0,0),
591 COLOR_NAME("red2",238,0,0),
592 COLOR_NAME("red3",205,0,0),
593 COLOR_NAME("red4",139,0,0),
594 COLOR_NAME("rosybrown",188,143,143),
595 COLOR_NAME("rosybrown1",255,193,193),
596 COLOR_NAME("rosybrown2",238,180,180),
597 COLOR_NAME("rosybrown3",205,155,155),
598 COLOR_NAME("rosybrown4",139,105,105),
599 COLOR_NAME("royalblue",65,105,225),
600 COLOR_NAME("royalblue1",72,118,255),
601 COLOR_NAME("royalblue2",67,110,238),
602 COLOR_NAME("royalblue3",58,95,205),
603 COLOR_NAME("royalblue4",39,64,139),
604 COLOR_NAME("saddlebrown",139,69,19),
605 COLOR_NAME("salmon",250,128,114),
606 COLOR_NAME("salmon1",255,140,105),
607 COLOR_NAME("salmon2",238,130,98),
608 COLOR_NAME("salmon3",205,112,84),
609 COLOR_NAME("salmon4",139,76,57),
610 COLOR_NAME("sandybrown",244,164,96),
611 COLOR_NAME("seagreen",46,139,87),
612 COLOR_NAME("seagreen1",84,255,159),
613 COLOR_NAME("seagreen2",78,238,148),
614 COLOR_NAME("seagreen3",67,205,128),
615 COLOR_NAME("seagreen4",46,139,87),
616 COLOR_NAME("seashell",255,245,238),
617 COLOR_NAME("seashell1",255,245,238),
618 COLOR_NAME("seashell2",238,229,222),
619 COLOR_NAME("seashell3",205,197,191),
620 COLOR_NAME("seashell4",139,134,130),
621 COLOR_NAME("sienna",160,82,45),
622 COLOR_NAME("sienna1",255,130,71),
623 COLOR_NAME("sienna2",238,121,66),
624 COLOR_NAME("sienna3",205,104,57),
625 COLOR_NAME("sienna4",139,71,38),
626 COLOR_NAME("silver",192,192,192),
627 COLOR_NAME("skyblue",135,206,235),
628 COLOR_NAME("skyblue1",135,206,255),
629 COLOR_NAME("skyblue2",126,192,238),
630 COLOR_NAME("skyblue3",108,166,205),
631 COLOR_NAME("skyblue4",74,112,139),
632 COLOR_NAME("slateblue",106,90,205),
633 COLOR_NAME("slategray",112,128,144),
634 COLOR_NAME("slategrey",112,128,144),
635 COLOR_NAME("slateblue1",131,111,255),
636 COLOR_NAME("slateblue2",122,103,238),
637 COLOR_NAME("slateblue3",105,89,205),
638 COLOR_NAME("slateblue4",71,60,139),
639 COLOR_NAME("slategray1",198,226,255),
640 COLOR_NAME("slategray2",185,211,238),
641 COLOR_NAME("slategray3",159,182,205),
642 COLOR_NAME("slategray4",108,123,139),
643 COLOR_NAME("snow",255,250,250),
644 COLOR_NAME("snow1",255,250,250),
645 COLOR_NAME("snow2",238,233,233),
646 COLOR_NAME("snow3",205,201,201),
647 COLOR_NAME("snow4",139,137,137),
648 COLOR_NAME("springgreen",0,255,127),
649 COLOR_NAME("springgreen1",0,255,127),
650 COLOR_NAME("springgreen2",0,238,118),
651 COLOR_NAME("springgreen3",0,205,102),
652 COLOR_NAME("springgreen4",0,139,69),
653 COLOR_NAME("steelblue",70,130,180),
654 COLOR_NAME("steelblue1",99,184,255),
655 COLOR_NAME("steelblue2",92,172,238),
656 COLOR_NAME("steelblue3",79,148,205),
657 COLOR_NAME("steelblue4",54,100,139),
658 COLOR_NAME("tan",210,180,140),
659 COLOR_NAME("tan1",255,165,79),
660 COLOR_NAME("tan2",238,154,73),
661 COLOR_NAME("tan3",205,133,63),
662 COLOR_NAME("tan4",139,90,43),
663 COLOR_NAME("teal",0,128,128),
664 COLOR_NAME("thistle",216,191,216),
665 COLOR_NAME("thistle1",255,225,255),
666 COLOR_NAME("thistle2",238,210,238),
667 COLOR_NAME("thistle3",205,181,205),
668 COLOR_NAME("thistle4",139,123,139),
669 COLOR_NAME("tomato",255,99,71),
670 COLOR_NAME("tomato1",255,99,71),
671 COLOR_NAME("tomato2",238,92,66),
672 COLOR_NAME("tomato3",205,79,57),
673 COLOR_NAME("tomato4",139,54,38),
674 COLOR_NAME("turquoise",64,224,208),
675 COLOR_NAME("turquoise1",0,245,255),
676 COLOR_NAME("turquoise2",0,229,238),
677 COLOR_NAME("turquoise3",0,197,205),
678 COLOR_NAME("turquoise4",0,134,139),
679 COLOR_NAME("violet",238,130,238),
680 COLOR_NAME("violetred",208,32,144),
681 COLOR_NAME("violetred1",255,62,150),
682 COLOR_NAME("violetred2",238,58,140),
683 COLOR_NAME("violetred3",205,50,120),
684 COLOR_NAME("violetred4",139,34,82),
685 COLOR_NAME("webgray",128,128,128),
686 COLOR_NAME("webgreen",0,128,0),
687 COLOR_NAME("webgrey",128,128,128),
688 COLOR_NAME("webmaroon",128,0,0),
689 COLOR_NAME("webpurple",128,0,128),
690 COLOR_NAME("wheat",245,222,179),
691 COLOR_NAME("wheat1",255,231,186),
692 COLOR_NAME("wheat2",238,216,174),
693 COLOR_NAME("wheat3",205,186,150),
694 COLOR_NAME("wheat4",139,126,102),
695 COLOR_NAME("white",255,255,255),
696 COLOR_NAME("whitesmoke",245,245,245),
697 COLOR_NAME("x11gray",190,190,190),
698 COLOR_NAME("x11green",0,255,0),
699 COLOR_NAME("x11grey",190,190,190),
700 COLOR_NAME("x11maroon",176,48,96),
701 COLOR_NAME("x11purple",160,32,240),
702 COLOR_NAME("yellow",255,255,0),
703 COLOR_NAME("yellowgreen",154,205,50),
704 COLOR_NAME("yellow1",255,255,0),
705 COLOR_NAME("yellow2",238,238,0),
706 COLOR_NAME("yellow3",205,205,0),
707 COLOR_NAME("yellow4",139,139,0),
708 };
709
_color_name_search(const void * value,const void * element)710 int _color_name_search(const void * value, const void * element)
711 {
712 return strcmp((char *) value, ((const Color_Name_Value *) element)->name);
713 }
714
715 void
evas_common_text_props_bidi_set(Evas_Text_Props * props,Evas_BiDi_Paragraph_Props * bidi_par_props,size_t start)716 evas_common_text_props_bidi_set(Evas_Text_Props *props,
717 Evas_BiDi_Paragraph_Props *bidi_par_props, size_t start)
718 {
719 #ifdef BIDI_SUPPORT
720 props->bidi_dir = (evas_bidi_is_rtl_char(
721 bidi_par_props,
722 0,
723 start)) ? EVAS_BIDI_DIRECTION_RTL : EVAS_BIDI_DIRECTION_LTR;
724 #else
725 (void) start;
726 (void) bidi_par_props;
727 props->bidi_dir = EVAS_BIDI_DIRECTION_LTR;
728 #endif
729 PROPS_CHANGE(props);
730 }
731
732 void
evas_common_text_props_script_set(Evas_Text_Props * props,Evas_Script_Type scr)733 evas_common_text_props_script_set(Evas_Text_Props *props, Evas_Script_Type scr)
734 {
735 props->script = scr;
736 PROPS_CHANGE(props);
737 }
738
739 void
evas_common_text_props_content_copy_and_ref(Evas_Text_Props * dst,const Evas_Text_Props * src)740 evas_common_text_props_content_copy_and_ref(Evas_Text_Props *dst,
741 const Evas_Text_Props *src)
742 {
743 memcpy(dst, src, sizeof(Evas_Text_Props));
744 dst->glyphs = NULL;
745 evas_common_text_props_content_ref(dst);
746 }
747
748 void
evas_common_text_props_content_ref(Evas_Text_Props * props)749 evas_common_text_props_content_ref(Evas_Text_Props *props)
750 {
751 /* No content in this case */
752 if (!props->info)
753 return;
754
755 props->info->refcount++;
756 if (props->font_instance)
757 ((RGBA_Font_Int *)props->font_instance)->references++;
758 }
759
760 void
evas_common_text_props_content_nofree_unref(Evas_Text_Props * props)761 evas_common_text_props_content_nofree_unref(Evas_Text_Props *props)
762 {
763 /* No content in this case */
764 if (!props->info)
765 return;
766
767 if (--(props->info->refcount) == 0)
768 {
769 if (props->font_instance)
770 {
771 evas_common_font_int_unref(props->font_instance);
772 props->font_instance = NULL;
773 }
774
775 evas_common_font_glyphs_unref(props->glyphs);
776 props->glyphs = NULL;
777
778 if (props->info->glyph)
779 free(props->info->glyph);
780 #ifdef OT_SUPPORT
781 if (props->info->ot)
782 free(props->info->ot);
783 #endif
784 free(props->info);
785 props->info = NULL;
786 }
787 }
788
789 void
evas_common_text_props_content_unref(Evas_Text_Props * props)790 evas_common_text_props_content_unref(Evas_Text_Props *props)
791 {
792 /* No content in this case */
793 if (!props->info)
794 return;
795
796 if (props->glyphs) evas_common_font_glyphs_unref(props->glyphs);
797 props->glyphs = NULL;
798
799 if (--(props->info->refcount) == 0)
800 {
801 if (props->font_instance)
802 {
803 evas_common_font_int_unref(props->font_instance);
804 props->font_instance = NULL;
805 }
806
807 if (props->info->glyph)
808 free(props->info->glyph);
809 #ifdef OT_SUPPORT
810 if (props->info->ot)
811 free(props->info->ot);
812 #endif
813 free(props->info);
814 props->info = NULL;
815 }
816 }
817
818 static int
_evas_common_text_props_cluster_move(const Evas_Text_Props * props,int pos,Eina_Bool right)819 _evas_common_text_props_cluster_move(const Evas_Text_Props *props, int pos,
820 Eina_Bool right)
821 {
822 int prop_pos = evas_common_text_props_index_find(props, pos);
823 if (!right && (prop_pos > 0))
824 {
825 #ifdef OT_SUPPORT
826 int base_cluster = props->info->ot[props->start + prop_pos].source_cluster;
827 prop_pos--;
828 for ( ; prop_pos >= 0 ; prop_pos--)
829 {
830 int cur_cluster = props->info->ot[props->start + prop_pos].source_cluster;
831 if (cur_cluster != base_cluster)
832 {
833 return cur_cluster - props->text_offset;
834 }
835 }
836 #else
837 return props->start + prop_pos - 1 - props->text_offset;
838 #endif
839 }
840 else if (right && (prop_pos < (int) (props->len - 1)))
841 {
842 #ifdef OT_SUPPORT
843 int base_cluster = props->info->ot[props->start + prop_pos].source_cluster;
844 prop_pos++;
845 for ( ; prop_pos < (int) props->len ; prop_pos++)
846 {
847 int cur_cluster = props->info->ot[props->start + prop_pos].source_cluster;
848 if (cur_cluster != base_cluster)
849 {
850 return cur_cluster - props->text_offset;
851 }
852 }
853 #else
854 return props->start + prop_pos + 1 - props->text_offset;
855 #endif
856 }
857
858 return pos;
859 }
860
861 EAPI int
evas_common_text_props_cluster_next(const Evas_Text_Props * props,int pos)862 evas_common_text_props_cluster_next(const Evas_Text_Props *props, int pos)
863 {
864 Eina_Bool right;
865 /* Move right if we are in a non-rtl text */
866 right = (props->bidi_dir != EVAS_BIDI_DIRECTION_RTL);
867 return _evas_common_text_props_cluster_move(props, pos, right);
868 }
869
870 EAPI int
evas_common_text_props_cluster_prev(const Evas_Text_Props * props,int pos)871 evas_common_text_props_cluster_prev(const Evas_Text_Props *props, int pos)
872 {
873 Eina_Bool right;
874 /* Move right if we are in an rtl text */
875 right = (props->bidi_dir == EVAS_BIDI_DIRECTION_RTL);
876 return _evas_common_text_props_cluster_move(props, pos, right);
877 }
878
879 /* Returns the index of the logical char in the props. */
880 EAPI int
evas_common_text_props_index_find(const Evas_Text_Props * props,int _cutoff)881 evas_common_text_props_index_find(const Evas_Text_Props *props, int _cutoff)
882 {
883 #ifdef OT_SUPPORT
884 Evas_Font_OT_Info *ot_info;
885 int min = 0;
886 int max = props->len - 1;
887 int mid;
888
889 /* Props can be empty, verify they are not before going on. */
890 if (!props->info)
891 return -1;
892
893 _cutoff += props->text_offset;
894 ot_info = props->info->ot + props->start;
895 /* Should get us closer to the right place. */
896 if ((min <= _cutoff) && (_cutoff <= max))
897 mid = _cutoff;
898 else
899 mid = (min + max) / 2;
900
901 if (props->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
902 {
903 /* Monotonic in a descending order */
904 do
905 {
906 if (_cutoff > (int) ot_info[mid].source_cluster)
907 max = mid - 1;
908 else if (_cutoff < (int) ot_info[mid].source_cluster)
909 min = mid + 1;
910 else
911 break;
912
913 mid = (min + max) / 2;
914 }
915 while (min <= max);
916 }
917 else
918 {
919 /* Monotonic in an ascending order */
920 do
921 {
922 if (_cutoff < (int) ot_info[mid].source_cluster)
923 max = mid - 1;
924 else if (_cutoff > (int) ot_info[mid].source_cluster)
925 min = mid + 1;
926 else
927 break;
928
929 mid = (min + max) / 2;
930 }
931 while (min <= max);
932 }
933
934 /* If we didn't find, abort */
935 if (min > max)
936 return -1;
937
938 ot_info += mid;
939 if (props->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
940 {
941 /* Walk to the last one of the same cluster */
942 for ( ; mid < (int) props->len ; mid++, ot_info++)
943 {
944 if (ot_info->source_cluster != (size_t) _cutoff)
945 break;
946 }
947 mid--;
948 }
949 else
950 {
951 /* Walk to the last one of the same cluster */
952 for ( ; mid >= 0 ; mid--, ot_info--)
953 {
954 if (ot_info->source_cluster != (size_t) _cutoff)
955 break;
956 }
957 mid++;
958 }
959
960 return mid;
961 #else
962 if (props->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
963 {
964 return props->len - _cutoff - 1;
965 }
966 else
967 {
968 return _cutoff;
969 }
970 #endif
971 }
972
973 /* Won't work in the middle of ligatures, assumes cutoff < len.
974 * Also won't work in the middle of indic words, should handle that in a
975 * smart way. */
976 EAPI Eina_Bool
evas_common_text_props_split(Evas_Text_Props * base,Evas_Text_Props * ext,int _cutoff)977 evas_common_text_props_split(Evas_Text_Props *base,
978 Evas_Text_Props *ext, int _cutoff)
979 {
980 size_t cutoff;
981
982 /* Translate text cutoff pos to string object cutoff point */
983 _cutoff = evas_common_text_props_index_find(base, _cutoff);
984
985 if (_cutoff >= 0)
986 {
987 cutoff = (size_t) _cutoff;
988 }
989 else
990 {
991 ERR("Couldn't find the cutoff position. Is it inside a cluster?");
992 return EINA_FALSE;
993 }
994
995 evas_common_text_props_content_copy_and_ref(ext, base);
996 if (base->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
997 {
998 ext->start = base->start;
999 ext->len = cutoff + 1;
1000 base->start = base->start + ext->len;
1001 base->len = base->len - ext->len;
1002
1003 #ifdef OT_SUPPORT
1004 ext->text_offset =
1005 ext->info->ot[ext->start + ext->len - 1].source_cluster;
1006 #else
1007 ext->text_offset = base->text_offset + base->len;
1008 #endif
1009 }
1010 else
1011 {
1012 ext->start = base->start + cutoff;
1013 ext->len = base->len - cutoff;
1014 base->len = cutoff;
1015
1016 #ifdef OT_SUPPORT
1017 ext->text_offset = ext->info->ot[ext->start].source_cluster;
1018 #else
1019 ext->text_offset = base->text_offset + base->len;
1020 #endif
1021 }
1022 ext->text_len = base->text_len - (ext->text_offset - base->text_offset);
1023 base->text_len = (ext->text_offset - base->text_offset);
1024 PROPS_CHANGE(base);
1025 PROPS_CHANGE(ext);
1026 return EINA_TRUE;
1027 }
1028
1029 /* Won't work in the middle of ligatures */
1030 EAPI void
evas_common_text_props_merge(Evas_Text_Props * item1,const Evas_Text_Props * item2)1031 evas_common_text_props_merge(Evas_Text_Props *item1,
1032 const Evas_Text_Props *item2)
1033 {
1034 if (item1->info != item2->info)
1035 {
1036 ERR("tried merge back items that weren't together in the first place.");
1037 return;
1038 }
1039 if (item1->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
1040 {
1041 item1->start = item2->start;
1042 }
1043
1044 item1->len += item2->len;
1045 item1->text_len += item2->text_len;
1046 PROPS_CHANGE(item1);
1047 }
1048
1049 #ifdef OT_SUPPORT
1050 static inline void
_content_create_ot(RGBA_Font_Int * fi,const Eina_Unicode * text,Evas_Text_Props * text_props,int len,Evas_Text_Props_Mode mode,const char * lang)1051 _content_create_ot(RGBA_Font_Int *fi, const Eina_Unicode *text,
1052 Evas_Text_Props *text_props, int len, Evas_Text_Props_Mode mode, const char *lang)
1053 {
1054 size_t char_index;
1055 Evas_Font_Glyph_Info *gl_itr;
1056 Evas_Coord pen_x = 0, adjust_x = 0;
1057
1058 evas_common_font_ot_populate_text_props(text, text_props, len, mode, lang);
1059
1060 gl_itr = text_props->info->glyph;
1061 for (char_index = 0 ; char_index < text_props->len ; char_index++, gl_itr++)
1062 {
1063 FT_UInt idx;
1064 RGBA_Font_Glyph *fg;
1065 Eina_Bool is_replacement = EINA_FALSE;
1066 /* If we got a malformed index, show the replacement char instead */
1067 if (gl_itr->index == 0)
1068 {
1069 gl_itr->index = evas_common_get_char_index(fi, REPLACEMENT_CHAR, 0);
1070 is_replacement = EINA_TRUE;
1071 }
1072 idx = gl_itr->index;
1073 LKL(fi->ft_mutex);
1074 fg = evas_common_font_int_cache_glyph_get(fi, idx);
1075 if (!fg)
1076 {
1077 LKU(fi->ft_mutex);
1078 continue;
1079 }
1080 LKU(fi->ft_mutex);
1081
1082 gl_itr->x_bear = fg->x_bear;
1083 gl_itr->y_bear = fg->y_bear;
1084 gl_itr->width = fg->width;
1085 /* text_props->info->glyph[char_index].advance =
1086 * text_props->info->glyph[char_index].index =
1087 * already done by the ot function */
1088 if (EVAS_FONT_CHARACTER_IS_INVISIBLE(
1089 text[text_props->info->ot[char_index].source_cluster]))
1090 {
1091 gl_itr->index = 0;
1092 /* Reduce the current advance */
1093 if (gl_itr > text_props->info->glyph)
1094 {
1095 adjust_x -= gl_itr->pen_after - (gl_itr - 1)->pen_after;
1096 }
1097 else
1098 {
1099 adjust_x -= gl_itr->pen_after;
1100 }
1101 }
1102 else
1103 {
1104 if (is_replacement)
1105 {
1106 /* Update the advance accordingly */
1107 adjust_x += (pen_x + (fg->advance.x >> 16)) -
1108 gl_itr->pen_after;
1109 }
1110 pen_x = gl_itr->pen_after;
1111 }
1112 gl_itr->pen_after += adjust_x;
1113
1114 fi = text_props->font_instance;
1115 }
1116 }
1117 #else
1118 static inline void
_content_create_regular(RGBA_Font_Int * fi,const Eina_Unicode * text,Evas_Text_Props * text_props,const Evas_BiDi_Paragraph_Props * par_props,size_t par_pos,int len,Evas_Text_Props_Mode mode)1119 _content_create_regular(RGBA_Font_Int *fi, const Eina_Unicode *text,
1120 Evas_Text_Props *text_props, const Evas_BiDi_Paragraph_Props *par_props,
1121 size_t par_pos, int len, Evas_Text_Props_Mode mode)
1122 {
1123 /* We are walking the string in visual ordering */
1124 Evas_Font_Glyph_Info *gl_itr;
1125 Eina_Bool use_kerning;
1126 FT_UInt prev_index;
1127 FT_Face pface = NULL;
1128 Evas_Coord pen_x = 0;
1129 int adv_d, i;
1130 #if !defined(OT_SUPPORT) && defined(BIDI_SUPPORT)
1131 Eina_Unicode *base_str = NULL;
1132 if (mode == EVAS_TEXT_PROPS_MODE_SHAPE)
1133 {
1134 if (text_props->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
1135 {
1136 text = base_str = eina_unicode_strndup(text, len);
1137 evas_bidi_shape_string(base_str, par_props, par_pos, len);
1138 }
1139 }
1140 #else
1141 (void) mode;
1142 (void) par_props;
1143 (void) par_pos;
1144 #endif
1145
1146 FTLOCK();
1147 use_kerning = FT_HAS_KERNING(fi->src->ft.face);
1148 FTUNLOCK();
1149 prev_index = 0;
1150
1151 i = len;
1152 text_props->info->glyph = calloc(len,
1153 sizeof(Evas_Font_Glyph_Info));
1154
1155 if (text_props->bidi_dir == EVAS_BIDI_DIRECTION_RTL)
1156 {
1157 text += len - 1;
1158 adv_d = -1;
1159 }
1160 else
1161 {
1162 adv_d = 1;
1163 }
1164
1165 gl_itr = text_props->info->glyph;
1166 for ( ; i > 0 ; gl_itr++, text += adv_d, i--)
1167 {
1168 FT_UInt idx;
1169 RGBA_Font_Glyph *fg;
1170 int _gl, kern;
1171 Evas_Coord adv;
1172 _gl = *text;
1173 if (_gl == 0) break;
1174
1175 idx = evas_common_get_char_index(fi, _gl, 0);
1176 if (idx == 0)
1177 {
1178 idx = evas_common_get_char_index(fi, REPLACEMENT_CHAR, 0);
1179 }
1180
1181 fg = evas_common_font_int_cache_glyph_get(fi, idx);
1182 if (!fg) continue;
1183 kern = 0;
1184
1185 if ((use_kerning) && (prev_index) && (idx) &&
1186 (pface == fi->src->ft.face))
1187 {
1188 if (evas_common_font_query_kerning(fi, prev_index, idx, &kern))
1189 {
1190 pen_x += kern;
1191 (gl_itr - 1)->pen_after +=
1192 EVAS_FONT_ROUND_26_6_TO_INT(kern);
1193 }
1194 }
1195
1196 pface = fi->src->ft.face;
1197
1198 gl_itr->index = idx;
1199 gl_itr->x_bear = fg->x_bear;
1200 gl_itr->y_bear = fg->y_bear;
1201 adv = fg->advance.x >> 10;
1202 gl_itr->width = fg->width;
1203
1204 if (EVAS_FONT_CHARACTER_IS_INVISIBLE(_gl))
1205 {
1206 gl_itr->index = 0;
1207 }
1208 else
1209 {
1210 pen_x += adv;
1211 }
1212
1213 gl_itr->pen_after = EVAS_FONT_ROUND_26_6_TO_INT(pen_x);
1214
1215 prev_index = idx;
1216 }
1217 text_props->len = len;
1218 # if !defined(OT_SUPPORT) && defined(BIDI_SUPPORT)
1219 if (base_str)
1220 free(base_str);
1221 # endif
1222 }
1223 #endif
1224
1225 EAPI Eina_Bool
evas_common_text_props_content_create(void * _fi,const Eina_Unicode * text,Evas_Text_Props * text_props,const Evas_BiDi_Paragraph_Props * par_props,size_t par_pos,int len,Evas_Text_Props_Mode mode,const char * lang)1226 evas_common_text_props_content_create(void *_fi, const Eina_Unicode *text,
1227 Evas_Text_Props *text_props, const Evas_BiDi_Paragraph_Props *par_props,
1228 size_t par_pos, int len, Evas_Text_Props_Mode mode, const char *lang)
1229 {
1230 RGBA_Font_Int *fi = (RGBA_Font_Int *) _fi;
1231
1232 if (text_props->info)
1233 {
1234 evas_common_text_props_content_unref(text_props);
1235 }
1236 if (len == 0)
1237 {
1238 text_props->info = NULL;
1239 text_props->start = text_props->len = text_props->text_offset = 0;
1240 }
1241 text_props->info = calloc(1, sizeof(Evas_Text_Props_Info));
1242
1243 if (text_props->font_instance != fi)
1244 {
1245 if (text_props->font_instance)
1246 evas_common_font_int_unref(text_props->font_instance);
1247 text_props->font_instance = fi;
1248 fi->references++;
1249 }
1250
1251 evas_common_font_int_reload(fi);
1252 if (fi->src->current_size != fi->size)
1253 {
1254 evas_common_font_source_reload(fi->src);
1255 FTLOCK();
1256 FT_Activate_Size(fi->ft.size);
1257 FTUNLOCK();
1258 fi->src->current_size = fi->size;
1259 }
1260
1261 text_props->changed = EINA_TRUE;
1262
1263 #ifdef OT_SUPPORT
1264 (void) par_props;
1265 (void) par_pos;
1266 _content_create_ot(fi, text, text_props, len, mode, lang);
1267 #else
1268 (void) lang;
1269 _content_create_regular(fi, text, text_props, par_props, par_pos, len, mode);
1270 #endif
1271
1272 text_props->text_len = len;
1273 text_props->info->refcount = 1;
1274 return EINA_TRUE;
1275 }
1276
1277
1278 /**
1279 * @internal
1280 * Returns the numeric value of HEX chars for example for ch = 'A'
1281 * the function will return 10.
1282 *
1283 * @param ch The HEX char.
1284 * @return numeric value of HEX.
1285 */
1286 static int
_hex_string_get(char ch,Eina_Bool * ok)1287 _hex_string_get(char ch, Eina_Bool *ok)
1288 {
1289 if ((ch >= '0') && (ch <= '9')) return (ch - '0');
1290 else if ((ch >= 'A') && (ch <= 'F')) return (ch - 'A' + 10);
1291 else if ((ch >= 'a') && (ch <= 'f')) return (ch - 'a' + 10);
1292 *ok = EINA_FALSE;
1293 return 0;
1294 }
1295
1296 /**
1297 * @internal
1298 * copy lower source without space into dest buffer
1299 *
1300 * @param source source buffer
1301 * @param dest destination buffer
1302 * @param max maximum number of chars to be copied
1303 * @return number of spaces removed
1304 */
1305
remove_spaces_lowercase(const char * source,char * dest,size_t max)1306 size_t remove_spaces_lowercase(const char* source,char * dest,size_t max)
1307 {
1308 size_t spaces=0;
1309 while (*source && max)
1310 {
1311 if (*source != ' ')
1312 {
1313 *dest = ((*source >= 'A') && (*source <= 'Z')) ? *source + 32 : *source;
1314 dest++;
1315 }
1316 else
1317 {
1318 spaces++;
1319 }
1320 source++;
1321 max--;
1322 }
1323 return spaces;
1324 }
1325
1326 /**
1327 * @internal
1328 * read color component from string
1329 *
1330 * @param source source string
1331 * @param[out] next position after the color compnent
1332 * @param byte store color value read from string
1333 * @return if read success
1334 */
1335
read_byte_color_component(const char * source,char ** next,unsigned char * byte)1336 Eina_Bool read_byte_color_component(const char* source,char ** next,unsigned char * byte)
1337 {
1338 const char *p_start = source;
1339 char *p_stop = NULL;
1340 Eina_Bool b_ret = EINA_TRUE;
1341 long value = 0;
1342 value = strtol(p_start, &p_stop, 10);
1343 if ( value > 255 || value < 0 || p_start == p_stop )
1344 {
1345 b_ret = EINA_FALSE;
1346 }
1347
1348 if (next)
1349 *next = p_stop;
1350 if (byte)
1351 *byte = (unsigned char) value;
1352
1353 return b_ret;
1354 }
1355
1356
1357 /**
1358 * @internal
1359 * Parses a string of one of the formas:
1360 * 1. "#RRGGBB"
1361 * 2. "#RRGGBBAA"
1362 * 3. "#RGB"
1363 * 4. "#RGBA"
1364 * 5. "color names"
1365 * 6. "rgb(r,g,b)"
1366 * 7. "rgba(r,g,b,a)"
1367 * TODO (we may use specific color parser)
1368 * 8. "hsl(H,S,L)"
1369 * 9. "hsla(H,S,L,A)"
1370 * To the rgba values.
1371 *
1372 * @param[in] str The string to parse - NOT NULL.
1373 * @param[out] r The Red value - NOT NULL.
1374 * @param[out] g The Green value - NOT NULL.
1375 * @param[out] b The Blue value - NOT NULL.
1376 * @param[out] a The Alpha value - NOT NULL.
1377 */
1378 Eina_Bool
evas_common_format_color_parse(const char * str,int slen,unsigned char * r,unsigned char * g,unsigned char * b,unsigned char * a)1379 evas_common_format_color_parse(const char *str, int slen,
1380 unsigned char *r, unsigned char *g,
1381 unsigned char *b, unsigned char *a)
1382 {
1383 Eina_Bool v = EINA_TRUE;
1384
1385 *r = *g = *b = *a = 0;
1386 if (slen>0 && str[0]=='#')
1387 {
1388 if (slen == 7) /* #RRGGBB */
1389 {
1390 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
1391 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
1392 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
1393 *a = 0xff;
1394 }
1395 else if (slen == 9) /* #RRGGBBAA */
1396 {
1397 *r = (_hex_string_get(str[1], &v) << 4) | (_hex_string_get(str[2], &v));
1398 *g = (_hex_string_get(str[3], &v) << 4) | (_hex_string_get(str[4], &v));
1399 *b = (_hex_string_get(str[5], &v) << 4) | (_hex_string_get(str[6], &v));
1400 *a = (_hex_string_get(str[7], &v) << 4) | (_hex_string_get(str[8], &v));
1401 }
1402 else if (slen == 4) /* #RGB */
1403 {
1404 *r = _hex_string_get(str[1], &v);
1405 *r = (*r << 4) | *r;
1406 *g = _hex_string_get(str[2], &v);
1407 *g = (*g << 4) | *g;
1408 *b = _hex_string_get(str[3], &v);
1409 *b = (*b << 4) | *b;
1410 *a = 0xff;
1411 }
1412 else if (slen == 5) /* #RGBA */
1413 {
1414 *r = _hex_string_get(str[1], &v);
1415 *r = (*r << 4) | *r;
1416 *g = _hex_string_get(str[2], &v);
1417 *g = (*g << 4) | *g;
1418 *b = _hex_string_get(str[3], &v);
1419 *b = (*b << 4) | *b;
1420 *a = _hex_string_get(str[4], &v);
1421 *a = (*a << 4) | *a;
1422 }
1423 else v = EINA_FALSE;
1424 }
1425 else if (slen <= 21)/* search for rgb(),hsv(),colorname, 20 is length of rgba(255,255,255,255) */
1426 {
1427 /*remove spaces and convert name to lowercase*/
1428 char color_name[0xFF] = {0};
1429 slen = slen - (int) remove_spaces_lowercase(str,color_name,0xFF);
1430
1431 if ((strncmp(color_name,"rgb(",4) == 0) && color_name[slen-1] == ')'&& slen >= 10 && slen <=16) /* rgb() */
1432 {
1433 char * p_color = &color_name[3];
1434
1435 if (
1436 (!read_byte_color_component(++p_color,&p_color,r) || !p_color || *p_color != ',') ||
1437 (!read_byte_color_component(++p_color,&p_color,g) || !p_color || *p_color != ',') ||
1438 (!read_byte_color_component(++p_color,&p_color,b) || !p_color || *p_color != ')')
1439 )
1440 {
1441 *r = *g = *b = *a = 0;
1442 v = EINA_FALSE;
1443 }
1444 else
1445 {
1446 *a = 0xff;
1447 }
1448 }
1449 else if ((strncmp(color_name,"rgba(",4) == 0) && color_name[slen-1] == ')'&& slen >= 13 && slen <=21) /* rgba() */
1450 {
1451 char * p_color = &color_name[4];
1452
1453 if (
1454 (!read_byte_color_component(++p_color,&p_color,r) || !p_color || *p_color != ',') ||
1455 (!read_byte_color_component(++p_color,&p_color,g) || !p_color || *p_color != ',') ||
1456 (!read_byte_color_component(++p_color,&p_color,b) || !p_color || *p_color != ',') ||
1457 (!read_byte_color_component(++p_color,&p_color,a) || !p_color || *p_color != ')')
1458 )
1459 {
1460 *r = *g = *b = *a = 0;
1461 v = EINA_FALSE;
1462 }
1463 }
1464 else
1465 {
1466 static size_t color_array_length = sizeof(color_name_value_sorted)/sizeof(Color_Name_Value);
1467 Color_Name_Value* pcolor = (Color_Name_Value*) bsearch(color_name, color_name_value_sorted, color_array_length, sizeof(Color_Name_Value),_color_name_search);
1468 if (pcolor)
1469 {
1470 *r = pcolor->r;
1471 *g = pcolor->g;
1472 *b = pcolor->b;
1473 *a = 0xff;
1474 }
1475 else
1476 {
1477 v = EINA_FALSE;
1478 }
1479 }
1480 }
1481
1482 if(*a != 0xFF)
1483 {
1484 *r = (*r * *a) / 255;
1485 *g = (*g * *a) / 255;
1486 *b = (*b * *a) / 255;
1487 }
1488 return v;
1489 }
1490