+++ /dev/null
-#
-# /*************************************************************************
-# * Copyright (c) 2011 AT&T Intellectual Property
-# * All rights reserved. This program and the accompanying materials
-# * are made available under the terms of the Eclipse Public License v1.0
-# * which accompanies this distribution, and is available at
-# * http://www.eclipse.org/legal/epl-v10.html
-# *
-# * Contributors: Details at http://www.graphviz.org/
-# *************************************************************************/
-#
-# Convert Brewer data to same RGBA format used in color_names.
-# See brewer_colors for input format.
-#
-# All colors assumed opaque, so A = 255 in all colors
-BEGIN {
- FS = ","
-}
-/^[^#]/{
- if ($1 != "") {
- name = $1 $2;
- gsub ("\"","",name);
- }
- printf ("/%s/%s %s %s %s 255\n", name, $5, $7, $8, $9);
-}
)
add_custom_command(
OUTPUT brewer_lib
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/brewer_colors
- ${CMAKE_SOURCE_DIR}/awk/brewer.awk
- COMMAND ${AWK_EXECUTABLE} -f ${CMAKE_SOURCE_DIR}/awk/brewer.awk
+ MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/brewer_colors
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/make_brewer_lib.py
+ COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_brewer_lib.py
${CMAKE_CURRENT_SOURCE_DIR}/brewer_colors
- >${CMAKE_CURRENT_BINARY_DIR}/brewer_lib
+ ${CMAKE_CURRENT_BINARY_DIR}/brewer_lib
COMMENT "generate Brewer color library"
)
configure_file(
color_lib : brewer_lib svgcolor_lib $(top_srcdir)/lib/common/color_names
cat brewer_lib svgcolor_lib $(top_srcdir)/lib/common/color_names | LC_ALL=C $(SORT) > color_lib
-brewer_lib : $(top_srcdir)/lib/common/brewer_colors $(top_srcdir)/awk/brewer.awk
- $(AWK) -f $(top_srcdir)/awk/brewer.awk $(top_srcdir)/lib/common/brewer_colors > brewer_lib
+brewer_lib: $(top_srcdir)/lib/common/brewer_colors \
+ $(top_srcdir)/lib/common/make_brewer_lib.py
+ python3 $(top_srcdir)/lib/common/make_brewer_lib.py "$<" "$@"
svgcolor_lib: $(top_srcdir)/lib/common/svgcolor_names \
$(top_srcdir)/lib/common/make_svgcolor_lib.py
entities.html entities.tcl \
brewer_colors brewer_lib svgcolor_names svgcolor_lib \
color_names color_lib colortbl.h \
- make_svgcolor_lib.py
+ make_brewer_lib.py make_svgcolor_lib.py
--- /dev/null
+#!/usr/bin/python3
+
+"""
+brewer_colors → brewer_lib generator
+"""
+
+import argparse
+import sys
+from typing import List
+
+def main(args: List[str]) -> int:
+ """entry point"""
+
+ # parse command line arguments
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("input", type=argparse.FileType("rt"),
+ help="input Brewer CSV data")
+ parser.add_argument("output", type=argparse.FileType("wt"),
+ help="output color table entries")
+ options = parser.parse_args(args[1:])
+
+ name = None
+
+ for line in options.input:
+
+ # skip comments and empty lines
+ if line.startswith("#") or line.strip() == "":
+ continue
+
+ # split the line into columns
+ items = line.split(",")
+ assert len(items) == 10, f"unexpected line {line}"
+
+ # do we have a new name on this line?
+ if items[0] != "":
+ # derive the name from the first two columns
+ name = "".join(items[:2]).replace('"', "")
+
+ assert name is not None, "first line contained no name"
+
+ # write this as a color table entry
+ options.output.write(f"/{name}/{items[4]} {items[6]} {items[7]} {items[8]} 255\n")
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
<PreBuildEvent>
<Command>win_bison -dy -Wno-yacc common\htmlparse.y -o common\htmlparse.c
python common\make_svgcolor_lib.py common\svgcolor_names common\svgcolor_lib
-awk -f $(SolutionDir)awk\brewer.awk common\brewer_colors > common\brewer_lib
+python common\make_brewer_lib.py common\brewer_colors common\brewer_lib
type common\brewer_lib common\svgcolor_lib common\color_names | sort /L C > color_lib
awk -f $(SolutionDir)awk\colortbl.awk color_lib > common\colortbl.h</Command>
</PreBuildEvent>
<PreBuildEvent>
<Command>win_bison -dy -Wno-yacc common\htmlparse.y -o common\htmlparse.c
python common\make_svgcolor_lib.py common\svgcolor_names common\svgcolor_lib
-awk -f $(SolutionDir)awk\brewer.awk common\brewer_colors > common\brewer_lib
+python common\make_brewer_lib.py common\brewer_colors common\brewer_lib
type common\brewer_lib common\svgcolor_lib common\color_names | sort /L C > color_lib
awk -f $(SolutionDir)awk\colortbl.awk color_lib > common\colortbl.h</Command>
</PreBuildEvent>