summaryrefslogtreecommitdiffstats
path: root/printing/units.cc
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-20 17:55:55 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-20 17:55:55 +0000
commit4ae30d08d2df7fdb8b236b6c650a1a29a84ee562 (patch)
tree97a77e2c9bbab02533378c88aa3311cd2353562b /printing/units.cc
parentde4024067816c20a69189c1e0d7728aa2cf16d66 (diff)
downloadchromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.zip
chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.tar.gz
chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.tar.bz2
Move units to new module printing. Add printing_unittests on Windows too. Make test_shell and chrome_dll dependent on printing.
Review URL: http://codereview.chromium.org/21475 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/units.cc')
-rw-r--r--printing/units.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/printing/units.cc b/printing/units.cc
new file mode 100644
index 0000000..5f543fe
--- /dev/null
+++ b/printing/units.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "printing/units.h"
+
+#include "base/logging.h"
+
+namespace printing {
+
+int ConvertUnit(int value, int old_unit, int new_unit) {
+ DCHECK_GT(new_unit, 0);
+ DCHECK_GT(old_unit, 0);
+ // With integer arithmetic, to divide a value with correct rounding, you need
+ // to add half of the divisor value to the dividend value. You need to do the
+ // reverse with negative number.
+ if (value >= 0) {
+ return ((value * new_unit) + (old_unit / 2)) / old_unit;
+ } else {
+ return ((value * new_unit) - (old_unit / 2)) / old_unit;
+ }
+}
+
+double ConvertUnitDouble(double value, double old_unit, double new_unit) {
+ DCHECK_GT(new_unit, 0);
+ DCHECK_GT(old_unit, 0);
+ return value * new_unit / old_unit;
+}
+
+int ConvertMilliInchToHundredThousanthMeter(int milli_inch) {
+ // 1" == 25.4 mm
+ // 1" == 25400 um
+ // 0.001" == 25.4 um
+ // 0.001" == 2.54 cmm
+ return ConvertUnit(milli_inch, 100, 254);
+}
+
+int ConvertHundredThousanthMeterToMilliInch(int cmm) {
+ return ConvertUnit(cmm, 254, 100);
+}
+
+} // namespace printing