From e816781e41b95db2511918b0efb5a5702683189f Mon Sep 17 00:00:00 2001 From: Nick Romano Date: Wed, 10 Jan 2024 20:31:35 -0800 Subject: [PATCH 1/2] Fix non-mirrored LTR/RTL icons --- importer/process_ios_assets.py | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/importer/process_ios_assets.py b/importer/process_ios_assets.py index 48a1c1e73a..4aff96bd02 100644 --- a/importer/process_ios_assets.py +++ b/importer/process_ios_assets.py @@ -59,17 +59,16 @@ def xc_image_data_for_file_name(file_name, locale, metadata): elif metadata["singleton"] == "RTL": output["language-direction"] = "right-to-left" - # These icons are being replaced by new icons with metadata - # for backward compatibility we add the language-direction - if "_ltr_" in file_name and not metadata: + if "_ltr" in file_name: output["language-direction"] = "left-to-right" - if "_rtl_" in file_name and not metadata: + elif "_rtl" in file_name: output["language-direction"] = "right-to-left" return output def create_icon_set(fluent_icon_assets, original_icon_names, icon_assets_path): + print("create_icon_set") for fluent_icon_asset in fluent_icon_assets: language_metadata = fluent_icon_asset.metadata.get("language") languages = [] @@ -82,17 +81,26 @@ def create_icon_set(fluent_icon_assets, original_icon_names, icon_assets_path): if languages == ["en"]: languages = [] - for file_name in os.listdir(os.path.join(fluent_icon_asset.path, IMAGE_FORMAT.upper())): - icon_name = get_icon_name(file_name) + files = os.listdir(os.path.join(fluent_icon_asset.path, IMAGE_FORMAT.upper())) + icon_names = set() + for file in files: + icon_names.add(file.replace("_ltr", "").replace("_rtl", "").replace(f".{IMAGE_FORMAT}", "")) + for icon_name in icon_names: if icon_name in original_icon_names: continue original_icon_names.add(icon_name) + files_for_size_and_style = [] + for file in files: + if icon_name in file: + files_for_size_and_style.append(file) + imageset_path = os.path.join(icon_assets_path, "{icon_name}.imageset".format(icon_name=icon_name)) os.mkdir(imageset_path) - shutil.copyfile(os.path.join(fluent_icon_asset.path, IMAGE_FORMAT.upper(), file_name), os.path.join(imageset_path, file_name)) + for file_name in files_for_size_and_style: + shutil.copyfile(os.path.join(fluent_icon_asset.path, IMAGE_FORMAT.upper(), file_name), os.path.join(imageset_path, file_name)) supported_languages = [] for language in languages: @@ -130,9 +138,9 @@ def create_icon_set(fluent_icon_assets, original_icon_names, icon_assets_path): if icon_name.endswith("_color") or icon_name.startswith("ic_fluent_flag_pride"): rendering_intent = "original" - images = [ - xc_image_data_for_file_name(file_name, locale=None, metadata=fluent_icon_asset.metadata) - ] + images = [] + for file_name in files_for_size_and_style: + images.append(xc_image_data_for_file_name(file_name, locale=None, metadata=fluent_icon_asset.metadata)) contents = { "images": images, @@ -165,6 +173,8 @@ def create_icon_set(fluent_icon_assets, original_icon_names, icon_assets_path): def process_assets(): + print("Generating iOS xcassets directories and code") + project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) assets_dir = os.path.join(project_root, "assets") @@ -174,10 +184,10 @@ def process_assets(): continue icon_assets_path = os.path.join(assets_dir, file_name) metadata_path = os.path.join(icon_assets_path, "metadata.json") - metadata = {} - if os.path.exists(metadata_path): - with open(metadata_path) as metadata_json: - metadata = json.loads(metadata_json.read()) + if not os.path.exists(metadata_path): + continue + with open(metadata_path) as metadata_json: + metadata = json.loads(metadata_json.read()) icon_assets.append(FluentIconAsset( name=file_name, From 641bb745c31729674f3fec27fb45658b016362f0 Mon Sep 17 00:00:00 2001 From: Nick Romano Date: Wed, 10 Jan 2024 21:38:11 -0800 Subject: [PATCH 2/2] Include folders without metadata --- importer/process_ios_assets.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/importer/process_ios_assets.py b/importer/process_ios_assets.py index 4aff96bd02..5d1ea4374f 100644 --- a/importer/process_ios_assets.py +++ b/importer/process_ios_assets.py @@ -184,10 +184,14 @@ def process_assets(): continue icon_assets_path = os.path.join(assets_dir, file_name) metadata_path = os.path.join(icon_assets_path, "metadata.json") - if not os.path.exists(metadata_path): + metadata = {} + if os.path.exists(metadata_path): + with open(metadata_path) as metadata_json: + metadata = json.loads(metadata_json.read()) + + if " LTR" in file_name or " RTL" in file_name: + # Old file format for ltr/rtl continue - with open(metadata_path) as metadata_json: - metadata = json.loads(metadata_json.read()) icon_assets.append(FluentIconAsset( name=file_name,