2 // System.Drawing.Printing.PrinterUnitConvert.cs
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Herve Poussineau (hpoussineau@fr.st)
8 // (C) 2003 Martin Willemoes Hansen
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 namespace System
.Drawing
.Printing
36 public sealed class PrinterUnitConvert
38 private PrinterUnitConvert ()
42 public static double Convert (double value,
48 case PrinterUnit
.Display
:
51 case PrinterUnit
.Display
: return value;
52 case PrinterUnit
.ThousandthsOfAnInch
: return value * 10;
53 case PrinterUnit
.HundredthsOfAMillimeter
: return value * 25.4;
54 case PrinterUnit
.TenthsOfAMillimeter
: return value * 2.54;
57 case PrinterUnit
.ThousandthsOfAnInch
:
60 case PrinterUnit
.Display
: return value / 10;
61 case PrinterUnit
.ThousandthsOfAnInch
: return value;
62 case PrinterUnit
.HundredthsOfAMillimeter
: return value * 2.54;
63 case PrinterUnit
.TenthsOfAMillimeter
: return value * 0.254;
66 case PrinterUnit
.HundredthsOfAMillimeter
:
69 case PrinterUnit
.Display
: return value / 25.4;
70 case PrinterUnit
.ThousandthsOfAnInch
: return value / 2.54;
71 case PrinterUnit
.HundredthsOfAMillimeter
: return value;
72 case PrinterUnit
.TenthsOfAMillimeter
: return value / 10;
75 case PrinterUnit
.TenthsOfAMillimeter
:
78 case PrinterUnit
.Display
: return value / 2.54;
79 case PrinterUnit
.ThousandthsOfAnInch
: return value / 0.254;
80 case PrinterUnit
.HundredthsOfAMillimeter
: return value * 10;
81 case PrinterUnit
.TenthsOfAMillimeter
: return value;
85 // should never happen
86 throw new NotImplementedException();
89 public static int Convert (int value,
94 rslt
= Convert ((double) value, fromUnit
, toUnit
);
95 return (int) Math
.Round (rslt
);
99 public static Margins
Convert (Margins
value,
100 PrinterUnit fromUnit
,
104 Convert(value.Left
, fromUnit
, toUnit
),
105 Convert(value.Right
, fromUnit
, toUnit
),
106 Convert(value.Top
, fromUnit
, toUnit
),
107 Convert(value.Bottom
, fromUnit
, toUnit
));
110 public static Point
Convert (Point
value,
111 PrinterUnit fromUnit
,
115 Convert(value.X
, fromUnit
, toUnit
),
116 Convert(value.Y
, fromUnit
, toUnit
));
119 public static Rectangle
Convert (Rectangle
value,
120 PrinterUnit fromUnit
,
123 return new Rectangle(
124 Convert(value.X
, fromUnit
, toUnit
),
125 Convert(value.Y
, fromUnit
, toUnit
),
126 Convert(value.Width
, fromUnit
, toUnit
),
127 Convert(value.Height
, fromUnit
, toUnit
));
130 public static Size
Convert (Size
value,
131 PrinterUnit fromUnit
,
135 Convert(value.Width
, fromUnit
, toUnit
),
136 Convert(value.Height
, fromUnit
, toUnit
));