| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import fileinput | 5 import fileinput |
| 6 import glob | 6 import glob |
| 7 import optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import textwrap | 9 import textwrap |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 icon_list = glob.glob(working_directory + "*.icon") | 22 icon_list = glob.glob(working_directory + "*.icon") |
| 23 | 23 |
| 24 input_header_template = open(os.path.join(working_directory, | 24 input_header_template = open(os.path.join(working_directory, |
| 25 "vector_icons.h.template")) | 25 "vector_icons.h.template")) |
| 26 header_template_contents = input_header_template.readlines() | 26 header_template_contents = input_header_template.readlines() |
| 27 input_header_template.close() | 27 input_header_template.close() |
| 28 output_header = open(output_h, "w") | 28 output_header = open(output_h, "w") |
| 29 for line in header_template_contents: | 29 for line in header_template_contents: |
| 30 if not "TEMPLATE_PLACEHOLDER" in line: | 30 if not "TEMPLATE_PLACEHOLDER" in line: |
| 31 output_header.write(line) | 31 output_header.write(line) |
| 32 else: | 32 continue |
| 33 for icon_path in icon_list: | 33 |
| 34 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path)) | 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) |
| 38 if not scale_factor: |
| 35 output_header.write(" {},\n".format(icon_name.upper())) | 39 output_header.write(" {},\n".format(icon_name.upper())) |
| 36 output_header.close() | 40 output_header.close() |
| 37 | 41 |
| 38 input_cc_template = open( | 42 input_cc_template = open( |
| 39 os.path.join(working_directory, "vector_icons.cc.template")) | 43 os.path.join(working_directory, "vector_icons.cc.template")) |
| 40 cc_template_contents = input_cc_template.readlines() | 44 cc_template_contents = input_cc_template.readlines() |
| 41 input_cc_template.close() | 45 input_cc_template.close() |
| 42 output_cc = open(output_cc, "w") | 46 output_cc = open(output_cc, "w") |
| 43 for line in cc_template_contents: | 47 for line in cc_template_contents: |
| 44 if not "TEMPLATE_PLACEHOLDER" in line: | 48 if not "TEMPLATE_PLACEHOLDER" in line: |
| 45 output_cc.write(line) | 49 output_cc.write(line) |
| 46 else: | 50 continue; |
| 47 for icon_path in icon_list: | 51 |
| 48 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path)) | 52 for icon_path in icon_list: |
| 49 icon_file = open(icon_path) | 53 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path)) |
| 50 vector_commands = "".join(icon_file.readlines()) | 54 (icon_name, scale_factor) = os.path.splitext(icon_name) |
| 51 icon_file.close() | 55 assert not scale_factor or scale_factor == ".1x" |
| 52 output_cc.write("ICON_TEMPLATE({}, {})\n".format(icon_name.upper(), | 56 if (("1X" in line and scale_factor != ".1x") or |
| 53 vector_commands)) | 57 (not "1X" in line and scale_factor == ".1x")): |
| 58 continue |
| 59 |
| 60 icon_file = open(icon_path) |
| 61 vector_commands = "".join(icon_file.readlines()) |
| 62 icon_file.close() |
| 63 output_cc.write("ICON_TEMPLATE({}, {})\n".format(icon_name.upper(), |
| 64 vector_commands)) |
| 54 output_cc.close() | 65 output_cc.close() |
| 55 | 66 |
| 56 | 67 |
| 57 def main(): | 68 def main(): |
| 58 parser = optparse.OptionParser() | 69 parser = optparse.OptionParser() |
| 59 parser.add_option("--working_directory", | 70 parser.add_option("--working_directory", |
| 60 help="The directory to look for template C++ as well as " | 71 help="The directory to look for template C++ as well as " |
| 61 "icon files.") | 72 "icon files.") |
| 62 parser.add_option("--output_cc", | 73 parser.add_option("--output_cc", |
| 63 help="The path to output the CC file to.") | 74 help="The path to output the CC file to.") |
| 64 parser.add_option("--output_h", | 75 parser.add_option("--output_h", |
| 65 help="The path to output the header file to.") | 76 help="The path to output the header file to.") |
| 66 | 77 |
| 67 (options, args) = parser.parse_args() | 78 (options, args) = parser.parse_args() |
| 68 | 79 |
| 69 AggregateVectorIcons(options.working_directory, | 80 AggregateVectorIcons(options.working_directory, |
| 70 options.output_cc, | 81 options.output_cc, |
| 71 options.output_h) | 82 options.output_h) |
| 72 | 83 |
| 73 | 84 |
| 74 if __name__ == "__main__": | 85 if __name__ == "__main__": |
| 75 main() | 86 main() |
| OLD | NEW |