Commit 68612780 authored by dpapad@chromium.org's avatar dpapad@chromium.org

Print Preview: Partial fix, when number format can't be retrieved for current locale.

BUG=104858
TEST=NONE


Review URL: http://codereview.chromium.org/8922021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114167 0039d316-1c4b-4281-b951-d872f2087c98
parent 49fffd31
...@@ -167,7 +167,7 @@ cr.define('print_preview', function() { ...@@ -167,7 +167,7 @@ cr.define('print_preview', function() {
/** /**
* Extracts the number formatting and measurement system for the current * Extracts the number formatting and measurement system for the current
* locale. * locale.
* @param {string} numberFormat Is the formatted version of a sample number, * @param {string} numberFormat Is the formatted version of a sample number
* sent from the backend. * sent from the backend.
* @param {number} measurementSystem 0 for SI (aka metric system), 1 for the * @param {number} measurementSystem 0 for SI (aka metric system), 1 for the
* system used in the US. Note: Mathces UMeasurementSystem enum in * system used in the US. Note: Mathces UMeasurementSystem enum in
...@@ -175,10 +175,9 @@ cr.define('print_preview', function() { ...@@ -175,10 +175,9 @@ cr.define('print_preview', function() {
*/ */
MarginSettings.setNumberFormatAndMeasurementSystem = function( MarginSettings.setNumberFormatAndMeasurementSystem = function(
numberFormat, measurementSystem) { numberFormat, measurementSystem) {
var regex = /^(\d+)(\.|\,)(\d+)(\.|\,)(\d+)$/; var symbols = parseNumberFormat(numberFormat);
var matches = numberFormat.match(regex); MarginSettings.thousandsPoint = symbols[0];
MarginSettings.thousandsPoint = matches[2]; MarginSettings.decimalPoint = symbols[1];
MarginSettings.decimalPoint = matches[4];
MarginSettings.useMetricSystem = measurementSystem == 0; MarginSettings.useMetricSystem = measurementSystem == 0;
}; };
......
...@@ -247,3 +247,19 @@ function convertMillimetersToPoints(value) { ...@@ -247,3 +247,19 @@ function convertMillimetersToPoints(value) {
function convertPointsToMillimeters(value) { function convertPointsToMillimeters(value) {
return value / POINTS_PER_MILLIMETER; return value / POINTS_PER_MILLIMETER;
} }
/**
* Parses |numberFormat| and extracts the symbols used for the thousands point
* and decimal point.
* @param {string} numberFormat The formatted version of the number 12345678.
* @return {!array.<string>} The extracted symbols in the order
* [thousandsSymbol, decimalSymbol]]. For example
* parseNumberFormat("123,456.78") returns [",", "."].
*/
function parseNumberFormat(numberFormat) {
if (!numberFormat)
numberFormat = '';
var regex = /^(\d+)(\W{0,1})(\d+)(\W{0,1})(\d+)$/;
var matches = numberFormat.match(regex) || ['','',',','','.'];
return [matches[2], matches[4]];
}
...@@ -111,3 +111,21 @@ TEST_F('PrintPreviewUtilsUnitTest', 'PageSetToPageRanges', function() { ...@@ -111,3 +111,21 @@ TEST_F('PrintPreviewUtilsUnitTest', 'PageSetToPageRanges', function() {
assertEquals(pageRanges[2].from, 11); assertEquals(pageRanges[2].from, 11);
assertEquals(pageRanges[2].to, 11); assertEquals(pageRanges[2].to, 11);
}); });
TEST_F('PrintPreviewUtilsUnitTest', 'ParseNumberFormat', function() {
assertTrue(areArraysEqual(['.', ','], parseNumberFormat('123.456,78')));
assertTrue(areArraysEqual(['.', '.'], parseNumberFormat('123.456.78')));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat('123,456.78')));
assertTrue(areArraysEqual([',', ','], parseNumberFormat('123,456,78')));
assertTrue(areArraysEqual([' ', ','], parseNumberFormat('123 456,78')));
assertTrue(areArraysEqual([' ', '.'], parseNumberFormat('123 456.78')));
assertTrue(areArraysEqual([' ', ' '], parseNumberFormat('123 456 78')));
assertTrue(areArraysEqual(['', ''], parseNumberFormat('123')));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat('abcdef')));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat(null)));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat(undefined)));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat('')));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat('1')));
assertTrue(areArraysEqual([',', '.'], parseNumberFormat('12')));
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment