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
Index: src/java/org/apache/fop/pdf/PDFMetadata.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFMetadata.java (revision 750423)
+++ src/java/org/apache/fop/pdf/PDFMetadata.java (working copy)
@@ -59,9 +59,8 @@
}
/** {...@inheritdoc} */
- protected void setupFilterList() {
- addDefaultFilter(PDFFilterList.METADATA_FILTER);
- super.setupFilterList();
+ protected String getDefaultFilterName() {
+ return PDFFilterList.METADATA_FILTER;
}
/**
Index: src/java/org/apache/fop/pdf/PDFImageXObject.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFImageXObject.java (revision 750423)
+++ src/java/org/apache/fop/pdf/PDFImageXObject.java (working copy)
@@ -159,14 +159,11 @@
}
/**
- * This sets up the default filters for XObjects. It uses the PDFImage
- * instance to determine what default filters to apply.
* {...@inheritdoc}
+ * This class uses the PDFImage instance to determine the default filter.
*/
- protected void setupFilterList() {
- addDefaultFilter(pdfimage.getFilterHint());
- super.setupFilterList();
+ protected String getDefaultFilterName() {
+ return pdfimage.getFilterHint();
}
-
}
Index: src/java/org/apache/fop/pdf/AbstractPDFFontStream.java
===================================================================
--- src/java/org/apache/fop/pdf/AbstractPDFFontStream.java (revision 750423)
+++ src/java/org/apache/fop/pdf/AbstractPDFFontStream.java (working copy)
@@ -33,9 +33,8 @@
}
/** {...@inheritdoc} */
- protected void setupFilterList() {
- addDefaultFilter(PDFFilterList.FONT_FILTER);
- super.setupFilterList();
+ protected String getDefaultFilterName() {
+ return PDFFilterList.FONT_FILTER;
}
}
Index: src/java/org/apache/fop/pdf/AbstractPDFStream.java
===================================================================
--- src/java/org/apache/fop/pdf/AbstractPDFStream.java (revision 750423)
+++ src/java/org/apache/fop/pdf/AbstractPDFStream.java (working copy)
@@ -47,21 +47,23 @@
* from outside.
*/
protected void setupFilterList() {
- addDefaultFilter(PDFFilterList.DEFAULT_FILTER);
+ if (!getFilterList().isInitialized()) {
+ getFilterList().addDefaultFilters(
+ getDocumentSafely().getFilterMap(),
+ getDefaultFilterName());
+ }
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
+ * Returns the name of a suitable filter for this PDF object.
+ *
+ * @return the default filter
+ * @see PDFFilterList
*/
- protected void addDefaultFilter(String filterName) {
- if (!getFilterList().isInitialized()) {
- getFilterList().addDefaultFilters(
- getDocumentSafely().getFilterMap(),
- filterName);
- }
+ protected String getDefaultFilterName() {
+ return PDFFilterList.DEFAULT_FILTER;
}
/**