예제 #1
0
파일: EPUB.cs 프로젝트: dlbeer/saraswati
        public EPubFile(Stream s)
        {
            try
            {
            zip = new ZipFile(s);

            string mpath = getRootFromContainer
            (GetContent("META-INF/container.xml"));
            OPFParser.ParseStream(GetContent(mpath), mpath,
                      out Manifest, out Spine);

            if (Spine.TocId == null)
            {
            Toc = new TableOfContents();
            }
            else
            {
            string tocPath = Manifest.GetById(Spine.TocId).Linkref;

            Toc = NCXParser.ParseStream(GetContent(tocPath), tocPath);
            }

            stream = s;
            }
            catch (Exception ex)
            {
            s.Dispose();
            throw ex;
            }
        }
예제 #2
0
파일: NCX.cs 프로젝트: Ripper555/saraswati
        public static TableOfContents ParseStream(Stream s, string rel)
        {
            TableOfContents toc = new TableOfContents();
            var parser = new NCXParser(toc, rel);

            parser.Parse(s);
            return toc;
        }
예제 #3
0
파일: XHTML.cs 프로젝트: dlbeer/saraswati
        public static TableOfContents Scan(Stream s)
        {
            var result = new TableOfContents();
            var levelPath = new Stack<int>();
            int ent = -1;

            using (XmlTextReader r = new XmlTextReader(s))
            {
            r.XmlResolver = null;

            while (r.Read())
            if (r.NodeType == XmlNodeType.Element)
            {
            if ((r.Name.Length == 2) &&
                (char.ToLower(r.Name[0]) == 'h') &&
                char.IsDigit(r.Name[1]))
            {
                int level = r.Name[1] - '0';
                string id = r.GetAttribute("id");
                string text = r.ReadElementContentAsString();

                if ((id != null) && (text != null))
                {
                while ((levelPath.Count > 0) &&
                       (levelPath.Peek() >= level))
                {
                    levelPath.Pop();
                    ent = result.Parent(ent);
                }

                levelPath.Push(level);
                ent = result.AddEntry(ent);

                result.SetName(ent, text);
                result.SetLinkref(ent, id);
                }
            }
            else if (r.Name.ToLower() == "title")
            {
                result.Title = r.ReadElementContentAsString();
            }
            }
            }

            return result;
        }
예제 #4
0
파일: NCX.cs 프로젝트: Ripper555/saraswati
 public NCXParser(TableOfContents t, string rel)
 {
     toc = t;
     relPath = rel;
 }
예제 #5
0
파일: NCX.cs 프로젝트: Ripper555/saraswati
        static void PrintEntry(TableOfContents toc,
			       IDocumentConsumer doc,
			       int ent, int depth, int depthLimit)
        {
            if ((depthLimit >= 0) && (depth > depthLimit))
            return;

            doc.PushBlock(new Block() {
            Indent = depth
            });

            doc.PushFragment(new Fragment() {
            Attr = Fragment.Attributes.Heading,
            Text = toc.GetName(ent),
            Linkref = toc.GetLinkref(ent)
            });

            for (int i = toc.FirstChild(ent); i >= 0; i = toc.NextSibling(i))
            PrintEntry(toc, doc, i, depth + 1, depthLimit);
        }
예제 #6
0
파일: NCX.cs 프로젝트: Ripper555/saraswati
        public static void PrintToc(TableOfContents toc,
				    IDocumentConsumer doc,
				    int depthLimit = -1)
        {
            doc.PushBlock(new Block());
            doc.PushFragment(new Fragment() {
            Attr = Fragment.Attributes.Heading,
            Text = toc.Title
            });

            for (int i = toc.FirstRoot(); i >= 0; i = toc.NextSibling(i))
            PrintEntry(toc, doc, i, 0, depthLimit);

            doc.Close();
        }
예제 #7
0
        public SectionIndex(AnchorIndex anchor, TableOfContents toc)
        {
            for (int i = 0; i < toc.Count; i++)
            {
            int word = anchor.FindAnchor(toc.GetLinkref(i));

            if (word >= 0)
            items.Add(new Item(toc.GetName(i), word));
            }

            items.Sort(cmpWord);
        }