poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1160288 - in /poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter: AbstractWordConverter.java AbstractWordUtils.java WordToFoConverter.java WordToFoUtils.java WordToHtmlConverter.java WordToHtmlUtils.java WordToTextConverter.java
Date Mon, 22 Aug 2011 15:01:50 GMT
Author: sergey
Date: Mon Aug 22 15:01:49 2011
New Revision: 1160288

URL: http://svn.apache.org/viewvc?rev=1160288&view=rev
Log:
add page breaks support; fix paragraphs-in-bookmarks handling

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
Mon Aug 22 15:01:49 2011
@@ -342,8 +342,8 @@ public abstract class AbstractWordConver
                 bookmarkStack.addAll( bookmarks );
                 try
                 {
-                    Range subrange = new Range( structure.start, structure.end,
-                            range )
+                    int end = Math.min( range.getEndOffset(), structure.end );
+                    Range subrange = new Range( structure.start, end, range )
                     {
                         @Override
                         public String toString()
@@ -372,7 +372,7 @@ public abstract class AbstractWordConver
                         + structure.structure.getClass() );
             }
 
-            previous = structure.end;
+            previous = Math.min( range.getEndOffset(), structure.end );
         }
 
         if ( previous != range.getStartOffset() )
@@ -865,6 +865,9 @@ public abstract class AbstractWordConver
         return false;
     }
 
+    protected abstract void processPageBreak( HWPFDocumentCore wordDocument,
+            Element flow );
+
     protected abstract void processPageref( HWPFDocumentCore wordDocument,
             Element currentBlock, Range textRange, int currentTableLevel,
             String pageref );
@@ -903,6 +906,11 @@ public abstract class AbstractWordConver
                 continue;
             }
 
+            if ( paragraph.text().equals( "\u000c" ) )
+            {
+                processPageBreak( wordDocument, flow );
+            }
+
             if ( paragraph.getIlfo() != currentListInfo )
             {
                 currentListInfo = paragraph.getIlfo();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java Mon
Aug 22 15:01:49 2011
@@ -130,7 +130,7 @@ public class AbstractWordUtils
         return true;
     }
 
-    static void compactChildNodes( Element parentElement, String childTagName )
+    static void compactChildNodesR( Element parentElement, String childTagName )
     {
         NodeList childNodes = parentElement.getChildNodes();
         for ( int i = 0; i < childNodes.getLength() - 1; i++ )
@@ -146,6 +146,16 @@ public class AbstractWordUtils
             child2.getParentNode().removeChild( child2 );
             i--;
         }
+
+        childNodes = parentElement.getChildNodes();
+        for ( int i = 0; i < childNodes.getLength() - 1; i++ )
+        {
+            Node child = childNodes.item( i );
+            if ( child instanceof Element )
+            {
+                compactChildNodesR( (Element) child, childTagName );
+            }
+        }
     }
 
     static boolean equals( String str1, String str2 )
@@ -320,10 +330,12 @@ public class AbstractWordUtils
         if ( argbValue == -1 )
             throw new IllegalArgumentException( "This colorref is empty" );
 
-        int value = argbValue & 0x00FFFFFF;
+        int bgrValue = argbValue & 0x00FFFFFF;
+        int rgbValue = ( bgrValue & 0x0000FF ) << 16 | ( bgrValue & 0x00FF00
)
+                | ( bgrValue & 0xFF0000 ) >> 16;
 
         // http://www.w3.org/TR/REC-html40/types.html#h-6.5
-        switch ( value )
+        switch ( rgbValue )
         {
         case 0xFFFFFF:
             return "white";
@@ -360,7 +372,7 @@ public class AbstractWordUtils
         }
 
         StringBuilder result = new StringBuilder( "#" );
-        String hex = Integer.toHexString( value );
+        String hex = Integer.toHexString( rgbValue );
         for ( int i = hex.length(); i < 6; i++ )
         {
             result.append( '0' );

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java Mon
Aug 22 15:01:49 2011
@@ -50,6 +50,8 @@ import org.apache.poi.util.POILogFactory
 import org.apache.poi.util.POILogger;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 
 /**
@@ -119,6 +121,8 @@ public class WordToFoConverter extends A
 
     private AtomicInteger internalLinkCounter = new AtomicInteger( 0 );
 
+    private boolean outputCharactersLanguage = false;
+
     private Set<String> usedIds = new LinkedHashSet<String>();
 
     /**
@@ -202,6 +206,11 @@ public class WordToFoConverter extends A
         return foDocumentFacade.getDocument();
     }
 
+    public boolean isOutputCharactersLanguage()
+    {
+        return outputCharactersLanguage;
+    }
+
     @Override
     protected void outputCharacters( Element block, CharacterRun characterRun,
             String text )
@@ -211,11 +220,15 @@ public class WordToFoConverter extends A
         Triplet triplet = getCharacterRunTriplet( characterRun );
 
         if ( WordToFoUtils.isNotEmpty( triplet.fontName ) )
-            WordToFoUtils.setFontFamily( inline, characterRun.getFontName() );
+            WordToFoUtils.setFontFamily( inline, triplet.fontName );
         WordToFoUtils.setBold( inline, triplet.bold );
         WordToFoUtils.setItalic( inline, triplet.italic );
         WordToFoUtils.setFontSize( inline, characterRun.getFontSize() / 2 );
         WordToFoUtils.setCharactersProperties( characterRun, inline );
+
+        if ( isOutputCharactersLanguage() )
+            WordToFoUtils.setLanguage( characterRun, inline );
+
         block.appendChild( inline );
 
         Text textNode = foDocumentFacade.createText( text );
@@ -411,6 +424,32 @@ public class WordToFoConverter extends A
         block.appendChild( foDocumentFacade.createBlock() );
     }
 
+    @Override
+    protected void processPageBreak( HWPFDocumentCore wordDocument, Element flow )
+    {
+        Element block = null;
+        NodeList childNodes = flow.getChildNodes();
+        if ( childNodes.getLength() > 0 )
+        {
+            Node lastChild = childNodes.item( childNodes.getLength() - 1 );
+            if ( lastChild instanceof Element )
+            {
+                Element lastElement = (Element) lastChild;
+                if ( !lastElement.hasAttribute( "break-after" ) )
+                {
+                    block = lastElement;
+                }
+            }
+        }
+
+        if ( block == null )
+        {
+            block = foDocumentFacade.createBlock();
+            flow.appendChild( block );
+        }
+        block.setAttribute( "break-after", "page" );
+    }
+
     protected void processPageref( HWPFDocumentCore hwpfDocument,
             Element currentBlock, Range textRange, int currentTableLevel,
             String pageref )
@@ -606,4 +645,9 @@ public class WordToFoConverter extends A
         return true;
     }
 
+    public void setOutputCharactersLanguage( boolean outputCharactersLanguage )
+    {
+        this.outputCharactersLanguage = outputCharactersLanguage;
+    }
+
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoUtils.java Mon Aug
22 15:01:49 2011
@@ -30,7 +30,7 @@ public class WordToFoUtils extends Abstr
 {
     static void compactInlines( Element blockElement )
     {
-        compactChildNodes( blockElement, "fo:inline" );
+        compactChildNodesR( blockElement, "fo:inline" );
     }
 
     public static void setBold( final Element element, final boolean bold )
@@ -82,12 +82,6 @@ public class WordToFoUtils extends Abstr
             inline.setAttribute( "opacity",
                     getOpacity( characterRun.getIco24() ) );
         }
-        if ( characterRun.getLanguageCode() != 0 )
-        {
-            final String language = getLanguage( characterRun.getLanguageCode() );
-            if ( isNotEmpty( language ) )
-                inline.setAttribute( "language", language );
-        }
         if ( characterRun.isCapitalized() )
         {
             inline.setAttribute( "text-transform", "uppercase" );
@@ -206,6 +200,17 @@ public class WordToFoUtils extends Abstr
             element.setAttribute( "text-align", justification );
     }
 
+    public static void setLanguage( final CharacterRun characterRun,
+            final Element inline )
+    {
+        if ( characterRun.getLanguageCode() != 0 )
+        {
+            final String language = getLanguage( characterRun.getLanguageCode() );
+            if ( isNotEmpty( language ) )
+                inline.setAttribute( "language", language );
+        }
+    }
+
     public static void setParagraphProperties( Paragraph paragraph,
             Element block )
     {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java Mon
Aug 22 15:01:49 2011
@@ -495,6 +495,12 @@ public class WordToHtmlConverter extends
         }
     }
 
+    @Override
+    protected void processPageBreak( HWPFDocumentCore wordDocument, Element flow )
+    {
+        flow.appendChild( htmlDocumentFacade.createLineBreak() );
+    }
+
     protected void processPageref( HWPFDocumentCore hwpfDocument,
             Element currentBlock, Range textRange, int currentTableLevel,
             String pageref )

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java Mon Aug
22 15:01:49 2011
@@ -233,7 +233,7 @@ public class WordToHtmlUtils extends Abs
 
     static void compactSpans( Element pElement )
     {
-        compactChildNodes( pElement, "span" );
+        compactChildNodesR( pElement, "span" );
     }
 
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java?rev=1160288&r1=1160287&r2=1160288&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java Mon
Aug 22 15:01:49 2011
@@ -381,6 +381,14 @@ public class WordToTextConverter extends
     }
 
     @Override
+    protected void processPageBreak( HWPFDocumentCore wordDocument, Element flow )
+    {
+        Element block = textDocumentFacade.createBlock();
+        block.appendChild( textDocumentFacade.createText( "\n" ) );
+        flow.appendChild( block );
+    }
+
+    @Override
     protected void processPageref( HWPFDocumentCore wordDocument,
             Element currentBlock, Range textRange, int currentTableLevel,
             String pageref )



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message