bckfnn 2004/10/20 10:53:36 Modified: src/java/org/apache/fop/render/rtf ListAttributesConverter.java PageAttributesConverter.java RTFHandler.java TableAttributesConverter.java TextAttributesConverter.java src/java/org/apache/fop/render/rtf/rtflib/rtfdoc BorderAttributesConverter.java Log: 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 Revision Changes Path 1.9 +5 -10 xml-fop/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java Index: ListAttributesConverter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ListAttributesConverter.java 1 Oct 2004 09:19:15 -0000 1.8 +++ ListAttributesConverter.java 20 Oct 2004 17:53:35 -0000 1.9 @@ -20,10 +20,7 @@ //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 @@ 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 1.12 +21 -20 xml-fop/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java Index: PageAttributesConverter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- PageAttributesConverter.java 1 Oct 2004 09:22:15 -0000 1.11 +++ PageAttributesConverter.java 20 Oct 2004 17:53:35 -0000 1.12 @@ -21,13 +21,13 @@ 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 @@ 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 @@ 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 @@ //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) { 1.37 +30 -67 xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java Index: RTFHandler.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- RTFHandler.java 17 Oct 2004 20:12:57 -0000 1.36 +++ RTFHandler.java 20 Oct 2004 17:53:35 -0000 1.37 @@ -53,11 +53,7 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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 @@ } 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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ } try { - RtfAttributes rtfAttr - = TextAttributesConverter.convertAttributes(footnote); - IRtfTextrunContainer container = (IRtfTextrunContainer)builderContext.getContainer( IRtfTextrunContainer.class, @@ -1146,7 +1109,7 @@ 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? 1.20 +63 -75 xml-fop/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java Index: TableAttributesConverter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- TableAttributesConverter.java 19 Oct 2004 13:41:25 -0000 1.19 +++ TableAttributesConverter.java 20 Oct 2004 17:53:35 -0000 1.20 @@ -23,8 +23,11 @@ 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 @@ * * @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 @@ * * @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. "); - } - - } - 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); + 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); + } + + 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.getProperty(Constants.PR_NUMBER_COLUMNS_SPANNED).getNumber().intValue(); + int n = fobj.getNumberColumnsSpanned(); // Column spanning : if (n > 1) { attrib.set(ITableAttributes.COLUMN_SPAN, n); @@ -154,7 +155,7 @@ * @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 @@ 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 @@ //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 @@ * 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) { 1.18 +87 -97 xml-fop/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java Index: TextAttributesConverter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- TextAttributesConverter.java 1 Oct 2004 09:44:57 -0000 1.17 +++ TextAttributesConverter.java 20 Oct 2004 17:53:35 -0000 1.18 @@ -24,11 +24,16 @@ 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 @@ * 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 @@ * 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 @@ * @param fobj FObj whose properties are to be converted */ public static RtfAttributes convertCharacterAttributes( - FObj fobj) throws FOPException { + Character 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); + 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 attrBlockFontUnderline(FObj fobj, RtfAttributes rtfAttr) { - EnumProperty enumProp = (EnumProperty) fobj.getProperty(Constants.PR_TEXT_DECORATION); - if (enumProp.getEnum() == Constants.UNDERLINE) { + + 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 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 @@ } */ - 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 @@ * @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 1.4 +14 -1 xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java Index: BorderAttributesConverter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/BorderAttributesConverter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- BorderAttributesConverter.java 3 Oct 2004 18:05:15 -0000 1.3 +++ BorderAttributesConverter.java 20 Oct 2004 17:53:36 -0000 1.4 @@ -28,6 +28,7 @@ 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 @@ -127,6 +128,18 @@ attrs.set(BORDER_COLOR, propList.get(color).getColorType()); attrs.set(convertAttributetoRtf(styleEnum)); attrs.set(BORDER_WIDTH, propList.get(width).getLength()); + attributes.set(controlWord, attrs); + } + } + + 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); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]