/// <summary> /// Handle the mouse move /// </summary> /// <param name="sender"></param> /// <param name="mouseEventArgs"></param> public override void MouseMove(object sender, MouseEventArgs mouseEventArgs) { if (EditStatus != EditStatus.MOVING) { return; } Owner.Invalidate(); var newGripperLocation = new NativePoint(mouseEventArgs.X, mouseEventArgs.Y); var surfaceBounds = new NativeRect(0, 0, Owner.Parent.Width, Owner.Parent.Height); // Check if gripper inside the parent (surface), if not we need to move it inside // This was made for BUG-1682 if (!surfaceBounds.Contains(newGripperLocation)) { if (newGripperLocation.X > surfaceBounds.Right) { newGripperLocation = newGripperLocation.ChangeX(surfaceBounds.Right - 5); } if (newGripperLocation.X < surfaceBounds.Left) { newGripperLocation = newGripperLocation.ChangeX(surfaceBounds.Left); } if (newGripperLocation.Y > surfaceBounds.Bottom) { newGripperLocation = newGripperLocation.ChangeY(surfaceBounds.Bottom - 5); } if (newGripperLocation.Y < surfaceBounds.Top) { newGripperLocation = newGripperLocation.ChangeY(surfaceBounds.Top); } } Location = newGripperLocation; Owner.Invalidate(); }
private void ApplyDropShadowEffectValues(string valuesString, DropShadowEffect effect) { var values = valuesString.Split('|'); foreach (var nameValuePair in values) { var pair = nameValuePair.Split(':'); switch (pair[0]) { case "Darkness": // Fix to prevent BUG-1753 if (pair[1] != null && float.TryParse(pair[1], NumberStyles.Float, _numberFormatInfo, out var darkness)) { if (darkness <= 1.0) { effect.Darkness = darkness; } } break; case "ShadowSize": if (int.TryParse(pair[1], out var shadowSize)) { effect.ShadowSize = shadowSize; } break; case "ShadowOffset": var shadowOffset = new NativePoint(); var coordinates = pair[1].Split(','); if (int.TryParse(coordinates[0], out var shadowOffsetX)) { shadowOffset = shadowOffset.ChangeX(shadowOffsetX); } if (int.TryParse(coordinates[1], out var shadowOffsetY)) { shadowOffset = shadowOffset.ChangeY(shadowOffsetY); } effect.ShadowOffset = shadowOffset; break; } } }
/// <summary> /// This method takes the actual capture of the document (frame) /// </summary> /// <param name="documentContainer">DocumentContainer</param> /// <param name="contentWindowDetails">Needed for referencing the location of the frame</param> /// <param name="graphicsTarget">Graphics</param> /// <returns>Bitmap with the capture</returns> private static void DrawDocument(DocumentContainer documentContainer, IInteropWindow contentWindowDetails, Graphics graphicsTarget) { documentContainer.SetAttribute("scroll", 1); //Get Browser Window Width & Height var pageWidth = documentContainer.ScrollWidth; var pageHeight = documentContainer.ScrollHeight; if (pageWidth * pageHeight == 0) { Log.Warn().WriteLine("Empty page for DocumentContainer {0}: {1}", documentContainer.Name, documentContainer.Url); return; } //Get Screen Width & Height (this is better as the WindowDetails.ClientRectangle as the real visible parts are there! var viewportWidth = documentContainer.ClientWidth; var viewportHeight = documentContainer.ClientHeight; if (viewportWidth * viewportHeight == 0) { Log.Warn().WriteLine("Empty viewport for DocumentContainer {0}: {1}", documentContainer.Name, documentContainer.Url); return; } // Store the current location so we can set the browser back and use it for the mouse cursor var startLeft = documentContainer.ScrollLeft; var startTop = documentContainer.ScrollTop; Log.Debug().WriteLine("Capturing {4} with total size {0},{1} displayed with size {2},{3}", pageWidth, pageHeight, viewportWidth, viewportHeight, documentContainer.Name); // Variable used for looping horizontally var horizontalPage = 0; // The location of the browser, used as the destination into the bitmap target var targetOffset = new NativePoint(); // Loop of the pages and make a copy of the visible viewport while (horizontalPage * viewportWidth < pageWidth) { // Scroll to location documentContainer.ScrollLeft = viewportWidth * horizontalPage; targetOffset = targetOffset.ChangeX(documentContainer.ScrollLeft); // Variable used for looping vertically var verticalPage = 0; while (verticalPage * viewportHeight < pageHeight) { // Scroll to location documentContainer.ScrollTop = viewportHeight * verticalPage; //Shoot visible window targetOffset = targetOffset.ChangeY(documentContainer.ScrollTop); // Draw the captured fragment to the target, but "crop" the scrollbars etc while capturing var viewPortSize = new Size(viewportWidth, viewportHeight); var clientRectangle = new NativeRect(documentContainer.SourceLocation, viewPortSize); var fragment = contentWindowDetails.PrintWindow(); if (fragment != null) { Log.Debug().WriteLine("Captured fragment size: {0}x{1}", fragment.Width, fragment.Height); try { // cut all junk, due to IE "border" we need to remove some parts var viewportRect = documentContainer.ViewportRectangle; if (!viewportRect.IsEmpty) { Log.Debug().WriteLine("Cropping to viewport: {0}", viewportRect); BitmapHelper.Crop(ref fragment, ref viewportRect); } Log.Debug().WriteLine("Cropping to clientRectangle: {0}", clientRectangle); // Crop to clientRectangle if (BitmapHelper.Crop(ref fragment, ref clientRectangle)) { var targetLocation = new NativePoint(documentContainer.DestinationLocation.X, documentContainer.DestinationLocation.Y); Log.Debug().WriteLine("Fragment targetLocation is {0}", targetLocation); targetLocation = targetLocation.Offset(targetOffset); Log.Debug().WriteLine("After offsetting the fragment targetLocation is {0}", targetLocation); Log.Debug().WriteLine("Drawing fragment of size {0} to {1}", fragment.Size, targetLocation); graphicsTarget.DrawImage(fragment, targetLocation); graphicsTarget.Flush(); } else { // somehow we are capturing nothing!? Log.Warn().WriteLine("Crop of {0} failed?", documentContainer.Name); break; } } finally { fragment.Dispose(); } } else { Log.Warn().WriteLine("Capture of {0} failed!", documentContainer.Name); } verticalPage++; } horizontalPage++; } // Return to where we were documentContainer.ScrollLeft = startLeft; documentContainer.ScrollTop = startTop; }
/// <summary> /// Private helper method for the FindAutoCropRectangle /// </summary> /// <param name="fastBitmap">IFastBitmap</param> /// <param name="referenceColor">color for reference</param> /// <param name="cropDifference">int</param> /// <returns>NativeRect</returns> private static NativeRect FindAutoCropRectangle(this IFastBitmap fastBitmap, Color referenceColor, int cropDifference) { var cropRectangle = NativeRect.Empty; var min = new NativePoint(int.MaxValue, int.MaxValue); var max = new NativePoint(int.MinValue, int.MinValue); if (cropDifference > 0) { for (var y = 0; y < fastBitmap.Height; y++) { for (var x = 0; x < fastBitmap.Width; x++) { var currentColor = fastBitmap.GetColorAt(x, y); var diffR = Math.Abs(currentColor.R - referenceColor.R); var diffG = Math.Abs(currentColor.G - referenceColor.G); var diffB = Math.Abs(currentColor.B - referenceColor.B); if ((diffR + diffG + diffB) / 3 <= cropDifference) { continue; } if (x < min.X) { min = min.ChangeX(x); } if (y < min.Y) { min = min.ChangeY(y); } if (x > max.X) { max = max.ChangeX(x); } if (y > max.Y) { max = max.ChangeY(y); } } } } else { for (var y = 0; y < fastBitmap.Height; y++) { for (var x = 0; x < fastBitmap.Width; x++) { var currentColor = fastBitmap.GetColorAt(x, y); if (!referenceColor.Equals(currentColor)) { continue; } if (x < min.X) { min = min.ChangeX(x); } if (y < min.Y) { min = min.ChangeY(y); } if (x > max.X) { max = max.ChangeX(x); } if (y > max.Y) { max = max.ChangeY(y); } } } } if (!(NativePoint.Empty.Equals(min) && max.Equals(new NativePoint(fastBitmap.Width - 1, fastBitmap.Height - 1))) && !(min.X == int.MaxValue || min.Y == int.MaxValue || max.X == int.MinValue || min.X == int.MinValue)) { cropRectangle = new NativeRect(min.X, min.Y, max.X - min.X + 1, max.Y - min.Y + 1); } return(cropRectangle); }