public string ToString(ObjectStyle defaultStyle) { StringBuilder sb = new StringBuilder(); if (!Number.IsEqualTo(xStart, defaultStyle.xStart)) { sb.AppendFormat("xstart:{0};", xStart); } if (!Number.IsEqualTo(yStart, defaultStyle.yStart)) { sb.AppendFormat("ystart:{0};", yStart); } if (relativeWidth != defaultStyle.relativeWidth) { sb.AppendFormat("width:{0}%;", relativeWidth ?? 100); } if (width != defaultStyle.width) { sb.AppendFormat("width:{0};", width ?? 0); } if (relativeHeight != defaultStyle.relativeHeight) { sb.AppendFormat("height:{0}%;", relativeHeight ?? 100); } if (height != defaultStyle.height) { sb.AppendFormat("height:{0};", height ?? 0); } if (hPadding == vPadding && ((hPadding != defaultStyle.hPadding || vPadding != defaultStyle.vPadding))) { sb.AppendFormat("padding:{0};", Padding ?? 0); } else { if (hPadding != defaultStyle.hPadding) { sb.AppendFormat("hpadding:{0};", hPadding ?? 0); } if (vPadding != defaultStyle.vPadding) { sb.AppendFormat("vpadding:{0};", vPadding ?? 0); } } if (hFill != defaultStyle.hFill) { sb.AppendFormat("hfill:{0};", (hFill ?? false).ToString().ToLower()); } if (vFill != defaultStyle.vFill) { sb.AppendFormat("vfill:{0};", (vFill ?? false).ToString().ToLower()); } if (border != defaultStyle.border) { sb.AppendFormat("border:{0};", border ?? 0); } if (innerVerticalBorder == innerHorizontalBorder && (innerVerticalBorder != defaultStyle.innerVerticalBorder || innerHorizontalBorder != defaultStyle.innerHorizontalBorder)) { sb.AppendFormat("innerborder:{0};", InnerBorder ?? 0); } else { if (innerHorizontalBorder != defaultStyle.innerHorizontalBorder) { sb.AppendFormat("innerhborder:{0};", innerHorizontalBorder ?? 0); } if (innerVerticalBorder != defaultStyle.innerVerticalBorder) { sb.AppendFormat("innervborder:{0};", innerVerticalBorder ?? 0); } } if (spacing != defaultStyle.spacing) { sb.AppendFormat("spacing:{0};", spacing ?? 0); } if (innerVSpacing == innerHSpacing && (innerVSpacing != defaultStyle.innerVSpacing || innerHSpacing != defaultStyle.innerHSpacing)) { sb.AppendFormat("innerspacing:{0};", InnerSpacing ?? 0); } else { if (innerHSpacing != defaultStyle.innerHSpacing) { sb.AppendFormat("innerhspacing:{0};", innerHSpacing ?? 0); } if (innerVSpacing != defaultStyle.innerVSpacing) { sb.AppendFormat("innervspacing:{0};", innerVSpacing ?? 0); } } if (HAlign != HorizontalAlignment.Left && HAlign != defaultStyle.HAlign) { switch (HAlign) { case HorizontalAlignment.Right: sb.Append("halign:right;"); break; case HorizontalAlignment.Center: sb.Append("halign:center;"); break; } } if (VAlign != VerticalAlignment.Top && VAlign != defaultStyle.VAlign) { switch (VAlign) { case VerticalAlignment.Bottom: sb.Append("valign:bottom;"); break; case VerticalAlignment.Center: sb.Append("valign:center;"); break; } } if (DrawEmpty != defaultStyle.DrawEmpty) { sb.AppendFormat("drawempty:{0};", DrawEmpty.ToString().ToLowerInvariant()); } if (AllowHBreak != defaultStyle.AllowHBreak) { sb.AppendFormat("allowhbreak:{0};", AllowHBreak.ToString().ToLowerInvariant()); } if (AllowVBreak != defaultStyle.AllowVBreak) { sb.AppendFormat("allowvbreak:{0};", AllowVBreak.ToString().ToLowerInvariant()); } if (!bgColor.Equal(defaultStyle.BgColor)) { sb.AppendFormat("bgcolor:{0};", BgColor.ToHTMLColor()); } if (!fgColor.Equal(defaultStyle.FgColor)) { sb.AppendFormat("fgcolor:{0};", FgColor.ToHTMLColor()); } if (!borderColor.Equals(defaultStyle.BorderColor)) { sb.AppendFormat("bordercolor:{0};", BorderColor.ToHTMLColor()); } return(sb.ToString().TrimEnd(';')); }
private void HandlePintaCoreActionsImageAutoCropActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); Cairo.ImageSurface image = doc.CurrentUserLayer.Surface; Gdk.Rectangle rect = image.GetBounds(); Cairo.Color borderColor = image.GetPixel(0, 0); bool cropSide = true; int depth = -1; //From the top down while (cropSide) { depth++; for (int i = 0; i < image.Width; i++) { if (!borderColor.Equals(image.GetPixel(i, depth))) { cropSide = false; break; } } //Check if the image is blank/mono-coloured, only need to do it on this scan if (depth == image.Height) { return; } } rect = new Gdk.Rectangle(rect.X, rect.Y + depth, rect.Width, rect.Height - depth); depth = image.Height; cropSide = true; //From the bottom up while (cropSide) { depth--; for (int i = 0; i < image.Width; i++) { if (!borderColor.Equals(image.GetPixel(i, depth))) { cropSide = false; break; } } } rect = new Gdk.Rectangle(rect.X, rect.Y, rect.Width, depth - rect.Y); depth = 0; cropSide = true; //From left to right while (cropSide) { depth++; for (int i = 0; i < image.Height; i++) { if (!borderColor.Equals(image.GetPixel(depth, i))) { cropSide = false; break; } } } rect = new Gdk.Rectangle(rect.X + depth, rect.Y, rect.Width - depth, rect.Height); depth = image.Width; cropSide = true; //From right to left while (cropSide) { depth--; for (int i = 0; i < image.Height; i++) { if (!borderColor.Equals(image.GetPixel(depth, i))) { cropSide = false; break; } } } rect = new Gdk.Rectangle(rect.X, rect.Y, depth - rect.X, rect.Height); CropImageToRectangle(doc, rect); }