1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
12 def AggregateVectorIcons(working_directory
, output_cc
, output_h
):
13 """Compiles all .icon files in a directory into two C++ files.
16 working_directory: The path to the directory that holds the .icon files
18 output_cc: The path that should be used to write the .cc file.
19 output_h: The path that should be used to write the .h file.
22 icon_list
= glob
.glob(working_directory
+ "*.icon")
24 input_header_template
= open(os
.path
.join(working_directory
,
25 "vector_icons.h.template"))
26 header_template_contents
= input_header_template
.readlines()
27 input_header_template
.close()
28 output_header
= open(output_h
, "w")
29 for line
in header_template_contents
:
30 if not "TEMPLATE_PLACEHOLDER" in line
:
31 output_header
.write(line
)
34 for icon_path
in icon_list
:
35 # The icon name should be of the format "foo.icon" or "foo.1x.icon".
36 (icon_name
, extension
) = os
.path
.splitext(os
.path
.basename(icon_path
))
37 (icon_name
, scale_factor
) = os
.path
.splitext(icon_name
)
39 output_header
.write(" {},\n".format(icon_name
.upper()))
42 input_cc_template
= open(
43 os
.path
.join(working_directory
, "vector_icons.cc.template"))
44 cc_template_contents
= input_cc_template
.readlines()
45 input_cc_template
.close()
46 output_cc
= open(output_cc
, "w")
47 for line
in cc_template_contents
:
48 if not "TEMPLATE_PLACEHOLDER" in line
:
52 for icon_path
in icon_list
:
53 (icon_name
, extension
) = os
.path
.splitext(os
.path
.basename(icon_path
))
54 (icon_name
, scale_factor
) = os
.path
.splitext(icon_name
)
55 assert not scale_factor
or scale_factor
== ".1x"
56 if (("1X" in line
and scale_factor
!= ".1x") or
57 (not "1X" in line
and scale_factor
== ".1x")):
60 icon_file
= open(icon_path
)
61 vector_commands
= "".join(icon_file
.readlines())
63 output_cc
.write("ICON_TEMPLATE({}, {})\n".format(icon_name
.upper(),
69 parser
= optparse
.OptionParser()
70 parser
.add_option("--working_directory",
71 help="The directory to look for template C++ as well as "
73 parser
.add_option("--output_cc",
74 help="The path to output the CC file to.")
75 parser
.add_option("--output_h",
76 help="The path to output the header file to.")
78 (options
, args
) = parser
.parse_args()
80 AggregateVectorIcons(options
.working_directory
,
85 if __name__
== "__main__":