public override List <object> Deserealize(IPlugin plugin)
        {
            string TextString;

            if (plugin == null)
            {
                using (StreamReader fStream = new StreamReader(FilePath))
                {
                    TextString = fStream.ReadToEnd();
                }
            }
            else
            {
                TextString = plugin.PreProcessString(FilePath);
            }

            var ObjectList = new List <object>();

            string[] LineList = TextString.Split('\n');
            foreach (string line in LineList)
            {
                if (line != "")
                {
                    object obj = StrToObject(line);
                    ObjectList.Add(obj);
                }
            }
            return(ObjectList);
        }
Пример #2
0
        public static void GetByteCount_Span_MatchesEncodingByteCount()
        {
            const string TextString = "hello world";
            Encoding     e          = Encoding.UTF8;

            Assert.Equal(e.GetByteCount(TextString), e.GetEncoder().GetByteCount(TextString.AsSpan(), flush: true));
        }
Пример #3
0
        // draw the tab  and the currently selected tabs items
        public void Draw(SpriteBatch sb)
        {
            foreach (UiTab Tab in tabList)
            {
                /*if (Tab.tabNumber == currentSelection)
                 *  Tab.tabButton.TextBoxColour =;
                 * else*/
                Tab.Draw(sb);
            }

            foreach (UiButton button in tabList[currentSelection].ButtonList)
            {
                button.DrawButton(sb);
            }

            foreach (UiTextBox textBox in tabList[currentSelection].TextBoxList)
            {
                textBox.Draw(sb);
            }

            foreach (UiTextString TextString in tabList[currentSelection].StringList)
            {
                TextString.DrawString(sb);
            }
        }
Пример #4
0
        private void RemoveQuotesFromString_Execute(ExecuteEventArgs ea)
        {
            TextString TheString = CodeRush.Source.ActiveString;
            var        TheRange  = TheString.Range;

            CodeRush.Documents.ActiveTextDocument.SetText(new SourceRange(TheRange.Start.OffsetPoint(0, -1), TheRange.End.OffsetPoint(0, 1)), (string)TheString.PrimitiveExpression.PrimitiveValue);
        }
Пример #5
0
        // Update pressed keys
        private void UpdateInput()
        {
            OldKeyboardState     = CurrentKeyboardState;
            CurrentKeyboardState = Keyboard.GetState();

            Keys[] PressedKeys;
            PressedKeys = CurrentKeyboardState.GetPressedKeys();

            foreach (Keys Key in PressedKeys)
            {
                if (OldKeyboardState.IsKeyUp(Key))
                {
                    if (Key == Keys.Back && TextString.Length > 0) // backspace
                    {
                        TextString = TextString.Remove(TextString.Length - 1, 1);
                    }
                    else if (TextString.Length > 16)
                    {
                        break;
                    }
                    else if (Key == Keys.Space)
                    {
                        TextString = TextString.Insert(TextString.Length, " ");
                    }
                    else if (Key == Keys.OemQuotes) // apostrophe
                    {
                        TextString = TextString.Insert(TextString.Length, "\'");
                    }
                    else if (Key.ToString().Length == 1)
                    {
                        TextString += Key.ToString();
                    }
                }
            }
        }
Пример #6
0
        /**
         * <summary>Processes the text strings matching the specified filter.</summary>
         * <param name="textStrings">Text strings to filter.</param>
         * <param name="filter">Matching processor.</param>
         */
        public void Filter(
            IDictionary <RectangleF?, IList <ITextString> > textStrings,
            IIntervalFilter filter
            )
        {
            IEnumerator <IList <ITextString> > textStringsIterator = textStrings.Values.GetEnumerator();

            if (!textStringsIterator.MoveNext())
            {
                return;
            }

            IEnumerator <ITextString> areaTextStringsIterator = textStringsIterator.Current.GetEnumerator();

            if (!areaTextStringsIterator.MoveNext())
            {
                return;
            }

            IList <TextChar> textChars = areaTextStringsIterator.Current.TextChars;
            int baseTextCharIndex      = 0;
            int textCharIndex          = 0;

            while (filter.MoveNext())
            {
                Interval <int> interval = filter.Current;
                TextString     match    = new TextString();
                {
                    int matchStartIndex = interval.Low;
                    int matchEndIndex   = interval.High;
                    while (matchStartIndex > baseTextCharIndex + textChars.Count)
                    {
                        baseTextCharIndex += textChars.Count;
                        if (!areaTextStringsIterator.MoveNext())
                        {
                            areaTextStringsIterator = textStringsIterator.Current.GetEnumerator(); areaTextStringsIterator.MoveNext();
                        }
                        textChars = areaTextStringsIterator.Current.TextChars;
                    }
                    textCharIndex = matchStartIndex - baseTextCharIndex;

                    while (baseTextCharIndex + textCharIndex < matchEndIndex)
                    {
                        if (textCharIndex == textChars.Count)
                        {
                            baseTextCharIndex += textChars.Count;
                            if (!areaTextStringsIterator.MoveNext())
                            {
                                areaTextStringsIterator = textStringsIterator.Current.GetEnumerator(); areaTextStringsIterator.MoveNext();
                            }
                            textChars     = areaTextStringsIterator.Current.TextChars;
                            textCharIndex = 0;
                        }
                        match.TextChars.Add(textChars[textCharIndex++]);
                    }
                }
                filter.Process(interval, match);
            }
        }
Пример #7
0
        public static void GetBytes_Span_MatchesEncodingGetBytes()
        {
            const string TextString = "hello world";
            Encoding     e          = Encoding.UTF8;

            byte[] bytes = new byte[e.GetByteCount(TextString)];
            Assert.Equal(bytes.Length, e.GetEncoder().GetBytes(TextString.AsSpan(), bytes, flush: true));
            Assert.Equal(e.GetBytes(TextString), bytes);
        }
        protected internal override void arrangeCharacters(int width, int height, TextString ts)
        {
            double x = leftMargin;

            foreach (TextCharacter tc in ts.Characters)
            {
                double y = topMargin + (height + tc.Ascent * 0.7) / 2;
                tc.X = x;
                tc.Y = y;
                x   += tc.Width;
            }
        }
Пример #9
0
		private static void CurrentChangedCallback( DependencyObject d, DependencyPropertyChangedEventArgs e ) {

			TextString msg_pair = (TextString)e.NewValue;
			if( string.IsNullOrEmpty( msg_pair.Text ) ) {
				( d as FeedbackList ).ClearList();
			}
			FeedbackList fb = d as FeedbackList;
			fb.AddText( msg_pair );

			// need to reset the value to allow multiple identical messages.
			d.SetCurrentValue( CurrentProperty, CurrentProperty.DefaultMetadata.DefaultValue );

		}
        protected internal override void arrangeCharacters(int width, int height, TextString ts)
        {
            double widthRemaining = (width - ts.Width - leftMargin - rightMargin) / ts.Characters.Count;
            double x = leftMargin + widthRemaining / 2;

            height -= topMargin + bottomMargin;
            foreach (TextCharacter tc in ts.Characters)
            {
                double y = topMargin + (height + tc.Ascent * 0.7) / 2;
                tc.X = x;
                tc.Y = y;
                x   += tc.Width + widthRemaining;
            }
        }
Пример #11
0
        public void TextStringSplitNoString2Test()
        {
            TextString target = new TextString();

            target.String1     = "The  quick  brown  fox  jumped  over  the  lazy  dog.";
            target.String2     = null;
            target.TaskAction  = "Split";
            target.BuildEngine = new MockBuildEngine();

            bool result = target.Execute();

            Assert.IsFalse(result);

            target.String2 = string.Empty;
            result         = target.Execute();
            Assert.IsFalse(result);
        }
Пример #12
0
        public void TextStringSplitNoString1Test()
        {
            TextString target = new TextString();

            target.String1     = null;
            target.String2     = " ";
            target.TaskAction  = "Split";
            target.BuildEngine = new MockBuildEngine();

            bool result = target.Execute();

            Assert.IsFalse(result);

            target.String1 = string.Empty;
            result         = target.Execute();
            Assert.IsFalse(result);
        }
Пример #13
0
    public void UpdateInput()
    {
        if (!this.IsFinished)
        {
            oldKeyboardState     = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            Keys[] pressedKeys;
            pressedKeys = currentKeyboardState.GetPressedKeys();

            foreach (Keys key in pressedKeys)
            {
                if (oldKeyboardState.IsKeyUp(key))
                {
                    if (key == Keys.Back && TextString.Length > 0)
                    {
                        TextString = TextString.Remove(TextString.Length - 1, 1);
                    }
                    else if (key == Keys.Space)
                    {
                        TextString = TextString.Insert(TextString.Length, " ");
                    }
                    else if (key == Keys.Enter)
                    {
                        this.IsFinished = true;
                    }
                    else
                    {
                        string keyString   = key.ToString();
                        bool   isUpperCase = ((Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock) &&
                                               (!currentKeyboardState.IsKeyDown(Keys.RightShift) &&
                                                !currentKeyboardState.IsKeyDown(Keys.LeftShift))) ||
                                              (!Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock) &&
                                               (currentKeyboardState.IsKeyDown(Keys.RightShift) ||
                                                currentKeyboardState.IsKeyDown(Keys.LeftShift))));

                        if (keyString.Length == 1)
                        {
                            TextString += isUpperCase ? keyString.ToUpper() : keyString.ToLower();
                        }
                    }
                }
            }
        }
    }
Пример #14
0
        /**
         * <summary>Gets the text strings matching the specified areas.</summary>
         * <param name="textStrings">Text strings to filter.</param>
         * <param name="areas">Graphic areas which text strings have to be matched to.</param>
         */
        public IDictionary <RectangleF?, IList <ITextString> > Filter(
            IList <ITextString> textStrings,
            params RectangleF[] areas
            )
        {
            IDictionary <RectangleF?, IList <ITextString> > filteredAreasTextStrings = new Dictionary <RectangleF?, IList <ITextString> >();

            foreach (RectangleF area in areas)
            {
                IList <ITextString> filteredAreaTextStrings = new List <ITextString>();
                filteredAreasTextStrings[area] = filteredAreaTextStrings;
                RectangleF toleratedArea = (areaTolerance != 0
          ? new RectangleF(
                                                area.X - areaTolerance,
                                                area.Y - areaTolerance,
                                                area.Width + areaTolerance * 2,
                                                area.Height + areaTolerance * 2
                                                )
          : area);
                foreach (ITextString textString in textStrings)
                {
                    RectangleF?textStringBox = textString.Box;
                    if (toleratedArea.IntersectsWith(textStringBox.Value))
                    {
                        TextString      filteredTextString      = new TextString();
                        List <TextChar> filteredTextStringChars = filteredTextString.TextChars;
                        foreach (TextChar textChar in textString.TextChars)
                        {
                            RectangleF textCharBox = textChar.Box;
                            if ((areaMode == AreaModeEnum.Containment && toleratedArea.Contains(textCharBox)) ||
                                (areaMode == AreaModeEnum.Intersection && toleratedArea.IntersectsWith(textCharBox)))
                            {
                                filteredTextStringChars.Add(textChar);
                            }
                        }
                        if (filteredTextStringChars.Count > 0)
                        {
                            filteredAreaTextStrings.Add(filteredTextString);
                        }
                    }
                }
            }
            return(filteredAreasTextStrings);
        }
Пример #15
0
 public Boolean AddFile( // for HeaderString and HeaderBytes
     String name,
     TypeIdentifier typeID,
     String headerString,
     Int32 byteOffset,
     String imageKey,
     String tag
     )
 {
     Byte[] headerBytes;
     if (typeID == TypeIdentifier.HeaderString)
     {
         headerBytes = TextString.ToByte(headerString);
     }
     else
     {
         headerBytes = Hex.ToBytes(headerString);
     }
     return(Add(name, iPhone.FileTypes.File, typeID, null, headerBytes, byteOffset, imageKey, tag));
 }
 public void PrintSubStringsSmall(ushort[] char_labels, TextString ts, int margin)
 {
     bool[,] stringimg = new bool[ts.bbx.Height + margin, ts.bbx.Width + margin];
     for (int i = 0; i < ts.char_list.Count; i++)
     {
         for (int xx = ts.bbx.X; xx < ts.bbx.X + ts.bbx.Width; xx++)
         {
             for (int yy = ts.bbx.Y; yy < ts.bbx.Y + ts.bbx.Height; yy++)
             {
                 if (char_labels[yy * width + xx] == ts.char_list[i].pixel_id)
                 {
                     stringimg[yy - ts.bbx.Y + margin / 2, xx - ts.bbx.X + margin / 2] = true;
                 }
             }
         }
     }
     if (ts.char_list.Count > 0)
     {
         ts.srcimg = ImageUtils.ArrayBool2DToBitmap(stringimg);
     }
 }
Пример #17
0
        public void TextEntered(TextEventArgs e)
        {
            if (HasFocus)
            {
                switch (e.Unicode[0])
                {
                case '\b':
                    if (TextString.Length > 0)
                    {
                        TextString = TextString.Remove(TextString.Length - 1, 1);
                    }
                    return;

                default:
                    if (CheckLength(e.Unicode))
                    {
                        TextString += e.Unicode;
                    }
                    break;
                }
            }
        }
Пример #18
0
        public static void Convert_Span_MatchesGetBytes()
        {
            const string TextString = "hello world";
            Encoding     encoding   = Encoding.UTF8;
            Encoder      encoder    = encoding.GetEncoder();

            byte[] bytes;

            bytes = new byte[encoding.GetByteCount(TextString)];
            encoder.Convert(TextString.AsSpan(), bytes.AsSpan(0, 2), true, out int charsUsed, out int bytesUsed, out bool completed);
            Assert.Equal(encoding.GetBytes(TextString).AsSpan(0, 2).ToArray(), bytes.AsSpan(0, 2).ToArray());
            Assert.Equal(2, charsUsed);
            Assert.Equal(2, bytesUsed);
            Assert.False(completed);

            bytes = new byte[encoding.GetByteCount(TextString)];
            encoder.Convert(TextString.AsSpan(), bytes, true, out charsUsed, out bytesUsed, out completed);
            Assert.Equal(encoding.GetBytes(TextString), bytes);
            Assert.Equal(TextString.Length, charsUsed);
            Assert.Equal(bytes.Length, bytesUsed);
            Assert.True(completed);
        }
Пример #19
0
        public void TextStringSplitWithSelectedIndexTest()
        {
            var input     = "The  quick  brown  fox  jumped  over  the  lazy  dog.";
            var separator = " ";

            string[] expected = input.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);

            TextString target = new TextString();

            target.String1     = input;
            target.String2     = separator;
            target.TaskAction  = "Split";
            target.StartIndex  = 2;
            target.BuildEngine = new MockBuildEngine();

            bool result = target.Execute();

            Assert.IsTrue(result);
            Assert.IsNotNull(target.Strings);
            Assert.AreEqual(expected.Length, target.Strings.Length);
            Assert.AreEqual(0, expected.Except(target.Strings.Select(x => x.ItemSpec)).Count());
            Assert.AreEqual(expected[target.StartIndex], target.NewString);
        }
Пример #20
0
        public ItemProperty FindItem(String fullPath)
        {
            /*Have to account for these:
             * FileName,
             * Extension,
             * FullPath,
             * FileType,
             * HeaderBytes,
             * HeaderString,
             * ExtHeadBytes, // Extension First, then Header
             * ExtHeadString
             */
            /* I need to lay out the approach here...
             * When we read a folder, we get back a list of all the folder entries,
             * including the current / parent folder pointers.
             *
             * I could break them up into FindFile / Folder / Device, but
             * I may use the same criteria to locate them
             * What's interesting with this particular approach is that the FIND
             * function doesn't specify what to look for. We literally scan the rules
             * and stop with the first MATCH.
             *
             * Now since we store the FileType of each ItemProperty entry, we need to
             * perform the first match on that attribute of the passed file.
             * So FileType is the first piece of information we need.
             */
            // Set variables to store whether we've already gathered a particular piece of info
            String  fileName   = null;
            Boolean _fileName  = false;
            String  extension  = null;
            Boolean _extension = false;

            ItemProperty returnItem = null;

            iPhone.FileTypes fileType = phone.FileType(fullPath);
            foreach (ItemProperty item in items)
            {
                if (fileType == item.Type)
                {
                    switch (item.Identifier)
                    {
                    case TypeIdentifier.FileType:
                        returnItem = item;
                        break;

                    case TypeIdentifier.FullPath:
                        if (item.FileInfoText.Equals(fullPath.ToLower()))
                        {
                            returnItem = item;
                        }
                        break;

                    case TypeIdentifier.FileName:
                        if (!_fileName)
                        {
                            fileName  = fullPath.Substring(fullPath.LastIndexOf("/") + 1).ToLower();
                            _fileName = true;
                        }
                        if (item.FileInfoText.Equals(fileName))
                        {
                            returnItem = item;
                        }
                        break;

                    case TypeIdentifier.Extension:
                        if (!_extension)
                        {
                            extension  = TextString.GetFileExtension(fullPath);
                            _extension = true;
                        }
                        if (extension == item.FileInfoText)
                        {
                            returnItem = item;
                        }
                        break;

                    case TypeIdentifier.ExtHeadString:
                    case TypeIdentifier.ExtHeadBytes:
                        if (!_extension)
                        {
                            extension  = TextString.GetFileExtension(fullPath);
                            _extension = true;
                        }
                        if (extension == item.FileInfoText)
                        {
                            Byte[] buffer = GetHeaderBytes(fullPath, item.ByteOffset, item.Header.Length);
                            if (buffer == item.Header)
                            {
                                returnItem = item;
                            }
                        }
                        break;

                    case TypeIdentifier.HeaderBytes:
                    case TypeIdentifier.HeaderString:
                        Byte[] fileBuffer = GetHeaderBytes(fullPath, item.ByteOffset, item.Header.Length);
                        if (fileBuffer == item.Header)
                        {
                            returnItem = item;
                        }
                        break;
                    }
                }
                if (returnItem != null)
                {
                    break;
                }
            }
            return(returnItem);
        }
        public void AddTextString(TextString dstString)
        {
            Update(ref dstString);
            List <int> insert_idx_list = new List <int>();// insert = -1;

            int[] matched_idx_array = new int[dstString.char_list.Count];
            for (int i = 0; i < matched_idx_array.Length; i++)
            {
                matched_idx_array[i] = -1;
            }
            int[] matched_char_blob_count = new int [text_string_list.Count];
            for (int i = 0; i < text_string_list.Count; i++)
            {
                TextString srcString = text_string_list[i];
                for (int x = 0; x < srcString.char_list.Count; x++)
                {
                    for (int y = 0; y < dstString.char_list.Count; y++)
                    {
                        if (Distance(srcString.char_list[x].mass_center, dstString.char_list[y].mass_center) < 3)
                        {
                            matched_idx_array[y] = i;
                            matched_char_blob_count[i]++;
                        }
                    }
                    //if(insert!=-1)
                    //break;
                }
            }
            int max_matched     = 0;
            int max_matched_idx = -1;

            for (int i = 0; i < matched_char_blob_count.Length; i++)
            {
                if (matched_char_blob_count[i] > max_matched)
                {
                    max_matched     = matched_char_blob_count[i];
                    max_matched_idx = i;
                }
            }
            int insert = max_matched_idx;

            if (insert == -1)
            {
                text_string_list.Add(dstString);
            }
            else
            {
                List <int> remove_string_list = new List <int>();
                for (int i = 0; i < matched_idx_array.Length; i++)
                {
                    if (matched_idx_array[i] != -1 && matched_idx_array[i] != insert)
                    {
                        remove_string_list.Add(i);
                    }
                }
                Point p1 = new Point(text_string_list[insert].bbx.X, text_string_list[insert].bbx.Y);
                Point p2 = new Point(dstString.bbx.X, dstString.bbx.Y);
                for (int c = 0; c < dstString.char_list.Count; c++)
                {
                    text_string_list[insert].AddChar(dstString.char_list[c]);
                }

                Bitmap   newimg1 = new Bitmap(text_string_list[insert].bbx.Width, text_string_list[insert].bbx.Height);
                Bitmap   newimg2 = new Bitmap(text_string_list[insert].bbx.Width, text_string_list[insert].bbx.Height);
                Graphics g1      = Graphics.FromImage(newimg1);
                g1.Clear(Color.White);
                g1.DrawImage(text_string_list[insert].srcimg,
                             p1.X - text_string_list[insert].bbx.X,
                             p1.Y - text_string_list[insert].bbx.Y);

                Graphics g2 = Graphics.FromImage(newimg2);
                g2.Clear(Color.White);
                g2.DrawImage(dstString.srcimg,
                             p2.X - text_string_list[insert].bbx.X,
                             p2.Y - text_string_list[insert].bbx.Y);
                g1.Dispose(); g2.Dispose();

                //ASHISH
                newimg1 = ImageUtils.GetIntersection(newimg1, newimg2);

                text_string_list[insert].srcimg = newimg1;

                //for (int i = 0; i < remove_string_list.Count; i++)
                //{

                //}
            }
        }
Пример #22
0
 public void FindElementsByPartialTextTest()
 {
     _element = Browser.SeleniumFind.ElementByPartialText(TextString.Substring(2));
 }
Пример #23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            var      UserStringArray       = TextFieldString.ToCharArray();
            var      AnswerStringArray     = TextString.ToCharArray();
            int      Len_UserStringArray   = UserStringArray.Length;
            int      Len_AnswerStringArray = AnswerStringArray.Length;
            int      i        = 0;
            float    pos_left = 0;

            g.Clear(BackColor);
            if (Len_UserStringArray == 0 && Len_AnswerStringArray == 0)
            {
                return;
            }
            string temp_str = string.Empty;

            while (true)
            {
                #region char using GDI+
                //char chr = AnswerStringArray[i];
                //var size = GetStringWidth(chr.ToString());
                //if (DrawNextCharHint && i == Len_UserStringArray)
                //    g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(Color.Lime), new PointF(pos_left, 0));
                //else if (i > Len_UserStringArray || (!DrawNextCharHint && i >= Len_UserStringArray))
                //    g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(ForeColor), new PointF(pos_left, 0));
                //else
                //{
                //    if (AnswerStringArray[i] == UserStringArray[i])
                //        g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(CorrectForeColor), new PointF(pos_left, 0));
                //    else
                //        g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(ErrorForeColor), new PointF(pos_left, 0));
                //}
                //pos_left += size.Width;
                //++i;
                //if (i >= Len_AnswerStringArray)
                //    break;
                #endregion

                #region string using GDI+
                char chr = AnswerStringArray[i];
                temp_str += chr;
                var sizeChr = GetStringWidth(chr.ToString());
                var sizeStr = GetStringWidth(temp_str);
                pos_left = sizeStr.Width - sizeChr.Width;
                if (DrawNextCharHint && i == Len_UserStringArray)
                {
                    g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(Color.Lime), new PointF(pos_left, 0));
                }
                else if (i > Len_UserStringArray || (!DrawNextCharHint && i >= Len_UserStringArray))
                {
                    g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(ForeColor), new PointF(pos_left, 0));
                }
                else
                {
                    if (AnswerStringArray[i] == UserStringArray[i])
                    {
                        g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(CorrectForeColor), new PointF(pos_left, 0));
                    }
                    else
                    {
                        g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(ErrorForeColor), new PointF(pos_left, 0));
                    }
                }
                ++i;
                if (i >= Len_AnswerStringArray)
                {
                    break;
                }
                #endregion

                #region char using GDI
                //char chr = AnswerStringArray[i];
                //var size = GetStringWidthWithTextRender(chr.ToString());
                //if (DrawNextCharHint && i == Len_UserStringArray)
                //    TextRenderer.DrawText(e.Graphics, chr.ToString(), SkinManager.FONT_SIZE_26, new Point((int)pos_left, 0), Color.Lime);
                //    //g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(Color.Lime), new PointF(pos_left, 0));
                //else if (i > Len_UserStringArray || (!DrawNextCharHint && i >= Len_UserStringArray))
                //    TextRenderer.DrawText(e.Graphics, chr.ToString(), SkinManager.FONT_SIZE_26, new Point((int)pos_left, 0), ForeColor);
                //    //g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(ForeColor), new PointF(pos_left, 0));
                //else
                //{
                //    if (AnswerStringArray[i] == UserStringArray[i])
                //        TextRenderer.DrawText(e.Graphics, chr.ToString(), SkinManager.FONT_SIZE_26, new Point((int)pos_left, 0), CorrectForeColor);
                //        //g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(CorrectForeColor), new PointF(pos_left, 0));
                //    else
                //        TextRenderer.DrawText(e.Graphics, chr.ToString(), SkinManager.FONT_SIZE_26, new Point((int)pos_left, 0), ErrorForeColor);
                //        //g.DrawString(chr.ToString(), SkinManager.FONT_SIZE_26, new SolidBrush(ErrorForeColor), new PointF(pos_left, 0));
                //}
                //pos_left += size.Width;
                //++i;
                //if (i >= Len_AnswerStringArray)
                //    break;
                #endregion
            }
        }
Пример #24
0
        /**
         * <summary>Sorts the extracted text strings.</summary>
         * <remarks>Sorting implies text position ordering, integration and aggregation.</remarks>
         * <param name="rawTextStrings">Source (lower-level) text strings.</param>
         * <param name="textStrings">Target (higher-level) text strings.</param>
         */
        private void Sort(
            List <ContentScanner.TextStringWrapper> rawTextStrings,
            List <ITextString> textStrings
            )
        {
            // Sorting the source text strings...
            {
                TextStringPositionComparer <ContentScanner.TextStringWrapper> positionComparator = new TextStringPositionComparer <ContentScanner.TextStringWrapper>();
                rawTextStrings.Sort(positionComparator);
            }

            // Aggregating and integrating the source text strings into the target ones...
            TextString textString       = null;
            TextStyle  textStyle        = null;
            TextChar   previousTextChar = null;
            bool       dehyphenating    = false;

            foreach (ContentScanner.TextStringWrapper rawTextString in rawTextStrings)
            {
                /*
                 * NOTE: Contents on the same line are grouped together within the same text string.
                 */
                // Add a new text string in case of new line!
                if (textString != null &&
                    textString.TextChars.Count > 0 &&
                    !TextStringPositionComparer <ITextString> .IsOnTheSameLine(textString.Box.Value, rawTextString.Box.Value))
                {
                    if (dehyphenated &&
                        previousTextChar.Value == '-') // Hyphened word.
                    {
                        textString.TextChars.Remove(previousTextChar);
                        dehyphenating = true;
                    }
                    else // Full word.
                    {
                        // Add synthesized space character!
                        textString.TextChars.Add(
                            new TextChar(
                                ' ',
                                new RectangleF(
                                    previousTextChar.Box.Right,
                                    previousTextChar.Box.Top,
                                    0,
                                    previousTextChar.Box.Height
                                    ),
                                textStyle,
                                true
                                )
                            );
                        textString    = null;
                        dehyphenating = false;
                    }
                    previousTextChar = null;
                }
                if (textString == null)
                {
                    textStrings.Add(textString = new TextString());
                }

                textStyle = rawTextString.Style;
                double spaceWidth = textStyle.GetWidth(' ') * .5;
                foreach (TextChar textChar in rawTextString.TextChars)
                {
                    if (previousTextChar != null)
                    {
                        /*
                         * NOTE: PDF files may have text contents omitting space characters,
                         * so they must be inferred and synthesized, marking them as virtual
                         * in order to allow the user to distinguish between original contents
                         * and augmented ones.
                         */
                        if (!textChar.Contains(' ') &&
                            !previousTextChar.Contains(' '))
                        {
                            float charSpace = textChar.Box.X - previousTextChar.Box.Right;
                            if (charSpace > spaceWidth)
                            {
                                // Add synthesized space character!
                                textString.TextChars.Add(
                                    previousTextChar = new TextChar(
                                        ' ',
                                        new RectangleF(
                                            previousTextChar.Box.Right,
                                            textChar.Box.Y,
                                            charSpace,
                                            textChar.Box.Height
                                            ),
                                        textStyle,
                                        true
                                        )
                                    );
                            }
                        }
                        else if (dehyphenating &&
                                 previousTextChar.Contains(' '))
                        {
                            textStrings.Add(textString = new TextString());
                            dehyphenating = false;
                        }
                    }
                    textString.TextChars.Add(previousTextChar = textChar);
                }
            }
        }
Пример #25
0
        public SignalFuture AddText(string text, string speaker = "Monologue", SpriteFont font = null, bool lineBreak = false)
        {
            var textPosition = Bounds.TopLeft + new Vector2(8, 0);
            float xOffset = 0;

            if (Strings.Count > 0) {
                var ls = Strings.Last();
                var lcb = ls.Layout.LastCharacterBounds.Translate(ls.Layout.Position);
                if (ls.LineBreakAfter) {
                    textPosition.Y = lcb.TopLeft.Y + ls.Font.LineSpacing;
                } else {
                    xOffset = lcb.BottomRight.X - ls.Layout.Position.X;
                    textPosition.Y = lcb.TopLeft.Y;
                }
            }

            bool italic = (speaker == "Monologue");
            var actualFont = font ?? (italic ? ItalicDialogueFont : DialogueFont);
            var color = Speakers.ByName[speaker].Color;

            var words = SplitWords(text);

            TextString s = null;

            float rightMargin = Bounds.Size.X - WordWrapRightMargin;

            foreach (var word in words) {
                var size = actualFont.MeasureString(word);

                // word wrap
                if ((xOffset + size.X) >= rightMargin) {
                    xOffset = WordWrapIndent;
                    textPosition.Y += actualFont.LineSpacing;
                }

                s = new TextString {
                    Speaker = speaker,
                    Font = actualFont,
                    Layout = actualFont.LayoutString(word, null, position: textPosition, xOffsetOfFirstLine: xOffset, color: color),
                    Length = word.Trim().Length,
                    IsMu = word.Contains("\u65E0")
                };
                Strings.Add(s);

                xOffset = s.Layout.LastCharacterBounds.BottomRight.X;

                if (word.EndsWith("\n")) {
                    xOffset = 0;
                    textPosition.Y += actualFont.LineSpacing;
                }
            }

            if (s == null)
                return null;

            s.LineBreakAfter = (lineBreak || text.EndsWith("\n"));
            return s.Future = new SignalFuture();
        }
Пример #26
0
        public C_Document Parse(string html)
        {
            List <C_Element> elementList = new List <C_Element>();
            int PositionCounter          = -1;

            foreach (char c in html.ToCharArray())
            {
                PositionCounter++;

                #region START OF TAG

                if (c == '<')
                {
                    InsideTag = true;

                    if (TextString.Trim().Length != 0)
                    {
                        elementList.Add(new C_Element("Content", TextString, C_ElementType.text, PositionCounter));
                        TextString = string.Empty;
                    }

                    continue;
                }

                #endregion

                #region END OF TAG

                if (c == '>')
                {
                    InsideTag = false;
                    TagString = TagString.Trim();

                    if (TagString.Length != 0)
                    {
                        elementList.Add(new C_Element(C_Helper.GetTag(TagString), TagString, C_ElementType.tag, PositionCounter));
                        TagString = string.Empty;
                    }

                    continue;
                }

                #endregion

                #region BUILD STRINGS

                if (InsideTag)
                {
                    TagString += c;
                }
                else
                {
                    TextString += c;
                }

                #endregion
            }

            return(new C_Document
            {
                Elements = elementList,
                OriginalString = html,
            });
        }
Пример #27
0
        public override void Activate()
        {
            ContentManager content = new ContentManager(this.ScreenManager.Game.Services, "Content");
            PresentationParameters pp = this.ScreenManager.GraphicsDevice.PresentationParameters;

            AudioManager.Instance.PauseSounds();

            this._closeText = new TextString(" to close.");
            this._closeText.Load(content);
            this._closeText.TextAlignment = TextAlignment.Left;
            this._closeText.ButtonType = (ButtonIcon)1;
            this._closeText.Position = new Vector2(this.ScreenManager.GraphicsDevice.Viewport.Height * 0.03f, this.ScreenManager.GraphicsDevice.Viewport.Height * 0.96f);

            this._texture = content.Load<Texture2D>(Defines.NOTE_DIRECTORY + "Note_Empty");
            this._font = FontManager.Instance.GetFont(FontList.Notes);
            string path = "./Content/Assets/Other/Notes/" + _ID + ".txt";

            this._noteString = File.ReadAllText(path);

            string[] noteWords = _noteString.Split(' ');
            string lineString = String.Empty;
            StringBuilder builder = new StringBuilder();
            int strPos = 0;
            float width = _texture.Width - _offset.X;

            for (int i = 0; i < noteWords.Length; i++)
            {
                string word = noteWords[i];
                string[] removeWord = new string[] { "\n", "\r" };
                string[] words;

                if (word.Contains("\n"))
                {
                    words = word.Split(removeWord, StringSplitOptions.None);
                    bool newLineComplete = false;
                    foreach (string str in words)
                    {
                        if (str == "" && !newLineComplete)
                        {
                            builder.AppendFormat("{0}", Environment.NewLine);
                            builder.AppendFormat("{0}", Environment.NewLine);
                            newLineComplete = true;
                        }
                        else
                        {
                            builder.AppendFormat(" {0}", str);
                            strPos = str.Length + 1;
                            lineString = str;
                        }
                    }

                    continue;
                }

                float size = _font.MeasureString(lineString).X + _font.MeasureString(word).X;

                if (size < width)
                {
                    builder.AppendFormat(" {0}", word);
                    strPos += word.Length + 1;
                    lineString += " " + word;
                }
                else
                {
                    builder.AppendFormat("{0}{1}", Environment.NewLine, word);
                    strPos = word.Length;
                    lineString = word;
                }
            }

            _noteString = builder.ToString();

            this._position = new Vector2(pp.BackBufferWidth * 0.5f, pp.BackBufferHeight * 0.2f);

            base.Activate();
        }
Пример #28
0
        /**
         * <summary>Sorts the extracted text strings.</summary>
         * <remarks>Sorting implies text position ordering, integration and aggregation.</remarks>
         * <param name="rawTextStrings">Source (lower-level) text strings.</param>
         * <param name="textStrings">Target (higher-level) text strings.</param>
         */
        private void Sort(
            List <ContentScanner.TextStringWrapper> rawTextStrings,
            List <ITextString> textStrings
            )
        {
            // Sorting the source text strings...
            {
                TextStringPositionComparer <ContentScanner.TextStringWrapper> positionComparator = new TextStringPositionComparer <ContentScanner.TextStringWrapper>();
                rawTextStrings.Sort(positionComparator);
            }

            // Aggregating and integrating the source text strings into the target ones...
            TextString textString       = null;
            TextChar   previousTextChar = null;

            foreach (ContentScanner.TextStringWrapper rawTextString in rawTextStrings)
            {
                /*
                 * NOTE: Contents on the same line are grouped together within the same text string.
                 */
                // Add a new text string in case of new line!
                if (textString == null ||
                    (textString.TextChars.Count > 0 &&
                     !TextStringPositionComparer <ITextString> .IsOnTheSameLine(
                         textString.Box.Value,
                         rawTextString.Box.Value)))
                {
                    textStrings.Add(textString = new TextString());
                    previousTextChar           = null;
                }

                TextStyle textStyle  = rawTextString.Style;
                float     spaceWidth = 0;
                try
                { spaceWidth = textStyle.Font.GetWidth(' ', textStyle.FontSize); }
                catch
                { /* NOOP. */ }
                if (spaceWidth == 0)
                {
                    spaceWidth = textStyle.FontSize * .25f;
                }                                 // NOTE: as a rule of thumb, space width is estimated according to the font size.
                foreach (TextChar textChar in rawTextString.TextChars)
                {
                    if (previousTextChar != null)
                    {
                        /*
                         * NOTE: PDF files may have text contents omitting space characters,
                         * so they must be inferred and synthesized, marking them as virtual
                         * in order to allow the user to distinguish between original contents
                         * and augmented ones.
                         */
                        float characterSpace = textChar.Box.X - previousTextChar.Box.Right;
                        if (characterSpace >= spaceWidth)
                        {
                            // Add synthesized space character!
                            textString.TextChars.Add(
                                new TextChar(
                                    ' ',
                                    new RectangleF(
                                        previousTextChar.Box.Right,
                                        textChar.Box.Y,
                                        characterSpace,
                                        textChar.Box.Height
                                        ),
                                    textStyle,
                                    true
                                    )
                                );
                        }
                    }
                    textString.TextChars.Add(previousTextChar = textChar);
                }
            }
        }
        public void Write(String message)
        {
            if (TextStrings.Count == 0)
            {
                TextStrings.Add(new TextString(message, _screenHeight));
            }

            else
            {
                TextString ts = new TextString(message, TextStrings.Last().Position+LineSpacing);
                TextStrings.Add(ts);
            }
        }
Пример #30
0
        public override void Activate()
        {
            ContentManager         content = new ContentManager(this.ScreenManager.Game.Services, "Content");
            PresentationParameters pp      = this.ScreenManager.GraphicsDevice.PresentationParameters;

            AudioManager.Instance.PauseSounds();

            this._closeText = new TextString(" to close.");
            this._closeText.Load(content);
            this._closeText.TextAlignment = TextAlignment.Left;
            this._closeText.ButtonType    = (ButtonIcon)1;
            this._closeText.Position      = new Vector2(this.ScreenManager.GraphicsDevice.Viewport.Height * 0.03f, this.ScreenManager.GraphicsDevice.Viewport.Height * 0.96f);

            this._texture = content.Load <Texture2D>(Defines.NOTE_DIRECTORY + "Note_Empty");
            this._font    = FontManager.Instance.GetFont(FontList.Notes);
            string path = "./Content/Assets/Other/Notes/" + _ID + ".txt";

            this._noteString = File.ReadAllText(path);

            string[]      noteWords  = _noteString.Split(' ');
            string        lineString = String.Empty;
            StringBuilder builder    = new StringBuilder();
            int           strPos     = 0;
            float         width      = _texture.Width - _offset.X;

            for (int i = 0; i < noteWords.Length; i++)
            {
                string   word       = noteWords[i];
                string[] removeWord = new string[] { "\n", "\r" };
                string[] words;

                if (word.Contains("\n"))
                {
                    words = word.Split(removeWord, StringSplitOptions.None);
                    bool newLineComplete = false;
                    foreach (string str in words)
                    {
                        if (str == "" && !newLineComplete)
                        {
                            builder.AppendFormat("{0}", Environment.NewLine);
                            builder.AppendFormat("{0}", Environment.NewLine);
                            newLineComplete = true;
                        }
                        else
                        {
                            builder.AppendFormat(" {0}", str);
                            strPos     = str.Length + 1;
                            lineString = str;
                        }
                    }

                    continue;
                }

                float size = _font.MeasureString(lineString).X + _font.MeasureString(word).X;

                if (size < width)
                {
                    builder.AppendFormat(" {0}", word);
                    strPos     += word.Length + 1;
                    lineString += " " + word;
                }
                else
                {
                    builder.AppendFormat("{0}{1}", Environment.NewLine, word);
                    strPos     = word.Length;
                    lineString = word;
                }
            }

            _noteString = builder.ToString();


            this._position = new Vector2(pp.BackBufferWidth * 0.5f, pp.BackBufferHeight * 0.2f);

            base.Activate();
        }
Пример #31
0
        protected override void OnKeyPressed(Reactive.KeyInput.Key pKey)
        {
            char newChar = pKey.Character;

            switch (pKey.KeysValue)
            {
            case Keys.Back:
                if (!string.IsNullOrEmpty(TextString) &&
                    _cursorPosition > 0)
                {
                    _cursorPosition = _cursorPosition - 1;
                    TextString      = TextString.Remove(_cursorPosition, 1);
                }
                break;

            case Keys.Delete:
                if (!string.IsNullOrEmpty(TextString) &&
                    TextString.Length > _cursorPosition)
                {
                    TextString = TextString.Remove(_cursorPosition, 1);
                }
                break;

            case Keys.Left:
                _cursorPosition = _cursorPosition > 0 ? _cursorPosition - 1 : 0;
                break;

            case Keys.Right:
                _cursorPosition = TextString.Length > _cursorPosition
                        ? _cursorPosition + 1
                        : _cursorPosition;
                break;

            case Keys.Home:
                _cursorPosition = 0;
                break;

            case Keys.End:
                _cursorPosition = TextString.Length;
                break;

            default:
                if ((int)pKey.Character >= 32)
                {
                    if (string.IsNullOrEmpty(TextString))
                    {
                        TextString = pKey.Character.ToString();
                    }
                    else
                    if (_cursorPosition == TextString.Length)
                    {
                        TextString = TextString + pKey.Character.ToString();
                    }
                    else
                    {
                        TextString = TextString.Insert(_cursorPosition, pKey.Character.ToString());
                    }
                    _cursorPosition++;
                }
                break;
            }
            ResetMillisecondTimer();
            SetCursorCoordinatesPosition();
        }
        public void Update(ref TextString srcString)
        {
            MyConnectedComponentsAnalysisFast.MyBlob char_blob0 = srcString.char_list[0];
            char_blob0.mass_center.X += srcString.x_offset;
            char_blob0.mass_center.Y += srcString.y_offset;
            char_blob0.bbx.X         += srcString.x_offset;
            char_blob0.bbx.Y         += srcString.y_offset;
            Rectangle bbx = char_blob0.bbx;

            for (int i = 1; i < srcString.char_list.Count; i++)
            {
                MyConnectedComponentsAnalysisFast.MyBlob char_blob = srcString.char_list[i];
                char_blob.mass_center.X += srcString.x_offset;
                char_blob.mass_center.Y += srcString.y_offset;
                char_blob.bbx.X         += srcString.x_offset;
                char_blob.bbx.Y         += srcString.y_offset;

                int x = bbx.X, y = bbx.Y, xx = bbx.X + bbx.Width - 1, yy = bbx.Y + bbx.Height - 1;
                int x1 = char_blob.bbx.X, y1 = char_blob.bbx.Y, xx1 = char_blob.bbx.X + char_blob.bbx.Width - 1, yy1 = char_blob.bbx.Y + char_blob.bbx.Height - 1;

                int x2, y2, xx2, yy2;

                if (x < x1)
                {
                    x2 = x;
                }
                else
                {
                    x2 = x1;
                }
                if (y < y1)
                {
                    y2 = y;
                }
                else
                {
                    y2 = y1;
                }

                if (xx < xx1)
                {
                    xx2 = xx1;
                }
                else
                {
                    xx2 = xx;
                }
                if (yy < yy1)
                {
                    yy2 = yy1;
                }
                else
                {
                    yy2 = yy;
                }

                bbx.X      = x2; bbx.Y = y2;
                bbx.Width  = xx2 - x2 + 1;
                bbx.Height = yy2 - y2 + 1;
            }
            srcString.bbx = bbx;
        }