Example usage for org.apache.poi.xslf.usermodel XSLFTextParagraph getDefaultFontFamily

List of usage examples for org.apache.poi.xslf.usermodel XSLFTextParagraph getDefaultFontFamily

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XSLFTextParagraph getDefaultFontFamily.

Prototype

@Override
    public String getDefaultFontFamily() 

Source Link

Usage

From source file:com.github.codeurjc.slidesconverter.PowerPointToHTML.java

License:Apache License

private void generateSlidesContent(XMLSlideShow pptx, HSLFSlideShow ppt) throws IOException {

    out.println("<h1>Slides</h1>");

    for (int numSlide = 0; numSlide < pptx.getSlides().size(); numSlide++) {

        System.out.println("Processing slide " + numSlide);

        XSLFSlide slideX = pptx.getSlides().get(numSlide);
        HSLFSlide slide = ppt.getSlides().get(numSlide);

        Section section = getSection(numSlide);

        if (section != null && section.startSlide == numSlide) {

            if (section.level == 0) {

                out.println("<h2>" + escape(section.sectionNum + ". " + section.name) + "</h2>");

            } else {

                out.println(/*  w  w  w  .j  av  a2 s .  c  om*/
                        "<h3>" + escape(section.sectionNum + "." + section.subsectionNum + ". " + section.name)
                                + "</h3>");
            }
        }

        generateSlideImage(slide);

        out.println("<h4>Slide (" + (numSlide + 1) + ")</h4>");

        out.println("<img src=" + getImageFileName(slideX.getSlideNumber()) + "><br>");

        for (XSLFShape shape : slideX.getShapes()) {

            if (shape instanceof XSLFTextShape) {

                XSLFTextShape tsh = (XSLFTextShape) shape;

                boolean first = true;
                boolean code = false;

                boolean subtitle = false;

                for (XSLFTextParagraph p : tsh) {

                    String indent = "";

                    int indentLevel = p.getIndentLevel();
                    if (subtitle) {
                        indentLevel++;
                    }

                    if (indentLevel > 0) {
                        for (int j = 0; j < indentLevel; j++) {
                            indent += "> ";
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    for (XSLFTextRun r : p) {
                        sb.append(r.getRawText());
                    }

                    String text = sb.toString();

                    // Avoid section or subsection name to appear in slide
                    // contents
                    if ((section != null && (text.equals(section.name)
                            || (section.parentSection != null && section.parentSection.name.equals(text))))
                            || text.trim().isEmpty()) {
                        continue;
                    }

                    if (first) {

                        code = p.getDefaultFontFamily().startsWith("Courier");

                        if (code) {
                            out.println("<pre style='border:1px;border-style: solid;'>");
                        }
                    }

                    if (!code) {
                        out.println("<p>");
                    }

                    out(indent + text);

                    if (!code) {
                        out.println("</p>");
                    }

                    first = false;
                    if (p.getTextAlign() == TextAlign.CENTER) {
                        subtitle = true;
                    }
                }

                if (code) {
                    out.println("</pre>");
                }

            } else if (shape instanceof XSLFPictureShape) {

                XSLFPictureShape pShape = (XSLFPictureShape) shape;

                out.println("<p>Imagen: " + pShape.getShapeName() + "</p>");
            }
        }

        out.println("<hr>");
    }

    out.println("</body></html>");
}