Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: chrome/browser/resources/print_preview/data/measurement_system.js

Issue 575333002: Compile print_preview, part 2: reduce down to 260 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@I_print_preview
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Measurement system of the print preview. Used to parse and serialize point 9 * Measurement system of the print preview. Used to parse and serialize point
10 * measurements into the system's local units (e.g. millimeters, inches). 10 * measurements into the system's local units (e.g. millimeters, inches).
(...skipping 20 matching lines...) Expand all
31 MeasurementSystem.parseNumberFormat = function(numberFormat) { 31 MeasurementSystem.parseNumberFormat = function(numberFormat) {
32 if (!numberFormat) { 32 if (!numberFormat) {
33 return [',', '.']; 33 return [',', '.'];
34 } 34 }
35 var regex = /^(\d+)(\W?)(\d+)(\W?)(\d+)$/; 35 var regex = /^(\d+)(\W?)(\d+)(\W?)(\d+)$/;
36 var matches = numberFormat.match(regex) || ['', '', ',', '', '.']; 36 var matches = numberFormat.match(regex) || ['', '', ',', '', '.'];
37 return [matches[2], matches[4]]; 37 return [matches[2], matches[4]];
38 }; 38 };
39 39
40 /** 40 /**
41 * Enumeration of measurement unit types.
42 * @enum {number}
43 */
44 MeasurementSystem.UnitType = {
45 METRIC: 0, // millimeters
46 IMPERIAL: 1 // inches
47 };
48
49 /**
50 * Maximum resolution of local unit values. 41 * Maximum resolution of local unit values.
51 * @type {!Object.<!print_preview.MeasurementSystem.UnitType, number>} 42 * @type {!Object.<!print_preview.MeasurementSystem.UnitType, number>}
52 * @private 43 * @private
53 */ 44 */
54 MeasurementSystem.Precision_ = {}; 45 MeasurementSystem.Precision_ = {};
55 MeasurementSystem.Precision_[MeasurementSystem.UnitType.METRIC] = 0.5; 46 MeasurementSystem.Precision_[MeasurementSystem.UnitType.METRIC] = 0.5;
56 MeasurementSystem.Precision_[MeasurementSystem.UnitType.IMPERIAL] = 0.01; 47 MeasurementSystem.Precision_[MeasurementSystem.UnitType.IMPERIAL] = 0.01;
57 48
58 /** 49 /**
59 * Maximum number of decimal places to keep for local unit. 50 * Maximum number of decimal places to keep for local unit.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 107
117 /** 108 /**
118 * Rounds a value in the local system's units to the appropriate precision. 109 * Rounds a value in the local system's units to the appropriate precision.
119 * @param {number} value Value to round. 110 * @param {number} value Value to round.
120 * @return {number} Rounded value. 111 * @return {number} Rounded value.
121 */ 112 */
122 roundValue: function(value) { 113 roundValue: function(value) {
123 var precision = MeasurementSystem.Precision_[this.unitType_]; 114 var precision = MeasurementSystem.Precision_[this.unitType_];
124 var roundedValue = Math.round(value / precision) * precision; 115 var roundedValue = Math.round(value / precision) * precision;
125 // Truncate 116 // Truncate
126 return roundedValue.toFixed( 117 return +roundedValue.toFixed(
127 MeasurementSystem.DecimalPlaces_[this.unitType_]); 118 MeasurementSystem.DecimalPlaces_[this.unitType_]);
128 }, 119 },
129 120
130 /** 121 /**
131 * @param {number} pts Value in points to convert to local units. 122 * @param {number} pts Value in points to convert to local units.
132 * @return {number} Value in local units. 123 * @return {number} Value in local units.
133 */ 124 */
134 convertFromPoints: function(pts) { 125 convertFromPoints: function(pts) {
135 if (this.unitType_ == MeasurementSystem.UnitType.METRIC) { 126 if (this.unitType_ == MeasurementSystem.UnitType.METRIC) {
136 return pts / MeasurementSystem.PTS_PER_MM_; 127 return pts / MeasurementSystem.PTS_PER_MM_;
(...skipping 13 matching lines...) Expand all
150 return localUnits * MeasurementSystem.PTS_PER_INCH_; 141 return localUnits * MeasurementSystem.PTS_PER_INCH_;
151 } 142 }
152 } 143 }
153 }; 144 };
154 145
155 // Export 146 // Export
156 return { 147 return {
157 MeasurementSystem: MeasurementSystem 148 MeasurementSystem: MeasurementSystem
158 }; 149 };
159 }); 150 });
151
152 /**
153 * Enumeration of measurement unit types.
154 * @enum {number}
155 */
156 print_preview.MeasurementSystem.UnitType = {
157 METRIC: 0, // millimeters
158 IMPERIAL: 1 // inches
159 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698