コード例 #1
0
        public IEnumerable<TokenBlockBase> GetLines(BookTokenIterator bookTokens, string lastText, int firstTokenID,
                                                    int stopTokenID = -1, string stopText = null)
        {
            _firstTokenID = firstTokenID;

            _tree = bookTokens.BuildTree(_firstTokenID);
            _lastOpenTag = _tree.Peek();
            _fontSize = GetCurrentFontSize();
            _separator = false;
            bool firstText = true;
            _marginLeft = _marginRight = 0.0;

            foreach (TagOpenToken openTagToken in _tree.Reverse())
                EnterMargin(openTagToken.TextProperties);

            if (string.IsNullOrEmpty(stopText) && stopTokenID > 0)
                --stopTokenID;

            while (bookTokens.MoveNext())
            {
                foreach (TokenBlockBase baseTokenLine in OutputLines(false))
                    yield return baseTokenLine;

                if (!Append(bookTokens, lastText, stopTokenID, stopText, ref firstText)) 
                    break;
            }
            foreach (TokenBlockBase baseTokenLine in OutputLines(true))
                yield return baseTokenLine;
        }
コード例 #2
0
 private void PopTag()
 {
     _tree.Pop();
     _lastOpenTag = _tree.Peek();
     _fontSize = GetCurrentFontSize();
 }
コード例 #3
0
 private void AppendToLine(TagOpenToken token)
 {
     if (!token.TextProperties.Inline)
     {
         if (_block != null)
         {
             _block.EndParagraph();
             _firstTokenID = token.ID;
             _output.Enqueue(_block);
         }
         EnterMargin(token.TextProperties);
         _block = null;
         _textWidth = _textIndent = token.TextProperties.TextIndent;
         _separator = false;
     }
     PushTag(token);
 }
コード例 #4
0
 private void PushTag(TagOpenToken tag)
 {
     _tree.Push(tag);
     _lastOpenTag = tag;
     _fontSize = GetCurrentFontSize();
 }
コード例 #5
0
        private IEnumerable<TokenBase> ParseNodes(XContainer container, Stack<TextVisualProperties> propertiesStack, TokenIndex top, int bookLevel, string pointer, int parentID = -1)
        {
            var pointerIndex = 0;
            foreach (XNode node in container.Nodes())
            {
                pointerIndex++;
                var text = node as XText;
                if (!string.IsNullOrEmpty(text?.Value))
                {
                    foreach (TokenBase token in ParseText(text.Value, top))
                    {
                        yield return token;
                    }
                }
                var element = node as XElement;
                if(element == null)
                    continue;

                TextVisualProperties properties = propertiesStack.Peek().Clone().Update(element, _styleSheet);
                
                string localName = element.Name.LocalName;
                int level = bookLevel;

                if (localName == "a")
                {
                    ProcessLinks(properties, element);
                }
                ProcessAnchors(top, element);

                if (localName == "section")
                {
                    yield return new NewPageToken(top.Index++);
                    level++;
                }

                if (localName == "title")
                {
                    ProcessTitleData(top, element, level);
                }

                if (localName == "image")
                {
                    XAttribute hrefAttr = element.Attributes().FirstOrDefault(t => (t.Name.LocalName == "href"));
                    string href = ((hrefAttr != null) ? hrefAttr.Value : string.Empty).TrimStart('#');
                    var pictureToken = new PictureToken(top.Index++, href);
                    yield return pictureToken;
                }
                else
                {
                    var tagOpen = new TagOpenToken(top.Index++, element, properties, parentID, pointer + @"/" + pointerIndex);
                    yield return tagOpen;

                    propertiesStack.Push(properties);
                    foreach (TokenBase token in ParseNodes(element, propertiesStack, top, level, pointer+@"/"+pointerIndex, tagOpen.ID))
                    {
                        yield return token;
                    }
                    propertiesStack.Pop();

                    yield return new TagCloseToken(top.Index++, parentID);
                }
                
            }
        }