Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable ConvertCurvesToArcs to avoid degenerate edge cases #65

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
### Added

- More robust SVG → vector conversions by Android Studio tools (#47)
- More compact printing of 2D coordinates when y < 0 for vector drawables

### Fixed

- In rare cases, subpath start points were tracked incorrectly which resulted in a crash (#57)
- Disabled `ConvertCurvesToArcs` until some edge cases can be worked out (#65)

## 2.1.0 - 09-14-2021

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,8 @@ class ScalableVectorGraphicCommandPrinter(private val decimalDigits: Int) : Comm
private fun print(point: Point) =
buildString {
append(print(point.x))

if (point.y.sign < 0f) {
append(print(point.y))
} else {
append(',')
append(print(point.y))
}
if (point.y.sign >= 0f) append(',')
append(print(point.y))
}

private fun print(parameter: CubicBezierCurve.Parameter): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.jzbrooks.vgo.core.optimization.BakeTransformations
import com.jzbrooks.vgo.core.optimization.BreakoutImplicitCommands
import com.jzbrooks.vgo.core.optimization.CollapseGroups
import com.jzbrooks.vgo.core.optimization.CommandVariant
import com.jzbrooks.vgo.core.optimization.ConvertCurvesToArcs
import com.jzbrooks.vgo.core.optimization.MergePaths
import com.jzbrooks.vgo.core.optimization.OptimizationRegistry
import com.jzbrooks.vgo.core.optimization.Polycommands
Expand All @@ -30,7 +29,7 @@ class SvgOptimizationRegistry : OptimizationRegistry(BOTTOM_UP, TOP_DOWN) {
BreakoutImplicitCommands(),
CommandVariant(CommandVariant.Mode.Relative),
SimplifyLineCommands(1e-3f),
ConvertCurvesToArcs(ScalableVectorGraphicCommandPrinter(3)),
// ConvertCurvesToArcs(ScalableVectorGraphicCommandPrinter(3)),
SimplifyBezierCurveCommands(1e-3f),
RemoveRedundantCommands(),
CommandVariant(CommandVariant.Mode.Compact(ScalableVectorGraphicCommandPrinter(3))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.jzbrooks.vgo.core.graphic.command.VerticalLineTo
import com.jzbrooks.vgo.core.util.math.Point
import java.math.RoundingMode
import java.text.DecimalFormat
import kotlin.math.sign

class VectorDrawableCommandPrinter(private val decimalDigits: Int) : CommandPrinter {
private val formatter =
Expand Down Expand Up @@ -235,7 +236,7 @@ class VectorDrawableCommandPrinter(private val decimalDigits: Int) : CommandPrin
private fun print(point: Point) =
buildString {
append(print(point.x))
append(',')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to say there was a reason this was omitted only for vector drawables on first implementation. I vaguely remember there being some issues with framework implementations of vector drawable on android for SDK versions ~21 (avoided with compatibility lib).

I searched around the issue tracker and couldn't find evidence of this.

This prevents some vectors from being represented more verbosely than inputs, and it probably isn't an issue now in practice.

if (point.y.sign >= 0f) append(',')
append(print(point.y))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.jzbrooks.vgo.core.optimization.BakeTransformations
import com.jzbrooks.vgo.core.optimization.BreakoutImplicitCommands
import com.jzbrooks.vgo.core.optimization.CollapseGroups
import com.jzbrooks.vgo.core.optimization.CommandVariant
import com.jzbrooks.vgo.core.optimization.ConvertCurvesToArcs
import com.jzbrooks.vgo.core.optimization.MergePaths
import com.jzbrooks.vgo.core.optimization.OptimizationRegistry
import com.jzbrooks.vgo.core.optimization.Polycommands
Expand All @@ -30,7 +29,7 @@ class VectorDrawableOptimizationRegistry : OptimizationRegistry(BOTTOM_UP, TOP_D
BreakoutImplicitCommands(),
CommandVariant(CommandVariant.Mode.Relative),
SimplifyLineCommands(1e-3f),
ConvertCurvesToArcs(VectorDrawableCommandPrinter(3)),
// ConvertCurvesToArcs(VectorDrawableCommandPrinter(3)),
SimplifyBezierCurveCommands(1e-3f),
RemoveRedundantCommands(),
CommandVariant(CommandVariant.Mode.Compact(VectorDrawableCommandPrinter(3))),
Expand Down
2 changes: 1 addition & 1 deletion vgo/src/test/resources/baseline/android_optimized.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="108dp" android:viewportHeight="108" android:viewportWidth="108" android:width="108dp">
<path android:fillColor="#26a69a" android:pathData="M0,0h108v108H0Z"/>
<path android:pathData="M-13.5,-27v162m15,-162v162m15,-162v162m15,-162v162m15,-162v162m15,-162v162M69,0v108M79,0v108M89,0v108M99,0v108m63,45H54m108,-10H54m108,-10H54m108,-10H54m108,-10H54m108,-10H54m-0,20h108M54,133h108M54,143h108M54,153h108M73,83h70M73,93h70m-70,10h70m-70,10h70m-70,10h70m-70,10h70M83,73v70M93,73v70m10,-70v70m10,-70v70m10,-70v70m10,-70v70" android:strokeColor="#33ffffff" android:strokeWidth=".8"/>
<path android:pathData="M-13.5-27v162m15-162v162m15-162v162m15-162v162m15-162v162m15-162v162M69,0v108M79,0v108M89,0v108M99,0v108m63,45H54m108-10H54m108-10H54m108-10H54m108-10H54m108-10H54m-0,20h108M54,133h108M54,143h108M54,153h108M73,83h70M73,93h70m-70,10h70m-70,10h70m-70,10h70m-70,10h70M83,73v70m10-70v70m10-70v70m10-70v70m10-70v70m10-70v70" android:strokeColor="#33ffffff" android:strokeWidth=".8"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
<group android:name="rotationGroup">
<path android:fillColor="#4d000000" android:name="vect" android:pathData="M17.03,5.672 15.417,5.24l0.518,-1.932L12.071,2.273l-0.518,1.932L9.94,3.772a1.336,1.336,0,0,0,-1.629,0.94l-0.95,3.545 4.762,1.276 1.551,-1.655-0.518,1.932 3.864,1.035 0.95,-3.545A1.336,1.336,0,0,0,17.03,5.672"/>
<path android:fillColor="#000" android:name="draw" android:pathData="M12.251,13.191l1.932,0.518-5.805,6.209 1.424,-5.313L7.869,14.088l4.254,-4.554L7.361,8.258 4.341,19.53a1.336,1.336,0,0,0,0.94,1.629l7.08,1.897A1.338,1.338,0,0,0,14,22.118l3.02,-11.272L13.157,9.811l-0.906,3.381"/>
<path android:fillColor="#4d000000" android:name="vect" android:pathData="M17.03,5.672 15.417,5.24l0.518-1.932-3.864-1.035-0.518,1.932L9.94,3.772C9.235,3.583 8.5,4.008 8.311,4.713l-0.95,3.545 4.762,1.276 1.551-1.655-0.518,1.932 3.864,1.035 0.95-3.545c0.189-0.705-0.235-1.44-0.94-1.629"/>
<path android:fillColor="#000" android:name="draw" android:pathData="M12.251,13.191l1.932,0.518-5.805,6.209 1.424-5.313-1.932-0.518 4.254-4.554L7.361,8.258 4.341,19.53c-0.189,0.705 0.235,1.44 0.94,1.629l7.08,1.897c0.715,0.192 1.45-0.233 1.639-0.938l3.02-11.272-3.864-1.035-0.906,3.381"/>
</group>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="100dp" android:viewportHeight="100" android:viewportWidth="100" android:width="100dp">
<path android:fillColor="#444" android:fillType="evenOdd" android:pathData="M50,0C22.397,0 0,22.397 0,50c0,27.603 22.397,50 50,50 27.549,0 50,-22.397 50,-50C100,22.397 77.549,0 50,0Zm33.026,23.048a42.512,42.512,0,0,1,9.653,26.573c-1.41,-0.271-15.51,-3.145-29.718,-1.356C62.636,47.56 62.364,46.8 62.039,46.041a127.096,127.096,0,0,0,-2.82,-6.182C74.946,33.46 82.104,24.241 83.026,23.048ZM50,7.375a42.611,42.611,0,0,1,28.308,10.738c-0.759,1.085-7.213,9.707-22.397,15.401C48.915,20.662 41.16,10.141 39.967,8.514A43.431,43.431,0,0,1,50,7.375Zm-18.167,4.013a269.496,269.496,0,0,1,15.835,24.675c-19.957,5.314-37.581,5.206-39.479,5.206A42.906,42.906,0,0,1,31.833,11.388ZM7.267,50.054l0,-1.301c1.844,0.054 22.56,0.325 43.872,-6.074a127.033,127.033,0,0,1,3.471,7.267c-0.542,0.163-1.139,0.325-1.681,0.488-22.017,7.104-33.731,26.519-34.707,28.145A42.608,42.608,0,0,1,7.267,50.054ZM50,92.733c-9.87,0-18.98,-3.362-26.193,-9.002C24.566,82.158 33.243,65.455 57.321,57.05c0.109,-0.054 0.163,-0.054 0.271,-0.109a176.543,176.543,0,0,1,9.111,32.375A42.003,42.003,0,0,1,50,92.733Zm23.807,-7.321A183.744,183.744,0,0,0,65.51,54.989c13.395,-2.115 25.108,1.356 26.573,1.844A42.341,42.341,0,0,1,73.807,85.412Z"/>
<path android:fillColor="#444" android:fillType="evenOdd" android:pathData="M50,0C22.397,0 0,22.397 0,50c0,27.603 22.397,50 50,50 27.549,0 50-22.397 50-50 0-27.603-22.451-50-50-50Zm33.026,23.048c5.965,7.267 9.545,16.54 9.653,26.573-1.41-0.271-15.51-3.145-29.718-1.356-0.325-0.705-0.597-1.464-0.922-2.223-0.868-2.061-1.844-4.176-2.82-6.182 15.727-6.399 22.885-15.618 23.807-16.811ZM50,7.375c10.846,0 20.77,4.067 28.308,10.738-0.759,1.085-7.213,9.707-22.397,15.401-6.996-12.852-14.751-23.373-15.944-25 3.2-0.759 6.562-1.139 10.033-1.139Zm-18.167,4.013c1.139,1.518 8.731,12.093 15.835,24.675-19.957,5.314-37.581,5.206-39.479,5.206 2.766-13.232 11.714-24.241 23.644-29.881ZM7.267,50.054l0-1.301c1.844,0.054 22.56,0.325 43.872-6.074 1.247,2.386 2.386,4.826 3.471,7.267-0.542,0.163-1.139,0.325-1.681,0.488-22.017,7.104-33.731,26.519-34.707,28.145-6.779-7.538-10.954-17.57-10.954-28.525ZM50,92.733c-9.87,0-18.98-3.362-26.193-9.002 0.759-1.573 9.436-18.276 33.514-26.681 0.109-0.054 0.163-0.054 0.271-0.109 6.019,15.564 8.46,28.633 9.111,32.375C61.551,91.54 55.911,92.733 50,92.733Zm23.807-7.321c-0.434-2.603-2.712-15.076-8.297-30.423 13.395-2.115 25.108,1.356 26.573,1.844-1.844,11.876-8.677,22.126-18.275,28.579Z"/>
</vector>
Loading