Files
mono/mcs/class/System.Drawing/System.Drawing.Printing/PrinterUnitConvert.cs
T
Andreas N ccad7900c6 2004-02-07 Andreas Nahr <[email protected]>
* Margins.cs: Restyled, implemented missing members
	* PageSettings.cs: Added missing attributes, stubbed,
	  fixed a few small issues
	* PreviewPrintController.cs: Stubbed, small issues fixed
	* PrintController.cs: Marked unfinished, restyled
	* PrintDocument.cs: Added attributes
	* PrinterResolution.cs: Added missing method
	* PrinterSettings.cs: Mono-stylyzed, fixed signatures,
	  removed commented out values
	* PrinterUnitConvert.cs: Added private constructor
	* StandardPrintController.cs: Little restyling
	* PaperKind.cs: Added missing enum values

svn path=/trunk/mcs/; revision=22874
2004-02-08 07:59:06 +00:00

114 lines
3.0 KiB
C#

//
// System.Drawing.Printing.PrinterUnitConvert.cs
//
// Authors:
// Martin Willemoes Hansen ([email protected])
// Herve Poussineau ([email protected])
//
// (C) 2003 Martin Willemoes Hansen
//
namespace System.Drawing.Printing
{
public sealed class PrinterUnitConvert
{
private PrinterUnitConvert ()
{
}
public static double Convert (double value,
PrinterUnit fromUnit,
PrinterUnit toUnit)
{
switch (fromUnit)
{
case PrinterUnit.Display:
switch (toUnit)
{
case PrinterUnit.Display: return value;
case PrinterUnit.ThousandthsOfAnInch: return value * 10;
case PrinterUnit.HundredthsOfAMillimeter: return value * 2.54;
case PrinterUnit.TenthsOfAMillimeter: return value * .254;
}
break;
case PrinterUnit.ThousandthsOfAnInch:
switch (toUnit)
{
case PrinterUnit.Display: return value / 10;
case PrinterUnit.ThousandthsOfAnInch: return value;
case PrinterUnit.HundredthsOfAMillimeter: return value * .254;
case PrinterUnit.TenthsOfAMillimeter: return value * .0254;
}
break;
case PrinterUnit.HundredthsOfAMillimeter:
switch (toUnit)
{
case PrinterUnit.Display: return value / 2.54;
case PrinterUnit.ThousandthsOfAnInch: return value / .254;
case PrinterUnit.HundredthsOfAMillimeter: return value;
case PrinterUnit.TenthsOfAMillimeter: return value / 10;
}
break;
case PrinterUnit.TenthsOfAMillimeter:
switch (toUnit)
{
case PrinterUnit.Display: return value / .254;
case PrinterUnit.ThousandthsOfAnInch: return value / .0254;
case PrinterUnit.HundredthsOfAMillimeter: return value * 10;
case PrinterUnit.TenthsOfAMillimeter: return value;
}
break;
}
// should never happen
throw new NotImplementedException();
}
public static int Convert (int value,
PrinterUnit fromUnit,
PrinterUnit toUnit)
{
return (int)Convert((double)value, fromUnit, toUnit);
}
public static Margins Convert (Margins value,
PrinterUnit fromUnit,
PrinterUnit toUnit)
{
return new Margins(
Convert(value.Left, fromUnit, toUnit),
Convert(value.Right, fromUnit, toUnit),
Convert(value.Top, fromUnit, toUnit),
Convert(value.Bottom, fromUnit, toUnit));
}
public static Point Convert (Point value,
PrinterUnit fromUnit,
PrinterUnit toUnit)
{
return new Point(
Convert(value.X, fromUnit, toUnit),
Convert(value.Y, fromUnit, toUnit));
}
public static Rectangle Convert (Rectangle value,
PrinterUnit fromUnit,
PrinterUnit toUnit)
{
return new Rectangle(
Convert(value.X, fromUnit, toUnit),
Convert(value.Y, fromUnit, toUnit),
Convert(value.Width, fromUnit, toUnit),
Convert(value.Height, fromUnit, toUnit));
}
public static Size Convert (Size value,
PrinterUnit fromUnit,
PrinterUnit toUnit)
{
return new Size(
Convert(value.Width, fromUnit, toUnit),
Convert(value.Height, fromUnit, toUnit));
}
}
}