Ejemplo n.º 1
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (!base.IsValidSubType(item))
     {
         return(false);
     }
     if (item is Image ||
         item is SmallText ||
         item is Sub ||
         item is Sup)
     {
         return(false);
     }
     if (item.SubElements().FindAll(x => x is Image).Count > 0)
     {
         return(false);
     }
     if (item.SubElements().FindAll(x => x is SmallText).Count > 0)
     {
         return(false);
     }
     if (item.SubElements().FindAll(x => x is Sub).Count > 0)
     {
         return(false);
     }
     if (item.SubElements().FindAll(x => x is Sup).Count > 0)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Remove sub-item
 /// </summary>
 /// <param name="item"></param>
 public virtual void Remove(IHTMLItem item)
 {
     if (Subitems.Remove(item))
     {
         item.Parent = null;
     }
 }
Ejemplo n.º 3
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (!base.IsValidSubType(item))
     {
         return false;
     }
     if (item is Image ||
         item is SmallText ||
         item is Sub ||
         item is Sup)
     {
         return false;
     }
     if (item.SubElements().FindAll(x => x is Image).Count > 0)
     {
         return false;
     }
     if (item.SubElements().FindAll(x => x is SmallText).Count > 0)
     {
         return false;
     }
     if (item.SubElements().FindAll(x => x is Sub).Count > 0)
     {
         return false;
     }
     if (item.SubElements().FindAll(x => x is Sup).Count > 0)
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
        private ulong SplitBlockHTMLItem(IHTMLItem item, Div content, IList <IHTMLItem> resList, ulong documentSize)
        {
            ulong docSize  = documentSize;
            ulong itemSize = item.EstimateSize();

            if (_checker.ExceedSizeLimit(documentSize + itemSize))
            {
                var oldContent = content;
                resList.Add(content);
                content = new Div(HTMLElementType.HTML5);
                content.GlobalAttributes.Class.Value    = oldContent.GlobalAttributes.Class.Value;
                content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value;
                docSize = 0;
            }
            if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document
            {
                docSize += itemSize;
                content.Add(item);
            }
            else
            {
                var div = item as Div;
                if (div != null) // if the item that bigger than max size is Div block
                {
                    foreach (var splitedItem in SplitDiv(div, documentSize))
                    {
                        documentSize = SplitSimpleHTMLItem(splitedItem, content, resList, documentSize);
                    }
                }
            }
            return(docSize);
        }
Ejemplo n.º 5
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     // may appear only once and only as first element
     if (item is TableCaption)
     {
         if (Subitems.Count > 0)
         {
             return(false);
         }
         IHTMLItem seekItem = Subitems.Find(x => x is TableCaption);
         if (seekItem != null)
         {
             return(false);
         }
         return(item.IsValid());
     }
     if (item is ColElement)
     {
         return(item.IsValid());
     }
     if (item is ColGroup)
     {
         return(item.IsValid());
     }
     if (item is TableBody)
     {
         IHTMLItem seekItem = Subitems.Find(x => x is TableBody);
         if (seekItem != null)
         {
             return(false);
         }
         seekItem = Subitems.Find(x => x is TableRow);
         if (seekItem != null)
         {
             return(false);
         }
         return(item.IsValid());
     }
     if (item is TableRow)
     {
         IHTMLItem seekItem = Subitems.Find(x => x is TableBody);
         if (seekItem != null)
         {
             return(false);
         }
         seekItem = Subitems.Find(x => x is TableHead);
         if (seekItem != null)
         {
             return(false);
         }
         seekItem = Subitems.Find(x => x is TableFooter);
         if (seekItem != null)
         {
             return(false);
         }
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 6
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IBlockElement)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 7
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is SimpleHTML5Text)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 8
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is ColElement)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 9
0
 private BaseXHTMLFileV3 GetIDParentDocument(EPubFileV3 file, IHTMLItem value)
 {
     if ((file.AnnotationPage != null) && file.AnnotationPage.PartOfDocument(value))
     {
         return(file.AnnotationPage);
     }
     return(file.GetIDOfParentDocument(value) as BaseXHTMLFileV3);
 }
Ejemplo n.º 10
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is Frame)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 11
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is Option)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 12
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is Option)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 13
0
 public IBaseXHTMLFile GetIDOfParentDocument(IHTMLItem value)
 {
     return(_sections.FirstOrDefault(document =>
     {
         var baseXHTMLFileV3 = document as BaseXHTMLFileV3;
         return baseXHTMLFileV3 != null && baseXHTMLFileV3.PartOfDocument(value);
     }));
 }
Ejemplo n.º 14
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is Frame)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 15
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is SimpleHTML5Text)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 16
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     // TODO: full check for ruby sequence
     if (item is IRubyItem)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 17
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     // TODO: full check for ruby sequence
     if (item is IRubyItem)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 18
0
        private IEnumerable <Anchor> GetAllContainedAnchors(IHTMLItem linkItem)
        {
            if (linkItem.SubElements() == null) // if no sub elements - simple text item can't be anchor, so return empty list
            {
                return(new List <Anchor>());
            }
            IEnumerable <Anchor> containedAnchors = linkItem.SubElements().OfType <Anchor>();

            return(linkItem.SubElements().Aggregate(containedAnchors, (current, subElement) => current.Concat(GetAllContainedAnchors(subElement))));
        }
Ejemplo n.º 19
0
        private IEnumerable <Anchor> GetAllFirstLevelContainedAnchors(IHTMLItem linkItem)
        {
            if (linkItem.SubElements() == null) // if no sub elements - simple text item can't be anchor, so return empty list
            {
                return(new List <Anchor>());
            }
            IEnumerable <Anchor> containedAnchors = linkItem.SubElements().OfType <Anchor>();

            return(containedAnchors);
        }
Ejemplo n.º 20
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IInlineItem ||
         item is IBlockElement ||
         item is SimpleHTML5Text)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 21
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IInlineItem ||
         item is IBlockElement ||
         item is SimpleHTML5Text)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 22
0
        private static ulong EstimateSize(IHTMLItem item)
        {
            var   stream = new MemoryStream();
            XNode node   = item.Generate();

            using (var writer = XmlWriter.Create(stream))
            {
                node.WriteTo(writer);
            }
            return((ulong)stream.Length);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Adds sub-item to the item , only if
 /// allowed by the rules and element can accept content
 /// </summary>
 /// <param name="item">sub-item to add</param>
 public virtual void Add(IHTMLItem item)
 {
     if ((item != null) && IsValidSubType(item))
     {
         Subitems.Add(item);
         item.Parent = this;
     }
     else
     {
         throw new HTML5ViolationException();
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Detect parent container of the element
 /// </summary>
 /// <param name="referencedItem"></param>
 /// <returns></returns>
 private static IHTMLItem DetectParentContainer(IHTMLItem referencedItem)
 {
     if (referencedItem is IBlockElement)
     {
         return(referencedItem);
     }
     if (referencedItem.Parent is IBlockElement)
     {
         return(referencedItem.Parent);
     }
     return(null);
 }
Ejemplo n.º 25
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is TableData)
     {
         return(item.IsValid());
     }
     if (item is TableHeaderCell)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 26
0
 public LinkReMapperV2(KeyValuePair <string, List <Anchor> > link, Dictionary <string, IHTMLItem> ids, BookStructureManager structureManager)
 {
     _link               = link;
     _structureManager   = structureManager;
     _idString           = ReferencesUtils.GetIdFromLink(link.Key);                // Get ID of a link target;
     _linkTargetItem     = ids[_idString];                                         // get object targeted by link
     _linkTargetDocument = GetIDParentDocument(structureManager, _linkTargetItem); // get parent document (file) containing targeted object
     if (_linkTargetDocument != null)
     {
         _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item
     }
 }
Ejemplo n.º 27
0
 public LinkReMapperV2(KeyValuePair<string, List<Anchor>> link, Dictionary<string, IHTMLItem> ids, BookStructureManager structureManager)
 {
     _link = link;
     _structureManager = structureManager;
     _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target;
     _linkTargetItem = ids[_idString]; // get object targeted by link
     _linkTargetDocument = GetIDParentDocument(structureManager, _linkTargetItem); // get parent document (file) containing targeted object
     if (_linkTargetDocument != null)
     {
         _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item
     }
 }
Ejemplo n.º 28
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is DefinitionDescription)
     {
         return(item.IsValid());
     }
     if (item is DefinitionTerms)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 29
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is DefinitionDescription)
     {
         return item.IsValid();
     }
     if (item is DefinitionTerms)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Extends IHTMLItem class to evaluate the size of generated output
        /// </summary>
        /// <param name="item">item to evaluate</param>
        /// <returns></returns>
        public static ulong EstimateSize(this IHTMLItem item)
        {
            var stream = new MemoryStream();
            var node   = item.Generate();
            var doc    = new XDocument();

            doc.Add(node);
            using (var writer = XmlWriter.Create(stream))
            {
                doc.WriteTo(writer);
            }
            return((ulong)stream.Length);
        }
Ejemplo n.º 31
0
 public LinkReMapperV3(KeyValuePair<string, List<Anchor>> link, IDictionary<string, HTMLItem> ids, BookStructureManager structureManager, IEPubV3Settings v3Settings)
 {
     _link = link;
     _ids = ids;
     _v3Settings = v3Settings;
     _structureManager = structureManager;
     _idString = ReferencesUtils.GetIdFromLink(link.Key); // Get ID of a link target;
     _linkTargetItem = ids[_idString]; // get object targeted by link
     _linkTargetDocument = GetItemParentDocument(_linkTargetItem); // get parent document (file) containing targeted object
     if (_linkTargetDocument != null) // if link target container document (document containing item with ID we jump to) found
     {
         _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item
     }
 }
Ejemplo n.º 32
0
 public LinkReMapperV3(KeyValuePair <string, List <Anchor> > link, IDictionary <string, HTMLItem> ids, BookStructureManager structureManager, IEPubV3Settings v3Settings)
 {
     _link               = link;
     _ids                = ids;
     _v3Settings         = v3Settings;
     _structureManager   = structureManager;
     _idString           = ReferencesUtils.GetIdFromLink(link.Key);         // Get ID of a link target;
     _linkTargetItem     = ids[_idString];                                  // get object targeted by link
     _linkTargetDocument = GetItemParentDocument(_linkTargetItem);          // get parent document (file) containing targeted object
     if (_linkTargetDocument != null)                                       // if link target container document (document containing item with ID we jump to) found
     {
         _linkParentContainer = DetectItemParentContainer(_linkTargetItem); // get parent container of link target item
     }
 }
Ejemplo n.º 33
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is Title   ||
         item is Base    ||
         item is Link    ||
         item is Meta    ||
         item is Script  ||
         item is Style   ||
         item is NoScript
         )
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 34
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is Title ||
         item is Base ||
         item is Link ||
         item is Meta ||
         item is Script ||
         item is Style ||
         item is NoScript
         )
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 35
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (
         !(item is Input) &&
         !(item is TextArea) &&
         !(item is Button) &&
         !(item is Select) &&
         !(item is Option) &&
         !(item is OptionGroup) &&
         !(item is Label) &&
         !(item is FieldSet))
     {
         return(false);
     }
     return(item.IsValid());
 }
Ejemplo n.º 36
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IInlineItem)
     {
         if (item is Anchor)
         {
             return(false);
         }
         return(item.IsValid());
     }
     if (item is SimpleHTML5Text)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Checks if XHTML element is part of current document
 /// </summary>
 /// <param name="value">elemenrt to check</param>
 /// <returns>true idf part of this document, false otherwise</returns>
 public override bool PartOfDocument(IHTMLItem value)
 {
     if (BookAnnotation == null)
     {
         return false;
     }
     IHTMLItem parent = value;
     while (parent.Parent != null)
     {
         parent = parent.Parent;
     }
     if (parent == BookAnnotation)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 38
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IInlineItem)
     {
         // TODO: check for label presence at depth
         if (item is Label)
         {
             return(false);
         }
         return(item.IsValid());
     }
     if (item is SimpleHTML5Text)
     {
         return(item.IsValid());
     }
     return(false);
 }
Ejemplo n.º 39
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IInlineItem)
     {
         // TODO: check for label presence at depth
         if (item is Label)
         {
             return false;
         }
         return item.IsValid();
     }
     if (item is SimpleHTML5Text)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Checks if XHTML element is part of current document
        /// </summary>
        /// <param name="value">element to check</param>
        /// <returns>true if part of this document, false otherwise</returns>
        public virtual bool PartOfDocument(IHTMLItem value)
        {
            if (Content == null)
            {
                return(false);
            }
            IHTMLItem parent = value;

            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            if (parent == Content)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 41
0
 /// <summary>
 /// Add used ID to the list
 /// </summary>
 /// <param name="id">Id to list as used</param>
 /// <param name="item">item that ID belong to</param>
 /// <returns>returns and registers the id if available, empty string if ID already exists</returns>
 public string AddIdUsed(string id,IHTMLItem item)
 {
     if (string.IsNullOrEmpty(id))
     {
         return id;
     }
     string newid = EnsureGoodId(id);
     if (_ids.ContainsKey(newid))
     {
         // we get here if in file same ID used twice
         // The assumption here that since the text located in FB2 main body we should not have same ID used more than once
         // otherwise we would not know how (and where to) go back
         Logger.Log.InfoFormat("item with ID {0} already defined, ignoring to avoid inconsistences", newid);
         return string.Empty;
     }
     _ids.Add(newid, item);
     return newid;
 }
Ejemplo n.º 42
0
        /// <summary>
        /// Checks if XHTML element is part of current document
        /// </summary>
        /// <param name="value">elemenrt to check</param>
        /// <returns>true idf part of this document, false otherwise</returns>
        public override bool PartOfDocument(IHTMLItem value)
        {
            if (BookAnnotation == null)
            {
                return(false);
            }
            IHTMLItem parent = value;

            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            if (parent == BookAnnotation)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 43
0
        /// <summary>
        /// Add used ID to the list
        /// </summary>
        /// <param name="id">Id to list as used</param>
        /// <param name="item">item that ID belong to</param>
        /// <returns>returns and registers the id if available, empty string if ID already exists</returns>
        public string AddIdUsed(string id, IHTMLItem item)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(id);
            }
            string newid = EnsureGoodId(id);

            if (_ids.ContainsKey(newid))
            {
                // we get here if in file same ID used twice
                // The assumption here that since the text located in FB2 main body we should not have same ID used more than once
                // otherwise we would not know how (and where to) go back
                Logger.Log.InfoFormat("item with ID {0} already defined, ignoring to avoid inconsistences", newid);
                return(string.Empty);
            }
            _ids.Add(newid, item);
            return(newid);
        }
Ejemplo n.º 44
0
        /// <summary>
        /// Loads an element and it's data from a node
        /// </summary>
        /// <param name="xNode"></param>
        public virtual void Load(XNode xNode)
        {
            if (xNode.NodeType != XmlNodeType.Element)
            {
                throw new ArgumentException("xNode is not of element type", "xNode");
            }
            string currentObjectElementName = GetObjectElementName();
            var    xElement = (XElement)xNode;

            // check that we got a element of matching (to us) type/name
            if (string.CompareOrdinal(xElement.Name.LocalName, currentObjectElementName) != 0)
            {
                throw new ArgumentException(string.Format("xNode is not {0} element, it's {1}", currentObjectElementName, xElement.Name.LocalName), "xNode");
            }
            // load attributes
            ReadAttributes(xElement);

            // load sub-items
            Subitems.Clear();
            IEnumerable <XNode> descendants = xElement.Nodes();

            foreach (var node in descendants)
            {
                IHTMLItem item = ElementFactory.CreateElement(node, _htmlStandard);
                if ((item != null) && IsValidSubType(item))
                {
                    try
                    {
                        item.Load(node);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    Subitems.Add(item);
                }
            }
            if (TextContent != null) // need to be created in constructor of derived class
            {
                TextContent.Load(xElement);
            }
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Detect parent container of the element
        /// </summary>
        /// <param name="referencedItem"></param>
        /// <returns></returns>
        private IHTMLItem DetectItemParentContainer(IHTMLItem referencedItem)
        {
            if (referencedItem is IBlockElement) // if item itself is container - return it
            {
                return referencedItem;
            }
            if (referencedItem.Parent != null)
            {
                if (referencedItem.Parent is IBlockElement) // if item is located inside container
                {
                    return referencedItem.Parent;
                }
                if (referencedItem.Parent is TextBasedElement) // if parent is text, i's ok for container
                {
                    return referencedItem.Parent;
                }
                return DetectItemParentContainer(referencedItem.Parent); // go up the inclusion chain
            }

            return null;
        }
Ejemplo n.º 46
0
        protected override bool IsValidSubType(IHTMLItem item)
        {
            if (Subitems.Count >= 2) // no more than two sub elements
            {
                return false;
            }
            if (Subitems.Count == 0) // head have to be first
            {
                if (!(item is Head)  )
                {
                    return false;
                }
            }
            if (Subitems.Count == 1) // body have to be second
            {
                if (!(item is Body)  )
                {
                    return false;
                }
            }

            return item.IsValid();
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Checks if XHTML element is part of current document
 /// </summary>
 /// <param name="value">element to check</param>
 /// <returns>true if part of this document, false otherwise</returns>
 public virtual bool PartOfDocument(IHTMLItem value)
 {
     if (Content == null)
     {
         return false;
     }
     IHTMLItem parent = value;
     while (parent.Parent != null)
     {
         parent = parent.Parent;
     }
     if (parent == Content)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 48
0
 private ulong SplitSimpleHTMLItem(IHTMLItem splitedItem, Div content, IList<IHTMLItem> resList, ulong documentSize)
 {
     ulong docSize = documentSize;
     ulong itemSize = splitedItem.EstimateSize();
     if (_checker.ExceedSizeLimit(documentSize + itemSize))
     {
         var oldContent = content;
         resList.Add(content);
         content = new Div(HTMLElementType.HTML5);
         content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value;
         content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value;
         docSize = 0;
     }
     if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document
     {
         docSize += itemSize;
         content.Add(splitedItem);
     }
     return docSize;
 }
Ejemplo n.º 49
0
 private ulong SplitBlockHTMLItem(IHTMLItem item, Div content, IList<IHTMLItem> resList, ulong documentSize)
 {
     ulong docSize = documentSize;
     ulong itemSize = item.EstimateSize();
     if (_checker.ExceedSizeLimit(documentSize + itemSize))
     {
         var oldContent = content;
         resList.Add(content);
         content = new Div(HTMLElementType.HTML5);
         content.GlobalAttributes.Class.Value = oldContent.GlobalAttributes.Class.Value;
         content.GlobalAttributes.Language.Value = oldContent.GlobalAttributes.Language.Value;
         docSize = 0;
     }
     if (!_checker.ExceedSizeLimit(itemSize)) // if we can "fit" element into a max size XHTML document
     {
         docSize += itemSize;
         content.Add(item);
     }
     else
     {
         var div = item as Div;
         if (div != null) // if the item that bigger than max size is Div block
         {
             foreach (var splitedItem in SplitDiv(div, documentSize))
             {
                 documentSize = SplitSimpleHTMLItem(splitedItem, content, resList, documentSize);
             }
         }
     }
     return docSize;
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Detect parent container of the element
 /// </summary>
 /// <param name="referencedItem"></param>
 /// <returns></returns>
 private static IHTMLItem DetectParentContainer(IHTMLItem referencedItem)
 {
     if (referencedItem is IBlockElement)
     {
         return referencedItem;
     }
     if (referencedItem.Parent is IBlockElement)
     {
         return referencedItem.Parent;
     }
     return null;
 }
Ejemplo n.º 51
0
 /// <summary>
 /// Remove sub-item 
 /// </summary>
 /// <param name="item"></param>
 public virtual void Remove(IHTMLItem item)
 {
     if (Subitems.Remove(item))
     {
         item.Parent = null;
     }
 }
Ejemplo n.º 52
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is IInlineItem)
     {
         if (item is Anchor)
         {
             return false;
         }
         return item.IsValid();
     }
     if (item is SimpleHTML5Text)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 53
0
 /// <summary>
 /// Check if item passed is valid to be inserted as a sub-item
 /// Need to be overridden in extensions to provide proper check
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 protected virtual bool IsValidSubType(IHTMLItem item)
 {
     return false; // by default nothing valid - means nothing added as subtype
 }
Ejemplo n.º 54
0
 private BaseXHTMLFileV2 GetIDParentDocument(EPubFileV2 file, IHTMLItem value)
 {
     if ((file.AnnotationPage != null) && file.AnnotationPage.PartOfDocument(value))
     {
         return file.AnnotationPage;
     }
     return file.GetIDOfParentDocument(value) as BaseXHTMLFileV2;
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Adds sub-item to the item , only if 
 /// allowed by the rules and element can accept content
 /// </summary>
 /// <param name="item">sub-item to add</param>
 public virtual void Add(IHTMLItem item)
 {
     if ((item != null) && IsValidSubType(item))
     {
         Subitems.Add(item);
         item.Parent = this;
     }
     else
     {
         throw new HTML5ViolationException();
     }
 }
Ejemplo n.º 56
0
 protected override bool IsValidSubType(IHTMLItem item)
 {
     if (item is TableData)
     {
         return item.IsValid();
     }
     if (item is TableHeaderCell)
     {
         return item.IsValid();
     }
     return false;
 }
Ejemplo n.º 57
0
 /// <summary>
 /// Adds sub item to the item , only if 
 /// allowed by the rules and element can accept content
 /// simple text can't have sub-items so it will always return false
 /// </summary>
 /// <param name="item">sub item to add</param>
 public override void Add(IHTMLItem item)
 {
     throw new Exception("This element does not contain or obtain sub items");
 }
Ejemplo n.º 58
0
 public IBaseXHTMLFile GetIDOfParentDocument(IHTMLItem value)
 {
     return _sections.FirstOrDefault(document =>
     {
         var baseXHTMLFileV2 = document as BaseXHTMLFileV2;
         return baseXHTMLFileV2 != null && baseXHTMLFileV2.PartOfDocument(value);
     });
 }
Ejemplo n.º 59
0
 private static ulong EstimateSize(IHTMLItem item)
 {
     var stream = new MemoryStream();
     XNode node = item.Generate();
     using (var writer = XmlWriter.Create(stream))
     {
         node.WriteTo(writer);
     }
     return (ulong)stream.Length;
 }
Ejemplo n.º 60
0
 private BaseXHTMLFileV2 GetIDParentDocument(BookStructureManager structureManager, IHTMLItem value)
 {
     return structureManager.GetItemParentDocument(value) as BaseXHTMLFileV2;
 }