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 [2/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...

Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,132 @@
+/*
+ * 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.font;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A font.
+ */
+public class Font {
+
+    public final static Font TIMES_FONT;
+
+    static {
+        Map<Character, Integer> m = new HashMap<Character, Integer>();
+        m.put(' ', 250);
+        m.put('!', 333);
+        m.put('#', 500);
+        m.put('$', 500);
+        m.put('%', 833);
+        m.put('&', 778);
+        m.put('”', 333);
+        m.put('(', 333);
+        m.put(')', 333);
+        m.put('*', 500);
+        m.put('+', 564);
+        m.put(',', 250);
+        m.put('-', 333);
+        m.put('.', 250);
+        m.put('/', 278);
+        m.put('0', 500);
+        m.put('1', 500);
+        m.put('2', 500);
+        m.put('3', 500);
+        m.put('4', 500);
+        m.put('5', 500);
+        m.put('6', 500);
+        m.put('7', 500);
+        m.put('8', 500);
+        m.put('9', 500);
+        m.put(':', 278);
+        m.put(';', 278);
+        m.put('<', 564);
+        m.put('=', 564);
+        m.put('>', 564);
+        m.put('?', 444);
+        m.put('@', 921);
+        m.put('A', 722);
+        m.put('B', 667);
+        m.put('C', 667);
+        m.put('D', 722);
+        m.put('E', 611);
+        m.put('F', 556);
+        m.put('G', 722);
+        m.put('H', 722);
+        m.put('I', 333);
+        m.put('J', 389);
+        m.put('K', 722);
+        m.put('L', 611);
+        m.put('M', 889);
+        m.put('N', 722);
+        m.put('O', 722);
+        m.put('P', 556);
+        m.put('Q', 722);
+        m.put('R', 667);
+        m.put('S', 556);
+        m.put('T', 611);
+        m.put('U', 722);
+        m.put('V', 722);
+        m.put('W', 944);
+        m.put('X', 722);
+        m.put('Y', 722);
+        m.put('Z', 611);
+        m.put('_', 500);
+        m.put('“', 333);
+        m.put('a', 444);
+        m.put('b', 500);
+        m.put('c', 444);
+        m.put('d', 500);
+        m.put('e', 444);
+        m.put('f', 333);
+        m.put('g', 500);
+        m.put('h', 500);
+        m.put('i', 278);
+        m.put('j', 278);
+        m.put('k', 500);
+        m.put('l', 278);
+        m.put('m', 778);
+        m.put('n', 500);
+        m.put('o', 500);
+        m.put('p', 500);
+        m.put('q', 500);
+        m.put('r', 333);
+        m.put('s', 389);
+        m.put('t', 278);
+        m.put('u', 500);
+        m.put('v', 500);
+        m.put('w', 722);
+        m.put('x', 500);
+        m.put('y', 500);
+        m.put('z', 444);
+        TIMES_FONT = new Font(m);
+    }
+
+    private Map<Character, Integer> charWidths;
+
+    private Font(Map<Character, Integer> charWidths) {
+        this.charWidths = charWidths;
+    }
+
+    public int getCharWidth(char ch) {
+        return charWidths.get(ch);
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/font/Font.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.knuth;
+
+/**
+ * A box.
+ */
+public class Box extends KnuthElement {
+
+    /**
+     * @param length
+     * @param content
+     */
+    public Box(int length, String content) {
+        super(length, content);
+    }
+
+    public boolean isBox() {
+        return true;
+    }
+
+    public String toString() {
+        return "Box w = " + getLength() + super.toString();
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Box.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.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.knuth;
+
+/**
+ * A glue.
+ */
+public class Glue extends KnuthElement {
+
+    private int stretch;
+
+    private int shrink;
+
+    public Glue(int length, int stretch, int shrink, String content) {
+        super(length, content);
+        this.stretch = stretch;
+        this.shrink = shrink;
+    }
+
+    public Glue(int length, int stretch, int shrink) {
+        this(length, stretch, shrink, "");
+    }
+
+    /**
+     * @return the stretch
+     */
+    public int getStretch() {
+        return stretch;
+    }
+
+    /**
+     * @return the shrink
+     */
+    public int getShrink() {
+        return shrink;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Glue w = " + getLength() + " str = " + stretch + " shr = " + shrink
+                + super.toString();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean isGlue() {
+        return true;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Glue.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.prototype.knuth;
+
+import org.apache.fop.prototype.TypographicElement;
+
+/**
+ * A Knuth element.
+ */
+public class KnuthElement implements TypographicElement {
+
+    private int length;
+
+    private String content;
+
+    /**
+     * @param length
+     * @param content
+     */
+    protected KnuthElement(int length, String content) {
+        this.length = length;
+        this.content = content;
+    }
+
+    /**
+     * @param length
+     */
+    protected KnuthElement(int length) {
+        this(length, "");
+    }
+
+    public int getLength() {
+        return length;
+    }
+
+    public String getLabel() {
+        return content;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        if (content.isEmpty()) {
+            return "";
+        } else {
+            return " \"" + content + "\"";
+        }
+    }
+
+    public boolean isGlue() {
+        return false;
+    }
+
+    public boolean isBox() {
+        return false;
+    }
+
+    public boolean isPenalty() {
+        return false;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/KnuthElement.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,105 @@
+/*
+ * 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.knuth;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A box representing a line of a paragraph.
+ */
+public class LineBox extends KnuthElement {
+
+    private List<KnuthElement> elements;
+
+    private int difference;
+
+    private int spaceCharWidth;
+
+    public LineBox(int length, List<KnuthElement> elements, int difference, int spaceCharWidth) {
+        super(length);
+        this.elements = elements;
+        this.difference = difference;
+        this.spaceCharWidth = spaceCharWidth;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean isBox() {
+        return true;
+    }
+
+    private void createLabel(StringBuilder label, Iterator<KnuthElement> iter, int spaceNumber, int spaceSize) {
+        if (spaceNumber > 0) {
+            char[] space = new char[spaceSize];
+            Arrays.fill(space, ' ');
+            do {
+                KnuthElement e = iter.next();
+                label.append(e.getLabel());
+                if (e.isGlue()) {
+                    label.append(space);
+                    spaceNumber--;
+                }
+            } while (spaceNumber > 0);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getLabel() {
+        StringBuilder label = new StringBuilder();
+        if (difference > 0) {
+            int nbGlues = 0;
+            for (KnuthElement e: elements) {
+                if (e.isGlue()) {
+                    nbGlues++;
+                }
+            }
+            if (nbGlues > 1) {
+                int nbSpaceChars = difference / spaceCharWidth;
+                int q = nbSpaceChars / nbGlues;
+                int r = nbSpaceChars % nbGlues;
+                Iterator<KnuthElement> iter = elements.iterator();
+                createLabel(label, iter, nbGlues - r, q);
+                createLabel(label, iter, r, q + 1);
+                do {
+                    label.append(iter.next().getLabel());
+                } while (iter.hasNext());
+            }
+        } else {
+            for (KnuthElement e: elements) {
+                label.append(e.getLabel());
+            }
+        }
+        return label.toString();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        StringBuilder str = new StringBuilder();
+        for (KnuthElement e: elements) {
+            str.append(e.getLabel());
+        }
+        str.append("\\n");
+        return str.toString();
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/LineBox.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Added: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.java?rev=669448&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.java (added)
+++ xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.java Thu Jun 19 03:56:51 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.knuth;
+
+/**
+ * A penalty.
+ */
+public class Penalty extends KnuthElement {
+
+    public static final Penalty DEFAULT_PENALTY = new Penalty(0, 0); 
+
+    public static final int INFINITE = 1000;
+
+    private int penalty;
+
+    public Penalty(int length, int penalty, String content) {
+        super(length, content);
+        this.penalty = penalty;
+    }
+
+    public Penalty(int length, int penalty) {
+        this(length, penalty, "");
+    }
+
+    public boolean isForcedBreak() {
+        return penalty == -INFINITE; 
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean isPenalty() {
+        return true;
+    }
+
+    /**
+     * @return the penalty
+     */
+    public int getPenalty() {
+        return penalty;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Pen w = " + getLength() + " p = " + penalty + super.toString();
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_Interleaved_Page_Line_Breaking/prototype/java/src/org/apache/fop/prototype/knuth/Penalty.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