using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Drawing; using System.Windows.Forms; using FastReport.Utils; using FastReport.Barcode; namespace FastReport.Import.DevExpress { /// /// The DevExpress units converter. /// public static class UnitsConverter { public static float Ratio = 1; #region Public Methods /// /// Converts SizeF to pixels. /// /// SizeF value as string. /// The value in pixels. public static float SizeFToPixels(string str) { float value = 0.0f; if (!String.IsNullOrEmpty(str)) { int end = str.IndexOf("F"); if (end > -1) { value = Convert.ToSingle(str.Substring(0, end), CultureInfo.InvariantCulture); } else { value = Convert.ToSingle(str, CultureInfo.InvariantCulture); } } return value / Ratio; } /// /// Converts SizeF to pixels. /// /// SizeF value as string. /// The value in pixels. /// /// Use this method for fonts, because font size is not stored as multiplied by dpi /// public static float SizeFToPixelsFont(string str) { return SizeFToPixels(str) * Ratio; } /// /// Converts value to Boolean. /// /// Boolen value as string. public static bool ConvertBool(string str) { return str.ToLower() == "true"; } /// /// Converts DevExpress Color. /// /// The DevExpress Color value as string. /// The Color value. public static Color ConvertColor(string str) { if (!String.IsNullOrEmpty(str)) { if (str.IndexOf("FromArgb") > -1) { int start = str.IndexOf("byte") + 6; int red = Convert.ToInt32(str.Substring(start, str.IndexOf(")", start) - start)); start = str.IndexOf("byte", start) + 6; int green = Convert.ToInt32(str.Substring(start, str.IndexOf(")", start) - start)); start = str.IndexOf("byte", start) + 6; int blue = Convert.ToInt32(str.Substring(start, str.IndexOf(")", start) - start)); return Color.FromArgb(red, green, blue); } else if(str.Split(',').Length == 4) { string[] colors = str.Split(','); int alpha = Convert.ToInt32(colors[0]); int red = Convert.ToInt32(colors[1]); int green = Convert.ToInt32(colors[2]); int blue = Convert.ToInt32(colors[3]); return Color.FromArgb(alpha, red, green, blue); } else { return Color.FromName(str.Replace("System.Drawing.Color.", "")); } } return Color.Black; } /// /// Converts DevExpress BackColor. /// /// The DevExpress BackColor value as string. /// The Color value. public static Color ConvertBackColor(string str) { if (!String.IsNullOrEmpty(str)) { if (str.IndexOf("FromArgb") > -1) { int start = str.IndexOf("byte") + 6; int red = Convert.ToInt32(str.Substring(start, str.IndexOf(")", start) - start)); start = str.IndexOf("byte", start) + 6; int green = Convert.ToInt32(str.Substring(start, str.IndexOf(")", start) - start)); start = str.IndexOf("byte", start) + 6; int blue = Convert.ToInt32(str.Substring(start, str.IndexOf(")", start) - start)); return Color.FromArgb(red, green, blue); } else if (str.Split(',').Length == 4) { string[] colors = str.Split(','); int alpha = Convert.ToInt32(colors[0]); int red = Convert.ToInt32(colors[1]); int green = Convert.ToInt32(colors[2]); int blue = Convert.ToInt32(colors[3]); return Color.FromArgb(alpha, red, green, blue); } else { return Color.FromName(str.Replace("System.Drawing.Color.", "")); } } return Color.Transparent; } /// /// Converts the DevExpress BorderDashStyle to LineStyle. /// /// The DevExpress BorderDashStyle value. /// The LineStyle value. public static LineStyle ConvertBorderDashStyle(string borderDashStyle) { if (borderDashStyle == "DevExpress.XtraPrinting.BorderDashStyle.Dot" || borderDashStyle.Equals("Dot")) { return LineStyle.Dot; } else if (borderDashStyle == "DevExpress.XtraPrinting.BorderDashStyle.Dash" || borderDashStyle.Equals("Dash")) { return LineStyle.Dash; } else if (borderDashStyle == "DevExpress.XtraPrinting.BorderDashStyle.DashDot" || borderDashStyle.Equals("DashDot")) { return LineStyle.DashDot; } else if (borderDashStyle == "DevExpress.XtraPrinting.BorderDashStyle.DashDotDot" || borderDashStyle.Equals("DashDotDot")) { return LineStyle.DashDotDot; } else if (borderDashStyle == "DevExpress.XtraPrinting.BorderDashStyle.Double" || borderDashStyle.Equals("Double")) { return LineStyle.Double; } return LineStyle.Solid; } /// /// Converts the DevExpress LineStyle to LineStyle. /// /// The DevExpress LineStyle value. /// The LineStyle value. public static LineStyle ConvertLineStyle(string lineStyle) { if (lineStyle == "System.Drawing.Drawing2D.DashStyle.Dot") { return LineStyle.Dot; } else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.Dash") { return LineStyle.Dash; } else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.DashDot") { return LineStyle.DashDot; } else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.DashDotDot") { return LineStyle.DashDotDot; } else if (lineStyle == "System.Drawing.Drawing2D.DashStyle.Double") { return LineStyle.Double; } return LineStyle.Solid; } /// /// Converts the DevExpress TextAlignment to HorzAlignment. /// /// The DevExpress TextAlignment value. /// The HorzAlign value. public static HorzAlign ConvertTextAlignmentToHorzAlign(string textAlignment) { if (textAlignment.Contains("Center")) { return HorzAlign.Center; } if (textAlignment.Contains("Justify")) { return HorzAlign.Justify; } if (textAlignment.Contains("Right")) { return HorzAlign.Right; } return HorzAlign.Left; } /// /// Converts the DevExpress TextAlignment to VertAlignment. /// /// The DevExpress TextAlignment value. /// The VertAlign value. public static VertAlign ConvertTextAlignmentToVertAlign(string textAlignment) { if (textAlignment.Contains("Middle")) { return VertAlign.Center; } if (textAlignment.Contains("Bottom")) { return VertAlign.Bottom; } return VertAlign.Top; } /// /// Converts the DevExpress ImageSizeMode to PictureBoxSizeMode. /// /// The ImageSizeMode value as string. /// The PictureBoxSizeMode value. public static PictureBoxSizeMode ConvertImageSizeMode(string sizeMode) { if (sizeMode == "DevExpress.XtraPrinting.ImageSizeMode.StretchImage" || sizeMode == "StretchImage") { return PictureBoxSizeMode.StretchImage; } else if (sizeMode == "DevExpress.XtraPrinting.ImageSizeMode.AutoSize" || sizeMode == "AutoSize") { return PictureBoxSizeMode.AutoSize; } else if (sizeMode == "DevExpress.XtraPrinting.ImageSizeMode.CenterImage" || sizeMode == "CenterImage") { return PictureBoxSizeMode.CenterImage; } else if (sizeMode == "DevExpress.XtraPrinting.ImageSizeMode.ZoomImage" || sizeMode == "ZoomImage") { return PictureBoxSizeMode.Zoom; } else if (sizeMode == "DevExpress.XtraPrinting.ImageSizeMode.Squeeze" || sizeMode == "Squeeze") { return PictureBoxSizeMode.Zoom; } return PictureBoxSizeMode.Normal; } internal static ImageAlign ConvertImageAlignment(string alignment) { ImageAlign align = ImageAlign.None; switch(alignment) { case "TopCenter": return ImageAlign.Top_Center; case "TopLeft": return ImageAlign.Top_Left; case "TopRight": return ImageAlign.Top_Right; case "CenterLeft": return ImageAlign.Center_Left; case "CenterCenter": return ImageAlign.Center_Center; case "CenterRight": return ImageAlign.Center_Right; case "BottomLeft": return ImageAlign.Bottom_Left; case "BottomCenter": return ImageAlign.Bottom_Center; case "BottomRight": return ImageAlign.Bottom_Right; } return align; } /// /// Converts the DevExpress Shape to ShapeKind. /// /// The DevExpress Shape value as string. /// The ShapeKind value. public static ShapeKind ConvertShape(string shape) { if (shape.Contains("Rectangle")) { return ShapeKind.Rectangle; } else if (shape.Contains("Polygon")) { return ShapeKind.Triangle; } return ShapeKind.Ellipse; } /// /// Converts the DevExpress Barcode.Symbology to Barcode.Barcode. /// /// The DevExpress Barcode.Symbology value as string. /// The BarcodeObject instance. public static void ConvertBarcodeSymbology(string symbology, BarcodeObject barcode) { symbology = symbology.ToLower(); if (symbology.Contains("codabar")) { barcode.Barcode = new BarcodeCodabar(); } else if (symbology.Contains("code128")) { barcode.Barcode = new Barcode128(); } else if (symbology.Contains("code39")) { barcode.Barcode = new Barcode39(); } else if (symbology.Contains("code39extended")) { barcode.Barcode = new Barcode39Extended(); } else if (symbology.Contains("code93")) { barcode.Barcode = new Barcode93(); } else if (symbology.Contains("code9eextended")) { barcode.Barcode = new Barcode93Extended(); } else if (symbology.Contains("codemsi")) { barcode.Barcode = new BarcodeMSI(); } else if (symbology.Contains("datamatrix")) { barcode.Barcode = new BarcodeDatamatrix(); } else if (symbology.Contains("ean128")) { barcode.Barcode = new BarcodeEAN128(); } else if (symbology.Contains("ean13")) { barcode.Barcode = new BarcodeEAN13(); } else if (symbology.Contains("ean8")) { barcode.Barcode = new BarcodeEAN8(); } else if (symbology.Contains("industrial2of5")) { barcode.Barcode = new Barcode2of5Industrial(); } else if (symbology.Contains("interleaved2of5")) { barcode.Barcode = new Barcode2of5Interleaved(); } else if (symbology.Contains("matrix2of5")) { barcode.Barcode = new Barcode2of5Matrix(); } else if (symbology.Contains("pdf417")) { barcode.Barcode = new BarcodePDF417(); } else if (symbology.Contains("postnet")) { barcode.Barcode = new BarcodePostNet(); } else if (symbology.Contains("qrcode")) { barcode.Barcode = new BarcodeQR(); } else if (symbology.Contains("upca")) { barcode.Barcode = new BarcodeUPC_A(); } else if (symbology.Contains("upce0")) { barcode.Barcode = new BarcodeUPC_E0(); } else if (symbology.Contains("upce1")) { barcode.Barcode = new BarcodeUPC_E1(); } else if (symbology.Contains("upcsupplemental2")) { barcode.Barcode = new BarcodeSupplement2(); } else if (symbology.Contains("upcsupplemental5")) { barcode.Barcode = new BarcodeSupplement5(); } } /// /// Converts the DevExpress border sides to FastReport border sides /// /// The DevExpress Barcode.Symbology value as string. /// The BarcodeObject instance. public static BorderLines ConvertBorderSides(string sides, Border border) { BorderLines borderLines = BorderLines.None; if (!String.IsNullOrEmpty(sides)) { if (sides.IndexOf("Left") > -1) { borderLines |= BorderLines.Left; } if (sides.IndexOf("Top") > -1) { borderLines |= BorderLines.Top; } if (sides.IndexOf("Right") > -1) { borderLines |= BorderLines.Right; } if (sides.IndexOf("Bottom") > -1) { borderLines |= BorderLines.Bottom; } if (sides.IndexOf("All") > -1) { borderLines = BorderLines.All; } } return borderLines; } #endregion // Public Methods } }