using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Windows.Forms; using FastReport.DataVisualization.Charting; namespace FastReport.Design.ExportPlugins.RDL { /// /// The FR units converter. /// internal static class UnitsConverter { #region Public Methods /// /// Converts the float size in pixels to string value in millimeters. /// /// The float value in pixels. /// The string value in millimeters. public static string PixelsToMillimeters(float pixels) { return (pixels / Import.RDL.SizeUnitsP.Millimeter).ToString() + "mm"; } /// /// Converts the float size in millimeters to string value in millimeters. /// /// The float value in millimeters. /// The string value in millimeters. public static string MillimetersToString(float millimeters) { return millimeters.ToString() + "mm"; } /// /// Converts the bool value to string. /// /// The bool value. /// The string value. public static string ConvertBool(bool value) { return value.ToString().ToLower(); } /// /// Converts the int size in pixels to string value in pt. /// /// The int value in pixels. /// The string value in pt. public static string ConvertPixels(int pixels) { return pixels.ToString() + "pt"; } /// /// Converts the Color value to string. /// /// The Color value. /// The string representation of Color value. public static string ConvertColor(Color color) { if (color.ToKnownColor() == 0) { return Color.Red.Name; } return color.Name; } /// /// Converts the LineStyle value to RDL BorderStyle value. /// /// The LineStyle value. /// The string with RDL BorderStyle value. public static string ConvertLineStyle(LineStyle ls) { if (ls == LineStyle.Dot) { return "Dotted"; } else if (ls == LineStyle.Dash) { return "Dashed"; } else if (ls == LineStyle.Double) { return "Double"; } return "Solid"; } /// /// Converts the GradientStyle value to RDL GradientType value. /// /// The GradientStyle value. /// The string with RDL GradientType value. public static string ConvertGradientStyle(GradientStyle gs) { if (gs == GradientStyle.Center) { return "Center"; } else if (gs == GradientStyle.DiagonalLeft) { return "DiagonalLeft"; } else if (gs == GradientStyle.DiagonalRight) { return "DiagonalRight"; } else if (gs == GradientStyle.HorizontalCenter) { return "HorizontalCenter"; } else if (gs == GradientStyle.LeftRight) { return "LeftRight"; } else if (gs == GradientStyle.TopBottom) { return "TopBottom"; } else if (gs == GradientStyle.VerticalCenter) { return "VerticalCenter"; } return "None"; } /// /// Converts the FontStyle value to RDL FontStyle value. /// /// The FontStyle value. /// The string with RDL FontStyle value. public static string ConvertFontStyle(FontStyle fs) { if (fs == FontStyle.Italic) { return "Italic"; } return "Normal"; } /// /// Converts the FontFamily value to RDL FontFamily value. /// /// The FontFamily value. /// The string with RDL FontFamily value. public static string ConvertFontFamily(FontFamily ff) { return ff.Name; } /// /// Converts the HorzAlign value to RDL TextAlign value. /// /// The HorzAlign value. /// The string with RDL TextAling value. public static string ConvertHorzAlign(HorzAlign ha) { if (ha == HorzAlign.Center) { return "Center"; } else if (ha == HorzAlign.Right) { return "Right"; } return "Left"; } /// /// Converts the VertAling value to RDL VerticalAling value. /// /// The VertAling value. /// The string with RDL VerticalAlign value. public static string ConvertVertAlign(VertAlign va) { if (va == VertAlign.Center) { return "Middle"; } else if (va == VertAlign.Bottom) { return "Bottom"; } return "Top"; } /// /// Converts the Angle value to RDL WritingMode value. /// /// The Angle value. /// The string with RDL WritingMode value. public static string ConvertAngleToWritingMode(int angle) { if (angle == 90) { return "tb-rl"; } return "lr-tb"; } /// /// Converts the FontSize value to RDL FontSize value. /// /// The FontSize value. /// The string with RDL FontSize value. public static string ConvertFontSize(float fs) { return fs.ToString() + "pt"; } /// /// Converts the PictureBoxSizeMode value to RDL Sizing value. /// /// The PictureBoxSizeMode value. /// The string with RDL Sizing value. public static string ConvertSizeMode(PictureBoxSizeMode sm) { if (sm == PictureBoxSizeMode.AutoSize) { return "AutoSize"; } else if (sm == PictureBoxSizeMode.StretchImage) { return "Fit"; } else if (sm == PictureBoxSizeMode.Zoom) { return "FitProportional"; } return "Clip"; } /// /// Converts the SeriesChartType value to RDL Chart.Type value. /// /// The SeriesChartType value. /// The string with RDL Chart.Type value. public static string ConvertChartType(SeriesChartType type) { if (type == SeriesChartType.Area) { return "Area"; } else if (type == SeriesChartType.Bar) { return "Bar"; } else if (type == SeriesChartType.Doughnut) { return "Doughnut"; } else if (type == SeriesChartType.Line) { return "Line"; } else if (type == SeriesChartType.Pie) { return "Pie"; } else if (type == SeriesChartType.Bubble) { return "Bubble"; } return "Column"; } /// /// Converts the ChartColorPalette value to RDL Chart.Palette value. /// /// The ChartColorPalette value. /// The string with RDL Chart.Palette value. public static string ConvertChartPalette(ChartColorPalette palette) { if (palette == ChartColorPalette.EarthTones) { return "EarthTones"; } else if (palette == ChartColorPalette.Excel) { return "Excel"; } else if (palette == ChartColorPalette.Grayscale) { return "GrayScale"; } else if (palette == ChartColorPalette.Light) { return "Light"; } else if (palette == ChartColorPalette.Pastel) { return "Pastel"; } else if (palette == ChartColorPalette.SemiTransparent) { return "SemiTransparent"; } return "Default"; } /// /// Converts the Legend.Docking and Legend.Alignment values to RDL Chart.Legend.Position value. /// /// The Legend.Docking value. /// The Legend.Alignment value. /// The string with RDL Chart.Legend.Position value. public static string ConvertLegendDockingAndAlignment(Docking docking, StringAlignment alignment) { if (docking == Docking.Top && alignment == StringAlignment.Near) { return "TopLeft"; } else if (docking == Docking.Top && alignment == StringAlignment.Center) { return "TopCenter"; } else if (docking == Docking.Top && alignment == StringAlignment.Far) { return "TopRight"; } else if (docking == Docking.Left && alignment == StringAlignment.Near) { return "LeftTop"; } else if (docking == Docking.Left && alignment == StringAlignment.Center) { return "LeftCenter"; } else if (docking == Docking.Left && alignment == StringAlignment.Far) { return "LeftBottom"; } else if (docking == Docking.Right && alignment == StringAlignment.Near) { return "RightTop"; } else if (docking == Docking.Right && alignment == StringAlignment.Center) { return "RightCenter"; } else if (docking == Docking.Right && alignment == StringAlignment.Far) { return "RightBottom"; } else if (docking == Docking.Bottom && alignment == StringAlignment.Near) { return "BottomLeft"; } else if (docking == Docking.Bottom && alignment == StringAlignment.Center) { return "BottomCenter"; } else if (docking == Docking.Bottom && alignment == StringAlignment.Far) { return "BottomRight"; } return "TopLeft"; } /// /// Converts the LegendStyle value to Chart.Legend.Layout value. /// /// The LegendStyle value. /// The string with RDL Chart.Legend.Layout value. public static string ConvertLegendStyle(LegendStyle ls) { if (ls == LegendStyle.Table) { return "Table"; } else if (ls == LegendStyle.Row) { return "Row"; } return "Column"; } /// /// Converts the LightStyle value to RDL Shading value. /// /// The LightStyle value. /// The string with RDL Shading value. public static string ConvertLightStyle(LightStyle ls) { if (ls == LightStyle.Simplistic) { return "Simple"; } else if (ls == LightStyle.Realistic) { return "Real"; } return "Simple"; } /// /// Converts the ChartDashStyle value to RDL BorderStyle value. /// /// The ChartDashStyle value. /// The string with RDL ChartDahsStyle value. public static string ConvertChartDashStyle(ChartDashStyle cds) { if (cds == ChartDashStyle.Dot) { return "Dotted"; } else if (cds == ChartDashStyle.Dash) { return "Dashed"; } return "Solid"; } /// /// Converts the ContentAlignment value to RDL TextAlign value. /// /// The ContentAlignment value. /// The string with RDL TextAlign value. public static string ContentAlignmentToTextAlign(ContentAlignment ca) { if (ca == ContentAlignment.BottomCenter || ca == ContentAlignment.MiddleCenter || ca == ContentAlignment.TopCenter) { return "Center"; } else if (ca == ContentAlignment.BottomLeft || ca == ContentAlignment.MiddleLeft || ca == ContentAlignment.TopLeft) { return "Left"; } else if (ca == ContentAlignment.BottomRight || ca == ContentAlignment.MiddleRight || ca == ContentAlignment.TopRight) { return "Right"; } return "Left"; } /// /// Converts the ContentAlignment value to RDL VerticalAlign value. /// /// The ContentAlignment value. /// The string with RDL VerticalAlign value. public static string ContentAlignmentToVerticalAlign(ContentAlignment ca) { if (ca == ContentAlignment.TopCenter || ca == ContentAlignment.TopLeft || ca == ContentAlignment.TopRight) { return "Top"; } else if (ca == ContentAlignment.MiddleCenter || ca == ContentAlignment.MiddleLeft || ca == ContentAlignment.MiddleRight) { return "Middle"; } else if (ca == ContentAlignment.BottomCenter || ca == ContentAlignment.BottomLeft || ca == ContentAlignment.BottomRight) { return "Bottom"; } return "Top"; } /// /// Converts the AxisEnabled value to RDL Axis.Visible value. /// /// The AxisEnabled value. /// The string with RDL Axis.Visible value. public static string ConvertAxisEnabled(AxisEnabled ae) { if (ae == AxisEnabled.False) { return "false"; } return "true"; } /// /// Converts the TickMarkStyle value to RDL TickMarkStyle value. /// /// The TickMarkStyle value. /// The string with RDL TickMarkStyle value. public static string ConvertTickMarkStyle(TickMarkStyle style) { if (style == TickMarkStyle.InsideArea) { return "Inside"; } else if (style == TickMarkStyle.OutsideArea) { return "Outside"; } else if (style == TickMarkStyle.AcrossAxis) { return "Cross"; } return "None"; } /// /// Converts the StringAlignment value to RDL TextAlign value. /// /// The StringAlignment value. /// The string with RDL TextAlign value. public static string ConvertStringAlignment(StringAlignment sa) { if (sa == StringAlignment.Near) { return "Left"; } else if (sa == StringAlignment.Far) { return "Right"; } return "Center"; } #endregion // Public Methods } }