public void TestColorAdded() { var image = new CodedImage { Size = new Size(2, 3), Palette = new CodedPalette() }; var undoRedoProvider = new UndoRedoProvider(image); Assert.IsFalse(undoRedoProvider.CanUndo, "Precondition"); image.Palette.Add(new CodedColor(1) { ColorCode = "100" }); Assert.IsTrue(undoRedoProvider.CanUndo); Assert.AreEqual(Ravlyk.SAE.Drawing.Properties.Resources.UndoRedoActionAddThread, undoRedoProvider.UndoDescription); Assert.IsFalse(undoRedoProvider.CanRedo); Assert.AreEqual(1, image.Palette.Count); Assert.AreEqual("100", image.Palette[1].ColorCode); undoRedoProvider.Undo(); Assert.IsFalse(undoRedoProvider.CanUndo); Assert.IsTrue(undoRedoProvider.CanRedo); Assert.AreEqual(Ravlyk.SAE.Drawing.Properties.Resources.UndoRedoActionAddThread, undoRedoProvider.RedoDescription); Assert.AreEqual(0, image.Palette.Count); undoRedoProvider.Redo(); Assert.IsTrue(undoRedoProvider.CanUndo); Assert.AreEqual(Ravlyk.SAE.Drawing.Properties.Resources.UndoRedoActionAddThread, undoRedoProvider.UndoDescription); Assert.IsFalse(undoRedoProvider.CanRedo); Assert.AreEqual(1, image.Palette.Count); Assert.AreEqual("100", image.Palette[1].ColorCode); }
public void TestSetNewImage() { var imageSetter = new ImageSetterManipulator(); var originalImage = imageSetter.ManipulatedImage; var newImage = new CodedImage { Size = new Size(5, 5) }; int[] newPixels, manipulatedPixels; using (newImage.LockPixels(out newPixels)) { for (int i = 0; i < newPixels.Length; i++) { newPixels[i] = i; } } imageSetter.SetNewImage(newImage); Assert.AreSame(originalImage, imageSetter.SourceImage, "Source image still should be same original object."); Assert.AreSame(originalImage, imageSetter.ManipulatedImage, "Manipulated image still should be same original object."); Assert.AreEqual(newImage.Size, imageSetter.ManipulatedImage.Size); using (newImage.LockPixels(out newPixels)) using (imageSetter.ManipulatedImage.LockPixels(out manipulatedPixels)) { Assert.AreEqual(newPixels.Length, manipulatedPixels.Length); for (int i = 0; i < newPixels.Length; i++) { Assert.AreEqual(newPixels[i], manipulatedPixels[i], string.Format("Pixels in position {0} should be same", i)); } } }
public void TestGetTouchPointerStyle() { var sourceImage = new CodedImage { Size = new Size(200, 150) }; var cropController = new ImageCropController(new ImageCropManipulator(sourceImage)); var visualZoomedCropController = new VisualZoomCropController(cropController, new Size(60, 50)); visualZoomedCropController.ZoomPercent = 100; visualZoomedCropController.CropKind = ImageCropper.CropKind.Rectangle; visualZoomedCropController.SetCropRectForTest(new Rectangle(20, 10, 160, 130)); visualZoomedCropController.ZoomPercent = 50; Assert.AreEqual(new Rectangle(10, 5, 80, 65), visualZoomedCropController.CropRect); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.Shift, false, new Point(0, 0), new Point(99, 74)); visualZoomedCropController.OnTouched(new Point(0, 0)); visualZoomedCropController.OnShift(new Point(-20, -10)); // Shift on distance (-20, -10) visualZoomedCropController.OnUntouched(new Point(0, 0)); Assert.AreEqual(new Rectangle(20, 10, 60, 50), visualZoomedCropController.VisualImageFrame); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeAll, false, new Point(0, 0), new Point(20, 30)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeLeftTop_RightBottom, true, new Point(-10, -5), new Point(70, 60)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeRightTop_LeftBottom, true, new Point(70, -5), new Point(-10, 60)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeHorizontal, true, new Point(-10, 27), new Point(70, 27)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeVertical, true, new Point(30, -5), new Point(30, 60)); }
public void TestMouseWheel() { var font = SAEResources.GetAllFonts().First(); var image = new CodedImage { Size = new Size(5, 5) }; var symboler = new ImageSymbolsController(new ImageSymbolsManipulator(image), new[] { font }, font); using (symboler.SuspendCallManipulations()) { symboler.IncludeLetters = true; symboler.IncludeNumbers = false; symboler.IncludeSymbols = false; } var visualSymbolsController = new VisualSymbolsController(symboler, new Size(100, 150)); Assert.AreEqual(0, visualSymbolsController.VerticalShift); using (visualSymbolsController.SuspendUpdateVisualImage()) { visualSymbolsController.OnMouseWheel(100); Assert.AreEqual(0, visualSymbolsController.VerticalShift, "Should not shift beyond top row."); visualSymbolsController.OnMouseWheel(-100); Assert.AreEqual(10, visualSymbolsController.VerticalShift); visualSymbolsController.OnMouseWheel(30); Assert.AreEqual(7, visualSymbolsController.VerticalShift); visualSymbolsController.OnMouseWheel(-30000); Assert.AreEqual(1098, visualSymbolsController.VerticalShift, "Should not shift beyond bottom row."); } }
public void TestDefaultSettings() { var image = new CodedImage { Size = new Size(5, 5) }; var resizer = new ImageSizeController4Test(new ImageSizeManipulator(image)); // Use test controller as we don't need to update image using (resizer.SuspendCallManipulations()) { resizer.KeepAspect = false; resizer.Width = 30; resizer.Height = 25; resizer.FilterType = ImageResampler.FilterType.Box; } var newResizer = new ImageSizeController4Test(new ImageSizeManipulator(image)); // Precondition checks Assert.IsTrue(newResizer.KeepAspect); Assert.AreNotEqual(30, newResizer.Width); Assert.AreNotEqual(25, newResizer.Height); Assert.AreNotEqual(ImageResampler.FilterType.Box, newResizer.FilterType); resizer.SaveDefaults(); newResizer = new ImageSizeController4Test(new ImageSizeManipulator(image)); Assert.IsFalse(newResizer.KeepAspect); Assert.AreEqual(30, newResizer.Width); Assert.AreEqual(25, newResizer.Height); Assert.AreEqual(ImageResampler.FilterType.Box, newResizer.FilterType); SAEWizardSettings.Default.Reset(); // Restore defaults }
public void TestFlipHorizontally() { var srcImage = new CodedImage { Size = new Size(3, 2) }; int[] pixels; using (srcImage.LockPixels(out pixels)) { for (int i = 0; i < pixels.Length; i++) { pixels[i] = i; } } var rotator = new ImageRotateManipulator(srcImage); rotator.FlipHorizontally(); var dstImage = rotator.ManipulatedImage; Assert.AreEqual(new Size(3, 2), dstImage.Size); using (dstImage.LockPixels(out pixels)) { Assert.AreEqual(2, pixels[0]); Assert.AreEqual(1, pixels[1]); Assert.AreEqual(0, pixels[2]); Assert.AreEqual(5, pixels[3]); Assert.AreEqual(4, pixels[4]); Assert.AreEqual(3, pixels[5]); } }
public void TestSetNewImage() { var controller = new ImageSetterController(new ImageSetterManipulator()); var newImage = new CodedImage { Size = new Size(5, 5) }; int[] newPixels, manipulatedPixels; using (newImage.LockPixels(out newPixels)) { for (int i = 0; i < newPixels.Length; i++) { newPixels[i] = i; } } controller.SetNewImage(newImage); Assert.AreEqual(newImage.Size, controller.Manipulator.ManipulatedImage.Size); using (newImage.LockPixels(out newPixels)) using (controller.Manipulator.ManipulatedImage.LockPixels(out manipulatedPixels)) { Assert.AreEqual(newPixels.Length, manipulatedPixels.Length); for (int i = 0; i < newPixels.Length; i++) { Assert.AreEqual(newPixels[i], manipulatedPixels[i], string.Format("Pixels in position {0} should be same", i)); } } }
public void TestSymbolsFont() { var font = SAEResources.GetAllFonts().First(); var image = new CodedImage { Size = new Size(5, 5) }; var symboler = new ImageSymbolsController4Test(new ImageSymbolsManipulator(image), new[] { font }, font); Assert.AreEqual(1, symboler.AvailableFonts.Count()); Assert.AreSame(font, symboler.SymbolsFont); Assert.AreEqual(font.Name, symboler.SymbolsFontName); symboler.CallManipulationsCoreFired = false; var otherFont = SAEResources.GetAllFonts().First(); otherFont.ChangeNameForTest("Other font"); symboler.AddSymbolsFonts(new[] { otherFont }); Assert.AreEqual(2, symboler.AvailableFonts.Count()); Assert.AreSame(font, symboler.SymbolsFont, "Selected font should not be changed."); Assert.IsFalse(symboler.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); symboler.SymbolsFontName = "Xyz"; Assert.AreSame(font, symboler.SymbolsFont, "Selected font should remain if new name is incorrect."); Assert.AreEqual(font.Name, symboler.SymbolsFontName); Assert.IsFalse(symboler.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); symboler.SymbolsFontName = "Other font"; Assert.AreSame(otherFont, symboler.SymbolsFont, "New font should be selected"); Assert.AreEqual("Other font", symboler.SymbolsFontName); Assert.IsTrue(symboler.CallManipulationsCoreFired, "Should call manipulations when symbols font is changed."); }
public void TestAvailableSymbols() { var font = SAEResources.GetAllFonts().First(); var image = new CodedImage { Size = new Size(5, 5) }; var symboler = new ImageSymbolsController4Test(new ImageSymbolsManipulator(image), new[] { font }, font); symboler.IncludeNumbers = false; symboler.IncludeLetters = false; symboler.IncludeSymbols = false; Assert.AreEqual(1, symboler.AvailableSymbols.Count); Assert.AreEqual(' ', symboler.AvailableSymbols[0].Key); symboler.IncludeNumbers = true; Assert.AreEqual(11, symboler.AvailableSymbols.Count, "10 digits and 1 space."); symboler.IncludeNumbers = false; symboler.IncludeLetters = true; Assert.AreEqual(117, symboler.AvailableSymbols.Count, "26 latin letters in both cases + 32 cyrillic letters in both cases + 1 space."); symboler.IncludeNumbers = true; Assert.AreEqual(127, symboler.AvailableSymbols.Count, "10+116+1"); symboler.IncludeSymbols = true; Assert.IsTrue(symboler.AvailableSymbols.Count > 127, "10+116+1+more"); }
public void TestDoesntCallManipulationsWithoutChanges() { var image = new CodedImage { Size = new Size(5, 5) }; var cropper = new ImageCropController4Test(new ImageCropManipulator(image)); Assert.AreEqual(ImageCropper.CropKind.None, cropper.CropKind, "Prerequisits"); Assert.AreEqual(new Rectangle(0, 0, 5, 5), cropper.CropRect, "Prerequisits"); Assert.IsFalse(cropper.CallManipulationsCoreFired, "Prerequisits"); cropper.CropKind = ImageCropper.CropKind.Rectangle; Assert.IsTrue(cropper.CallManipulationsCoreFired, "Should call manipulations for initial crop kind change."); cropper.CallManipulationsCoreFired = false; cropper.CropKind = ImageCropper.CropKind.Rectangle; Assert.IsFalse(cropper.CallManipulationsCoreFired, "Should not call manipulations because there are no changes."); cropper.CropKind = ImageCropper.CropKind.Arc; Assert.IsTrue(cropper.CallManipulationsCoreFired, "Should call manipulations after changed parameters."); cropper.CallManipulationsCoreFired = false; cropper.CropRect = new Rectangle(0, 0, 5, 5); Assert.IsFalse(cropper.CallManipulationsCoreFired, "Should not call manipulations because there are no changes."); cropper.CropRect = new Rectangle(1, 1, 3, 2); Assert.IsTrue(cropper.CallManipulationsCoreFired, "Should call manipulations after changed parameters."); }
public void TestDoesntCallManipulationsWithoutChanges() { var image = new CodedImage { Size = new Size(5, 5) }; var symboler = new ImageSymbolsController4Test(new ImageSymbolsManipulator(image)); Assert.IsFalse(symboler.IncludeNumbers, "Default value"); Assert.IsFalse(symboler.IncludeLetters, "Default value"); Assert.IsTrue(symboler.IncludeSymbols, "Default value"); Assert.IsTrue(symboler.CallManipulationsCoreFired, "Manipulations should have been already executed for default options."); symboler.CallManipulationsCoreFired = false; symboler.IncludeNumbers = false; Assert.IsFalse(symboler.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); symboler.IncludeNumbers = true; Assert.IsTrue(symboler.CallManipulationsCoreFired, "Should call manipulations for changed included symbols range."); symboler.CallManipulationsCoreFired = false; symboler.IncludeLetters = false; Assert.IsFalse(symboler.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); symboler.IncludeLetters = true; Assert.IsTrue(symboler.CallManipulationsCoreFired, "Should call manipulations for changed included symbols range."); symboler.CallManipulationsCoreFired = false; symboler.IncludeSymbols = true; Assert.IsFalse(symboler.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); symboler.IncludeSymbols = false; Assert.IsTrue(symboler.CallManipulationsCoreFired, "Should call manipulations for changed included symbols range."); }
public override void TestRestoreManipulationsCore() { var image = new CodedImage { Size = new Size(30, 20), Palette = new CodedPalette() }; image.CompletePalette(); for (int x = 0; x < 30; x++) { for (int y = 0; y < 20; y++) { image[x, y] = new CodedColor((byte)(x * 8), (byte)(y * 12), (byte)((x + y) * 5)); } } var dummyManipulator = new ImageManipulatorTest.DummyManipulator(image); var colorer = new ImageColorsManipulator(dummyManipulator); var childManipulator = new ImageManipulatorTest.DummyManipulator(colorer); colorer.QuantizeColors(3); Assert.AreEqual(3, colorer.ManipulatedImage.Palette.Count); colorer.ManipulatedImage.Palette.Add(new CodedColor(254, 254, 254)); childManipulator.RestoreManipulationsCoreFired = false; Assert.AreEqual(4, colorer.ManipulatedImage.Palette.Count, "Precondition"); Assert.IsFalse(childManipulator.RestoreManipulationsCoreFired); dummyManipulator.CallOnImageChanged(); Assert.AreEqual(3, colorer.ManipulatedImage.Palette.Count); Assert.IsFalse(childManipulator.RestoreManipulationsCoreFired); Assert.NotNull(childManipulator.ManipulatedImage); Assert.IsTrue(childManipulator.RestoreManipulationsCoreFired); }
public void TestImage() { var image = new CodedImage(); var action = new DummyUndoRedoAction(image); Assert.AreSame(image, action.ImageExposed); }
protected override void RestoreImageSettingsCore(CodedImage image) { base.RestoreImageSettingsCore(image); using (SuspendCallManipulations()) { PaletteName = image.Palette.Name; int maxColorsValue; MaxColorsCount = image.TryGetAdditionalValueAsInt(nameof(MaxColorsCount), out maxColorsValue) ? maxColorsValue : image.Palette.Count; string comparisonTypeValue; if (image.TryGetAdditionalDataAsString(nameof(ColorComparisonType), out comparisonTypeValue)) { ColorComparisonTypes comparisonType; if (Enum.TryParse(comparisonTypeValue, out comparisonType)) { ColorComparisonType = comparisonType; } } bool ensureBlackAndWhiteValue; if (image.TryGetAdditionalValueAsBool(nameof(EnsureBlackAndWhiteColors), out ensureBlackAndWhiteValue)) { EnsureBlackAndWhiteColors = ensureBlackAndWhiteValue; } int ditherLevelValue; if (image.TryGetAdditionalValueAsInt(nameof(DitherLevel), out ditherLevelValue)) { DitherLevel = ditherLevelValue; } } }
public void TestMaxColorsCountInCorrectLimits() { var image = new CodedImage { Size = new Size(5, 5) }; var colorer = new ImageColorsController4Test(new ImageColorsManipulator(image)); Assert.AreEqual(ImageColorsController.MaximumAvailableColorsCountWithoutPalette, colorer.MaxAvailableColorsCount, "Maximum available colors count without palette."); colorer.MaxColorsCount = 1; Assert.AreEqual(2, colorer.MaxColorsCount, "Minimum valid max colors count is 2."); colorer.MaxColorsCount = 1000; Assert.AreEqual(ImageColorsController.MaximumAvailableColorsCountWithoutPalette, colorer.MaxColorsCount, "Max colors count should not go above maximum value without palette."); var palette = new CodedPalette { Name = "Palette 1" }; for (int i = 0; i < 10; i++) { palette.Add(new CodedColor(i)); } colorer = new ImageColorsController4Test(new ImageColorsManipulator(image), new[] { palette }); Assert.AreEqual(10, colorer.MaxAvailableColorsCount, "Maximum available colors count should equal colors count in palette."); colorer.MaxColorsCount = 1000; Assert.AreEqual(10, colorer.MaxColorsCount, "Max colors count should not go above colors count in palette."); }
static Style GetCrossCellStyle(Stylesheet stylesheet, CodedImage image, int x, int y, PatternGridPainter gridPainter) { var codedColor = image[x, y]; var style = new Style(); //style.NumberFormat = new NumberFormat(""); style.Alignment = new Alignment { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Middle, WrapText = false }; style.Fill = new Fill { Color = GdiColor.FromArgb(gridPainter.GetBackColorArgb(codedColor)) }; style.Font = new Font { Name = gridPainter.SymbolsFont.Name, Size = 10, Color = GdiColor.FromArgb(gridPainter.GetSymbolColorArgb(codedColor)) }; style.Borders = new Borders(); style.Borders.Top.BorderStyle = GetBorderStyle(y, image.Size.Height); style.Borders.Top.Color = GetBorderColor(y, image.Size.Height); style.Borders.Bottom.BorderStyle = GetBorderStyle(y + 1, image.Size.Height); style.Borders.Bottom.Color = GetBorderColor(y + 1, image.Size.Height); style.Borders.Left.BorderStyle = GetBorderStyle(x, image.Size.Width); style.Borders.Left.Color = GetBorderColor(x, image.Size.Width); style.Borders.Right.BorderStyle = GetBorderStyle(x + 1, image.Size.Width); style.Borders.Right.Color = GetBorderColor(x + 1, image.Size.Width); style.Borders.Diagonal.BorderStyle = BorderStyles.None; return(stylesheet.AddStyle(style)); }
public void TestParentManipulator() { var image = new CodedImage { Size = new Size(2, 2) }; var parentManipulator = new DummyManipulator(image); var childManipulator = new DummyManipulator(parentManipulator); var grandChildManipulator = new DummyManipulator(childManipulator); Assert.IsNotNull(childManipulator.SourceImage); Assert.IsNotNull(childManipulator.ManipulatedImage); Assert.IsNotNull(grandChildManipulator.ManipulatedImage); Assert.AreNotSame(childManipulator.SourceImage, childManipulator.ManipulatedImage); Assert.AreSame(parentManipulator.ManipulatedImage, childManipulator.SourceImage); Assert.AreSame(childManipulator.ManipulatedImage, grandChildManipulator.SourceImage); childManipulator.RestoreManipulationsCoreFired = false; grandChildManipulator.RestoreManipulationsCoreFired = false; parentManipulator.CallOnImageChanged(); Assert.IsTrue(childManipulator.RestoreManipulationsCoreFired); Assert.IsFalse(childManipulator.ResetFired); Assert.IsTrue(grandChildManipulator.RestoreManipulationsCoreFired); Assert.IsFalse(grandChildManipulator.ResetFired); }
static Style GetVerticalRulerCellStyle(Stylesheet stylesheet, CodedImage image, int y, PatternGridPainter gridPainter) { var style = new Style(); style.Alignment = new Alignment { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Middle, WrapText = false }; style.Font = new Font { Size = 10, Color = GridPainterSettings.Default.NumbersArgb }; style.Borders = new Borders(); style.Borders.Top.BorderStyle = GetBorderStyle(y, image.Size.Height); style.Borders.Top.Color = GetBorderColor(y, image.Size.Height); style.Borders.Bottom.BorderStyle = GetBorderStyle(y + 1, image.Size.Height); style.Borders.Bottom.Color = GetBorderColor(y + 1, image.Size.Height); style.Borders.Left.BorderStyle = BorderStyles.None; style.Borders.Right.BorderStyle = BorderStyles.Medium; style.Borders.Right.Color = GridPainterSettings.Default.Line10Argb; style.Borders.Diagonal.BorderStyle = BorderStyles.None; return(stylesheet.AddStyle(style)); }
protected virtual CodedImage CreateManipulatedImage(CodedImage originalImage) { var newImage = originalImage.Clone(true); newImage.ResetAdditionalData(); return(newImage); }
public void TestCropRect() { var srcImage = new CodedImage { Size = new Size(5, 5) }; int[] pixels; using (srcImage.LockPixels(out pixels)) { for (int i = 0; i < pixels.Length; i++) { pixels[i] = i; } } var cropper = new ImageCropManipulator(srcImage); cropper.CropRect(new Rectangle(2, 1, 2, 3)); var dstImage = cropper.ManipulatedImage; Assert.AreEqual(new Size(2, 3), dstImage.Size); using (dstImage.LockPixels(out pixels)) { Assert.AreEqual(6, pixels.Length); Assert.AreEqual(7, pixels[0]); Assert.AreEqual(8, pixels[1]); Assert.AreEqual(12, pixels[2]); Assert.AreEqual(13, pixels[3]); Assert.AreEqual(17, pixels[4]); Assert.AreEqual(18, pixels[5]); } }
/// <summary> /// Initialized undo/redo action. /// </summary> /// <param name="image">Image object for undo/redo operation.</param> /// <param name="x">Pixel's x-coordinate.</param> /// <param name="y">Pixel's y-coordinate.</param> /// <param name="oldColor">Pixel's old color.</param> /// <param name="newColor">Pixel's new color.</param> public UndoRedoActionChangePixelColor(CodedImage image, int x, int y, CodedColor oldColor, CodedColor newColor) : base(image) { this.x = x; this.y = y; this.oldColor = oldColor; this.newColor = newColor; }
public void TestCropArt() { var srcImage = new CodedImage { Size = new Size(10, 10) }; int[] pixels; using (srcImage.LockPixels(out pixels)) { for (int i = 0; i < pixels.Length; i++) { pixels[i] = 100; } } var cropper = new ImageCropManipulator(srcImage); cropper.CropArc(new Rectangle(1, 1, 8, 8)); var dstImage = cropper.ManipulatedImage; dstImage.CompletePalette(); Assert.AreEqual(new Size(8, 8), dstImage.Size); Assert.AreEqual(new CodedColor(255, 255, 255), dstImage[0, 0]); Assert.AreEqual(new CodedColor(255, 255, 255), dstImage[0, 7]); Assert.AreEqual(new CodedColor(255, 255, 255), dstImage[7, 0]); Assert.AreEqual(new CodedColor(255, 255, 255), dstImage[7, 7]); Assert.AreEqual(new CodedColor(100), dstImage[4, 4], "Some point in the centre"); }
public void TestVisualSymbolsController() { var font = SAEResources.GetAllFonts().First(); var image = new CodedImage { Size = new Size(5, 5) }; var symboler = new ImageSymbolsController(new ImageSymbolsManipulator(image), new[] { font }, font); using (symboler.SuspendCallManipulations()) { symboler.IncludeLetters = true; symboler.IncludeNumbers = false; symboler.IncludeSymbols = false; } Assert.AreEqual(117, symboler.AvailableSymbols.Count, "Precondition"); var visualSymbolsController = new VisualSymbolsController(symboler, new Size(100, 150)); Assert.AreSame(symboler, visualSymbolsController.Controller); Assert.AreEqual(3, visualSymbolsController.ColumnsCount); Assert.AreEqual(39, visualSymbolsController.RowsCount); Assert.AreEqual(5, visualSymbolsController.VisibleRowsCount); Assert.IsTrue(visualSymbolsController.RequiresShift); Assert.AreEqual(new Size(96, 150), visualSymbolsController.VisualImage.Size); }
static string ToCsv(CodedImage image) { const char Delimiter = '\t'; var sb = new StringBuilder(); for (int y = 0; y < image.Size.Height; y++) { for (int x = 0; x < image.Size.Width; x++) { if (x > 0) { sb.Append(Delimiter); } sb.Append(image[x, y].SymbolChar); } sb.AppendLine(); } sb.AppendLine(); sb.AppendLine(); sb.AppendLine(image.Palette.Name); sb.Append("Symbol").Append(Delimiter).Append("Code").AppendLine(); foreach (var color in image.Palette) { sb.Append(color.SymbolChar).Append(Delimiter).Append(color.ColorCode).AppendLine(); } return(sb.ToString()); }
public void TestSetSizeInCorrectLimits() { var image = new CodedImage { Size = new Size(5, 5) }; var resizer = new ImageSizeController4Test(new ImageSizeManipulator(image)); // Use test controller as we don't need to update image Assert.AreEqual(200, resizer.Width, "Default value"); Assert.AreEqual(200, resizer.Height, "Initially recalculated height value"); resizer.Width = ImageSizeController.MinimumSize - 5; Assert.AreEqual(ImageSizeController.MinimumSize, resizer.Width, "Should be changed to minimum width."); Assert.AreEqual(ImageSizeController.MinimumSize, resizer.Height, "Height should be recalculated."); resizer.Width = ImageSizeController.MaximumSize + 5; Assert.AreEqual(ImageSizeController.MaximumSize, resizer.Width, "Should be changed to maximum width."); Assert.AreEqual(ImageSizeController.MaximumSize, resizer.Height, "Height should be recalculated."); resizer.Height = ImageSizeController.MinimumSize - 5; Assert.AreEqual(ImageSizeController.MinimumSize, resizer.Width, "Width should be recalculated."); Assert.AreEqual(ImageSizeController.MinimumSize, resizer.Height, "Should be changed to minimum width height."); resizer.Height = ImageSizeController.MaximumSize + 5; Assert.AreEqual(ImageSizeController.MaximumSize, resizer.Width, "Width should be recalculated."); Assert.AreEqual(ImageSizeController.MaximumSize, resizer.Height, "Should be changed to maximum width height."); }
public void TestPaletteName() { var image = new CodedImage { Size = new Size(5, 5) }; var palette1 = new CodedPalette { Name = "Palette 1" }; var palette2 = new CodedPalette { Name = "Palette 2" }; var colorer = new ImageColorsController4Test(new ImageColorsManipulator(image), new[] { palette1, palette2 }); Assert.AreSame(palette1, colorer.SelectedPalette, "First palette should be selected by default."); Assert.AreEqual("Palette 1", colorer.PaletteName, "Name of current palette should be returned."); colorer.PaletteName = "Palette 2"; Assert.AreSame(palette2, colorer.SelectedPalette, "Second palette should be selected."); Assert.AreEqual("Palette 2", colorer.PaletteName, "Name of current palette should be returned."); colorer.PaletteName = "Palette 3"; Assert.AreSame(palette2, colorer.SelectedPalette, "Previous palette should remain selected."); Assert.AreEqual("Palette 2", colorer.PaletteName, "Name of current palette should be returned."); colorer.PaletteName = "pAlEtTe 1"; Assert.AreSame(palette1, colorer.SelectedPalette, "First palette should be selected ignoring characters case."); Assert.AreEqual("Palette 1", colorer.PaletteName, "Name of current palette should be returned."); }
public void TestCropRect() { var sourceImage = new CodedImage { Size = new Size(200, 150) }; var cropController = new ImageCropController(new ImageCropManipulator(sourceImage)); var visualZoomedCropController = new VisualZoomCropController(cropController, new Size(60, 50)); visualZoomedCropController.ZoomPercent = 100; Assert.AreEqual(100, visualZoomedCropController.ZoomPercent, "Precondition."); visualZoomedCropController.SetCropRectForTest(new Rectangle(40, 50, 60, 70)); Assert.AreEqual(new Rectangle(40, 50, 60, 70), cropController.CropRect); Assert.AreEqual(new Rectangle(40, 50, 60, 70), visualZoomedCropController.CropRect); visualZoomedCropController.ZoomPercent = 150; Assert.AreEqual(new Rectangle(40, 50, 60, 70), cropController.CropRect); Assert.AreEqual(new Rectangle(60, 75, 90, 105), visualZoomedCropController.CropRect, "Visual crop rect should be recalculated."); visualZoomedCropController.SetCropRectForTest(new Rectangle(30, 45, 60, 75)); Assert.AreEqual(new Rectangle(20, 30, 40, 50), cropController.CropRect); Assert.AreEqual(new Rectangle(30, 45, 60, 75), visualZoomedCropController.CropRect); visualZoomedCropController.ZoomPercent = 50; Assert.AreEqual(new Rectangle(20, 30, 40, 50), cropController.CropRect); Assert.AreEqual(new Rectangle(10, 15, 20, 25), visualZoomedCropController.CropRect, "Visual crop rect should be recalculated."); }
public void TestDoesntCallManipulationsWithoutChanges() { var image = new CodedImage { Size = new Size(5, 5) }; var colorer = new ImageColorsController4Test(new ImageColorsManipulator(image)); Assert.AreEqual(0, colorer.DitherLevel, "Default value"); Assert.IsFalse(colorer.EnsureBlackAndWhiteColors, "Default value"); Assert.AreEqual(30, colorer.MaxColorsCount, "Default value"); Assert.IsTrue(colorer.CallManipulationsCoreFired, "Manipulations should have been already executed for default options."); colorer.CallManipulationsCoreFired = false; colorer.DitherLevel = 0; Assert.IsFalse(colorer.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); colorer.DitherLevel = 1; Assert.IsTrue(colorer.CallManipulationsCoreFired, "Should call manipulations for changed dither level."); colorer.CallManipulationsCoreFired = false; colorer.EnsureBlackAndWhiteColors = false; Assert.IsFalse(colorer.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); colorer.EnsureBlackAndWhiteColors = true; Assert.IsTrue(colorer.CallManipulationsCoreFired, "Should call manipulations for changed ensure special colors."); colorer.CallManipulationsCoreFired = false; colorer.MaxColorsCount = 30; Assert.IsFalse(colorer.CallManipulationsCoreFired, "Should not call manipulations when there are no changes."); colorer.MaxColorsCount = 50; Assert.IsTrue(colorer.CallManipulationsCoreFired, "Should call manipulations for changed max colors count."); }
public void TestShift() { var sourceImage = new CodedImage { Size = new Size(200, 150) }; var cropController = new ImageCropController(new ImageCropManipulator(sourceImage)); var visualZoomedCropController = new VisualZoomCropController(cropController, new Size(60, 50)); using (visualZoomedCropController.SuspendUpdateVisualImage()) { visualZoomedCropController.ZoomPercent = 50; visualZoomedCropController.CropKind = ImageCropper.CropKind.Rectangle; visualZoomedCropController.SetCropRectForTest(new Rectangle(0, 0, 100, 75)); } visualZoomedCropController.OnTouched(new Point(20, 20)); visualZoomedCropController.OnShift(new Point(0, 10)); // Shift on distance (-20, -10) visualZoomedCropController.OnUntouched(new Point(0, 10)); AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(-10, -5), new Size(5, 10), new Rectangle(15, 15, 45, 30)); // Left-top AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(40, -5), new Size(5, 10), new Rectangle(10, 15, 55, 30)); // Right-top AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(-10, 35), new Size(5, 10), new Rectangle(15, 5, 45, 50)); // Left-bottom AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(40, 35), new Size(5, 10), new Rectangle(10, 5, 55, 50)); // Right-bottom AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(-10, 15), new Size(5, 10), new Rectangle(15, 5, 45, 40)); // Left AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(15, -5), new Size(5, 10), new Rectangle(10, 15, 50, 30)); // Top AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(40, 15), new Size(5, 10), new Rectangle(10, 5, 55, 40)); // Right AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(15, 35), new Size(5, 10), new Rectangle(10, 5, 50, 50)); // Bottom }
public void TestPixelColorChanged() { var image = new CodedImage { Size = new Size(2, 2), Palette = new CodedPalette { new CodedColor(0), new CodedColor(1) } }; image[0, 0] = new CodedColor(1); image[0, 1] = new CodedColor(1); image[1, 0] = new CodedColor(0); image[1, 1] = new CodedColor(0); var undoRedoProvider = new UndoRedoProvider(image); Assert.IsFalse(undoRedoProvider.CanUndo, "Precondition"); image[1, 1] = new CodedColor(1); Assert.IsTrue(undoRedoProvider.CanUndo); Assert.AreEqual(Ravlyk.SAE.Drawing.Properties.Resources.UndoRedoActionChangeCellColor, undoRedoProvider.UndoDescription); Assert.IsFalse(undoRedoProvider.CanRedo); Assert.AreEqual(new CodedColor(1), image[1, 1]); undoRedoProvider.Undo(); Assert.IsFalse(undoRedoProvider.CanUndo); Assert.IsTrue(undoRedoProvider.CanRedo); Assert.AreEqual(Ravlyk.SAE.Drawing.Properties.Resources.UndoRedoActionChangeCellColor, undoRedoProvider.RedoDescription); Assert.AreEqual(new CodedColor(0), image[1, 1]); undoRedoProvider.Redo(); Assert.IsTrue(undoRedoProvider.CanUndo); Assert.AreEqual(Ravlyk.SAE.Drawing.Properties.Resources.UndoRedoActionChangeCellColor, undoRedoProvider.UndoDescription); Assert.IsFalse(undoRedoProvider.CanRedo); Assert.AreEqual(new CodedColor(1), image[1, 1]); }