Пример #1
0
        VgVisualDoc ReadSvgFile(string filename)
        {
            string       svgContent = System.IO.File.ReadAllText(filename);
            VgDocBuilder docBuidler = new VgDocBuilder();
            SvgParser    parser     = new SvgParser(docBuidler);

            WebLexer.TextSnapshot textSnapshot = new WebLexer.TextSnapshot(svgContent);
            parser.ParseDocument(textSnapshot);
            //TODO: review this step again
            VgVisualDocBuilder builder = new VgVisualDocBuilder();

            return(builder.CreateVgVisualDoc(docBuidler.ResultDocument, _vgVisualDocHost));
        }
Пример #2
0
        public static VgVisualElement CreateVgVisualElemFromSvgContent(string svgContent)
        {
            VgDocBuilder docBuidler = new VgDocBuilder();
            SvgParser    parser     = new SvgParser(docBuidler);

            WebLexer.TextSnapshot textSnapshot = new WebLexer.TextSnapshot(svgContent);
            parser.ParseDocument(textSnapshot);//start document parsing

            //TODO: review this step again
            VgVisualDocBuilder builder = new VgVisualDocBuilder();
            VgDocument         svgDoc  = docBuidler.ResultDocument;

            //optional
            svgDoc.OriginalContent = svgContent;
            //-------------------------------------------------------------
            VgVisualElement vgVisRootElem = builder.CreateVgVisualDoc(svgDoc, null).VgRootElem;

            //
            vgVisRootElem.OwnerDocument = svgDoc;//tmp


            return(vgVisRootElem);
        }
Пример #3
0
        protected override void OnStartDemo(SampleViewport viewport)
        {
            PaintLab.Svg.SvgParser parser = new SvgParser();
            _backBoard           = new BackDrawBoardUI(400, 400);
            _backBoard.BackColor = Color.White;
            viewport.AddContent(_backBoard);



            box1           = new LayoutFarm.CustomWidgets.SimpleBox(50, 50);
            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            _backBoard.AddChild(box1);

            //----------------------

            //load lion svg
            string file       = @"d:\\WImageTest\\lion.svg";
            string svgContent = System.IO.File.ReadAllText(file);

            WebLexer.TextSnapshot textSnapshot = new WebLexer.TextSnapshot(svgContent);
            parser.ParseDocument(textSnapshot);
            //
            SvgRenderVx svgRenderVx = parser.GetResultAsRenderVx();
            var         uiSprite    = new UISprite(10, 10);

            uiSprite.LoadSvg(svgRenderVx);
            _backBoard.AddChild(uiSprite);
            //--------
            rectBoxController.Init();
            //------------
            viewport.AddContent(rectBoxController);

            //foreach (var ui in rectBoxController.GetControllerIter())
            //{
            //    viewport.AddContent(ui);
            //}

            //--------
            var evListener = new GeneralEventListener();

            uiSprite.AttachExternalEventListener(evListener);


            evListener.MouseDown += (e) =>
            {
                //e.MouseCursorStyle = MouseCursorStyle.Pointer;
                ////--------------------------------------------
                //e.SetMouseCapture(rectBoxController.ControllerBoxMain);
                rectBoxController.UpdateControllerBoxes(box1);
                rectBoxController.Focus();
                //System.Console.WriteLine("click :" + (count++));
            };
            rectBoxController.ControllerBoxMain.KeyDown += (s1, e1) =>
            {
                if (e1.Ctrl && e1.KeyCode == UIKeys.X)
                {
                    //test copy back image buffer from current rect area

#if DEBUG
                    //test save some area
                    int w = rectBoxController.ControllerBoxMain.Width;
                    int h = rectBoxController.ControllerBoxMain.Height;

                    using (DrawBoard gdiDrawBoard = DrawBoardCreator.CreateNewDrawBoard(1, w, h))
                    {
                        gdiDrawBoard.OffsetCanvasOrigin(rectBoxController.ControllerBoxMain.Left, rectBoxController.ControllerBoxMain.Top);
                        _backBoard.CurrentPrimaryRenderElement.CustomDrawToThisCanvas(gdiDrawBoard, new Rectangle(0, 0, w, h));
                        var img2 = new ActualImage(w, h);
                        //copy content from drawboard to target image and save
                        gdiDrawBoard.RenderTo(img2, 0, 0, w, h);

                        img2.dbugSaveToPngFile("d:\\WImageTest\\ddd001.png");
                    }
#endif
                }
            };
        }
Пример #4
0
        public override void Analyze(TextSnapshot textSnapshot)
        {
#if DEBUG
            dbug_OnStartAnalyze();
#endif

            this.textSnapshot = textSnapshot;
            char[] sourceBuffer  = TextSnapshot.UnsafeGetInternalBuffer(textSnapshot);
            int    lim           = sourceBuffer.Length;
            char   strEscapeChar = '"';
            int    currentState  = 0;
            //-----------------------------

            for (int i = 0; i < lim; i++)
            {
                char c = sourceBuffer[i];
#if DEBUG
                dbug_currentLineCharIndex++;
                dbugReportChar(c, currentState);
#endif
                switch (currentState)
                {
                default:
                {
                    //???
                }
                break;

                case 0:      //from content mode
                {
                    if (c == '<')
                    {
                        //flush existing content
                        //switch to content  tag mode
                        FlushExisingBuffer(i, HtmlLexerEvent.FromContentPart);
                        currentState = 1;
                        //not need whitespace in this mode
                    }
                    else
                    {
                        //in content mode
                        AppendBuffer(c, i);
                    }
                }
                break;

                case 1:
                {
                    //after open angle
                    switch (c)
                    {
                    case '!':
                    {
                        currentState = 11;
                    }
                    break;

                    case '?':
                    {
                        //process instruction
                        currentState = 8;
                    }
                    break;

                    case ':':
                    {
                        //shold not occurs
                        currentState = 4;
                    }
                    break;

                    case '/':
                    {
                        //close tag
                        RaiseStateChanged(HtmlLexerEvent.VisitOpenSlashAngle, i, 1);
                        currentState = 5;                //collect node name
                    }
                    break;

                    default:
                    {
                        currentState = 5;
                        //clear prev buffer
                        //then start collect node name

                        AppendBuffer(c, i);
                    }
                    break;
                    }
                }
                break;

                case 2:
                {
                    //inside comment node
                    if (c == '-')
                    {
                        if (i < lim - 2)
                        {
                            if (sourceBuffer[i + 1] == '-' && sourceBuffer[i + 2] == '>')
                            {
                                //end comment node
                                FlushExisingBuffer(i, HtmlLexerEvent.CommentContent);
                                i           += 2;
                                currentState = 0;
                                continue;
                            }
                        }
                    }
                    //skip all comment  content ?
                    AppendBuffer(c, i);
                }
                break;

                case 5:
                {
                    //inside open angle
                    //name collecting
                    //terminate with...
                    switch (c)
                    {
                    case '/':
                    {
                        currentState = 7;
                    }
                    break;

                    case '>':
                    {
                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                        RaiseStateChanged(HtmlLexerEvent.VisitCloseAngle, i, 1);
                        //flush
                        currentState = 0;
                        //goto content mode
                    }
                    break;

                    case ':':
                    {
                        //flush node name
                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                        //start new node name
                    }
                    break;

                    case ' ':
                    {
                        //flush node name
                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                    }
                    break;

                    case '=':
                    {
                        //flush name
                        FlushExisingBuffer(i, HtmlLexerEvent.Attribute);
                        RaiseStateChanged(HtmlLexerEvent.VisitAttrAssign, i, 1);
                        //start collect value of attr
                    }
                    break;

                    case '"':
                    {
                        //start string escap with "
                        currentState  = 6;
                        strEscapeChar = '"';
                    }
                    break;

                    case '\'':
                    {
                        //start string escap with '
                        currentState  = 6;
                        strEscapeChar = '\'';
                    }
                    break;

                    default:
                    {
                        //else collect
                        //flush nodename

                        if (char.IsWhiteSpace(c))
                        {
                            FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                        }
                        else
                        {
                            AppendBuffer(c, i);
                        }
                    }
                    break;
                    }
                }
                break;

                case 6:
                {
                    //collect string
                    if (c == strEscapeChar)
                    {
                        //stop string escape
                        //flush
                        FlushExisingBuffer(i, HtmlLexerEvent.AttributeValueAsLiteralString);
                        currentState = 5;
                    }
                    else
                    {
                        AppendBuffer(c, i);
                    }
                }
                break;

                case 7:
                {
                    //after /   //must be >
                    if (c == '>')
                    {
                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                        RaiseStateChanged(HtmlLexerEvent.VisitCloseSlashAngle, i, 1);
                        currentState = 0;
                    }
                    else
                    {
                        //error ?
                    }
                }
                break;

                case 10:
                {
                    //unknown tag
                    //exit from this tag when found >
                    if (c == '>')
                    {
                        currentState = 0;
                    }
                }
                break;

                case 11:
                {
                    //open_angle, exlcimation
                    switch (c)
                    {
                    case '-':
                    {
                        //looking for next char
                        if (i < lim)
                        {
                            if (sourceBuffer[i + 1] == '-')
                            {
                                currentState = 2;
                                continue;
                            }
                            else
                            {
                                //unknown tag?
                                currentState = 10;
                            }
                        }
                    }
                    break;

                    case '[':
                    {
                        // <![
                        //
                        currentState = 10;                //not implement,just skip
                    }
                    break;

                    default:
                    {
                        //doc type?
                        if (char.IsLetter(sourceBuffer[i + 1]))
                        {
                            RaiseStateChanged(HtmlLexerEvent.VisitOpenAngleExclimation, i, 2);
                            AppendBuffer(c, i);
                            currentState = 5;
                        }
                        else
                        {
                            currentState = 10;                //not implement, just skip
                        }
                    }
                    break;
                    }
                }
                break;
                }
            }

#if DEBUG
            dbug_OnFinishAnalyze();
#endif
        }
Пример #5
0
        /// <summary>
        /// parse to htmldom
        /// </summary>
        /// <param name="stbuilder"></param>
        internal void Parse(TextSnapshot textSnapshot, WebDocument htmldoc, DomElement currentNode)
        {
            this.textSnapshot = textSnapshot;
            //1. lex 
            lexer.BeginLex();
            //2. mini parser    
            this.curHtmlNode = currentNode;
            this._resultHtmlDoc = htmldoc;
            lexer.Analyze(textSnapshot);
            lexer.EndLex();

        }
Пример #6
0
 public void ResetParser()
 {
     this._resultHtmlDoc = null;
     this.openEltStack.Clear();
     this.curHtmlNode = null;
     this.curAttr = null;
     this.curTextNode = null;
     this.parseState = 0;
     this.textSnapshot = null;
 }
Пример #7
0
 public static char[] DecodeHtml(TextSnapshot source, int startIndex, int decLength)
 {
     return DecodeHtml(TextSnapshot.UnsafeGetInternalBuffer(source), startIndex, decLength);
 }
Пример #8
0
 //--------------
 public static char[] UnsafeGetInternalBuffer(TextSnapshot snap)
 {
     return(snap.textBuffer);
 }
Пример #9
0
 //--------------
 public static char[] UnsafeGetInternalBuffer(TextSnapshot snap)
 {
     return snap.textBuffer;
 }
Пример #10
0
        public void Analyze(TextSnapshot textSnapshot)
        {

#if DEBUG
            dbug_OnStartAnalyze();
#endif

            this.textSnapshot = textSnapshot;
            char[] sourceBuffer = TextSnapshot.UnsafeGetInternalBuffer(textSnapshot);

            int lim = sourceBuffer.Length;

            char strEscapeChar = '"';
            int currentState = 0;
            //-----------------------------

            for (int i = 0; i < lim; i++)
            {


                char c = sourceBuffer[i];
#if DEBUG
                dbug_currentLineCharIndex++;
                dbugReportChar(c, currentState);
#endif
                switch (currentState)
                {
                    default:
                        {
                            //???

                        } break;
                    case 0:  //from content mode 
                        {
                            if (c == '<')
                            {
                                //flush existing content 
                                //switch to content  tag mode 
                                FlushExisingBuffer(i, HtmlLexerEvent.FromContentPart);
                                currentState = 1;
                                //not need whitespace in this mode 
                            }
                            else
                            {
                                //in content mode
                                AppendBuffer(c, i);
                            }
                        } break;
                    case 1:
                        {
                            //after open angle
                            switch (c)
                            {
                                case '!':
                                    {
                                        currentState = 11;
                                    } break;
                                case '?':
                                    {
                                        //process instruction
                                        currentState = 8;
                                    } break;
                                case ':':
                                    {
                                        //shold not occurs
                                        currentState = 4;
                                    } break;
                                case '/':
                                    {
                                        //close tag 
                                        LexStateChanged(HtmlLexerEvent.VisitOpenSlashAngle, i, 1);
                                        currentState = 5;//collect node name 
                                    } break;
                                default:
                                    {
                                        currentState = 5;
                                        //clear prev buffer 
                                        //then start collect node name

                                        AppendBuffer(c, i);
                                    } break;
                            }
                        } break;
                    case 2:
                        {
                            //inside comment node
                            if (c == '-')
                            {
                                if (i < lim - 2)
                                {
                                    if (sourceBuffer[i + 1] == '-' && sourceBuffer[i + 2] == '>')
                                    {
                                        //end comment node  
                                        FlushExisingBuffer(i, HtmlLexerEvent.CommentContent);
                                        i += 2;
                                        currentState = 0;
                                        continue;
                                    }
                                }
                            }
                            //skip all comment  content ? 
                            AppendBuffer(c, i);

                        } break;
                    case 5:
                        {
                            //inside open angle
                            //name collecting
                            //terminate with... 
                            switch (c)
                            {
                                case '/':
                                    {
                                        currentState = 7;
                                    } break;
                                case '>':
                                    {

                                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                                        LexStateChanged(HtmlLexerEvent.VisitCloseAngle, i, 1);
                                        //flush 
                                        currentState = 0;
                                        //goto content mode
                                    } break;
                                case ':':
                                    {
                                        //flush node name
                                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                                        //start new node name

                                    } break;
                                case ' ':
                                    {
                                        //flush node name
                                        FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                                    } break;
                                case '=':
                                    {
                                        //flush name
                                        FlushExisingBuffer(i, HtmlLexerEvent.Attribute);
                                        LexStateChanged(HtmlLexerEvent.VisitAttrAssign, i, 1);
                                        //start collect value of attr 
                                    } break;
                                case '"':
                                    {
                                        //start string escap with " 
                                        currentState = 6;
                                        strEscapeChar = '"';
                                    } break;
                                case '\'':
                                    {
                                        //start string escap with ' 
                                        currentState = 6;
                                        strEscapeChar = '\'';

                                    } break;
                                default:
                                    {
                                        //else collect 
                                        //flush nodename

                                        if (char.IsWhiteSpace(c))
                                        {
                                            FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);

                                        }
                                        else
                                        {
                                            AppendBuffer(c, i);
                                        }
                                    } break;
                            }
                        } break;
                    case 6:
                        {
                            //collect string 
                            if (c == strEscapeChar)
                            {
                                //stop string escape
                                //flush 
                                FlushExisingBuffer(i, HtmlLexerEvent.AttributeValueAsLiteralString);

                                currentState = 5;
                            }
                            else
                            {
                                AppendBuffer(c, i);

                            }
                        } break;
                    case 7:
                        {
                            //after /   //must be >
                            if (c == '>')
                            {
                                FlushExisingBuffer(i, HtmlLexerEvent.NodeNameOrAttribute);
                                LexStateChanged(HtmlLexerEvent.VisitCloseSlashAngle, i, 1);
                                currentState = 0;
                            }
                            else
                            {
                                //error ?
                            }
                        } break;
                    case 10:
                        {
                            //unknown tag
                            //exit from this tag when found >
                            if (c == '>')
                            {
                                currentState = 0;
                            }
                        } break;
                    case 11:
                        {
                            //open_angle, exlcimation
                            switch (c)
                            {
                                case '-':
                                    {
                                        //looking for next char
                                        if (i < lim)
                                        {
                                            if (sourceBuffer[i + 1] == '-')
                                            {
                                                currentState = 2;
                                                continue;
                                            }
                                            else
                                            {
                                                //unknown tag?
                                                currentState = 10;
                                            }
                                        }

                                    } break;
                                case '[':
                                    {
                                        // <![
                                        //
                                        currentState = 10;//not implement,just skip
                                    } break;
                                default:
                                    {
                                        //doc type?
                                        if (char.IsLetter(sourceBuffer[i + 1]))
                                        {

                                            LexStateChanged(HtmlLexerEvent.VisitOpenAngleExclimation, i, 2);
                                            AppendBuffer(c, i);
                                            currentState = 5;
                                        }
                                        else
                                        {
                                            currentState = 10;//not implement, just skip
                                        }
                                    } break;
                            }
                        } break;

                }
            }

#if DEBUG
            dbug_OnFinishAnalyze();
#endif
        }
Пример #11
0
 public TextSource(char[] textBuffer)
 {
     this.actualSnapshot = new TextSnapshot(textBuffer);
 }
Пример #12
0
 public virtual void Analyze(TextSnapshot textSnapshot) { }