diff options
author | Finn Bock <bckfnn@apache.org> | 2004-10-20 17:53:36 +0000 |
---|---|---|
committer | Finn Bock <bckfnn@apache.org> | 2004-10-20 17:53:36 +0000 |
commit | 8a84b42f3ec6471dc8dfd82a741239010c7576c7 (patch) | |
tree | 37fd4791dfc25caa428d29da50d7fe5ebc465f75 | |
parent | 84d94659a64d3e5def55bf5413f10a2d12e4611e (diff) | |
download | xmlgraphics-fop-8a84b42f3ec6471dc8dfd82a741239010c7576c7.tar.gz xmlgraphics-fop-8a84b42f3ec6471dc8dfd82a741239010c7576c7.zip |
Fourth phase of performance improvement.
- Get rid of calls to FObj.getProperty() and its friends. Replace them
with the property getters on the FO nodes.
PR: 31699
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198093 13f79535-47bb-0310-9956-ffa450edef68
6 files changed, 215 insertions, 265 deletions
diff --git a/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java b/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java index cf987f5bb..ec3afdacd 100644 --- a/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java @@ -20,10 +20,7 @@ package org.apache.fop.render.rtf; //FOP import org.apache.fop.apps.FOPException; -import org.apache.fop.fo.Constants; -import org.apache.fop.fo.FObj; - -//RTF +import org.apache.fop.fo.flow.ListBlock; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListTable; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText; @@ -42,15 +39,13 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText; public class ListAttributesConverter { - static RtfAttributes convertAttributes(FObj fobj) + static RtfAttributes convertAttributes(ListBlock fobj) throws FOPException { FOPRtfAttributes attrib = new FOPRtfAttributes(); - attrib.set(RtfListTable.LIST_INDENT, - fobj.getProperty(Constants.PR_START_INDENT).getLength()); - attrib.set(RtfText.LEFT_INDENT_BODY, - fobj.getProperty(Constants.PR_END_INDENT).getLength()); + attrib.set(RtfListTable.LIST_INDENT, fobj.getCommonMarginBlock().startIndent); + attrib.set(RtfText.LEFT_INDENT_BODY, fobj.getCommonMarginBlock().endIndent); /* * set list table defaults diff --git a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java index 3199a6e3e..00efe46b7 100644 --- a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java @@ -21,13 +21,13 @@ package org.apache.fop.render.rtf; import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.SimpleLog; - -//FOP import org.apache.fop.datatypes.Length; import org.apache.fop.fo.Constants; -import org.apache.fop.fo.pagination.Region; -import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.fo.expr.NumericOp; +import org.apache.fop.fo.pagination.RegionBA; +import org.apache.fop.fo.pagination.RegionBody; +import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfPage; @@ -46,17 +46,17 @@ class PageAttributesConverter { FOPRtfAttributes attrib = new FOPRtfAttributes(); try { - Region before = pagemaster.getRegion(Constants.FO_REGION_BEFORE); - Region body = pagemaster.getRegion(Constants.FO_REGION_BODY); - Region after = pagemaster.getRegion(Constants.FO_REGION_AFTER); + RegionBA before = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_BEFORE); + RegionBody body = (RegionBody) pagemaster.getRegion(Constants.FO_REGION_BODY); + RegionBA after = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_AFTER); - attrib.set(RtfPage.PAGE_WIDTH, pagemaster.getProperty(Constants.PR_PAGE_WIDTH).getLength()); - attrib.set(RtfPage.PAGE_HEIGHT, pagemaster.getProperty(Constants.PR_PAGE_HEIGHT).getLength()); + attrib.set(RtfPage.PAGE_WIDTH, pagemaster.getPageWidth()); + attrib.set(RtfPage.PAGE_HEIGHT, pagemaster.getPageHeight()); - Length pageTop = pagemaster.getProperty(Constants.PR_MARGIN_TOP).getLength(); - Length pageBottom = pagemaster.getProperty(Constants.PR_MARGIN_BOTTOM).getLength(); - Length pageLeft = pagemaster.getProperty(Constants.PR_MARGIN_LEFT).getLength(); - Length pageRight = pagemaster.getProperty(Constants.PR_MARGIN_RIGHT).getLength(); + Length pageTop = pagemaster.getCommonMarginBlock().marginTop; + Length pageBottom = pagemaster.getCommonMarginBlock().marginBottom; + Length pageLeft = pagemaster.getCommonMarginBlock().marginLeft; + Length pageRight = pagemaster.getCommonMarginBlock().marginRight; Length bodyTop = pageTop; Length bodyBottom = pageBottom; @@ -65,10 +65,11 @@ class PageAttributesConverter { if (body != null) { // Should perhaps be replaced by full reference-area handling. - bodyTop = (Length) NumericOp.addition(pageTop, body.getProperty(Constants.PR_MARGIN_TOP).getLength()); - bodyBottom = (Length) NumericOp.addition(pageBottom, body.getProperty(Constants.PR_MARGIN_BOTTOM).getLength()); - bodyLeft = (Length) NumericOp.addition(pageLeft, body.getProperty(Constants.PR_MARGIN_LEFT).getLength()); - bodyRight = (Length) NumericOp.addition(pageRight, body.getProperty(Constants.PR_MARGIN_RIGHT).getLength()); + CommonMarginBlock bodyMargin = body.getCommonMarginBlock(); + bodyTop = (Length) NumericOp.addition(pageTop, bodyMargin.marginTop); + bodyBottom = (Length) NumericOp.addition(pageBottom, bodyMargin.marginBottom); + bodyLeft = (Length) NumericOp.addition(pageLeft, bodyMargin.marginLeft); + bodyRight = (Length) NumericOp.addition(pageRight, bodyMargin.marginRight); } attrib.set(RtfPage.MARGIN_TOP, bodyTop); @@ -79,14 +80,14 @@ class PageAttributesConverter { //region-before attributes Length beforeTop = pageTop; if (before != null) { - beforeTop = (Length) NumericOp.addition(pageTop, before.getProperty(Constants.PR_MARGIN_TOP).getLength()); + beforeTop = (Length) NumericOp.addition(pageTop, before.getExtent()); } attrib.set(RtfPage.HEADERY, beforeTop); //region-after attributes Length afterBottom = pageBottom; if (after != null) { - afterBottom = (Length) NumericOp.addition(pageBottom, after.getProperty(Constants.PR_MARGIN_BOTTOM).getLength()); + afterBottom = (Length) NumericOp.addition(pageBottom, after.getExtent()); } attrib.set(RtfPage.FOOTERY, beforeTop); } catch (Exception e) { diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index acade3c66..86bfef537 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -53,11 +53,7 @@ import org.apache.fop.fo.flow.TableRow; import org.apache.fop.fo.pagination.Flow; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.SimplePageMaster; -import org.apache.fop.fo.properties.EnumProperty; -import org.apache.fop.fo.properties.FixedLength; -import org.apache.fop.fo.properties.LengthProperty; import org.apache.fop.fo.properties.Property; -import org.apache.fop.fo.properties.StringProperty; import org.apache.fop.fo.Constants; import org.apache.fop.fo.FOText; import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes; @@ -175,19 +171,17 @@ public class RTFHandler extends FOEventHandler { sect = docArea.newSection(); //read page size and margins, if specified - Property prop; - if ((prop = pageSeq.getProperty(Constants.PR_MASTER_REFERENCE)) != null) { - String reference = prop.getString(); + + String reference = pageSeq.getMasterReference(); - SimplePageMaster pagemaster + SimplePageMaster pagemaster = pageSeq.getRoot().getLayoutMasterSet().getSimplePageMaster(reference); - //only simple-page-master supported, so pagemaster may be null - if (pagemaster != null) { - sect.getRtfAttributes().set( - PageAttributesConverter.convertPageAttributes( - pagemaster)); - } + //only simple-page-master supported, so pagemaster may be null + if (pagemaster != null) { + sect.getRtfAttributes().set( + PageAttributesConverter.convertPageAttributes( + pagemaster)); } builderContext.pushContainer(sect); @@ -221,7 +215,7 @@ public class RTFHandler extends FOEventHandler { } try { - if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-body")) { + if (fl.getFlowName().equals("xsl-region-body")) { // if there is no header in current page-sequence but there has been // a header in a previous page-sequence, insert an empty header. if (bPrevHeaderSpecified && !bHeaderSpecified) { @@ -246,7 +240,7 @@ public class RTFHandler extends FOEventHandler { contAfter.newAfter(attr); } - } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-before")) { + } else if (fl.getFlowName().equals("xsl-region-before")) { bHeaderSpecified = true; bPrevHeaderSpecified = true; @@ -263,7 +257,7 @@ public class RTFHandler extends FOEventHandler { RtfBefore before = c.newBefore(beforeAttributes); builderContext.pushContainer(before); - } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-after")) { + } else if (fl.getFlowName().equals("xsl-region-after")) { bFooterSpecified = true; bPrevFooterSpecified = true; @@ -300,11 +294,11 @@ public class RTFHandler extends FOEventHandler { } try { - if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-body")) { + if (fl.getFlowName().equals("xsl-region-body")) { //just do nothing - } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-before")) { + } else if (fl.getFlowName().equals("xsl-region-before")) { builderContext.popContainer(); - } else if (fl.getPropString(Constants.PR_FLOW_NAME).equals("xsl-region-after")) { + } else if (fl.getFlowName().equals("xsl-region-after")) { builderContext.popContainer(); } } catch (Exception e) { @@ -618,8 +612,7 @@ public class RTFHandler extends FOEventHandler { } try { - RtfAttributes atts = TableAttributesConverter.convertRowAttributes (tb, - null); + RtfAttributes atts = TableAttributesConverter.convertTableBodyAttributes(tb); RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this); tbl.setHeaderAttribs(atts); @@ -719,16 +712,16 @@ public class RTFHandler extends FOEventHandler { RtfTableCell cell = row.newTableCell((int)width, atts); //process number-rows-spanned attribute - Property p = null; - if ((p = tc.getProperty(Constants.PR_NUMBER_ROWS_SPANNED)) != null) { + int numberRowsSpanned = tc.getNumberRowsSpanned(); + if (numberRowsSpanned > 1) { // Start vertical merge cell.setVMerge(RtfTableCell.MERGE_START); // set the number of rows spanned - tctx.setCurrentColumnRowSpanning(new Integer(p.getNumber().intValue()), + tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), cell.getRtfAttributes()); } else { - tctx.setCurrentColumnRowSpanning(new Integer(1), null); + tctx.setCurrentColumnRowSpanning(new Integer(numberRowsSpanned), null); } builderContext.pushContainer(cell); @@ -914,15 +907,10 @@ public class RTFHandler extends FOEventHandler { RtfHyperLink link=textrun.addHyperlink(new RtfAttributes()); - StringProperty internal - = (StringProperty)basicLink.getProperty(Constants.PR_INTERNAL_DESTINATION); - StringProperty external - = (StringProperty)basicLink.getProperty(Constants.PR_EXTERNAL_DESTINATION); - - if(external != null) { - link.setExternalURL(external.getString()); - } else if(internal != null) { - link.setInternalURL(internal.getString()); + if (basicLink.getExternalDestination() != null) { + link.setExternalURL(basicLink.getExternalDestination()); + } else { + link.setInternalURL(basicLink.getInternalDestination()); } builderContext.pushContainer(link); @@ -967,40 +955,18 @@ public class RTFHandler extends FOEventHandler { Property p = null; //get source file - if ((p = eg.getProperty(Constants.PR_SRC)) != null) { - newGraphic.setURL (p.getString()); - } else { - log.error("The attribute 'src' of <fo:external-graphic> is required."); - return; - } + newGraphic.setURL(eg.getSrc()); //get scaling - if ((p = eg.getProperty(Constants.PR_SCALING)) != null) { - EnumProperty e = (EnumProperty)p; - if (p.getEnum() == Constants.UNIFORM) { - newGraphic.setScaling ("uniform"); - } + if (eg.getScaling() == Constants.UNIFORM) { + newGraphic.setScaling ("uniform"); } //get width - if ((p = eg.getProperty(Constants.PR_WIDTH)) != null) { - LengthProperty lengthProp = (LengthProperty)p; - if (lengthProp.getLength() instanceof FixedLength) { - Float f = new Float(lengthProp.getLength().getValue() / 1000f); - String sValue = f.toString() + "pt"; - newGraphic.setWidth(sValue); - } - } + newGraphic.setWidth(eg.getWidth().getValue() / 1000f + "pt"); //get height - if ((p = eg.getProperty(Constants.PR_HEIGHT)) != null) { - LengthProperty lengthProp = (LengthProperty)p; - if (lengthProp.getLength() instanceof FixedLength) { - Float f = new Float(lengthProp.getLength().getValue() / 1000f); - String sValue = f.toString() + "pt"; - newGraphic.setHeight(sValue); - } - } + newGraphic.setHeight(eg.getHeight().getValue() / 1000f + "pt"); //TODO: make this configurable: // int compression = m_context.m_options.getRtfExternalGraphicCompressionRate (); @@ -1037,9 +1003,6 @@ public class RTFHandler extends FOEventHandler { } try { - RtfAttributes rtfAttr - = TextAttributesConverter.convertAttributes(footnote); - IRtfTextrunContainer container = (IRtfTextrunContainer)builderContext.getContainer( IRtfTextrunContainer.class, @@ -1146,7 +1109,7 @@ public class RTFHandler extends FOEventHandler { RtfTextrun textrun = container.getTextrun(); textrun.pushAttributes(rtfAttr); - textrun.addString(c.getPropString(Constants.PR_CHARACTER)); + textrun.addString(new String(new char[] { c.getCharacter() })); textrun.popAttributes(); } catch (IOException ioe) { // FIXME could we throw Exception in all FOEventHandler events? diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 62308ebba..d37db2ca5 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -23,8 +23,11 @@ import org.apache.commons.logging.impl.SimpleLog; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.Constants; -import org.apache.fop.fo.FObj; -import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableRow; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.Property; import org.apache.fop.render.rtf.rtflib.rtfdoc.BorderAttributesConverter; import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes; @@ -73,11 +76,26 @@ public class TableAttributesConverter { * * @throws ConverterException On convertion error */ - static RtfAttributes convertTableAttributes(FObj fobj) + static RtfAttributes convertTableAttributes(Table fobj) + throws FOPException { + FOPRtfAttributes attrib = new FOPRtfAttributes(); + attrib.set(ITableAttributes.ATTR_ROW_LEFT_INDENT, fobj.getCommonMarginBlock().marginLeft); + return attrib; + } + + /** + * Converts table-only attributes to rtf attributes. + * + * @param attrs Given attributes + * @param defaultAttributes Default rtf attributes + * + * @return All valid rtf attributes together + * + * @throws ConverterException On convertion error + */ + static RtfAttributes convertTableBodyAttributes(TableBody fobj) throws FOPException { FOPRtfAttributes attrib = new FOPRtfAttributes(); - attrib.set(ITableAttributes.ATTR_ROW_LEFT_INDENT, - fobj.getProperty(Constants.PR_MARGIN_LEFT).getLength()); return attrib; } @@ -89,53 +107,36 @@ public class TableAttributesConverter { * * @throws ConverterException On conversion error */ - static RtfAttributes convertCellAttributes(FObj fobj) + static RtfAttributes convertCellAttributes(TableCell fobj) throws FOPException { Property p; RtfColorTable colorTable = RtfColorTable.getInstance(); - PropertyList propList = fobj.getPropertyList(); - FOPRtfAttributes attrib = new FOPRtfAttributes(); boolean isBorderPresent = false; // Cell background color - if ((p = propList.getNearestSpecified( - Constants.PR_BACKGROUND_COLOR)) != null) { - ColorType color = p.getColorType(); - if (color != null) { - if (color.getAlpha() != 0 - || color.getRed() != 0 - || color.getGreen() != 0 - || color.getBlue() != 0) { - attrib.set( - ITableAttributes.CELL_COLOR_BACKGROUND, color); - } - } else { - log.warn("Named color '" + p.toString() + "' not found. "); - } - + ColorType color = fobj.getCommonBorderPaddingBackground().backgroundColor; + if (color.getAlpha() != 0 + || color.getRed() != 0 + || color.getGreen() != 0 + || color.getBlue() != 0) { + attrib.set(ITableAttributes.CELL_COLOR_BACKGROUND, color); } - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_TOP, - Constants.PR_BORDER_TOP_COLOR, - Constants.PR_BORDER_TOP_STYLE, - Constants.PR_BORDER_TOP_WIDTH); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_BOTTOM, - Constants.PR_BORDER_BOTTOM_COLOR, - Constants.PR_BORDER_BOTTOM_STYLE, - Constants.PR_BORDER_BOTTOM_WIDTH); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_LEFT, - Constants.PR_BORDER_LEFT_COLOR, - Constants.PR_BORDER_LEFT_STYLE, - Constants.PR_BORDER_LEFT_WIDTH); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_RIGHT, - Constants.PR_BORDER_RIGHT_COLOR, - Constants.PR_BORDER_RIGHT_STYLE, - Constants.PR_BORDER_RIGHT_WIDTH); - - int n = fobj.getProperty(Constants.PR_NUMBER_COLUMNS_SPANNED).getNumber().intValue(); + + CommonBorderPaddingBackground border = fobj.getCommonBorderPaddingBackground(); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.BEFORE, + attrib, ITableAttributes.CELL_BORDER_TOP); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.AFTER, + attrib, ITableAttributes.CELL_BORDER_BOTTOM); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.START, + attrib, ITableAttributes.CELL_BORDER_LEFT); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.END, + attrib, ITableAttributes.CELL_BORDER_RIGHT); + + int n = fobj.getNumberColumnsSpanned(); // Column spanning : if (n > 1) { attrib.set(ITableAttributes.COLUMN_SPAN, n); @@ -154,7 +155,7 @@ public class TableAttributesConverter { * @return All valid rtf attributes together * @throws ConverterException On converion error */ - static RtfAttributes convertRowAttributes(FObj fobj, + static RtfAttributes convertRowAttributes(TableRow fobj, RtfAttributes rtfatts) throws FOPException { @@ -163,10 +164,10 @@ public class TableAttributesConverter { RtfAttributes attrib = null; - if (rtfatts == null) { - attrib = new RtfAttributes(); - } else { - attrib = rtfatts; + if (rtfatts == null) { + attrib = new RtfAttributes(); + } else { + attrib = rtfatts; } String attrValue; @@ -174,30 +175,24 @@ public class TableAttributesConverter { //need to set a default width //check for keep-together row attribute - if ((p = fobj.getProperty(Constants.PR_KEEP_TOGETHER).getKeep().getWithinPage()) != null) { - attrib.set(ITableAttributes.ROW_KEEP_TOGETHER); - } - if ((p = fobj.getProperty(Constants.PR_KEEP_TOGETHER)) != null) { + if (fobj.getKeepTogether().getWithinPage().getEnum() == Constants.ALWAYS) { attrib.set(ITableAttributes.ROW_KEEP_TOGETHER); } //Check for keep-with-next row attribute. - if ((p = fobj.getProperty(Constants.PR_KEEP_WITH_NEXT)) != null) { + if (fobj.getKeepWithNext().getWithinPage().getEnum() == Constants.ALWAYS) { attrib.set(ITableAttributes.ROW_KEEP_WITH_NEXT); } //Check for keep-with-previous row attribute. - if ((p = fobj.getProperty(Constants.PR_KEEP_WITH_PREVIOUS)) != null) { + if (fobj.getKeepWithPrevious().getWithinPage().getEnum() == Constants.ALWAYS) { attrib.set(ITableAttributes.ROW_KEEP_WITH_PREVIOUS); } //Check for height row attribute. - if ((p = fobj.getProperty(Constants.PR_HEIGHT)) != null) { - Float f = new Float(p.getLength().getValue() / 1000); - attrValue = f.toString() + "pt"; - attrib.set(ITableAttributes.ROW_HEIGHT, - (int)FoUnitsConverter.getInstance().convertToTwips(attrValue)); + if (!fobj.getHeight().isAuto()) { + attrib.set(ITableAttributes.ROW_HEIGHT, fobj.getHeight().getValue() / (1000 / 20)); } /* to write a border to a side of a cell one must write the directional @@ -213,23 +208,16 @@ public class TableAttributesConverter { * it is implemented that the border type is the value of the border * place. */ - PropertyList propList = fobj.getPropertyList(); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_TOP, - Constants.PR_BORDER_TOP_COLOR, - Constants.PR_BORDER_TOP_STYLE, - Constants.PR_BORDER_TOP_WIDTH); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_BOTTOM, - Constants.PR_BORDER_BOTTOM_COLOR, - Constants.PR_BORDER_BOTTOM_STYLE, - Constants.PR_BORDER_BOTTOM_WIDTH); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_LEFT, - Constants.PR_BORDER_LEFT_COLOR, - Constants.PR_BORDER_LEFT_STYLE, - Constants.PR_BORDER_LEFT_WIDTH); - BorderAttributesConverter.makeBorder(propList, attrib, ITableAttributes.CELL_BORDER_RIGHT, - Constants.PR_BORDER_RIGHT_COLOR, - Constants.PR_BORDER_RIGHT_STYLE, - Constants.PR_BORDER_RIGHT_WIDTH); + CommonBorderPaddingBackground border = fobj.getCommonBorderPaddingBackground(); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.BEFORE, + attrib, ITableAttributes.CELL_BORDER_TOP); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.AFTER, + attrib, ITableAttributes.CELL_BORDER_BOTTOM); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.START, + attrib, ITableAttributes.CELL_BORDER_LEFT); + BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.END, + attrib, ITableAttributes.CELL_BORDER_RIGHT); + /* ep = (EnumProperty)fobj.getProperty(Constants.PR_BORDER_TOP_STYLE); if (ep != null && ep.getEnum() != Constants.NONE) { diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index ac667297d..6efa54ad7 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -24,11 +24,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.SimpleLog; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.ColorType; -import org.apache.fop.datatypes.Length; import org.apache.fop.fo.Constants; -import org.apache.fop.fo.FObj; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.PageNumber; import org.apache.fop.fo.properties.ColorTypeProperty; -import org.apache.fop.fo.properties.EnumProperty; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.CommonFont; +import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFontManager; @@ -52,19 +57,15 @@ class TextAttributesConverter { * Converts all known text FO properties to RtfAttributes * @param props list of FO properites, which are to be converted */ - public static RtfAttributes convertAttributes(FObj fobj) + public static RtfAttributes convertAttributes(Block fobj) throws FOPException { FOPRtfAttributes attrib = new FOPRtfAttributes(); - attrBlockFontFamily(fobj, attrib); - attrBlockFontWeight(fobj, attrib); - attrBlockFontSize(fobj, attrib); - attrBlockFontColor(fobj, attrib); - attrBlockFontItalic(fobj, attrib); - attrBlockFontUnderline(fobj, attrib); - attrBlockBackgroundColor(fobj, attrib); - attrBlockSpaceBeforeAfter(fobj, attrib); - attrBlockMargins(fobj, attrib); - attrBlockTextAlign(fobj, attrib); + attrFont(fobj.getCommonFont(), attrib); + attrFontColor(fobj.getColor(), attrib); + //attrTextDecoration(fobj.getTextDecoration(), attrib); + attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); + attrBlockMargin(fobj.getCommonMarginBlock(), attrib); + attrBlockTextAlign(fobj.getTextAlign(), attrib); return attrib; } @@ -73,19 +74,11 @@ class TextAttributesConverter { * Converts all known text FO properties to RtfAttributes * @param props list of FO properites, which are to be converted */ - public static RtfAttributes convertBlockContainerAttributes(FObj fobj) + public static RtfAttributes convertBlockContainerAttributes(BlockContainer fobj) throws FOPException { FOPRtfAttributes attrib = new FOPRtfAttributes(); - attrBlockFontFamily(fobj, attrib); - attrBlockFontWeight(fobj, attrib); - attrBlockFontSize(fobj, attrib); - attrBlockFontColor(fobj, attrib); - attrBlockFontItalic(fobj, attrib); - attrBlockFontUnderline(fobj, attrib); - attrBlockBackgroundColor(fobj, attrib); - attrBlockSpaceBeforeAfter(fobj, attrib); - attrBlockMargins(fobj, attrib); - attrBlockTextAlign(fobj, attrib); + attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); + attrBlockMargin(fobj.getCommonMarginBlock(), attrib); //attrBlockDimension(fobj, attrib); return attrib; @@ -96,101 +89,99 @@ class TextAttributesConverter { * @param fobj FObj whose properties are to be converted */ public static RtfAttributes convertCharacterAttributes( - FObj fobj) throws FOPException { - - RtfAttributes attrib = new RtfAttributes(); - attrBlockFontFamily(fobj, attrib); - attrBlockFontWeight(fobj, attrib); - attrBlockFontSize(fobj, attrib); - attrBlockFontColor(fobj, attrib); - attrBlockFontItalic(fobj, attrib); - attrBlockFontUnderline(fobj, attrib); - attrBlockBackgroundColor(fobj, attrib); + Character fobj) throws FOPException { + + FOPRtfAttributes attrib = new FOPRtfAttributes(); + attrFont(fobj.getCommonFont(), attrib); + attrFontColor(fobj.getColor(), attrib); + attrTextDecoration(fobj.getTextDecoration(), attrib); + + attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); return attrib; } + /** + * Converts all character related FO properties to RtfAttributes. + * @param fobj FObj whose properties are to be converted + */ + public static RtfAttributes convertCharacterAttributes( + PageNumber fobj) throws FOPException { - private static void attrBlockFontFamily(FObj fobj, RtfAttributes rtfAttr) { - String fopValue = fobj.getProperty(Constants.PR_FONT_FAMILY).getString(); - - if (fopValue != null) { - rtfAttr.set(RtfText.ATTR_FONT_FAMILY, - RtfFontManager.getInstance().getFontNumber(fopValue)); - } + FOPRtfAttributes attrib = new FOPRtfAttributes(); + attrFont(fobj.getCommonFont(), attrib); + attrTextDecoration(fobj.getTextDecoration(), attrib); + attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); + return attrib; } - private static void attrBlockFontSize(FObj fobj, RtfAttributes rtfAttr) { - int fopValue = fobj.getPropLength(Constants.PR_FONT_SIZE) / 500; - rtfAttr.set("fs", fopValue); - } + /** + * Converts all character related FO properties to RtfAttributes. + * @param fobj FObj whose properties are to be converted + */ + public static RtfAttributes convertCharacterAttributes( + Inline fobj) throws FOPException { - private static void attrBlockFontColor(FObj fobj, RtfAttributes rtfAttr) { - // Cell background color - ColorTypeProperty colorTypeProp = (ColorTypeProperty)fobj.getProperty(Constants.PR_COLOR); - if (colorTypeProp != null) { - ColorType colorType = colorTypeProp.getColorType(); - if (colorType != null) { - if (colorType.getAlpha() != 0 - || colorType.getRed() != 0 - || colorType.getGreen() != 0 - || colorType.getBlue() != 0) { - rtfAttr.set( - RtfText.ATTR_FONT_COLOR, - convertFOPColorToRTF(colorType)); - } - } else { - log.warn("Named color '" + colorTypeProp.toString() + "' not found. "); - } - } + FOPRtfAttributes attrib = new FOPRtfAttributes(); + attrFont(fobj.getCommonFont(), attrib); + attrFontColor(fobj.getColor(), attrib); + attrTextDecoration(fobj.getTextDecoration(), attrib); + attrBackgroundColor(fobj.getCommonBorderPaddingBackground(), attrib); + return attrib; } + private static void attrFont(CommonFont font, FOPRtfAttributes rtfAttr) { + rtfAttr.set(RtfText.ATTR_FONT_FAMILY, + RtfFontManager.getInstance().getFontNumber(font.fontFamily)); + rtfAttr.set("fs", font.fontSize); - - private static void attrBlockFontWeight(FObj fobj, RtfAttributes rtfAttr) { - String fopValue = fobj.getProperty(Constants.PR_FONT_WEIGHT).getString(); - if (fopValue == "bold" || fopValue == "700") { + if (font.fontWeight.equals("bold") || font.fontWeight.equals("700")) { rtfAttr.set("b", 1); } else { rtfAttr.set("b", 0); } - } - - private static void attrBlockFontItalic(FObj fobj, RtfAttributes rtfAttr) { - String fopValue = fobj.getProperty(Constants.PR_FONT_STYLE).getString(); - if (fopValue.equals("italic")) { + + if (font.fontStyle.equals("italic")) { rtfAttr.set(RtfText.ATTR_ITALIC, 1); } else { rtfAttr.set(RtfText.ATTR_ITALIC, 0); } + + + } + + + private static void attrFontColor(ColorType colorType, RtfAttributes rtfAttr) { + // Cell background color + if (colorType != null) { + if (colorType.getAlpha() != 0 + || colorType.getRed() != 0 + || colorType.getGreen() != 0 + || colorType.getBlue() != 0) { + rtfAttr.set(RtfText.ATTR_FONT_COLOR, + convertFOPColorToRTF(colorType)); + } + } } - private static void attrBlockFontUnderline(FObj fobj, RtfAttributes rtfAttr) { - EnumProperty enumProp = (EnumProperty) fobj.getProperty(Constants.PR_TEXT_DECORATION); - if (enumProp.getEnum() == Constants.UNDERLINE) { + + + private static void attrTextDecoration(int textDecoration, RtfAttributes rtfAttr) { + if (textDecoration == Constants.UNDERLINE) { rtfAttr.set(RtfText.ATTR_UNDERLINE, 1); } else { rtfAttr.set(RtfText.ATTR_UNDERLINE, 0); } } - private static void attrBlockSpaceBeforeAfter(FObj fobj, FOPRtfAttributes rtfAttr) { - Length space; - space = fobj.getProperty(Constants.PR_SPACE_BEFORE).getLengthRange().getOptimum().getLength(); - if (space.getValue() >= 0) { - rtfAttr.set(RtfText.SPACE_BEFORE, space); - } - space = fobj.getProperty(Constants.PR_SPACE_AFTER).getLengthRange().getOptimum().getLength(); - if (space.getValue() >= 0) { - rtfAttr.set(RtfText.SPACE_AFTER, space); - } + private static void attrBlockMargin(CommonMarginBlock cmb, FOPRtfAttributes rtfAttr) { + rtfAttr.set(RtfText.SPACE_BEFORE, + cmb.spaceBefore.getOptimum().getLength()); + rtfAttr.set(RtfText.SPACE_AFTER, + cmb.spaceAfter.getOptimum().getLength()); + rtfAttr.set(RtfText.LEFT_INDENT_BODY, cmb.marginLeft); + rtfAttr.set(RtfText.RIGHT_INDENT_BODY, cmb.marginRight); } - private static void attrBlockMargins(FObj fobj, FOPRtfAttributes rtfAttr) { - rtfAttr.set(RtfText.LEFT_INDENT_BODY, - fobj.getProperty(Constants.PR_MARGIN_LEFT).getLength()); - rtfAttr.set(RtfText.RIGHT_INDENT_BODY, - fobj.getProperty(Constants.PR_MARGIN_RIGHT).getLength()); - } /* private static void attrBlockDimension(FObj fobj, FOPRtfAttributes rtfAttr) { @@ -205,10 +196,9 @@ class TextAttributesConverter { } */ - private static void attrBlockTextAlign(FObj fobj, RtfAttributes rtfAttr) { - int fopValue = fobj.getPropEnum(Constants.PR_TEXT_ALIGN); + private static void attrBlockTextAlign(int enum, RtfAttributes rtfAttr) { String rtfValue = null; - switch (fopValue) { + switch (enum) { case Constants.CENTER: rtfValue = RtfText.ALIGN_CENTER; break; @@ -232,8 +222,8 @@ class TextAttributesConverter { * @param bl the Block object the properties are read from * @param rtfAttr the RtfAttributes object the attributes are written to */ - private static void attrBlockBackgroundColor(FObj fobj, RtfAttributes rtfAttr) { - ColorType fopValue = fobj.getProperty(Constants.PR_BACKGROUND_COLOR).getColorType(); + private static void attrBackgroundColor(CommonBorderPaddingBackground bpb, RtfAttributes rtfAttr) { + ColorType fopValue = bpb.backgroundColor; int rtfColor = 0; /* FOP uses a default background color of "transparent", which is actually a transparent black, which is generally not suitable as a diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java index 4f329e0b7..6a5f667b7 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java @@ -28,6 +28,7 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc; import org.apache.fop.fo.Constants; import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.render.rtf.FOPRtfAttributes; /** Constants for RTF border attribute names, and a static method for converting @@ -131,6 +132,18 @@ public class BorderAttributesConverter { } } + public static void makeBorder(CommonBorderPaddingBackground border, int side, + RtfAttributes attributes, String controlWord) { + int styleEnum = border.getBorderStyle(side); + if (styleEnum != Constants.NONE) { + FOPRtfAttributes attrs = new FOPRtfAttributes(); + attrs.set(BORDER_COLOR, border.getBorderColor(side)); + attrs.set(convertAttributetoRtf(styleEnum)); + attrs.set(BORDER_WIDTH, border.getBorderWidth(side, false)); + attributes.set(controlWord, attrs); + } + } + /** * * @param iBorderStyle the border style to be converted |