Exemplo n.º 1
0
        internal void Load(XElement xCoverpage)
        {
            if (xCoverpage == null)
            {
                throw new ArgumentNullException("xCoverpage");
            }

            if (xCoverpage.Name.LocalName != GetElementName())
            {
                throw new ArgumentException("Element of wrong type passed", "xCoverpage");
            }

            coverimages.Clear();
            IEnumerable<XElement> xImages = xCoverpage.Elements(fileNameSpace +InlineImageItem.Fb2InlineImageElementName);
            foreach (var xImage in xImages)
            {
                InlineImageItem image = new InlineImageItem();
                try
                {
                    image.Load(xImage);
                    coverimages.Add(image);
                }
                catch (Exception)
                {
                }

            }
        }
Exemplo n.º 2
0
 private Image CreateCoverImage(InlineImageItem item, HRefManagerV2 refManagerV2)
 {
     var coverImage = new Image(Compatibility);
     coverImage.GlobalAttributes.Class.Value = ElementStylesV2.CoverImage;
     coverImage.Source.Value = refManagerV2.AddImageRefferenced(item, coverImage);
     coverImage.Alt.Value = "Cover";
     return coverImage;
 }
Exemplo n.º 3
0
 public CoverPageFileV2(InlineImageItem item, HRefManagerV2 refManagerV2)
 {
     _coverImage = CreateCoverImage(item, refManagerV2);
     InternalPageTitle = "Cover";
     GuideRole = GuideTypeEnum.Cover;
     Id = "cover";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     FileName = "cover.xhtml";
 }
Exemplo n.º 4
0
 public CoverPageFileV3(InlineImageItem item,HRefManagerV3 refManagerV3)
 {
     _coverImage = CreateCoverImage(item,refManagerV3);
     InternalPageTitle = "Cover";
     GuideRole = GuideTypeEnum.Cover;
     Id = "cover";
     FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder);
     FileName = "cover.xhtml";
     SetDocumentEpubType(EpubV3Vocabulary.Cover);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Converts FB2 inline image
        /// </summary>
        /// <returns></returns>
        public IHTMLItem Convert(InlineImageItem inlineImageItem,InlineImageConverterParamsV2 inlineImageConverterParams)
        {
            if (inlineImageItem == null)
            {
                throw new ArgumentNullException("inlineImageItem");
            }
            var img = new Image(HTMLElementType.XHTML11);
            img.Alt.Value = inlineImageItem.AltText ?? string.Empty; // ePub require image always to have attribute

            img.Source.Value = inlineImageConverterParams.Settings.ReferencesManager.AddImageRefferenced(inlineImageItem, img);

            SetClassType(img, ElementStylesV2.InlineImage);
            return img;
        }
Exemplo n.º 6
0
 public string AddImageRefferenced(InlineImageItem item, Image img)
 {
     if (item == null)
     {
         return string.Empty;
     }
     string validName = MakeValidImageName(item.HRef);
     if (!_images.ContainsKey(validName))
     {
         var entryList = new List<Image>();
         _images.Add(validName, entryList);
     }
     _images[validName].Add(img);
     return ReferencesUtils.FormatImagePath(validName,FlatStructure);
 }
Exemplo n.º 7
0
        internal void Load(XElement xLink)
        {
            if (xLink == null)
            {
                throw new ArgumentNullException(nameof(xLink));
            }
            if (xLink.Name.LocalName != Fb2InternalLinkElementName)
            {
                throw new ArgumentException("Element of wrong type passed", nameof(xLink));
            }

            if (xLink.HasElements)
            {
                IEnumerable <XNode> childElements = xLink.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                _linkData.Add(image);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItem.StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                _linkData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }
                    else
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            _linkData.Add(text);
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xLink.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xLink);
                _linkData.Add(text);
            }

            XAttribute xTypeAttr = xLink.Attribute("type");

            if (xTypeAttr != null && xTypeAttr.Value != null)
            {
                Type = xTypeAttr.Value;
            }

            XAttribute xHRefAttr = xLink.Attribute(lNamespace + "href");

            if (xHRefAttr != null && xHRefAttr.Value != null)
            {
                HRef = xHRefAttr.Value;
            }
        }
Exemplo n.º 8
0
 public void Load(XNode xText)
 {
     subtext.Clear();
     if (xText == null)
     {
         throw new ArgumentNullException("xText");
     }
     switch (xText.NodeType)
     {
         case XmlNodeType.Text:
             XText textNode = (XText) xText;
             if (!string.IsNullOrEmpty(textNode.Value))
             {
                 Text = textNode.Value;
                 style = TextStyles.Normal;
             }
             break;
         case XmlNodeType.Element:
             XElement xTextElement = (XElement)xText;
             if (xTextElement.HasElements)
             {
                 Text = string.Empty;
                 style = GetStyle(xTextElement.Name.LocalName);
                 IEnumerable<XNode> childElements = xTextElement.Nodes();
                 foreach (var node in childElements)
                 {
                     if (node.NodeType == XmlNodeType.Element)
                     {
                         XElement element = (XElement) node;
                         switch (element.Name.LocalName)
                         {
                             case InternalLinkItem.Fb2InternalLinkElementName:
                                 InternalLinkItem link = new InternalLinkItem();
                                 try
                                 {
                                     link.Load(element);
                                     subtext.Add(link);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                             case InlineImageItem.Fb2InlineImageElementName:
                                 InlineImageItem image = new InlineImageItem();
                                 try
                                 {
                                     image.Load(element);
                                     subtext.Add(image);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                             default:
                                 SimpleText text = new SimpleText();
                                 try
                                 {
                                     text.Load(element);
                                     subtext.Add(text);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                         }
                     }
                     else
                     {
                         SimpleText text = new SimpleText();
                         try
                         {
                             text.Load(node);
                             subtext.Add(text);
                         }
                         catch (Exception)
                         {
                             continue;
                         }
                     }
                 }
             }
             else
             {
                 style = GetStyle(xTextElement.Name.LocalName);
                 Text = xTextElement.Value;
                 //switch (xTextElement.Name.LocalName)
                 //{
                 //    case "strong":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "emphasis":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "code":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "sub":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "sup":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "strikethrough":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    default:
                 //        Text = xTextElement.Value;
                 //        break;
                 //}
             }
             break;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Load element data from the node
        /// </summary>
        /// <param name="xStyle"></param>
        public void Load(XElement xStyle)
        {
            if (xStyle == null)
            {
                throw new ArgumentNullException("style");
            }
            if (xStyle.Name.LocalName != StyleItemName)
            {
                throw new ArgumentException(string.Format("The element is of type {0} while StyleItem accepts only {1} types", xStyle.Name.LocalName, StyleItemName));
            }

            Lang = null;
            XAttribute xLang = xStyle.Attribute(XNamespace.Xml + "lang");

            if (xLang != null)
            {
                Lang = xLang.Value;
            }

            Name = string.Empty;
            XAttribute xName = xStyle.Attribute("name");

            if (xName != null && xName.Value != null)
            {
                Name = xName.Value;
            }

            if (xStyle.HasElements)
            {
                IEnumerable <XNode> childElements = xStyle.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                StyleData.Add(image);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                StyleData.Add(linkItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                StyleData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            StyleData.Add(text);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xStyle.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xStyle);
                StyleData.Add(text);
            }
        }
Exemplo n.º 10
0
        public void Load(XNode xText)
        {
            subtext.Clear();
            if (xText == null)
            {
                throw new ArgumentNullException("xText");
            }
            switch (xText.NodeType)
            {
            case XmlNodeType.Text:
                XText textNode = (XText)xText;
                if (!string.IsNullOrEmpty(textNode.Value))
                {
                    Text  = textNode.Value;
                    style = TextStyles.Normal;
                }
                break;

            case XmlNodeType.Element:
                XElement xTextElement = (XElement)xText;
                if (xTextElement.HasElements)
                {
                    Text  = string.Empty;
                    style = GetStyle(xTextElement.Name.LocalName);
                    IEnumerable <XNode> childElements = xTextElement.Nodes();
                    foreach (var node in childElements)
                    {
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            XElement element = (XElement)node;
                            switch (element.Name.LocalName)
                            {
                            case InternalLinkItem.Fb2InternalLinkElementName:
                                InternalLinkItem link = new InternalLinkItem();
                                try
                                {
                                    link.Load(element);
                                    subtext.Add(link);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;

                            case InlineImageItem.Fb2InlineImageElementName:
                                InlineImageItem image = new InlineImageItem();
                                try
                                {
                                    image.Load(element);
                                    subtext.Add(image);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;

                            default:
                                SimpleText text = new SimpleText();
                                try
                                {
                                    text.Load(element);
                                    subtext.Add(text);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;
                            }
                        }
                        else
                        {
                            SimpleText text = new SimpleText();
                            try
                            {
                                text.Load(node);
                                subtext.Add(text);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    style = GetStyle(xTextElement.Name.LocalName);
                    Text  = xTextElement.Value;
                    //switch (xTextElement.Name.LocalName)
                    //{
                    //    case "strong":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "emphasis":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "code":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "sub":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "sup":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "strikethrough":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    default:
                    //        Text = xTextElement.Value;
                    //        break;
                    //}
                }
                break;
            }
        }
Exemplo n.º 11
0
        protected void LoadData(XElement xParagraph)
        {
            if (xParagraph.HasElements)
            {
                IEnumerable <XNode> childElements = xParagraph.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                paragraphData.Add(image);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                paragraphData.Add(linkItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItem.StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                paragraphData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else //if ( element.NodeType != XmlNodeType.Whitespace)
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            paragraphData.Add(text);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xParagraph.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xParagraph);
                paragraphData.Add(text);
            }

            XAttribute xID = xParagraph.Attribute("id");

            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }

            XAttribute xStyle = xParagraph.Attribute("style");

            if ((xStyle != null) && (xStyle.Value != null))
            {
                Style = xStyle.Value;
            }

            Lang = null;
            XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang");

            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
        }
Exemplo n.º 12
0
        protected void LoadData(XElement xParagraph)
        {
            if (xParagraph.HasElements)
            {
                IEnumerable<XNode> childElements = xParagraph.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement) element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                paragraphData.Add(image);

                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                paragraphData.Add(linkItem);

                            }
                            catch (Exception)
                            {
                            }                            
                        }
                    }
                    else //if ( element.NodeType != XmlNodeType.Whitespace)
                    {
                            SimpleText text = new SimpleText();
                            try
                            {
                                text.Load(element);
                                paragraphData.Add(text);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                    }
                }
               
            }
            else if (!string.IsNullOrEmpty(xParagraph.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xParagraph);
                paragraphData.Add(text);
            }

            XAttribute xID = xParagraph.Attribute("id");
            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }

            XAttribute xStyle = xParagraph.Attribute("style");
            if ((xStyle != null) && (xStyle.Value != null))
            {
                Style = xStyle.Value;
            }

            Lang = null;
            XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
            
        }