예제 #1
0
        private void Crop_Changed(object sender, EventArgs e)
        {
            RadioButton rb = sender as RadioButton;

            _croppingMode = (Cropping)rb.Tag;
            ShowCroppedText();
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Cropping"/> class.
 /// Copy Constructor
 /// </summary>
 /// <param name="croping">
 /// The croping.
 /// </param>
 public Cropping(Cropping croping)
 {
     this.Top = croping.Top;
     this.Bottom = croping.Bottom;
     this.Left = croping.Left;
     this.Right = croping.Right;
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Cropping"/> class.
 /// Copy Constructor
 /// </summary>
 /// <param name="croping">
 /// The croping.
 /// </param>
 public Cropping(Cropping croping)
 {
     this.Top    = croping.Top;
     this.Bottom = croping.Bottom;
     this.Left   = croping.Left;
     this.Right  = croping.Right;
 }
        public Cropping GetCropping()
        {
            Cropping cropping = new Cropping();
            UInt32   status   = OpenNIImporter.xnGetCropping(this.InternalObject, ref cropping);

            WrapperUtils.CheckStatus(status);
            return(cropping);
        }
예제 #5
0
        public void SameSourceAndDestSizeResultInMultiplicatorOf6()
        {
            var sourceSize = new Size(463, 600);
            var destSize   = new Size(180, 180);

            var multi = new Cropping().GetMultiplicator(sourceSize, destSize);

            Assert.Equal(0.39, multi, 2);
        }
예제 #6
0
        public override void ClearROI()
        {
            Cropping croppingROI = new Cropping();
            //roi.bEnabled = true;
            //roi.nXOffset = 1;
            //roi.nXSize = 640;
            //roi.nYOffset = 1;
            //roi.nYSize = 480;

            //ir.GetCroppingCap().SetCropping(ref roi);
        }
예제 #7
0
        /// <summary>
        /// Selects the Crop Option for the scanned file
        /// </summary>
        /// <param name="cropOption">crop optoin type to select(case sensitive)</param>
        public void SelectCropOption(Cropping cropOption)
        {
            OpenOptionsPanel();

            if (!_controlPanel.ScrollPressWait("#hpid-option-auto-crop", "#hpid-option-auto-crop-screen", TimeSpan.FromSeconds(5)))
            {
                throw new DeviceWorkflowException("Unable to select cropping option.");
            }

            _controlPanel.ScrollPress($"#hpid-auto-crop-selection-{cropOption.ToString().ToLower()}");

            Pacekeeper.Sync();
            _controlPanel.PressWait(".hp-button-done", ".hp-option-list");
        }
예제 #8
0
        public override Rectangle  SetROI(Rectangle newRoi)
        {
            Cropping croppingROI = new Cropping();

            //roi.bEnabled = true;
            //roi.nXOffset = 1;
            //roi.nXSize = 640;
            //roi.nYOffset = 1;
            //roi.nYSize = 480;

            //ir.GetCroppingCap().SetCropping(ref roi);

            roi = newRoi;
            return(roi);
        }
        private WebImage CropImage(WebImage image, int width, int height)
        {
            var    cropper = new Cropping();
            double multi   = cropper.GetMultiplicator(new Size(image.Width, image.Height), new Size(width, height));

            double fWidth  = image.Width * multi;
            double fHeight = image.Height * multi;

            image = image.Resize((int)fWidth, (int)fHeight, preserveAspectRatio: false);
            int iWidth  = image.Width;
            int iHeight = image.Height;
            int top     = Math.Max((iHeight - height) / 2, 0);
            int left    = Math.Max((iWidth - width) / 2, 0);
            int bottom  = Math.Max(iHeight - (height + top), 0);
            int right   = Math.Max(iWidth - (width + left), 0);

            return(image.Crop(top, left, bottom, right));
        }
예제 #10
0
 /// <summary>
 /// Aligns the specified string within a field of the desired width, cropping it if it doesn't fit, and expanding it otherwise.
 /// </summary>
 /// <param name="str">The string to align.</param>
 /// <param name="width">The width of the field in characters in which the string should be fitted.</param>
 /// <param name="alignment">The aligmnent that will be used for fitting the string in the field in case it is shorter than the specified field width.</param>
 /// <param name="cropping">The method that will be used for cropping if the string is too wide to fit in the specified width.</param>
 /// <param name="ellipsis">A string that will be inserted at the cropped side(s) of the string to denote that the string has been cropped.</param>
 /// <returns>
 /// A string exactly <paramref name="width"/> characters wide, containing the specified string <paramref name="str"/> fitted
 /// according to the parameters specified.
 /// </returns>
 /// <remarks>
 /// <para>If the string consists of several lines, each line will be aligned according to the specified parameters.</para>
 /// <para>The padding character used will be the normal white space character (' ').</para>
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception>
 /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception>
 /// <exception cref="ArgumentException"><paramref name="width"/> is less than the length of the specified <paramref name="ellipsis"/>, or, 
 /// the cropping specified is <see cref="Cropping.Both"/> and <paramref name="width"/> was less than <i>twice</i> the 
 /// length of the <paramref name="ellipsis"/></exception>
 public static string Align(string str, int width, Alignment alignment, Cropping cropping, string ellipsis)
 {
     return Align(str, width, alignment, cropping, ellipsis, ' ');
 }
예제 #11
0
 /// <summary>
 /// Selects the Crop Option for the scanned file
 /// </summary>
 /// <param name="selectedCropOption">crop optoin type to select(case sensitive)</param>
 void INetworkFolderJobOptions.SelectCropOption(Cropping selectedCropOption)
 {
     throw new NotImplementedException($"SelectCropOption with setting {selectedCropOption} feature is not implemented on SiriusUIv3 devices");
 }
예제 #12
0
        /// <summary>
        /// Aligns the specified string within a field of the desired width, cropping it if it doesn't fit, and expanding it otherwise.
        /// </summary>
        /// <param name="str">The string to align.</param>
        /// <param name="width">The width of the field in characters in which the string should be fitted.</param>
        /// <param name="alignment">The aligmnent that will be used for fitting the string in the field in case it is shorter than the specified field width.</param>
        /// <param name="cropping">The method that will be used for cropping if the string is too wide to fit in the specified width.</param>
        /// <param name="ellipsis">A string that will be inserted at the cropped side(s) of the string to denote that the string has been cropped.</param>
        /// <param name="padCharacter">The character that will be used for padding the string in case it is shorter than the specified field width.</param>
        /// <returns>
        /// A string exactly <paramref name="width"/> characters wide, containing the specified string <paramref name="str"/> fitted
        /// according to the parameters specified.
        /// </returns>
        /// <remarks>If the string consists of several lines, each line will be aligned according to the specified parameters.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception>
        /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception>
        /// <exception cref="ArgumentException"><paramref name="width"/> is less than the length of the specified <paramref name="ellipsis"/>, or,
        /// the cropping specified is <see cref="Cropping.Both"/> and <paramref name="width"/> was less than <i>twice</i> the
        /// length of the <paramref name="ellipsis"/></exception>
        public static string Align(string str, int width, Alignment alignment, Cropping cropping, string ellipsis, char padCharacter)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width");
            }

            if (ellipsis != null)
            {
                if (cropping != Cropping.Both && width < ellipsis.Length)
                {
                    throw new ArgumentException("width must not be less than the length of ellipsis");
                }
                else if (cropping == Cropping.Both && width < ellipsis.Length * 2)
                {
                    throw new ArgumentException("width must not be less than twice the length of the ellipsis when cropping is set to Both");
                }
            }

            IList <string> lines  = SplitAtLineBreaks(str);
            StringBuilder  result = new StringBuilder();

            for (int j = 0; j < lines.Count; j++)
            {
                if (j != 0)
                {
                    result.Append(Environment.NewLine);
                }

                string s      = lines[j];
                int    length = s.Length;
                if (length <= width)
                {
                    switch (alignment)
                    {
                    case Alignment.Left:
                        result.Append(s);
                        result.Append(padCharacter, width - length);
                        continue;

                    case Alignment.Right:
                        result.Append(padCharacter, width - length);
                        result.Append(s);
                        continue;

                    case Alignment.Center:
                        result.Append(padCharacter, (width - length) / 2);
                        result.Append(s);
                        result.Append(padCharacter, (width - length) - ((width - length) / 2));
                        continue;

                    case Alignment.Justified:
                        string trimmed = s.Trim();
                        length = trimmed.Length;

                        int spaceCount = GetWordCount(s) - 1;

                        Debug.Assert(spaceCount >= 0);

                        if (spaceCount == 0) // string only contain a single word
                        {
                            result.Append(trimmed);
                            result.Append(padCharacter, width - length);
                        }

                        StringBuilder localResult    = new StringBuilder();
                        int           remainingSpace = width - length;
                        bool          readingWord    = true;

                        for (int i = 0; i < length; i++)
                        {
                            if (!char.IsWhiteSpace(trimmed[i]))
                            {
                                readingWord = true;
                                localResult.Append(trimmed[i]);
                            }
                            else if (readingWord)
                            {
                                localResult.Append(trimmed[i]);
                                int spacesToAdd = remainingSpace / spaceCount--;
                                remainingSpace -= spacesToAdd;
                                localResult.Append(padCharacter, spacesToAdd);
                                readingWord = false;
                            }
                        }
                        result.Append(localResult);
                        continue;

                    default:
                        throw new InvalidOperationException("Internal error; Unimplemented Justification specified");
                    }
                }

                // The string is too long and need to be cropped
                switch (cropping)
                {
                case Cropping.Right:
                    return(s.Substring(0, width - ellipsis.Length) + ellipsis);

                case Cropping.Left:
                    return(ellipsis + s.Substring(length - width + ellipsis.Length));

                case Cropping.Both:
                    return(ellipsis + s.Substring(length / 2 - width / 2, width - ellipsis.Length * 2) + ellipsis);

                default:
                    break;
                }
            }
            return(result.ToString());
        }
예제 #13
0
 /// <summary>
 /// Aligns the specified string within a field of the desired width, cropping it if it doesn't fit, and expanding it otherwise.
 /// </summary>
 /// <param name="str">The string to align.</param>
 /// <param name="width">The width of the field in characters in which the string should be fitted.</param>
 /// <param name="alignment">The aligmnent that will be used for fitting the string in the field in case it is shorter than the specified field width.</param>
 /// <param name="cropping">The method that will be used for cropping if the string is too wide to fit in the specified width.</param>
 /// <param name="ellipsis">A string that will be inserted at the cropped side(s) of the string to denote that the string has been cropped.</param>
 /// <returns>
 /// A string exactly <paramref name="width"/> characters wide, containing the specified string <paramref name="str"/> fitted
 /// according to the parameters specified.
 /// </returns>
 /// <remarks>
 /// <para>If the string consists of several lines, each line will be aligned according to the specified parameters.</para>
 /// <para>The padding character used will be the normal white space character (' ').</para>
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception>
 /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception>
 /// <exception cref="ArgumentException"><paramref name="width"/> is less than the length of the specified <paramref name="ellipsis"/>, or,
 /// the cropping specified is <see cref="Cropping.Both"/> and <paramref name="width"/> was less than <i>twice</i> the
 /// length of the <paramref name="ellipsis"/></exception>
 public static string Align(string str, int width, Alignment alignment, Cropping cropping, string ellipsis)
 {
     return(Align(str, width, alignment, cropping, ellipsis, ' '));
 }
예제 #14
0
 /// <summary>
 /// Aligns the specified string within a field of the desired width, cropping it if it doesn't fit, and expanding it otherwise.
 /// </summary>
 /// <param name="str">The string to align.</param>
 /// <param name="width">The width of the field in characters in which the string should be fitted.</param>
 /// <param name="alignment">The aligmnent that will be used for fitting the string in the field in case it is shorter than the specified field width.</param>
 /// <param name="cropping">The method that will be used for cropping if the string is too wide to fit in the specified width.</param>
 /// <returns>
 /// A string exactly <paramref name="width"/> characters wide, containing the specified string <paramref name="str"/> fitted
 /// according to the parameters specified.
 /// </returns>
 /// <remarks>
 /// <para>If the string consists of several lines, each line will be aligned according to the specified parameters.</para>
 /// <para>The padding character used will be the normal white space character (' '), and the ellipsis used will be the
 /// string <b>"..."</b>.</para>
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception>
 /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception>
 /// <exception cref="ArgumentException"><paramref name="width"/> is less than the length of the specified <paramref name="ellipsis"/>, or,
 /// the cropping specified is <see cref="Cropping.Both"/> and <paramref name="width"/> was less than <i>twice</i> the
 /// length of the <paramref name="ellipsis"/></exception>
 public static string Align(string str, int width, Alignment alignment, Cropping cropping)
 {
     return(Align(str, width, alignment, cropping, "..."));
 }
예제 #15
0
 /// <summary>
 /// Selects the Crop Option for the scanned file
 /// </summary>
 /// <param name="cropOption">crop optoin type to select(case sensitive)</param>
 public void SelectCropOption(Cropping cropOption)
 {
     throw new NotImplementedException($"SelectCropOption with setting {cropOption} feature is not implemented on JediWindjammer devices");
 }
예제 #16
0
        public void SetCropping(ref Cropping cropping)
        {
            UInt32 status = OpenNIImporter.xnSetCropping(this.InternalObject, ref cropping);

            WrapperUtils.CheckStatus(status);
        }
예제 #17
0
        /// <summary>
        /// Aligns the specified string within a field of the desired width, cropping it if it doesn't fit, and expanding it otherwise.
        /// </summary>
        /// <param name="str">The string to align.</param>
        /// <param name="width">The width of the field in characters in which the string should be fitted.</param>
        /// <param name="alignment">The aligmnent that will be used for fitting the string in the field in case it is shorter than the specified field width.</param>
        /// <param name="cropping">The method that will be used for cropping if the string is too wide to fit in the specified width.</param>
        /// <param name="ellipsis">A string that will be inserted at the cropped side(s) of the string to denote that the string has been cropped.</param>
        /// <param name="padCharacter">The character that will be used for padding the string in case it is shorter than the specified field width.</param>
        /// <returns>
        /// A string exactly <paramref name="width"/> characters wide, containing the specified string <paramref name="str"/> fitted
        /// according to the parameters specified.
        /// </returns>
        /// <remarks>If the string consists of several lines, each line will be aligned according to the specified parameters.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception>
        /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception>
        /// <exception cref="ArgumentException"><paramref name="width"/> is less than the length of the specified <paramref name="ellipsis"/>, or, 
        /// the cropping specified is <see cref="Cropping.Both"/> and <paramref name="width"/> was less than <i>twice</i> the 
        /// length of the <paramref name="ellipsis"/></exception>
        public static string Align(string str, int width, Alignment alignment, Cropping cropping, string ellipsis, char padCharacter)
        {
            if (str == null)
                throw new ArgumentNullException("str");

            if (width <= 0)
                throw new ArgumentOutOfRangeException("width");

            if (ellipsis != null)
            {
                if (cropping != Cropping.Both && width < ellipsis.Length)
                    throw new ArgumentException("width must not be less than the length of ellipsis");
                else if (cropping == Cropping.Both && width < ellipsis.Length * 2)
                    throw new ArgumentException("width must not be less than twice the length of the ellipsis when cropping is set to Both");
            }

            IIndexed<string> lines = SplitAtLineBreaks(str);
            StringBuilder result = new StringBuilder();

            for (int j = 0; j < lines.Count; j++)
            {
                if (j != 0)
                    result.Append(Environment.NewLine);

                string s = lines[j];
                int length = s.Length;
                if (length <= width)
                {
                    switch (alignment)
                    {
                        case Alignment.Left:
                            result.Append(s);
                            result.Append(padCharacter, width - length);
                            continue;
                        case Alignment.Right:
                            result.Append(padCharacter, width - length);
                            result.Append(s);
                            continue;
                        case Alignment.Center:
                            result.Append(padCharacter, (width - length) / 2);
                            result.Append(s);
                            result.Append(padCharacter, (width - length) - ((width - length) / 2));
                            continue;                            
                        case Alignment.Justified:
                            string trimmed = s.Trim();
                            length = trimmed.Length;

                            int spaceCount = GetWordCount(s) - 1;

                            Debug.Assert(spaceCount >= 0);

                            if (spaceCount == 0) // string only contain a single word
                            {
                                result.Append(trimmed);
                                result.Append(padCharacter, width - length);
                            }

                            StringBuilder localResult = new StringBuilder();
                            int remainingSpace = width - length;
                            bool readingWord = true;

                            for (int i = 0; i < length; i++)
                            {
                                if (!char.IsWhiteSpace(trimmed[i]))
                                {
                                    readingWord = true;
                                    localResult.Append(trimmed[i]);
                                }
                                else if (readingWord)
                                {
                                    localResult.Append(trimmed[i]);
                                    int spacesToAdd = remainingSpace / spaceCount--;
                                    remainingSpace -= spacesToAdd;
                                    localResult.Append(padCharacter, spacesToAdd);
                                    readingWord = false;

                                }
                            }
                            result.Append(localResult);
                            continue;
                        default:
                            throw new InvalidOperationException("Internal error; Unimplemented Justification specified");
                    }
                }

                // The string is too long and need to be cropped
                switch (cropping)
                {
                    case Cropping.Right:
                        return s.Substring(0, width - ellipsis.Length) + ellipsis;
                    case Cropping.Left:
                        return ellipsis + s.Substring(length - width + ellipsis.Length);
                    case Cropping.Both:
                        return ellipsis + s.Substring(length / 2 - width / 2, width - ellipsis.Length * 2) + ellipsis;
                    default:
                        break;
                }
            }
            return result.ToString();
        }
예제 #18
0
 /// <summary>
 /// Aligns the specified string within a field of the desired width, cropping it if it doesn't fit, and expanding it otherwise.
 /// </summary>
 /// <param name="str">The string to align.</param>
 /// <param name="width">The width of the field in characters in which the string should be fitted.</param>
 /// <param name="alignment">The aligmnent that will be used for fitting the string in the field in case it is shorter than the specified field width.</param>
 /// <param name="cropping">The method that will be used for cropping if the string is too wide to fit in the specified width.</param>
 /// <returns>
 /// A string exactly <paramref name="width"/> characters wide, containing the specified string <paramref name="str"/> fitted
 /// according to the parameters specified.
 /// </returns>
 /// <remarks>
 /// <para>If the string consists of several lines, each line will be aligned according to the specified parameters.</para>
 /// <para>The padding character used will be the normal white space character (' '), and the ellipsis used will be the
 /// string <b>"..."</b>.</para>
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception>
 /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception>
 /// <exception cref="ArgumentException"><paramref name="width"/> is less than the length of the specified <paramref name="ellipsis"/>, or, 
 /// the cropping specified is <see cref="Cropping.Both"/> and <paramref name="width"/> was less than <i>twice</i> the 
 /// length of the <paramref name="ellipsis"/></exception>
 public static string Align(string str, int width, Alignment alignment, Cropping cropping)
 {
     return Align(str, width, alignment, cropping, "...");
 }
 /// <summary>
 /// Selects the Crop Option for the scanned file
 /// </summary>
 /// <param name="selectedCropOption">crop optoin type to select(case sensitive)</param>
 void IEmailJobOptions.SelectCropOption(Cropping selectedCropOption)
 {
     throw new NotImplementedException($"SelectCropOption with setting {selectedCropOption} feature is not implemented on PhoenixMagicFrame devices");
 }