123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- using System.Drawing;
- using System.Globalization;
- using System.Windows.Forms;
- namespace FastReport.Import.RDL
- {
- /// <summary>
- /// The RDL units converter.
- /// </summary>
- public static partial class UnitsConverter
- {
- #region Public Methods
- /// <summary>
- /// Converts the RDL Boolean to bool value.
- /// </summary>
- /// <param name="boolean">The RDL Boolean value.</param>
- /// <returns>The bool value.</returns>
- public static bool BooleanToBool(string boolean)
- {
- if (boolean.ToLower() == "true")
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// Converts the RDL Color to Color.
- /// </summary>
- /// <param name="colorName">The RDL Color value.</param>
- /// <returns>The Color value.</returns>
- public static Color ConvertColor(string colorName)
- {
- return Color.FromName(colorName);
- }
- /// <summary>
- /// Converts the RDL Size to float value.
- /// </summary>
- /// <param name="size">The RDL Size value.</param>
- /// <param name="unit">The RDL Size units measure.</param>
- /// <returns>The float value of RDL Size.</returns>
- public static float SizeToFloat(string size, string unit)
- {
- return float.Parse(size.Replace(unit, ""), new CultureInfo("en-US", false).NumberFormat);
- }
- /// <summary>
- /// Converts the RDL Size to int value.
- /// </summary>
- /// <param name="size">The RDL Size value.</param>
- /// <param name="unit">The RDL Size units measure.</param>
- /// <returns>The int value of RDL Size.</returns>
- public static int SizeToInt(string size, string unit)
- {
- int resSize = 0;
- int.TryParse(size.Replace(unit, ""), NumberStyles.None, new CultureInfo("en-US", false).NumberFormat, out resSize);
- return resSize;
- }
- /// <summary>
- /// Converts the RDL Size to millimeters.
- /// </summary>
- /// <param name="size">The RDL Size value.</param>
- /// <returns>The float value of RDL Size in millimeters.</returns>
- public static float SizeToMillimeters(string size)
- {
- if (size.Contains(SizeUnits.Millimeter))
- {
- return SizeToFloat(size, SizeUnits.Millimeter);
- }
- else if (size.Contains(SizeUnits.Centimeter))
- {
- return SizeToFloat(size, SizeUnits.Centimeter) * SizeUnitsM.Centimeter;
- }
- else if (size.Contains(SizeUnits.Inch))
- {
- return SizeToFloat(size, SizeUnits.Inch) * SizeUnitsM.Inch;
- }
- else if (size.Contains(SizeUnits.Point))
- {
- return SizeToFloat(size, SizeUnits.Point) * SizeUnitsM.Point;
- }
- else if (size.Contains(SizeUnits.Pica))
- {
- return SizeToFloat(size, SizeUnits.Pica) * SizeUnitsM.Pica;
- }
- return 0.0f;
- }
- /// <summary>
- /// Converts the RDL Size to pixels.
- /// </summary>
- /// <param name="size">The RDL Size value.</param>
- /// <returns>The float value of RDL Size in pixels.</returns>
- public static float SizeToPixels(string size)
- {
- if (size.Contains(SizeUnits.Millimeter))
- {
- return SizeToFloat(size, SizeUnits.Millimeter) * SizeUnitsP.Millimeter;
- }
- else if (size.Contains(SizeUnits.Centimeter))
- {
- return SizeToFloat(size, SizeUnits.Centimeter) * SizeUnitsP.Centimeter;
- }
- else if (size.Contains(SizeUnits.Inch))
- {
- return SizeToFloat(size, SizeUnits.Inch) * SizeUnitsP.Inch;
- }
- else if (size.Contains(SizeUnits.Point))
- {
- return SizeToFloat(size, SizeUnits.Point) * SizeUnitsP.Point;
- }
- else if (size.Contains(SizeUnits.Pica))
- {
- return SizeToFloat(size, SizeUnits.Pica) * SizeUnitsP.Pica;
- }
- return 0.0f;
- }
- /// <summary>
- /// Converts the RDL FontStyle to FontStyle.
- /// </summary>
- /// <param name="fontStyle">The RDL FontStyle value.</param>
- /// <returns>The FontStyle value.</returns>
- public static FontStyle ConvertFontStyle(string fontStyle)
- {
- if (fontStyle == "Italic")
- {
- return FontStyle.Italic;
- }
- return FontStyle.Regular;
- }
- /// <summary>
- /// Converts the RDL FontSize to float.
- /// </summary>
- /// <param name="fontSize">The RDL FontSize value.</param>
- /// <returns>The float value of RDL FontSize in points.</returns>
- public static float ConvertFontSize(string fontSize)
- {
- return float.Parse(fontSize.Replace(SizeUnits.Point, ""), new CultureInfo("en-US", false).NumberFormat);
- }
- /// <summary>
- /// Converts the RDL TextAlign to HorzAlign.
- /// </summary>
- /// <param name="textAlign">The RDL TextAlign value.</param>
- /// <returns>The HorzAlign value.</returns>
- public static HorzAlign ConvertTextAlign(string textAlign)
- {
- if (textAlign == "Center")
- {
- return HorzAlign.Center;
- }
- else if (textAlign == "Right")
- {
- return HorzAlign.Right;
- }
- return HorzAlign.Left;
- }
- /// <summary>
- /// Converts the RDL TextAlign to VerticalAlign.
- /// </summary>
- /// <param name="verticalAlign">The RDL VerticalAlign value.</param>
- /// <returns>The VertAlign value.</returns>
- public static VertAlign ConvertVerticalAlign(string verticalAlign)
- {
- if (verticalAlign == "Middle")
- {
- return VertAlign.Center;
- }
- else if (verticalAlign == "Bottom")
- {
- return VertAlign.Bottom;
- }
- return VertAlign.Top;
- }
- /// <summary>
- /// Converts the RDL WritingMode to Angle.
- /// </summary>
- /// <param name="writingMode">The RDL WritingMode value.</param>
- /// <returns>The int value of RDL WritingMode in degree.</returns>
- public static int ConvertWritingMode(string writingMode)
- {
- if (writingMode == "tb-rl")
- {
- return 90;
- }
- return 0;
- }
- /// <summary>
- /// Converts the RDL TextAlign to StringAlignment.
- /// </summary>
- /// <param name="textAlign">The RDL TextAling value.</param>
- /// <returns>The StringAlignment value.</returns>
- public static StringAlignment ConvertTextAlignToStringAlignment(string textAlign)
- {
- if (textAlign == "Left")
- {
- return StringAlignment.Near;
- }
- else if (textAlign == "Right")
- {
- return StringAlignment.Far;
- }
- return StringAlignment.Center;
- }
- /// <summary>
- /// Converts the RDL TextAlign and VerticalAlign to ContentAlignment.
- /// </summary>
- /// <param name="textAlign">The RDL TextAlign value.</param>
- /// <param name="vertAlign">The RDL VerticalAlign value.</param>
- /// <returns>The ContentAlignment value.</returns>
- public static ContentAlignment ConvertTextAndVerticalAlign(string textAlign, string vertAlign)
- {
- if (textAlign == "General" || textAlign == "Center")
- {
- if (vertAlign == "Top")
- {
- return ContentAlignment.TopCenter;
- }
- else if (vertAlign == "Middle")
- {
- return ContentAlignment.MiddleCenter;
- }
- else if (vertAlign == "Bottom")
- {
- return ContentAlignment.BottomCenter;
- }
- return ContentAlignment.TopCenter;
- }
- else if (textAlign == "Left")
- {
- if (vertAlign == "Top")
- {
- return ContentAlignment.TopLeft;
- }
- else if (vertAlign == "Middle")
- {
- return ContentAlignment.MiddleLeft;
- }
- else if (vertAlign == "Bottom")
- {
- return ContentAlignment.BottomLeft;
- }
- return ContentAlignment.TopLeft;
- }
- else if (textAlign == "Right")
- {
- if (vertAlign == "Top")
- {
- return ContentAlignment.TopRight;
- }
- else if (vertAlign == "Middle")
- {
- return ContentAlignment.MiddleRight;
- }
- else if (vertAlign == "Bottom")
- {
- return ContentAlignment.BottomRight;
- }
- return ContentAlignment.TopRight;
- }
- return ContentAlignment.TopLeft;
- }
- /// <summary>
- /// Converts the RDL BorderStyle to LineStyle.
- /// </summary>
- /// <param name="borderStyle">The RDL BorderStyle value.</param>
- /// <returns>The LineStyle value.</returns>
- public static LineStyle ConvertBorderStyle(string borderStyle)
- {
- if (borderStyle == "Dotted")
- {
- return LineStyle.Dot;
- }
- else if (borderStyle == "Dashed")
- {
- return LineStyle.Dash;
- }
- else if (borderStyle == "Double")
- {
- return LineStyle.Double;
- }
- return LineStyle.Solid;
- }
- /// <summary>
- /// Converts the RDL Sizing to PictureBoxSizeMode.
- /// </summary>
- /// <param name="sizing">The RDL Sizing value.</param>
- /// <returns>The PictureBoxSizeMode value.</returns>
- public static PictureBoxSizeMode ConvertSizing(string sizing)
- {
- if (sizing == "AutoSize")
- {
- return PictureBoxSizeMode.AutoSize;
- }
- else if (sizing == "Fit")
- {
- return PictureBoxSizeMode.StretchImage;
- }
- else if (sizing == "Clip")
- {
- return PictureBoxSizeMode.Normal;
- }
- return PictureBoxSizeMode.Zoom;
- }
- /// <summary>
- /// Converts the RDL GradientType to GradientStyle.
- /// </summary>
- /// <param name="gradientType">The RDL GradientType value.</param>
- /// <returns>The GradientStyle value.</returns>
- /*public static GradientStyle ConvertGradientType(string gradientType)
- {
- if (gradientType == "LeftRight")
- {
- return GradientStyle.LeftRight;
- }
- else if (gradientType == "TopBottom")
- {
- return GradientStyle.TopBottom;
- }
- else if (gradientType == "Center")
- {
- return GradientStyle.Center;
- }
- else if (gradientType == "DiagonalLeft")
- {
- return GradientStyle.DiagonalLeft;
- }
- else if (gradientType == "DiagonalRight")
- {
- return GradientStyle.DiagonalRight;
- }
- else if (gradientType == "HorizontalCenter")
- {
- return GradientStyle.HorizontalCenter;
- }
- else if (gradientType == "VerticalCenter")
- {
- return GradientStyle.VerticalCenter;
- }
- return GradientStyle.None;
- }*/
- /// <summary>
- /// Converts the RDL Chart.Type to SeriesChartType.
- /// </summary>
- /// <param name="chartType">The RDL Chart.Type value.</param>
- /// <returns>The SeriesChartType value.</returns>
- /*public static SeriesChartType ConvertChartType(string chartType)
- {
- if (chartType == "Area")
- {
- return SeriesChartType.Area;
- }
- else if (chartType == "Bar")
- {
- return SeriesChartType.Bar;
- }
- else if (chartType == "Doughnut")
- {
- return SeriesChartType.Doughnut;
- }
- else if (chartType == "Line")
- {
- return SeriesChartType.Line;
- }
- else if (chartType == "Pie")
- {
- return SeriesChartType.Pie;
- }
- else if (chartType == "Bubble")
- {
- return SeriesChartType.Bubble;
- }
- return SeriesChartType.Column;
- }*/
- /// <summary>
- /// Converts the RDL Chart.Palette to ChartColorPalette.
- /// </summary>
- /// <param name="chartPalette">The RDL Chart.Palette value.</param>
- /// <returns>The RDL ChartColorPalette value.</returns>
- /*public static ChartColorPalette ConvertChartPalette(string chartPalette)
- {
- if (chartPalette == "EarthTones")
- {
- return ChartColorPalette.EarthTones;
- }
- else if (chartPalette == "Excel")
- {
- return ChartColorPalette.Excel;
- }
- else if (chartPalette == "GrayScale")
- {
- return ChartColorPalette.Grayscale;
- }
- else if (chartPalette == "Light")
- {
- return ChartColorPalette.Light;
- }
- else if (chartPalette == "Pastel")
- {
- return ChartColorPalette.Pastel;
- }
- else if (chartPalette == "SemiTransparent")
- {
- return ChartColorPalette.SemiTransparent;
- }
- return ChartColorPalette.None;
- }*/
- /// <summary>
- /// Converts the RDL Chart.Legend.Position to Legend.Docking and Legend.Alignment.
- /// </summary>
- /// <param name="chartLegendPosition">The RDL Chart.Legend.Position value.</param>
- /// <param name="legend">The Legend instance to convert to.</param>
- /*public static void ConvertChartLegendPosition(string chartLegendPosition, Legend legend)
- {
- if (chartLegendPosition == "TopLeft")
- {
- legend.Docking = Docking.Top;
- legend.Alignment = StringAlignment.Near;
- }
- else if (chartLegendPosition == "TopCenter")
- {
- legend.Docking = Docking.Top;
- legend.Alignment = StringAlignment.Center;
- }
- else if (chartLegendPosition == "TopRight")
- {
- legend.Docking = Docking.Top;
- legend.Alignment = StringAlignment.Far;
- }
- else if (chartLegendPosition == "LeftTop")
- {
- legend.Docking = Docking.Left;
- legend.Alignment = StringAlignment.Near;
- }
- else if (chartLegendPosition == "LeftCenter")
- {
- legend.Docking = Docking.Left;
- legend.Alignment = StringAlignment.Center;
- }
- else if (chartLegendPosition == "LeftBottom")
- {
- legend.Docking = Docking.Left;
- legend.Alignment = StringAlignment.Far;
- }
- else if (chartLegendPosition == "RightTop")
- {
- legend.Docking = Docking.Right;
- legend.Alignment = StringAlignment.Near;
- }
- else if (chartLegendPosition == "RightCenter")
- {
- legend.Docking = Docking.Right;
- legend.Alignment = StringAlignment.Center;
- }
- else if (chartLegendPosition == "RightBottom")
- {
- legend.Docking = Docking.Right;
- legend.Alignment = StringAlignment.Far;
- }
- else if (chartLegendPosition == "BottomLeft")
- {
- legend.Docking = Docking.Bottom;
- legend.Alignment = StringAlignment.Near;
- }
- else if (chartLegendPosition == "BottomCenter")
- {
- legend.Docking = Docking.Bottom;
- legend.Alignment = StringAlignment.Center;
- }
- else if (chartLegendPosition == "BottomRight")
- {
- legend.Docking = Docking.Bottom;
- legend.Alignment = StringAlignment.Far;
- }
- }*/
- /// <summary>
- /// Converts the RDL Chart.Legend.Layout to LegendStyle.
- /// </summary>
- /// <param name="chartLegendLayout">The RDL Chart.Legend.Layout value.</param>
- /// <returns>The LegendStyle value.</returns>
- /*public static LegendStyle ConvertChartLegendLayout(string chartLegendLayout)
- {
- if (chartLegendLayout == "Table")
- {
- return LegendStyle.Table;
- }
- else if (chartLegendLayout == "Row")
- {
- return LegendStyle.Row;
- }
- return LegendStyle.Column;
- }*/
- /// <summary>
- /// Converts the RDL BorderStyle to ChartDashStyle.
- /// </summary>
- /// <param name="borderStyle">The RDL BorderStyle value.</param>
- /// <returns>The ChartDashStyle value.</returns>
- /*public static ChartDashStyle ConvertBorderStyleToChartDashStyle(string borderStyle)
- {
- if (borderStyle == "Dotted")
- {
- return ChartDashStyle.Dot;
- }
- else if (borderStyle == "Dashed")
- {
- return ChartDashStyle.Dash;
- }
- return ChartDashStyle.Solid;
- }*/
- /// <summary>
- /// Converts the RDL Axis.Visible to AxisEnabled.
- /// </summary>
- /// <param name="axisVisible">The RDL Axis.Visible value.</param>
- /// <returns>The AxisEnabled value.</returns>
- /*public static AxisEnabled ConvertAxisVisibleToAxisEnabled(string axisVisible)
- {
- if (axisVisible.ToLower() == "true")
- {
- return AxisEnabled.True;
- }
- else if (axisVisible.ToLower() == "false")
- {
- return AxisEnabled.False;
- }
- return AxisEnabled.Auto;
- }*/
- /// <summary>
- /// Converts the RDL TickMarkStyle to TickMarkStyle.
- /// </summary>
- /// <param name="tickMarkStyle">The RDL TickMarkStyle value.</param>
- /// <returns>The TickMarkStyle value.</returns>
- /*public static TickMarkStyle ConvertTickMarkStyle(string tickMarkStyle)
- {
- if (tickMarkStyle == "Inside")
- {
- return TickMarkStyle.InsideArea;
- }
- else if (tickMarkStyle == "Outside")
- {
- return TickMarkStyle.OutsideArea;
- }
- else if (tickMarkStyle == "Cross")
- {
- return TickMarkStyle.AcrossAxis;
- }
- return TickMarkStyle.None;
- }*/
- /// <summary>
- /// Converts the RDL Shading to LightStyle.
- /// </summary>
- /// <param name="shading">The RDL Shading value.</param>
- /// <returns>The LightStyle value.</returns>
- /*public static LightStyle ConvertShading(string shading)
- {
- if (shading == "Simple")
- {
- return LightStyle.Simplistic;
- }
- else if (shading == "Real")
- {
- return LightStyle.Realistic;
- }
- return LightStyle.None;
- }*/
- #endregion // Public Methods
- }
- }
|