jeremias 2003/11/08 06:01:24
Modified: src/java/org/apache/fop/render/rtf/rtflib/rtfdoc
RtfTextrun.java RtfExternalGraphic.java
src/java/org/apache/fop/render/rtf RTFHandler.java
src/java/org/apache/fop/render/rtf/rtflib/tools
ImageUtil.java
Log:
RTF: added support for fo:external-graphic
Submitted By: Peter Herweg <[EMAIL PROTECTED]>
Revision Changes Path
1.2 +5 -0
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
Index: RtfTextrun.java
===================================================================
RCS file:
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RtfTextrun.java 4 Nov 2003 23:59:11 -0000 1.1
+++ RtfTextrun.java 8 Nov 2003 14:01:23 -0000 1.2
@@ -63,6 +63,7 @@
import java.util.Iterator;
import java.io.IOException;
import org.apache.fop.render.rtf.rtflib.exceptions.RtfStructureException;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic;
/** Class which contains a linear text run. It has methods to add attributes,
text, paragraph breaks....
* @author Peter Herweg, [EMAIL PROTECTED]
@@ -166,6 +167,10 @@
public void addPageNumber(RtfAttributes attr) throws IOException {
RtfPageNumber r=new RtfPageNumber(this, writer, attr);
+ }
+
+ public RtfExternalGraphic newImage() throws IOException {
+ return new RtfExternalGraphic(this, writer);
}
/**
1.2 +7 -7
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java
Index: RtfExternalGraphic.java
===================================================================
RCS file:
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExternalGraphic.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RtfExternalGraphic.java 4 Nov 2003 23:59:11 -0000 1.1
+++ RtfExternalGraphic.java 8 Nov 2003 14:01:23 -0000 1.2
@@ -277,10 +277,10 @@
// convert
int to = ImageConstants.CONVERT_TO [type -
ImageConstants.I_TO_CONVERT_BASIS];
- if (to == ImageConstants.I_JPG) {
- ByteArrayOutputStream out = null;
+// if (to == ImageConstants.I_JPG) {
+// ByteArrayOutputStream out = null;
// try {
- //convert to jpeg
+// //convert to jpeg
// out = new ByteArrayOutputStream();
// Encoder jpgEncoder = new Encoder(graphicCompressionRate, out);
// jpgEncoder.encodeJPEG(data);
@@ -292,11 +292,11 @@
// + "not be created (src = '" + url + "'");
// }
// finally {
- out.close();
+// out.close();
// }
- } else {
+// } else {
type = ImageConstants.I_NOT_SUPPORTED;
- }
+// }
}
1.2 +65 -1 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RTFHandler.java 4 Nov 2003 23:59:11 -0000 1.1
+++ RTFHandler.java 8 Nov 2003 14:01:24 -0000 1.2
@@ -59,7 +59,9 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.ColorType;
+import org.apache.fop.fo.EnumProperty;
import org.apache.fop.fo.FOInputHandler;
+import org.apache.fop.datatypes.FixedLength;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.ExternalGraphic;
import org.apache.fop.fo.flow.Inline;
@@ -78,10 +80,12 @@
import org.apache.fop.fo.pagination.SimplePageMaster;
import org.apache.fop.fo.properties.Constants;
import org.apache.fop.fo.Property;
+import org.apache.fop.fo.LengthProperty;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.apps.Document;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfBeforeContainer;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfExternalGraphicContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfPageNumberContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfParagraphContainer;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTextrunContainer;
@@ -91,6 +95,7 @@
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFontManager;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph;
@@ -111,6 +116,7 @@
* @author Trembicki-Guy, Ed <[EMAIL PROTECTED]>
* @author Boris Poudérous <[EMAIL PROTECTED]>
* @author Peter Herweg <[EMAIL PROTECTED]>
+ * @author Andreas Putz <[EMAIL PROTECTED]>
*/
public class RTFHandler extends FOInputHandler {
@@ -693,6 +699,64 @@
* @see org.apache.fop.fo.FOInputHandler#image(ExternalGraphic)
*/
public void image(ExternalGraphic eg) {
+ try {
+
+
+ final IRtfTextrunContainer c =
+
(IRtfTextrunContainer)builderContext.getContainer(IRtfTextrunContainer.class,
+ true, this);
+
+ final RtfExternalGraphic newGraphic = c.getTextrun().newImage();
+
+ Property p=null;
+
+ //get source file
+ if((p=eg.properties.get("src"))!=null) {
+ newGraphic.setURL (p.getString());
+ } else {
+ log.error("The attribute 'src' of <fo:external-graphic> is
required.");
+ return;
+ }
+
+ //get scaling
+ if((p=eg.properties.get("scaling"))!=null) {
+ EnumProperty e=(EnumProperty)p;
+ if(p.getEnum()==Constants.UNIFORM) {
+ newGraphic.setScaling ("uniform");
+ }
+ }
+
+ //get width
+ if((p=eg.properties.get("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);
+ }
+ }
+
+ //get height
+ if((p=eg.properties.get("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);
+ }
+ }
+
+ //TODO: make this configurable:
+ // int compression =
m_context.m_options.getRtfExternalGraphicCompressionRate ();
+ int compression = 0;
+ if (compression != 0) {
+ if (! newGraphic.setCompressionRate (compression)) {
+ log.warn("The compression rate " + compression + " is invalid.
The value has to be between 1 and 100 %.");
+ }
+ }
+ } catch(Exception e) {
+ log.error("image: " + e.getMessage());
+ }
}
/**
1.2 +5 -1
xml-fop/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java
Index: ImageUtil.java
===================================================================
RCS file:
/home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/rtflib/tools/ImageUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ImageUtil.java 4 Nov 2003 23:59:13 -0000 1.1
+++ ImageUtil.java 8 Nov 2003 14:01:24 -0000 1.2
@@ -95,6 +95,10 @@
for (int i = 0; i < len; i++) {
if (Character.isDigit (s.charAt (i))) {
retString += s.charAt (i);
+ } else {
+ //for example "600.0pt" has to be exited,
+ //when the dot is reached.
+ break;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]