You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2009/02/16 09:09:29 UTC

svn commit: r744851 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf: AbstractPDFFontStream.java AbstractPDFStream.java PDFImageXObject.java PDFMetadata.java PDFT1Stream.java PDFTTFStream.java

Author: jeremias
Date: Mon Feb 16 08:09:29 2009
New Revision: 744851

URL: http://svn.apache.org/viewvc?rev=744851&view=rev
Log:
Now using the "font" filter list entry for font streams.
Made T1 and TTF streams children of a commons base class.
Refactored default filter addition a bit.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFStream.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFImageXObject.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFMetadata.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFT1Stream.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTTFStream.java

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java?rev=744851&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java Mon Feb 16 08:09:29 2009
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.pdf;
+
+
+/**
+ * Base class for PDF font streams.
+ */
+public abstract class AbstractPDFFontStream extends AbstractPDFStream {
+
+    /**
+     * Main constructor.
+     */
+    public AbstractPDFFontStream() {
+        super();
+    }
+
+    /** {@inheritDoc} */
+    protected void setupFilterList() {
+        addDefaultFilter(PDFFilterList.FONT_FILTER);
+        super.setupFilterList();
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFFontStream.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFStream.java?rev=744851&r1=744850&r2=744851&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFStream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/AbstractPDFStream.java Mon Feb 16 08:09:29 2009
@@ -47,13 +47,21 @@
      * from outside.
      */
     protected void setupFilterList() {
+        addDefaultFilter(PDFFilterList.DEFAULT_FILTER);
+        prepareImplicitFilters();
+        getDocument().applyEncryption(this);
+    }
+
+    /**
+     * Adds the default filter to the filter list if the filter list hasn't been initialized, yet.
+     * @param filterName the name of the default filter to use
+     */
+    protected void addDefaultFilter(String filterName) {
         if (!getFilterList().isInitialized()) {
             getFilterList().addDefaultFilters(
                 getDocumentSafely().getFilterMap(),
-                PDFFilterList.DEFAULT_FILTER);
+                filterName);
         }
-        prepareImplicitFilters();
-        getDocument().applyEncryption(this);
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFImageXObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFImageXObject.java?rev=744851&r1=744850&r2=744851&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFImageXObject.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFImageXObject.java Mon Feb 16 08:09:29 2009
@@ -164,11 +164,7 @@
      * {@inheritDoc}
      */
     protected void setupFilterList() {
-        if (!getFilterList().isInitialized()) {
-            getFilterList().addDefaultFilters(
-                getDocumentSafely().getFilterMap(),
-                pdfimage.getFilterHint());
-        }
+        addDefaultFilter(pdfimage.getFilterHint());
         super.setupFilterList();
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFMetadata.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFMetadata.java?rev=744851&r1=744850&r2=744851&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFMetadata.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFMetadata.java Mon Feb 16 08:09:29 2009
@@ -60,11 +60,7 @@
 
     /** {@inheritDoc} */
     protected void setupFilterList() {
-        if (!getFilterList().isInitialized()) {
-            getFilterList().addDefaultFilters(
-                getDocumentSafely().getFilterMap(),
-                PDFFilterList.METADATA_FILTER);
-        }
+        addDefaultFilter(PDFFilterList.METADATA_FILTER);
         super.setupFilterList();
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFT1Stream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFT1Stream.java?rev=744851&r1=744850&r2=744851&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFT1Stream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFT1Stream.java Mon Feb 16 08:09:29 2009
@@ -28,13 +28,11 @@
 /**
  * Special PDFStream for embedding Type 1 fonts.
  */
-public class PDFT1Stream extends AbstractPDFStream {
+public class PDFT1Stream extends AbstractPDFFontStream {
 
     private PFBData pfb;
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     protected int getSizeHint() throws IOException {
         if (this.pfb != null) {
             return pfb.getLength();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTTFStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTTFStream.java?rev=744851&r1=744850&r2=744851&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTTFStream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFTTFStream.java Mon Feb 16 08:09:29 2009
@@ -20,13 +20,15 @@
 package org.apache.fop.pdf;
 
 import java.io.IOException;
+import java.io.OutputStream;
 
 /**
  * Special PDFStream for embeddable TrueType fonts.
  */
-public class PDFTTFStream extends PDFStream {
+public class PDFTTFStream extends AbstractPDFFontStream {
 
     private int origLength;
+    private byte[] ttfData;
 
     /**
      * Main constructor
@@ -37,6 +39,15 @@
         origLength = len;
     }
 
+    /** {@inheritDoc} */
+    protected int getSizeHint() throws IOException {
+        if (this.ttfData != null) {
+            return ttfData.length;
+        } else {
+            return 0; //no hint available
+        }
+    }
+
     /**
      * Overload the base object method so we don't have to copy
      * byte arrays around so much
@@ -54,6 +65,11 @@
     }
 
     /** {@inheritDoc} */
+    protected void outputRawStreamData(OutputStream out) throws IOException {
+        out.write(this.ttfData);
+    }
+
+    /** {@inheritDoc} */
     protected void populateStreamDict(Object lengthEntry) {
         put("Length1", origLength);
         super.populateStreamDict(lengthEntry);
@@ -66,8 +82,8 @@
      * @throws IOException in case of an I/O problem
      */
     public void setData(byte[] data, int size) throws IOException {
-        this.data.clear();
-        getBufferOutputStream().write(data, 0, size);
+        this.ttfData = new byte[size];
+        System.arraycopy(data, 0, this.ttfData, 0, size);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Re: svn commit: r744851 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf: AbstractPDFFontStream.java AbstractPDFStream.java PDFImageXObject.java PDFMetadata.java PDFT1Stream.java PDFTTFStream.java

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Looks good.

On 06.03.2009 12:27:15 Vincent Hennebert wrote:
> Hi Jeremias,
> 
> Sorry to get back so late on this.
> 
> > Author: jeremias
> > Date: Mon Feb 16 08:09:29 2009
> > New Revision: 744851
> > 
> > URL: http://svn.apache.org/viewvc?rev=744851&view=rev
> > Log:
> > Now using the "font" filter list entry for font streams.
> > Made T1 and TTF streams children of a commons base class.
> > Refactored default filter addition a bit.
> 
> I think this could still be further simplified. Is the code ‘fail-fast’?
> I mean: What happens if, when implementing a new sub-class, a developer
> forgets to call super.setupFilterList? Will the code fail quickly at an
> obvious place or will you figure it out only after having wasted
> a certain amount of time in a debugging session?
> 
> Anyway, please have a look at the attached patch. The idea is not to ask
> sub-classes to set up the filter list themselves, but rather to ask them
> what is their default filter. That’s all they need to know, that’s the
> only thing that’s specific. Small change in the point of view. In the
> present case that may sound negligible or ridiculous or whatever, but
> I believe it illustrates the whole object-oriented philosophy. In more
> complex cases I think this can make a big difference.
> 
> If you’re ok with the patch I’ll apply it.
> 
> Thanks,
> Vincent




Jeremias Maerki


Re: svn commit: r744851 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf: AbstractPDFFontStream.java AbstractPDFStream.java PDFImageXObject.java PDFMetadata.java PDFT1Stream.java PDFTTFStream.java

Posted by Vincent Hennebert <vh...@gmail.com>.
Hi Jeremias,

Sorry to get back so late on this.

> Author: jeremias
> Date: Mon Feb 16 08:09:29 2009
> New Revision: 744851
> 
> URL: http://svn.apache.org/viewvc?rev=744851&view=rev
> Log:
> Now using the "font" filter list entry for font streams.
> Made T1 and TTF streams children of a commons base class.
> Refactored default filter addition a bit.

I think this could still be further simplified. Is the code ‘fail-fast’?
I mean: What happens if, when implementing a new sub-class, a developer
forgets to call super.setupFilterList? Will the code fail quickly at an
obvious place or will you figure it out only after having wasted
a certain amount of time in a debugging session?

Anyway, please have a look at the attached patch. The idea is not to ask
sub-classes to set up the filter list themselves, but rather to ask them
what is their default filter. That’s all they need to know, that’s the
only thing that’s specific. Small change in the point of view. In the
present case that may sound negligible or ridiculous or whatever, but
I believe it illustrates the whole object-oriented philosophy. In more
complex cases I think this can make a big difference.

If you’re ok with the patch I’ll apply it.

Thanks,
Vincent