Index: test/java/org/apache/fop/render/pdf/BasePDFTestCase.java
===================================================================
--- test/java/org/apache/fop/render/pdf/BasePDFTestCase.java (revision 540059)
+++ test/java/org/apache/fop/render/pdf/BasePDFTestCase.java (working copy)
@@ -93,7 +93,10 @@
return result;
}
- /** get FOP config File */
+ /**
+ * get FOP config File
+ * @return user config file to be used for testing
+ */
protected File getUserConfigFile() {
return new File("test/test.xconf");
}
Index: test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+/**
+ * tests font directory on system
+ */
+public class FontsDirectoryRecursiveTestCase extends BaseConstructiveUserConfigTestCase {
+
+ public FontsDirectoryRecursiveTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ protected String getUserConfigFilename() {
+ return "test_fonts_directory_recursive.xconf";
+ }
+}
Property changes on: test/java/org/apache/fop/config/FontsDirectoryRecursiveTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/java/org/apache/fop/config/EmbedUrlBadTestCase.java
===================================================================
--- test/java/org/apache/fop/config/EmbedUrlBadTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/EmbedUrlBadTestCase.java (working copy)
@@ -1,41 +0,0 @@
-/*
- * 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.config;
-
-import java.io.File;
-
-//
-/**
- * this font has an embed-url that does not exist on filesystem.
- */
-public class EmbedUrlBadTestCase extends BaseUserConfigTestCase {
-
- public EmbedUrlBadTestCase(String name) {
- super(name);
- }
-
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_embedurl_bad.xconf");
- }
-
- public String getName() {
- return "test_embedurl_bad.xconf";
- }
-}
Index: test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+/*
+ * this font has a malformed metrics-url
+ */
+public class FontMetricsUrlMalformedTestCase extends BaseDestructiveUserConfigTestCase {
+
+ public FontMetricsUrlMalformedTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_font_metricsurl_malformed.xconf";
+ }
+}
\ No newline at end of file
Property changes on: test/java/org/apache/fop/config/FontMetricsUrlMalformedTestCase.java
___________________________________________________________________
Name: svn:kewords
- Id
Index: test/java/org/apache/fop/config/FontAttributesMissingTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontAttributesMissingTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/FontAttributesMissingTestCase.java (working copy)
@@ -15,24 +15,22 @@
* limitations under the License.
*/
-/* $Id$ */
-
+/* $Id: $ */
package org.apache.fop.config;
-import java.io.File;
+/*
+ * this font is without a metrics-url or an embed-url
+ */
+public class FontAttributesMissingTestCase extends BaseDestructiveUserConfigTestCase {
-// this font is without a metrics-url or an embed-url
-public class FontAttributesMissingTestCase extends BaseUserConfigTestCase {
-
public FontAttributesMissingTestCase(String name) {
super(name);
}
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_fontattributes_missing.xconf");
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_font_attributes_missing.xconf";
}
-
- public String getName() {
- return "test_fontattributes_missing.xconf";
- }
}
Index: test/java/org/apache/fop/config/FontBaseBadTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontBaseBadTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/FontBaseBadTestCase.java (working copy)
@@ -15,15 +15,14 @@
* limitations under the License.
*/
-/* $Id$ */
-
+/* $Id: $ */
package org.apache.fop.config;
-import java.io.File;
+/*
+ * this font base does not exist and a relative font path is used
+ */
+public class FontBaseBadTestCase extends BaseDestructiveUserConfigTestCase {
-// this font base does not exist and a relative font path is used
-public class FontBaseBadTestCase extends BaseUserConfigTestCase {
-
public FontBaseBadTestCase(String name) {
super(name);
}
@@ -34,16 +33,9 @@
}
/**
- * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFile()
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
*/
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_fontbase_bad.xconf");
- }
-
- /**
- * @return configuration filename
- */
- public String getName() {
+ public String getUserConfigFilename() {
return "test_fontbase_bad.xconf";
}
}
Index: test/java/org/apache/fop/config/BaseConstructiveUserConfigTestCase.java
===================================================================
--- test/java/org/apache/fop/config/BaseConstructiveUserConfigTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/BaseConstructiveUserConfigTestCase.java (revision 0)
@@ -0,0 +1,44 @@
+/*
+ * 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.config;
+
+public abstract class BaseConstructiveUserConfigTestCase extends BaseUserConfigTestCase {
+
+ /**
+ * @see junit.framework.TestCase#TestCase(String)
+ */
+ public BaseConstructiveUserConfigTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Test using a standard FOP font
+ * @throws Exception checkstyle wants a comment here, even a silly one
+ */
+ public void testUserConfig() throws Exception {
+ try {
+ initConfig();
+ convertFO();
+ } catch (Exception e) {
+ // this should *not* happen!
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}
Property changes on: test/java/org/apache/fop/config/BaseConstructiveUserConfigTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/java/org/apache/fop/config/FontsAutoDetectTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontsAutoDetectTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontsAutoDetectTestCase.java (revision 0)
@@ -0,0 +1,33 @@
+/*
+ * 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.config;
+
+public class FontsAutoDetectTestCase extends BaseConstructiveUserConfigTestCase {
+
+ public FontsAutoDetectTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_fonts_autodetect.xconf";
+ }
+}
Property changes on: test/java/org/apache/fop/config/FontsAutoDetectTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+/**
+ * this font has a malformed embed-url
+ */
+public class FontEmbedUrlMalformedTestCase extends BaseDestructiveUserConfigTestCase {
+
+ public FontEmbedUrlMalformedTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_font_embedurl_malformed.xconf";
+ }
+}
Property changes on: test/java/org/apache/fop/config/FontEmbedUrlMalformedTestCase.java
___________________________________________________________________
Name: svn:kewords
- Id
Index: test/java/org/apache/fop/config/MetricsUrlMalformedTestCase.java
===================================================================
--- test/java/org/apache/fop/config/MetricsUrlMalformedTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/MetricsUrlMalformedTestCase.java (working copy)
@@ -1,38 +0,0 @@
-/*
- * 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.config;
-
-import java.io.File;
-
-// this font has a malformed metrics-url
-public class MetricsUrlMalformedTestCase extends BaseUserConfigTestCase {
-
- public MetricsUrlMalformedTestCase(String name) {
- super(name);
- }
-
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_metricsurl_malformed.xconf");
- }
-
- public String getName() {
- return "test_metricsurl_malformed.xconf";
- }
-}
Index: test/java/org/apache/fop/config/BaseDestructiveUserConfigTestCase.java
===================================================================
--- test/java/org/apache/fop/config/BaseDestructiveUserConfigTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/BaseDestructiveUserConfigTestCase.java (revision 0)
@@ -0,0 +1,44 @@
+/*
+ * 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.config;
+
+import org.apache.fop.apps.FOPException;
+
+public abstract class BaseDestructiveUserConfigTestCase extends BaseUserConfigTestCase {
+
+ /**
+ * @see junit.framework.TestCase#TestCase(String)
+ */
+ public BaseDestructiveUserConfigTestCase(String name) {
+ super(name);
+ }
+
+ public void testUserConfig() throws Exception {
+ try {
+ initConfig();
+ convertFO();
+ fail( getName() + ": Expected Configuration Exception" );
+ } catch (FOPException e) {
+ // this *should* happen!
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail( getName() + ": Expected FOPException but got: " + e.getMessage() );
+ }
+ }
+}
Property changes on: test/java/org/apache/fop/config/BaseDestructiveUserConfigTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/java/org/apache/fop/config/UserConfigTestSuite.java
===================================================================
--- test/java/org/apache/fop/config/UserConfigTestSuite.java (revision 540059)
+++ test/java/org/apache/fop/config/UserConfigTestSuite.java (working copy)
@@ -15,8 +15,7 @@
* limitations under the License.
*/
-/* $Id$ */
-
+/* $Id: $ */
package org.apache.fop.config;
import junit.framework.Test;
@@ -38,10 +37,12 @@
suite.addTest(new TestSuite(FontBaseBadTestCase.class));
suite.addTest(new TestSuite(FontAttributesMissingTestCase.class));
suite.addTest(new TestSuite(FontTripletAttributeMissingTestCase.class));
- suite.addTest(new TestSuite(MetricsUrlBadTestCase.class));
- suite.addTest(new TestSuite(EmbedUrlBadTestCase.class));
- suite.addTest(new TestSuite(MetricsUrlMalformedTestCase.class));
- suite.addTest(new TestSuite(EmbedUrlMalformedTestCase.class));
+ suite.addTest(new TestSuite(FontMetricsUrlBadTestCase.class));
+ suite.addTest(new TestSuite(FontEmbedUrlBadTestCase.class));
+ suite.addTest(new TestSuite(FontMetricsUrlMalformedTestCase.class));
+ suite.addTest(new TestSuite(FontEmbedUrlMalformedTestCase.class));
+ suite.addTest(new TestSuite(FontsDirectoryRecursiveTestCase.class));
+ suite.addTest(new TestSuite(FontsAutoDetectTestCase.class));
//$JUnit-END$
return suite;
}
Index: test/java/org/apache/fop/config/FontsDirectoryBadTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontsDirectoryBadTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontsDirectoryBadTestCase.java (revision 0)
@@ -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.config;
+
+/*
+ * this font has a metrics-url that does not exist on filesystem
+ */
+public class FontsDirectoryBadTestCase extends BaseDestructiveUserConfigTestCase {
+
+ public FontsDirectoryBadTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_fonts_directory_bad.xconf";
+ }
+
+ /** get test FOP config File */
+ protected String getFontFOFilePath() {
+ return "test/xml/bugtests/font-dir.fo";
+ }
+}
Property changes on: test/java/org/apache/fop/config/FontsDirectoryBadTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/java/org/apache/fop/config/EmbedUrlMalformedTestCase.java
===================================================================
--- test/java/org/apache/fop/config/EmbedUrlMalformedTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/EmbedUrlMalformedTestCase.java (working copy)
@@ -1,38 +0,0 @@
-/*
- * 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.config;
-
-import java.io.File;
-
-// this font has a malformed embed-url
-public class EmbedUrlMalformedTestCase extends BaseUserConfigTestCase {
-
- public EmbedUrlMalformedTestCase(String name) {
- super(name);
- }
-
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_embedurl_malformed.xconf");
- }
-
- public String getName() {
- return "test_embedurl_malformed.xconf";
- }
-}
Index: test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java (revision 0)
@@ -0,0 +1,39 @@
+/*
+ * 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.config;
+
+/*
+ * this font has a metrics-url that does not exist on filesystem
+ */
+public class FontMetricsUrlBadTestCase extends BaseDestructiveUserConfigTestCase {
+
+ /**
+ * @see junit.framework.TestCase#TestCase(String)
+ */
+ public FontMetricsUrlBadTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_font_metricsurl_bad.xconf";
+ }
+}
Property changes on: test/java/org/apache/fop/config/FontMetricsUrlBadTestCase.java
___________________________________________________________________
Name: svn:kewords
- Id
Index: test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/FontTripletAttributeMissingTestCase.java (working copy)
@@ -15,24 +15,22 @@
* limitations under the License.
*/
-/* $Id$ */
-
+/* $Id: $ */
package org.apache.fop.config;
-import java.io.File;
+/*
+ * this font has a missing font triplet attribute
+ */
+public class FontTripletAttributeMissingTestCase extends BaseDestructiveUserConfigTestCase {
-// this font has an embed-url that does not exist on filesystem
-public class FontTripletAttributeMissingTestCase extends BaseUserConfigTestCase {
-
public FontTripletAttributeMissingTestCase(String name) {
super(name);
}
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_fonttripletattribute_missing.xconf");
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_font_tripletattribute_missing.xconf";
}
-
- public String getName() {
- return "test_fonttripletattribute_missing.xconf";
- }
}
Index: test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java
===================================================================
--- test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java (revision 0)
+++ test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * 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.config;
+
+/**
+ * this font has an embed-url that does not exist on filesystem.
+ */
+public class FontEmbedUrlBadTestCase extends BaseDestructiveUserConfigTestCase {
+
+ public FontEmbedUrlBadTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
+ */
+ public String getUserConfigFilename() {
+ return "test_font_embedurl_bad.xconf";
+ }
+}
Property changes on: test/java/org/apache/fop/config/FontEmbedUrlBadTestCase.java
___________________________________________________________________
Name: svn:kewords
- Id
Index: test/java/org/apache/fop/config/BaseUserConfigTestCase.java
===================================================================
--- test/java/org/apache/fop/config/BaseUserConfigTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/BaseUserConfigTestCase.java (working copy)
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-/* $Id$ */
+/* $Id: $ */
package org.apache.fop.config;
@@ -28,7 +28,6 @@
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.pdf.BasePDFTestCase;
import org.xml.sax.SAXException;
@@ -39,7 +38,7 @@
*/
public abstract class BaseUserConfigTestCase extends BasePDFTestCase {
- protected static DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+ protected DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
/** logging instance */
protected Log log = LogFactory.getLog(BaseUserConfigTestCase.class);
@@ -59,28 +58,19 @@
// do nothing
}
- /**
- * Test using a standard FOP font
- * @throws Exception checkstyle wants a comment here, even a silly one
- */
- public void testUserConfig() throws Exception {
- try {
- fopFactory.setUserConfig(getUserConfig());
- final File baseDir = getBaseDir();
- final String fontFOFilePath = getFontFOFilePath();
- File foFile = new File(baseDir, fontFOFilePath);
- final boolean dumpOutput = false;
- FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
- convertFO(foFile, foUserAgent, dumpOutput);
- fail( getName() + ": Expected Configuration Exception" );
- } catch (FOPException e) {
- // this *should* happen!
- } catch (Exception e) {
- fail( getName() + ": Expected FOPException but got: " + e.getMessage() );
- }
+ protected void initConfig() throws Exception {
+ fopFactory.setUserConfig(getUserConfig());
}
-
+ protected void convertFO() throws Exception {
+ final File baseDir = getBaseDir();
+ final String fontFOFilePath = getFontFOFilePath();
+ File foFile = new File(baseDir, fontFOFilePath);
+ final boolean dumpOutput = false;
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ convertFO(foFile, foUserAgent, dumpOutput);
+ }
+
/**
* get test FOP config File
* @return fo test filepath
@@ -96,30 +86,39 @@
* @throws SAXException
* @throws ConfigurationException
*/
- protected Configuration getUserConfig(String configString)
- throws ConfigurationException, SAXException, IOException {
+ protected Configuration getUserConfig(String configString) throws ConfigurationException, SAXException, IOException {
return cfgBuilder.build(new ByteArrayInputStream(configString.getBytes()));
}
+ /** get base config directory */
+ protected String getBaseConfigDir() {
+ return "test/config";
+ }
+
/**
+ * @return user config File
+ */
+ abstract protected String getUserConfigFilename();
+
+ /*
+ * @see junit.framework.TestCase#getName()
+ */
+ public String getName() {
+ return getUserConfigFilename();
+ }
+
+ protected File getUserConfigFile() {
+ return new File(getBaseConfigDir() + File.separator + getUserConfigFilename());
+ }
+
+ /**
* get test FOP Configuration
* @return fo test filepath
* @throws IOException
* @throws SAXException
* @throws ConfigurationException
*/
- protected Configuration getUserConfig()
- throws ConfigurationException, SAXException, IOException {
+ protected Configuration getUserConfig() throws ConfigurationException, SAXException, IOException {
return cfgBuilder.buildFromFile(getUserConfigFile());
- }
-
- /** get base config directory */
- protected String getBaseConfigDir() {
- return "test/config";
- }
-
- /**
- * @return user config File
- */
- protected abstract File getUserConfigFile();
-}
+ }
+}
\ No newline at end of file
Index: test/java/org/apache/fop/config/MetricsUrlBadTestCase.java
===================================================================
--- test/java/org/apache/fop/config/MetricsUrlBadTestCase.java (revision 540059)
+++ test/java/org/apache/fop/config/MetricsUrlBadTestCase.java (working copy)
@@ -1,44 +0,0 @@
-/*
- * 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.config;
-
-import java.io.File;
-
-// this font has a metrics-url that does not exist on filesystem
-public class MetricsUrlBadTestCase extends BaseUserConfigTestCase {
-
- /**
- * @see junit.framework.TestCase#TestCase(String)
- */
- public MetricsUrlBadTestCase(String name) {
- super(name);
- }
-
- /**
- * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFile()
- */
- protected File getUserConfigFile() {
- return new File( getBaseConfigDir() + "/test_metricsurl_bad.xconf");
- }
-
- public String getName() {
- return "test_metricsurl_bad.xconf";
- }
-}
Index: test/test.xconf
===================================================================
--- test/test.xconf (revision 540059)
+++ test/test.xconf (working copy)
@@ -1,5 +1,9 @@
+
+
+ false
+
Index: test/xml/bugtests/font-dir.fo
===================================================================
--- test/xml/bugtests/font-dir.fo (revision 0)
+++ test/xml/bugtests/font-dir.fo (revision 0)
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ This is a simple fo text in Rage italic font.
+
+
+
+
Index: test/xml/pdf-encoding/pdf-encoding-test.xconf
===================================================================
--- test/xml/pdf-encoding/pdf-encoding-test.xconf (revision 540059)
+++ test/xml/pdf-encoding/pdf-encoding-test.xconf (working copy)
@@ -23,6 +23,9 @@
-->
+
+ false
+
Index: test/config/test_fonts_directory_recursive.xconf
===================================================================
--- test/config/test_fonts_directory_recursive.xconf (revision 0)
+++ test/config/test_fonts_directory_recursive.xconf (revision 0)
@@ -0,0 +1,22 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+ test/resources/fonts
+
+
+
+
\ No newline at end of file
Property changes on: test/config/test_fonts_directory_recursive.xconf
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/config/test_embedurl_bad.xconf
===================================================================
--- test/config/test_embedurl_bad.xconf (revision 540059)
+++ test/config/test_embedurl_bad.xconf (working copy)
@@ -1,22 +0,0 @@
-
-
-
- true
-
-
- ./
-
-
- ./
-
-
-
-
-
-
-
-
-
-
-
-
Index: test/config/test_font_attributes_missing.xconf
===================================================================
--- test/config/test_font_attributes_missing.xconf (revision 0)
+++ test/config/test_font_attributes_missing.xconf (revision 0)
@@ -0,0 +1,25 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
Index: test/config/test_font_metricsurl_malformed.xconf
===================================================================
--- test/config/test_font_metricsurl_malformed.xconf (revision 0)
+++ test/config/test_font_metricsurl_malformed.xconf (revision 0)
@@ -0,0 +1,25 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
Index: test/config/test_fontattributes_missing.xconf
===================================================================
--- test/config/test_fontattributes_missing.xconf (revision 540059)
+++ test/config/test_fontattributes_missing.xconf (working copy)
@@ -1,22 +0,0 @@
-
-
-
- true
-
-
- ./
-
-
- ./
-
-
-
-
-
-
-
-
-
-
-
-
Index: test/config/test_fontbase_bad.xconf
===================================================================
--- test/config/test_fontbase_bad.xconf (revision 517602)
+++ test/config/test_fontbase_bad.xconf (working copy)
@@ -3,6 +3,9 @@
true
+
+ false
+
./
Index: test/config/test_fonts_autodetect.xconf
===================================================================
--- test/config/test_fonts_autodetect.xconf (revision 0)
+++ test/config/test_fonts_autodetect.xconf (revision 0)
@@ -0,0 +1,22 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Property changes on: test/config/test_fonts_autodetect.xconf
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/config/test_font_embedurl_malformed.xconf
===================================================================
--- test/config/test_font_embedurl_malformed.xconf (revision 0)
+++ test/config/test_font_embedurl_malformed.xconf (revision 0)
@@ -0,0 +1,25 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
Index: test/config/test_metricsurl_malformed.xconf
===================================================================
--- test/config/test_metricsurl_malformed.xconf (revision 540059)
+++ test/config/test_metricsurl_malformed.xconf (working copy)
@@ -1,22 +0,0 @@
-
-
-
- true
-
-
- ./
-
-
- ./
-
-
-
-
-
-
-
-
-
-
-
-
Index: test/config/test_fonts_directory_bad.xconf
===================================================================
--- test/config/test_fonts_directory_bad.xconf (revision 0)
+++ test/config/test_fonts_directory_bad.xconf (revision 0)
@@ -0,0 +1,22 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+ doesnotexist
+
+
+
+
Property changes on: test/config/test_fonts_directory_bad.xconf
___________________________________________________________________
Name: svn:eol-style
+ native
Index: test/config/test_embedurl_malformed.xconf
===================================================================
--- test/config/test_embedurl_malformed.xconf (revision 540059)
+++ test/config/test_embedurl_malformed.xconf (working copy)
@@ -1,22 +0,0 @@
-
-
-
- true
-
-
- ./
-
-
- ./
-
-
-
-
-
-
-
-
-
-
-
-
Index: test/config/test_font_metricsurl_bad.xconf
===================================================================
--- test/config/test_font_metricsurl_bad.xconf (revision 0)
+++ test/config/test_font_metricsurl_bad.xconf (revision 0)
@@ -0,0 +1,25 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
Index: test/config/test_font_tripletattribute_missing.xconf
===================================================================
--- test/config/test_font_tripletattribute_missing.xconf (revision 0)
+++ test/config/test_font_tripletattribute_missing.xconf (revision 0)
@@ -0,0 +1,25 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
Index: test/config/test_fonttripletattribute_missing.xconf
===================================================================
--- test/config/test_fonttripletattribute_missing.xconf (revision 540059)
+++ test/config/test_fonttripletattribute_missing.xconf (working copy)
@@ -1,22 +0,0 @@
-
-
-
- true
-
-
- ./
-
-
- ./
-
-
-
-
-
-
-
-
-
-
-
-
Index: test/config/test_font_embedurl_bad.xconf
===================================================================
--- test/config/test_font_embedurl_bad.xconf (revision 0)
+++ test/config/test_font_embedurl_bad.xconf (revision 0)
@@ -0,0 +1,25 @@
+
+
+
+ true
+
+
+ false
+
+
+ ./
+
+
+ ./
+
+
+
+
+
+
+
+
+
+
+
+
Index: test/config/test_metricsurl_bad.xconf
===================================================================
--- test/config/test_metricsurl_bad.xconf (revision 540059)
+++ test/config/test_metricsurl_bad.xconf (working copy)
@@ -1,22 +0,0 @@
-
-
-
- true
-
-
- ./
-
-
- ./
-
-
-
-
-
-
-
-
-
-
-
-
Index: fop.cmd
===================================================================
--- fop.cmd (revision 540059)
+++ fop.cmd (working copy)
@@ -58,6 +58,8 @@
set LOCALCLASSPATH=%FOP_HYPHENATION_PATH%
for %%l in (%LOCAL_FOP_HOME%build\*.jar %LIBDIR%\*.jar) do set LOCALCLASSPATH=!LOCALCLASSPATH!;%%l
+set JAVAOPTS=-Denv.windir=%WINDIR%
+
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java
@@ -68,6 +70,6 @@
:runFop
rem echo "%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
-"%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
+"%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
ENDLOCAL
Index: src/java/org/apache/fop/render/PrintRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/PrintRendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/PrintRendererConfigurator.java (revision 0)
@@ -0,0 +1,342 @@
+/*
+ * 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.render;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopCache;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.fonts.CachedFontInfo;
+import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontResolver;
+import org.apache.fop.fonts.FontSetup;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.fonts.FontUtil;
+import org.apache.fop.fonts.autodetect.FontFileFinder;
+import org.apache.fop.fonts.autodetect.FontInfoFinder;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * Base Print renderer configurator (mostly handles font configuration)
+ */
+public class PrintRendererConfigurator implements RendererConfigurator {
+
+ /** have we already autodetected system fonts? */
+ private static boolean autodetectedFonts = false;
+
+ /** logger instance */
+ protected static Log log = LogFactory.getLog(PrintRendererConfigurator.class);
+
+ /** fop factory configuration */
+ protected FOUserAgent userAgent = null;
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public PrintRendererConfigurator(FOUserAgent userAgent) {
+ super();
+ this.userAgent = userAgent;
+ }
+
+ /**
+ * Builds a list of EmbedFontInfo objects for use with the setup() method.
+ *
+ * @param renderer print renderer
+ * @throws FOPException if something's wrong with the config data
+ */
+ public void configure(Renderer renderer) throws FOPException {
+ Configuration cfg = getRendererConfig(renderer);
+ if (cfg == null) {
+ return;
+ }
+
+ PrintRenderer printRenderer = (PrintRenderer)renderer;
+ FontResolver fontResolver = printRenderer.getFontResolver();
+ if (fontResolver == null) {
+ //Ensure that we have minimal font resolution capabilities
+ fontResolver = FontSetup.createMinimalFontResolver();
+ }
+
+ FopFactory factory = userAgent.getFactory();
+ boolean strict = factory.validateUserConfigStrictly();
+ boolean cacheFonts = factory.useCache();
+
+ List fontInfoList = new java.util.ArrayList();
+
+ Configuration fonts = cfg.getChild("fonts");
+ if (fonts != null) {
+ // native o/s search (autodetect) configuration
+ boolean autodetectFonts = (fonts.getChild("auto-detect", false) != null);
+ if (!autodetectedFonts && autodetectFonts) {
+ // search in font base if it is defined and
+ // is a directory but don't recurse
+ FontFileFinder fontFileFinder = new FontFileFinder();
+ String fontBaseURL = printRenderer.getUserAgent().getFontBaseURL();
+ if (fontBaseURL != null) {
+ try {
+ addFontInfoListFromFileList(
+ fontFileFinder.find(fontBaseURL),
+ fontInfoList,
+ fontResolver,
+ cacheFonts
+ );
+ } catch (IOException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+
+ // native o/s font directory finder
+ try {
+ addFontInfoListFromFileList(
+ fontFileFinder.find(),
+ fontInfoList,
+ fontResolver,
+ cacheFonts
+ );
+ } catch (IOException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ autodetectedFonts = true;
+ }
+
+ // directory (multiple font) configuration
+ Configuration[] directories = fonts.getChildren("directory");
+ for (int i = 0; i < directories.length; i++) {
+ boolean recursive = directories[i].getAttributeAsBoolean("recursive", false);
+ String directory = null;
+ try {
+ directory = directories[i].getValue();
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strict);
+ continue;
+ }
+ if (directory == null) {
+ LogUtil.handleException(log,
+ new FOPException("directory defined without value"), strict);
+ continue;
+ }
+ FontFileFinder fontFileFinder = new FontFileFinder(recursive ? -1 : 1);
+ try {
+ addFontInfoListFromFileList(
+ fontFileFinder.find(directory),
+ fontInfoList,
+ fontResolver,
+ cacheFonts
+ );
+ } catch (IOException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+
+ // font file (singular) configuration
+ Configuration[] font = fonts.getChildren("font");
+ for (int i = 0; i < font.length; i++) {
+ EmbedFontInfo fontInfo = getFontInfoFromConfiguration(
+ font[i], fontResolver, strict, cacheFonts);
+ if (fontInfo != null) {
+ fontInfoList.add(fontInfo);
+ }
+ }
+ }
+ FopCache cache = FopCache.getInstance();
+ if (factory.useCache() && cache.hasChanged()) {
+ cache.write();
+ }
+ printRenderer.addFontList(fontInfoList);
+ }
+
+ /**
+ * iterates over font file list adding font info to list
+ * @param fontFileList font file list
+ * @param fontInfoList font info list
+ * @param resolver font resolver
+ */
+ private void addFontInfoListFromFileList(
+ List fontFileList, List fontInfoList, FontResolver resolver, boolean cacheFonts) {
+ for (Iterator iter = fontFileList.iterator(); iter.hasNext();) {
+ File fontFile = (File)iter.next();
+ // parse font to ascertain font info
+ FontInfoFinder finder = new FontInfoFinder();
+ EmbedFontInfo fontInfo = finder.find(fontFile, resolver, cacheFonts);
+ if (fontInfo != null) {
+ fontInfoList.add(fontInfo);
+ }
+ }
+ }
+
+ /**
+ * Returns a font info from a font node Configuration definition
+ *
+ * @param fontCfg Configuration object (font node)
+ * @param fontResolver font resolver used to resolve font
+ * @param strict validate configuration strictly
+ * @param useCache use cache to find fonts
+ * @return font info
+ * @throws FOPException if something's wrong with the config data
+ */
+ public EmbedFontInfo getFontInfoFromConfiguration(
+ Configuration fontCfg, FontResolver fontResolver, boolean strict, boolean useCache)
+ throws FOPException {
+ String metricsUrl = fontCfg.getAttribute("metrics-url", null);
+ String embedUrl = fontCfg.getAttribute("embed-url", null);
+
+ if (metricsUrl == null && embedUrl == null) {
+ LogUtil.handleError(log, "Font configuration without metric-url or embed-url", strict);
+ return null;
+ }
+ if (embedUrl != null) {
+ StreamSource source = (StreamSource)fontResolver.resolve(embedUrl);
+ if (source == null) {
+ LogUtil.handleError(log,
+ "Failed to resolve font with embed-url '" + embedUrl + "'", strict);
+ return null;
+ }
+ embedUrl = source.getSystemId(); // absolute path/url
+ }
+ if (metricsUrl != null) {
+ StreamSource source = (StreamSource)fontResolver.resolve(metricsUrl);
+ if (source == null) {
+ LogUtil.handleError(log,
+ "Failed to resolve font with metric-url '" + metricsUrl + "'", strict);
+ return null;
+ }
+ metricsUrl = source.getSystemId(); // absolute path/url
+ }
+ boolean useKerning = fontCfg.getAttributeAsBoolean("kerning", false);
+
+ EmbedFontInfo fontInfo = null;
+ Configuration[] tripletCfg = fontCfg.getChildren("font-triplet");
+ // no font triplet info
+ if (tripletCfg.length == 0) {
+ LogUtil.handleError(log, "font without font-triplet", strict);
+
+ // if not strict try to determine font info from the embed/metrics url
+ File fontFile = CachedFontInfo.getFileFromUrls(new String[] {embedUrl, metricsUrl});
+ if (fontFile != null) {
+ FontInfoFinder finder = new FontInfoFinder();
+ return finder.find(fontFile, fontResolver, useCache);
+ } else {
+ return null;
+ }
+ } else {
+ List tripleList = new java.util.ArrayList();
+ for (int j = 0; j < tripletCfg.length; j++) {
+ try {
+ String name = tripletCfg[j].getAttribute("name");
+ if (name == null) {
+ LogUtil.handleError(log, "font-triplet without name", strict);
+ continue;
+ }
+ String weightStr = tripletCfg[j].getAttribute("weight");
+ if (weightStr == null) {
+ LogUtil.handleError(log, "font-triplet without weight", strict);
+ continue;
+ }
+ int weight = FontUtil.parseCSS2FontWeight(weightStr);
+ String style = tripletCfg[j].getAttribute("style");
+ if (style == null) {
+ LogUtil.handleError(log, "font-triplet without style", strict);
+ continue;
+ }
+ tripleList.add(FontInfo.createFontKey(name, style, weight));
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+
+ fontInfo = new EmbedFontInfo(metricsUrl, useKerning, tripleList, embedUrl);
+
+ if (useCache) {
+ FopCache cache = FopCache.getInstance();
+ if (!cache.containsFont(fontInfo)) {
+ cache.addFont(fontInfo);
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Adding font " + fontInfo.getEmbedFile()
+ + ", metric file " + fontInfo.getMetricsFile());
+ for (int j = 0; j < tripleList.size(); ++j) {
+ FontTriplet triplet = (FontTriplet) tripleList.get(j);
+ log.debug("Font triplet "
+ + triplet.getName() + ", "
+ + triplet.getStyle() + ", "
+ + triplet.getWeight());
+ }
+ }
+ }
+ return fontInfo;
+ }
+
+ /**
+ * Returns the configuration subtree for a specific renderer.
+ * @param renderer the renderer
+ * @return the requested configuration subtree, null if there's no configuration
+ */
+ protected Configuration getRendererConfig(Renderer renderer) {
+ Configuration cfg = userAgent.getFactory().getUserConfig();
+ if (cfg == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("userconfig is null");
+ }
+ return null;
+ }
+
+ String mimeType = renderer.getMimeType();
+ if (mimeType == null) {
+ if (log.isInfoEnabled()) {
+ log.info("renderer mimeType is null");
+ }
+ return null;
+ }
+
+ Configuration userRendererConfig = null;
+
+ Configuration[] cfgs
+ = cfg.getChild("renderers").getChildren("renderer");
+ for (int i = 0; i < cfgs.length; ++i) {
+ Configuration child = cfgs[i];
+ try {
+ if (child.getAttribute("mime").equals(mimeType)) {
+ userRendererConfig = child;
+ break;
+ }
+ } catch (ConfigurationException e) {
+ // silently pass over configurations without mime type
+ }
+ }
+ log.debug((userRendererConfig == null ? "No u" : "U")
+ + "ser configuration found for MIME type " + mimeType);
+ return userRendererConfig;
+ }
+}
Index: src/java/org/apache/fop/render/RendererContextInfoConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/RendererContextInfoConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/RendererContextInfoConfigurator.java (revision 0)
@@ -0,0 +1,87 @@
+/*
+ * 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.render;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Renderer context info configurator
+ */
+public class RendererContextInfoConfigurator extends PrintRendererConfigurator {
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public RendererContextInfoConfigurator(FOUserAgent userAgent) {
+ super(userAgent);
+ }
+
+ /**
+ * Returns the configuration subtree for a specific renderer.
+ * @param cfg the renderer configuration
+ * @param namespace the namespace (i.e. the XMLHandler) for which the configuration should
+ * be returned
+ * @return the requested configuration subtree, null if there's no configuration
+ */
+ private Configuration getHandlerConfig(Configuration cfg, String namespace) {
+ if (cfg == null || namespace == null) {
+ return null;
+ }
+ Configuration handlerConfig = null;
+
+ Configuration[] children = cfg.getChildren("xml-handler");
+ for (int i = 0; i < children.length; ++i) {
+ try {
+ if (children[i].getAttribute("namespace").equals(namespace)) {
+ handlerConfig = children[i];
+ break;
+ }
+ } catch (ConfigurationException e) {
+ // silently pass over configurations without namespace
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug((handlerConfig == null ? "No" : "")
+ + "XML handler configuration found for namespace " + namespace);
+ }
+ return handlerConfig;
+ }
+
+ /**
+ * Configures renderer context
+ * @param info renderer context info
+ * @throws FOPException fop exception
+ */
+ public void configure(RendererContextInfo info) throws FOPException {
+ //Optional XML handler configuration
+ Configuration cfg = super.getRendererConfig(info.getRenderer());
+ if (cfg != null) {
+ cfg = getHandlerConfig(cfg, info.getNamespace());
+ if (cfg != null) {
+ RendererContext ctx = info.getRendererContext();
+ ctx.setProperty(RendererContextConstants.HANDLER_CONFIGURATION, cfg);
+ }
+ }
+ }
+}
Index: src/java/org/apache/fop/render/AbstractRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/AbstractRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/AbstractRendererMaker.java (working copy)
@@ -1,62 +1,71 @@
-/*
- * 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.render;
-
-import org.apache.fop.apps.FOUserAgent;
-
-/**
- * Base class for factory classes which instantiate Renderers and provide information
- * about them.
- */
-public abstract class AbstractRendererMaker {
-
- /**
- * Instantiates a new renderer.
- * @param ua the user agent
- * @return the newly instantiated renderer
- */
- public abstract Renderer makeRenderer(FOUserAgent ua);
-
- /**
- * @return Indicates whether this renderer requires an OutputStream to work with.
- */
- public abstract boolean needsOutputStream();
-
- /**
- * @return an array of MIME types the renderer supports.
- */
- public abstract String[] getSupportedMimeTypes();
-
- /**
- * Indicates whether a specific MIME type is supported by this renderer.
- * @param mimeType the MIME type (ex. "application/pdf")
- * @return true if the MIME type is supported
- */
- public boolean isMimeTypeSupported(String mimeType) {
- String[] mimes = getSupportedMimeTypes();
- for (int i = 0; i < mimes.length; i++) {
- if (mimes[i].equals(mimeType)) {
- return true;
- }
- }
- return false;
- }
-
-}
+/*
+ * 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.render;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * Base class for factory classes which instantiate Renderers and provide information
+ * about them.
+ */
+public abstract class AbstractRendererMaker {
+
+ /**
+ * Instantiates a new renderer.
+ * @param userAgent the user agent
+ * @return the newly instantiated renderer
+ */
+ public abstract Renderer makeRenderer(FOUserAgent userAgent);
+
+ /**
+ * @return Indicates whether this renderer requires an OutputStream to work with.
+ */
+ public abstract boolean needsOutputStream();
+
+ /**
+ * @return an array of MIME types the renderer supports.
+ */
+ public abstract String[] getSupportedMimeTypes();
+
+ /**
+ * Returns a renderer config object that can be used to
+ * configure the renderer.
+ * @param userAgent user agent
+ * @return a config object that can be used to configure the renderer
+ */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return null;
+ }
+
+ /**
+ * Indicates whether a specific MIME type is supported by this renderer.
+ * @param mimeType the MIME type (ex. "application/pdf")
+ * @return true if the MIME type is supported
+ */
+ public boolean isMimeTypeSupported(String mimeType) {
+ String[] mimes = getSupportedMimeTypes();
+ for (int i = 0; i < mimes.length; i++) {
+ if (mimes[i].equals(mimeType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Index: src/java/org/apache/fop/render/PrintRenderer.java
===================================================================
--- src/java/org/apache/fop/render/PrintRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/PrintRenderer.java (working copy)
@@ -46,8 +46,27 @@
/** list of fonts */
protected List fontList = null;
+
+ /**
+ * adds a font list to current list of fonts
+ * @param fontInfoList font list
+ */
+ public void addFontList(List fontInfoList) {
+ if (this.fontList == null) {
+ setFontList(fontInfoList);
+ } else {
+ this.fontList.addAll(fontInfoList);
+ }
+ }
/**
+ * @param fontList list of available fonts
+ */
+ public void setFontList(List fontList) {
+ this.fontList = fontList;
+ }
+
+ /**
* Set up the font info
*
* @param inFontInfo font info to set up
Index: src/java/org/apache/fop/render/RendererContextInfo.java
===================================================================
--- src/java/org/apache/fop/render/RendererContextInfo.java (revision 0)
+++ src/java/org/apache/fop/render/RendererContextInfo.java (revision 0)
@@ -0,0 +1,78 @@
+/*
+ * 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.render;
+
+import org.w3c.dom.Document;
+
+/**
+ *
+ * Renderer information for the purposes of configuration
+ * @author Adrian Cumiskey
+ *
+ */
+public class RendererContextInfo {
+
+ private RendererContext rendererContext;
+ private Document document;
+ private String namespace;
+ private AbstractRenderer renderer;
+
+ /**
+ * Default constructor
+ * @param renderer
+ *
+ * @param ctx renderer context
+ * @param doc document
+ * @param namespace namespace
+ */
+ public RendererContextInfo(AbstractRenderer renderer, RendererContext ctx, Document doc, String namespace) {
+ this.renderer = renderer;
+ this.rendererContext = ctx;
+ this.document = doc;
+ this.namespace = namespace;
+ }
+
+ public AbstractRenderer getRenderer() {
+ return renderer;
+ }
+
+ /**
+ * returns the renderer context
+ * @return renderer context
+ */
+ public RendererContext getRendererContext() {
+ return rendererContext;
+ }
+
+ /**
+ * returns the document
+ * @return document
+ */
+ public Document getDocument() {
+ return document;
+ }
+
+ /**
+ * returns the namespace
+ * @return namespace
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+}
Property changes on: src/java/org/apache/fop/render/RendererContextInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/java/org/apache/fop/render/RendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/RendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/RendererConfigurator.java (revision 0)
@@ -0,0 +1,34 @@
+/*
+ * 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.render;
+
+import org.apache.fop.apps.FOPException;
+
+/**
+ * Renderer configurator interface
+ */
+public interface RendererConfigurator {
+ /**
+ * Configures a renderer
+ * @param renderer renderer
+ * @throws FOPException fop exception
+ */
+ void configure(Renderer renderer) throws FOPException;
+}
Index: src/java/org/apache/fop/render/bitmap/TIFFRenderer.java
===================================================================
--- src/java/org/apache/fop/render/bitmap/TIFFRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/bitmap/TIFFRenderer.java (working copy)
@@ -32,9 +32,6 @@
import java.io.OutputStream;
import java.util.Iterator;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
import org.apache.commons.logging.Log;
import org.apache.xmlgraphics.image.GraphicsUtil;
@@ -77,12 +74,12 @@
//private static final String COMPRESSION_NONE = "NONE";
//private static final String COMPRESSION_JPEG = "JPEG";
- private static final String COMPRESSION_PACKBITS = "PackBits";
+ public static final String COMPRESSION_PACKBITS = "PackBits";
//private static final String COMPRESSION_DEFLATE = "Deflate";
//private static final String COMPRESSION_LZW = "LZW";
//private static final String COMPRESSION_ZLIB = "ZLib";
- private static final String COMPRESSION_CCITT_T6 = "CCITT T.6"; //CCITT Group 4
- private static final String COMPRESSION_CCITT_T4 = "CCITT T.4"; //CCITT Group 3
+ public static final String COMPRESSION_CCITT_T6 = "CCITT T.6"; //CCITT Group 4
+ public static final String COMPRESSION_CCITT_T4 = "CCITT T.4"; //CCITT Group 3
/** ImageWriter parameters */
private ImageWriterParams writerParams;
@@ -115,30 +112,6 @@
writerParams.setResolution(dpi);
}
- /**
- * Configure the TIFF renderer. Get the configuration to be used for
- * compression
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration cfg) throws ConfigurationException {
- super.configure(cfg);
-
- //set compression
- String name = cfg.getChild("compression").getValue(COMPRESSION_PACKBITS);
- //Some compression formats need a special image format:
- if (name.equalsIgnoreCase(COMPRESSION_CCITT_T6)) {
- bufferedImageType = BufferedImage.TYPE_BYTE_BINARY;
- } else if (name.equalsIgnoreCase(COMPRESSION_CCITT_T4)) {
- bufferedImageType = BufferedImage.TYPE_BYTE_BINARY;
- } else {
- bufferedImageType = BufferedImage.TYPE_INT_ARGB;
- }
- if (!"NONE".equalsIgnoreCase(name)) {
- writerParams.setCompressionMethod(name);
- }
- log.info("TIFF compression set to " + name);
- }
-
/** @see org.apache.fop.render.Renderer#startRenderer(java.io.OutputStream) */
public void startRenderer(OutputStream outputStream) throws IOException {
this.outputStream = outputStream;
@@ -253,4 +226,12 @@
"Method 'remove' is not supported.");
}
}
+
+ public void setBufferedImageType(int bufferedImageType) {
+ this.bufferedImageType = bufferedImageType;
+ }
+
+ public ImageWriterParams getWriterParams() {
+ return writerParams;
+ }
}
Index: src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/bitmap/TIFFRendererMaker.java (working copy)
@@ -1,50 +1,55 @@
-/*
- * 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.render.bitmap;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the TIFF Renderer.
- */
-public class TIFFRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF};
-
-
- /** @see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new TIFFRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.bitmap;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the TIFF Renderer.
+ */
+public class TIFFRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_TIFF};
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#makeRenderer(FOUserAgent) */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new TIFFRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getConfigurator(FOUserAgent) */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new TIFFRendererConfigurator(userAgent);
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Index: src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java (revision 0)
@@ -0,0 +1,72 @@
+/*
+ * 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.render.bitmap;
+
+import java.awt.image.BufferedImage;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+
+/**
+ * TIFF Renderer configurator
+ */
+public class TIFFRendererConfigurator extends PrintRendererConfigurator {
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public TIFFRendererConfigurator(FOUserAgent userAgent) {
+ super(userAgent);
+ }
+
+ /**
+ * Configure the TIFF renderer. Get the configuration to be used for
+ * compression
+ * @param renderer tiff renderer
+ * @throws FOPException fop exception
+ * @see org.apache.fop.render.PrintRendererConfigurator#configure(Renderer)
+ */
+ public void configure(Renderer renderer) throws FOPException {
+ Configuration cfg = super.getRendererConfig(renderer);
+ if (cfg != null) {
+ TIFFRenderer tiffRenderer = (TIFFRenderer)renderer;
+ //set compression
+ String name = cfg.getChild("compression").getValue(TIFFRenderer.COMPRESSION_PACKBITS);
+ //Some compression formats need a special image format:
+ if (name.equalsIgnoreCase(TIFFRenderer.COMPRESSION_CCITT_T6)) {
+ tiffRenderer.setBufferedImageType(BufferedImage.TYPE_BYTE_BINARY);
+ } else if (name.equalsIgnoreCase(TIFFRenderer.COMPRESSION_CCITT_T4)) {
+ tiffRenderer.setBufferedImageType(BufferedImage.TYPE_BYTE_BINARY);
+ } else {
+ tiffRenderer.setBufferedImageType(BufferedImage.TYPE_INT_ARGB);
+ }
+ if (!"NONE".equalsIgnoreCase(name)) {
+ tiffRenderer.getWriterParams().setCompressionMethod(name);
+ }
+ if (log.isInfoEnabled()) {
+ log.info("TIFF compression set to " + name);
+ }
+ }
+ }
+}
Index: src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/bitmap/PNGRendererMaker.java (working copy)
@@ -1,50 +1,49 @@
-/*
- * 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.render.bitmap;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the PNG Renderer.
- */
-public class PNGRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG};
-
-
- /** @see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new PNGRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.bitmap;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+
+/**
+ * RendererMaker for the PNG Renderer.
+ */
+public class PNGRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PNG};
+
+ /** @see org.apache.fop.render.AbstractRendererMaker */
+ public Renderer makeRenderer(FOUserAgent ua) {
+ return new PNGRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Index: src/java/org/apache/fop/render/pcl/PCLRenderer.java
===================================================================
--- src/java/org/apache/fop/render/pcl/PCLRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/pcl/PCLRenderer.java (working copy)
@@ -53,8 +53,6 @@
import org.apache.xmlgraphics.java2d.GraphicContext;
// FOP
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOPException;
@@ -143,31 +141,8 @@
public PCLRenderer() {
}
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration cfg) throws ConfigurationException {
- super.configure(cfg);
- String rendering = cfg.getChild("rendering").getValue(null);
- if ("quality".equalsIgnoreCase(rendering)) {
- this.qualityBeforeSpeed = true;
- } else if ("speed".equalsIgnoreCase(rendering)) {
- this.qualityBeforeSpeed = false;
- } else if (rendering != null) {
- throw new ConfigurationException(
- "Valid values for 'rendering' are 'quality' and 'speed'. Value found: "
- + rendering);
- }
- String textRendering = cfg.getChild("text-rendering").getValue(null);
- if ("bitmap".equalsIgnoreCase(textRendering)) {
- this.allTextAsBitmaps = true;
- } else if ("auto".equalsIgnoreCase(textRendering)) {
- this.allTextAsBitmaps = false;
- } else if (textRendering != null) {
- throw new ConfigurationException(
- "Valid values for 'text-rendering' are 'auto' and 'bitmap'. Value found: "
- + textRendering);
- }
+ public void setQualityBeforeSpeed(boolean qualityBeforeSpeed) {
+ this.qualityBeforeSpeed = qualityBeforeSpeed;
}
/**
@@ -1499,6 +1474,10 @@
handleIOTrouble(ioe);
}
}
+
+ public void setAllTextAsBitmaps(boolean allTextAsBitmaps) {
+ this.allTextAsBitmaps = allTextAsBitmaps;
+ }
Index: src/java/org/apache/fop/render/pcl/PCLRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/pcl/PCLRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/pcl/PCLRendererMaker.java (working copy)
@@ -1,52 +1,57 @@
-/*
- * 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.render.pcl;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the PCL Renderer.
- */
-public class PCLRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {
- MimeConstants.MIME_PCL,
- MimeConstants.MIME_PCL_ALT};
-
-
- /**@see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new PCLRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.pcl;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the PCL Renderer.
+ */
+public class PCLRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {
+ MimeConstants.MIME_PCL,
+ MimeConstants.MIME_PCL_ALT
+ };
+
+ /**@see org.apache.fop.render.AbstractRendererMaker#makeRenderer(FOUserAgent) */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PCLRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getConfigurator(FOUserAgent) */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PCLRendererConfigurator(userAgent);
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+}
Index: src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java (revision 0)
@@ -0,0 +1,74 @@
+/*
+ * 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.render.pcl;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+
+/**
+ * PCL Renderer configurator
+ */
+public class PCLRendererConfigurator extends PrintRendererConfigurator {
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public PCLRendererConfigurator(FOUserAgent userAgent) {
+ super(userAgent);
+ }
+
+ /**
+ * Configure the TIFF renderer. Get the configuration to be used for
+ * compression
+ * @param renderer PCL renderer
+ * @throws FOPException fop exception
+ * @see org.apache.fop.render.PrintRendererConfigurator#configure(Renderer)
+ */
+ public void configure(Renderer renderer) throws FOPException {
+ Configuration cfg = super.getRendererConfig(renderer);
+ if (cfg != null) {
+ PCLRenderer pclRenderer = (PCLRenderer)renderer;
+ String rendering = cfg.getChild("rendering").getValue(null);
+ if ("quality".equalsIgnoreCase(rendering)) {
+ pclRenderer.setQualityBeforeSpeed(true);
+ } else if ("speed".equalsIgnoreCase(rendering)) {
+ pclRenderer.setQualityBeforeSpeed(false);
+ } else if (rendering != null) {
+ throw new FOPException(
+ "Valid values for 'rendering' are 'quality' and 'speed'. Value found: "
+ + rendering);
+ }
+ String textRendering = cfg.getChild("text-rendering").getValue(null);
+ if ("bitmap".equalsIgnoreCase(textRendering)) {
+ pclRenderer.setAllTextAsBitmaps(true);
+ } else if ("auto".equalsIgnoreCase(textRendering)) {
+ pclRenderer.setAllTextAsBitmaps(false);
+ } else if (textRendering != null) {
+ throw new FOPException(
+ "Valid values for 'text-rendering' are 'auto' and 'bitmap'. Value found: "
+ + textRendering);
+ }
+ }
+ }
+}
Index: src/java/org/apache/fop/render/txt/TXTRenderer.java
===================================================================
--- src/java/org/apache/fop/render/txt/TXTRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/txt/TXTRenderer.java (working copy)
@@ -27,8 +27,6 @@
import java.util.List;
import java.util.Map;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.fop.apps.FOPException;
import org.apache.fop.area.Area;
import org.apache.fop.area.CTM;
@@ -115,12 +113,6 @@
public String getMimeType() {
return "text/plain";
}
-
- /** @see org.apache.fop.render.AbstractRenderer */
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
- this.encoding = conf.getChild("encoding", true).getValue(null);
- }
/**
* Sets the encoding of the target file.
Index: src/java/org/apache/fop/render/txt/TXTRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/txt/TXTRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/txt/TXTRendererMaker.java (working copy)
@@ -1,50 +1,54 @@
-/*
- * 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.render.txt;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the Plain Text Renderer.
- */
-public class TXTRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_PLAIN_TEXT};
-
-
- /**@see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new TXTRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.txt;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the Plain Text Renderer.
+ */
+public class TXTRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_PLAIN_TEXT};
+
+ /**@see org.apache.fop.render.AbstractRendererMaker#makeRenderer(FOUserAgent) */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new TXTRenderer();
+ }
+
+ /**@see org.apache.fop.render.AbstractRendererMaker#getConfigurator(FOUserAgent) */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new TXTRendererConfigurator(userAgent);
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+}
Index: src/java/org/apache/fop/render/txt/TXTRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/txt/TXTRendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/txt/TXTRendererConfigurator.java (revision 0)
@@ -0,0 +1,53 @@
+/*
+ * 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.render.txt;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+
+/**
+ * TXT Renderer configurator
+ */
+public class TXTRendererConfigurator extends PrintRendererConfigurator {
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public TXTRendererConfigurator(FOUserAgent userAgent) {
+ super(userAgent);
+ }
+
+ /**
+ * Configure the PS renderer.
+ * @param renderer TXT renderer
+ * @throws FOPException fop exception
+ */
+ public void configure(Renderer renderer) throws FOPException {
+ Configuration cfg = super.getRendererConfig(renderer);
+ if (cfg != null) {
+ TXTRenderer txtRenderer = (TXTRenderer)renderer;
+ txtRenderer.setEncoding(cfg.getChild("encoding", true).getValue(null));
+ }
+ }
+}
Index: src/java/org/apache/fop/render/ps/PSRenderer.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/ps/PSRenderer.java (working copy)
@@ -35,8 +35,6 @@
import javax.xml.transform.Source;
// FOP
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -61,7 +59,6 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionAttachment;
import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontSetup;
import org.apache.fop.fonts.LazyFont;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.image.EPSImage;
@@ -146,24 +143,6 @@
private Map formResources;
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration cfg) throws ConfigurationException {
- super.configure(cfg);
- this.autoRotateLandscape = cfg.getChild(AUTO_ROTATE_LANDSCAPE).getValueAsBoolean(false);
- this.languageLevel = cfg.getChild(LANGUAGE_LEVEL).getValueAsInteger(this.languageLevel);
- this.twoPassGeneration = cfg.getChild(OPTIMIZE_RESOURCES).getValueAsBoolean(false);
-
- //Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg, this);
- if (this.fontList == null) {
- this.fontList = cfgFonts;
- } else {
- this.fontList.addAll(cfgFonts);
- }
- }
-
- /**
* @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
*/
public void setUserAgent(FOUserAgent agent) {
Index: src/java/org/apache/fop/render/ps/PSTextPainter.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSTextPainter.java (revision 540059)
+++ src/java/org/apache/fop/render/ps/PSTextPainter.java (working copy)
@@ -367,8 +367,8 @@
private int getWeight(AttributedCharacterIterator aci) {
Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
return ((taWeight != null) && (taWeight.floatValue() > 1.0))
- ? Font.BOLD
- : Font.NORMAL;
+ ? Font.WEIGHT_BOLD
+ : Font.WEIGHT_NORMAL;
}
private Font makeFont(AttributedCharacterIterator aci) {
@@ -402,7 +402,7 @@
}
}
}
- FontTriplet triplet = fontInfo.fontLookup("any", style, Font.NORMAL);
+ FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
int fsize = (int)(fontSize.floatValue() * 1000);
return fontInfo.getFontInstance(triplet, fsize);
}
@@ -411,7 +411,7 @@
final String style = getStyle(aci);
final int weight = getWeight(aci);
int fStyle = java.awt.Font.PLAIN;
- if (weight == Font.BOLD) {
+ if (weight == Font.WEIGHT_BOLD) {
fStyle |= java.awt.Font.BOLD;
}
if ("italic".equals(style)) {
Index: src/java/org/apache/fop/render/ps/PSRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/ps/PSRendererMaker.java (working copy)
@@ -1,50 +1,54 @@
-/*
- * 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.render.ps;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the PostScript Renderer.
- */
-public class PSRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_POSTSCRIPT};
-
-
- /** @see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new PSRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.ps;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the PostScript Renderer.
+ */
+public class PSRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_POSTSCRIPT};
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#makeRenderer(FOUserAgent) */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PSRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getConfigurator(FOUserAgent) */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PSRendererConfigurator(userAgent);
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+}
Index: src/java/org/apache/fop/render/ps/NativeTextHandler.java
===================================================================
--- src/java/org/apache/fop/render/ps/NativeTextHandler.java (revision 540059)
+++ src/java/org/apache/fop/render/ps/NativeTextHandler.java (working copy)
@@ -159,7 +159,7 @@
}
int fontSize = 1000 * f.getSize();
String style = f.isItalic() ? "italic" : "normal";
- int weight = f.isBold() ? Font.BOLD : Font.NORMAL;
+ int weight = f.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;
FontTriplet triplet = fontInfo.findAdjustWeight(fontFamily, style, weight);
if (triplet == null) {
Index: src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/ps/PSRendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/ps/PSRendererConfigurator.java (revision 0)
@@ -0,0 +1,56 @@
+/*
+ * 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.render.ps;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+
+/**
+ * Postscript renderer config
+ */
+public class PSRendererConfigurator extends PrintRendererConfigurator {
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public PSRendererConfigurator(FOUserAgent userAgent) {
+ super(userAgent);
+ }
+
+ /**
+ * Configure the PS renderer.
+ * @param renderer postscript renderer
+ * @throws FOPException fop exception
+ */
+ public void configure(Renderer renderer) throws FOPException {
+ Configuration cfg = super.getRendererConfig(renderer);
+ if (cfg != null) {
+ super.configure(renderer);
+
+ PSRenderer psRenderer = (PSRenderer)renderer;
+ psRenderer.setAutoRotateLandscape(
+ cfg.getChild("auto-rotate-landscape").getValueAsBoolean(false));
+ }
+ }
+}
Index: src/java/org/apache/fop/render/RendererContext.java
===================================================================
--- src/java/org/apache/fop/render/RendererContext.java (revision 540059)
+++ src/java/org/apache/fop/render/RendererContext.java (working copy)
@@ -23,7 +23,6 @@
import java.util.Map;
//FOP
-import org.apache.avalon.framework.configuration.Configuration;
import org.apache.fop.apps.FOUserAgent;
/**
@@ -156,17 +155,10 @@
return ((Integer)context.getProperty(RendererContextConstants.HEIGHT)).intValue();
}
- /** @return the handler configuration */
- public Configuration getHandlerConfiguration() {
- return (Configuration)context.getProperty(
- RendererContextConstants.HANDLER_CONFIGURATION);
- }
-
/** @return the foreign attributes */
public Map getForeignAttributes() {
return (Map)context.getProperty(RendererContextConstants.FOREIGN_ATTRIBUTES);
- }
-
+ }
}
}
Index: src/java/org/apache/fop/render/awt/AWTRenderer.java
===================================================================
--- src/java/org/apache/fop/render/awt/AWTRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/awt/AWTRenderer.java (working copy)
@@ -38,6 +38,7 @@
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactoryConfigurator;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Area;
import org.apache.fop.area.PageViewport;
@@ -149,10 +150,10 @@
pageWidth = (int) Math.round(bounds.getWidth() / 1000f);
pageHeight = (int) Math.round(bounds.getHeight() / 1000f);
double scaleX = scaleFactor
- * (25.4 / FOUserAgent.DEFAULT_TARGET_RESOLUTION)
+ * (25.4 / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION)
/ userAgent.getTargetPixelUnitToMillimeter();
double scaleY = scaleFactor
- * (25.4 / FOUserAgent.DEFAULT_TARGET_RESOLUTION)
+ * (25.4 / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION)
/ userAgent.getTargetPixelUnitToMillimeter();
int bitmapWidth = (int) ((pageWidth * scaleX) + 0.5);
int bitmapHeight = (int) ((pageHeight * scaleY) + 0.5);
Index: src/java/org/apache/fop/render/print/PrintRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/print/PrintRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/print/PrintRendererMaker.java (working copy)
@@ -1,50 +1,56 @@
-/*
- * 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.render.print;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the Print Renderer.
- */
-public class PrintRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_PRINT};
-
-
- /**@see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new PrintRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return false;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.print;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the Print Renderer.
+ */
+public class PrintRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_PRINT};
+
+ /**@see org.apache.fop.render.AbstractRendererMaker#makeRenderer(FOUserAgent) */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new PrintRenderer();
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getConfigurator(FOUserAgent) */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PrintRendererConfigurator(userAgent);
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return false;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Index: src/java/org/apache/fop/render/xml/XMLRenderer.java
===================================================================
--- src/java/org/apache/fop/render/xml/XMLRenderer.java (revision 540059)
+++ src/java/org/apache/fop/render/xml/XMLRenderer.java (working copy)
@@ -41,8 +41,6 @@
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.fop.util.QName;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
@@ -83,7 +81,6 @@
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.extensions.ExtensionAttachment;
import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.render.PrintRenderer;
import org.apache.fop.render.Renderer;
@@ -140,22 +137,6 @@
}
/**
- * Configure the XML renderer.
- * Get the configuration to be used for fonts etc.
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration cfg) throws ConfigurationException {
- super.configure(cfg);
- //Font configuration
- List cfgFonts = FontSetup.buildFontListFromConfiguration(cfg, this);
- if (this.fontList == null) {
- this.fontList = cfgFonts;
- } else {
- this.fontList.addAll(cfgFonts);
- }
- }
-
- /**
* @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
*/
public void setUserAgent(FOUserAgent agent) {
Index: src/java/org/apache/fop/render/xml/XMLRendererMaker.java
===================================================================
--- src/java/org/apache/fop/render/xml/XMLRendererMaker.java (revision 540059)
+++ src/java/org/apache/fop/render/xml/XMLRendererMaker.java (working copy)
@@ -1,50 +1,56 @@
-/*
- * 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.render.xml;
-
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.Renderer;
-
-/**
- * RendererMaker for the Area Tree XML Renderer.
- */
-public class XMLRendererMaker extends AbstractRendererMaker {
-
- private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AREA_TREE};
-
-
- /**@see org.apache.fop.render.AbstractRendererMaker */
- public Renderer makeRenderer(FOUserAgent ua) {
- return new XMLRenderer();
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
- public boolean needsOutputStream() {
- return true;
- }
-
- /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
- public String[] getSupportedMimeTypes() {
- return MIMES;
- }
-
-}
+/*
+ * 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.render.xml;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.render.AbstractRendererMaker;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfigurator;
+
+/**
+ * RendererMaker for the Area Tree XML Renderer.
+ */
+public class XMLRendererMaker extends AbstractRendererMaker {
+
+ private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_AREA_TREE};
+
+ /**@see org.apache.fop.render.AbstractRendererMaker#makeRenderer(FOUserAgent) */
+ public Renderer makeRenderer(FOUserAgent userAgent) {
+ return new XMLRenderer();
+ }
+
+ /**@see org.apache.fop.render.AbstractRendererMaker#getConfigurator(FOUserAgent) */
+ public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
+ return new PrintRendererConfigurator(userAgent);
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#needsOutputStream() */
+ public boolean needsOutputStream() {
+ return true;
+ }
+
+ /** @see org.apache.fop.render.AbstractRendererMaker#getSupportedMimeTypes() */
+ public String[] getSupportedMimeTypes() {
+ return MIMES;
+ }
+
+}
Index: src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
===================================================================
--- src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (revision 0)
+++ src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java (revision 0)
@@ -0,0 +1,241 @@
+/*
+ * 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.render.afp;
+
+import java.util.List;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.fonts.FontUtil;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.render.PrintRendererConfigurator;
+import org.apache.fop.render.Renderer;
+import org.apache.fop.render.afp.fonts.AFPFontInfo;
+import org.apache.fop.render.afp.fonts.CharacterSet;
+import org.apache.fop.render.afp.fonts.FopCharacterSet;
+import org.apache.fop.render.afp.fonts.OutlineFont;
+import org.apache.fop.render.afp.fonts.RasterFont;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * AFP Renderer configurator
+ */
+public class AFPRendererConfigurator extends PrintRendererConfigurator {
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public AFPRendererConfigurator(FOUserAgent userAgent) {
+ super(userAgent);
+ }
+
+ private AFPFontInfo buildFont(Configuration fontCfg, String fontPath)
+ throws ConfigurationException {
+
+ Configuration[] triple = fontCfg.getChildren("font-triplet");
+ List tripleList = new java.util.ArrayList();
+ if (triple.length == 0) {
+ log.error("Mandatory font configuration element ' 0) {
+ style = Font.STYLE_ITALIC;
+ } else {
+ for (int i = 0; i < ITALIC_WORDS.length; i++) {
+ if (searchName.indexOf(ITALIC_WORDS[i]) != -1) {
+ style = Font.STYLE_ITALIC;
+ break;
+ }
+ }
+ }
+
+ // weight
+ int weight = Font.WEIGHT_NORMAL;
+ for (int i = 0; i < BOLD_WORDS.length; i++) {
+ if (searchName.indexOf(BOLD_WORDS[i]) != -1) {
+ weight = Font.WEIGHT_BOLD;
+ break;
+ }
+ }
+ return new FontTriplet(name, style, weight);
+ }
+
+ /**
+ * Attempts to determine FontInfo from a given custom font
+ * @param fontFile
+ * @param customFont
+ * @param useCache resolve font info from cache
+ * @return
+ */
+ private EmbedFontInfo fontInfoFromCustomFont(
+ File fontFile, CustomFont customFont, boolean useCache) {
+ FontTriplet fontTriplet = tripletFromFont(customFont);
+ List fontTripletList = new java.util.ArrayList();
+ fontTripletList.add(fontTriplet);
+ String embedUrl;
+ try {
+ embedUrl = fontFile.toURL().toExternalForm();
+ } catch (MalformedURLException e) {
+ embedUrl = fontFile.getAbsolutePath();
+ }
+ EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(),
+ fontTripletList, embedUrl);
+ if (useCache) {
+ FopCache cache = FopCache.getInstance();
+ cache.addFont(fontInfo);
+ }
+ return fontInfo;
+ }
+
+ /**
+ * Attempts to determine EmbedFontInfo from a given font file.
+ *
+ * @param fontFile font file
+ * @param resolver font resolver used to resolve font
+ * @param useCache resolve font info from cache
+ * @return newly created embed font info
+ */
+ public EmbedFontInfo find(File fontFile, FontResolver resolver, boolean useCache) {
+ String embedUrl = null;
+ try {
+ embedUrl = fontFile.toURL().toExternalForm();
+ } catch (MalformedURLException mfue) {
+ // should never happen
+ log.error("Failed to convert '" + fontFile + "' to URL: " + mfue.getMessage() );
+ }
+
+ long fileLastModified = -1;
+ if (useCache) {
+ FopCache cache = FopCache.getInstance();
+ fileLastModified = fontFile.lastModified();
+ // firstly try and fetch it from cache before loading/parsing the font file
+ if (cache.containsFont(embedUrl)) {
+ CachedFontInfo fontInfo = cache.getFont(embedUrl);
+ if (fontInfo.lastModified() == fileLastModified) {
+ return fontInfo;
+ } else {
+ // out of date cache item
+ cache.removeFont(embedUrl);
+ }
+ // is this a previously failed parsed font?
+ } else if (cache.isFailedFont(embedUrl, fileLastModified)) {
+ log.info("Unable to load font file: " + embedUrl);
+ return null;
+ }
+ }
+
+ // try to determine triplet information from font file
+ CustomFont customFont = null;
+ try {
+ customFont = FontLoader.loadFont(fontFile, resolver);
+ } catch (Exception e) {
+ log.error("Unable to load font file: " + embedUrl);
+ if (useCache) {
+ FopCache.getInstance().registerFailedFont(embedUrl, fileLastModified);
+ }
+ return null;
+ }
+ return fontInfoFromCustomFont(fontFile, customFont, useCache);
+ }
+}
\ No newline at end of file
Property changes on: src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java
===================================================================
--- src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java (revision 0)
+++ src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java (revision 0)
@@ -0,0 +1,158 @@
+/*
+ * 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.fonts.autodetect;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.io.DirectoryWalker;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Helps to autodetect/locate available operating system fonts
+ */
+public class FontFileFinder extends DirectoryWalker implements FontFinder {
+
+ /** logging instance */
+ private final Log log = LogFactory.getLog(FontFileFinder.class);
+
+ /** default depth limit of recursion when searching for font files **/
+ public static final int DEFAULT_DEPTH_LIMIT = -1;
+
+ /**
+ * Default constructor
+ */
+ public FontFileFinder() {
+ super(getDirectoryFilter(), getFileFilter(), DEFAULT_DEPTH_LIMIT);
+ }
+
+ /**
+ * Constructor
+ * @param depthLimit recursion depth limit
+ */
+ public FontFileFinder(int depthLimit) {
+ super(getDirectoryFilter(), getFileFilter(), depthLimit);
+ }
+
+ /**
+ * Font directory filter. Currently ignores hidden directories.
+ * @return IOFileFilter font directory filter
+ */
+ protected static IOFileFilter getDirectoryFilter() {
+ return FileFilterUtils.andFileFilter(
+ FileFilterUtils.directoryFileFilter(),
+ FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter("."))
+ );
+ }
+
+ /**
+ * Font file filter. Currently searches for files with .ttf and .pfb extensions.
+ * @return IOFileFilter font file filter
+ */
+ protected static IOFileFilter getFileFilter() {
+ return FileFilterUtils.andFileFilter(
+ FileFilterUtils.fileFileFilter(),
+ FileFilterUtils.orFileFilter(
+ FileFilterUtils.suffixFileFilter(".ttf"),
+ FileFilterUtils.suffixFileFilter(".pfb")
+ )
+ );
+ }
+
+ /**
+ * @param directory directory to handle
+ * @param depth recursion depth
+ * @param results collection
+ * @return whether directory should be handled
+ * @see org.apache.commons.io.DirectoryWalker#handleDirectory(File, int, Collection)
+ */
+ protected boolean handleDirectory(File directory, int depth, Collection results) {
+ return true;
+ }
+
+ /**
+ * @param file file to handle
+ * @param depth recursion depth
+ * @param results collection
+ * @see org.apache.commons.io.DirectoryWalker#handleFile(File, int, Collection)
+ */
+ protected void handleFile(File file, int depth, Collection results) {
+ results.add(file);
+ }
+
+ /**
+ * @param directory the directory being processed
+ * @param depth the current directory level
+ * @param results the colleciton of results objects
+ * @see org.apache.commons.io.DirectoryWalker.handleDirectoryEnd
+ */
+ protected void handleDirectoryEnd(File directory, int depth, Collection results) {
+ if (log.isInfoEnabled()) {
+ log.info(directory + ": found " + results.size() + " font"
+ + ((results.size() == 1) ? "" : "s"));
+ }
+ }
+
+ /**
+ * Automagically finds a list of font files on local system
+ *
+ * @return list of font files
+ * @throws IOException io exception
+ * @see org.apache.fop.fonts.autodetect.FontFinder#find()
+ */
+ public List find() throws IOException {
+ final FontFinder fontDirFinder;
+ final String osName = System.getProperty("os.name");
+ if (osName.startsWith("Windows")) {
+ fontDirFinder = new WindowsFontDirFinder();
+ } else {
+ if (osName.startsWith("Mac")) {
+ fontDirFinder = new MacFontDirFinder();
+ } else {
+ fontDirFinder = new UnixFontDirFinder();
+ }
+ }
+ List fontDirs = fontDirFinder.find();
+ List results = new java.util.ArrayList();
+ for (Iterator iter = fontDirs.iterator(); iter.hasNext();) {
+ super.walk((File)iter.next(), results);
+ }
+ return results;
+ }
+
+ /**
+ * Searches a given directory for font files
+ *
+ * @param dir directory to search
+ * @return list of font files
+ * @throws IOException io exception
+ */
+ public List find(String dir) throws IOException {
+ List results = new java.util.ArrayList();
+ super.walk(new File(dir), results);
+ return results;
+ }
+}
\ No newline at end of file
Property changes on: src/java/org/apache/fop/fonts/autodetect/FontFileFinder.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/java/org/apache/fop/fonts/autodetect/FontFinder.java
===================================================================
--- src/java/org/apache/fop/fonts/autodetect/FontFinder.java (revision 0)
+++ src/java/org/apache/fop/fonts/autodetect/FontFinder.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * 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.fonts.autodetect;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Implementers provide find method for searching native operating system
+ * for available fonts.
+ */
+public interface FontFinder {
+ /**
+ * finds a list of font files
+ * @return list of font files
+ * @throws IOException io exception
+ */
+ List find() throws IOException;
+}
Property changes on: src/java/org/apache/fop/fonts/autodetect/FontFinder.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java
===================================================================
--- src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java (revision 0)
+++ src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java (revision 0)
@@ -0,0 +1,39 @@
+/*
+ * 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.fonts.autodetect;
+
+/**
+ * Mac font directory finder
+ */
+public class MacFontDirFinder extends NativeFontDirFinder {
+
+ /**
+ * Some guesses at possible unix font directory locations
+ * @return a array of possible font directory locations
+ */
+ protected String[] getSearchableDirectories() {
+ return new String[] {
+ System.getProperty("user.home") + "/Library/Fonts/", // user
+ "/Library/Fonts/", // local
+ "/System/Library/Fonts/", // system
+ "/Network/Library/Fonts/" // network
+ };
+ }
+}
Property changes on: src/java/org/apache/fop/fonts/autodetect/MacFontDirFinder.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/java/org/apache/fop/fonts/autodetect/package.html
===================================================================
--- src/java/org/apache/fop/fonts/autodetect/package.html (revision 0)
+++ src/java/org/apache/fop/fonts/autodetect/package.html (revision 0)
@@ -0,0 +1,23 @@
+
+
+
+org.apache.fop.fonts.autodetect Package
+
+
A collection of classes that aid in the autodetection of installed system fonts.
+
+
\ No newline at end of file
Index: src/java/org/apache/fop/fonts/FontInfo.java
===================================================================
--- src/java/org/apache/fop/fonts/FontInfo.java (revision 540059)
+++ src/java/org/apache/fop/fonts/FontInfo.java (working copy)
@@ -130,6 +130,9 @@
*/
private FontTriplet fontLookup(String family, String style,
int weight, boolean substFont) {
+ if( log.isDebugEnabled() ) {
+ log.debug(family + " " + style + " " + weight);
+ }
FontTriplet startKey = createFontKey(family, style, weight);
FontTriplet key = startKey;
// first try given parameters
@@ -146,13 +149,13 @@
// only if the font may be substituted
// fallback 1: try the same font-family and weight with default style
if (f == null) {
- key = createFontKey(family, "normal", weight);
+ key = createFontKey(family, Font.STYLE_NORMAL, weight);
f = getInternalFontKey(key);
}
// fallback 2: try the same font-family with default style and weight
if (f == null) {
- key = createFontKey(family, "normal", 400);
+ key = createFontKey(family, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
f = getInternalFontKey(key);
}
@@ -426,8 +429,4 @@
return 0;
}
}
-
}
-
-
-
Index: src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
===================================================================
--- src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (revision 540059)
+++ src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (working copy)
@@ -1,88 +1,77 @@
-/*
- * 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.fonts.type1;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.fop.fonts.CustomFont;
-import org.apache.fop.fonts.FontLoader;
-import org.apache.fop.fonts.FontResolver;
-import org.apache.fop.fonts.FontType;
-import org.apache.fop.fonts.SingleByteFont;
-
-/**
- * Loads a Type 1 font into memory directly from the original font file.
- */
-public class Type1FontLoader extends FontLoader {
-
- private String fontFileURI;
- private PFMFile pfm;
- private SingleByteFont singleFont;
- private CustomFont returnFont;
- private FontResolver resolver;
-
- /**
- * Constructs a new Type 1 font loader.
- * @param fontFileURI the URI to the PFB file of a Type 1 font
- * @param in the InputStream reading the PFM file of a Type 1 font
- * @param resolver the font resolver used to resolve URIs
- * @throws IOException In case of an I/O error
- */
- public Type1FontLoader(String fontFileURI, InputStream in, FontResolver resolver)
- throws IOException {
- this.fontFileURI = fontFileURI;
- this.resolver = resolver;
-
- pfm = new PFMFile();
- pfm.load(in);
- singleFont = new SingleByteFont();
- singleFont.setFontType(FontType.TYPE1);
- singleFont.setResolver(this.resolver);
- returnFont = singleFont;
- read();
- }
-
- private void read() throws IOException {
- returnFont.setFontName(pfm.getPostscriptName());
- returnFont.setCapHeight(pfm.getCapHeight());
- returnFont.setXHeight(pfm.getXHeight());
- returnFont.setAscender(pfm.getLowerCaseAscent());
- returnFont.setDescender(pfm.getLowerCaseDescent());
- returnFont.setFontBBox(pfm.getFontBBox());
- returnFont.setFirstChar(pfm.getFirstChar());
- returnFont.setLastChar(pfm.getFirstChar());
- returnFont.setFlags(pfm.getFlags());
- returnFont.setStemV(pfm.getStemV());
- returnFont.setItalicAngle(pfm.getItalicAngle());
- returnFont.setMissingWidth(0);
- for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
- singleFont.setWidth(i, pfm.getCharWidth(i));
- }
- singleFont.setEmbedFileName(this.fontFileURI);
-
- }
-
- /** @see org.apache.fop.fonts.FontLoader#getFont() */
- public CustomFont getFont() {
- return this.returnFont;
- }
-
-}
+/*
+ * 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.fonts.type1;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.fop.fonts.FontLoader;
+import org.apache.fop.fonts.FontResolver;
+import org.apache.fop.fonts.FontType;
+import org.apache.fop.fonts.SingleByteFont;
+
+/**
+ * Loads a Type 1 font into memory directly from the original font file.
+ */
+public class Type1FontLoader extends FontLoader {
+
+ private PFMFile pfm;
+ private SingleByteFont singleFont;
+
+ /**
+ * Constructs a new Type 1 font loader.
+ * @param fontFileURI the URI to the PFB file of a Type 1 font
+ * @param in the InputStream reading the PFM file of a Type 1 font
+ * @param resolver the font resolver used to resolve URIs
+ * @throws IOException In case of an I/O error
+ */
+ public Type1FontLoader(String fontFileURI, InputStream in, FontResolver resolver)
+ throws IOException {
+ super(fontFileURI, in, resolver);
+ }
+
+ /**
+ * @see FontLoader#read()
+ */
+ protected void read() throws IOException {
+ pfm = new PFMFile();
+ pfm.load(in);
+ singleFont = new SingleByteFont();
+ singleFont.setFontType(FontType.TYPE1);
+ singleFont.setResolver(this.resolver);
+ returnFont = singleFont;
+ returnFont.setFontName(pfm.getPostscriptName());
+ returnFont.setCapHeight(pfm.getCapHeight());
+ returnFont.setXHeight(pfm.getXHeight());
+ returnFont.setAscender(pfm.getLowerCaseAscent());
+ returnFont.setDescender(pfm.getLowerCaseDescent());
+ returnFont.setFontBBox(pfm.getFontBBox());
+ returnFont.setFirstChar(pfm.getFirstChar());
+ returnFont.setLastChar(pfm.getFirstChar());
+ returnFont.setFlags(pfm.getFlags());
+ returnFont.setStemV(pfm.getStemV());
+ returnFont.setItalicAngle(pfm.getItalicAngle());
+ returnFont.setMissingWidth(0);
+ for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
+ singleFont.setWidth(i, pfm.getCharWidth(i));
+ }
+ singleFont.setEmbedFileName(this.fontFileURI);
+ }
+}
Index: src/java/org/apache/fop/fonts/FontSetup.java
===================================================================
--- src/java/org/apache/fop/fonts/FontSetup.java (revision 540059)
+++ src/java/org/apache/fop/fonts/FontSetup.java (working copy)
@@ -34,16 +34,11 @@
import org.apache.fop.fonts.base14.CourierBoldOblique;
import org.apache.fop.fonts.base14.Symbol;
import org.apache.fop.fonts.base14.ZapfDingbats;
-import org.apache.fop.render.PrintRenderer;
// commons logging
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-// Avalon
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
// Java
import java.util.List;
@@ -63,7 +58,7 @@
* logging instance
*/
protected static Log log = LogFactory.getLog("org.apache.fop.fonts");
-
+
/**
* Sets up the font info object.
*
@@ -113,52 +108,52 @@
// fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
/* any is treated as serif */
- fontInfo.addFontProperties("F5", "any", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "any", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F6", "any", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F7", "any", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "any", "italic", Font.BOLD);
- fontInfo.addFontProperties("F8", "any", "oblique", Font.BOLD);
+ fontInfo.addFontProperties("F5", "any", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "any", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "any", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "any", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "any", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "any", "oblique", Font.WEIGHT_BOLD);
- fontInfo.addFontProperties("F1", "sans-serif", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F2", "sans-serif", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F2", "sans-serif", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F3", "sans-serif", "normal", Font.BOLD);
- fontInfo.addFontProperties("F4", "sans-serif", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F4", "sans-serif", "italic", Font.BOLD);
- fontInfo.addFontProperties("F5", "serif", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "serif", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "serif", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "serif", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "serif", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "serif", "italic", Font.BOLD);
- fontInfo.addFontProperties("F9", "monospace", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F10", "monospace", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F10", "monospace", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F11", "monospace", "normal", Font.BOLD);
- fontInfo.addFontProperties("F12", "monospace", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F12", "monospace", "italic", Font.BOLD);
+ fontInfo.addFontProperties("F1", "sans-serif", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "sans-serif", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F3", "sans-serif", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "sans-serif", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F5", "serif", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "serif", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "serif", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "serif", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "serif", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F9", "monospace", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "monospace", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F11", "monospace", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "monospace", "italic", Font.WEIGHT_BOLD);
- fontInfo.addFontProperties("F1", "Helvetica", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F2", "Helvetica", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F2", "Helvetica", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F3", "Helvetica", "normal", Font.BOLD);
- fontInfo.addFontProperties("F4", "Helvetica", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F4", "Helvetica", "italic", Font.BOLD);
- fontInfo.addFontProperties("F5", "Times", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "Times", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times", "italic", Font.BOLD);
- fontInfo.addFontProperties("F9", "Courier", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F10", "Courier", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F10", "Courier", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F11", "Courier", "normal", Font.BOLD);
- fontInfo.addFontProperties("F12", "Courier", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F12", "Courier", "italic", Font.BOLD);
- fontInfo.addFontProperties("F13", "Symbol", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", Font.NORMAL);
+ fontInfo.addFontProperties("F1", "Helvetica", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F2", "Helvetica", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F3", "Helvetica", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F4", "Helvetica", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F5", "Times", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "Times", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F9", "Courier", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F10", "Courier", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F11", "Courier", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F12", "Courier", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F13", "Symbol", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", Font.WEIGHT_NORMAL);
// Custom type 1 fonts step 2/2
// fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL);
@@ -166,20 +161,20 @@
// fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD);
/* for compatibility with PassiveTex */
- fontInfo.addFontProperties("F5", "Times-Roman", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times-Roman", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times-Roman", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "Times-Roman", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times-Roman", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times-Roman", "italic", Font.BOLD);
- fontInfo.addFontProperties("F5", "Times Roman", "normal", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times Roman", "oblique", Font.NORMAL);
- fontInfo.addFontProperties("F6", "Times Roman", "italic", Font.NORMAL);
- fontInfo.addFontProperties("F7", "Times Roman", "normal", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times Roman", "oblique", Font.BOLD);
- fontInfo.addFontProperties("F8", "Times Roman", "italic", Font.BOLD);
+ fontInfo.addFontProperties("F5", "Times-Roman", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times-Roman", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "Times-Roman", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times-Roman", "italic", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F5", "Times Roman", "normal", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "oblique", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F6", "Times Roman", "italic", Font.WEIGHT_NORMAL);
+ fontInfo.addFontProperties("F7", "Times Roman", "normal", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "oblique", Font.WEIGHT_BOLD);
+ fontInfo.addFontProperties("F8", "Times Roman", "italic", Font.WEIGHT_BOLD);
fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
- "normal", Font.NORMAL);
+ "normal", Font.WEIGHT_NORMAL);
/* Add configured fonts */
addConfiguredFonts(fontInfo, embedList, 15, resolver);
@@ -218,10 +213,7 @@
reader.setFontEmbedPath(configFontInfo.getEmbedFile());
fontInfo.addMetrics(internalName, reader.getFont());
*/
- LazyFont font = new LazyFont(configFontInfo.getEmbedFile(),
- metricsFile,
- configFontInfo.getKerning(),
- resolver);
+ LazyFont font = new LazyFont(configFontInfo, resolver);
fontInfo.addMetrics(internalName, font);
List triplets = configFontInfo.getFontTriplets();
@@ -237,7 +229,7 @@
}
/** @return a new FontResolver to be used by the font subsystem */
- private static FontResolver createMinimalFontResolver() {
+ public static FontResolver createMinimalFontResolver() {
return new FontResolver() {
/** @see org.apache.fop.fonts.FontResolver#resolve(java.lang.String) */
@@ -245,135 +237,6 @@
//Minimal functionality here
return new StreamSource(href);
}
-
};
- }
-
- /**
- * Builds a list of EmbedFontInfo objects for use with the setup() method.
- *
- * @param cfg Configuration object
- * @param renderer calling Renderer object
- * @return List the newly created list of fonts
- * @throws ConfigurationException if something's wrong with the config data
- */
- public static List buildFontListFromConfiguration(Configuration cfg, PrintRenderer renderer)
- throws ConfigurationException {
- List fontList = new java.util.ArrayList();
-
- FontResolver fontResolver = (renderer != null ? renderer.getFontResolver() : null);
- if (fontResolver == null) {
- //Ensure that we have minimal font resolution capabilities
- fontResolver = FontSetup.createMinimalFontResolver();
- }
-
- boolean strict = false;
- if (renderer != null) {
- strict = renderer.getUserAgent().getFactory().validateUserConfigStrictly();
- }
-
- Configuration[] fonts = cfg.getChildren("fonts");
- for (int f = 0; f < fonts.length; f++) {
-
- Configuration[] font = fonts[f].getChildren("font");
- for (int i = 0; i < font.length; i++) {
-
- String metricsUrl = font[i].getAttribute("metrics-url", null);
- String embedUrl = font[i].getAttribute("embed-url", null);
-
- if (metricsUrl == null && embedUrl == null) {
- if (strict) {
- throw new ConfigurationException(
- "Font configuration without metric-url or embed-url");
- }
- log.error("Font configuration without metric-url or embed-url");
- continue;
- }
-
- if (metricsUrl != null && fontResolver.resolve(metricsUrl) == null) {
- if (strict) {
- throw new ConfigurationException("Failed to resolve font metric-url '"
- + metricsUrl + "'");
- }
- log.error("Failed to resolve font metric-url '" + metricsUrl + "'");
- continue;
- }
-
- if (embedUrl != null && fontResolver.resolve(embedUrl) == null) {
- if (strict) {
- throw new ConfigurationException("Failed to resolve font with embed-url '"
- + embedUrl + "'");
- }
- log.error("Failed to resolve font with embed-url '" + embedUrl + "'");
- continue;
- }
-
- boolean useKerning = font[i].getAttributeAsBoolean("kerning", false);
-
- Configuration[] triple = font[i].getChildren("font-triplet");
- List tripleList = new java.util.ArrayList();
- for (int j = 0; j < triple.length; j++) {
- String name = triple[j].getAttribute("name");
- if (name == null) {
- if (strict) {
- throw new ConfigurationException("font-triplet without name");
- }
- log.error("font-triplet without name");
- continue;
- }
-
- String weightStr = triple[j].getAttribute("weight");
- if (weightStr == null) {
- if (strict) {
- throw new ConfigurationException("font-triplet without weight");
- }
- log.error("font-triplet without weight");
- continue;
- }
- int weight = FontUtil.parseCSS2FontWeight(weightStr);
-
- String style = triple[j].getAttribute("style");
- if (style == null) {
- if (strict) {
- throw new ConfigurationException("font-triplet without style");
- }
- log.error("font-triplet without style");
- continue;
- }
-
- tripleList.add(FontInfo.createFontKey(name,
- style, weight));
- }
-
- EmbedFontInfo configFontInfo = new EmbedFontInfo(metricsUrl,
- useKerning, tripleList, embedUrl);
-
- if (log.isDebugEnabled()) {
- log.debug("Adding font " + configFontInfo.getEmbedFile()
- + ", metric file " + configFontInfo.getMetricsFile());
- for (int j = 0; j < tripleList.size(); ++j) {
- FontTriplet triplet = (FontTriplet) tripleList.get(j);
- log.debug("Font triplet "
- + triplet.getName() + ", "
- + triplet.getStyle() + ", "
- + triplet.getWeight());
- }
- }
- fontList.add(configFontInfo);
- }
- }
- return fontList;
- }
-
- /**
- * Builds a list of EmbedFontInfo objects for use with the setup() method.
- *
- * @param cfg Configuration object
- * @return List the newly created list of fonts
- * @throws ConfigurationException if something's wrong with the config data
- */
- public static List buildFontListFromConfiguration(Configuration cfg)
- throws ConfigurationException {
- return buildFontListFromConfiguration(cfg, null);
- }
+ }
}
Index: src/java/org/apache/fop/fonts/FontLoader.java
===================================================================
--- src/java/org/apache/fop/fonts/FontLoader.java (revision 540059)
+++ src/java/org/apache/fop/fonts/FontLoader.java (working copy)
@@ -1,106 +1,179 @@
-/*
- * 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.fonts;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.fop.fonts.truetype.TTFFontLoader;
-import org.apache.fop.fonts.type1.Type1FontLoader;
-
-/**
- * Base class for font loaders.
- */
-public abstract class FontLoader {
-
- /**
- * Loads a custom font from a URI. In the case of Type 1 fonts, the PFB file must be specified.
- * @param fontFileURI the URI to the font
- * @param resolver the font resolver to use when resolving URIs
- * @return the newly loaded font
- * @throws IOException In case of an I/O error
- */
- public static CustomFont loadFont(String fontFileURI, FontResolver resolver)
- throws IOException {
- FontLoader loader;
- fontFileURI = fontFileURI.trim();
- String name = fontFileURI.toLowerCase();
- String effURI;
- boolean type1 = false;
- if (name.endsWith(".pfb")) {
- type1 = true;
- effURI = name.substring(0, fontFileURI.length() - 4) + ".pfm";
- } else {
- effURI = fontFileURI;
- }
-
- InputStream in = openFontFile(resolver, effURI);
- try {
- if (type1) {
- loader = new Type1FontLoader(fontFileURI, in, resolver);
- } else {
- loader = new TTFFontLoader(fontFileURI, in, resolver);
- }
- return loader.getFont();
- } finally {
- IOUtils.closeQuietly(in);
- }
- }
-
- private static InputStream openFontFile(FontResolver resolver, String uri)
- throws IOException, MalformedURLException {
- InputStream in = null;
- if (resolver != null) {
- Source source = resolver.resolve(uri);
- if (source == null) {
- String err = "Cannot load font: failed to create Source for font file "
- + uri;
- throw new IOException(err);
- }
- if (source instanceof StreamSource) {
- in = ((StreamSource) source).getInputStream();
- }
- if (in == null && source.getSystemId() != null) {
- in = new java.net.URL(source.getSystemId()).openStream();
- }
- if (in == null) {
- String err = "Cannot load font: failed to create InputStream from"
- + " Source for font file " + uri;
- throw new IOException(err);
- }
- } else {
- in = new URL(uri).openStream();
- }
- return in;
- }
-
- /**
- * @return the font loaded by this loader
- */
- public abstract CustomFont getFont();
-
-
-}
+/*
+ * 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.fonts;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fonts.truetype.TTFFontLoader;
+import org.apache.fop.fonts.type1.Type1FontLoader;
+
+/**
+ * Base class for font loaders.
+ */
+public abstract class FontLoader {
+
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog("org.apache.fop.fonts");
+
+ protected String fontFileURI = null;
+ protected InputStream in = null;
+ protected FontResolver resolver = null;
+ protected CustomFont returnFont = null;
+
+ protected boolean loaded = false;
+
+ public FontLoader(String fontFileURI, InputStream in, FontResolver resolver) {
+ this.fontFileURI = fontFileURI;
+ this.in = in;
+ this.resolver = resolver;
+ }
+
+ private static boolean isType1(String fontURI) {
+ return fontURI.toLowerCase().endsWith(".pfb");
+ }
+
+ /**
+ * Loads a custom font from a File. In the case of Type 1 fonts, the PFB file must be specified.
+ * @param fontFile the File representation of the font
+ * @param resolver the font resolver to use when resolving URIs
+ * @return the newly loaded font
+ * @throws IOException In case of an I/O error
+ */
+ public static CustomFont loadFont(File fontFile, FontResolver resolver)
+ throws IOException {
+ String fontFileURI = fontFile.getAbsolutePath();
+ boolean type1 = isType1(fontFileURI);
+ InputStream in = new FileInputStream(fontFile);
+ return loadFontFromInputStream(fontFileURI, resolver, type1, in);
+ }
+
+ /**
+ * Loads a custom font from a URI. In the case of Type 1 fonts, the PFB file must be specified.
+ * @param fontFileURI the URI to the font
+ * @param resolver the font resolver to use when resolving URIs
+ * @return the newly loaded font
+ * @throws IOException In case of an I/O error
+ */
+ public static CustomFont loadFont(String fontFileURI, FontResolver resolver)
+ throws IOException {
+ fontFileURI = fontFileURI.trim();
+ String name = fontFileURI.toLowerCase();
+ String effURI;
+ boolean type1 = isType1(fontFileURI);
+ if (type1) {
+ effURI = name.substring(0, fontFileURI.length() - 4) + ".pfm";
+ } else {
+ effURI = fontFileURI;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("opening " + effURI);
+ }
+ InputStream in = openFontFile(resolver, effURI);
+ return loadFontFromInputStream(fontFileURI, resolver, type1, in);
+ }
+
+ /**
+ * loads and returns a font given an input stream
+ * @param fontFileURI font file uri
+ * @param resolver font resolver
+ * @param isType1 is it a type1 font?
+ * @param in input stream
+ * @return
+ * @throws IOException
+ */
+ protected static CustomFont loadFontFromInputStream(
+ String fontFileURI, FontResolver resolver, boolean isType1,
+ InputStream in)
+ throws IOException {
+ FontLoader loader;
+ try {
+ if (isType1) {
+ loader = new Type1FontLoader(fontFileURI, in, resolver);
+ } else {
+ loader = new TTFFontLoader(fontFileURI, in, resolver);
+ }
+ return loader.getFont();
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ /**
+ * opens a font file and returns an input stream
+ * @param resolver
+ * @param uri
+ * @return
+ * @throws IOException
+ * @throws MalformedURLException
+ */
+ private static InputStream openFontFile(FontResolver resolver, String uri)
+ throws IOException, MalformedURLException {
+ InputStream in = null;
+ if (resolver != null) {
+ Source source = resolver.resolve(uri);
+ if (source == null) {
+ String err = "Cannot load font: failed to create Source for font file "
+ + uri;
+ throw new IOException(err);
+ }
+ if (source instanceof StreamSource) {
+ in = ((StreamSource) source).getInputStream();
+ }
+ if (in == null && source.getSystemId() != null) {
+ in = new java.net.URL(source.getSystemId()).openStream();
+ }
+ if (in == null) {
+ String err = "Cannot load font: failed to create InputStream from"
+ + " Source for font file " + uri;
+ throw new IOException(err);
+ }
+ } else {
+ in = new URL(uri).openStream();
+ }
+ return in;
+ }
+
+ /**
+ * reads/parses the font data
+ */
+ abstract protected void read() throws IOException;
+
+ /** @throws IOException
+ * @see org.apache.fop.fonts.FontLoader#getFont() */
+ public CustomFont getFont() throws IOException {
+ if (!loaded) {
+ read();
+ }
+ return this.returnFont;
+ }
+}
Index: src/java/org/apache/fop/svg/PDFTextPainter.java
===================================================================
--- src/java/org/apache/fop/svg/PDFTextPainter.java (revision 540059)
+++ src/java/org/apache/fop/svg/PDFTextPainter.java (working copy)
@@ -160,8 +160,8 @@
String style = ((posture != null) && (posture.floatValue() > 0.0))
? "italic" : "normal";
int weight = ((taWeight != null)
- && (taWeight.floatValue() > 1.0)) ? Font.BOLD
- : Font.NORMAL;
+ && (taWeight.floatValue() > 1.0)) ? Font.WEIGHT_BOLD
+ : Font.WEIGHT_NORMAL;
Font fontState = null;
FontInfo fi = fontInfo;
@@ -187,7 +187,7 @@
}
}
if (!found) {
- FontTriplet triplet = fontInfo.fontLookup("any", style, Font.NORMAL);
+ FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
int fsize = (int)(size.floatValue() * 1000);
fontState = fontInfo.getFontInstance(triplet, fsize);
} else {
@@ -196,7 +196,7 @@
}
}
int fStyle = java.awt.Font.PLAIN;
- if (weight == Font.BOLD) {
+ if (weight == Font.WEIGHT_BOLD) {
if (style.equals("italic")) {
fStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
} else {
Index: src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
===================================================================
--- src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (revision 540059)
+++ src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java (working copy)
@@ -28,13 +28,12 @@
import org.apache.fop.pdf.PDFResources;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.pdf.PDFAnnotList;
+import org.apache.fop.render.pdf.PDFRendererConfigurator;
import org.apache.fop.fonts.FontSetup;
import org.apache.fop.fonts.FontInfo;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import java.awt.Graphics;
import java.awt.Font;
@@ -57,7 +56,7 @@
* @see org.apache.fop.svg.PDFGraphics2D
*/
public class PDFDocumentGraphics2D extends PDFGraphics2D
- implements Configurable, Initializable {
+ implements Initializable {
private PDFContext pdfContext;
@@ -154,14 +153,6 @@
}
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration cfg) throws ConfigurationException {
- this.cfg = cfg;
- this.pdfContext.setFontList(FontSetup.buildFontListFromConfiguration(cfg));
- }
-
- /**
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
public void initialize() throws Exception {
@@ -176,7 +167,7 @@
if (this.cfg != null) {
this.pdfDoc.setFilterMap(
- PDFFilterList.buildFilterMapFromConfiguration(cfg));
+ PDFRendererConfigurator.buildFilterMapFromConfiguration(cfg));
}
}
Index: src/java/org/apache/fop/svg/PDFGraphics2D.java
===================================================================
--- src/java/org/apache/fop/svg/PDFGraphics2D.java (revision 540059)
+++ src/java/org/apache/fop/svg/PDFGraphics2D.java (working copy)
@@ -1429,7 +1429,7 @@
}
float siz = gFont.getSize2D();
String style = gFont.isItalic() ? "italic" : "normal";
- int weight = gFont.isBold() ? Font.BOLD : Font.NORMAL;
+ int weight = gFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;
FontTriplet triplet = fontInfo.fontLookup(n, style, weight);
fontState = fontInfo.getFontInstance(triplet, (int)(siz * 1000 + 0.5));
} else {
Index: src/java/org/apache/fop/apps/FopFactoryConfigurator.java
===================================================================
--- src/java/org/apache/fop/apps/FopFactoryConfigurator.java (revision 0)
+++ src/java/org/apache/fop/apps/FopFactoryConfigurator.java (revision 0)
@@ -0,0 +1,241 @@
+/*
+ * 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.apps;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.util.LogUtil;
+import org.xml.sax.SAXException;
+
+/**
+ * FopFactory configurator
+ */
+public class FopFactoryConfigurator {
+
+ /** Defines if FOP should use an alternative rule to determine text indents */
+ public static final boolean DEFAULT_BREAK_INDENT_INHERITANCE = false;
+
+ /** Defines if FOP should validate the user config strictly */
+ public static final boolean DEFAULT_STRICT_USERCONFIG_VALIDATION = true;
+
+ /** Defines if FOP should use strict validation for FO and user config */
+ public static final boolean DEFAULT_STRICT_FO_VALIDATION = true;
+
+ /** Defines the default page-width */
+ public static final String DEFAULT_PAGE_WIDTH = "8.26in";
+
+ /** Defines the default page-height */
+ public static final String DEFAULT_PAGE_HEIGHT = "11in";
+
+ /** Defines the default source resolution (72dpi) for FOP */
+ public static final float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi
+
+ /** Defines the default target resolution (72dpi) for FOP */
+ public static final float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi
+
+ /** Use cache (record previously detected font triplet info) */
+ public static final boolean DEFAULT_USE_CACHE = true;
+
+ /** logger instance */
+ private final Log log = LogFactory.getLog(FopFactoryConfigurator.class);
+
+ /** Fop factory */
+ private FopFactory factory = null;
+
+ /** Fop factory configuration */
+ private Configuration cfg = null;
+
+ /**
+ * Default constructor
+ * @param factory fop factory
+ */
+ public FopFactoryConfigurator(FopFactory factory) {
+ super();
+ this.factory = factory;
+ }
+
+ /**
+ * Initializes user agent settings from the user configuration
+ * file, if present: baseURL, resolution, default page size,...
+ * @param factory fop factory
+ * @throws FOPException fop exception
+ */
+ public void configure(FopFactory factory) throws FOPException {
+ if (log.isInfoEnabled()) {
+ log.info("Initializing FopFactory Configuration");
+ }
+
+ // strict configuration
+ if (cfg.getChild("strict-configuration", false) != null) {
+ try {
+ factory.setStrictUserConfigValidation(
+ cfg.getChild("strict-configuration").getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, false);
+ }
+ }
+ boolean strict = factory.validateUserConfigStrictly();
+
+ // strict fo validation
+ if (cfg.getChild("strict-validation", false) != null) {
+ try {
+ factory.setStrictValidation(
+ cfg.getChild("strict-validation").getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+
+ // base definitions for relative path resolution
+ if (cfg.getChild("base", false) != null) {
+ try {
+ factory.setBaseURL(
+ cfg.getChild("base").getValue(null));
+ } catch (MalformedURLException mfue) {
+ LogUtil.handleException(log, mfue, strict);
+ }
+ }
+ if (cfg.getChild("font-base", false) != null) {
+ try {
+ factory.setFontBaseURL(
+ cfg.getChild("font-base").getValue(null));
+ } catch (MalformedURLException mfue) {
+ LogUtil.handleException(log, mfue, strict);
+ }
+ }
+ if (cfg.getChild("hyphenation-base", false) != null) {
+ try {
+ factory.setHyphenBaseURL(
+ cfg.getChild("hyphenation-base").getValue(null));
+ } catch (MalformedURLException mfue) {
+ LogUtil.handleException(log, mfue, strict);
+ }
+ }
+
+ // renderer options
+ if (cfg.getChild("source-resolution", false) != null) {
+ factory.setSourceResolution(
+ cfg.getChild("source-resolution").getValueAsFloat(
+ FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION));
+ if (log.isInfoEnabled()) {
+ log.info("source-resolution set to: " + factory.getSourceResolution()
+ + "dpi (px2mm=" + factory.getSourcePixelUnitToMillimeter() + ")");
+ }
+ }
+ if (cfg.getChild("target-resolution", false) != null) {
+ factory.setTargetResolution(
+ cfg.getChild("target-resolution").getValueAsFloat(
+ FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION));
+ if (log.isInfoEnabled()) {
+ log.info("target-resolution set to: " + factory.getTargetResolution()
+ + "dpi (px2mm=" + factory.getTargetPixelUnitToMillimeter()
+ + ")");
+ }
+ }
+ if (cfg.getChild("break-indent-inheritance", false) != null) {
+ try {
+ factory.setBreakIndentInheritanceOnReferenceAreaBoundary(
+ cfg.getChild("break-indent-inheritance").getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+ Configuration pageConfig = cfg.getChild("default-page-settings");
+ if (pageConfig.getAttribute("height", null) != null) {
+ factory.setPageHeight(
+ pageConfig.getAttribute("height", FopFactoryConfigurator.DEFAULT_PAGE_HEIGHT));
+ if (log.isInfoEnabled()) {
+ log.info("Default page-height set to: " + factory.getPageHeight());
+ }
+ }
+ if (pageConfig.getAttribute("width", null) != null) {
+ factory.setPageWidth(
+ pageConfig.getAttribute("width", FopFactoryConfigurator.DEFAULT_PAGE_WIDTH));
+ if (log.isInfoEnabled()) {
+ log.info("Default page-width set to: " + factory.getPageWidth());
+ }
+ }
+
+ // caching (fonts)
+ if (cfg.getChild("use-cache", false) != null) {
+ try {
+ factory.setUseCache(
+ cfg.getChild("use-cache").getValueAsBoolean());
+ } catch (ConfigurationException mfue) {
+ LogUtil.handleException(log, mfue, strict);
+ }
+ }
+ }
+
+ /**
+ * Set the user configuration.
+ * @param userConfigFile the configuration file
+ * @throws IOException if an I/O error occurs
+ * @throws SAXException if a parsing error occurs
+ */
+ public void setUserConfig(File userConfigFile) throws SAXException, IOException {
+ try {
+ DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+ setUserConfig(cfgBuilder.buildFromFile(userConfigFile));
+ } catch (ConfigurationException e) {
+ throw new FOPException(e);
+ }
+ }
+
+ /**
+ * Set the user configuration from an URI.
+ * @param uri the URI to the configuration file
+ * @throws IOException if an I/O error occurs
+ * @throws SAXException if a parsing error occurs
+ */
+ public void setUserConfig(String uri) throws SAXException, IOException {
+ try {
+ DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+ setUserConfig(cfgBuilder.build(uri));
+ } catch (ConfigurationException e) {
+ throw new FOPException(e);
+ }
+ }
+
+ /**
+ * Set the user configuration.
+ * @param cfg avalon configuration
+ * @throws FOPException if a configuration problem occurs
+ */
+ public void setUserConfig(Configuration cfg) throws FOPException {
+ this.cfg = cfg;
+ configure(this.factory);
+ }
+
+ /**
+ * Get the avalon user configuration.
+ * @return the user configuration
+ */
+ public Configuration getUserConfig() {
+ return this.cfg;
+ }
+}
Index: src/java/org/apache/fop/apps/FOUserAgent.java
===================================================================
--- src/java/org/apache/fop/apps/FOUserAgent.java (revision 540059)
+++ src/java/org/apache/fop/apps/FOUserAgent.java (working copy)
@@ -63,19 +63,25 @@
public class FOUserAgent {
/** Defines the default target resolution (72dpi) for FOP */
- public static final float DEFAULT_TARGET_RESOLUTION = FopFactory.DEFAULT_TARGET_RESOLUTION;
+ public static final float DEFAULT_TARGET_RESOLUTION = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
private static Log log = LogFactory.getLog("FOP");
private FopFactory factory;
- /** The base URL for all URL resolutions, especially for external-graphics */
- private String baseURL;
-
+ /**
+ * The base URL for all URL resolutions, especially for
+ * external-graphics.
+ */
+ private String base = null;
+
+ /** The base URL for all font URL resolutions. */
+ private String fontBase = null;
+
/** A user settable URI Resolver */
private URIResolver uriResolver = null;
- private float targetResolution = DEFAULT_TARGET_RESOLUTION;
+ private float targetResolution = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
private Map rendererOptions = new java.util.HashMap();
private File outputFile = null;
private Renderer rendererOverride = null;
@@ -107,6 +113,7 @@
* Default constructor
* @throws FOPException
* @see org.apache.fop.apps.FopFactory
+ * @throws FOPException
* @deprecated Provided for compatibility only. Please use the methods from
* FopFactory to construct FOUserAgent instances!
*/
@@ -126,6 +133,7 @@
}
this.factory = factory;
setBaseURL(factory.getBaseURL());
+ setFontBaseURL(factory.getFontBaseURL());
setTargetResolution(factory.getTargetResolution());
}
@@ -277,18 +285,26 @@
/**
* Sets the base URL.
- * @param baseURL base URL
+ * @param baseUrl base URL
*/
- public void setBaseURL(String baseURL) {
- this.baseURL = baseURL;
+ public void setBaseURL(String baseUrl) {
+ this.base = baseUrl;
}
/**
+ * sets font base URL
+ * @param fontBaseUrl font base URL
+ */
+ public void setFontBaseURL(String fontBaseUrl) {
+ this.fontBase = fontBaseUrl;
+ }
+
+ /**
* Returns the base URL.
* @return the base URL
*/
public String getBaseURL() {
- return this.baseURL;
+ return this.base;
}
/**
@@ -410,8 +426,6 @@
*/
public void setTargetResolution(float dpi) {
this.targetResolution = dpi;
- log.info("target-resolution set to: " + targetResolution
- + "dpi (px2mm=" + getTargetPixelUnitToMillimeter() + ")");
}
/**
@@ -429,8 +443,7 @@
/** @return the font base URL */
public String getFontBaseURL() {
- String fontBaseURL = getFactory().getFontBaseURL();
- return fontBaseURL != null ? fontBaseURL : getBaseURL();
+ return fontBase != null ? fontBase : getBaseURL();
}
/**
Index: src/java/org/apache/fop/apps/FopCacheWriter.java
===================================================================
--- src/java/org/apache/fop/apps/FopCacheWriter.java (revision 0)
+++ src/java/org/apache/fop/apps/FopCacheWriter.java (revision 0)
@@ -0,0 +1,207 @@
+/*
+ * 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.apps;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.ConfigurationUtil;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fonts.CachedFontInfo;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * Writes fop cache to disk
+ */
+public class FopCacheWriter extends FopCacheConfigurator {
+
+ /** log class */
+ private static Log log = LogFactory.getLog(FopCacheReader.class);
+
+ /**
+ * Default constructor
+ * @param cache fop cache
+ */
+ public FopCacheWriter(FopCache cache) {
+ super(cache);
+ }
+
+ /**
+ * Updates the font info map from the font cache
+ *
+ * @param fontInfoMap
+ * font info map to serialize
+ * @throws FOPException
+ * fop exception
+ */
+ public void updateFonts(Map fontInfoMap) throws FOPException {
+ // create new fonts parent node
+ DefaultConfiguration fontsCfg = null;
+ DefaultConfiguration cacheConfig = (DefaultConfiguration)getConfiguration();
+ Configuration origFontsCfg = cacheConfig.getChild("fonts");
+ try {
+ fontsCfg = new DefaultConfiguration(origFontsCfg);
+ } catch (ConfigurationException e) {
+ // shouldn't happen
+ LogUtil.handleException(log, e, strictValidation);
+ }
+
+ long cached = System.currentTimeMillis();
+ // add new font info nodes to fonts parent node
+ for (Iterator it = fontInfoMap.values().iterator(); it.hasNext();) {
+ CachedFontInfo fontInfo = (CachedFontInfo) it.next();
+ String fontUrl = FopCache.getCacheKey(fontInfo);
+ Configuration[] fontCfgs = fontsCfg.getChildren("font");
+ boolean found = false;
+ for (int i = 0; i < fontCfgs.length; i++) {
+ Configuration fontCfg = fontCfgs[i];
+ String cfgFontUrl = null;
+ try {
+ cfgFontUrl = fontCfg.getAttribute("embed-url");
+ } catch (ConfigurationException e) {
+ try {
+ cfgFontUrl = fontCfg.getAttribute("metrics-url");
+ } catch (ConfigurationException e1) {
+ log.error(ConfigurationUtil.toString(fontCfg));
+ LogUtil.handleException(log, e, strictValidation);
+ continue;
+ }
+ }
+ if (fontUrl.equals(cfgFontUrl)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ // add to cache
+ DefaultConfiguration fontCfg = new DefaultConfiguration("font");
+ fontCfg.setAttribute("metrics-url", fontInfo.getMetricsFile());
+ fontCfg.setAttribute("embed-url", fontInfo.getEmbedFile());
+ fontCfg.setAttribute("kerning", String.valueOf(fontInfo
+ .getKerning()));
+ fontCfg.setAttribute("cached", cached);
+
+ // add associated font triplet list for this font info
+ List fontTriplets = fontInfo.getFontTriplets();
+ for (Iterator iter = fontTriplets.iterator(); iter.hasNext();) {
+ FontTriplet fontTriplet = (FontTriplet) iter.next();
+ DefaultConfiguration fontTripletCfg = new DefaultConfiguration(
+ "font-triplet");
+ fontTripletCfg.setAttribute("name", fontTriplet.getName());
+ fontTripletCfg
+ .setAttribute("style", fontTriplet.getStyle());
+ fontTripletCfg.setAttribute("weight", String
+ .valueOf(fontTriplet.getWeight()));
+ fontCfg.addChild(fontTripletCfg);
+ }
+ long lastModified = fontInfo.lastModified();
+ if (lastModified >= 0) {
+ fontCfg.setAttribute("modified", String
+ .valueOf(lastModified));
+ }
+ fontsCfg.addChild(fontCfg);
+ }
+ }
+ // remove old fonts parent node and add new one
+ cacheConfig.removeChild(origFontsCfg);
+ cacheConfig.addChild(fontsCfg);
+ }
+
+ /**
+ * Updates the failed font map from the font cache
+ *
+ * @param fontFailMap
+ * failed fonts map to serialize
+ * @throws FOPException
+ * fop exception
+ */
+ public void updateFailedFonts(Map fontFailMap) throws FOPException {
+ DefaultConfiguration cacheConfig = getConfiguration();
+ Configuration origFailed = cacheConfig.getChild("failed");
+ DefaultConfiguration failedFontsCfg = null;
+ try {
+ failedFontsCfg = new DefaultConfiguration(origFailed
+ .getChild("fonts"));
+ } catch (ConfigurationException e) {
+ // shouldn't happen
+ LogUtil.handleException(log, e, strictValidation);
+ }
+
+ // iterate over failed font map from font cache
+ // adding any new failed fonts to cache
+ long cached = System.currentTimeMillis();
+ for (Iterator it = fontFailMap.keySet().iterator(); it.hasNext();) {
+ String embedUrl = (String) it.next();
+ Configuration[] fontCfgs = failedFontsCfg.getChildren("font");
+ boolean found = false;
+ for (int i = 0; i < fontCfgs.length; i++) {
+ String cacheEmbedUrl = null;
+ try {
+ cacheEmbedUrl = fontCfgs[i].getAttribute("embed-url");
+ } catch (ConfigurationException e) {
+ // shouldn't happen
+ log.error(ConfigurationUtil.toString(fontCfgs[i]));
+ LogUtil.handleException(log, e, strictValidation);
+ }
+ if (cacheEmbedUrl.equals(embedUrl)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ // add to cache
+ long lastModified = ((Long) fontFailMap.get(embedUrl))
+ .longValue();
+ DefaultConfiguration fontCfg = new DefaultConfiguration("font");
+ fontCfg.setAttribute("embed-url", embedUrl);
+ fontCfg.setAttribute("modified", lastModified);
+ fontCfg.setAttribute("cached", cached);
+ failedFontsCfg.addChild(fontCfg);
+ }
+ }
+ // remove old failed fonts parent node and add new one
+ cacheConfig.removeChild(origFailed);
+ DefaultConfiguration failedCfg = new DefaultConfiguration("failed");
+ failedCfg.addChild(failedFontsCfg);
+ cacheConfig.addChild(failedCfg);
+ }
+
+ /**
+ * Serializes cache config to file
+ *
+ * @throws FOPException fop exception
+ */
+ public void write() throws FOPException {
+ // save font info/fail cache
+ try {
+ DefaultConfigurationSerializer cfgSerializer = new DefaultConfigurationSerializer();
+ cfgSerializer.serializeToFile(cache.getCacheFile(), getConfiguration());
+ } catch (Exception e) {
+ LogUtil.handleException(log, e, true);
+ }
+ }
+}
Index: src/java/org/apache/fop/apps/FOURIResolver.java
===================================================================
--- src/java/org/apache/fop/apps/FOURIResolver.java (revision 540059)
+++ src/java/org/apache/fop/apps/FOURIResolver.java (working copy)
@@ -29,6 +29,7 @@
import java.net.URLConnection;
import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
// commons logging
@@ -47,54 +48,63 @@
public class FOURIResolver
implements javax.xml.transform.URIResolver {
+ // log
private Log log = LogFactory.getLog("FOP");
+
+ // fop factory
+ private FopFactory factory = null;
+
+ /**
+ * default constructor
+ * @param factory fop factory
+ */
+ public FOURIResolver(FopFactory factory) {
+ this.factory = factory;
+ }
/**
- * Called by the processor through {@link FOUserAgent} when it encounters an
- * uri in an external-graphic element.
- * (see also {@link javax.xml.transform.URIResolver#resolve(String, String)}
- * This resolver will allow URLs without a scheme, i.e. it assumes 'file:' as
- * the default scheme. It also allows relative URLs with scheme,
- * e.g. file:../../abc.jpg which is not strictly RFC compliant as long as the
- * scheme is the same as the scheme of the base URL. If the base URL is null
- * a 'file:' URL referencing the current directory is used as the base URL.
- * If the method is successful it will return a Source of type
- * {@link javax.xml.transform.stream.StreamSource} with its SystemID set to
- * the resolved URL used to open the underlying InputStream.
- *
- * @param href An href attribute, which may be relative or absolute.
- * @param base The base URI against which the first argument will be made
- * absolute if the absolute URI is required.
- * @return A {@link javax.xml.transform.Source} object, or null if the href
- * cannot be resolved.
- * @throws javax.xml.transform.TransformerException Never thrown by this implementation.
- * @see javax.xml.transform.URIResolver#resolve(String, String)
+ * handles resolve exceptions appropriately
+ * @param errorStr error string
+ * @param strict strict user config
+ * @throws TransformerException
*/
- public Source resolve(String href, String base)
- throws javax.xml.transform.TransformerException {
-
- //data URLs can be quite long so don't try to build a File (can lead to problems)
+ private void handleException(Exception e, String errorStr, boolean strict)
+ throws TransformerException {
+ if (strict) {
+ throw new TransformerException(errorStr, e);
+ }
+ log.error(e.getMessage());
+ }
+
+ /**
+ * Attempts to return a URL from a given absolute reference
+ * @param href
+ * @param strict
+ * @return
+ * @throws MalformedURLException
+ */
+ public Source resolve(String href, String base) throws TransformerException {
+ // data URLs can be quite long so don't try to build a File (can lead to problems)
if (href.startsWith("data:")) {
return parseDataURI(href);
}
-
+
+ // strict user config
+ boolean strict = factory.validateUserConfigStrictly();
+
URL absoluteURL = null;
- File f = new File(href);
- if (f.exists()) {
+ File file = new File(href);
+ if (file.canRead() && file.isFile()) {
try {
- absoluteURL = f.toURL();
+ absoluteURL = file.toURL();
} catch (MalformedURLException mfue) {
- log.error("Could not convert filename to URL: " + mfue.getMessage());
+ handleException(mfue,
+ "Could not convert filename '" + href + "' to URL", strict);
}
} else {
- URL baseURL = null;
- try {
- baseURL = toBaseURL(base);
- } catch (MalformedURLException mfue) {
- log.error("Error with base URL \"" + base + "\"): " + mfue.getMessage());
- }
- if (baseURL == null) {
- // We don't have a valid baseURL just use the URL as given
+ // no base provided
+ if (base == null) {
+ // We don't have a valid file protocol based URL
try {
absoluteURL = new URL(href);
} catch (MalformedURLException mue) {
@@ -103,64 +113,78 @@
// the href contains only a path then file: is assumed
absoluteURL = new URL("file:" + href);
} catch (MalformedURLException mfue) {
- log.error("Error with URL '" + href + "': " + mue.getMessage());
- return null;
+ handleException(mfue,
+ "Error with URL '" + href + "'", strict);
}
}
+
+ // try and resolve from context of base
} else {
+ URL baseURL = null;
try {
- /*
- This piece of code is based on the following statement in
- RFC2396 section 5.2:
+ baseURL = new URL(base);
+ } catch (MalformedURLException mfue) {
+ handleException(mfue, "Error with base URL '" + base + "'", strict);
+ }
- 3) If the scheme component is defined, indicating that the reference
- starts with a scheme name, then the reference is interpreted as an
- absolute URI and we are done. Otherwise, the reference URI's
- scheme is inherited from the base URI's scheme component.
-
- Due to a loophole in prior specifications [RFC1630], some parsers
- allow the scheme name to be present in a relative URI if it is the
- same as the base URI scheme. Unfortunately, this can conflict
- with the correct parsing of non-hierarchical URI. For backwards
- compatibility, an implementation may work around such references
- by removing the scheme if it matches that of the base URI and the
- scheme is known to always use the syntax.
-
- The URL class does not implement this work around, so we do.
- */
-
- String scheme = baseURL.getProtocol() + ":";
- if (href.startsWith(scheme)) {
- href = href.substring(scheme.length());
- if ("file:".equals(scheme)) {
- int colonPos = href.indexOf(':');
- int slashPos = href.indexOf('/');
- if (slashPos >= 0 && colonPos >= 0 && colonPos < slashPos) {
- href = "/" + href; //Absolute file URL doesn't have a leading slash
- }
+ /*
+ * This piece of code is based on the following statement in
+ * RFC2396 section 5.2:
+ *
+ * 3) If the scheme component is defined, indicating that the
+ * reference starts with a scheme name, then the reference is
+ * interpreted as an absolute URI and we are done. Otherwise,
+ * the reference URI's scheme is inherited from the base URI's
+ * scheme component.
+ *
+ * Due to a loophole in prior specifications [RFC1630], some
+ * parsers allow the scheme name to be present in a relative URI
+ * if it is the same as the base URI scheme. Unfortunately, this
+ * can conflict with the correct parsing of non-hierarchical
+ * URI. For backwards compatibility, an implementation may work
+ * around such references by removing the scheme if it matches
+ * that of the base URI and the scheme is known to always use
+ * the syntax.
+ *
+ * The URL class does not implement this work around, so we do.
+ */
+ String scheme = baseURL.getProtocol() + ":";
+ if (href.startsWith(scheme)) {
+ href = href.substring(scheme.length());
+ if ("file:".equals(scheme)) {
+ int colonPos = href.indexOf(':');
+ int slashPos = href.indexOf('/');
+ if (slashPos >= 0 && colonPos >= 0 && colonPos < slashPos) {
+ href = "/" + href; // Absolute file URL doesn't
+ // have a leading slash
}
}
+ }
+ try {
absoluteURL = new URL(baseURL, href);
} catch (MalformedURLException mfue) {
- log.error("Error with URL '" + href + "': " + mfue.getMessage());
- return null;
+ handleException(mfue,
+ "Error with URL; base '" + base + "' " + "href '" + href + "'",
+ strict);
}
}
}
- String effURL = absoluteURL.toExternalForm();
- try {
- URLConnection connection = absoluteURL.openConnection();
- connection.setAllowUserInteraction(false);
- connection.setDoInput(true);
- updateURLConnection(connection, href);
- connection.connect();
- return new StreamSource(connection.getInputStream(), effURL);
- } catch (FileNotFoundException fnfe) {
- //Note: This is on "debug" level since the caller is supposed to handle this
- log.debug("File not found: " + effURL);
- } catch (java.io.IOException ioe) {
- log.error("Error with opening URL '" + effURL + "': " + ioe.getMessage());
+ if (absoluteURL != null) {
+ String effURL = absoluteURL.toExternalForm();
+ try {
+ URLConnection connection = absoluteURL.openConnection();
+ connection.setAllowUserInteraction(false);
+ connection.setDoInput(true);
+ updateURLConnection(connection, href);
+ connection.connect();
+ return new StreamSource(connection.getInputStream(), effURL);
+ } catch (FileNotFoundException fnfe) {
+ //Note: This is on "debug" level since the caller is supposed to handle this
+ log.debug("File not found: " + effURL);
+ } catch (java.io.IOException ioe) {
+ log.error("Error with opening URL '" + effURL + "': " + ioe.getMessage());
+ }
}
return null;
}
@@ -201,33 +225,10 @@
}
/**
- * Returns the base URL as a java.net.URL.
- * If the base URL is not set a default URL pointing to the
- * current directory is returned.
- * @param baseURL the base URL
- * @returns the base URL as java.net.URL
- */
- private URL toBaseURL(String base) throws MalformedURLException {
- if (base == null) {
- return new java.io.File("").toURL();
- }
- if (!base.endsWith("/")) {
- // The behavior described by RFC 3986 regarding resolution of relative
- // references may be misleading for normal users:
- // file://path/to/resources + myResource.res -> file://path/to/myResource.res
- // file://path/to/resources/ + myResource.res -> file://path/to/resources/myResource.res
- // We assume that even when the ending slash is missing, users have the second
- // example in mind
- base += "/";
- }
- return new URL(base);
- }
-
- /**
* Parses inline data URIs as generated by MS Word's XML export and FO stylesheet.
* @see RFC 2397
*/
- private Source parseDataURI(String href) {
+ private StreamSource parseDataURI(String href) {
int commaPos = href.indexOf(',');
// header is of the form data:[][;base64]
String header = href.substring(0, commaPos);
Index: src/java/org/apache/fop/apps/FopCache.java
===================================================================
--- src/java/org/apache/fop/apps/FopCache.java (revision 0)
+++ src/java/org/apache/fop/apps/FopCache.java (revision 0)
@@ -0,0 +1,279 @@
+/*
+ * 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.apps;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.fop.fonts.CachedFontInfo;
+import org.apache.fop.fonts.EmbedFontInfo;
+
+/**
+ * Fop cache (currently only used for font info caching)
+ */
+public final class FopCache {
+
+ /** font cache file path */
+ private static final String DEFAULT_CACHE_FILENAME = "fop.cache";
+
+ /** default conf directory */
+ private static final String CONF_DIR = "conf/";
+
+ /** cache file */
+ private File cacheFile = null;
+
+ /** has this cache been changed since it was last read? */
+ private boolean changed = false;
+
+ /** change lock */
+ private Object changeLock = new Object();
+
+ /** master mapping of font url -> font info */
+ private Map fontMap = null;
+
+ /** mapping of font url -> file modified date */
+ private Map failedFontMap = null;
+
+ /** private instance */
+ private static FopCache instance = null;
+
+ /**
+ * Default constructor
+ */
+ private FopCache() {
+ new FopCacheReader(this).read();
+ }
+
+ /**
+ * @return an instance of the cache manager
+ */
+ public static synchronized FopCache getInstance() {
+ if (instance == null) {
+ instance = new FopCache();
+ }
+ return instance;
+ }
+
+ /**
+ * sets the fonts
+ * @param fonts font map
+ */
+ protected void setFonts(Map fonts) {
+ this.fontMap = fonts;
+ }
+
+ /**
+ * sets the failed fonts
+ * @param failedFonts failed font map
+ */
+ protected void setFailedFonts(Map failedFonts) {
+ this.failedFontMap = failedFonts;
+ }
+
+ /**
+ * sets the cache file
+ *
+ * @param cacheFile
+ * cache file
+ */
+ public void setCacheFile(File cacheFile) {
+ this.cacheFile = cacheFile;
+ }
+
+ /**
+ * Sets the cache file
+ *
+ * @param cacheFile
+ * cache file path
+ */
+ public void setCacheFile(String cacheFile) {
+ setCacheFile(new File(cacheFile));
+ }
+
+ /**
+ * creates a key given a font info for the font mapping
+ * @param fontInfo font info
+ * @return font cache key
+ */
+ protected static String getCacheKey(EmbedFontInfo fontInfo) {
+ if (fontInfo != null) {
+ String embedFile = fontInfo.getEmbedFile();
+ String metricsFile = fontInfo.getMetricsFile();
+ return (embedFile != null) ? embedFile : metricsFile;
+ }
+ return null;
+ }
+
+ /**
+ * determines where cache file should be based upon configuration tries to
+ * use base dir first, then current working directory
+ *
+ * @return File cache File representation
+ */
+ protected File getCacheFile() {
+ if (cacheFile == null) {
+ // use current working directory
+ File confDir = new File(CONF_DIR);
+ if (confDir.isDirectory()) {
+ // / use conf dir underneath current working directory
+ cacheFile = new File(confDir, DEFAULT_CACHE_FILENAME);
+ } else {
+ // just use cache file in current working directory
+ cacheFile = new File(DEFAULT_CACHE_FILENAME);
+ }
+ }
+ return cacheFile;
+ }
+
+ /**
+ * Writes the cache to disk
+ * @throws FOPException fop exception
+ */
+ public void write() throws FOPException {
+ synchronized (changeLock) {
+ if (changed) {
+ new FopCacheWriter(this).write();
+ changed = false;
+ }
+ }
+ }
+
+ /**
+ * cache has been updated since it was read
+ * @return if this cache has changed
+ */
+ public boolean hasChanged() {
+ return this.changed;
+ }
+
+ /**
+ * is this font in the cache?
+ * @param embedUrl font info
+ * @return boolean
+ */
+ public boolean containsFont(String embedUrl) {
+ if (embedUrl != null) {
+ return fontMap.containsKey(embedUrl);
+ }
+ return false;
+ }
+
+ /**
+ * is this font info in the cache?
+ * @param fontInfo font info
+ * @return font
+ */
+ public boolean containsFont(EmbedFontInfo fontInfo) {
+ if (fontInfo != null) {
+ return fontMap.containsKey(getCacheKey(fontInfo));
+ }
+ return false;
+ }
+
+ /**
+ * adds a font info to cache
+ * @param fontInfo font info
+ */
+ public void addFont(EmbedFontInfo fontInfo) {
+ String cacheKey = getCacheKey(fontInfo);
+ synchronized (changeLock) {
+ if (!containsFont(cacheKey)) {
+ if (fontInfo instanceof CachedFontInfo) {
+ fontMap.put(cacheKey, fontInfo);
+ } else {
+ fontMap.put(cacheKey, new CachedFontInfo(fontInfo));
+ }
+ changed = true;
+ }
+ }
+ }
+
+ /**
+ * returns a font from the cache
+ * @param embedUrl font info
+ * @return boolean
+ */
+ public CachedFontInfo getFont(String embedUrl) {
+ if (containsFont(embedUrl)) {
+ return (CachedFontInfo)fontMap.get(embedUrl);
+ }
+ return null;
+ }
+
+ /**
+ * removes font from cache
+ * @param embedUrl embed url
+ */
+ public void removeFont(String embedUrl) {
+ synchronized (changeLock) {
+ if (containsFont(embedUrl)) {
+ fontMap.remove(embedUrl);
+ changed = true;
+ }
+ }
+ }
+
+ /**
+ * has this font previously failed to load?
+ * @param embedUrl embed url
+ * @param lastModified last modified
+ * @return whether this is a failed font
+ */
+ public boolean isFailedFont(String embedUrl, long lastModified) {
+ if (failedFontMap.containsKey(embedUrl)) {
+ synchronized (changeLock) {
+ long failedLastModified = ((Long)failedFontMap.get(embedUrl)).longValue();
+ if (lastModified != failedLastModified) {
+ // this font has been changed so lets remove it
+ // from failed font map for now
+ failedFontMap.remove(embedUrl);
+ changed = true;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * registers a failed font with the cache
+ * @param embedUrl embed url
+ * @param lastModified time last modified
+ */
+ public void registerFailedFont(String embedUrl, long lastModified) {
+ synchronized (changeLock) {
+ if (!failedFontMap.containsKey(embedUrl)) {
+ failedFontMap.put(embedUrl, new Long(lastModified));
+ changed = true;
+ }
+ }
+ }
+
+ /**
+ * clears font cache
+ */
+ public void clear() {
+ synchronized (changeLock) {
+ fontMap.clear();
+ failedFontMap.clear();
+ changed = true;
+ }
+ }
+}
Index: src/java/org/apache/fop/apps/FopCacheReader.java
===================================================================
--- src/java/org/apache/fop/apps/FopCacheReader.java (revision 0)
+++ src/java/org/apache/fop/apps/FopCacheReader.java (revision 0)
@@ -0,0 +1,210 @@
+/*
+ * 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.apps;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fonts.CachedFontInfo;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.fonts.FontUtil;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * Reads the fop cache from disk
+ */
+public class FopCacheReader extends FopCacheConfigurator {
+
+ /** log class */
+ private static Log log = LogFactory.getLog(FopCacheReader.class);
+
+ /**
+ * Default constructor
+ * @param cache fop cache
+ */
+ public FopCacheReader(FopCache cache) {
+ super(cache);
+ }
+
+ /**
+ * Adds to a font list from a font node Configuration definition
+ *
+ * @param fontCfg
+ * Configuration object (font node)
+ * @return font info
+ * @throws FOPException
+ * if something's wrong with the config data
+ */
+ public CachedFontInfo getFontInfoFromCache(Configuration fontCfg)
+ throws FOPException {
+ String metricsUrl = fontCfg.getAttribute("metrics-url", null);
+ String embedUrl = fontCfg.getAttribute("embed-url", null);
+ boolean useKerning = fontCfg.getAttributeAsBoolean("kerning", false);
+
+ long lastModified = -1;
+ try {
+ lastModified = fontCfg.getAttributeAsLong("modified");
+ } catch (ConfigurationException e1) {
+ // failed to get modified date
+ }
+
+ long cached = -1;
+ try {
+ cached = fontCfg.getAttributeAsLong("cached");
+ } catch (ConfigurationException e1) {
+ // failed to get cached date
+ }
+
+ Configuration[] triple = fontCfg.getChildren("font-triplet");
+ List tripleList = new java.util.ArrayList();
+ for (int j = 0; j < triple.length; j++) {
+ try {
+ String name = triple[j].getAttribute("name");
+ if (name == null) {
+ LogUtil.handleError(log, "font-triplet without name",
+ strictValidation);
+ continue;
+ }
+ String weightStr = triple[j].getAttribute("weight");
+ if (weightStr == null) {
+ LogUtil.handleError(log, "font-triplet without weight",
+ strictValidation);
+ continue;
+ }
+ int weight = FontUtil.parseCSS2FontWeight(weightStr);
+ String style = triple[j].getAttribute("style");
+ if (style == null) {
+ LogUtil.handleError(log, "font-triplet without style",
+ strictValidation);
+ continue;
+ }
+ tripleList.add(FontInfo.createFontKey(name, style, weight));
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strictValidation);
+ }
+ }
+ CachedFontInfo fontInfo = new CachedFontInfo(metricsUrl, useKerning,
+ tripleList, embedUrl, lastModified, cached);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Adding font " + fontInfo.getEmbedFile()
+ + ", metric file " + fontInfo.getMetricsFile());
+ for (int j = 0; j < tripleList.size(); ++j) {
+ FontTriplet triplet = (FontTriplet) tripleList.get(j);
+ log.debug("Font triplet " + triplet.getName() + ", "
+ + triplet.getStyle() + ", " + triplet.getWeight());
+ }
+ }
+ return fontInfo;
+ }
+
+ /**
+ * Returns font info map from cache file
+ *
+ * @return list of previously detected fonts
+ */
+ public Map getFonts() {
+ Map fontInfoMap = Collections.synchronizedMap(new java.util.HashMap());
+ Configuration cacheConfig;
+ try {
+ cacheConfig = getConfiguration();
+ } catch (FOPException e) {
+ log.error("Failed to get cache configuration :" + e.getMessage());
+ return Collections.synchronizedMap(new java.util.HashMap());
+ }
+ Configuration[] fontsCfg = cacheConfig.getChild("fonts").getChildren(
+ "font");
+ for (int numFontsCached = 0; numFontsCached < fontsCfg.length; numFontsCached++) {
+ Configuration fontCfg = fontsCfg[numFontsCached];
+ CachedFontInfo fontInfo = null;
+ try {
+ fontInfo = getFontInfoFromCache(fontCfg);
+ } catch (FOPException e) {
+ log.error("Error with parsing cache configuration: "
+ + e.getMessage());
+ continue;
+ }
+ String cacheKey = FopCache.getCacheKey(fontInfo);
+ URL embedUrl;
+ try {
+ embedUrl = new URL(cacheKey);
+ } catch (MalformedURLException e) {
+ log.error("Error with cache configuration url syntax '"
+ + cacheKey + "' : " + e.getMessage());
+ continue;
+ }
+ File fontFile = new File(embedUrl.toExternalForm());
+ if (fontFile.isFile()) {
+ // cache font info item is up to date and still reflects font
+ // file.
+ // it is valid we can keep it in the cache
+ if (fontInfo.lastModified() == fontFile.lastModified()) {
+ fontInfoMap.put(FopCache.getCacheKey(fontInfo), fontInfo);
+ }
+ }
+ }
+ return fontInfoMap;
+ }
+
+ /**
+ * @return Returns mapping of failed parsed/loaded fonts (embedUrl -> last modified date)
+ */
+ public Map getFailedFonts() {
+ Map fontFailMap = Collections.synchronizedMap(new java.util.HashMap());
+ Configuration cacheConfig;
+ try {
+ cacheConfig = getConfiguration();
+ } catch (FOPException e) {
+ log.error("Failed to get cache configuration :" + e.getMessage());
+ return Collections.synchronizedMap(new java.util.HashMap());
+ }
+ Configuration[] fontsCfg = cacheConfig.getChild("failed").getChild(
+ "fonts").getChildren("font");
+ for (int numFailedFonts = 0; numFailedFonts < fontsCfg.length; numFailedFonts++) {
+ Configuration fontCfg = fontsCfg[numFailedFonts];
+ String fontUrl = fontCfg.getAttribute("embed-url", null);
+ long lastModified = -1;
+ try {
+ lastModified = fontCfg.getAttributeAsLong("modified");
+ } catch (ConfigurationException e1) {
+ // failed to get modified date
+ }
+ fontFailMap.put(fontUrl, new Long(lastModified));
+ }
+ return fontFailMap;
+ }
+
+ /**
+ * Reads the fop cache from disk
+ */
+ public void read() {
+ cache.setFonts(getFonts());
+ cache.setFailedFonts(getFailedFonts());
+ }
+}
\ No newline at end of file
Index: src/java/org/apache/fop/apps/FopCacheConfigurator.java
===================================================================
--- src/java/org/apache/fop/apps/FopCacheConfigurator.java (revision 0)
+++ src/java/org/apache/fop/apps/FopCacheConfigurator.java (revision 0)
@@ -0,0 +1,91 @@
+/*
+ * 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.apps;
+
+import java.io.File;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * Base class for accessing avalon configuration
+ */
+public class FopCacheConfigurator {
+
+ /** log class */
+ private static Log log = LogFactory.getLog(FopCacheConfigurator.class);
+
+ /** font cache name */
+ private static final String CACHE_NAME = "fop-cache";
+
+ /**
+ * our cache instance
+ */
+ protected FopCache cache;
+
+ /**
+ * strict validation off
+ */
+ protected boolean strictValidation = false;
+
+ /**
+ * Default constructor
+ * @param cache fop cache
+ */
+ public FopCacheConfigurator(FopCache cache) {
+ this.cache = cache;
+ }
+
+ /**
+ * Builds or returns the font cache config
+ *
+ * @return Configuration configuration
+ * @throws FOPException fop exception
+ */
+ protected DefaultConfiguration getConfiguration() throws FOPException {
+ DefaultConfiguration cacheConfig = null;
+ File cacheFile = cache.getCacheFile();
+ if (!cacheFile.exists()) {
+ cacheConfig = new DefaultConfiguration(CACHE_NAME, cacheFile
+ .getAbsolutePath());
+ cacheConfig.setAttribute("version", "1.0");
+ } else {
+ try {
+ if (!(cacheFile.canRead() || cacheFile.canWrite())) {
+ throw new FOPException("Unable to read/write configuration file: " + cacheFile );
+ }
+ DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+ cacheConfig = new DefaultConfiguration(cfgBuilder.buildFromFile(cacheFile));
+ } catch (Exception e) {
+ throw new FOPException(e);
+ }
+ }
+ if (cacheConfig == null) {
+ LogUtil.handleError(log,
+ "failed to create or access fop cache file '"
+ + cacheFile.getAbsolutePath() + "'",
+ strictValidation);
+ }
+ return cacheConfig;
+ }
+}
Index: src/java/org/apache/fop/apps/FopFactory.java
===================================================================
--- src/java/org/apache/fop/apps/FopFactory.java (revision 540059)
+++ src/java/org/apache/fop/apps/FopFactory.java (working copy)
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -39,8 +40,6 @@
import org.xml.sax.SAXException;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -62,27 +61,6 @@
*/
public class FopFactory {
- /** Defines the default target resolution (72dpi) for FOP */
- public static final float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi
-
- /** Defines the default source resolution (72dpi) for FOP */
- private static final float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi
-
- /** Defines the default page-height */
- private static final String DEFAULT_PAGE_HEIGHT = "11in";
-
- /** Defines the default page-width */
- private static final String DEFAULT_PAGE_WIDTH = "8.26in";
-
- /** Defines if FOP should use strict validation for FO and user config */
- private static final boolean DEFAULT_STRICT_FO_VALIDATION = true;
-
- /** Defines if FOP should validate the user config strictly */
- private static final boolean DEFAULT_STRICT_USERCONFIG_VALIDATION = true;
-
- /** Defines if FOP should use an alternative rule to determine text indents */
- private static final boolean DEFAULT_BREAK_INDENT_INHERITANCE = false;
-
/** logger instance */
private static Log log = LogFactory.getLog(FopFactory.class);
@@ -100,7 +78,7 @@
= new ContentHandlerFactoryRegistry();
/** Our default resolver if none is set */
- private URIResolver foURIResolver = new FOURIResolver();
+ private URIResolver foURIResolver = null;
/** A user settable URI Resolver */
private URIResolver uriResolver = null;
@@ -108,22 +86,23 @@
/** The resolver for user-supplied hyphenation patterns */
private HyphenationTreeResolver hyphResolver;
+ /** Image factory for creating fop image objects */
private ImageFactory imageFactory = new ImageFactory();
- /** user configuration */
- private Configuration userConfig = null;
-
+ /** Configuration layer used to configure fop */
+ private FopFactoryConfigurator config = null;
+
/**
* The base URL for all URL resolutions, especially for
* external-graphics.
*/
- private String baseURL;
+ private String base = null;
/** The base URL for all font URL resolutions. */
- private String fontBaseURL;
+ private String fontBase = null;
/** The base URL for all hyphen URL resolutions. */
- private String hyphenBaseURL;
+ private String hyphenBase = null;
/**
* FOP has the ability, for some FO's, to continue processing even if the
@@ -131,32 +110,36 @@
* behavior for FOP. However, this flag, if set, provides the user the
* ability for FOP to halt on all content model violations if desired.
*/
- private boolean strictFOValidation = DEFAULT_STRICT_FO_VALIDATION;
+ private boolean strictFOValidation = FopFactoryConfigurator.DEFAULT_STRICT_FO_VALIDATION;
/**
* FOP will validate the contents of the user configuration strictly
* (e.g. base-urls and font urls/paths).
*/
- private boolean strictUserConfigValidation = DEFAULT_STRICT_USERCONFIG_VALIDATION;
-
+ private boolean strictUserConfigValidation
+ = FopFactoryConfigurator.DEFAULT_STRICT_USERCONFIG_VALIDATION;
+
+ /** Cache font info/font file triplet detection */
+ private boolean useCache = FopFactoryConfigurator.DEFAULT_USE_CACHE;
+
/** Allows enabling kerning on the base 14 fonts, default is false */
private boolean enableBase14Kerning = false;
/** Source resolution in dpi */
- private float sourceResolution = DEFAULT_SOURCE_RESOLUTION;
+ private float sourceResolution = FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION;
/** Target resolution in dpi */
- private float targetResolution = DEFAULT_TARGET_RESOLUTION;
+ private float targetResolution = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
/** Page height */
- private String pageHeight = DEFAULT_PAGE_HEIGHT;
+ private String pageHeight = FopFactoryConfigurator.DEFAULT_PAGE_HEIGHT;
/** Page width */
- private String pageWidth = DEFAULT_PAGE_WIDTH;
+ private String pageWidth = FopFactoryConfigurator.DEFAULT_PAGE_WIDTH;
/** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
private boolean breakIndentInheritanceOnReferenceAreaBoundary
- = DEFAULT_BREAK_INDENT_INHERITANCE;
+ = FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE;
/** Optional overriding LayoutManagerMaker */
private LayoutManagerMaker lmMakerOverride = null;
@@ -165,12 +148,14 @@
/** Map with cached ICC based ColorSpace objects. */
private Map colorSpaceMap = null;
-
+
/**
* Main constructor.
*/
protected FopFactory() {
+ this.config = new FopFactoryConfigurator(this);
this.elementMappingRegistry = new ElementMappingRegistry(this);
+ this.foURIResolver = new FOURIResolver(this);
// Use a synchronized Map - I am not really sure this is needed, but better safe than sorry.
this.colorSpaceMap = Collections.synchronizedMap(new java.util.HashMap());
}
@@ -336,11 +321,42 @@
}
/**
+ * cleans the base url
+ * @param base
+ * @return
+ * @throws MalformedURLException
+ * @throws URISyntaxException
+ */
+ private String checkBaseURL(String base) throws MalformedURLException {
+ if (!base.endsWith("/")) {
+ // The behavior described by RFC 3986 regarding resolution of relative
+ // references may be misleading for normal users:
+ // file://path/to/resources + myResource.res -> file://path/to/myResource.res
+ // file://path/to/resources/ + myResource.res -> file://path/to/resources/myResource.res
+ // We assume that even when the ending slash is missing, users have the second
+ // example in mind
+ base += "/";
+ }
+ File dir = new File(base);
+ try {
+ base = (dir.isDirectory() ? dir.toURL() : new URL(base)).toExternalForm();
+ } catch (MalformedURLException mfue) {
+ if (strictUserConfigValidation) {
+ throw mfue;
+ }
+ log.error(mfue.getMessage());
+ }
+ return base;
+ }
+
+ /**
* Sets the base URL.
- * @param baseURL base URL
+ * @param base base URL
+ * @throws MalformedURLException
+ * @throws URISyntaxException
*/
- void setBaseURL(String baseURL) {
- this.baseURL = baseURL;
+ public void setBaseURL(String base) throws MalformedURLException {
+ this.base = checkBaseURL(base);
}
/**
@@ -348,42 +364,46 @@
* @return the base URL
*/
public String getBaseURL() {
- return this.baseURL;
+ return this.base;
}
-
+
/**
* Sets the font base URL.
- * @param fontBaseURL font base URL
+ * @param fontBase font base URL
+ * @throws MalformedURLException
+ * @throws URISyntaxException
*/
- public void setFontBaseURL(String fontBaseURL) {
- this.fontBaseURL = fontBaseURL;
+ public void setFontBaseURL(String fontBase) throws MalformedURLException {
+ this.fontBase = checkBaseURL(fontBase);
}
/** @return the font base URL */
public String getFontBaseURL() {
- return this.fontBaseURL;
+ return this.fontBase;
}
/** @return the hyphen base URL */
public String getHyphenBaseURL() {
- return hyphenBaseURL;
+ return this.hyphenBase;
}
/**
* Sets the hyphen base URL.
- * @param hyphenBaseURL hythen base URL
- */
- public void setHyphenBaseURL(final String hyphenBaseURL) {
- if (hyphenBaseURL != null) {
+ * @param hyphenBase hythen base URL
+ * @throws MalformedURLException
+ * @throws URISyntaxException
+ * */
+ public void setHyphenBaseURL(final String hyphenBase) throws MalformedURLException {
+ if (hyphenBase != null) {
this.hyphResolver = new HyphenationTreeResolver() {
public Source resolve(String href) {
- return resolveURI(href, hyphenBaseURL);
+ return resolveURI(href, hyphenBase);
}
};
}
- this.hyphenBaseURL = hyphenBaseURL;
+ this.hyphenBase = checkBaseURL(hyphenBase);
}
-
+
/**
* Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
* patterns and as backup for URI resolution performed during a rendering run.
@@ -483,8 +503,6 @@
*/
public void setSourceResolution(float dpi) {
this.sourceResolution = dpi;
- log.info("source-resolution set to: " + sourceResolution
- + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
}
/** @return the resolution for resolution-dependant output */
@@ -538,7 +556,6 @@
*/
public void setPageHeight(String pageHeight) {
this.pageHeight = pageHeight;
- log.info("Default page-height set to: " + pageHeight);
}
/**
@@ -559,7 +576,6 @@
*/
public void setPageWidth(String pageWidth) {
this.pageWidth = pageWidth;
- log.info("Default page-width set to: " + pageWidth);
}
/**
@@ -595,7 +611,7 @@
public Set getIgnoredNamespace() {
return Collections.unmodifiableSet(this.ignoredNamespaces);
}
-
+
//------------------------------------------- Configuration stuff
/**
@@ -605,14 +621,9 @@
* @throws SAXException if a parsing error occurs
*/
public void setUserConfig(File userConfigFile) throws SAXException, IOException {
- try {
- DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
- setUserConfig(cfgBuilder.buildFromFile(userConfigFile));
- } catch (ConfigurationException e) {
- throw new FOPException(e);
- }
+ config.setUserConfig(userConfigFile);
}
-
+
/**
* Set the user configuration from an URI.
* @param uri the URI to the configuration file
@@ -620,12 +631,7 @@
* @throws SAXException if a parsing error occurs
*/
public void setUserConfig(String uri) throws SAXException, IOException {
- try {
- DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
- setUserConfig(cfgBuilder.build(uri));
- } catch (ConfigurationException e) {
- throw new FOPException(e);
- }
+ config.setUserConfig(uri);
}
/**
@@ -634,12 +640,7 @@
* @throws FOPException if a configuration problem occurs
*/
public void setUserConfig(Configuration userConfig) throws FOPException {
- this.userConfig = userConfig;
- try {
- configure(userConfig);
- } catch (ConfigurationException e) {
- throw new FOPException(e);
- }
+ config.setUserConfig(userConfig);
}
/**
@@ -647,160 +648,41 @@
* @return the user configuration
*/
public Configuration getUserConfig() {
- return userConfig;
+ return config.getUserConfig();
}
/**
- * Returns the configuration subtree for a specific renderer.
- * @param mimeType MIME type of the renderer
- * @return the requested configuration subtree, null if there's no configuration
+ * Is the user configuration to be validated?
+ * @param strictUserConfigValidation strict user config validation
*/
- public Configuration getUserRendererConfig(String mimeType) {
- if (userConfig == null || mimeType == null) {
- return null;
- }
-
- Configuration userRendererConfig = null;
-
- Configuration[] cfgs
- = userConfig.getChild("renderers").getChildren("renderer");
- for (int i = 0; i < cfgs.length; ++i) {
- Configuration child = cfgs[i];
- try {
- if (child.getAttribute("mime").equals(mimeType)) {
- userRendererConfig = child;
- break;
- }
- } catch (ConfigurationException e) {
- // silently pass over configurations without mime type
- }
- }
- log.debug((userRendererConfig == null ? "No u" : "U")
- + "ser configuration found for MIME type " + mimeType);
- return userRendererConfig;
+ public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
+ this.strictUserConfigValidation = strictUserConfigValidation;
}
/**
- * Initializes user agent settings from the user configuration
- * file, if present: baseURL, resolution, default page size,...
- *
- * @throws ConfigurationException when there is an entry that
- * misses the required attribute
- * Configures the FopFactory.
- * @param cfg Avalon Configuration Object
- * @see org.apache.avalon.framework.configuration.Configurable
+ * Is the user configuration to be validated?
+ * @return if the user configuration should be validated
*/
- public void configure(Configuration cfg) throws ConfigurationException {
- log.info("Initializing FopFactory Configuration");
-
- if (cfg.getChild("strict-configuration", false) != null) {
- this.strictUserConfigValidation
- = cfg.getChild("strict-configuration").getValueAsBoolean();
- }
- if (cfg.getChild("strict-validation", false) != null) {
- this.strictFOValidation = cfg.getChild("strict-validation").getValueAsBoolean();
- }
- if (cfg.getChild("base", false) != null) {
- try {
- setBaseURL(getBaseURLfromConfig(cfg, "base"));
- } catch (ConfigurationException e) {
- if (strictUserConfigValidation) {
- throw e;
- }
- log.error(e.getMessage());
- }
- }
- if (cfg.getChild("font-base", false) != null) {
- try {
- setFontBaseURL(getBaseURLfromConfig(cfg, "font-base"));
- } catch (ConfigurationException e) {
- if (strictUserConfigValidation) {
- throw e;
- }
- log.error(e.getMessage());
- }
- }
- if (cfg.getChild("hyphenation-base", false) != null) {
- try {
- setHyphenBaseURL(getBaseURLfromConfig(cfg, "hyphenation-base"));
- } catch (ConfigurationException e) {
- if (strictUserConfigValidation) {
- throw e;
- }
- log.error(e.getMessage());
- }
- }
- if (cfg.getChild("source-resolution", false) != null) {
- setSourceResolution(
- cfg.getChild("source-resolution").getValueAsFloat(DEFAULT_SOURCE_RESOLUTION));
- }
- if (cfg.getChild("target-resolution", false) != null) {
- setTargetResolution(
- cfg.getChild("target-resolution").getValueAsFloat(DEFAULT_TARGET_RESOLUTION));
- }
- if (cfg.getChild("break-indent-inheritance", false) != null) {
- setBreakIndentInheritanceOnReferenceAreaBoundary(
- cfg.getChild("break-indent-inheritance").getValueAsBoolean());
- }
- Configuration pageConfig = cfg.getChild("default-page-settings");
- if (pageConfig.getAttribute("height", null) != null) {
- setPageHeight(pageConfig.getAttribute("height", DEFAULT_PAGE_HEIGHT));
- }
- if (pageConfig.getAttribute("width", null) != null) {
- setPageWidth(pageConfig.getAttribute("width", DEFAULT_PAGE_WIDTH));
- }
+ public boolean validateUserConfigStrictly() {
+ return this.strictUserConfigValidation;
}
- /**
- * Retrieves and verifies a base URL.
- * @param cfg The Configuration object to retrieve the base URL from
- * @param name the element name for the base URL
- * @return the requested base URL or null if not available
- * @throws ConfigurationException
- */
- public static String getBaseURLfromConfig(Configuration cfg, String name)
- throws ConfigurationException {
- if (cfg.getChild(name, false) != null) {
- try {
- String cfgBasePath = cfg.getChild(name).getValue(null);
- if (cfgBasePath != null) {
- // Is the path a dirname?
- File dir = new File(cfgBasePath);
-// if (!dir.exists()) {
-// throw new ConfigurationException("Base URL '" + name
-// + "' references non-existent resource '"
-// + cfgBasePath + "'");
-// } else if (dir.isDirectory()) {
- if (dir.isDirectory()) {
- // Yes, convert it into a URL
- cfgBasePath = dir.toURL().toExternalForm();
- }
- // Otherwise, this is already a URL
- }
- log.info(name + " set to: " + cfgBasePath);
- return cfgBasePath;
- } catch (MalformedURLException mue) {
- throw new ConfigurationException("Base URL '" + name
- + "' in user config is malformed!");
- }
- }
- return null;
- }
+ //------------------------------------------- Cache related stuff
/**
- * Is the user configuration to be validated?
- * @param strictUserConfigValidation strict user config validation
+ * Whether or not to cache results of font triplet detection/auto-config
+ * @param useCache use cache or not
*/
- public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
- this.strictUserConfigValidation = strictUserConfigValidation;
+ public void setUseCache(boolean useCache) {
+ this.useCache = useCache;
}
/**
- * Is the user configuration to be validated?
- * @return if the user configuration should be validated
+ * Cache results of font triplet detection/auto-config?
+ * @return whether this factory is uses the cache
*/
- public boolean validateUserConfigStrictly() {
- return this.strictUserConfigValidation;
+ public boolean useCache() {
+ return this.useCache;
}
//------------------------------------------- URI resolution
@@ -810,26 +692,29 @@
* Will use the configured resolver and if not successful fall back
* to the default resolver.
* @param uri URI to access
- * @param base the base URI to resolve against
+ * @param baseUri the base URI to resolve against
* @return A {@link javax.xml.transform.Source} object, or null if the URI
* cannot be resolved.
* @see org.apache.fop.apps.FOURIResolver
*/
- public Source resolveURI(String uri, String base) {
+ public Source resolveURI(String uri, String baseUri) {
Source source = null;
//RFC 2397 data URLs don't need to be resolved, just decode them.
boolean bypassURIResolution = uri.startsWith("data:");
if (!bypassURIResolution && uriResolver != null) {
try {
- source = uriResolver.resolve(uri, base);
+ source = uriResolver.resolve(uri, baseUri);
} catch (TransformerException te) {
log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
+ if (validateUserConfigStrictly()) {
+ return null;
+ }
}
}
if (source == null) {
// URI Resolver not configured or returned null, use default resolver
try {
- source = foURIResolver.resolve(uri, base);
+ source = foURIResolver.resolve(uri, baseUri);
} catch (TransformerException te) {
log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
}
@@ -846,18 +731,18 @@
* The FOP URI resolver is used to try and locate the ICC file.
* If that fails null is returned.
*
- * @param base a base URI to resolve relative URIs
+ * @param baseUri a base URI to resolve relative URIs
* @param iccProfileSrc ICC Profile source to return a ColorSpace for
* @return ICC ColorSpace object or null if ColorSpace could not be created
*/
- public ColorSpace getColorSpace(String base, String iccProfileSrc) {
+ public ColorSpace getColorSpace(String baseUri, String iccProfileSrc) {
ColorSpace colorSpace = null;
- if (!this.colorSpaceMap.containsKey(base + iccProfileSrc)) {
+ if (!this.colorSpaceMap.containsKey(baseUri + iccProfileSrc)) {
try {
ICC_Profile iccProfile = null;
// First attempt to use the FOP URI resolver to locate the ICC
// profile
- Source src = this.resolveURI(iccProfileSrc, base);
+ Source src = this.resolveURI(iccProfileSrc, baseUri);
if (src != null && src instanceof StreamSource) {
// FOP URI resolver found ICC profile - create ICC profile
// from the Source
@@ -882,16 +767,16 @@
if (colorSpace != null) {
// Put in cache (not when VM resolved it as we can't control
- this.colorSpaceMap.put(base + iccProfileSrc, colorSpace);
+ this.colorSpaceMap.put(baseUri + iccProfileSrc, colorSpace);
} else {
// TODO To avoid an excessive amount of warnings perhaps
// register a null ColorMap in the colorSpaceMap
log.warn("Color profile '" + iccProfileSrc + "' not found.");
}
} else {
- colorSpace = (ColorSpace) this.colorSpaceMap.get(base
+ colorSpace = (ColorSpace) this.colorSpaceMap.get(baseUri
+ iccProfileSrc);
}
return colorSpace;
- }
-}
+ }
+}
\ No newline at end of file
Index: src/java/org/apache/fop/cli/CommandLineOptions.java
===================================================================
--- src/java/org/apache/fop/cli/CommandLineOptions.java (revision 540059)
+++ src/java/org/apache/fop/cli/CommandLineOptions.java (working copy)
@@ -32,6 +32,7 @@
import org.apache.fop.Version;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopCache;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.pdf.PDFAMode;
@@ -78,6 +79,8 @@
private Boolean suppressLowLevelAreas = Boolean.FALSE;
/* user configuration file */
private File userConfigFile = null;
+ /* cache file */
+ private File cacheFile = null;
/* input fo file */
private File fofile = null;
/* xsltfile (xslt transformation as input) */
@@ -143,8 +146,8 @@
dumpConfiguration();
}
checkSettings();
- createUserConfig();
-
+ setUserConfig();
+ setCacheFile();
//Factory config is set up, now we can create the user agent
foUserAgent = factory.newFOUserAgent();
foUserAgent.getRendererOptions().putAll(renderingOptions);
@@ -229,6 +232,8 @@
showConfiguration = Boolean.TRUE;
} else if (args[i].equals("-c")) {
i = i + parseConfigurationOption(args, i);
+ } else if (args[i].equals("-cache")) {
+ i = i + parseCacheOption(args, i);
} else if (args[i].equals("-l")) {
i = i + parseLanguageOption(args, i);
} else if (args[i].equals("-s")) {
@@ -333,6 +338,17 @@
}
}
+ private int parseCacheOption(String[] args, int i) throws FOPException {
+ if ((i + 1 == args.length)
+ || (args[i + 1].charAt(0) == '-')) {
+ throw new FOPException("if you use '-cache', you must specify "
+ + "the name of the cache file");
+ } else {
+ cacheFile = new File(args[i + 1]);
+ return 1;
+ }
+ }
+
private int parseLanguageOption(String[] args, int i) throws FOPException {
if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) {
@@ -772,11 +788,11 @@
} // end checkSettings
/**
- * Create the user configuration.
+ * Set the user configuration.
* @throws FOPException if creating the user configuration fails
* @throws IOException
*/
- private void createUserConfig() throws FOPException, IOException {
+ private void setUserConfig() throws FOPException, IOException {
if (userConfigFile == null) {
return;
}
@@ -788,6 +804,18 @@
}
/**
+ * Create the cache.
+ * @throws FOPException if creating the cache fails
+ * @throws IOException
+ */
+ private void setCacheFile() throws FOPException, IOException {
+ if (cacheFile == null) {
+ return;
+ }
+ FopCache.getInstance().setCacheFile(cacheFile);
+ }
+
+ /**
* @return the chosen output format (MIME type)
* @throws FOPException for invalid output formats
*/
@@ -914,7 +942,8 @@
+ " -noedit PDF file will be encrypted without edit content permission\n"
+ " -noannotations PDF file will be encrypted without edit annotation permission\n"
+ " -pdfprofile prof PDF file will be generated with the specified profile\n"
- + " (Examples for prof: PDF/A-1b or PDF/X-3:2003)\n\n"
+ + " (Examples for prof: PDF/A-1b or PDF/X-3:2003)\n"
+ + " -cache xx.xconf use fop cache file xx.xconf (when cache-fonts set)\n\n"
+ " [INPUT] \n"
+ " infile xsl:fo input file (the same as the next) \n"
+ " -fo infile xsl:fo input file \n"
Index: src/java/org/apache/fop/area/AreaTreeParser.java
===================================================================
--- src/java/org/apache/fop/area/AreaTreeParser.java (revision 540059)
+++ src/java/org/apache/fop/area/AreaTreeParser.java (working copy)
@@ -1060,7 +1060,7 @@
if (fontName != null) {
String fontStyle = attributes.getValue("font-style");
int fontWeight = getAttributeAsInteger(
- attributes, "font-weight", Font.NORMAL);
+ attributes, "font-weight", Font.WEIGHT_NORMAL);
area.addTrait(trait,
FontInfo.createFontKey(fontName, fontStyle, fontWeight));
}
Index: src/java/org/apache/fop/pdf/PDFFilterList.java
===================================================================
--- src/java/org/apache/fop/pdf/PDFFilterList.java (revision 540059)
+++ src/java/org/apache/fop/pdf/PDFFilterList.java (working copy)
@@ -24,14 +24,6 @@
import java.util.List;
import java.util.Map;
-// commons logging
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-// Avalon
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
/**
* This class represents a list of PDF filters to be applied when serializing
* the output of a PDF object.
@@ -56,13 +48,8 @@
private List filters = new java.util.ArrayList();
private boolean ignoreASCIIFilters = false;
-
+
/**
- * logging instance
- */
- protected static Log logger = LogFactory.getLog("org.apache.fop.render");
-
- /**
* Default constructor.
*
* The flag for ignoring ASCII filters defaults to false.
@@ -290,53 +277,4 @@
}
return out;
}
-
- /**
- * Builds a filter map from an Avalon Configuration object.
- * @param cfg the Configuration object
- * @return Map the newly built filter map
- * @throws ConfigurationException if a filter list is defined twice
- */
- public static Map buildFilterMapFromConfiguration(Configuration cfg)
- throws ConfigurationException {
- Map filterMap = new java.util.HashMap();
- Configuration[] filterLists = cfg.getChildren("filterList");
- for (int i = 0; i < filterLists.length; i++) {
- Configuration filters = filterLists[i];
- String type = filters.getAttribute("type", null);
- Configuration[] filt = filters.getChildren("value");
- List filterList = new java.util.ArrayList();
- for (int j = 0; j < filt.length; j++) {
- String name = filt[j].getValue();
- filterList.add(name);
- }
-
- if (type == null) {
- type = PDFFilterList.DEFAULT_FILTER;
- }
-
- if (!filterList.isEmpty() && logger.isDebugEnabled()) {
- StringBuffer debug = new StringBuffer("Adding PDF filter");
- if (filterList.size() != 1) {
- debug.append("s");
- }
- debug.append(" for type ").append(type).append(": ");
- for (int j = 0; j < filterList.size(); j++) {
- if (j != 0) {
- debug.append(", ");
- }
- debug.append(filterList.get(j));
- }
- logger.debug(debug.toString());
- }
-
- if (filterMap.get(type) != null) {
- throw new ConfigurationException("A filterList of type '"
- + type + "' has already been defined");
- }
- filterMap.put(type, filterList);
- }
- return filterMap;
- }
-
}
Index: src/java/org/apache/fop/util/LogUtil.java
===================================================================
--- src/java/org/apache/fop/util/LogUtil.java (revision 0)
+++ src/java/org/apache/fop/util/LogUtil.java (revision 0)
@@ -0,0 +1,57 @@
+/*
+ * 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.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.fop.apps.FOPException;
+
+/**
+ * Convenience Logging utility methods used in FOP
+ */
+public class LogUtil {
+
+ /**
+ * Convenience method that handles any error appropriately
+ * @param log log
+ * @param errorStr error string
+ * @param strict validate strictly
+ * @throws FOPException fop exception
+ */
+ public static void handleError(Log log, String errorStr, boolean strict) throws FOPException {
+ handleException(log, new FOPException(errorStr), strict);
+ }
+
+ /**
+ * Convenience method that handles any error appropriately
+ * @param log log
+ * @param e exception
+ * @param strict validate strictly
+ * @throws FOPException fop exception
+ */
+ public static void handleException(Log log, Exception e, boolean strict) throws FOPException {
+ if (strict) {
+ if (e instanceof FOPException) {
+ throw (FOPException)e;
+ }
+ throw new FOPException(e);
+ }
+ log.error(e.getMessage());
+ }
+}
Property changes on: src/java/org/apache/fop/util/LogUtil.java
___________________________________________________________________
Name: svn:eol-style
+ native
Index: src/documentation/content/xdocs/trunk/fonts.xml
===================================================================
--- src/documentation/content/xdocs/trunk/fonts.xml (revision 540059)
+++ src/documentation/content/xdocs/trunk/fonts.xml (working copy)
@@ -24,6 +24,7 @@
+
@@ -129,8 +130,7 @@
More information about fonts can be found at:
Type 1 Font Metrics
@@ -236,10 +236,24 @@
Register Fonts with FOP
You must tell FOP how to find and use the font metrics files by registering them in the FOP Configuration. Add entries for your custom fonts, regardless of font type, to the configuration file in a manner similar to the following:
-
+
+
+
+
+ C:\MyFonts1
+
+
+ C:\MyFonts2
+
+
+
+]]>
Review the documentation for FOP Configuration for instructions on making the FOP configuration available to FOP when it runs. Otherwise, FOP has no way of finding your custom font information.
@@ -247,8 +261,14 @@
Relative URLs are resolved relative to the font-base property (or base) if available.
See FOP: Configuration for more information.
-
The "kerning" and "embed-url" attributes are optional. Kerning is currently not used at all. If embedding is off, the output will position the text correctly (from the metrics file), but it will not be displayed or printed correctly unless the viewer has the applicable font available to their local system.
-
When setting the embed-url attribute for Type 1 fonts, be sure to specify the PFB (actual font data), not PFM (font metrics) file that you used to generate the XML font metrics file.
+
Either an "embed-url" or a "metrics-url" must be specified for font tag configurations.
+
The font "kerning" attribute is optional. Kerning is currently not used at all.
+
If embedding is off, the output will position the text correctly (from the metrics file), but it will not be displayed or printed correctly unless the viewer has the applicable font available to their local system.
+
When setting the "embed-url" attribute for Type 1 fonts, be sure to specify the PFB (actual font data), not PFM (font metrics) file that you used to generate the XML font metrics file.
+
The fonts "directory" tag can be used to register fonts contained within a single or list of directory paths. The "recursive" attribute can be specified to recursively add fonts from all sub directories.
+
The fonts "auto-detect" tag can be used to automatically register fonts that are found to be installed on the native operating system.
+
Fonts registered with "font" tag configurations override fonts found by means of "directory" tag definitions.
+
Fonts found as a result of a "directory" tag configuration override fonts found as a result of the "auto-detect" tag being specified.
If relative URLs are specified, they are evaluated relative to the value of the
"font-base" setting. If there is no "font-base" setting, the fonts are evaluated
@@ -281,7 +301,7 @@
See Table of TTF Encoding Options for more details.
- Explicitely embedding the base 14 fonts
+ Explicitly embedding the base 14 fonts
There are cases where you might want to force the embedding of one or more of the base 14 fonts that
can normally be considered available on the target platform (viewer, printer). One of these cases is
Index: src/documentation/content/xdocs/trunk/configuration.xml
===================================================================
--- src/documentation/content/xdocs/trunk/configuration.xml (revision 540059)
+++ src/documentation/content/xdocs/trunk/configuration.xml (working copy)
@@ -152,6 +152,24 @@
"height" 11 inches, "width" 8.26 inches
+
use-cache
+
boolean (true, false)
+
All fonts information that has been gathered as a result of "directory"
+ or "auto-detect" font configurations will be cached for future rendering runs.
+ This setting should improve performance on systems where
+ fonts have been configured using the "directory" or "auto-detect" tag mechanisms.
+ By default this option is switched on.
+
true
+
+
+
cache-file
+
String
+
This options specifies the file/directory path of the fop cache file.
+ This option can also be specified on the command-line using the -cache option.
+ This file is currently only used to cache font triplet information for future reference.
+
${base}/conf/fop.cache
+
+
renderers
(see text below)
Contains the configuration for each renderer. See below.
Index: fop.bat
===================================================================
--- fop.bat (revision 540059)
+++ fop.bat (working copy)
@@ -62,7 +62,7 @@
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\batik-all-1.6.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xmlgraphics-commons-1.2svn.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\avalon-framework-4.2.0.jar
-set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\commons-io-1.1.jar
+set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\commons-io-1.3.1.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\commons-logging-1.0.4.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jar
@@ -70,6 +70,8 @@
set LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\fop-hyph.jar
set LOCALCLASSPATH=%LOCALCLASSPATH%;%FOP_HYPHENATION_PATH%
+set JAVAOPTS=-Denv.windir=%WINDIR%
+
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java
@@ -80,5 +82,4 @@
:runFop
rem ECHO "%JAVACMD%"
-"%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
-
+"%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
Index: lib/commons-io-1.1.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: lib/commons-io-1.3.1.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: lib/commons-io-1.3.1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream