Skip to content

Commit

Permalink
Fix list parsing not handling exponents (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur authored Nov 8, 2024
1 parent 56d3f7d commit 2e8668e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/data_classes/AttributeList.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
11 changes: 10 additions & 1 deletion src/data_classes/AttributePathdata.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down
35 changes: 30 additions & 5 deletions src/data_classes/ElementRoot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions visual/icons/element/text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions visual/icons/element/text.svg.import
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2e8668e

Please sign in to comment.