Skip to content

Commit

Permalink
Fix AndroidSVG formatting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenHenning committed Jun 9, 2023
1 parent 4bc1d26 commit 1265eb1
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.caverock.androidsvg.utils;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class CSSFontVariationSettings
Expand All @@ -18,6 +20,7 @@ public class CSSFontVariationSettings
static final Float VARIATION_ITALIC_VALUE_ON = 1f;
static final Float VARIATION_OBLIQUE_VALUE_ON = -14f; // -14 degrees

private static final NumberFormat NUMBER_FORMATTER = createNumberFormatter();

private static class FontVariationEntry {
String name;
Expand Down Expand Up @@ -70,8 +73,7 @@ public String toString()
sb.append("'");
sb.append(entry.getKey());
sb.append("' ");
DecimalFormat format = new DecimalFormat("#.##");
sb.append(format.format(entry.getValue()));
sb.append(NUMBER_FORMATTER.format(entry.getValue()));
}
return sb.toString();
}
Expand Down Expand Up @@ -124,5 +126,21 @@ private static CSSFontVariationSettings.FontVariationEntry nextFeatureEntry(Text
}


private static final NumberFormat createNumberFormatter() {
// Use the US locale for strong consistency in number-only formatting for high confidence in
// the parsability of formatted values.
NumberFormat formatter = NumberFormat.getNumberInstance(Locale.US);

// NumberFormat's factories should generally be used instead of directly instantiating a
// DecimalFormat (per documentation). Also, the Locale must be fixed because this is producing
// a string that will be parsed so non-Hindi-Arabic numerals won't work for such times when
// the default Locale is changed to use one of those numeral types for formatting (such as
// eastern Arabic numerals).
if (formatter instanceof DecimalFormat) {
((DecimalFormat) formatter).applyPattern("#.##");
}

return formatter;
}

}

0 comments on commit 1265eb1

Please sign in to comment.