UnitsConverter.BaseExt.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System.Drawing;
  2. using System.Globalization;
  3. using System.Windows.Forms;
  4. using FastReport.DataVisualization.Charting;
  5. namespace FastReport.Import.RDL
  6. {
  7. /// <summary>
  8. /// The RDL units converter.
  9. /// </summary>
  10. public static partial class UnitsConverter
  11. {
  12. #region Public Methods
  13. /// <summary>
  14. /// Converts the RDL GradientType to GradientStyle.
  15. /// </summary>
  16. /// <param name="gradientType">The RDL GradientType value.</param>
  17. /// <returns>The GradientStyle value.</returns>
  18. public static GradientStyle ConvertGradientType(string gradientType)
  19. {
  20. if (gradientType == "LeftRight")
  21. {
  22. return GradientStyle.LeftRight;
  23. }
  24. else if (gradientType == "TopBottom")
  25. {
  26. return GradientStyle.TopBottom;
  27. }
  28. else if (gradientType == "Center")
  29. {
  30. return GradientStyle.Center;
  31. }
  32. else if (gradientType == "DiagonalLeft")
  33. {
  34. return GradientStyle.DiagonalLeft;
  35. }
  36. else if (gradientType == "DiagonalRight")
  37. {
  38. return GradientStyle.DiagonalRight;
  39. }
  40. else if (gradientType == "HorizontalCenter")
  41. {
  42. return GradientStyle.HorizontalCenter;
  43. }
  44. else if (gradientType == "VerticalCenter")
  45. {
  46. return GradientStyle.VerticalCenter;
  47. }
  48. return GradientStyle.None;
  49. }
  50. /// <summary>
  51. /// Converts the RDL Chart.Type to SeriesChartType.
  52. /// </summary>
  53. /// <param name="chartType">The RDL Chart.Type value.</param>
  54. /// <returns>The SeriesChartType value.</returns>
  55. public static SeriesChartType ConvertChartType(string chartType)
  56. {
  57. if (chartType == "Area")
  58. {
  59. return SeriesChartType.Area;
  60. }
  61. else if (chartType == "Bar")
  62. {
  63. return SeriesChartType.Bar;
  64. }
  65. else if (chartType == "Doughnut")
  66. {
  67. return SeriesChartType.Doughnut;
  68. }
  69. else if (chartType == "Line")
  70. {
  71. return SeriesChartType.Line;
  72. }
  73. else if (chartType == "Pie")
  74. {
  75. return SeriesChartType.Pie;
  76. }
  77. else if (chartType == "Bubble")
  78. {
  79. return SeriesChartType.Bubble;
  80. }
  81. return SeriesChartType.Column;
  82. }
  83. /// <summary>
  84. /// Converts the RDL Chart.Palette to ChartColorPalette.
  85. /// </summary>
  86. /// <param name="chartPalette">The RDL Chart.Palette value.</param>
  87. /// <returns>The RDL ChartColorPalette value.</returns>
  88. public static ChartColorPalette ConvertChartPalette(string chartPalette)
  89. {
  90. if (chartPalette == "EarthTones")
  91. {
  92. return ChartColorPalette.EarthTones;
  93. }
  94. else if (chartPalette == "Excel")
  95. {
  96. return ChartColorPalette.Excel;
  97. }
  98. else if (chartPalette == "GrayScale")
  99. {
  100. return ChartColorPalette.Grayscale;
  101. }
  102. else if (chartPalette == "Light")
  103. {
  104. return ChartColorPalette.Light;
  105. }
  106. else if (chartPalette == "Pastel")
  107. {
  108. return ChartColorPalette.Pastel;
  109. }
  110. else if (chartPalette == "SemiTransparent")
  111. {
  112. return ChartColorPalette.SemiTransparent;
  113. }
  114. return ChartColorPalette.None;
  115. }
  116. /// <summary>
  117. /// Converts the RDL Chart.Legend.Position to Legend.Docking and Legend.Alignment.
  118. /// </summary>
  119. /// <param name="chartLegendPosition">The RDL Chart.Legend.Position value.</param>
  120. /// <param name="legend">The Legend instance to convert to.</param>
  121. public static void ConvertChartLegendPosition(string chartLegendPosition, Legend legend)
  122. {
  123. if (chartLegendPosition == "TopLeft")
  124. {
  125. legend.Docking = Docking.Top;
  126. legend.Alignment = StringAlignment.Near;
  127. }
  128. else if (chartLegendPosition == "TopCenter")
  129. {
  130. legend.Docking = Docking.Top;
  131. legend.Alignment = StringAlignment.Center;
  132. }
  133. else if (chartLegendPosition == "TopRight")
  134. {
  135. legend.Docking = Docking.Top;
  136. legend.Alignment = StringAlignment.Far;
  137. }
  138. else if (chartLegendPosition == "LeftTop")
  139. {
  140. legend.Docking = Docking.Left;
  141. legend.Alignment = StringAlignment.Near;
  142. }
  143. else if (chartLegendPosition == "LeftCenter")
  144. {
  145. legend.Docking = Docking.Left;
  146. legend.Alignment = StringAlignment.Center;
  147. }
  148. else if (chartLegendPosition == "LeftBottom")
  149. {
  150. legend.Docking = Docking.Left;
  151. legend.Alignment = StringAlignment.Far;
  152. }
  153. else if (chartLegendPosition == "RightTop")
  154. {
  155. legend.Docking = Docking.Right;
  156. legend.Alignment = StringAlignment.Near;
  157. }
  158. else if (chartLegendPosition == "RightCenter")
  159. {
  160. legend.Docking = Docking.Right;
  161. legend.Alignment = StringAlignment.Center;
  162. }
  163. else if (chartLegendPosition == "RightBottom")
  164. {
  165. legend.Docking = Docking.Right;
  166. legend.Alignment = StringAlignment.Far;
  167. }
  168. else if (chartLegendPosition == "BottomLeft")
  169. {
  170. legend.Docking = Docking.Bottom;
  171. legend.Alignment = StringAlignment.Near;
  172. }
  173. else if (chartLegendPosition == "BottomCenter")
  174. {
  175. legend.Docking = Docking.Bottom;
  176. legend.Alignment = StringAlignment.Center;
  177. }
  178. else if (chartLegendPosition == "BottomRight")
  179. {
  180. legend.Docking = Docking.Bottom;
  181. legend.Alignment = StringAlignment.Far;
  182. }
  183. }
  184. /// <summary>
  185. /// Converts the RDL Chart.Legend.Layout to LegendStyle.
  186. /// </summary>
  187. /// <param name="chartLegendLayout">The RDL Chart.Legend.Layout value.</param>
  188. /// <returns>The LegendStyle value.</returns>
  189. public static LegendStyle ConvertChartLegendLayout(string chartLegendLayout)
  190. {
  191. if (chartLegendLayout == "Table")
  192. {
  193. return LegendStyle.Table;
  194. }
  195. else if (chartLegendLayout == "Row")
  196. {
  197. return LegendStyle.Row;
  198. }
  199. return LegendStyle.Column;
  200. }
  201. /// <summary>
  202. /// Converts the RDL BorderStyle to ChartDashStyle.
  203. /// </summary>
  204. /// <param name="borderStyle">The RDL BorderStyle value.</param>
  205. /// <returns>The ChartDashStyle value.</returns>
  206. public static ChartDashStyle ConvertBorderStyleToChartDashStyle(string borderStyle)
  207. {
  208. if (borderStyle == "Dotted")
  209. {
  210. return ChartDashStyle.Dot;
  211. }
  212. else if (borderStyle == "Dashed")
  213. {
  214. return ChartDashStyle.Dash;
  215. }
  216. return ChartDashStyle.Solid;
  217. }
  218. /// <summary>
  219. /// Converts the RDL Axis.Visible to AxisEnabled.
  220. /// </summary>
  221. /// <param name="axisVisible">The RDL Axis.Visible value.</param>
  222. /// <returns>The AxisEnabled value.</returns>
  223. public static AxisEnabled ConvertAxisVisibleToAxisEnabled(string axisVisible)
  224. {
  225. if (axisVisible.ToLower() == "true")
  226. {
  227. return AxisEnabled.True;
  228. }
  229. else if (axisVisible.ToLower() == "false")
  230. {
  231. return AxisEnabled.False;
  232. }
  233. return AxisEnabled.Auto;
  234. }
  235. /// <summary>
  236. /// Converts the RDL TickMarkStyle to TickMarkStyle.
  237. /// </summary>
  238. /// <param name="tickMarkStyle">The RDL TickMarkStyle value.</param>
  239. /// <returns>The TickMarkStyle value.</returns>
  240. public static TickMarkStyle ConvertTickMarkStyle(string tickMarkStyle)
  241. {
  242. if (tickMarkStyle == "Inside")
  243. {
  244. return TickMarkStyle.InsideArea;
  245. }
  246. else if (tickMarkStyle == "Outside")
  247. {
  248. return TickMarkStyle.OutsideArea;
  249. }
  250. else if (tickMarkStyle == "Cross")
  251. {
  252. return TickMarkStyle.AcrossAxis;
  253. }
  254. return TickMarkStyle.None;
  255. }
  256. /// <summary>
  257. /// Converts the RDL Shading to LightStyle.
  258. /// </summary>
  259. /// <param name="shading">The RDL Shading value.</param>
  260. /// <returns>The LightStyle value.</returns>
  261. public static LightStyle ConvertShading(string shading)
  262. {
  263. if (shading == "Simple")
  264. {
  265. return LightStyle.Simplistic;
  266. }
  267. else if (shading == "Real")
  268. {
  269. return LightStyle.Realistic;
  270. }
  271. return LightStyle.None;
  272. }
  273. #endregion // Public Methods
  274. }
  275. }