コード例 #1
0
        public static void ProcT2C(string path, bool replaceOriginal)
        {
            string[] lines = File.ReadAllLines(path);
            string   outpath;

            if (replaceOriginal)
            {
                outpath = path;
            }
            else
            {
                outpath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_cc" + Path.GetExtension(path));
            }
            ChineseConvert cc = new ChineseConvert();

            cc.Prepare();
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("##"))
                {
                    continue;
                }
                lines[i] = cc.Convert(lines[i]);
            }
            File.WriteAllLines(outpath, lines);
            Log.Note("Output: " + outpath);
        }
コード例 #2
0
        public GenEpub(ChineseConvertOption cc_option = ChineseConvertOption.None)
        {
            this.cc_option = cc_option;
            if (cc_option == ChineseConvertOption.T2S)
            {
                Log.log("[Info]Chinese Convert: T2S");
                cc = new ChineseConvert();
                cc.Prepare();
            }

            TextItem t = epub.GetItem <TextItem>("OEBPS/Text/template.xhtml");

            xhtml_temp = t.data;
            epub.items.Remove(t);
        }
コード例 #3
0
ファイル: GenEPUB.cs プロジェクト: yihuil1992/AeroNovel
        public GenEpub(ChineseConvertOption cc_option = ChineseConvertOption.None)
        {
            this.cc_option = cc_option;
            if (cc_option == ChineseConvertOption.T2S)
            {
                Log.Note("Chinese Convert: T2S");
                cc = new ChineseConvert();
                cc.Prepare();
            }

            TextEpubItemFile t = epub.GetFile <TextEpubItemFile>("OEBPS/Text/template.xhtml");

            xhtml_temp = t.text;
            epub.items.Remove(t);
        }
コード例 #4
0
        public EpubFile Gen(string dir)
        {
            if (cc_option == ChineseConvertOption.T2S)
            {
                Log.Note("Chinese Convert: T2S");
                cc = new ChineseConvert();
                cc.Prepare();
            }
            if (!indentAdjust)
            {
                Log.Note("Option: No indent adjustion.");
            }
            if (!addInfo)
            {
                Log.Note("Qption: Do not add generation info.");
            }

            this.dir = dir;

            string metaPath = Path.Combine(dir, "meta.txt");

            if (File.Exists(Path.Combine(dir, "meta3.txt")))
            {
                metaPath   = Path.Combine(dir, "meta3.txt");
                version    = "3.0";
                xhtml_temp = Regex.Replace(xhtml_temp, "<!DOCTYPE html([\\s\\S]*?)>", "<!DOCTYPE html>");
            }

            if (File.Exists(Path.Combine(dir, "macros.txt")))
            {
                Log.Info("Read macros.txt");
                string[] macros_raw = File.ReadAllLines(Path.Combine(dir, "macros.txt"));
                macros = new Dictionary <string, string>();
                foreach (string macro in macros_raw)
                {
                    string[] s = macro.Split('\t');
                    if (s.Length < 2)
                    {
                        Log.Warn("Macro defination is not complete. Use tab to separate: " + macro);
                    }
                    macros.Add(s[0], s[1]);
                }
            }

            string meta = File.ReadAllText(metaPath);

            meta = meta.Replace("{urn:uuid}", uid);
            uid  = Regex.Match(meta, "<dc:identifier id=\"BookId\">(.*?)</dc:identifier>").Groups[1].Value;
            meta = meta.Replace("{date}", DateTime.Today.ToString("yyyy-MM-ddT00:00:00Z"));
            if (cc != null)
            {
                meta = cc.Convert(meta);
            }
            if (cc_option == ChineseConvertOption.T2S)
            {
                meta = meta.Replace("<dc:language>zh-tw</dc:language>", "<dc:language>zh</dc:language>", true, null);
            }
            title = Regex.Match(meta, "<dc:title.*?>(.*?)</dc:title>").Groups[1].Value;

            GenFileNames();
            GenContent();
            GetImage();
            GetCss();

            TextEpubItemFile toc = epub.GetFile <TextEpubItemFile>("OEBPS/toc.ncx");
            TextEpubItemFile nav = epub.GetFile <TextEpubItemFile>("OEBPS/nav.xhtml");

            if (version == "2.0")
            {
                epub.items.Remove(nav);
                var tocDocuments = GenTOC(File.ReadAllLines(Path.Combine(dir, "toc.txt")), uid, title, toc.text);
                toc.text = tocDocuments.Item1;
            }
            else
            {
                var tocDocuments = GenTOC(File.ReadAllLines(Path.Combine(dir, "toc.txt")), uid, title, toc.text, nav.text);
                toc.text = tocDocuments.Item1;
                nav.text = tocDocuments.Item2;
                items   += "    <item id=\"nav.xhtml\" href=\"nav.xhtml\" media-type=\"application/xhtml+xml\" properties=\"nav\"/>";
            }

            TextEpubItemFile opf = epub.GetFile <TextEpubItemFile>("OEBPS/content.opf");

            opf.text = string.Format(opf.text, meta, items, spine, version);

            epub.ReadMeta();
            return(epub);
        }