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

Side by Side Diff: printing/units.cc

Issue 2116283002: Don't let rounding prematurely influence document size when printing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@620456-2
Patch Set: bug 467579 Created 4 years, 4 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
« no previous file with comments | « printing/units.h ('k') | printing/units_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "printing/units.h" 5 #include "printing/units.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "printing/print_job_constants.h" 8 #include "printing/print_job_constants.h"
9 9
10 namespace printing { 10 namespace printing {
11 11
12 int ConvertUnit(int value, int old_unit, int new_unit) { 12 int ConvertUnit(double value, int old_unit, int new_unit) {
13 DCHECK_GT(new_unit, 0); 13 DCHECK_GT(new_unit, 0);
14 DCHECK_GT(old_unit, 0); 14 DCHECK_GT(old_unit, 0);
15 // With integer arithmetic, to divide a value with correct rounding, you need 15 // With integer arithmetic, to divide a value with correct rounding, you need
16 // to add half of the divisor value to the dividend value. You need to do the 16 // to add half of the divisor value to the dividend value. You need to do the
17 // reverse with negative number. 17 // reverse with negative number.
18 if (value >= 0) { 18 if (value >= 0) {
19 return ((value * new_unit) + (old_unit / 2)) / old_unit; 19 return ((value * new_unit) + (old_unit / 2)) / old_unit;
20 } else { 20 } else {
21 return ((value * new_unit) - (old_unit / 2)) / old_unit; 21 return ((value * new_unit) - (old_unit / 2)) / old_unit;
22 } 22 }
(...skipping 23 matching lines...) Expand all
46 46
47 double ConvertPixelsToPointDouble(double pixels) { 47 double ConvertPixelsToPointDouble(double pixels) {
48 return ConvertUnitDouble(pixels, kPixelsPerInch, kPointsPerInch); 48 return ConvertUnitDouble(pixels, kPixelsPerInch, kPointsPerInch);
49 } 49 }
50 50
51 double ConvertPointsToPixelDouble(double points) { 51 double ConvertPointsToPixelDouble(double points) {
52 return ConvertUnitDouble(points, kPointsPerInch, kPixelsPerInch); 52 return ConvertUnitDouble(points, kPointsPerInch, kPixelsPerInch);
53 } 53 }
54 54
55 } // namespace printing 55 } // namespace printing
OLDNEW
« no previous file with comments | « printing/units.h ('k') | printing/units_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698