1# trml2pdf - An RML to PDF converter
2# Copyright (C) 2003, Fabien Pinckaers, UCL, FSA
3#
4# This library is free software; you can redistribute it and/or
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the License, or (at your option) any later version.
8#
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# Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public
15# License along with this library; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18from reportlab.lib import colors
19import re
20
21allcols = colors.getAllNamedColors()
22
23regex_t = re.compile('\(([0-9\.]*),([0-9\.]*),([0-9\.]*)\)')
24regex_h = re.compile('#([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA-Z][0-9a-zA-Z])')
25
26def get(col_str):
27	global allcols
28	if col_str in list(allcols.keys()):
29		return allcols[col_str]
30	res = regex_t.search(col_str, 0)
31	if res:
32		return (float(res.group(1)),float(res.group(2)),float(res.group(3)))
33	res = regex_h.search(col_str, 0)
34	if res:
35		return tuple([ float(int(res.group(i),16))/255 for i in range(1,4)])
36	return colors.red
37