Exemplo n.º 1
0
 public TagOpenToken(int id, HtmlNode node, TextVisualProperties properties, int parentID)
     : base(id)
 {
     Name = node.Name;
     TextProperties = properties;
     ParentID = parentID;
 }
        public static TextVisualProperties Update(this TextVisualProperties properties, XElement element, CSS css)
        {
            string localName = element.Name.LocalName;

            string[] selectors = { localName };
            return(properties.UpdateCss(css, selectors));
        }
Exemplo n.º 3
0
 private TagOpenToken(int id, string name, TextVisualProperties properties, int parentId)
     : base(id)
 {
     Name = name;
     TextProperties = properties;
     ParentID = parentId;
 }
Exemplo n.º 4
0
 public TagOpenToken(int id, XElement element, TextVisualProperties properties, int parentID)
     : base(id)
 {
     Name = element.Name.LocalName;
     TextProperties = properties;
     ParentID = parentID;
 }
Exemplo n.º 5
0
 public override IEnumerable<TokenBase> GetTokens()
 {
     var propertiesStack = new Stack<TextVisualProperties>();
     var item = new TextVisualProperties();
     propertiesStack.Push(item);
     var top = new TokenIndex();
     return _root.Elements(_ns + "body").SelectMany(b => ParseNodes(b, propertiesStack, top, 0));
 }
        public static TextVisualProperties Update(this TextVisualProperties properties, HtmlNode element, CSS css)
        {
            var list = new List <string>
            {
                element.Name
            };
            string attributeValue = element.GetAttributeValue("class", string.Empty);

            if (!string.IsNullOrEmpty(attributeValue))
            {
                list.Add(element.Name + "." + attributeValue);
                list.Add("." + attributeValue);
            }
            return(properties.UpdateCss(css, list.ToArray()));
        }
Exemplo n.º 7
0
        public override IEnumerable<TokenBase> GetTokens()
        {
            var propertiesStack = new Stack<TextVisualProperties>();
            var item = new TextVisualProperties();
            propertiesStack.Push(item);
            var top = new TokenIndex();
            foreach (EpubSpineItem spineItem in GetSpineItems())
            {
                yield return new NewPageToken(top.Index++);

                AddAnchor(top, (_opfPath) + spineItem.Path);
                foreach (TokenBase token in ParseSpineItem(spineItem, propertiesStack, top))
                {
                    yield return token;
                }
            }
        }
Exemplo n.º 8
0
 public void AddText(string text, TextVisualProperties properties, double fontSize, Size size, string part = null, int tokenID = -1)
 {
     part = part ?? string.Empty;
     Inlines.Add(new TextElement
                 {
                     Text = text,
                     Width = size.Width,
                     Height = size.Height,
                     Bold = properties.Bold,
                     Italic = properties.Italic,
                     Size = fontSize,
                     SupOption = properties.SupOption,
                     SubOption = properties.SubOption,
                     Part = part,
                     LinkID = properties.LinkID,
                     TokenID = tokenID
                 });
 }
Exemplo n.º 9
0
        public override IEnumerable<TokenBase> GetTokens()
        {
            _css = new CSS();

            var html = new HtmlDocument
                            {
                                OptionOutputAsXml = true,
                                OptionReadEncoding = false
                            };
            html.Load(_reader);
            var root  = html.DocumentNode.SelectSingleNode("//body");
            
            var cssNode = html.DocumentNode.SelectSingleNode("//style");
            if (cssNode != null)
            {
                _css.Analyze(cssNode.InnerText);
            }

            var stack = new Stack<TextVisualProperties>();
            var item = new TextVisualProperties();
            stack.Push(item);

            return ParseTokens(root, stack, new TokenIndex());
        }
Exemplo n.º 10
0
        public override IEnumerable<TokenBase> GetTokens()
        {
            var top = new TokenIndex();
            string line;
            while ((line = _reader.ReadLine()) != null)
            {
                if(string.IsNullOrEmpty(line))
                    continue;
                
                var p = new XElement("p");
                var property = new TextVisualProperties
                                {
                                    TextIndent = 32.0,
                                    Inline = false
                                };

                yield return new TagOpenToken(top.Index++, p, property, -1);
                
                foreach (TokenBase baseToken in ParseText(line, top))
                    yield return baseToken;
                
                yield return new TagCloseToken(top.Index++, -1);
            }
        }
Exemplo n.º 11
0
 public void ApplyProperties(string[] selectors, TextVisualProperties properties)
 {
     foreach (CssRule rule in Rules.Where(r => r.Selectors.Any(selectors.Contains)))
     {
         string val;
         if (rule.TryGetValueForRule("font-weight", out val))
         {
             properties.Bold = val == "bold";
         }
         if (rule.TryGetValueForRule("font-style", out val))
         {
             properties.Italic = val == "italic";
         }
         if (rule.TryGetValueForRule("display", out val))
         {
             properties.Inline = val == "inline";
         }
         if (rule.TryGetValueForRule("vertical-align", out val))
         {
             properties.SupOption = val == "super";
         }
         if (rule.TryGetValueForRule("vertical-align", out val))
         {
             properties.SubOption = val == "sub";
         }
         if (rule.TryGetValueForRule("font-size", out val))
         {
             double size;
             FontSizeType type;
             if (TryParseFontSize(val, out size, out type))
             {
                 properties.FontSize = size;
                 properties.FontSizeType = type;
             }
         }
         if (rule.TryGetValueForRule("text-align", out val) && (val != "inherit"))
         {
             properties.TextAlign = val;
         }
         if (rule.TryGetValueForRule("margin", out val))
         {
             double left;
             double right;
             double bottom;
             ParseMargin(val, out left, out right, out bottom);
             properties.MarginLeft = left;
             properties.MarginRight = right;
             properties.MarginBottom = bottom;
         }
         if (rule.TryGetValueForRule("margin-left", out val))
         {
             properties.MarginLeft = ParseMarginValue(val);
         }
         if (rule.TryGetValueForRule("margin-right", out val))
         {
             properties.MarginRight = ParseMarginValue(val);
         }
         if (rule.TryGetValueForRule("margin-bottom", out val))
         {
             properties.MarginBottom = ParseMarginValue(val);
         }
         if (rule.TryGetValueForRule("text-indent", out val))
         {
             properties.TextIndent = ParseMarginValue(val);
         }
     }
 }
Exemplo n.º 12
0
 private void LeaveMargin(TextVisualProperties properties)
 {
     _marginLeft -= properties.MarginLeft;
     _marginRight -= properties.MarginRight;
 }
Exemplo n.º 13
0
 private double GetTextWidth(string text, TextVisualProperties properties, double size)
 {
     return text.Aggregate(0.0, (s, c) => s + _helper.GetSize(c, size, properties.Bold, properties.Italic).Width);
 }
Exemplo n.º 14
0
 private void EnterMargin(TextVisualProperties properties)
 {
     _marginLeft += properties.MarginLeft;
     _marginRight += properties.MarginRight;
 }
Exemplo n.º 15
0
 private double GetTextWidth(string text, bool separator, TextVisualProperties properties)
 {
     if (separator)
         text = " " + text;
     double size = _fontSize*(properties.SubOption || properties.SupOption ? 0.5 : 1.0);
     var width = GetTextWidth(text, properties, size);
     return width;
 }
Exemplo n.º 16
0
 private Size GetTextSize(string text, TextVisualProperties properties)
 {
     return new Size(
         GetTextWidth(text, false, properties), 
         GetTextHeight(text, properties.Bold, properties.Italic));
 }
Exemplo n.º 17
0
 public void ApplyProperties(string[] selectors, TextVisualProperties properties)
 {
     foreach (CssRule rule in Rules.Where(r => r.Selectors.Any(selectors.Contains)))
     {
         string val;
         if (rule.TryGetValueForRule("font-weight", out val))
         {
             properties.Bold = val == "bold";
         }
         if (rule.TryGetValueForRule("font-style", out val))
         {
             properties.Italic = val == "italic";
         }
         if (rule.TryGetValueForRule("display", out val))
         {
             properties.Inline = val == "inline";
         }
         if (rule.TryGetValueForRule("vertical-align", out val))
         {
             properties.SupOption = val == "super";
         }
         if (rule.TryGetValueForRule("vertical-align", out val))
         {
             properties.SubOption = val == "sub";
         }
         if (rule.TryGetValueForRule("font-size", out val))
         {
             double       size;
             FontSizeType type;
             if (TryParseFontSize(val, out size, out type))
             {
                 properties.FontSize     = size;
                 properties.FontSizeType = type;
             }
         }
         if (rule.TryGetValueForRule("text-align", out val) && (val != "inherit"))
         {
             properties.TextAlign = val;
         }
         if (rule.TryGetValueForRule("margin", out val))
         {
             double left;
             double right;
             double bottom;
             ParseMargin(val, out left, out right, out bottom);
             properties.MarginLeft   = left;
             properties.MarginRight  = right;
             properties.MarginBottom = bottom;
         }
         if (rule.TryGetValueForRule("margin-left", out val))
         {
             properties.MarginLeft = ParseMarginValue(val);
         }
         if (rule.TryGetValueForRule("margin-right", out val))
         {
             properties.MarginRight = ParseMarginValue(val);
         }
         if (rule.TryGetValueForRule("margin-bottom", out val))
         {
             properties.MarginBottom = ParseMarginValue(val);
         }
         if (rule.TryGetValueForRule("text-indent", out val))
         {
             properties.TextIndent = ParseMarginValue(val);
         }
     }
 }
 private static TextVisualProperties UpdateCss(this TextVisualProperties properties, CSS css, string[] selectors)
 {
     css.ApplyProperties(selectors, properties);
     return(properties);
 }
Exemplo n.º 19
0
 private static void ProcessLinks(TextVisualProperties properties, XElement xelement)
 {
     properties.LinkID = string.Empty;
     XAttribute attribute = xelement.Attributes().FirstOrDefault(t => (t.Name.LocalName == "href"));
     string str = ((attribute != null) ? attribute.Value : string.Empty).TrimStart('#');
     if (!string.IsNullOrEmpty(str))
     {
         properties.LinkID = str;
     }
 }