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 vh...@apache.org on 2008/06/19 12:56:52 UTC
svn commit: r669448 [1/2] - in
/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java:
./ src/ src/org/ src/org/apache/ src/org/apache/fop/
src/org/apache/fop/prototype/ src/org/apache/fop/prototype/breaking/
src/org/apache/fop/pr...
Author: vhennebert
Date: Thu Jun 19 03:56:51 2008
New Revision: 669448
URL: http://svn.apache.org/viewvc?rev=669448&view=rev
Log:
A Java version of the prototype for interleaved page and line breaking
Added:
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java (with props)
xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.java (with props)
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,113 @@
+/*
+ * 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.prototype;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+import org.apache.fop.prototype.knuth.KnuthElement;
+
+
+/**
+ * A class that creates a graph of layouts in the dot format and renders it into PDF.
+ */
+public class Dot {
+
+ private static String getLayoutID(Layout l) {
+ return String.valueOf(l.hashCode());
+ }
+
+ private static void dumpLayout(Layout l, PrintStream s, Set<Layout> handled) {
+ if (!handled.contains(l)) {
+ handled.add(l);
+ if (l.getPrevious() == null) {
+ s.print(" \"");
+ s.print(getLayoutID(l));
+ s.println("\" [label=\"\" shape=box width=0.2 height=0.2]");
+ } else {
+ Layout previousLayout = l.getPrevious();
+// if (l instanceof LineLayout && l.getProgress().getTotalLength() == 0) {
+// previousLayout = previousLayout.getPrevious();
+// }
+ if (previousLayout instanceof LineLayout
+ && ((LineLayout) previousLayout).getLineLayout().getProgress()
+ .getPartNumber() == 0) {
+ previousLayout = previousLayout.getPrevious();
+ }
+ dumpLayout(previousLayout, s, handled);
+ StringBuilder label = new StringBuilder();
+ StringBuilder shape = new StringBuilder();
+ if (l.getProgress().getTotalLength() == 0) {
+ shape.append("shape=box");
+ for (KnuthElement e: l.getPrevious().getElements()) {
+ label.append(e.getLabel());
+ label.append("\\l");
+ }
+ } else {
+ for (KnuthElement e: l.getElements()) {
+ label.append(e.getLabel());
+ label.append("\\l");
+ }
+ }
+ s.printf(" \"%s\" [%s label=\"%s\"]%n", getLayoutID(l), shape, label);
+ s.printf(" \"%s\" -> \"%s\"%n", getLayoutID(previousLayout), getLayoutID(l));
+ for (Layout a: l.getAlternatives()) {
+ dumpLayout(a, s, handled);
+ s.printf(" \"%s\" -> \"%s\" [style=dashed]%n", getLayoutID(a), getLayoutID(l));
+ }
+ }
+ }
+ }
+
+ public static void createGraph(Iterable<Layout> layouts) throws Exception {
+ PrintStream s = new PrintStream(new File("/tmp/res.dot"));
+ Set<Layout> handled = new HashSet<Layout>();
+// page="8.27,11.69"
+// size="11,16"
+// margin="0.3"
+ s.println("digraph ActiveNodes {");
+ s.println("nodesep=.5; ranksep=1.5");
+ s.println("node [shape=none fontname=\"Nimbus Roman No9 L\"]");
+ s.println("edge [dir=none]");
+ for (Layout l: layouts) {
+ dumpLayout(l, s, handled);
+ }
+ s.println('}');
+ s.close();
+ Process p = Runtime.getRuntime().exec(
+ new String[] { "dot", "-Tpdf", "-o/tmp/res.pdf", "/tmp/res.dot" });
+ p.waitFor();
+ InputStream err = p.getErrorStream();
+ int b;
+ while ((b = err.read()) >= 0) {
+ System.err.write(b);
+ }
+ err.close();
+ int exitValue = p.exitValue();
+ if (exitValue != 0) {
+ System.err.println("dot exited with value " + exitValue);
+ }
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/Dot.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,102 @@
+/*
+ * 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.prototype;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.fop.prototype.breaking.LineBreakHandler;
+import org.apache.fop.prototype.breaking.LineBreaker;
+import org.apache.fop.prototype.breaking.PageBreakHandler;
+import org.apache.fop.prototype.breaking.PageBreaker;
+import org.apache.fop.prototype.breaking.PageDimensions;
+import org.apache.fop.prototype.breaking.ParagraphBreakHandler;
+import org.apache.fop.prototype.fo.Paragraph;
+import org.apache.fop.prototype.font.Font;
+import org.apache.fop.prototype.knuth.Glue;
+import org.apache.fop.prototype.knuth.Penalty;
+
+
+/**
+ * A layout engine that typesets various kinds of typographical material.
+ */
+public class LayoutEngine {
+
+ private PageBreakHandler pageBreakHandler;
+
+ private ParagraphBreakHandler paragraphBreakHandler;
+
+ private LineBreakHandler lineBreakHandler;
+
+ public LayoutEngine(List<PageDimensions> pageDims) {
+ pageBreakHandler = new PageBreakHandler(pageDims);
+ paragraphBreakHandler = new ParagraphBreakHandler(pageDims);
+ lineBreakHandler = new LineBreakHandler(pageDims);
+ }
+
+ public void typeset(List<? extends TypographicElement> content) {
+ LineBreaker lineBreaker = new LineBreaker(lineBreakHandler, paragraphBreakHandler);
+ PageBreaker pageBreaker = new PageBreaker(pageBreakHandler, lineBreaker);
+ pageBreaker.findBreaks(content);
+ }
+
+ public static void main(String[] args) {
+ List<TypographicElement> paragraphs = new LinkedList<TypographicElement>();
+ paragraphs.add(new Paragraph(Arrays.asList(new String[] { "In", "olden", "times", "when",
+ "wishing", "still", "helped", "one,", "there", "lived", "a", "king", "whose",
+ "daughters", "were", "all", "beautiful,", "soooo", "much", "beautiful." }),
+ Font.TIMES_FONT));
+ paragraphs.add(Penalty.DEFAULT_PENALTY);
+ paragraphs.add(new Glue(1, 1, 0));
+ paragraphs.add(new Paragraph(Arrays.asList(new String[] { "In", "olden", "times", "when",
+ "wishing", "still", "helped", "one,", "there", "lived", "a", "king", "whose",
+ "daughters", "were", "all", "beautiful,", "but", "the", "youngest", "was", "so",
+ "beautiful", "that", "the", "sun", "itself,", "which", "has", "seen", "so",
+ "much,", "was", "astonished", "whenever", "it", "shone", "in", "her", "face." }),
+ Font.TIMES_FONT));
+// paragraphs.add(Penalty.DEFAULT_PENALTY);
+// paragraphs.add(new Glue(2, 0, 1));
+// paragraphs.add(new Paragraph(Arrays.asList(new String[] { "And", "now", "I", "am", "about",
+// "to", "start", "the", "next", "paragraph", "and", "the", "goal", "is", "to",
+// "check", "that", "the", "algorithm", "is", "working", "properly,", "a", "thing",
+// "I", "am", "not", "quite", "sure", "of." }), Font.TIMES_FONT));
+// paragraphs.add(Penalty.DEFAULT_PENALTY);
+// paragraphs.add(new Glue(2, 0, 1));
+// paragraphs.add(new Paragraph(Arrays.asList(new String[] { "In", "olden", "times", "when",
+// "wishing", "still", "helped", "one,", "there", "lived", "a", "king", "whose",
+// "daughters", "were", "all", "beautiful,", "but", "the", "youngest", "was", "so",
+// "beautiful", "that", "the", "sun", "itself,", "which", "has", "seen", "so",
+// "much,", "was", "astonished", "whenever", "it", "shone", "in", "her", "face." }),
+// Font.TIMES_FONT));
+ paragraphs.add(new Glue(0, 1000000, 0));
+ paragraphs.add(new Penalty(0, -Penalty.INFINITE));
+
+ List<PageDimensions> pageDims = new LinkedList<PageDimensions>();
+ pageDims.add(new PageDimensions(13000, 8));
+ pageDims.add(new PageDimensions(16000, 8));
+ pageDims.add(new PageDimensions(13000, 8));
+ pageDims.add(new PageDimensions(13000, 8));
+ pageDims.add(new PageDimensions(13000, 8));
+
+ new LayoutEngine(pageDims).typeset(paragraphs);
+ }
+}
+
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/LayoutEngine.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,27 @@
+/*
+ * 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.prototype;
+
+/**
+ * A marker interface for elements handled by the breaking algorithm. Typographic elements
+ * are divided into two main categories:
+ * {@link org.apache.fop.prototype.knuth.KnuthElement Knuth elements} and Formatting Objects.
+ */
+public interface TypographicElement { }
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/TypographicElement.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,223 @@
+/*
+ * 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.prototype.breaking;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.ProgressInfo;
+import org.apache.fop.prototype.knuth.KnuthElement;
+
+
+/**
+ * TODO javadoc
+ */
+class ActiveLayouts<L extends Layout> implements Iterable<L> {
+
+ private class ListMap<K, V> {
+
+ private Map<K, Set<V>> backingMap = new HashMap<K, Set<V>>();
+
+ public void put(K key, V value) {
+ Set<V> set = backingMap.get(key);
+ if (set == null) {
+ set = new HashSet<V>();
+ backingMap.put(key, set);
+ }
+ set.add(value);
+ }
+
+ public void removeValue(K key, V value) {
+ Set<V> set = backingMap.get(key);
+ if (set != null) {
+ set.remove(value);
+ }
+ }
+
+ public void clear() {
+ backingMap.clear();
+ }
+
+ public Iterator<Iterator<V>> keyIterator() {
+ final Iterator<Map.Entry<K, Set<V>>> keyIter = backingMap.entrySet().iterator();
+ return new Iterator<Iterator<V>>() {
+
+ private Set<V> nextSet;
+
+ @Override
+ public boolean hasNext() {
+ while (keyIter.hasNext()) {
+ nextSet = keyIter.next().getValue();
+ if (!nextSet.isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Iterator<V> next() {
+ return nextSet.iterator();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ };
+ }
+ }
+
+ private ListMap<Integer, L> blockClasses = new ListMap<Integer, L>();
+
+ private ListMap<ProgressInfo, L> lineClasses = new ListMap<ProgressInfo, L>();
+
+ private List<L> layouts = new LinkedList<L>();
+
+ void setLayoutsFrom(ActiveLayouts<? extends L> other) {
+ blockClasses.clear();
+ lineClasses.clear();
+ layouts.clear();
+ for (L layout: other) {
+ add(layout);
+ }
+ }
+
+ void add(L layout) {
+ ProgressInfo progress = layout.getProgress();
+ blockClasses.put(progress.getPartNumber(), layout);
+ lineClasses.put(progress.copy(), layout);
+ layouts.add(layout);
+ }
+
+ void updateLayouts(KnuthElement e, Breaker<L> breaker) {
+ assert e.isBox() || e.isGlue();
+ ListMap<ProgressInfo, L> newMap = new ListMap<ProgressInfo, L>();
+ for (L l: layouts) {
+ breaker.getLayout(l).addElement(e);
+ newMap.put(l.getProgress(), l);
+ }
+ lineClasses = newMap;
+ }
+
+ boolean isEmpty() {
+ return layouts.isEmpty();
+ }
+
+ private abstract class AbstractClassIterator<K> implements Iterator<Iterator<L>> {
+
+ private Iterator<Iterator<L>> iter;
+
+ private final ListMap<K, L> other;
+
+ /**
+ * @param iter
+ */
+ AbstractClassIterator(Iterator<Iterator<L>> iter, ListMap<K, L> other) {
+ this.iter = iter;
+ this.other = other;
+ }
+
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ abstract K getKey(L l);
+
+ public Iterator<L> next() {
+ final Iterator<L> backingIter = iter.next();
+ return new Iterator<L>() {
+
+ L currentLayout;
+
+ @Override
+ public boolean hasNext() {
+ return backingIter.hasNext();
+ }
+
+ @Override
+ public L next() {
+ currentLayout = backingIter.next();
+ return currentLayout;
+ }
+
+ @Override
+ public void remove() {
+ backingIter.remove();
+ other.removeValue(getKey(currentLayout), currentLayout);
+ layouts.remove(currentLayout);
+ }
+ };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ }
+
+ Iterator<Iterator<L>> getBlockClassIterator() {
+ return new AbstractClassIterator<ProgressInfo>(blockClasses.keyIterator(), lineClasses) {
+
+ @Override
+ ProgressInfo getKey(L l) {
+ return l.getProgress();
+ }
+ };
+ }
+
+ Iterator<Iterator<L>> getLineClassIterator() {
+ return new AbstractClassIterator<Integer>(lineClasses.keyIterator(), blockClasses) {
+
+ @Override
+ Integer getKey(L l) {
+ return l.getProgress().getPartNumber();
+ }
+ };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Iterator<L> iterator() {
+ return layouts.iterator();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ StringBuilder s = new StringBuilder();
+ for (L l: layouts) {
+ s.append(l);
+ if (s.charAt(s.length() - 1) != '\n') {
+ s.append('\n');
+ }
+ s.append('\n');
+ }
+ return s.toString();
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ActiveLayouts.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.prototype.breaking;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.ProgressInfo;
+import org.apache.fop.prototype.knuth.Penalty;
+
+
+/**
+ * TODO javadoc
+ */
+abstract class BlockLevelBreakHandler<L extends Layout> extends LegalBreakHandler<L> {
+
+ private List<PageDimensions> pageDims;
+
+ public BlockLevelBreakHandler(List<PageDimensions> pageDims) {
+ this.pageDims = pageDims;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected Iterator<Iterator<L>> getClassIter(ActiveLayouts<L> layouts) {
+ return layouts.getBlockClassIterator();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected int computeDifference(L layout, Penalty p) {
+ return pageDims.get(layout.getProgress().getPartNumber()).getBpd()
+ - layout.getProgress().getTotalLength();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected ProgressInfo getProgress(L layout) {
+ return layout.getProgress();
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreakHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java Thu Jun 19 03:56:51 2008
@@ -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.prototype.breaking;
+
+import org.apache.fop.prototype.breaking.layout.Layout;
+
+/**
+ * TODO javadoc
+ */
+public abstract class BlockLevelBreaker<L extends Layout> extends Breaker<L> {
+
+ /** {@inheritDoc} */
+ @Override
+ Layout getLayout(Layout layout) {
+ return layout;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/BlockLevelBreaker.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,97 @@
+/*
+ * 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.prototype.breaking;
+
+import java.util.List;
+
+import org.apache.fop.prototype.TypographicElement;
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+import org.apache.fop.prototype.knuth.KnuthElement;
+import org.apache.fop.prototype.knuth.Penalty;
+
+
+/**
+ * Base class for breaking a list of elements into parts (pages, lines...).
+ */
+abstract class Breaker<L extends Layout> {
+
+ protected ActiveLayouts<L> layouts;
+
+ private Breaker<?> parentBreaker;
+
+ public void findBreaks(List<? extends TypographicElement> content) {
+ initBreaking();
+ for (TypographicElement e: content) {
+ if (e instanceof KnuthElement) {
+ KnuthElement k = (KnuthElement) e;
+ if (k.isBox() || k.isGlue()) {
+ layouts.updateLayouts(k, this);
+ } else if (k.isPenalty()) {
+ Penalty p = (Penalty) k;
+ if (p.getPenalty() < Penalty.INFINITE) {
+ considerLegalBreak(p);
+ }
+ }
+ } else {
+ handleElement(e);
+ }
+ }
+ endBreaking();
+ }
+
+ /**
+ * @return the parentBreaker
+ */
+ Breaker<?> getParentBreaker() {
+ return parentBreaker;
+ }
+
+ /**
+ * @param parentBreaker the parentBreaker to set
+ */
+ void setParentBreaker(Breaker<?> parentBreaker) {
+ this.parentBreaker = parentBreaker;
+ }
+
+ /** Performs optional necessary stuff before the breaking starts. */
+ protected void initBreaking() { }
+
+ /**
+ * Returns the sub-layout of the given layout that holds progress information for this
+ * kind of breaking. For page breaking this is the layout itself, for line breaking
+ * this is the enclosed layout that holds line-level information.
+ *
+ * @param layout a layout
+ * @return the sub-layout corresponding to the kind of breaking performed by this
+ * object.
+ * @see LineLayout#getLineLayout()
+ */
+ abstract Layout getLayout(L layout);
+
+ protected abstract void considerLegalBreak(Penalty p);
+
+ void newLayoutsFound(LineBreaker breaker, ActiveLayouts<LineLayout> newLayouts) { }
+
+ protected void handleElement(TypographicElement e) { }
+
+ /** Performs optional operations once the breaking is finished. */
+ protected void endBreaking() { }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/Breaker.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,81 @@
+/*
+ * 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.prototype.breaking;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.fop.prototype.breaking.layout.Layout;
+
+
+/**
+ * TODO javadoc
+ */
+class FeasibleBreaks<L extends Layout> {
+
+ static class BestBreak<L> {
+
+ L layout;
+
+ double demerits;
+
+ int difference;
+
+ /**
+ * @param layout
+ * @param demerits
+ * @param difference
+ */
+ BestBreak(L layout, double demerits, int difference) {
+ this.layout = layout;
+ this.demerits = demerits;
+ this.difference = difference;
+ }
+
+ void set(L layout, double demerits, int difference) {
+ this.layout = layout;
+ this.demerits = demerits;
+ this.difference = difference;
+ }
+ }
+
+ private BestBreak<L> best = null;
+
+ private Collection<Layout> alternatives = new LinkedList<Layout>();
+
+ void add(L layout, double demerits, int difference) {
+ if (best == null) {
+ best = new BestBreak<L>(layout, demerits, difference);
+ } else if (demerits < best.demerits) {
+ alternatives.add(best.layout);
+ best.set(layout, demerits, difference);
+ } else {
+ alternatives.add(layout);
+ }
+ }
+
+ BestBreak<L> getBest() {
+ return best;
+ }
+
+ Collection<Layout> getAlternatives() {
+ return alternatives;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/FeasibleBreaks.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java Thu Jun 19 03:56:51 2008
@@ -0,0 +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.prototype.breaking;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.fop.prototype.breaking.FeasibleBreaks.BestBreak;
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+import org.apache.fop.prototype.breaking.layout.ProgressInfo;
+import org.apache.fop.prototype.knuth.Penalty;
+
+
+/**
+ * Base class for handling legal breaks. It iterates over active layouts and considers
+ * whether they complete a part (a page, a line...).
+ */
+abstract class LegalBreakHandler<L extends Layout> {
+
+ static final int INFINITE_RATIO = 1000;
+
+ ActiveLayouts<L> considerBreak(Penalty p, ActiveLayouts<L> layouts) {
+ ActiveLayouts<L> newLayouts = new ActiveLayouts<L>();
+ for (Iterator<Iterator<L>> classIter = getClassIter(layouts); classIter.hasNext();) {
+ FeasibleBreaks<L> feasibleBreaks = new FeasibleBreaks<L>();
+ for (Iterator<L> layoutIter = classIter.next(); layoutIter.hasNext();) {
+ L layout = layoutIter.next();
+ int difference = computeDifference(layout, p) - p.getLength();
+ double ratio = computeAdjustmentRatio(getProgress(layout), difference);
+ if (ratio < -1.0 || p.isForcedBreak()) {
+ difference = 0; // TODO
+ layoutIter.remove();
+ }
+ if (-1.0 <= ratio && ratio <= getThreshold()) {
+ double d = computeDemerits(p, ratio) + getDemerits(layout);
+ feasibleBreaks.add(layout, d, difference);
+ }
+ }
+ BestBreak<L> best = feasibleBreaks.getBest();
+ if (best != null) {
+ newLayouts.add(createLayout(best, feasibleBreaks.getAlternatives()));
+ }
+ }
+ if (!newLayouts.isEmpty()) {
+ for (L l : newLayouts) {
+ layouts.add(l);
+ // TODO $log.debug("After break:")
+ // TODO $log.debug("#{layouts}")
+ }
+ }
+ return newLayouts;
+ }
+
+ /**
+ * Returns an iterator for iterating over sets of layouts of the same class. The
+ * notion of class equivalence differs whether we are at the page or line level.
+ *
+ * @param layouts active layouts to iterate over
+ * @return an iterator over sets of layouts of the same class
+ */
+ protected abstract Iterator<Iterator<L>> getClassIter(ActiveLayouts<L> layouts);
+
+ /**
+ * Returns the maximum adjustment ratio allowed for feasible breaks.
+ *
+ * @return a threshold above which layouts are considered to be too much stretched
+ */
+ protected double getThreshold() {
+ return 1.0;
+ }
+
+ /**
+ * Computes the difference between the dimension of the part corresponding to the
+ * given layout, and the space actually occupied by that latter.
+ *
+ * @param layout a layout
+ * @param p the penalty corresponding to the currently considered legal break
+ * @return the difference between the part's dimension and the natural length of the
+ * layout elements
+ */
+ protected abstract int computeDifference(L layout, Penalty p);
+
+ /**
+ * Returns the (sub-)layout of the given layout that holds progress information for
+ * this kind of breaking. For page breaking this is the layout itself, for line
+ * breaking this is the enclosed layout that holds line-level information.
+ *
+ * @param layout a layout
+ * @return the sub-layout corresponding to the kind of breaking performed by this
+ * object.
+ * @see LineLayout#getLineLayout()
+ */
+ protected abstract ProgressInfo getProgress(L layout); // TODO redundant with Breaker#getLayout
+
+ /**
+ * Returns the demerits associated to the given layout, for the kind of breaking
+ * performed by this object (line-level or block-level).
+ *
+ * @param layout a layout
+ * @return the layout's demerits
+ */
+ protected abstract double getDemerits(L layout);
+
+ /**
+ * Creates and returns a new layout based on the given best break.
+ *
+ * @param best the best layout for the currently considered layout class
+ * @param alternatives alternative feasible layouts
+ * @return a layout for the new part
+ */
+ protected abstract L createLayout(BestBreak<L> best, Collection<Layout> alternatives);
+
+ private double computeAdjustmentRatio(ProgressInfo progress, int difference) {
+ if (difference > 0.0) {
+ int stretch = progress.getTotalStretch();
+ if (stretch > 0) {
+ return ((double) difference) / ((double) stretch);
+ } else {
+ return INFINITE_RATIO;
+ }
+ } else if (difference < 0.0) {
+ int shrink = progress.getTotalShrink();
+ if (shrink > 0) {
+ return ((double) difference) / ((double) shrink);
+ } else {
+ return -INFINITE_RATIO;
+ }
+ } else {
+ return 0.0;
+ }
+ }
+
+ private double computeDemerits(Penalty penalty, double ratio) {
+ double d = 1 + 100 * Math.pow(Math.abs(ratio), 3);
+ int p = penalty.getPenalty();
+ if (p > 0) {
+ return Math.pow(d + p, 2);
+ } else if (!penalty.isForcedBreak()) {
+ return d * d - p * p;
+ } else {
+ return d * d;
+ }
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LegalBreakHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.prototype.breaking;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.fop.prototype.breaking.FeasibleBreaks.BestBreak;
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+import org.apache.fop.prototype.breaking.layout.ProgressInfo;
+import org.apache.fop.prototype.font.Font;
+import org.apache.fop.prototype.knuth.KnuthElement;
+import org.apache.fop.prototype.knuth.LineBox;
+import org.apache.fop.prototype.knuth.Penalty;
+
+
+/**
+ * TODO javadoc
+ */
+public class LineBreakHandler extends LegalBreakHandler<LineLayout> {
+
+ private List<PageDimensions> pageDims;
+
+ public LineBreakHandler(List<PageDimensions> pageDims) {
+ this.pageDims = pageDims;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected Iterator<Iterator<LineLayout>> getClassIter(ActiveLayouts<LineLayout> layouts) {
+ return layouts.getLineClassIterator();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getThreshold() {
+ return 7.6;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected int computeDifference(LineLayout layout, Penalty p) {
+ return pageDims.get(layout.getProgress().getPartNumber()).getIpd()
+ - layout.getLineLayout().getProgress().getTotalLength();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected ProgressInfo getProgress(LineLayout layout) {
+ return layout.getLineLayout().getProgress();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getDemerits(LineLayout layout) {
+ return layout.getLineLayout().getDemerits();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected LineLayout createLayout(BestBreak<LineLayout> best, Collection<Layout> alternatives) {
+ List<KnuthElement> elements = new LinkedList<KnuthElement>(best.layout.getLineLayout()
+ .getElements());
+ LineBox lineBox = new LineBox(1/*TODO line bpd*/, elements, best.difference, Font.TIMES_FONT
+ .getCharWidth(' ')/*TODO*/);
+ LineLayout newLayout = LineLayout.createLayoutForNewLine(best.layout, best.demerits,
+ alternatives);
+ newLayout.addElement(lineBox);
+
+ return newLayout;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreakHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java Thu Jun 19 03:56:51 2008
@@ -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.prototype.breaking;
+
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+import org.apache.fop.prototype.knuth.Penalty;
+
+/**
+ * A breaker for paragraphs.
+ */
+public class LineBreaker extends Breaker<LineLayout> {
+
+ private LineBreakHandler lineBreakHandler;
+
+ private BlockLevelBreakHandler<LineLayout> pageBreakHandler;
+
+
+ /**
+ * @param lineBreakHandler
+ * @param pageBreakHandler
+ */
+ public LineBreaker(LineBreakHandler lineBreakHandler, BlockLevelBreakHandler<LineLayout> pageBreakHandler) {
+ this.lineBreakHandler = lineBreakHandler;
+ this.pageBreakHandler = pageBreakHandler;
+ }
+
+ protected BlockLevelBreakHandler<LineLayout> getPageBreakHandler() {
+ return pageBreakHandler;
+ }
+
+ void setLayouts(ActiveLayouts<LineLayout> layouts) {
+ this.layouts = layouts;
+ }
+
+ void integrateBlockLayouts(ActiveLayouts<LineLayout> blockLayouts) {
+ for (LineLayout l: blockLayouts) {
+ layouts.add(l);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ Layout getLayout(LineLayout layout) {
+ return layout.getLineLayout();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void considerLegalBreak(Penalty p) {
+ ActiveLayouts<LineLayout> newLayouts = lineBreakHandler.considerBreak(p, layouts);
+ if (!newLayouts.isEmpty()) {
+ getParentBreaker().newLayoutsFound(this, newLayouts);
+ }
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/LineBreaker.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.prototype.breaking;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.fop.prototype.breaking.FeasibleBreaks.BestBreak;
+import org.apache.fop.prototype.breaking.layout.Layout;
+
+
+/**
+ * TODO javadoc
+ */
+public class PageBreakHandler extends BlockLevelBreakHandler<Layout> {
+
+ public PageBreakHandler(List<PageDimensions> pageDims) {
+ super(pageDims);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getDemerits(Layout layout) {
+ return layout.getDemerits();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected Layout createLayout(BestBreak<Layout> best, Collection<Layout> alternatives) {
+ return Layout.createLayoutForNewPart(best.layout, best.demerits, alternatives);
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreakHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.prototype.breaking;
+
+import org.apache.fop.prototype.Dot;
+import org.apache.fop.prototype.TypographicElement;
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+import org.apache.fop.prototype.fo.Paragraph;
+import org.apache.fop.prototype.knuth.Penalty;
+
+/**
+ * A breaker that builds pages.
+ */
+public class PageBreaker extends BlockLevelBreaker<Layout> {
+
+ private PageBreakHandler pageBreakHandler;
+
+ private LineBreaker lineBreaker;
+
+ /**
+ * @param pageBreakHandler
+ * @param lineBreaker
+ */
+ public PageBreaker(PageBreakHandler pageBreakHandler, LineBreaker lineBreaker) {
+ this.pageBreakHandler = pageBreakHandler;
+ this.lineBreaker = lineBreaker;
+ this.lineBreaker.setParentBreaker(this);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void initBreaking() {
+ layouts = new ActiveLayouts<Layout>();
+ layouts.add(new Layout());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void considerLegalBreak(Penalty p) {
+ pageBreakHandler.considerBreak(p, layouts);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ void newLayoutsFound(LineBreaker breaker, ActiveLayouts<LineLayout> newLayouts) {
+ newLayouts = breaker.getPageBreakHandler().considerBreak(
+ Penalty.DEFAULT_PENALTY, newLayouts);
+ breaker.integrateBlockLayouts(newLayouts);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void handleElement(TypographicElement e) {
+ if (e instanceof Paragraph) {
+ ActiveLayouts<LineLayout> lineLayouts = new ActiveLayouts<LineLayout>();
+ for (Layout l: layouts) {
+ lineLayouts.add(new LineLayout(l));
+ }
+ lineBreaker.setLayouts(lineLayouts);
+ lineBreaker.findBreaks(((Paragraph) e).getKnuthElements());
+ layouts.setLayoutsFrom(lineLayouts);
+ }
+ }
+
+ /** Creates a graph of all the layouts created by this breaker, in PDF format. */
+ @Override
+ protected void endBreaking() {
+ try {
+ Dot.createGraph(layouts);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageBreaker.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java Thu Jun 19 03:56:51 2008
@@ -0,0 +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.prototype.breaking;
+
+/**
+ * TODO javadoc
+ */
+public class PageDimensions {
+
+ private int ipd;
+
+ private int bpd;
+
+ /**
+ * @param ipd
+ * @param bpd
+ */
+ public PageDimensions(int ipd, int bpd) {
+ this.ipd = ipd;
+ this.bpd = bpd;
+ }
+
+ /**
+ * @return the ipd
+ */
+ public int getIpd() {
+ return ipd;
+ }
+
+ /**
+ * @return the bpd
+ */
+ public int getBpd() {
+ return bpd;
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/PageDimensions.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java Thu Jun 19 03:56:51 2008
@@ -0,0 +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.prototype.breaking;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.fop.prototype.breaking.FeasibleBreaks.BestBreak;
+import org.apache.fop.prototype.breaking.layout.Layout;
+import org.apache.fop.prototype.breaking.layout.LineLayout;
+
+
+/**
+ * TODO javadoc
+ */
+public class ParagraphBreakHandler extends BlockLevelBreakHandler<LineLayout> {
+
+ /**
+ * @param pageDims
+ */
+ public ParagraphBreakHandler(List<PageDimensions> pageDims) {
+ super(pageDims);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getDemerits(LineLayout layout) {
+ return layout.getDemerits() + layout.getLineLayout().getDemerits();//TODO
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected LineLayout createLayout(BestBreak<LineLayout> best, Collection<Layout> alternatives) {
+ return LineLayout.createLayoutForNewPart(best.layout, best.demerits, alternatives);
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/ParagraphBreakHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,121 @@
+/*
+ * 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.prototype.breaking.layout;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.fop.prototype.knuth.Glue;
+import org.apache.fop.prototype.knuth.KnuthElement;
+
+
+/**
+ * TODO javadoc
+ */
+public class Layout {
+
+ protected Layout previous;
+
+ /** The demerits represented by this layout plus all of its predecessors. */
+ protected double demerits;
+
+ protected ProgressInfo progress;
+
+ protected Collection<Layout> alternatives;
+
+ protected List<KnuthElement> elements;
+
+ /** Creates an empty layout starting on part 0. */
+ public Layout() {
+ previous = null;
+ demerits = 0;
+ progress = new ProgressInfo();
+ elements = new LinkedList<KnuthElement>();
+ }
+
+ /** Creates a deep copy of the given layout. */
+ Layout(Layout other) {
+ previous = other.previous;
+ demerits = other.demerits;
+ progress = new ProgressInfo(other.progress);
+ if (other.alternatives != null) {
+ alternatives = new LinkedList<Layout>(other.alternatives);
+ }
+ elements = new LinkedList<KnuthElement>(other.elements);
+ }
+
+ public static Layout createLayoutForNewPart(Layout previous, double demerits,
+ Collection<Layout> alternatives) {
+ Layout l = new Layout();
+ l.previous = previous;
+ l.demerits = demerits;
+ l.progress.setPartNumber(previous.getProgress().getPartNumber() + 1);
+ l.alternatives = alternatives;
+ return l;
+ }
+
+ Layout copy() {
+ return new Layout(this);
+ }
+
+ public Layout getPrevious() {
+ return previous;
+ }
+
+ /** Returns the demerits represented by this layout plus all of its predecessors. */
+ public double getDemerits() {
+ return demerits;
+ }
+
+ public ProgressInfo getProgress() {
+ return progress;
+ }
+
+ public Collection<Layout> getAlternatives() {
+ return Collections.unmodifiableCollection(alternatives);
+ }
+
+ public List<KnuthElement> getElements() {
+ return Collections.unmodifiableList(elements);
+ }
+
+ public void addElement(KnuthElement e) {
+ if (e.isBox() || !elements.isEmpty()) {
+ if (e.isGlue()) {
+ Glue g = (Glue) e;
+ progress.add(g.getLength(), g.getStretch(), g.getShrink());
+ } else {
+ progress.add(e.getLength());
+ }
+ elements.add(e);
+ }
+ }
+
+ public String toString() {
+ StringBuilder s = new StringBuilder();
+ for (KnuthElement e: elements) {
+ s.append(e.getLabel());
+ s.append('\n');
+ }
+ return s.toString();
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/Layout.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.prototype.breaking.layout;
+
+import java.util.Collection;
+
+import org.apache.fop.prototype.knuth.KnuthElement;
+
+
+/**
+ * TODO javadoc
+ */
+public class LineLayout extends Layout {
+
+ private Layout lineLayout;
+
+ private LineLayout() { }
+
+ /**
+ * Creates an empty layout starting on line 0.
+ *
+ * @param blockLayout the block-level layout preceding this one. That is, the layout
+ * containing the elements preceding this line-level element.
+ */
+ public LineLayout(Layout blockLayout) {
+ super(blockLayout);
+ previous = blockLayout;
+ lineLayout = new Layout();
+ }
+
+ public static LineLayout createLayoutForNewLine(LineLayout previous, double demerits,
+ Collection<Layout> alternatives) {
+ LineLayout l = new LineLayout(previous);
+ l.lineLayout = Layout.createLayoutForNewPart(previous, demerits, null);
+ l.alternatives = alternatives;
+ return l;
+ }
+
+ public static LineLayout createLayoutForNewPart(LineLayout previous, double demerits,
+ Collection<Layout> alternatives) {
+ LineLayout l = new LineLayout();
+ l.previous = previous;
+ l.demerits = demerits;
+ l.progress.setPartNumber(previous.progress.getPartNumber() + 1);
+ l.alternatives = alternatives;
+ l.lineLayout = previous.lineLayout.copy();
+ return l;
+ }
+
+ public Layout getLineLayout() {
+ return lineLayout;
+ }
+
+ String getLineLabel() {
+ StringBuilder label = new StringBuilder();
+ label.append("[ ");
+ for (KnuthElement e: lineLayout.getElements()) {
+ label.append(e.toString());
+ }
+ label.append(" ]");
+ return label.toString();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ StringBuilder s = new StringBuilder(super.toString());
+ s.append('[');
+ for (KnuthElement e: lineLayout.getElements()) {
+ s.append(e.getLabel());
+ }
+ s.append(']');
+ return s.toString();
+ }
+
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/LineLayout.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,104 @@
+/*
+ * 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.prototype.breaking.layout;
+
+/**
+ * TODO javadoc
+ */
+public class ProgressInfo {
+
+ private int totalLength;
+
+ private int totalStretch;
+
+ private int totalShrink;
+
+ private int partNumber;
+
+ ProgressInfo() { }
+
+ ProgressInfo(ProgressInfo o) {
+ this.totalLength = o.totalLength;
+ this.totalStretch = o.totalStretch;
+ this.totalShrink = o.totalShrink;
+ this.partNumber = o.partNumber;
+ }
+
+ public ProgressInfo copy() {
+ return new ProgressInfo(this);
+ }
+
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+ /**
+ * @return the totalStretch
+ */
+ public int getTotalStretch() {
+ return totalStretch;
+ }
+
+ /**
+ * @return the totalShrink
+ */
+ public int getTotalShrink() {
+ return totalShrink;
+ }
+
+ public int getPartNumber() {
+ return partNumber;
+ }
+
+ void setPartNumber(int partNumber) {
+ this.partNumber = partNumber;
+ }
+
+ void add(int length) {
+ totalLength += length;
+ }
+
+ void add(int length, int stretch, int shrink) {
+ add(length);
+ totalStretch += stretch;
+ totalShrink += shrink;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean equals(Object o) {
+ assert o instanceof ProgressInfo;
+ ProgressInfo p = (ProgressInfo) o;
+ return this.totalLength == p.totalLength && this.totalStretch == p.totalStretch
+ && this.totalShrink == p.totalShrink && this.partNumber == p.partNumber;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int hashCode() {
+ return Integer.valueOf(totalLength).hashCode();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String toString() {
+ return totalLength + "+" + totalStretch + "â" + totalShrink;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/breaking/layout/ProgressInfo.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.prototype.fo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.fop.prototype.TypographicElement;
+import org.apache.fop.prototype.font.Font;
+import org.apache.fop.prototype.knuth.Box;
+import org.apache.fop.prototype.knuth.Glue;
+import org.apache.fop.prototype.knuth.KnuthElement;
+import org.apache.fop.prototype.knuth.Penalty;
+
+
+/**
+ * A paragraph
+ */
+public class Paragraph implements TypographicElement {
+
+ private List<String> words;
+
+ private Font font;
+
+ public Paragraph(List<String> words, Font font) {
+ this.words = words;
+ this.font = font;
+ }
+
+ public List<KnuthElement> getKnuthElements() {
+ List<KnuthElement> elements = new ArrayList<KnuthElement>(3 * words.size() + 2);
+ int spaceWidth = font.getCharWidth(' ');
+ for (String word: words) {
+ elements.add(new Box(getWordWidth(word), word));
+ elements.add(Penalty.DEFAULT_PENALTY);
+ elements.add(new Glue(spaceWidth, spaceWidth / 2, spaceWidth / 3, " "));
+ }
+ elements.set(elements.size() - 2, new Glue(0, 1000000, 0));
+ elements.set(elements.size() - 1, new Penalty(0, -Penalty.INFINITE));
+ return elements;
+ }
+
+ private int getWordWidth(String word) {
+ int w = 0;
+ for (int i = 0; i < word.length(); i++) {
+ w += font.getCharWidth(word.charAt(i));
+ }
+ return w;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/fo/Paragraph.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org
Re: svn commit: r669448 [1/2] - in /xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java:
./ src/ src/org/ src/org/apache/ src/org/apache/fop/ src/org/apache/fop/prototype/
src/org/apache/fop/prototype/breaking/ src/org/apache/fop/pr...
Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Hi,
> Author: vhennebert
> Date: Thu Jun 19 03:56:51 2008
> New Revision: 669448
>
> URL: http://svn.apache.org/viewvc?rev=669448&view=rev
> Log:
> A Java version of the prototype for interleaved page and line breaking
Since I’ll be away for the next 10 days, I thought I’d commit what
I have now so that interested people can have a look meanwhile. Please
don’t enable Checkstyle on this code ;-)
The best place to start from is probably o.a.f.prototype.LayoutEngine.
Watch also the Dot class that makes all sort of things with your hard
drive.
Cheers,
Vincent
--
Vincent Hennebert Anyware Technologies
http://people.apache.org/~vhennebert http://www.anyware-tech.com
Apache FOP Committer FOP Development/Consulting