Changeset 1087


Ignore:
Timestamp:
02/26/10 14:41:23 (2 years ago)
Author:
jharrop
Message:

Basic character formatting in SVG output

Location:
trunk/docx4j/src/pptx4j/java/org/pptx4j
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/pptx4j/java/org/pptx4j/convert/out/svginhtml/SvgExporter.java

    r1086 r1087  
    2222import org.docx4j.convert.out.html.HtmlExporterNG; 
    2323import org.docx4j.convert.out.html.AbstractHtmlExporter.HtmlSettings; 
     24import org.docx4j.dml.CTTextCharacterProperties; 
    2425import org.docx4j.dml.CTTextListStyle; 
    2526import org.docx4j.dml.CTTextParagraphProperties; 
     
    3637import org.docx4j.wml.PPr; 
    3738import org.docx4j.wml.Pict; 
     39import org.docx4j.wml.RPr; 
     40//import org.docx4j.wml.RPr; 
    3841import org.docx4j.wml.Style; 
    3942import org.plutext.jaxb.svg11.Line; 
     
    131134                String pStyleVal; 
    132135         
     136                System.out.println("cNvPrName: " + cNvPrName + "; " + "phType: " + phType ); 
     137                 
    133138                if (cNvPrName.toLowerCase().indexOf("subtitle")>-1 
    134139                                || phType.toLowerCase().indexOf("subtitle")>-1) { 
     
    139144                        pStyleVal = "Lvl" + level + "Master" + rl.getMasterNumber() + "Title"; 
    140145                } else { 
    141                         pStyleVal = "Lvl" + level + "Master" + rl.getMasterNumber() + "Body";                    
    142                 } 
     146                        // eg cNvPrName: TextBox 2; phType: 
     147                        pStyleVal = "Lvl" + level + "Master" + rl.getMasterNumber() + "Other";                   
     148                } 
     149                System.out.println("--> " + pStyleVal ); 
    143150                 
    144151        try { 
     
    291298         
    292299} 
    293      
    294 //    public static CTTextListStyle unmarshalFormatting(NodeIterator lstStyleNodeIt ) { 
     300 
     301        public static DocumentFragment createBlockForR( 
     302                        PresentationMLPackage pmlPackage, NodeIterator rPrNodeIt, 
     303                        NodeIterator childResults) { 
     304 
     305                DocumentFragment docfrag = null; 
     306                Document d = null; 
     307                Element span = null; 
     308 
     309                try { 
     310 
     311                        // Create a DOM builder and parse the fragment 
     312                        DocumentBuilderFactory factory = DocumentBuilderFactory 
     313                                        .newInstance(); 
     314                        d = factory.newDocumentBuilder().newDocument(); 
     315 
     316                        span = d.createElement("span"); 
     317                        d.appendChild(span); 
     318 
     319                        CTTextCharacterProperties textCharProps = (CTTextCharacterProperties) nodeToObjectModel( 
     320                                        rPrNodeIt.nextNode(), CTTextCharacterProperties.class); 
     321 
     322                        RPr rPr = TextStyles.getWmlRPr(textCharProps); 
     323 
     324                        // Does our rPr contain anything else? 
     325                        StringBuffer inlineStyle = new StringBuffer(); 
     326                        HtmlExporterNG.createCss(pmlPackage, rPr, inlineStyle); 
     327                        if (!inlineStyle.toString().equals("")) { 
     328                                span.setAttribute("style", inlineStyle.toString()); 
     329                        } 
     330 
     331                        Node n = childResults.nextNode(); 
     332                        XmlUtils.treeCopy((DTMNodeProxy) n, span); 
     333 
     334                } catch (Exception e) { 
     335                        e.printStackTrace(); 
     336                        log.error(e); 
     337                        // If something went wrong with the formatting, 
     338                        // still try to display the text! 
     339                        Node n = childResults.nextNode(); 
     340                        XmlUtils.treeCopy((DTMNodeProxy) n, span); 
     341                } 
     342 
     343                // Machinery 
     344                docfrag = d.createDocumentFragment(); 
     345                docfrag.appendChild(d.getDocumentElement()); 
     346                return docfrag; 
     347 
     348        } 
     349 
     350        //    public static CTTextListStyle unmarshalFormatting(NodeIterator lstStyleNodeIt ) { 
    295351//               
    296352//      // Get the pPr node as a JAXB object, 
     
    467523 
    468524    public static Object nodeToObjectModel(Node n, Class declaredType) throws Docx4JException { 
     525         
     526        if (n==null) { 
     527                throw new Docx4JException("null input"); 
     528        } 
     529         
     530//      if (log.isDebugEnabled() ) { 
     531//              System.out.println("IN: " + XmlUtils.w3CDomNodeToString(n)); 
     532//      } 
     533         
    469534                Object jaxb=null; 
    470535                try { 
  • trunk/docx4j/src/pptx4j/java/org/pptx4j/convert/out/svginhtml/pptx2svginhtml.xslt

    r1085 r1087  
    155155 
    156156 <xsl:template match="a:r"> 
    157         <xsl:apply-templates select="a:t"/> 
     157                <xsl:variable name="rPr" select="a:rPr"/> 
     158                <xsl:variable name="childResults"><xsl:apply-templates select="a:t"/></xsl:variable> 
     159                <xsl:copy-of select="java:org.pptx4j.convert.out.svginhtml.SvgExporter.createBlockForR( 
     160                        $wmlPackage, $rPr, 
     161                         $childResults)" /> 
    158162 </xsl:template> 
    159163 
  • trunk/docx4j/src/pptx4j/java/org/pptx4j/model/TextStyles.java

    r1061 r1087  
    3333import org.docx4j.UnitsOfMeasurement; 
    3434import org.docx4j.XmlUtils; 
     35import org.docx4j.dml.CTTextCharacterProperties; 
    3536import org.docx4j.dml.CTTextListStyle; 
    3637import org.docx4j.dml.CTTextParagraphProperties; 
     
    4546import org.docx4j.openpackaging.parts.PresentationML.MainPresentationPart; 
    4647import org.docx4j.openpackaging.parts.PresentationML.SlideMasterPart; 
     48import org.docx4j.wml.BooleanDefaultTrue; 
    4749import org.docx4j.wml.HpsMeasure; 
    4850import org.docx4j.wml.Jc; 
     
    5456import org.docx4j.wml.Style; 
    5557import org.docx4j.wml.Styles; 
     58import org.docx4j.wml.U; 
     59import org.docx4j.wml.UnderlineEnumeration; 
    5660import org.docx4j.wml.Style.Name; 
    5761import org.pptx4j.pml.CTSlideMasterTextStyles; 
     
    209213//              <w:sz w:val="28" /> 
    210214                        if (lvlPPr.getDefRPr().getSz()!=null) {                          
    211                                 HpsMeasure sz = factory.createHpsMeasure(); 
    212                                 int halfPts = Math.round(lvlPPr.getDefRPr().getSz()/50);  
    213                                 sz.setVal( BigInteger.valueOf(halfPts) ); 
    214                                 rPr.setSz(sz); 
     215                                rPr.setSz( convertFontSize(lvlPPr.getDefRPr().getSz()) ); 
    215216                        } 
    216217                         
     
    233234                return rPr; 
    234235        }        
     236         
     237        private static HpsMeasure convertFontSize(Integer in) { 
     238                ObjectFactory factory = Context.getWmlObjectFactory(); 
     239                HpsMeasure sz = factory.createHpsMeasure(); 
     240                int halfPts = Math.round(in/50);  
     241                sz.setVal( BigInteger.valueOf(halfPts) ); 
     242                return sz; 
     243        } 
     244         
    235245        // From Main Presentation Part 
    236246        public static List<Style> generateWordStylesFromPresentationPart(CTTextListStyle textStyles, String suffix,   
     
    346356        }        
    347357     
    348          
     358        public static RPr getWmlRPr(CTTextCharacterProperties in) { 
     359                 
     360                ObjectFactory factory = Context.getWmlObjectFactory(); 
     361                RPr rPr = factory.createRPr(); 
     362 
     363                if (in==null) { 
     364                        System.out.println("Was passed null"); 
     365                        return rPr; 
     366                } 
     367                 
     368//        <a:rPr  i="true" />            
     369                if (in.isI()!=null && in.isI()) { 
     370                        rPr.setI( new BooleanDefaultTrue() ); 
     371                } 
     372                 
     373//        <a:rPr  b="true" 
     374                if (in.isB()!=null && in.isB()) { 
     375                        rPr.setB( new BooleanDefaultTrue() ); 
     376                } 
     377                 
     378//        <a:rPr  u="sng"  
     379                if (in.getU()!=null) { 
     380                        U u = factory.createU();  
     381                        u.setVal(UnderlineEnumeration.SINGLE); 
     382                        rPr.setU(u); 
     383                } 
     384//        <a:rPr  sz="4000"  
     385                if (in.getSz()!=null) { 
     386                        rPr.setSz( 
     387                                        convertFontSize(in.getSz() ) ); 
     388                } 
     389                 
     390                return rPr; 
     391 
     392        } 
    349393} 
Note: See TracChangeset for help on using the changeset viewer.