| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/print_messages.h" | 
|  | 9 #include "printing/print_job_constants.h" | 
| 8 | 10 | 
| 9 namespace printing { | 11 namespace printing { | 
| 10 | 12 | 
| 11 int ConvertUnit(int value, int old_unit, int new_unit) { | 13 int ConvertUnit(int value, int old_unit, int new_unit) { | 
| 12   DCHECK_GT(new_unit, 0); | 14   DCHECK_GT(new_unit, 0); | 
| 13   DCHECK_GT(old_unit, 0); | 15   DCHECK_GT(old_unit, 0); | 
| 14   // With integer arithmetic, to divide a value with correct rounding, you need | 16   // With integer arithmetic, to divide a value with correct rounding, you need | 
| 15   // to add half of the divisor value to the dividend value. You need to do the | 17   // to add half of the divisor value to the dividend value. You need to do the | 
| 16   // reverse with negative number. | 18   // reverse with negative number. | 
| 17   if (value >= 0) { | 19   if (value >= 0) { | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 40 } | 42 } | 
| 41 | 43 | 
| 42 int ConvertPixelsToPoint(int pixels) { | 44 int ConvertPixelsToPoint(int pixels) { | 
| 43   return ConvertUnit(pixels, kPixelsPerInch, kPointsPerInch); | 45   return ConvertUnit(pixels, kPixelsPerInch, kPointsPerInch); | 
| 44 } | 46 } | 
| 45 | 47 | 
| 46 double ConvertPixelsToPointDouble(double pixels) { | 48 double ConvertPixelsToPointDouble(double pixels) { | 
| 47   return ConvertUnitDouble(pixels, kPixelsPerInch, kPointsPerInch); | 49   return ConvertUnitDouble(pixels, kPixelsPerInch, kPointsPerInch); | 
| 48 } | 50 } | 
| 49 | 51 | 
|  | 52 double ConvertPointsToPixelDouble(double points) { | 
|  | 53   return ConvertUnitDouble(points, kPointsPerInch, kPixelsPerInch); | 
|  | 54 } | 
|  | 55 | 
|  | 56 double GetSegmentWidth(double page_width) { | 
|  | 57   // Interstice is left at both ends of the page as well as between | 
|  | 58   // each region, so 1 is added. | 
|  | 59   double total_interstice_width = | 
|  | 60       (printing::kSettingHeaderFooterHorizontalRegions + 1) * | 
|  | 61       printing::kSettingHeaderFooterInterstice; | 
|  | 62   return (page_width - total_interstice_width) / | 
|  | 63              printing::kSettingHeaderFooterHorizontalRegions; | 
|  | 64 } | 
|  | 65 | 
|  | 66 int GetDPI(const PrintMsg_Print_Params* print_params) { | 
|  | 67 #if defined(OS_MACOSX) | 
|  | 68   // On the Mac, the printable area is in points, don't do any scaling based | 
|  | 69   // on dpi. | 
|  | 70   return printing::kPointsPerInch; | 
|  | 71 #else | 
|  | 72   return static_cast<int>(print_params->dpi); | 
|  | 73 #endif  // defined(OS_MACOSX) | 
|  | 74 } | 
|  | 75 | 
| 50 }  // namespace printing | 76 }  // namespace printing | 
| OLD | NEW | 
|---|