Beispiel #1
0
        internal void Load(XElement xCoverPage)
        {
            if (xCoverPage == null)
            {
                throw new ArgumentNullException(nameof(xCoverPage));
            }

            if (xCoverPage.Name.LocalName != GetElementName())
            {
                throw new ArgumentException("Element of wrong type passed", nameof(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)
                {
                    // ignore
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Преобразования объекта типв <see cref="StyleType"/> в html
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static string ToHtml(this StyleType item)
 {
     return(item switch {
         SimpleText text => text.ToHtml(),
         InternalLinkItem link => link.ToHtml(),
         InlineImageItem image => image.ToHtml(),
         _ => item.ToString()
     });
        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);
        }
 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";
 }
 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);
 }
        /// <summary>
        /// Converts FB2 inline image
        /// </summary>
        /// <returns></returns>
        public IHTMLItem Convert(InlineImageItem inlineImageItem, InlineImageConverterParamsV3 inlineImageConverterParams)
        {
            if (inlineImageItem == null)
            {
                throw new ArgumentNullException("inlineImageItem");
            }
            var img = new Image(HTMLElementType.HTML5);

            img.Alt.Value = inlineImageItem.AltText ?? string.Empty;

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

            SetClassType(img, ElementStylesV3.InlineImage);
            return(img);
        }
Beispiel #7
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));
        }