123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- 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
- {
- /// <summary>
- /// The FR units converter.
- /// </summary>
- internal static class UnitsConverter
- {
- #region Public Methods
- /// <summary>
- /// Converts the float size in pixels to string value in millimeters.
- /// </summary>
- /// <param name="pixels">The float value in pixels.</param>
- /// <returns>The string value in millimeters.</returns>
- public static string PixelsToMillimeters(float pixels)
- {
- return (pixels / Import.RDL.SizeUnitsP.Millimeter).ToString() + "mm";
- }
- /// <summary>
- /// Converts the float size in millimeters to string value in millimeters.
- /// </summary>
- /// <param name="millimeters">The float value in millimeters.</param>
- /// <returns>The string value in millimeters.</returns>
- public static string MillimetersToString(float millimeters)
- {
- return millimeters.ToString() + "mm";
- }
- /// <summary>
- /// Converts the bool value to string.
- /// </summary>
- /// <param name="value">The bool value.</param>
- /// <returns>The string value.</returns>
- public static string ConvertBool(bool value)
- {
- return value.ToString().ToLower();
- }
- /// <summary>
- /// Converts the int size in pixels to string value in pt.
- /// </summary>
- /// <param name="pixels">The int value in pixels.</param>
- /// <returns>The string value in pt.</returns>
- public static string ConvertPixels(int pixels)
- {
- return pixels.ToString() + "pt";
- }
- /// <summary>
- /// Converts the Color value to string.
- /// </summary>
- /// <param name="color">The Color value.</param>
- /// <returns>The string representation of Color value.</returns>
- public static string ConvertColor(Color color)
- {
- if (color.ToKnownColor() == 0)
- {
- return Color.Red.Name;
- }
- return color.Name;
- }
- /// <summary>
- /// Converts the LineStyle value to RDL BorderStyle value.
- /// </summary>
- /// <param name="ls">The LineStyle value.</param>
- /// <returns>The string with RDL BorderStyle value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the GradientStyle value to RDL GradientType value.
- /// </summary>
- /// <param name="gs">The GradientStyle value.</param>
- /// <returns>The string with RDL GradientType value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the FontStyle value to RDL FontStyle value.
- /// </summary>
- /// <param name="fs">The FontStyle value.</param>
- /// <returns>The string with RDL FontStyle value.</returns>
- public static string ConvertFontStyle(FontStyle fs)
- {
- if (fs == FontStyle.Italic)
- {
- return "Italic";
- }
- return "Normal";
- }
- /// <summary>
- /// Converts the FontFamily value to RDL FontFamily value.
- /// </summary>
- /// <param name="ff">The FontFamily value.</param>
- /// <returns>The string with RDL FontFamily value.</returns>
- public static string ConvertFontFamily(FontFamily ff)
- {
- return ff.Name;
- }
- /// <summary>
- /// Converts the HorzAlign value to RDL TextAlign value.
- /// </summary>
- /// <param name="ha">The HorzAlign value.</param>
- /// <returns>The string with RDL TextAling value.</returns>
- public static string ConvertHorzAlign(HorzAlign ha)
- {
- if (ha == HorzAlign.Center)
- {
- return "Center";
- }
- else if (ha == HorzAlign.Right)
- {
- return "Right";
- }
- return "Left";
- }
- /// <summary>
- /// Converts the VertAling value to RDL VerticalAling value.
- /// </summary>
- /// <param name="va">The VertAling value.</param>
- /// <returns>The string with RDL VerticalAlign value.</returns>
- public static string ConvertVertAlign(VertAlign va)
- {
- if (va == VertAlign.Center)
- {
- return "Middle";
- }
- else if (va == VertAlign.Bottom)
- {
- return "Bottom";
- }
- return "Top";
- }
- /// <summary>
- /// Converts the Angle value to RDL WritingMode value.
- /// </summary>
- /// <param name="angle">The Angle value.</param>
- /// <returns>The string with RDL WritingMode value.</returns>
- public static string ConvertAngleToWritingMode(int angle)
- {
- if (angle == 90)
- {
- return "tb-rl";
- }
- return "lr-tb";
- }
- /// <summary>
- /// Converts the FontSize value to RDL FontSize value.
- /// </summary>
- /// <param name="fs">The FontSize value.</param>
- /// <returns>The string with RDL FontSize value.</returns>
- public static string ConvertFontSize(float fs)
- {
- return fs.ToString() + "pt";
- }
- /// <summary>
- /// Converts the PictureBoxSizeMode value to RDL Sizing value.
- /// </summary>
- /// <param name="sm">The PictureBoxSizeMode value.</param>
- /// <returns>The string with RDL Sizing value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the SeriesChartType value to RDL Chart.Type value.
- /// </summary>
- /// <param name="type">The SeriesChartType value.</param>
- /// <returns>The string with RDL Chart.Type value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the ChartColorPalette value to RDL Chart.Palette value.
- /// </summary>
- /// <param name="palette">The ChartColorPalette value.</param>
- /// <returns>The string with RDL Chart.Palette value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the Legend.Docking and Legend.Alignment values to RDL Chart.Legend.Position value.
- /// </summary>
- /// <param name="docking">The Legend.Docking value.</param>
- /// <param name="alignment">The Legend.Alignment value.</param>
- /// <returns>The string with RDL Chart.Legend.Position value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the LegendStyle value to Chart.Legend.Layout value.
- /// </summary>
- /// <param name="ls">The LegendStyle value.</param>
- /// <returns>The string with RDL Chart.Legend.Layout value.</returns>
- public static string ConvertLegendStyle(LegendStyle ls)
- {
- if (ls == LegendStyle.Table)
- {
- return "Table";
- }
- else if (ls == LegendStyle.Row)
- {
- return "Row";
- }
- return "Column";
- }
- /// <summary>
- /// Converts the LightStyle value to RDL Shading value.
- /// </summary>
- /// <param name="ls">The LightStyle value.</param>
- /// <returns>The string with RDL Shading value.</returns>
- public static string ConvertLightStyle(LightStyle ls)
- {
- if (ls == LightStyle.Simplistic)
- {
- return "Simple";
- }
- else if (ls == LightStyle.Realistic)
- {
- return "Real";
- }
- return "Simple";
- }
- /// <summary>
- /// Converts the ChartDashStyle value to RDL BorderStyle value.
- /// </summary>
- /// <param name="cds">The ChartDashStyle value.</param>
- /// <returns>The string with RDL ChartDahsStyle value.</returns>
- public static string ConvertChartDashStyle(ChartDashStyle cds)
- {
- if (cds == ChartDashStyle.Dot)
- {
- return "Dotted";
- }
- else if (cds == ChartDashStyle.Dash)
- {
- return "Dashed";
- }
- return "Solid";
- }
- /// <summary>
- /// Converts the ContentAlignment value to RDL TextAlign value.
- /// </summary>
- /// <param name="ca">The ContentAlignment value.</param>
- /// <returns>The string with RDL TextAlign value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the ContentAlignment value to RDL VerticalAlign value.
- /// </summary>
- /// <param name="ca">The ContentAlignment value.</param>
- /// <returns>The string with RDL VerticalAlign value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the AxisEnabled value to RDL Axis.Visible value.
- /// </summary>
- /// <param name="ae">The AxisEnabled value.</param>
- /// <returns>The string with RDL Axis.Visible value.</returns>
- public static string ConvertAxisEnabled(AxisEnabled ae)
- {
- if (ae == AxisEnabled.False)
- {
- return "false";
- }
- return "true";
- }
- /// <summary>
- /// Converts the TickMarkStyle value to RDL TickMarkStyle value.
- /// </summary>
- /// <param name="style">The TickMarkStyle value.</param>
- /// <returns>The string with RDL TickMarkStyle value.</returns>
- 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";
- }
- /// <summary>
- /// Converts the StringAlignment value to RDL TextAlign value.
- /// </summary>
- /// <param name="sa">The StringAlignment value.</param>
- /// <returns>The string with RDL TextAlign value.</returns>
- public static string ConvertStringAlignment(StringAlignment sa)
- {
- if (sa == StringAlignment.Near)
- {
- return "Left";
- }
- else if (sa == StringAlignment.Far)
- {
- return "Right";
- }
- return "Center";
- }
- #endregion // Public Methods
- }
- }
|