示例#1
0
 private static void DebugCheck(StringWithFont current, StringWithFont previous)
 {
     if (previous.String.Equals(current.String))
     {
         Debugger.Break();
     }
 }
示例#2
0
        public override bool Accept(IEventData data, EventType type)
        {
            if (!type.Equals(EventType.RENDER_TEXT))
            {
                return(false);
            }

            var    renderInfo = (TextRenderInfo)data;
            string text       = renderInfo.GetText();

            if (text == null)
            {
                return(false);
            }

            if (text.Equals("die’"))
            {
                Debugger.Break();
            }

            var stringWithFont = new StringWithFont()
            {
                String = text,
                Width  = renderInfo.GetSingleSpaceWidth()
            };

            if (previousEntry == null)
            {
                Program.TextWithWidth.AddLast(stringWithFont);
                previousEntry = stringWithFont;
                return(true);
            }

            var previousWidth       = previousEntry.Value.Width;
            var stringWithFontWidth = stringWithFont.Width;
            var delta = Math.Abs(previousWidth - stringWithFontWidth);

            if ((!previousEntry.Value.String.Equals(stringWithFont.String) &&
                 previousEntry.Value.String.EndsWith(stringWithFont.String)) ||
                previousEntry.Value.String.Equals(stringWithFont.String))
            {
                Program.TextWithWidth.RemoveLast();
                previousEntry = new StringWithFont()
                {
                    String = previousEntry.Value.String,
                    Width  = Math.Max(stringWithFont.Width, previousWidth)
                };
                Program.TextWithWidth.AddLast(previousEntry.Value);
            }
            else if (delta < 0.001f &&
                     !previousEntry.Value.String.Equals(stringWithFont.String))
            {
                DebugCheck(stringWithFont, previousEntry.Value);

                Program.TextWithWidth.RemoveLast();
                previousEntry = new StringWithFont()
                {
                    String = previousEntry.Value.String + stringWithFont.String,
                    Width  = Math.Max(stringWithFont.Width, previousWidth)
                };

                Program.TextWithWidth.AddLast(previousEntry.Value);
            }
            else
            {
                DebugCheck(stringWithFont, previousEntry.Value);
                Program.TextWithWidth.AddLast(stringWithFont);
                previousEntry = stringWithFont;
            }

            return(true);
        }