| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.exportPath('print_preview'); | 5 cr.exportPath('print_preview'); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Enumeration of measurement unit types. | 8 * Enumeration of measurement unit types. |
| 9 * @enum {number} | 9 * @enum {number} |
| 10 */ | 10 */ |
| 11 print_preview.MeasurementSystemUnitType = { | 11 print_preview.MeasurementSystemUnitType = { |
| 12 METRIC: 0, // millimeters | 12 METRIC: 0, // millimeters |
| 13 IMPERIAL: 1 // inches | 13 IMPERIAL: 1 // inches |
| 14 }; | 14 }; |
| 15 | 15 |
| 16 cr.define('print_preview', function() { | 16 cr.define('print_preview', function() { |
| 17 'use strict'; | 17 'use strict'; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Measurement system of the print preview. Used to parse and serialize point | 20 * Measurement system of the print preview. Used to parse and serialize point |
| 21 * measurements into the system's local units (e.g. millimeters, inches). | 21 * measurements into the system's local units (e.g. millimeters, inches). |
| 22 * @param {string} thousandsDelimeter Delimeter between thousands digits. | 22 * @param {string} thousandsDelimeter Delimeter between thousands digits. |
| 23 * @param {string} decimalDelimeter Delimeter between integers and decimals. | 23 * @param {string} decimalDelimeter Delimeter between integers and decimals. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 var matches = numberFormat.match(regex) || ['', '', ',', '', '.']; | 47 var matches = numberFormat.match(regex) || ['', '', ',', '', '.']; |
| 48 return [matches[2], matches[4]]; | 48 return [matches[2], matches[4]]; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Maximum resolution of local unit values. | 52 * Maximum resolution of local unit values. |
| 53 * @type {!Object<!print_preview.MeasurementSystemUnitType, number>} | 53 * @type {!Object<!print_preview.MeasurementSystemUnitType, number>} |
| 54 * @private | 54 * @private |
| 55 */ | 55 */ |
| 56 MeasurementSystem.Precision_ = {}; | 56 MeasurementSystem.Precision_ = {}; |
| 57 MeasurementSystem.Precision_[ | 57 MeasurementSystem.Precision_[print_preview.MeasurementSystemUnitType.METRIC] = |
| 58 print_preview.MeasurementSystemUnitType.METRIC] = 0.5; | 58 0.5; |
| 59 MeasurementSystem.Precision_[ | 59 MeasurementSystem |
| 60 print_preview.MeasurementSystemUnitType.IMPERIAL] = 0.01; | 60 .Precision_[print_preview.MeasurementSystemUnitType.IMPERIAL] = 0.01; |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Maximum number of decimal places to keep for local unit. | 63 * Maximum number of decimal places to keep for local unit. |
| 64 * @type {!Object<!print_preview.MeasurementSystemUnitType, number>} | 64 * @type {!Object<!print_preview.MeasurementSystemUnitType, number>} |
| 65 * @private | 65 * @private |
| 66 */ | 66 */ |
| 67 MeasurementSystem.DecimalPlaces_ = {}; | 67 MeasurementSystem.DecimalPlaces_ = {}; |
| 68 MeasurementSystem.DecimalPlaces_[ | 68 MeasurementSystem |
| 69 print_preview.MeasurementSystemUnitType.METRIC] = 1; | 69 .DecimalPlaces_[print_preview.MeasurementSystemUnitType.METRIC] = 1; |
| 70 MeasurementSystem.DecimalPlaces_[ | 70 MeasurementSystem |
| 71 print_preview.MeasurementSystemUnitType.IMPERIAL] = 2; | 71 .DecimalPlaces_[print_preview.MeasurementSystemUnitType.IMPERIAL] = 2; |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Number of points per inch. | 74 * Number of points per inch. |
| 75 * @type {number} | 75 * @type {number} |
| 76 * @const | 76 * @const |
| 77 * @private | 77 * @private |
| 78 */ | 78 */ |
| 79 MeasurementSystem.PTS_PER_INCH_ = 72.0; | 79 MeasurementSystem.PTS_PER_INCH_ = 72.0; |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * Number of points per millimeter. | 82 * Number of points per millimeter. |
| 83 * @type {number} | 83 * @type {number} |
| 84 * @const | 84 * @const |
| 85 * @private | 85 * @private |
| 86 */ | 86 */ |
| 87 MeasurementSystem.PTS_PER_MM_ = MeasurementSystem.PTS_PER_INCH_ / 25.4; | 87 MeasurementSystem.PTS_PER_MM_ = MeasurementSystem.PTS_PER_INCH_ / 25.4; |
| 88 | 88 |
| 89 MeasurementSystem.prototype = { | 89 MeasurementSystem.prototype = { |
| 90 /** @return {string} The unit type symbol of the measurement system. */ | 90 /** @return {string} The unit type symbol of the measurement system. */ |
| 91 get unitSymbol() { | 91 get unitSymbol() { |
| 92 if (this.unitType_ == print_preview.MeasurementSystemUnitType.METRIC) { | 92 if (this.unitType_ == print_preview.MeasurementSystemUnitType.METRIC) { |
| 93 return 'mm'; | 93 return 'mm'; |
| 94 } else if (this.unitType_ == | 94 } else if ( |
| 95 print_preview.MeasurementSystemUnitType.IMPERIAL) { | 95 this.unitType_ == print_preview.MeasurementSystemUnitType.IMPERIAL) { |
| 96 return '"'; | 96 return '"'; |
| 97 } else { | 97 } else { |
| 98 throw Error('Unit type not supported: ' + this.unitType_); | 98 throw Error('Unit type not supported: ' + this.unitType_); |
| 99 } | 99 } |
| 100 }, | 100 }, |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * @return {string} The thousands delimeter character of the measurement | 103 * @return {string} The thousands delimeter character of the measurement |
| 104 * system. | 104 * system. |
| 105 */ | 105 */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 convertToPoints: function(localUnits) { | 153 convertToPoints: function(localUnits) { |
| 154 if (this.unitType_ == print_preview.MeasurementSystemUnitType.METRIC) { | 154 if (this.unitType_ == print_preview.MeasurementSystemUnitType.METRIC) { |
| 155 return localUnits * MeasurementSystem.PTS_PER_MM_; | 155 return localUnits * MeasurementSystem.PTS_PER_MM_; |
| 156 } else { | 156 } else { |
| 157 return localUnits * MeasurementSystem.PTS_PER_INCH_; | 157 return localUnits * MeasurementSystem.PTS_PER_INCH_; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 // Export | 162 // Export |
| 163 return { | 163 return {MeasurementSystem: MeasurementSystem}; |
| 164 MeasurementSystem: MeasurementSystem | |
| 165 }; | |
| 166 }); | 164 }); |
| OLD | NEW |