(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Drawing / System.Drawing.Printing / PrinterUnitConvert.cs
blobbdaef44b3efb1610da3dfab109ffa35c77be2baa
1 //
2 // System.Drawing.Printing.PrinterUnitConvert.cs
3 //
4 // Authors:
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Herve Poussineau (hpoussineau@fr.st)
7 //
8 // (C) 2003 Martin Willemoes Hansen
9 //
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:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
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,
43 PrinterUnit fromUnit,
44 PrinterUnit toUnit)
46 switch (fromUnit)
48 case PrinterUnit.Display:
49 switch (toUnit)
51 case PrinterUnit.Display: return value;
52 case PrinterUnit.ThousandthsOfAnInch: return value * 10;
53 case PrinterUnit.HundredthsOfAMillimeter: return value * 2.54;
54 case PrinterUnit.TenthsOfAMillimeter: return value * .254;
56 break;
57 case PrinterUnit.ThousandthsOfAnInch:
58 switch (toUnit)
60 case PrinterUnit.Display: return value / 10;
61 case PrinterUnit.ThousandthsOfAnInch: return value;
62 case PrinterUnit.HundredthsOfAMillimeter: return value * .254;
63 case PrinterUnit.TenthsOfAMillimeter: return value * .0254;
65 break;
66 case PrinterUnit.HundredthsOfAMillimeter:
67 switch (toUnit)
69 case PrinterUnit.Display: return value / 2.54;
70 case PrinterUnit.ThousandthsOfAnInch: return value / .254;
71 case PrinterUnit.HundredthsOfAMillimeter: return value;
72 case PrinterUnit.TenthsOfAMillimeter: return value / 10;
74 break;
75 case PrinterUnit.TenthsOfAMillimeter:
76 switch (toUnit)
78 case PrinterUnit.Display: return value / .254;
79 case PrinterUnit.ThousandthsOfAnInch: return value / .0254;
80 case PrinterUnit.HundredthsOfAMillimeter: return value * 10;
81 case PrinterUnit.TenthsOfAMillimeter: return value;
83 break;
85 // should never happen
86 throw new NotImplementedException();
89 public static int Convert (int value,
90 PrinterUnit fromUnit,
91 PrinterUnit toUnit)
93 return (int)Convert((double)value, fromUnit, toUnit);
96 public static Margins Convert (Margins value,
97 PrinterUnit fromUnit,
98 PrinterUnit toUnit)
100 return new Margins(
101 Convert(value.Left, fromUnit, toUnit),
102 Convert(value.Right, fromUnit, toUnit),
103 Convert(value.Top, fromUnit, toUnit),
104 Convert(value.Bottom, fromUnit, toUnit));
107 public static Point Convert (Point value,
108 PrinterUnit fromUnit,
109 PrinterUnit toUnit)
111 return new Point(
112 Convert(value.X, fromUnit, toUnit),
113 Convert(value.Y, fromUnit, toUnit));
116 public static Rectangle Convert (Rectangle value,
117 PrinterUnit fromUnit,
118 PrinterUnit toUnit)
120 return new Rectangle(
121 Convert(value.X, fromUnit, toUnit),
122 Convert(value.Y, fromUnit, toUnit),
123 Convert(value.Width, fromUnit, toUnit),
124 Convert(value.Height, fromUnit, toUnit));
127 public static Size Convert (Size value,
128 PrinterUnit fromUnit,
129 PrinterUnit toUnit)
131 return new Size(
132 Convert(value.Width, fromUnit, toUnit),
133 Convert(value.Height, fromUnit, toUnit));