using System;
using System.Collections;
namespace FastReport.Utils
{
///
/// The report page units.
///
public enum PageUnits
{
///
/// Specifies the units measured in millimeters.
///
Millimeters,
///
/// Specifies the units measured in centimeters.
///
Centimeters,
///
/// Specifies the units measured in inches.
///
Inches,
///
/// Specifies the units measured in hundreths of inch.
///
HundrethsOfInch
}
///
/// Defines the constants used to convert between report units and screen pixels.
///
///
/// To convert pixels to millimeters, use the following code:
/// valueInMillimeters = valueInPixels / Units.Millimeters;
/// To convert millimeters to pixels, use the following code:
/// valueInPixels = valueInMillimeters * Units.Millimeters;
///
public static class Units
{
///
/// The number of pixels in one millimeter.
///
public static float Millimeters = 3.78f;
///
/// The number of pixels in one centimeter.
///
public static float Centimeters = 37.8f;
///
/// The number of pixels in one inch.
///
public static float Inches = 96;
///
/// The number of pixels in 1/10 of ich.
///
public static float TenthsOfInch = 9.6f;
///
/// The number of pixels in 1/100 of inch.
///
public static float HundrethsOfInch = 0.96f;
}
public static class FileSize
{
///
/// File size units.
///
public enum Units
{
///
/// Bytes.
///
Bytes,
///
/// Kilobytes.
///
KB,
///
/// Megabytes.
///
MB,
///
/// Gigabytes.
///
GB,
///
/// Terobytes.
///
TB
}
///
/// Convert numbers to file size (example 1 MB).
///
///
///
public static string ConvertToString(long value)
{
int steps = 0;
float result = value;
while (result > 1024 - 1)
{
result /= 1024;
steps++;
}
return result.ToString("F2") + " " + GetUnits((Units)steps);
}
private static string GetUnits(Units units)
{
switch (units)
{
case Units.Bytes:
return Res.Get("Misc,Bytes");
case Units.KB:
return Res.Get("Misc,KB");
case Units.MB:
return Res.Get("Misc,MB");
case Units.GB:
return Res.Get("Misc,GB");
case Units.TB:
return Res.Get("Misc,TB");
default:
return Res.Get("Misc,Bytes");
}
}
}
}