You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/03/06 14:34:59 UTC
svn commit: r634267 [8/39] - in
/xmlgraphics/fop/branches/Temp_ProcessingFeedback: ./ examples/embedding/
examples/embedding/java/embedding/
examples/embedding/java/embedding/intermediate/ examples/embedding/xml/xml/
examples/fo/ examples/fo/advanced/ ...
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java Thu Mar 6 05:33:44 2008
@@ -1,92 +1,339 @@
-/*
- * 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 java.util.Set;
-
-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);
- }
-
- /**
- * {@inheritDoc}
- */
- protected void read() throws IOException {
- pfm = new PFMFile();
- pfm.load(in);
- singleFont = new SingleByteFont();
- singleFont.setFontType(FontType.TYPE1);
- if (pfm.getCharSet() >= 0 && pfm.getCharSet() <= 2) {
- singleFont.setEncoding(pfm.getCharSetName() + "Encoding");
- } else {
- log.warn("The PFM reports an unsupported encoding ("
- + pfm.getCharSetName() + "). The font may not work as expected.");
- singleFont.setEncoding("WinAnsiEncoding"); //Try fallback, no guarantees!
- }
- singleFont.setResolver(this.resolver);
- returnFont = singleFont;
- returnFont.setFontName(pfm.getPostscriptName());
- String fullName = pfm.getPostscriptName();
- fullName = fullName.replace('-', ' '); //Hack! Try to emulate full name
- returnFont.setFullName(fullName); //should be afm.getFullName()!!
- //TODO not accurate: we need FullName from the AFM file but we don't have an AFM parser
- Set names = new java.util.HashSet();
- names.add(pfm.getWindowsName()); //should be afm.getFamilyName()!!
- returnFont.setFamilyNames(names);
- 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.getLastChar());
- 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);
- }
-}
+/*
+ * 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.awt.geom.RectangularShape;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.fonts.CodePointMapping;
+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 SingleByteFont singleFont;
+
+ /**
+ * Constructs a new Type 1 font loader.
+ * @param fontFileURI the URI to the PFB 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, FontResolver resolver)
+ throws IOException {
+ super(fontFileURI, resolver);
+ }
+
+ private String getPFMURI(String pfbURI) {
+ String pfbExt = pfbURI.substring(pfbURI.length() - 3, pfbURI.length());
+ String pfmExt = pfbExt.substring(0, 2)
+ + (Character.isUpperCase(pfbExt.charAt(2)) ? "M" : "m");
+ return pfbURI.substring(0, pfbURI.length() - 4) + "." + pfmExt;
+ }
+
+ private static final String[] AFM_EXTENSIONS = new String[] {".AFM", ".afm", ".Afm"};
+
+ /** {@inheritDoc} */
+ protected void read() throws IOException {
+ AFMFile afm = null;
+ PFMFile pfm = null;
+
+ InputStream afmIn = null;
+ for (int i = 0; i < AFM_EXTENSIONS.length; i++) {
+ try {
+ String afmUri = this.fontFileURI.substring(0, this.fontFileURI.length() - 4)
+ + AFM_EXTENSIONS[i];
+ afmIn = openFontUri(resolver, afmUri);
+ if (afmIn != null) {
+ break;
+ }
+ } catch (IOException ioe) {
+ //Ignore, AFM probably not available under the URI
+ }
+ }
+ if (afmIn != null) {
+ try {
+ AFMParser afmParser = new AFMParser();
+ afm = afmParser.parse(afmIn);
+ } finally {
+ IOUtils.closeQuietly(afmIn);
+ }
+ }
+
+ String pfmUri = getPFMURI(this.fontFileURI);
+ InputStream pfmIn = null;
+ try {
+ pfmIn = openFontUri(resolver, pfmUri);
+ } catch (IOException ioe) {
+ //Ignore, PFM probably not available under the URI
+ }
+ if (pfmIn != null) {
+ try {
+ pfm = new PFMFile();
+ pfm.load(pfmIn);
+ } finally {
+ IOUtils.closeQuietly(pfmIn);
+ }
+ }
+
+ if (afm == null && pfm == null) {
+ throw new java.io.FileNotFoundException(
+ "Neither an AFM nor a PFM file was found for " + this.fontFileURI);
+ }
+ if (pfm == null) {
+ //Cannot do without the PFM for now
+ throw new java.io.FileNotFoundException(
+ "No PFM file was found for " + this.fontFileURI);
+ }
+ buildFont(afm, pfm);
+ this.loaded = true;
+ }
+
+ private void buildFont(AFMFile afm, PFMFile pfm) {
+ if (afm == null && pfm == null) {
+ throw new IllegalArgumentException("Need at least an AFM or a PFM!");
+ }
+ singleFont = new SingleByteFont();
+ singleFont.setFontType(FontType.TYPE1);
+ singleFont.setResolver(this.resolver);
+ singleFont.setEmbedFileName(this.fontFileURI);
+ returnFont = singleFont;
+
+ //Encoding
+ if (afm != null) {
+ String encoding = afm.getEncodingScheme();
+ if ("AdobeStandardEncoding".equals(encoding)) {
+ //Use WinAnsi in this case as it better fits the usual character set people need
+ singleFont.setEncoding(CodePointMapping.WIN_ANSI_ENCODING);
+ } else {
+ String effEncodingName;
+ if ("FontSpecific".equals(encoding)) {
+ effEncodingName = afm.getFontName() + "Encoding";
+ } else {
+ effEncodingName = encoding;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Unusual font encoding encountered: "
+ + encoding + " -> " + effEncodingName);
+ }
+ CodePointMapping mapping = buildCustomEncoding(effEncodingName, afm);
+ singleFont.setEncoding(mapping);
+ }
+ } else {
+ if (pfm.getCharSet() >= 0 && pfm.getCharSet() <= 2) {
+ singleFont.setEncoding(pfm.getCharSetName() + "Encoding");
+ } else {
+ log.warn("The PFM reports an unsupported encoding ("
+ + pfm.getCharSetName() + "). The font may not work as expected.");
+ singleFont.setEncoding("WinAnsiEncoding"); //Try fallback, no guarantees!
+ }
+ }
+
+ //Font name
+ if (afm != null) {
+ returnFont.setFontName(afm.getFontName()); //PostScript font name
+ returnFont.setFullName(afm.getFullName());
+ Set names = new java.util.HashSet();
+ names.add(afm.getFamilyName());
+ returnFont.setFamilyNames(names);
+ } else {
+ returnFont.setFontName(pfm.getPostscriptName());
+ String fullName = pfm.getPostscriptName();
+ fullName = fullName.replace('-', ' '); //Hack! Try to emulate full name
+ returnFont.setFullName(fullName); //emulate afm.getFullName()
+ Set names = new java.util.HashSet();
+ names.add(pfm.getWindowsName()); //emulate afm.getFamilyName()
+ returnFont.setFamilyNames(names);
+ }
+
+ //Basic metrics
+ if (afm != null) {
+ if (afm.getCapHeight() != null) {
+ returnFont.setCapHeight(afm.getCapHeight().intValue());
+ }
+ if (afm.getXHeight() != null) {
+ returnFont.setXHeight(afm.getXHeight().intValue());
+ }
+ if (afm.getAscender() != null) {
+ returnFont.setAscender(afm.getAscender().intValue());
+ }
+ if (afm.getDescender() != null) {
+ returnFont.setDescender(afm.getDescender().intValue());
+ }
+
+ returnFont.setFontBBox(afm.getFontBBoxAsIntArray());
+ if (afm.getStdVW() != null) {
+ returnFont.setStemV(afm.getStdVW().intValue());
+ } else {
+ returnFont.setStemV(80); //Arbitrary value
+ }
+ returnFont.setItalicAngle((int)afm.getWritingDirectionMetrics(0).getItalicAngle());
+ } else {
+ returnFont.setFontBBox(pfm.getFontBBox());
+ returnFont.setStemV(pfm.getStemV());
+ returnFont.setItalicAngle(pfm.getItalicAngle());
+ }
+ if (pfm != null) {
+ //Sometimes the PFM has these metrics while the AFM doesn't (ex. Symbol)
+ if (returnFont.getCapHeight() == 0) {
+ returnFont.setCapHeight(pfm.getCapHeight());
+ }
+ if (returnFont.getXHeight(1) == 0) {
+ returnFont.setXHeight(pfm.getXHeight());
+ }
+ if (returnFont.getAscender() == 0) {
+ returnFont.setAscender(pfm.getLowerCaseAscent());
+ }
+ if (returnFont.getDescender() == 0) {
+ returnFont.setDescender(pfm.getLowerCaseDescent());
+ }
+ }
+
+ //Fallbacks when some crucial font metrics aren't available
+ //(the following are all optional in AFM, but FontBBox is always available)
+ if (returnFont.getXHeight(1) == 0) {
+ int xHeight = 0;
+ if (afm != null) {
+ AFMCharMetrics chm = afm.getChar("x");
+ if (chm != null) {
+ RectangularShape rect = chm.getBBox();
+ if (rect != null) {
+ xHeight = (int)Math.round(rect.getMinX());
+ }
+ }
+ }
+ if (xHeight == 0) {
+ xHeight = Math.round(returnFont.getFontBBox()[3] * 0.6f);
+ }
+ returnFont.setXHeight(xHeight);
+ }
+ if (returnFont.getAscender() == 0) {
+ int asc = 0;
+ if (afm != null) {
+ AFMCharMetrics chm = afm.getChar("d");
+ if (chm != null) {
+ RectangularShape rect = chm.getBBox();
+ if (rect != null) {
+ asc = (int)Math.round(rect.getMinX());
+ }
+ }
+ }
+ if (asc == 0) {
+ asc = Math.round(returnFont.getFontBBox()[3] * 0.9f);
+ }
+ returnFont.setAscender(asc);
+ }
+ if (returnFont.getDescender() == 0) {
+ int desc = 0;
+ if (afm != null) {
+ AFMCharMetrics chm = afm.getChar("p");
+ if (chm != null) {
+ RectangularShape rect = chm.getBBox();
+ if (rect != null) {
+ desc = (int)Math.round(rect.getMinX());
+ }
+ }
+ }
+ if (desc == 0) {
+ desc = returnFont.getFontBBox()[1];
+ }
+ returnFont.setDescender(desc);
+ }
+ if (returnFont.getCapHeight() == 0) {
+ returnFont.setCapHeight(returnFont.getAscender());
+ }
+
+ /* DISABLED because of mismatch with our using WinAnsiEncoding and the AFM
+ delivering the font's default encoding.
+ if (afm != null) {
+ //TODO returnFont.setFlags(flags);
+
+ returnFont.setFirstChar(afm.getFirstChar());
+ returnFont.setLastChar(afm.getLastChar());
+ Iterator iter = afm.getCharMetrics().iterator();
+ while (iter.hasNext()) {
+ AFMCharMetrics chm = (AFMCharMetrics)iter.next();
+ if (chm.hasCharCode()) {
+ singleFont.setWidth(chm.getCharCode(), (int)Math.round(chm.getWidthX()));
+ }
+ }
+ returnFont.replaceKerningMap(afm.createXKerningMapEncoded());
+ } else {*/
+ returnFont.setFlags(pfm.getFlags());
+ returnFont.setFirstChar(pfm.getFirstChar());
+ returnFont.setLastChar(pfm.getLastChar());
+ for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
+ singleFont.setWidth(i, pfm.getCharWidth(i));
+ }
+ returnFont.replaceKerningMap(pfm.getKerning());
+ //}
+ }
+
+ private CodePointMapping buildCustomEncoding(String encodingName, AFMFile afm) {
+ List chars = afm.getCharMetrics();
+ int mappingCount = 0;
+ //Just count the first time...
+ Iterator iter = chars.iterator();
+ while (iter.hasNext()) {
+ AFMCharMetrics charMetrics = (AFMCharMetrics)iter.next();
+ if (charMetrics.getCharCode() >= 0) {
+ String u = charMetrics.getUnicodeSequence();
+ if (u != null && u.length() == 1) {
+ mappingCount++;
+ }
+ }
+ }
+ //...and now build the table.
+ int[] table = new int[mappingCount * 2];
+ String[] charNameMap = new String[256];
+ iter = chars.iterator();
+ int idx = 0;
+ while (iter.hasNext()) {
+ AFMCharMetrics charMetrics = (AFMCharMetrics)iter.next();
+ if (charMetrics.getCharCode() >= 0) {
+ charNameMap[charMetrics.getCharCode()] = charMetrics.getCharName();
+ String unicodes = charMetrics.getUnicodeSequence();
+ if (unicodes == null) {
+ log.info("No Unicode mapping for glyph: " + charMetrics);
+ } else if (unicodes.length() == 1) {
+ table[idx] = charMetrics.getCharCode();
+ idx++;
+ table[idx] = unicodes.charAt(0);
+ idx++;
+ } else {
+ log.warn("Multi-character representation of glyph not currently supported: "
+ + charMetrics);
+ }
+ }
+ }
+ return new CodePointMapping(encodingName, table, charNameMap);
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/ByteVector.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/CharVector.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/Hyphen.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/Hyphenation.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/HyphenationException.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/HyphenationTree.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/HyphenationTreeCache.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/HyphenationTreeResolver.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/Hyphenator.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/PatternConsumer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/PatternParser.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/hyphenation/TernaryTree.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/EmfImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/EmfImage.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/EmfImage.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/EmfImage.java Thu Mar 6 05:33:44 2008
@@ -1,51 +1,51 @@
-/*
- * 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.image;
-
-/**
- * Enhanced metafile image.
- * This supports loading a EMF image.
- *
- * @see AbstractFopImage
- * @see FopImage
- */
-public class EmfImage extends AbstractFopImage {
-
- /**
- * Create a bitmap image with the image data.
- *
- * @param imgInfo the image information
- */
- public EmfImage(FopImage.ImageInfo imgInfo) {
- super(imgInfo);
- }
-
- /**
- * Load the original EMF data.
- * This loads the original EMF data and reads the color space,
- * and icc profile if any.
- *
- * @return true if loaded false for any error
- */
- protected boolean loadOriginalData() {
- return loadDefaultOriginalData();
- }
-}
-
+/*
+ * 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.image;
+
+/**
+ * Enhanced metafile image.
+ * This supports loading a EMF image.
+ *
+ * @see AbstractFopImage
+ * @see FopImage
+ */
+public class EmfImage extends AbstractFopImage {
+
+ /**
+ * Create a bitmap image with the image data.
+ *
+ * @param imgInfo the image information
+ */
+ public EmfImage(FopImage.ImageInfo imgInfo) {
+ super(imgInfo);
+ }
+
+ /**
+ * Load the original EMF data.
+ * This loads the original EMF data and reads the color space,
+ * and icc profile if any.
+ *
+ * @return true if loaded false for any error
+ */
+ protected boolean loadOriginalData() {
+ return loadDefaultOriginalData();
+ }
+}
+
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/EmfImage.java
------------------------------------------------------------------------------
--- svn:eol-style (original)
+++ svn:eol-style Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-CRLF
+native
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/PNGImage.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/RegisterableImageProvider.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/TIFFImage.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/XmlGraphicsCommonsImage.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/analyser/EMFReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/analyser/EMFReader.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/analyser/EMFReader.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/analyser/EMFReader.java Thu Mar 6 05:33:44 2008
@@ -1,162 +1,162 @@
-/*
- * 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.image.analyser;
-
-// Java
-import java.io.InputStream;
-import java.io.IOException;
-
-// FOP
-import org.apache.fop.image.FopImage;
-import org.apache.fop.apps.FOUserAgent;
-
-/**
- * ImageReader object for EMF image type.
- *
- * @author Peter Herweg
- */
-public class EMFReader implements ImageReader {
-
- /** Length of the EMF header */
- protected static final int EMF_SIG_LENGTH = 88;
-
- /** offset to signature */
- private static final int SIGNATURE_OFFSET = 40;
- /** offset to width */
- private static final int WIDTH_OFFSET = 32;
- /** offset to height */
- private static final int HEIGHT_OFFSET = 36;
- /** offset to horizontal resolution in pixel */
- private static final int HRES_PIXEL_OFFSET = 72;
- /** offset to vertical resolution in pixel */
- private static final int VRES_PIXEL_OFFSET = 76;
- /** offset to horizontal resolution in mm */
- private static final int HRES_MM_OFFSET = 80;
- /** offset to vertical resolution in mm */
- private static final int VRES_MM_OFFSET = 84;
-
- /** {@inheritDoc} */
- public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
- FOUserAgent ua) throws IOException {
- byte[] header = getDefaultHeader(bis);
- boolean supported
- = ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20)
- && (header[SIGNATURE_OFFSET + 1] == (byte) 0x45)
- && (header[SIGNATURE_OFFSET + 2] == (byte) 0x4D)
- && (header[SIGNATURE_OFFSET + 3] == (byte) 0x46) );
-
- if (supported) {
- FopImage.ImageInfo info = getDimension(header);
- info.originalURI = uri;
- info.mimeType = getMimeType();
- info.inputStream = bis;
- return info;
- } else {
- return null;
- }
- }
-
- /**
- * Returns the MIME type supported by this implementation.
- *
- * @return The MIME type
- */
- public String getMimeType() {
- return "image/emf";
- }
-
- private FopImage.ImageInfo getDimension(byte[] header) {
- FopImage.ImageInfo info = new FopImage.ImageInfo();
- long value = 0;
- int byte1;
- int byte2;
- int byte3;
- int byte4;
-
- // little endian notation
-
- //resolution
- byte1 = header[HRES_MM_OFFSET] & 0xff;
- byte2 = header[HRES_MM_OFFSET + 1] & 0xff;
- byte3 = header[HRES_MM_OFFSET + 2] & 0xff;
- byte4 = header[HRES_MM_OFFSET + 3] & 0xff;
- long hresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
-
- byte1 = header[VRES_MM_OFFSET] & 0xff;
- byte2 = header[VRES_MM_OFFSET + 1] & 0xff;
- byte3 = header[VRES_MM_OFFSET + 2] & 0xff;
- byte4 = header[VRES_MM_OFFSET + 3] & 0xff;
- long vresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
-
- byte1 = header[HRES_PIXEL_OFFSET] & 0xff;
- byte2 = header[HRES_PIXEL_OFFSET + 1] & 0xff;
- byte3 = header[HRES_PIXEL_OFFSET + 2] & 0xff;
- byte4 = header[HRES_PIXEL_OFFSET + 3] & 0xff;
- long hresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
-
- byte1 = header[VRES_PIXEL_OFFSET] & 0xff;
- byte2 = header[VRES_PIXEL_OFFSET + 1] & 0xff;
- byte3 = header[VRES_PIXEL_OFFSET + 2] & 0xff;
- byte4 = header[VRES_PIXEL_OFFSET + 3] & 0xff;
- long vresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
-
- info.dpiHorizontal = hresPixel / (hresMM / 25.4f);
- info.dpiVertical = vresPixel / (vresMM / 25.4f);
-
- //width
- byte1 = header[WIDTH_OFFSET] & 0xff;
- byte2 = header[WIDTH_OFFSET + 1] & 0xff;
- byte3 = header[WIDTH_OFFSET + 2] & 0xff;
- byte4 = header[WIDTH_OFFSET + 3] & 0xff;
- value = (long) ((byte4 << 24) | (byte3 << 16)
- | (byte2 << 8) | byte1);
- value = Math.round(value / 100f / 25.4f * info.dpiHorizontal);
- info.width = (int) (value & 0xffffffff);
-
- //height
- byte1 = header[HEIGHT_OFFSET] & 0xff;
- byte2 = header[HEIGHT_OFFSET + 1] & 0xff;
- byte3 = header[HEIGHT_OFFSET + 2] & 0xff;
- byte4 = header[HEIGHT_OFFSET + 3] & 0xff;
- value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
- value = Math.round(value / 100f / 25.4f * info.dpiVertical);
- info.height = (int) (value & 0xffffffff);
-
- return info;
- }
-
- private byte[] getDefaultHeader(InputStream imageStream)
- throws IOException {
- byte[] header = new byte[EMF_SIG_LENGTH];
- try {
- imageStream.mark(EMF_SIG_LENGTH + 1);
- imageStream.read(header);
- imageStream.reset();
- } catch (IOException ex) {
- try {
- imageStream.reset();
- } catch (IOException exbis) {
- // throw the original exception, not this one
- }
- throw ex;
- }
- return header;
- }
-}
+/*
+ * 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.image.analyser;
+
+// Java
+import java.io.InputStream;
+import java.io.IOException;
+
+// FOP
+import org.apache.fop.image.FopImage;
+import org.apache.fop.apps.FOUserAgent;
+
+/**
+ * ImageReader object for EMF image type.
+ *
+ * @author Peter Herweg
+ */
+public class EMFReader implements ImageReader {
+
+ /** Length of the EMF header */
+ protected static final int EMF_SIG_LENGTH = 88;
+
+ /** offset to signature */
+ private static final int SIGNATURE_OFFSET = 40;
+ /** offset to width */
+ private static final int WIDTH_OFFSET = 32;
+ /** offset to height */
+ private static final int HEIGHT_OFFSET = 36;
+ /** offset to horizontal resolution in pixel */
+ private static final int HRES_PIXEL_OFFSET = 72;
+ /** offset to vertical resolution in pixel */
+ private static final int VRES_PIXEL_OFFSET = 76;
+ /** offset to horizontal resolution in mm */
+ private static final int HRES_MM_OFFSET = 80;
+ /** offset to vertical resolution in mm */
+ private static final int VRES_MM_OFFSET = 84;
+
+ /** {@inheritDoc} */
+ public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
+ FOUserAgent ua) throws IOException {
+ byte[] header = getDefaultHeader(bis);
+ boolean supported
+ = ( (header[SIGNATURE_OFFSET + 0] == (byte) 0x20)
+ && (header[SIGNATURE_OFFSET + 1] == (byte) 0x45)
+ && (header[SIGNATURE_OFFSET + 2] == (byte) 0x4D)
+ && (header[SIGNATURE_OFFSET + 3] == (byte) 0x46) );
+
+ if (supported) {
+ FopImage.ImageInfo info = getDimension(header);
+ info.originalURI = uri;
+ info.mimeType = getMimeType();
+ info.inputStream = bis;
+ return info;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the MIME type supported by this implementation.
+ *
+ * @return The MIME type
+ */
+ public String getMimeType() {
+ return "image/emf";
+ }
+
+ private FopImage.ImageInfo getDimension(byte[] header) {
+ FopImage.ImageInfo info = new FopImage.ImageInfo();
+ long value = 0;
+ int byte1;
+ int byte2;
+ int byte3;
+ int byte4;
+
+ // little endian notation
+
+ //resolution
+ byte1 = header[HRES_MM_OFFSET] & 0xff;
+ byte2 = header[HRES_MM_OFFSET + 1] & 0xff;
+ byte3 = header[HRES_MM_OFFSET + 2] & 0xff;
+ byte4 = header[HRES_MM_OFFSET + 3] & 0xff;
+ long hresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
+
+ byte1 = header[VRES_MM_OFFSET] & 0xff;
+ byte2 = header[VRES_MM_OFFSET + 1] & 0xff;
+ byte3 = header[VRES_MM_OFFSET + 2] & 0xff;
+ byte4 = header[VRES_MM_OFFSET + 3] & 0xff;
+ long vresMM = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
+
+ byte1 = header[HRES_PIXEL_OFFSET] & 0xff;
+ byte2 = header[HRES_PIXEL_OFFSET + 1] & 0xff;
+ byte3 = header[HRES_PIXEL_OFFSET + 2] & 0xff;
+ byte4 = header[HRES_PIXEL_OFFSET + 3] & 0xff;
+ long hresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
+
+ byte1 = header[VRES_PIXEL_OFFSET] & 0xff;
+ byte2 = header[VRES_PIXEL_OFFSET + 1] & 0xff;
+ byte3 = header[VRES_PIXEL_OFFSET + 2] & 0xff;
+ byte4 = header[VRES_PIXEL_OFFSET + 3] & 0xff;
+ long vresPixel = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
+
+ info.dpiHorizontal = hresPixel / (hresMM / 25.4f);
+ info.dpiVertical = vresPixel / (vresMM / 25.4f);
+
+ //width
+ byte1 = header[WIDTH_OFFSET] & 0xff;
+ byte2 = header[WIDTH_OFFSET + 1] & 0xff;
+ byte3 = header[WIDTH_OFFSET + 2] & 0xff;
+ byte4 = header[WIDTH_OFFSET + 3] & 0xff;
+ value = (long) ((byte4 << 24) | (byte3 << 16)
+ | (byte2 << 8) | byte1);
+ value = Math.round(value / 100f / 25.4f * info.dpiHorizontal);
+ info.width = (int) (value & 0xffffffff);
+
+ //height
+ byte1 = header[HEIGHT_OFFSET] & 0xff;
+ byte2 = header[HEIGHT_OFFSET + 1] & 0xff;
+ byte3 = header[HEIGHT_OFFSET + 2] & 0xff;
+ byte4 = header[HEIGHT_OFFSET + 3] & 0xff;
+ value = (long) ((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1);
+ value = Math.round(value / 100f / 25.4f * info.dpiVertical);
+ info.height = (int) (value & 0xffffffff);
+
+ return info;
+ }
+
+ private byte[] getDefaultHeader(InputStream imageStream)
+ throws IOException {
+ byte[] header = new byte[EMF_SIG_LENGTH];
+ try {
+ imageStream.mark(EMF_SIG_LENGTH + 1);
+ imageStream.read(header);
+ imageStream.reset();
+ } catch (IOException ex) {
+ try {
+ imageStream.reset();
+ } catch (IOException exbis) {
+ // throw the original exception, not this one
+ }
+ throw ex;
+ }
+ return header;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/analyser/EMFReader.java
------------------------------------------------------------------------------
--- svn:eol-style (original)
+++ svn:eol-style Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-CRLF
+native
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java Thu Mar 6 05:33:44 2008
@@ -76,7 +76,7 @@
return null;
}
}
- if (info != null && ImageUtil.hasInputStream(src)) {
+ if (info != null) {
ImageUtil.closeQuietly(src); //Image is fully read
}
return info;
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java Thu Mar 6 05:33:44 2008
@@ -25,6 +25,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.fop.fo.Constants;
import org.apache.fop.traits.MinOptMax;
@@ -560,10 +561,8 @@
nextSequenceStartsOn = handleSpanChange(childLC, nextSequenceStartsOn);
Position breakPosition = null;
- if (((KnuthElement) returnedList.getLast()).isPenalty()
- && ((KnuthPenalty) returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
- KnuthPenalty breakPenalty = (KnuthPenalty) returnedList
- .removeLast();
+ if (((KnuthElement) returnedList.getLast()).isForcedBreak()) {
+ KnuthPenalty breakPenalty = (KnuthPenalty)returnedList.removeLast();
breakPosition = breakPenalty.getPosition();
switch (breakPenalty.getBreakClass()) {
case Constants.EN_PAGE:
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java Thu Mar 6 05:33:44 2008
@@ -1,107 +1,107 @@
-/*
- * 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.layoutmgr;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fop.traits.MinOptMax;
-
-/**
- * This is a the breaking algorithm that is responsible for balancing columns in multi-column
- * layout.
- */
-public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm {
-
- private Log log = LogFactory.getLog(BalancingColumnBreakingAlgorithm.class);
-
- private int columnCount;
- private int fullLen;
- private int idealPartLen;
-
- public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,
- PageProvider pageProvider,
- PageBreakingLayoutListener layoutListener,
- int alignment, int alignmentLast,
- MinOptMax footnoteSeparatorLength,
- boolean partOverflowRecovery,
- int columnCount) {
- super(topLevelLM, pageProvider, layoutListener,
- alignment, alignmentLast,
- footnoteSeparatorLength, partOverflowRecovery, false, false);
- this.columnCount = columnCount;
- this.considerTooShort = true; //This is important!
- }
-
- /** {@inheritDoc} */
- protected double computeDemerits(KnuthNode activeNode,
- KnuthElement element, int fitnessClass, double r) {
- double dem = super.computeDemerits(activeNode, element, fitnessClass, r);
- if (log.isTraceEnabled()) {
- log.trace("original demerit=" + dem + " " + totalWidth
- + " line=" + activeNode.line + "/" + columnCount
- + " pos=" + activeNode.position + "/" + (par.size() - 1));
- }
- int remParts = columnCount - activeNode.line;
- int curPos = par.indexOf(element);
- if (fullLen == 0) {
- fullLen = ElementListUtils.calcContentLength(par, activeNode.position, par.size() - 1);
- this.idealPartLen = (fullLen / columnCount);
- }
- int partLen = ElementListUtils.calcContentLength(par, activeNode.position, curPos - 1);
- int restLen = ElementListUtils.calcContentLength(par, curPos - 1, par.size() - 1);
- int avgRestLen = 0;
- if (remParts > 0) {
- avgRestLen = restLen / remParts;
- }
- if (log.isTraceEnabled()) {
- log.trace("remaining parts: " + remParts + " rest len: " + restLen
- + " avg=" + avgRestLen);
- }
- double balance = (idealPartLen - partLen) / 1000f;
- if (log.isTraceEnabled()) {
- log.trace("balance=" + balance);
- }
- double absBalance = Math.abs(balance);
- dem = absBalance;
- //Step 1: This does the rough balancing
- if (columnCount > 2) {
- if (balance > 0) {
- //shorter parts are less desired than longer ones
- dem = dem * 1.2f;
- }
- } else {
- if (balance < 0) {
- //shorter parts are less desired than longer ones
- dem = dem * 1.2f;
- }
- }
- //Step 2: This helps keep the trailing parts shorter than the previous ones
- dem += (avgRestLen) / 1000f;
-
- if (activeNode.line >= columnCount) {
- //We don't want more columns than available
- dem = Double.MAX_VALUE;
- }
- if (log.isTraceEnabled()) {
- log.trace("effective dem=" + dem + " " + totalWidth);
- }
- return dem;
- }
-}
+/*
+ * 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.layoutmgr;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.traits.MinOptMax;
+
+/**
+ * This is a the breaking algorithm that is responsible for balancing columns in multi-column
+ * layout.
+ */
+public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm {
+
+ private Log log = LogFactory.getLog(BalancingColumnBreakingAlgorithm.class);
+
+ private int columnCount;
+ private int fullLen;
+ private int idealPartLen;
+
+ public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,
+ PageProvider pageProvider,
+ PageBreakingLayoutListener layoutListener,
+ int alignment, int alignmentLast,
+ MinOptMax footnoteSeparatorLength,
+ boolean partOverflowRecovery,
+ int columnCount) {
+ super(topLevelLM, pageProvider, layoutListener,
+ alignment, alignmentLast,
+ footnoteSeparatorLength, partOverflowRecovery, false, false);
+ this.columnCount = columnCount;
+ this.considerTooShort = true; //This is important!
+ }
+
+ /** {@inheritDoc} */
+ protected double computeDemerits(KnuthNode activeNode,
+ KnuthElement element, int fitnessClass, double r) {
+ double dem = super.computeDemerits(activeNode, element, fitnessClass, r);
+ if (log.isTraceEnabled()) {
+ log.trace("original demerit=" + dem + " " + totalWidth
+ + " line=" + activeNode.line + "/" + columnCount
+ + " pos=" + activeNode.position + "/" + (par.size() - 1));
+ }
+ int remParts = columnCount - activeNode.line;
+ int curPos = par.indexOf(element);
+ if (fullLen == 0) {
+ fullLen = ElementListUtils.calcContentLength(par, activeNode.position, par.size() - 1);
+ this.idealPartLen = (fullLen / columnCount);
+ }
+ int partLen = ElementListUtils.calcContentLength(par, activeNode.position, curPos - 1);
+ int restLen = ElementListUtils.calcContentLength(par, curPos - 1, par.size() - 1);
+ int avgRestLen = 0;
+ if (remParts > 0) {
+ avgRestLen = restLen / remParts;
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("remaining parts: " + remParts + " rest len: " + restLen
+ + " avg=" + avgRestLen);
+ }
+ double balance = (idealPartLen - partLen) / 1000f;
+ if (log.isTraceEnabled()) {
+ log.trace("balance=" + balance);
+ }
+ double absBalance = Math.abs(balance);
+ dem = absBalance;
+ //Step 1: This does the rough balancing
+ if (columnCount > 2) {
+ if (balance > 0) {
+ //shorter parts are less desired than longer ones
+ dem = dem * 1.2f;
+ }
+ } else {
+ if (balance < 0) {
+ //shorter parts are less desired than longer ones
+ dem = dem * 1.2f;
+ }
+ }
+ //Step 2: This helps keep the trailing parts shorter than the previous ones
+ dem += (avgRestLen) / 1000f;
+
+ if (activeNode.line >= columnCount) {
+ //We don't want more columns than available
+ dem = Double.MAX_VALUE;
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("effective dem=" + dem + " " + totalWidth);
+ }
+ return dem;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java Thu Mar 6 05:33:44 2008
@@ -32,6 +32,8 @@
import org.apache.fop.area.Block;
import org.apache.fop.area.BlockViewport;
import org.apache.fop.area.CTM;
+import org.apache.fop.area.BlockViewport;
+import org.apache.fop.area.CTM;
import org.apache.fop.area.Trait;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.datatypes.Length;
@@ -65,7 +67,8 @@
private int vpContentBPD;
// When viewport should grow with the content.
- private boolean autoHeight = true;
+ private boolean autoHeight = true;
+ private boolean inlineElementList = false;
/* holds the (one-time use) fo:block space-before
and -after properties. Large fo:blocks are split
@@ -196,6 +199,8 @@
return getNextKnuthElementsAbsolute(context, alignment);
}
+ boolean switchedProgressionDirection
+ = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
autoHeight = false;
//boolean rotated = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
int maxbpd = context.getStackLimit().opt;
@@ -203,9 +208,13 @@
if (height.getEnum() == EN_AUTO
|| (!height.isAbsolute() && getAncestorBlockAreaBPD() <= 0)) {
//auto height when height="auto" or "if that dimension is not specified explicitly
- //(i.e., it depends on content's blockprogression-dimension)" (XSL 1.0, 7.14.1)
+ //(i.e., it depends on content's block-progression-dimension)" (XSL 1.0, 7.14.1)
allocBPD = maxbpd;
autoHeight = true;
+ if (getBlockContainerFO().getReferenceOrientation() == 0) {
+ //Cannot easily inline element list when ref-or="180"
+ inlineElementList = true;
+ }
} else {
allocBPD = height.getValue(this); //this is the content-height
allocBPD += getBPIndents();
@@ -229,19 +238,14 @@
contentRectOffsetY += getBlockContainerFO()
.getCommonBorderPaddingBackground().getPaddingBefore(false, this);
- Rectangle2D rect = new Rectangle2D.Double(
- contentRectOffsetX, contentRectOffsetY,
- getContentAreaIPD(), getContentAreaBPD());
- relDims = new FODimension(0, 0);
- absoluteCTM = CTM.getCTMandRelDims(getBlockContainerFO().getReferenceOrientation(),
- getBlockContainerFO().getWritingMode(), rect, relDims);
+ updateRelDims(contentRectOffsetX, contentRectOffsetY, autoHeight);
int availableIPD = referenceIPD - getIPIndents();
- if (rect.getWidth() > availableIPD) {
+ if (getContentAreaIPD() > availableIPD) {
log.warn(FONode.decorateWithContextInfo(
"The extent in inline-progression-direction (width) of a block-container is"
+ " bigger than the available space ("
- + rect.getWidth() + "mpt > " + context.getRefIPD() + "mpt)",
+ + getContentAreaIPD() + "mpt > " + context.getRefIPD() + "mpt)",
getBlockContainerFO()));
}
@@ -268,7 +272,7 @@
addKnuthElementsForBorderPaddingBefore(returnList, !firstVisibleMarkServed);
firstVisibleMarkServed = true;
- if (autoHeight) {
+ if (autoHeight && inlineElementList) {
//Spaces, border and padding to be repeated at each break
addPendingMarks(context);
@@ -355,9 +359,16 @@
MinOptMax range = new MinOptMax(relDims.ipd);
BlockContainerBreaker breaker = new BlockContainerBreaker(this, range);
breaker.doLayout(relDims.bpd, autoHeight);
- boolean contentOverflows = false;
- if (!breaker.isEmpty()) {
- contentOverflows = (breaker.deferredAlg.getPageBreaks().size() > 1);
+ boolean contentOverflows = breaker.isOverflow();
+ if (autoHeight) {
+ //Update content BPD now that it is known
+ int newHeight = breaker.deferredAlg.totalWidth;
+ if (switchedProgressionDirection) {
+ setContentAreaIPD(newHeight);
+ } else {
+ vpContentBPD = newHeight;
+ }
+ updateRelDims(contentRectOffsetX, contentRectOffsetY, false);
}
Position bcPosition = new BlockContainerPosition(this, breaker);
@@ -388,6 +399,8 @@
private LinkedList getNextKnuthElementsAbsolute(LayoutContext context, int alignment) {
autoHeight = false;
+ boolean switchedProgressionDirection
+ = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
Point offset = getAbsOffset();
int allocBPD, allocIPD;
if (height.getEnum() == EN_AUTO
@@ -435,7 +448,9 @@
} else {
int maxbpd = context.getStackLimit().opt;
allocBPD = maxbpd;
- autoHeight = true;
+ if (!switchedProgressionDirection) {
+ autoHeight = true;
+ }
}
} else {
allocBPD = height.getValue(this); //this is the content-height
@@ -477,6 +492,9 @@
*/
allocIPD = 0;
}
+ if (switchedProgressionDirection) {
+ autoHeight = true;
+ }
}
} else {
allocIPD = width.getValue(this); //this is the content-width
@@ -486,29 +504,29 @@
vpContentBPD = allocBPD - getBPIndents();
setContentAreaIPD(allocIPD - getIPIndents());
- double contentRectOffsetX = 0;
- double contentRectOffsetY = 0;
-
- Rectangle2D rect = new Rectangle2D.Double(
- contentRectOffsetX, contentRectOffsetY,
- getContentAreaIPD(), vpContentBPD);
- relDims = new FODimension(0, 0);
- absoluteCTM = CTM.getCTMandRelDims(
- getBlockContainerFO().getReferenceOrientation(),
- getBlockContainerFO().getWritingMode(),
- rect, relDims);
+ updateRelDims(0, 0, autoHeight);
MinOptMax range = new MinOptMax(relDims.ipd);
BlockContainerBreaker breaker = new BlockContainerBreaker(this, range);
breaker.doLayout((autoHeight ? 0 : relDims.bpd), autoHeight);
boolean contentOverflows = breaker.isOverflow();
+ if (autoHeight) {
+ //Update content BPD now that it is known
+ int newHeight = breaker.deferredAlg.totalWidth;
+ if (switchedProgressionDirection) {
+ setContentAreaIPD(newHeight);
+ } else {
+ vpContentBPD = newHeight;
+ }
+ updateRelDims(0, 0, false);
+ }
LinkedList returnList = new LinkedList();
if (!breaker.isEmpty()) {
Position bcPosition = new BlockContainerPosition(this, breaker);
returnList.add(new KnuthBox(0, notifyPos(bcPosition), false));
//TODO Maybe check for page overflow when autoHeight=true
- if (!autoHeight & (contentOverflows/*usedBPD > relDims.bpd*/)) {
+ if (!autoHeight & (contentOverflows)) {
log.warn("Contents overflow block-container viewport: clipping");
if (getBlockContainerFO().getOverflow() == EN_ERROR_IF_OVERFLOW) {
//TODO Throw layout exception
@@ -519,6 +537,18 @@
setFinished(true);
return returnList;
}
+
+ private void updateRelDims(double xOffset, double yOffset, boolean skipAutoHeight) {
+ Rectangle2D rect = new Rectangle2D.Double(
+ xOffset, yOffset,
+ getContentAreaIPD(),
+ this.vpContentBPD);
+ relDims = new FODimension(0, 0);
+ absoluteCTM = CTM.getCTMandRelDims(
+ getBlockContainerFO().getReferenceOrientation(),
+ getBlockContainerFO().getWritingMode(),
+ rect, relDims);
+ }
private class BlockContainerPosition extends NonLeafPosition {
@@ -648,9 +678,9 @@
}
//Rendering all parts (not just the first) at once for the case where the parts that
//overflow should be visible.
- //TODO Check if this has any unwanted side-effects. Feels a bit like a hack.
+ this.deferredAlg.removeAllPageBreaks();
this.addAreas(this.deferredAlg,
- /*1*/ this.deferredAlg.getPageBreaks().size(),
+ this.deferredAlg.getPageBreaks().size(),
this.deferredOriginalList, this.deferredEffectiveList);
}
@@ -857,13 +887,18 @@
*/
public Area getParentArea(Area childArea) {
if (referenceArea == null) {
- viewportBlockArea = new BlockViewport();
+ boolean switchedProgressionDirection
+ = (getBlockContainerFO().getReferenceOrientation() % 180 != 0);
+ boolean allowBPDUpdate = autoHeight && !switchedProgressionDirection;
+
+ viewportBlockArea = new BlockViewport(allowBPDUpdate);
viewportBlockArea.addTrait(Trait.IS_VIEWPORT_AREA, Boolean.TRUE);
+
viewportBlockArea.setIPD(getContentAreaIPD());
- if (autoHeight) {
+ if (allowBPDUpdate) {
viewportBlockArea.setBPD(0);
} else {
- viewportBlockArea.setBPD(getContentAreaBPD());
+ viewportBlockArea.setBPD(this.vpContentBPD);
}
transferForeignAttributes(viewportBlockArea);
@@ -944,16 +979,7 @@
getBlockContainerFO().getCommonBorderPaddingBackground(),
this);
- // Fake a 0 height for absolute positioned blocks.
- int saveBPD = viewportBlockArea.getBPD();
- if (viewportBlockArea.getPositioning() == Block.ABSOLUTE) {
- viewportBlockArea.setBPD(0);
- }
super.flush();
- // Restore the right height.
- if (viewportBlockArea.getPositioning() == Block.ABSOLUTE) {
- viewportBlockArea.setBPD(saveBPD);
- }
}
/** {@inheritDoc} */
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BlockLevelLayoutManager.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BreakElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BreakElement.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BreakElement.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BreakElement.java Thu Mar 6 05:33:44 2008
@@ -46,10 +46,13 @@
/**
* Constructor for hard breaks.
+ *
* @param position the Position instance needed by the addAreas stage of the LMs.
* @param penaltyWidth the penalty width
* @param penaltyValue the penalty value for the penalty element to be constructed
- * @param breakClass the break class of this penalty (one of the break-* constants)
+ * @param breakClass the break class of this penalty (one of {@link Constants#EN_AUTO},
+ * {@link Constants#EN_COLUMN}, {@link Constants#EN_PAGE},
+ * {@link Constants#EN_EVEN_PAGE}, {@link Constants#EN_ODD_PAGE})
* @param context the layout context which contains the pending conditional elements
*/
public BreakElement(Position position, int penaltyWidth, int penaltyValue,
@@ -96,14 +99,23 @@
return penaltyValue == -KnuthElement.INFINITE;
}
- /** @return the break class of this penalty (one of the break-* constants) */
+ /**
+ * Returns the break class of this penalty.
+ *
+ * @return one of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
+ * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE},
+ * {@link Constants#EN_ODD_PAGE}
+ */
public int getBreakClass() {
return breakClass;
}
/**
* Sets the break class.
- * @param breakClass the new break class
+ *
+ * @param breakClass one of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
+ * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE},
+ * {@link Constants#EN_ODD_PAGE}
*/
public void setBreakClass(int breakClass) {
this.breakClass = breakClass;
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/ElementListObserver.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java Thu Mar 6 05:33:44 2008
@@ -39,6 +39,7 @@
import org.apache.fop.area.BodyRegion;
import org.apache.fop.area.CTM;
import org.apache.fop.area.LineArea;
+import org.apache.fop.area.PageSequence;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.inline.Image;
@@ -102,7 +103,7 @@
Dimension intrinsicSize = info.getSize().getDimensionMpt();
ImageLayout layout = new ImageLayout(getExternalDocument(), this, intrinsicSize);
- areaTreeHandler.getAreaTreeModel().startPageSequence(null);
+ areaTreeHandler.getAreaTreeModel().startPageSequence(new PageSequence(null));
if (log.isDebugEnabled()) {
log.debug("Starting layout");
}
@@ -200,6 +201,7 @@
}
}
+ /** {@inheritDoc} */
protected Page createPage(int pageNumber, boolean isBlank) {
String pageNumberString = pageSeq.makeFormattedPageNumber(pageNumber);
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthBlockBox.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthBox.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthElement.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthGlue.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java Thu Mar 6 05:33:44 2008
@@ -65,11 +65,13 @@
/**
* Create a new KnuthPenalty.
- *
+ *
* @param w the width of this penalty
* @param p the penalty value of this penalty
* @param f is this penalty flagged?
- * @param iBreakClass the break class of this penalty (one of the break-* constants)
+ * @param iBreakClass the break class of this penalty (one of
+ * {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN}, {@link Constants#EN_PAGE},
+ * {@link Constants#EN_EVEN_PAGE}, {@link Constants#EN_ODD_PAGE})
* @param pos the Position stored in this penalty
* @param bAux is this penalty auxiliary?
*/
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthPenalty.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/KnuthSequence.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/LayoutContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/LayoutContext.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/LayoutContext.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/LayoutContext.java Thu Mar 6 05:33:44 2008
@@ -133,6 +133,10 @@
/** Amount of space to reserve at the end of each line */
private int lineEndBorderAndPaddingWidth = 0;
+ private int breakBefore;
+
+ private int breakAfter;
+
/**
* Copy constructor for creating child layout contexts.
* @param parentLC the parent layout context to copy from
@@ -482,7 +486,54 @@
public void setSpaceAfter(int spaceAfter) {
this.spaceAfter = spaceAfter;
}
-
+
+ /**
+ * Returns the value of the break before the element whose
+ * {@link LayoutManager#getNextKnuthElements(LayoutContext, int)} method has just been
+ * called.
+ *
+ * @return one of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
+ * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE}, or
+ * {@link Constants#EN_ODD_PAGE}
+ */
+ public int getBreakBefore() {
+ return breakBefore;
+ }
+
+ /**
+ * Sets the value of the break before the current element.
+ *
+ * @param breakBefore the value of the break-before
+ * @see #getBreakBefore()
+ */
+ public void setBreakBefore(int breakBefore) {
+ this.breakBefore = breakBefore;
+ }
+
+ /**
+ * Returns the value of the break after the element whose
+ * {@link LayoutManager#getNextKnuthElements(LayoutContext, int)} method has just been
+ * called.
+ *
+ * @return one of {@link Constants#EN_AUTO}, {@link Constants#EN_COLUMN},
+ * {@link Constants#EN_PAGE}, {@link Constants#EN_EVEN_PAGE}, or
+ * {@link Constants#EN_ODD_PAGE}
+ */
+ public int getBreakAfter() {
+ return breakAfter;
+ }
+
+
+ /**
+ * Sets the value of the break after the current element.
+ *
+ * @param breakAfter the value of the break-after
+ * @see #getBreakAfter()
+ */
+ public void setBreakAfter(int breakAfter) {
+ this.breakAfter = breakAfter;
+ }
+
/** {@inheritDoc} */
public String toString() {
return "Layout Context:" +
@@ -499,7 +550,9 @@
"\nIs Last Area: \t" + isLastArea() +
"\nTry Hyphenate: \t" + tryHyphenate() +
"\nKeeps: \t[" + (isKeepWithNextPending() ? "keep-with-next" : "") + "]["
- + (isKeepWithPreviousPending() ? "keep-with-previous" : "") + "] pending";
+ + (isKeepWithPreviousPending() ? "keep-with-previous" : "") + "] pending" +
+ "\nBreaks: \tforced [" + (breakBefore != Constants.EN_AUTO ? "break-before" : "") + "]["
+ + (breakAfter != Constants.EN_AUTO ? "break-after" : "") + "]";
}
}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/MinOptMaxUtil.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreaker.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreaker.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreaker.java Thu Mar 6 05:33:44 2008
@@ -470,7 +470,9 @@
} else if (breakVal == Constants.EN_NONE) {
curPage.getPageViewport().createSpan(false);
return;
- } else if (breakVal == Constants.EN_COLUMN || breakVal <= 0) {
+ } else if (breakVal == Constants.EN_COLUMN
+ || breakVal <= 0
+ || breakVal == Constants.EN_AUTO) {
PageViewport pv = curPage.getPageViewport();
//Check if previous page was spanned
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Thu Mar 6 05:33:44 2008
@@ -364,7 +364,13 @@
} else {
// there are no footnotes
}
- return getLineWidth(activeNode.line) - actualWidth;
+ int diff = getLineWidth(activeNode.line) - actualWidth;
+ if (autoHeight && diff < 0) {
+ //getLineWidth() for auto-height parts return 0 so the diff will be negative
+ return 0; //...but we don't want to shrink in this case. Stick to optimum.
+ } else {
+ return diff;
+ }
}
/** Checks whether footnotes from preceding pages may be deferred to the page after
@@ -732,6 +738,20 @@
pageBreaks = new LinkedList();
}
pageBreaks.addFirst(pageBreak);
+ }
+
+ /**
+ * Removes all page breaks from the result list. This is used by block-containers and
+ * static-content when it is only desired to know where there is an overflow but later the
+ * whole content should be painted as one part.
+ */
+ public void removeAllPageBreaks() {
+ if (pageBreaks == null) {
+ return;
+ }
+ while (pageBreaks.size() > 1) {
+ pageBreaks.removeFirst();
+ }
}
private int getPartCount() {
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java Thu Mar 6 05:33:44 2008
@@ -23,6 +23,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.fop.area.AreaTreeHandler;
+import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.LineArea;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.PageSequenceMaster;
@@ -88,7 +89,12 @@
}
}
- areaTreeHandler.getAreaTreeModel().startPageSequence(title);
+ AreaTreeModel areaTreeModel = areaTreeHandler.getAreaTreeModel();
+ org.apache.fop.area.PageSequence pageSequenceAreaObject
+ = new org.apache.fop.area.PageSequence(title);
+ pageSequenceAreaObject.setLanguage(getPageSequence().getLanguage());
+ pageSequenceAreaObject.setCountry(getPageSequence().getCountry());
+ areaTreeModel.startPageSequence(pageSequenceAreaObject);
if (log.isDebugEnabled()) {
log.debug("Starting layout");
}
Propchange: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Thu Mar 6 05:33:44 2008
@@ -1 +1 @@
-Author Date Id Revision
+Id
Modified: xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java?rev=634267&r1=634266&r2=634267&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ProcessingFeedback/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java Thu Mar 6 05:33:44 2008
@@ -25,9 +25,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.fop.area.RegionReference;
+
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
+import org.apache.fop.area.RegionReference;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.SideRegion;
@@ -339,11 +340,14 @@
protected void doPhase3(PageBreakingAlgorithm alg, int partCount,
BlockSequence originalList, BlockSequence effectiveList) {
- //Directly add areas after finding the breaks
- this.addAreas(alg, partCount, originalList, effectiveList);
if (partCount > 1) {
overflow = true;
}
+ //Rendering all parts (not just the first) at once for the case where the parts that
+ //overflow should be visible.
+ alg.removeAllPageBreaks();
+ //Directly add areas after finding the breaks
+ this.addAreas(alg, 1, originalList, effectiveList);
}
protected void finishPart(PageBreakingAlgorithm alg, PageBreakPosition pbp) {
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org