Package com.adobe.dp.epub.ops

Examples of com.adobe.dp.epub.ops.Element$SizeRemains


      return null;
    if (r instanceof OPSResource) {
      OPSDocument ops = ((OPSResource) r).getDocument();
      if (id == null)
        return ops.getRootXRef();
      Element e = ops.getElementById(id);
      if (e != null)
        return e.getSelfRef();
    }
    XRef ref;
    if (unresolvedXRefMap == null || (ref = (XRef) unresolvedXRefMap.get(id)) == null) {
      if (unresolvedXRefMap == null)
        unresolvedXRefMap = new Hashtable();
View Full Code Here


        continue;
      // chapter change: move back to the chapter boundary
      lastResource = resource;
      if (page.xref.getTargetId() != null) {
        if (report) {
          Element p = resource.getDocument().getBody();
          Element t = page.xref.getTagetElement();
          while (p != t) {
            Iterator it = p.content();
            if (!it.hasNext())
              break;
            Object f = it.next();
View Full Code Here

      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();

      // add a header
      Element header2 = chapter1Doc.createElement("h1");
      header2.add("Two");
      body2.add(header2);

      // add a paragraph
      Element paragraph2 = chapter2Doc.createElement("p");
      StringBuffer sb2 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb2.append("This is sentence " + i
            + " of the second chapter's first paragraph. ");
      paragraph2.add(sb2.toString());
      body2.add(paragraph2);

      // add a bitmap resource
      DataSource dataSource = new ResourceDataSource(HelloEPUB3.class,
          "cassini.jpg");
      BitmapImageResource imageResource = epub.createBitmapImageResource(
          "OPS/images/cassini.jpg", "image/jpeg", dataSource);

      // add a bitmap image
      Element container = chapter2Doc.createElement("p");
      container.setClassName("container");
      body2.add(container);
      ImageElement bitmap = chapter2Doc.createImageElement("img");
      bitmap.setClassName("bitmap");
      bitmap.setImageResource(imageResource);
      container.add(bitmap);

      // and another paragraph
      Element paragraph3 = chapter2Doc.createElement("p");
      StringBuffer sb3 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb3.append("This is sentence " + i
            + " of the second chapter's second paragraph. ");
      paragraph3.add(sb3.toString());
      body2.add(paragraph3);

      // add a link to the target paragraph in the first chapter
      HyperlinkElement a = chapter2Doc.createHyperlinkElement("a");
      a.setXRef(target.getSelfRef());
      a.add("Here is a link.");
      paragraph3.add(a);

      // embed fonts
      // NB: on non-Windows platforms you need to supply your own
      // FontLocator implementation or place fonts in ~/.epubfonts
      FontLocator fontLocator = DefaultFontLocator.getInstance();
View Full Code Here

      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();

      // add a header
      Element header2 = chapter1Doc.createElement("h1");
      header2.add("Two");
      body2.add(header2);

      // add a paragraph
      Element paragraph2 = chapter2Doc.createElement("p");
      StringBuffer sb2 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb2.append("This is sentence " + i
            + " of the second chapter's first paragraph. ");
      paragraph2.add(sb2.toString());
      body2.add(paragraph2);

      // and another one
      Element paragraph3 = chapter2Doc.createElement("p");
      StringBuffer sb3 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb3.append("This is sentence " + i
            + " of the second chapter's second paragraph. ");
      paragraph3.add(sb3.toString());
      body2.add(paragraph3);

      // save EPUB to an OCF container
      OCFContainerWriter writer = new OCFContainerWriter(
          new FileOutputStream("hello.epub"));
View Full Code Here

      TOCEntry mainTOCEntry = toc.createTOCEntry("Intro", mainDoc
          .getRootXRef());
      rootTOCEntry.add(mainTOCEntry);

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

      // add a header
      Element h1 = mainDoc.createElement("h1");
      h1.add("My First EPUB");
      body.add(h1);

      // add a paragraph
      Element paragraph = mainDoc.createElement("p");
      paragraph.add("Hello, world!");
      body.add(paragraph);

      // save EPUB to an OCF container
      OCFContainerWriter writer = new OCFContainerWriter(
          new FileOutputStream("hello.epub"));
View Full Code Here

    }

    public void traverse(Node e, Element dstElement) throws Exception {
        classesForDebug.add(e.getClass().toString());
        boolean skipChildren = false;
        Element newElement = null;
        /**
         * Original ODT's element evalutation
         */
        if (e instanceof TextNoteBodyElement) {// Corpo di una nota
            TextNoteBodyElement noteBody = (TextNoteBodyElement) e;
        } else if (e instanceof TextNoteCitationElement) {// Rimando ad una nota

        } else if (e instanceof OfficeTextElement) {// OFFICE
            OfficeTextElement ote = (OfficeTextElement) e;

        } else if (e instanceof OfficeScriptsElement) {// OFFICE

        } else if (e instanceof OfficeDocumentContentElement) {// OFFICE

        } else if (e instanceof OdfOfficeAutomaticStyles) {// OFFICE

        } else if (e instanceof OfficeBodyElement) {// OFFICE

        } else if (e instanceof TextSElement) {// ?
            TextSElement te = (TextSElement) e;

        } else if (e instanceof TextAElement) {// is an hyperlink
            TextAElement ta = (TextAElement) e;
            String ref = ta.getAttribute("xlink:href");

            HyperlinkElement a = getCurrentResource().getDocument().createHyperlinkElement("a");
            if (ref.startsWith("#")) {// internal Link
                a.setTitle(ta.getAttribute("xlink:href"));
                getInternalLink().add(a);
            } else {
                a.setExternalHRef(ref);
            }
            dstElement.add(a);
            // a.add("ciao");
            traverse(ta.getFirstChild(), a);
            skipChildren = true;

        } else if (e instanceof TextBookmarkElement) {// is bookmark in epub can
                                                      // be used to implement
                                                      // internal link anchors
            TextBookmarkElement ta = (TextBookmarkElement) e;

            HyperlinkElement a = getCurrentResource().getDocument().createHyperlinkElement("a");
            a.setId(ta.getAttribute("text:name"));
            dstElement.add(a);
            getBookmarks().put("#" + ta.getAttribute("text:name"), a);
        } else if (e instanceof TextNoteElement) {// Is a footnote container
            addFootnote((TextNoteElement) e, dstElement);
            skipChildren = true;
        } else if (e instanceof OdfDrawFrame) {
            OdfDrawFrame dframe = (OdfDrawFrame) e;
        // if(!(dframe.getParentNode().getParentNode() instanceof DrawTextBoxElement)){
            // here can be captured resize options
            newElement = addImageBox(dframe, dstElement);
         //}

        } else if (e instanceof DrawTextBoxElement) {
            DrawTextBoxElement didascalia = (DrawTextBoxElement) e;
       

        } else if (e instanceof OdfDrawImage) {
            addImage((OdfDrawImage) e, dstElement);

        } else if (e instanceof OdfTextList) {
            OdfTextList otl = (OdfTextList) e;
            dstElement = getCurrentResource().getDocument().getBody();
            /**
             * ul.a {list-style-type:circle;} ul.b {list-style-type:square;}
             * ol.c {list-style-type:upper-roman;} ol.d
             * {list-style-type:lower-alpha;}
             */
            Object n = getXpath().evaluate(
                    "//text:list-style[@style:name='" + otl.getTextStyleNameAttribute()
                            + "']/text:list-level-style-bullet", getOdt().getContentDom(), XPathConstants.NODE);
            if (n != null) {// is a bullet list
                newElement = getCurrentResource().getDocument().createElement("ul");
            } else {
                n = getXpath().evaluate(
                        "//text:list-style[@style:name='" + otl.getTextStyleNameAttribute()
                                + "']/text:list-level-style-number", getOdt().getContentDom(), XPathConstants.NODE);
                if (n != null) {
                    newElement = getCurrentResource().getDocument().createElement("ol");
                }
            }

            if (newElement != null) {
                dstElement.add(newElement);
                newElement.setClassName(otl.getTextStyleNameAttribute());
            }
            // title[@lang='eng']
        } else if (e instanceof TextListItemElement) {
            TextListItemElement li = (TextListItemElement) e;
            newElement = getCurrentResource().getDocument().createElement("li");
            dstElement.add(newElement);

        } else if (e instanceof TableTableElement) {
            TableTableElement otl = (TableTableElement) e;
            dstElement = getCurrentResource().getDocument().getBody();
            newElement = getCurrentResource().getDocument().createElement("table");
            dstElement.add(newElement);
            newElement.setClassName(otl.getStyleName());
            Selector selector = getStylesheet().getSimpleSelector(null, otl.getStyleName());
            SelectorRule rule = getStylesheet().getRuleForSelector(selector, true);
          
            rule.set("width", new CSSName("100%"));
            selector = getStylesheet().getSimpleSelector("table", null);
            rule = getStylesheet().getRuleForSelector(selector, true);
            rule.set("border-collapse", new CSSName("collapse"));
            rule.set("border", new CSSName("1px solid black"));
            selector = getStylesheet().getSimpleSelector("td",null);
            rule = getStylesheet().getRuleForSelector(selector, true);
            rule.set("border", new CSSName("1px solid black"));
            selector = getStylesheet().getSimpleSelector("tr", null);
            rule = getStylesheet().getRuleForSelector(selector, true);
            rule.set("border", new CSSName("1px solid black"));

        } else if (e instanceof TableTableRowElement) {
            TableTableRowElement otl = (TableTableRowElement) e;
            newElement = getCurrentResource().getDocument().createElement("tr");
            dstElement.add(newElement);
            newElement.setClassName(otl.getStyleName());

        } else if (e instanceof TableTableCellElement) {
            TableTableCellElement otl = (TableTableCellElement) e;
            newElement = getCurrentResource().getDocument().createElement("td");
            dstElement.add(newElement);
            newElement.setClassName(otl.getStyleName());
        } else if (e instanceof OdfTextHeading) {// text:p
            // System.out.println(e.getTextContent());
            OdfTextHeading oth = (OdfTextHeading) e;
            if (hasPageBreak(oth)) {
                createNewResource();
            }
            newElement = getCurrentResource().getDocument().createElement("h" + oth.getAttribute("text:outline-level"));
            if (dstElement != null) {
                dstElement.add(newElement);
            } else {
                getCurrentResource().getDocument().getBody().add(newElement);
            }
            newElement.setClassName(oth.getStyleName());
            if (oth.getTextContent() != null && oth.getTextContent().trim().length() > 0) {
                addTocEntry(oth.getTextContent(), Integer.parseInt(oth.getAttribute("text:outline-level")), newElement);
            }

            if (oth.getAutomaticStyle() != null) {// probabile che sia stato
                // oth.getAutomaticStyles() // modificato lo stile
                List<OdfStyleBase> classeCSS = new ArrayList<OdfStyleBase>();
                OdfStyleBase p = oth.getAutomaticStyle().getParentStyle();
                while (p != null) {
                    classeCSS.add(p);
                    p = p.getParentStyle();

                }
                Collections.reverse(classeCSS);
                for (OdfStyleBase odfStyleBase : classeCSS) {
                    stylesPropsToCSS(odfStyleBase.getStyleProperties(), newElement.getClassName());
                }
                stylesPropsToCSS(oth.getAutomaticStyle().getStyleProperties(), oth.getStyleName());
                if (newElement != null) {
                    newElement.setClassName(oth.getStyleName());
                }
                if (isDebugMode()) {
                    Utils.printStyleProps(oth.getAutomaticStyle().getStyleProperties());
                }
            }

            getOdt().getDocumentStyles().getElementsByTagName(oth.getTextStyleNameAttribute());

        } else if (e instanceof OdfTextParagraph) {// text:p
            // System.out.println(e.getTextContent());

            OdfTextParagraph otp = (OdfTextParagraph) e;
            if (hasPageBreak(otp)) {
                createNewResource();
            }

            newElement = getCurrentResource().getDocument().createElement("p");

            if (dstElement != null) {
                dstElement.add(newElement);
            } else {
                getCurrentResource().getDocument().getBody().add(newElement);
            }

            newElement.setClassName(otp.getStyleName().trim());

            if (otp.getAutomaticStyle() != null) {// probabile che sia stato
                                                  // modificato lo stile
                List<OdfStyleBase> classeCSS = new ArrayList<OdfStyleBase>();
                OdfStyleBase p = otp.getAutomaticStyle().getParentStyle();
                while (p != null) {
                    classeCSS.add(p);
                    p = p.getParentStyle();

                }
                Collections.reverse(classeCSS);
                for (OdfStyleBase odfStyleBase : classeCSS) {
                    stylesPropsToCSS(odfStyleBase.getStyleProperties(), newElement.getClassName());
                }

                // while(p!=null){
                // if(p.getAttribute("style:name")!=null&&p.getAttribute("style:name").trim().length()>0){
                // newElement.setClassName(p.getAttribute("style:name").trim()+" "+newElement.getClassName());
                // stylesPropsToCSS(p.getStyleProperties(),
                // p.getAttribute("style:name"));
                // }
                // p=p.getParentStyle();
                //
                // }
                // Object
                // n=getXpath().evaluate("//style:style[@style:name='Body_20_Text_20_3']",
                // getOdt().getDocumentStyles(), XPathConstants.NODE);
                // n=getXpath().evaluate("//style:style[@style:name='Standard']",
                // getOdt().getDocumentStyles(), XPathConstants.NODE);
                // getXpath().evaluate("//style:style[@style:name='P38']",
                // getOdt().getDocumentStyles(), XPathConstants.NODE)
                stylesPropsToCSS(otp.getAutomaticStyle().getStyleProperties(), otp.getStyleName());

                if (isDebugMode()) {
                    Utils.printStyleProps(otp.getAutomaticStyle().getStyleProperties());
                }
            }

        } else if (e instanceof OdfTextSpan) {// text:span
            // System.out.println(e.getTextContent());
            // sembra che se automatic.style � vuoto allora esiste uno stile
            // definito che pu� definire bold e italic
            OdfTextSpan ots = (OdfTextSpan) e;

            if (ots.getAutomaticStyle() != null) {// probabile che sia stato
                                                  // modificato lo stile
                newElement = getCurrentResource().getDocument().createElement("span");
                dstElement.add(newElement);
                newElement.setClassName(ots.getStyleName());
                stylesPropsToCSS(ots.getAutomaticStyle().getStyleProperties(), newElement.getClassName());
                if (isDebugMode()) {
                    Utils.printStyleProps(ots.getAutomaticStyle().getStyleProperties());
                }
            }

View Full Code Here

        Selector selector = getStylesheet().getSimpleSelector(null, box.getStyleName());
        SelectorRule rule = getStylesheet().getRuleForSelector(selector, true);
        rule.set("width", new CSSName("100%"));

        rule.set("text-align", new CSSName("center"));
        Element idiv = getFootnotesResource().getDocument().createElement("div");
        idiv.setClassName(box.getStyleName());
        stylesPropsToCSS(box.getAutomaticStyle().getStyleProperties(), idiv.getClassName());
        dstElem.add(idiv);
        return idiv;
    }
View Full Code Here

        TextNoteCitationElement noteCit = (TextNoteCitationElement) getXpath().evaluate(".//text:note-citation", e,
                XPathConstants.NODE);

        // Element fn=addFootnoteLink(noteCit.getTextContent(),dstElem);

        Element fn = getFootnotesResource().getDocument().createElement("div");
        fn.setClassName("fnDiv");
        getFootnotesResource().getDocument().getBody().add(fn);

        HyperlinkElement a = getCurrentResource().getDocument().createHyperlinkElement("a");
        a.setClassName("fnLink");
        a.setXRef(fn.getSelfRef());
        a.add(noteCit.getTextContent());
        dstElem.add(a);

        Element noteId = getFootnotesResource().getDocument().createHyperlinkElement("p");
        noteId.setClassName("Footnote");
        noteId.add(noteCit.getTextContent() + ")");
        fn.add(noteId);

        HyperlinkElement ar = getFootnotesResource().getDocument().createHyperlinkElement("a");
        // ar.setClassName("fnLink");
        ar.setXRef(a.getSelfRef());
View Full Code Here

        return internalLink;
    }

    public void processInternalLinksCrossReferences() {
        for (HyperlinkElement h : getInternalLink()) {
            Element target = getBookmarks().get(h.getTitle());
            if (target != null) {
                h.setTitle("");
                h.setXRef(target.getSelfRef());
            }
        }

    }
View Full Code Here

            Collections.sort(bl);
           
            addTocEntry("Bookmarks", 0, getBookmarks().get(bl.get(0)));
           
            for (String k : bl) {
                Element el=getBookmarks().get(k);
                addTocEntry(el.getId(), 1, el);
            }
          
        }
    }
View Full Code Here

TOP

Related Classes of com.adobe.dp.epub.ops.Element$SizeRemains

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.