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()
+ structure.structure.getClass() );
}
- previous = structure.end;
+ previous = Math.min( range.getEndOffset(), structure.end );
}
if ( previous != range.getStartOffset() )
return false;
}
+ protected abstract void processPageBreak( HWPFDocumentCore wordDocument,
+ Element flow );
+
protected abstract void processPageref( HWPFDocumentCore wordDocument,
Element currentBlock, Range textRange, int currentTableLevel,
String pageref );
continue;
}
+ if ( paragraph.text().equals( "\u000c" ) )
+ {
+ processPageBreak( wordDocument, flow );
+ }
+
if ( paragraph.getIlfo() != currentListInfo )
{
currentListInfo = paragraph.getIlfo();
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++ )
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 )
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";
}
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' );
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;
/**
private AtomicInteger internalLinkCounter = new AtomicInteger( 0 );
+ private boolean outputCharactersLanguage = false;
+
private Set<String> usedIds = new LinkedHashSet<String>();
/**
return foDocumentFacade.getDocument();
}
+ public boolean isOutputCharactersLanguage()
+ {
+ return outputCharactersLanguage;
+ }
+
@Override
protected void outputCharacters( Element block, CharacterRun characterRun,
String text )
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 );
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 )
return true;
}
+ public void setOutputCharactersLanguage( boolean outputCharactersLanguage )
+ {
+ this.outputCharactersLanguage = outputCharactersLanguage;
+ }
+
}
{
static void compactInlines( Element blockElement )
{
- compactChildNodes( blockElement, "fo:inline" );
+ compactChildNodesR( blockElement, "fo:inline" );
}
public static void setBold( final Element element, final boolean bold )
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" );
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 )
{
}
}
+ @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 )
static void compactSpans( Element pElement )
{
- compactChildNodes( pElement, "span" );
+ compactChildNodesR( pElement, "span" );
}
}
}
}
+ @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,