Пример #1
0
 /// <summary>
 /// 添加到opf
 /// </summary>
 /// <param name="chName"></param>
 /// <param name="img"></param>
 /// <param name="newBook"></param>
 public static void AddImgFileList(string chName, BookImage img,Book newBook)
 {
     var fileInfo = new BookFileInfo
     {
         chName = chName,
         fileAllName = "Images/" + img.storeName + img.ext,
         fileName = img.storeName + img.ext,
         clearName = img.storeName + img.ext,
         inContents = false,
         media_type = "image/" + img.ext.Replace(".", "").Replace("jpg", "jpeg")
     };
     newBook.filelist.Add(fileInfo);
 }
Пример #2
0
        /// <summary>
        /// 复制模板的CSS,返回成功或失败
        /// </summary>
        /// <param name="toPath"></param>
        /// <param name="newBook"></param>
        /// <returns></returns>
        public static bool CopyCSS(string toPath, Book newBook)
        {
            string cssModelPathFolder = Application.StartupPath + BasePath + SofeSetting.Get("生成模板") + "/Styles";
            if (!Directory.Exists(cssModelPathFolder))
            {
                return false;
            }
            if (!Directory.Exists(toPath))
            {
                Directory.CreateDirectory(toPath);
            }
            List<BookImage> nlbi = new List<BookImage>();
            DirectoryInfo theFolder = new DirectoryInfo(cssModelPathFolder);
            FileInfo[] fi = theFolder.GetFiles("*.*");
            int cssFileCount = 0;
            foreach (FileInfo tmpfi in fi)
            {
                string extension = tmpfi.Extension.ToLower();
                if (extension == ".css")
                {
                    cssFileCount++;
                    string imgpath = tmpfi.FullName;
                    string filename = imgpath.Substring(imgpath.LastIndexOf(@"\") + 1);
                    string ext = filename.Substring(filename.LastIndexOf('.'));
                    filename = filename.Substring(0, filename.LastIndexOf('.'));

                    BookFileInfo fileInfo = new BookFileInfo();
                    fileInfo.chName = "层叠样式表";
                    fileInfo.fileAllName = "Styles/" + filename + ext;
                    fileInfo.fileName = filename + ext; //带后缀的
                    fileInfo.clearName = filename; //不带后缀的
                    fileInfo.inContents = false;
                    fileInfo.media_type = "text/css";
                    newBook.filelist.Add(fileInfo);
                }
            }

            if (cssFileCount==0)
            {
                return false;
            }
            DefaultModel.CopyFolder(cssModelPathFolder, toPath);
            return true;
        }
Пример #3
0
        /// <summary>
        /// 移动图片,在生成epub时调用
        /// </summary>
        /// <param name="path">目标路径</param>
        /// <param name="newBook"></param>
        public static void MoveImage(string path, Book newBook)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (newBook.imgCover != null && newBook.imgCover.name != "")
            {
                File.Copy(newBook.imgCover.path, path + newBook.imgCover.storeName + newBook.imgCover.ext, true);
                AddImgFileList("封面", newBook.imgCover, newBook);
            }
            if (newBook.imgBackCover != null && newBook.imgBackCover.name != "")
            {
                File.Copy(newBook.imgBackCover.path, path + newBook.imgBackCover.storeName + newBook.imgBackCover.ext, true);
                AddImgFileList("封底", newBook.imgBackCover, newBook);
            }
            if (newBook.imgContents != null && newBook.imgContents.name != "")
            {
                File.Copy(newBook.imgContents.path, path + newBook.imgContents.storeName + newBook.imgContents.ext, true);
                AddImgFileList("目录", newBook.imgContents, newBook);
            }
            foreach (BookImage bookImage in newBook.imgIllustrations)
            {
                File.Copy(bookImage.path, path + bookImage.storeName + bookImage.ext, true);
                AddImgFileList("插画", bookImage, newBook);
            }
            foreach (BookImage bookImage in newBook.imgInBook)
            {
                if (bookImage.lines.Count > 0)
                {
                    File.Copy(bookImage.path, path + bookImage.storeName + bookImage.ext, true);
                    AddImgFileList("插图", bookImage, newBook);
                }
            }

            foreach (BookImage bookImage in newBook.imgOthers)
            {
                if (bookImage.lines.Count > 0)
                {
                    File.Copy(bookImage.path, path + bookImage.storeName + bookImage.ext, true);
                    AddImgFileList("插图", bookImage, newBook);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 导入图片
        /// </summary>
        /// <param name="newBook"></param>
        public static void ImportImgs(Book newBook)
        {
            newBook.imgIllustrations = new List<BookImage>();
            newBook.imgInBook = new List<BookImage>();
            newBook.imgOthers = new List<BookImage>();
            List<BookImage> images = SearchFolder(newBook.ImgsFolder);
            int inIndex = 0;//文内插图序号
            int otherIndex = 0;//文内插图序号
            foreach (BookImage bookImage in images)
            {
                //图像书籍整理
                bookImage.type = getImgType(bookImage.name);
                if (bookImage.type == ImageType.InBook)
                {
                    bookImage.index = inIndex;
                    inIndex++;
                    //bookImage.name = bookImage.name.Replace("[in]", "").Trim().ToLower();
                }
                if (bookImage.type == ImageType.Default)
                {
                    bookImage.index = otherIndex;
                    otherIndex++;
                }
                else if (bookImage.type == ImageType.Illustration)
                    bookImage.index = int.Parse(bookImage.name);
                bookImage.storeName = _getStoreName(bookImage).ToLower();

                //图片编入书籍模型
                if (bookImage.type == ImageType.Cover)
                {
                    newBook.imgCover = bookImage;
                }
                if (bookImage.type == ImageType.BackCover)
                {
                    newBook.imgBackCover = bookImage;
                }
                else if (bookImage.type == ImageType.Contents)
                {
                    newBook.imgContents = bookImage;
                }
                else if (bookImage.type == ImageType.Illustration)
                {
                    newBook.imgIllustrations.Add(bookImage);
                }
                else if (bookImage.type == ImageType.InBook)
                {
                    newBook.imgInBook.Add(bookImage);
                }
                else
                {
                    newBook.imgOthers.Add(bookImage);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 将原始的TXT行转换为EPUB行
 /// </summary>
 /// <param name="newBook"></param>
 /// <returns></returns>
 public static Book Text2Epub(Book newBook)
 {
     string _delimiterClass = delimiterClass == "" ? "" : " class='" + delimiterClass.Trim() + "'";
     newBook.capaters = new List<Capater>();
     int capaterIndex = 0; //章节序号
     for (int i = 0; i < newBook.booklines.Count; i++)
     {
         if (IsTitle(newBook.booklines[i]))
         {
             newBook.epublines[i] = DefaultModel.GetSetting("正文标题").Replace("[%标题%]", newBook.booklines[i]);
             Capater cm = new Capater();
             cm.Name = newBook.booklines[i];
             cm.SatrtLine = i;
             cm.CapaterIndex = capaterIndex;
             cm.EndLine = newBook.booklines.Count - 1;
             if (capaterIndex > 0)
             {
                 newBook.capaters[capaterIndex - 1].EndLine = i - 1;
             }
             newBook.capaters.Add(cm);
             capaterIndex++;
         }
         else
         {
             if (IsDelimiter(newBook.booklines[i]))
                 newBook.epublines[i] = "<" + delimiterMark + _delimiterClass + ">" + newBook.booklines[i] + "</" + delimiterMark + ">";//若为分界符
             else
             {
                 newBook.epublines[i] = DefaultModel.GetSetting("正文行").Replace("[%该行内容%]", newBook.booklines[i]);
             }
         }
     }
     return newBook;
 }
Пример #6
0
 public static void CopyMisc(string toPath, Book newBook)
 {
     //复制内容
     string imageModelPath = Application.StartupPath + BasePath + SofeSetting.Get("生成模板") + "/Misc";
     if (!Directory.Exists(imageModelPath))
     {
         return;
     }
     if (!Directory.Exists(toPath))
     {
         Directory.CreateDirectory(toPath);
     }
     List<BookImage> lbis = ImgManger._searchImg(imageModelPath,"|.js|.txt|");
     foreach (var file in lbis)
     {
         var fileInfo = new BookFileInfo
         {
             chName = "文本",
             fileAllName = "Misc/" + file.storeName + file.ext,
             fileName = file.storeName + file.ext,
             clearName = file.storeName + file.ext,
             inContents = false,
             media_type = "text/plain"
         };
         newBook.filelist.Add(fileInfo);
     }
     DefaultModel.CopyFolder(imageModelPath, toPath);
 }
Пример #7
0
 /// <summary>
 /// 复制模板文件
 /// </summary>
 public static void CopyImages(string toPath,Book newBook)
 {
     //复制图片
     string imageModelPath = Application.StartupPath + BasePath + SofeSetting.Get("生成模板") + "/Images";
     if (!Directory.Exists(imageModelPath))
     {
         return;
     }
     if (!Directory.Exists(toPath))
     {
         Directory.CreateDirectory(toPath);
     }
     List<BookImage> lbis = ImgManger.SearchFolder(imageModelPath);
     foreach (var bookImage in lbis)
     {
         ImgManger.AddImgFileList("其他", bookImage, newBook);
     }
     DefaultModel.CopyFolder(imageModelPath, toPath);
 }