Package com.adobe.dp.epub.ncx

Examples of com.adobe.dp.epub.ncx.TOCEntry


          break;
        }
      }
      if (headings.size() < depth + 1) {
        String title = getText();
        TOCEntry entry = new TOCEntry(title, getSelfRef());
        level.getTOCEntry().add(entry);
        TOCLevel myLevel = new TOCLevel(headingLevel, entry);
        headings.push(myLevel);
      }
    }
View Full Code Here


  public void splitLargeChapters() {
    splitLargeChapters(100000);
  }

  public void generateTOCFromHeadings(int depth) {
    TOCEntry entry = getTOC().getRootTOCEntry();
    entry.removeAll();
    Iterator spine = spine();
    Stack headings = new Stack();
    headings.push(new TOCLevel(0, entry));
    while (spine.hasNext()) {
      Resource r = (Resource) spine.next();
View Full Code Here

  public TOCEntry getRootTOCEntry() {
    return rootTOCEntry;
  }

  public TOCEntry createTOCEntry(String title, XRef xref) {
    return new TOCEntry(title, xref);
  }
View Full Code Here

  private static int calculateDepth(TOCEntry entry) {
    Iterator it = entry.content();
    int maxDepth = 0;
    while (it.hasNext()) {
      TOCEntry child = (TOCEntry) it.next();
      int depth = calculateDepth(child);
      if (depth > maxDepth)
        maxDepth = depth;
    }
    return maxDepth + 1;
View Full Code Here

  }

  private void serializeChildEntries(TOCEntry entry, XMLSerializer ser) {
    Iterator it = entry.content();
    while (it.hasNext()) {
      TOCEntry child = (TOCEntry) it.next();
      SMapImpl attrs = new SMapImpl();
      attrs.put(null, "playOrder", Integer.toString(child.getXRef().getPlayOrder()));
      attrs.put(null, "id", "id" + entryCount);
      entryCount++;
      ser.startElement(ncxns, "navPoint", attrs, false);
      ser.newLine();
      ser.startElement(ncxns, "navLabel", null, false);
      ser.newLine();
      ser.startElement(ncxns, "text", null, false);
      String title = child.getTitle();
      if (title == null)
        title = "";
      if (epub.isTranslit())
        title = Translit.translit(title);
      char[] arr = title.toCharArray();
      ser.text(arr, 0, arr.length);
      ser.endElement(ncxns, "text");
      ser.newLine();
      ser.endElement(ncxns, "navLabel");
      ser.newLine();
      attrs = new SMapImpl();
      attrs.put(null, "src", child.getXRef().makeReference(this));
      ser.startElement(ncxns, "content", attrs, false);
      ser.endElement(ncxns, "content");
      ser.newLine();
      serializeChildEntries(child, ser);
      ser.endElement(ncxns, "navPoint");
View Full Code Here

      epub.addDCMetadata("creator", System.getProperty("user.name"));
      epub.addDCMetadata("language", "en");

      // prepare table of contents
      NCXResource toc = epub.getTOC();
      TOCEntry rootTOCEntry = toc.getRootTOCEntry();

      // create a stylesheet
      StyleResource style = epub.createStyleResource("OPS/styles.css");
      Stylesheet stylesheet = style.getStylesheet();

      // style h1 element
      Selector h1Selector = stylesheet.getSimpleSelector("h1", null);
      SelectorRule h1Rule = stylesheet.getRuleForSelector(h1Selector,
          true);
      h1Rule.set("color", new CSSName("gray"));
      CSSValue[] border = { new CSSLength(2, "px"), new CSSName("solid"),
          new CSSName("gray") };
      h1Rule.set("border-bottom", new CSSValueList(' ', border));
      h1Rule.set("text-align", new CSSName("right"));
      CSSValue[] margin = { new CSSLength(2, "em"),
          new CSSLength(8, "px"), new CSSLength(1, "em"),
          new CSSLength(0, "px") };
      h1Rule.set("margin", new CSSValueList(' ', margin));

      // style p element
      Selector pSelector = stylesheet.getSimpleSelector("p", null);
      SelectorRule pRule = stylesheet.getRuleForSelector(pSelector, true);
      pRule.set("margin", new CSSLength(0, "px"));
      pRule.set("text-indent", new CSSLength(1, "em"));
      pRule.set("text-align", new CSSName("justify"));

      // create first chapter resource
      OPSResource chapter1 = epub.createOPSResource("OPS/chapter1.html");
      epub.addToSpine(chapter1);

      // get chapter document
      OPSDocument chapter1Doc = chapter1.getDocument();

      // link our stylesheet
      chapter1Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter1TOCEntry = toc.createTOCEntry("Chapter 1",
          chapter1Doc.getRootXRef());
      rootTOCEntry.add(chapter1TOCEntry);

      // chapter XHTML body element
      Element body1 = chapter1Doc.getBody();

      // add a header
      Element header1 = chapter1Doc.createElement("h1");
      header1.add("One");
      body1.add(header1);

      // add a paragraph
      Element paragraph1 = chapter1Doc.createElement("p");
      StringBuffer sb1 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb1.append("This is sentence " + i
            + " of the first chapter's first paragraph. ");
      paragraph1.add(sb1.toString());
      body1.add(paragraph1);

      // create second chapter resource
      OPSResource chapter2 = epub.createOPSResource("OPS/chapter2.html");
      epub.addToSpine(chapter2);

      // get chapter document
      OPSDocument chapter2Doc = chapter2.getDocument();

      // link our stylesheet
      chapter2Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter2TOCEntry = toc.createTOCEntry("Chapter 2",
          chapter2Doc.getRootXRef());
      rootTOCEntry.add(chapter2TOCEntry);

      // chapter XHTML body element
      Element body2 = chapter2Doc.getBody();
View Full Code Here

      epub.addDCMetadata("creator", System.getProperty("user.name"));
      epub.addDCMetadata("language", "en");

      // prepare table of contents
      NCXResource toc = epub.getTOC();
      TOCEntry rootTOCEntry = toc.getRootTOCEntry();

      // create new chapter resource
      OPSResource main = epub.createOPSResource("OPS/main.html");
      epub.addToSpine(main);

      // get chapter document
      OPSDocument mainDoc = main.getDocument();

      // add chapter to the table of contents
      TOCEntry mainTOCEntry = toc.createTOCEntry("Intro", mainDoc
          .getRootXRef());
      rootTOCEntry.add(mainTOCEntry);

      // chapter XHTML body element
      Element body = mainDoc.getBody();
View Full Code Here

      epub.addDCMetadata("creator", System.getProperty("user.name"));
      epub.addDCMetadata("language", "en");

      // prepare table of contents
      NCXResource toc = epub.getTOC();
      TOCEntry rootTOCEntry = toc.getRootTOCEntry();

      // create a stylesheet
      StyleResource style = epub.createStyleResource("OPS/styles.css");
      Stylesheet stylesheet = style.getStylesheet();

      // style h1 element
      Selector h1Selector = stylesheet.getSimpleSelector("h1", null);
      SelectorRule h1Rule = stylesheet.getRuleForSelector(h1Selector,
          true);
      h1Rule.set("color", new CSSName("gray"));
      CSSValue[] border = { new CSSLength(2, "px"), new CSSName("solid"),
          new CSSName("gray") };
      h1Rule.set("border-bottom", new CSSValueList(' ', border));
      h1Rule.set("text-align", new CSSName("right"));
      CSSValue[] margin = { new CSSLength(2, "em"),
          new CSSLength(8, "px"), new CSSLength(1, "em"),
          new CSSLength(0, "px") };
      h1Rule.set("margin", new CSSValueList(' ', margin));
      h1Rule.set("font-family", new CSSQuotedString("Adobe Garamond Pro"));

      // style p element
      Selector pSelector = stylesheet.getSimpleSelector("p", null);
      SelectorRule pRule = stylesheet.getRuleForSelector(pSelector, true);
      pRule.set("margin", new CSSLength(0, "px"));
      pRule.set("text-indent", new CSSLength(1, "em"));
      pRule.set("text-align", new CSSName("justify"));
      h1Rule.set("font-family", new CSSQuotedString("Chaparral Pro"));

      // style bitmap class (JPEG image)
      Selector bitmapSelector = stylesheet.getSimpleSelector(null,
          "bitmap");
      SelectorRule bitmapRule = stylesheet.getRuleForSelector(
          bitmapSelector, true);
      bitmapRule.set("width", new CSSLength(80, "%"));
      bitmapRule.set("max-width", new CSSLength(553, "px"));

      // style container class (container for JPEG image)
      Selector containerSelector = stylesheet.getSimpleSelector("p",
          "container");
      SelectorRule containerRule = stylesheet.getRuleForSelector(
          containerSelector, true);
      containerRule.set("text-align", new CSSName("center"));
      containerRule.set("text-indent", new CSSLength(0, "px"));
      CSSValue[] padval = { new CSSLength(0.5, "em"), new CSSLength(0, "px") };
      containerRule.set("padding", new CSSValueList(' ', padval));

      // style svgimage class (embedded SVG)
      Selector svgimageSelector = stylesheet.getSimpleSelector(null,
          "svgimage");
      SelectorRule svgimageRule = stylesheet.getRuleForSelector(svgimageSelector, true);
      svgimageRule.set("width", new CSSLength(80, "%"));
      CSSValue[] padval1 = { new CSSLength(0.5, "em"), new CSSLength(10, "%") };
      svgimageRule.set("padding", new CSSValueList(' ', padval1));

      // style label1 class (text in embedded SVG)
      Selector label1Selector = stylesheet.getSimpleSelector(null,
          "label1");
      SelectorRule label1Rule = stylesheet.getRuleForSelector(label1Selector, true);
      label1Rule.set("font-size", new CSSLength(36, "px"));
      label1Rule.set("font-family", new CSSQuotedString("Chaparral Pro"));

      // style label2 class (text in embedded SVG)
      Selector label2Selector = stylesheet.getSimpleSelector(null,
          "label2");
      SelectorRule label2Rule = stylesheet.getRuleForSelector(label2Selector, true);
      label2Rule.set("font-size", new CSSLength(48, "px"));
      label2Rule.set("font-family", new CSSQuotedString("Comic Sans MS"));

      // create first chapter resource
      OPSResource chapter1 = epub.createOPSResource("OPS/chapter1.html");
      epub.addToSpine(chapter1);

      // get chapter document
      OPSDocument chapter1Doc = chapter1.getDocument();

      // link our stylesheet
      chapter1Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter1TOCEntry = toc.createTOCEntry("Chapter 1",
          chapter1Doc.getRootXRef());
      rootTOCEntry.add(chapter1TOCEntry);

      // chapter XHTML body element
      Element body1 = chapter1Doc.getBody();

      // add a header
      Element header1 = chapter1Doc.createElement("h1");
      header1.add("One");
      body1.add(header1);

      // add a paragraph
      Element paragraph1 = chapter1Doc.createElement("p");
      StringBuffer sb1 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb1.append("This is sentence " + i
            + " of the first chapter's first paragraph. ");
      paragraph1.add(sb1.toString());
      body1.add(paragraph1);

      // add SVG graphics area
      SVGElement svg = chapter1Doc.createSVGElement("svg");
      svg.setAttribute("viewBox", "0 0 400 200");
      svg.setClassName("svgimage");
      body1.add(svg);

      // draw background
      SVGElement bg = chapter1Doc.createSVGElement("rect");
      bg.setAttribute("x", "1");
      bg.setAttribute("y", "1");
      bg.setAttribute("width", "398");
      bg.setAttribute("height", "198");
      bg.setAttribute("stroke", "black");
      bg.setAttribute("stroke-width", "2");
      bg.setAttribute("fill", "#FFF8EE");
      svg.add(bg);

      // draw a shape
      SVGElement path = chapter1Doc.createSVGElement("path");
      path.setAttribute("fill", "none");
      path.setAttribute("stroke", "black");
      path.setAttribute("stroke-width", "4");
      String resistorPath = "M90 120h50l10 20l20-40l20 40l20-40l20 40l20-40l20 40l20-40l20 40l10-20h50";
      path.setAttribute("d", resistorPath);
      svg.add(path);

      // draw a label
      SVGElement label1 = chapter1Doc.createSVGElement("text");
      label1.setClassName("label1");
      label1.setAttribute("x", "150");
      label1.setAttribute("y", "60");
      label1.add("R = 30\u03A9");
      svg.add(label1);

      // draw rotated label
      SVGElement label2 = chapter1Doc.createSVGElement("text");
      label2.setClassName("label2");
      label2.setAttribute("transform", "translate(40 110)rotate(-75)");
      SVGElement t1 = chapter1Doc.createSVGElement("tspan");
      t1.setAttribute("fill", "red");
      t1.add("S");
      label2.add(t1);
      SVGElement t2 = chapter1Doc.createSVGElement("tspan");
      t2.setAttribute("fill", "green");
      t2.add("V");
      label2.add(t2);
      SVGElement t3 = chapter1Doc.createSVGElement("tspan");
      t3.setAttribute("fill", "blue");
      t3.add("G");
      label2.add(t3);
      svg.add(label2);

      // create a small paragraph to use as a link target
      Element target = chapter1Doc.createElement("p");
      target.add("Link in the second chapter points here.");
      body1.add(target);

      // create second chapter resource
      OPSResource chapter2 = epub.createOPSResource("OPS/chapter2.html");
      epub.addToSpine(chapter2);

      // get chapter document
      OPSDocument chapter2Doc = chapter2.getDocument();

      // link our stylesheet
      chapter2Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter2TOCEntry = toc.createTOCEntry("Chapter 2",
          chapter2Doc.getRootXRef());
      rootTOCEntry.add(chapter2TOCEntry);

      // chapter XHTML body element
      Element body2 = chapter2Doc.getBody();
View Full Code Here

        return false;

    }

    public void addTocEntry(String title, int headingLevel, Element dstElem) {
        TOCEntry te = getToc().createTOCEntry(title, dstElem.getSelfRef());
        boolean found = false;
        for (int j = getTocEntriesBuffer().size() - 1; j >= 0; j--) {

            TOCLevel target = getTocEntriesBuffer().get(j);
            if (target.getHeadingLevel() < headingLevel) {
View Full Code Here

TOP

Related Classes of com.adobe.dp.epub.ncx.TOCEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.