import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFDocumentCore;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
-import org.apache.poi.hwpf.usermodel.Section;
-import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
return String.valueOf( number );
}
- public static SectionProperties getSectionProperties( Section section )
- {
- try
- {
- Field field = Section.class.getDeclaredField( "_props" );
- field.setAccessible( true );
- return (SectionProperties) field.get( section );
- }
- catch ( Exception exc )
- {
- throw new Error( exc );
- }
- }
-
static boolean isEmpty( String str )
{
return str == null || str.length() == 0;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
-
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFDocumentCore;
+import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Section;
-import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableRow;
this.foDocumentFacade = new FoDocumentFacade( document );
}
- protected String createPageMaster( SectionProperties sep, String type,
- int section )
+ protected String createPageMaster( Section section, String type,
+ int sectionIndex )
{
- float height = sep.getYaPage() / WordToFoUtils.TWIPS_PER_INCH;
- float width = sep.getXaPage() / WordToFoUtils.TWIPS_PER_INCH;
- float leftMargin = sep.getDxaLeft() / WordToFoUtils.TWIPS_PER_INCH;
- float rightMargin = sep.getDxaRight() / WordToFoUtils.TWIPS_PER_INCH;
- float topMargin = sep.getDyaTop() / WordToFoUtils.TWIPS_PER_INCH;
- float bottomMargin = sep.getDyaBottom() / WordToFoUtils.TWIPS_PER_INCH;
+ float height = section.getPageHeight() / WordToFoUtils.TWIPS_PER_INCH;
+ float width = section.getPageWidth() / WordToFoUtils.TWIPS_PER_INCH;
+ float leftMargin = section.getMarginLeft()
+ / WordToFoUtils.TWIPS_PER_INCH;
+ float rightMargin = section.getMarginRight()
+ / WordToFoUtils.TWIPS_PER_INCH;
+ float topMargin = section.getMarginTop() / WordToFoUtils.TWIPS_PER_INCH;
+ float bottomMargin = section.getMarginBottom()
+ / WordToFoUtils.TWIPS_PER_INCH;
// add these to the header
- String pageMasterName = type + "-page" + section;
+ String pageMasterName = type + "-page" + sectionIndex;
Element pageMaster = foDocumentFacade
.addSimplePageMaster( pageMasterName );
// WordToFoUtils.setBorder(regionBody, sep.getBrcLeft(), "left");
// WordToFoUtils.setBorder(regionBody, sep.getBrcRight(), "right");
- if ( sep.getCcolM1() > 0 )
+ if ( section.getNumColumns() > 1 )
{
- regionBody.setAttribute( "column-count", ""
- + ( sep.getCcolM1() + 1 ) );
- if ( sep.getFEvenlySpaced() )
+ regionBody.setAttribute( "column-count",
+ "" + ( section.getNumColumns() ) );
+ if ( section.isColumnsEvenlySpaced() )
{
- regionBody.setAttribute( "column-gap",
- ( sep.getDxaColumns() / WordToFoUtils.TWIPS_PER_INCH )
- + "in" );
+ float distance = section.getDistanceBetweenColumns()
+ / WordToFoUtils.TWIPS_PER_INCH;
+ regionBody.setAttribute( "column-gap", distance + "in" );
}
else
{
protected void processSection( HWPFDocumentCore wordDocument,
Section section, int sectionCounter )
{
- String regularPage = createPageMaster(
- WordToFoUtils.getSectionProperties( section ), "page",
- sectionCounter );
+ String regularPage = createPageMaster( section, "page", sectionCounter );
Element pageSequence = foDocumentFacade.addPageSequence( regularPage );
Element flow = foDocumentFacade.addFlowToPageSequence( pageSequence,
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
-
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFDocumentCore;
+import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Section;
-import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableRow;
private static String getSectionStyle( Section section )
{
- SectionProperties sep = WordToHtmlUtils.getSectionProperties( section );
-
- float leftMargin = sep.getDxaLeft() / TWIPS_PER_INCH;
- float rightMargin = sep.getDxaRight() / TWIPS_PER_INCH;
- float topMargin = sep.getDyaTop() / TWIPS_PER_INCH;
- float bottomMargin = sep.getDyaBottom() / TWIPS_PER_INCH;
+ float leftMargin = section.getMarginLeft() / TWIPS_PER_INCH;
+ float rightMargin = section.getMarginRight() / TWIPS_PER_INCH;
+ float topMargin = section.getMarginTop() / TWIPS_PER_INCH;
+ float bottomMargin = section.getMarginBottom() / TWIPS_PER_INCH;
String style = "margin: " + topMargin + "in " + rightMargin + "in "
+ bottomMargin + "in " + leftMargin + "in; ";
- if ( sep.getCcolM1() > 0 )
+ if ( section.getNumColumns() > 1 )
{
- style += "column-count: " + ( sep.getCcolM1() + 1 ) + "; ";
- if ( sep.getFEvenlySpaced() )
+ style += "column-count: " + ( section.getNumColumns() ) + "; ";
+ if ( section.isColumnsEvenlySpaced() )
{
- style += "column-gap: "
- + ( sep.getDxaColumns() / TWIPS_PER_INCH ) + "in; ";
+ float distance = section.getDistanceBetweenColumns()
+ / TWIPS_PER_INCH;
+ style += "column-gap: " + distance + "in; ";
}
else
{
final CharacterRun characterRun = paragraph.getCharacterRun( 0 );
if ( characterRun != null )
{
- Triplet triplet = getCharacterRunTriplet(characterRun);
+ Triplet triplet = getCharacterRunTriplet( characterRun );
pFontSize = characterRun.getFontSize() / 2;
pFontName = triplet.fontName;
WordToHtmlUtils.addFontFamily( pFontName, style );
return s;
}
+ /**
+ * @return distance to be maintained between columns, in twips. Used when
+ * {@link #isColumnsEvenlySpaced()} == true
+ */
+ public int getDistanceBetweenColumns()
+ {
+ return _props.getDxaColumns();
+ }
+
+ public int getMarginBottom()
+ {
+ return _props.getDyaBottom();
+ }
+
+ public int getMarginLeft()
+ {
+ return _props.getDxaLeft();
+ }
+
+ public int getMarginRight()
+ {
+ return _props.getDxaRight();
+ }
+
+ public int getMarginTop()
+ {
+ return _props.getDyaTop();
+ }
+
public int getNumColumns()
{
return _props.getCcolM1() + 1;
}
+ /**
+ * @return page height (in twips) in current section. Default value is 15840
+ * twips
+ */
+ public int getPageHeight()
+ {
+ return _props.getYaPage();
+ }
+
+ /**
+ * @return page width (in twips) in current section. Default value is 12240
+ * twips
+ */
+ public int getPageWidth()
+ {
+ return _props.getXaPage();
+ }
+
+ public boolean isColumnsEvenlySpaced()
+ {
+ return _props.getFEvenlySpaced();
+ }
+
@Override
public String toString()
{