diff --git a/src/data_classes/AttributeList.gd b/src/data_classes/AttributeList.gd index 3deb4909..33dbaf13 100644 --- a/src/data_classes/AttributeList.gd +++ b/src/data_classes/AttributeList.gd @@ -76,7 +76,7 @@ static func text_to_list(string: String) -> PackedFloat32Array: @warning_ignore("shadowed_global_identifier") var char := string[pos] match char: - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "+", ".": + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "+", ".", "e": current_num_string += char " ": if current_num_string.is_empty(): diff --git a/src/data_classes/AttributePathdata.gd b/src/data_classes/AttributePathdata.gd index 56d8809b..89401535 100644 --- a/src/data_classes/AttributePathdata.gd +++ b/src/data_classes/AttributePathdata.gd @@ -149,7 +149,7 @@ func insert_command(idx: int, cmd_char: String, vec := Vector2.ZERO) -> void: sync_after_commands_change() -func convert_command(idx: int, cmd_char: String) -> void: +func _convert_command(idx: int, cmd_char: String) -> void: var old_cmd := get_command(idx) if old_cmd.command_char == cmd_char: return @@ -195,6 +195,15 @@ func convert_command(idx: int, cmd_char: String) -> void: _commands.insert(idx, new_cmd) if relative: _commands[idx].toggle_relative() + +func convert_command(idx: int, cmd_char: String) -> void: + _convert_command(idx, cmd_char) + sync_after_commands_change() + +func convert_commands_optimized(indices: PackedInt32Array, +cmd_chars: PackedStringArray) -> void: + for i in indices.size(): + _convert_command(indices[i], cmd_chars[i]) sync_after_commands_change() diff --git a/src/data_classes/ElementRoot.gd b/src/data_classes/ElementRoot.gd index 0b9f4025..3177bb16 100644 --- a/src/data_classes/ElementRoot.gd +++ b/src/data_classes/ElementRoot.gd @@ -192,7 +192,21 @@ func replace_xnode(id: PackedInt32Array, new_xnode: XNode) -> void: # The return value is true if the SVG can be optimized, otherwise false. # If apply_changes is false, you'll only get the return value. func optimize(not_applied := false) -> bool: - for element in get_all_element_descendants(): + for xnode in get_all_xnode_descendants(): + if not xnode.is_element(): + var basic_xnode: BasicXNode = xnode + var xids_to_remove: Array[PackedInt32Array] = [] + if basic_xnode.get_type() in [BasicXNode.NodeType.COMMENT, + BasicXNode.NodeType.UNKNOWN]: + if not_applied: + return true + xids_to_remove.append(xnode.xid) + else: + continue # The logic for removing these safely is more particular. + delete_xnodes(xids_to_remove) + continue + + var element: Element = xnode match element.name: "ellipse": # If possible, turn ellipses into circles. @@ -229,26 +243,37 @@ func optimize(not_applied := false) -> bool: if not_applied: return true pathdata.set_command_property(cmd_idx, "rot", 0) + # Replace L with H or V when possible. + var conversion_indices := PackedInt32Array() + var conversion_cmd_chars := PackedStringArray() + for cmd_idx in pathdata.get_command_count(): var command := pathdata.get_command(cmd_idx) var cmd_char := command.command_char + if cmd_char == "l": if command.x == 0: if not_applied: return true - pathdata.convert_command(cmd_idx, "v") + conversion_indices.append(cmd_idx) + conversion_cmd_chars.append("v") elif command.y == 0: if not_applied: return true - pathdata.convert_command(cmd_idx, "h") + conversion_indices.append(cmd_idx) + conversion_cmd_chars.append("h") elif cmd_char == "L": if command.x == command.start.x: if not_applied: return true - pathdata.convert_command(cmd_idx, "V") + conversion_indices.append(cmd_idx) + conversion_cmd_chars.append("V") elif command.y == command.start.y: if not_applied: return true - pathdata.convert_command(cmd_idx, "H") + conversion_indices.append(cmd_idx) + conversion_cmd_chars.append("H") + pathdata.convert_commands_optimized(conversion_indices, conversion_cmd_chars) + return false diff --git a/visual/icons/element/text.svg b/visual/icons/element/text.svg new file mode 100644 index 00000000..fa11868e --- /dev/null +++ b/visual/icons/element/text.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/visual/icons/element/text.svg.import b/visual/icons/element/text.svg.import new file mode 100644 index 00000000..6643e569 --- /dev/null +++ b/visual/icons/element/text.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c2ienefxrtut" +path="res://.godot/imported/text.svg-2e6aa7ee99b0bb99cb575439c3119d4e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://visual/icons/element/text.svg" +dest_files=["res://.godot/imported/text.svg-2e6aa7ee99b0bb99cb575439c3119d4e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false