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 ke...@apache.org on 2002/02/11 10:45:39 UTC

cvs commit: xml-fop/src/org/apache/fop/tools AreaTreeBuilder.java

keiron      02/02/11 01:45:39

  Modified:    src/org/apache/fop/layoutmgr TextLayoutManager.java
               src/org/apache/fop/render/pdf CIDFont.java Font.java
                        PDFRenderer.java
               src/org/apache/fop/render/pdf/fonts LazyFont.java
                        MultiByteFont.java
               src/org/apache/fop/tools AreaTreeBuilder.java
  Log:
  does a bit better job at adding text to line area
  
  Revision  Changes    Path
  1.4       +78 -74    xml-fop/src/org/apache/fop/layoutmgr/TextLayoutManager.java
  
  Index: TextLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/layoutmgr/TextLayoutManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TextLayoutManager.java	8 Jan 2002 09:52:17 -0000	1.3
  +++ TextLayoutManager.java	11 Feb 2002 09:45:39 -0000	1.4
  @@ -1,5 +1,5 @@
   /*
  - * $Id: TextLayoutManager.java,v 1.3 2002/01/08 09:52:17 keiron Exp $
  + * $Id: TextLayoutManager.java,v 1.4 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -12,6 +12,7 @@
   import org.apache.fop.area.Area;
   import org.apache.fop.area.Property;
   import org.apache.fop.area.inline.Word;
  +import org.apache.fop.area.inline.Space;
   import org.apache.fop.util.CharUtilities;
   
   import org.apache.fop.fo.properties.*;
  @@ -27,6 +28,14 @@
       private char[] chars;
       private FOText.TextInfo textInfo;
   
  +    private static final char NEWLINE = '\n';
  +    private static final char RETURN = '\r';
  +    private static final char TAB = '\t';
  +    private static final char LINEBREAK = '\u2028';
  +    private static final char ZERO_WIDTH_SPACE = '\u200B';
  +    // byte order mark
  +    private static final char ZERO_WIDTH_NOBREAK_SPACE = '\uFEFF';
  +
       /* values that prev (below) may take */
       protected static final int NOTHING = 0;
       protected static final int WHITESPACE = 1;
  @@ -48,11 +57,11 @@
   
           // Iterate over characters and make text areas.
           // Add each one to parent. Handle word-space.
  -//        Word curWordArea = new Word();
  -//        curWordArea.setWord(new String(chars));
  -//System.out.println("word:" + new String(chars));
  +        //        Word curWordArea = new Word();
  +        //        curWordArea.setWord(new String(chars));
  +        //System.out.println("word:" + new String(chars));
           //parentLM.addChild(curWordArea);
  -parseChars();
  +        parseChars();
   
           //setCurrentArea(curWordArea);
           //flush();
  @@ -65,62 +74,59 @@
   
           int wordStart = 0;
           int wordLength = 0;
  -        int wordWidth = 0; 
  +        int wordWidth = 0;
           int spaceWidth = 0;
   
           int prev = NOTHING;
   
  -        boolean isText = false;
  -
  -        /* iterate over each character */ 
  +        /* iterate over each character */
           for (int i = 0; i < chars.length; i++) {
               int charWidth;
               /* get the character */
               char c = chars[i];
  -            if (!(CharUtilities.isSpace(c) || (c == '\n') || (c == '\r') || (c == '\t')
  -                    || (c == '\u2028'))) {
  +            if (!(CharUtilities.isSpace(c) || (c == NEWLINE) ||
  +                    (c == RETURN) || (c == TAB) || (c == LINEBREAK))) {
                   charWidth = CharUtilities.getCharWidth(c, textInfo.fs);
  -                isText = true; 
                   prev = TEXT;
  -wordLength++;
  -wordWidth += charWidth;
  +                wordLength++;
  +                wordWidth += charWidth;
                   // Add support for zero-width spaces
  -                if (charWidth <= 0 && c != '\u200B' && c != '\uFEFF')
  +                if (charWidth <= 0 && c != ZERO_WIDTH_SPACE &&
  +                                 c != ZERO_WIDTH_NOBREAK_SPACE)
                       charWidth = whitespaceWidth;
               } else {
  -                if ((c == '\n') || (c == '\r') || (c == '\t'))
  +                if ((c == NEWLINE) || (c == RETURN) || (c == TAB))
                       charWidth = whitespaceWidth;
                   else
                       charWidth = CharUtilities.getCharWidth(c, textInfo.fs);
   
  -                isText = false;
  -
                   if (prev == WHITESPACE) {
   
                       // if current & previous are WHITESPACE
   
  -                    if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE) {
  -                        if (CharUtilities.isSpace(c)) { 
  -                            spaceWidth += CharUtilities.getCharWidth(c, textInfo.fs);
  -                        } else if (c == '\n' || c == '\u2028') {
  -                            // force line break 
  +                    if (textInfo.whiteSpaceCollapse ==
  +                            WhiteSpaceCollapse.FALSE) {
  +                        if (CharUtilities.isSpace(c)) {
  +                            spaceWidth += CharUtilities.getCharWidth(c,
  +                                          textInfo.fs);
  +                        } else if (c == NEWLINE || c == LINEBREAK) {
  +                            // force line break
                               if (spaceWidth > 0) {
  -                                /*InlineSpace is = new InlineSpace(spaceWidth);
  -                                addChild(is);*/
  +                                Space is = new Space();
  +                                is.setWidth(spaceWidth);
  +                                parentLM.addChild(is);
                                   spaceWidth = 0;
                               }
  -                        } else if (c == '\t') {
  +                        } else if (c == TAB) {
                               spaceWidth += 8 * whitespaceWidth;
                           }
  -                    } else if (c == '\u2028') {
  +                    } else if (c == LINEBREAK) {
                           // Line separator
                           // Breaks line even if WhiteSpaceCollapse = True
                           if (spaceWidth > 0) {
  -                            /*InlineSpace is = new InlineSpace(spaceWidth);
  -                            is.setUnderlined(textState.getUnderlined());
  -                            is.setOverlined(textState.getOverlined());
  -                            is.setLineThrough(textState.getLineThrough());
  -                            addChild(is);*/
  +                            Space is = new Space();
  +                            is.setWidth(spaceWidth);
  +                            parentLM.addChild(is);
                               spaceWidth = 0;
                           }
                       }
  @@ -133,17 +139,9 @@
                       // was some)
   
                       if (spaceWidth > 0) {
  -                        /*InlineSpace is = new InlineSpace(spaceWidth);
  -                        if (prevUlState) {
  -                            is.setUnderlined(textState.getUnderlined());
  -                        }
  -                        if (prevOlState) {
  -                            is.setOverlined(textState.getOverlined());
  -                        }
  -                        if (prevLTState) {
  -                            is.setLineThrough(textState.getLineThrough());
  -                        }
  -                        addChild(is);*/
  +                        Space is = new Space();
  +                        is.setWidth(spaceWidth);
  +                        parentLM.addChild(is);
                           spaceWidth = 0;
                       }
   
  @@ -151,17 +149,18 @@
   
                       if (wordLength > 0) {
                           // The word might contain nonbreaking
  -                        // spaces. Split the word and add InlineSpace
  +                        // spaces. Split the word and add Space
                           // as necessary. All spaces inside the word
                           // Have a fixed width.
  -        Word curWordArea = new Word(); 
  -curWordArea.setWidth(wordWidth);
  -        curWordArea.setWord(new String(chars, wordStart, wordLength + 1));
  -Property prop = new Property();
  -prop.propType = Property.FONT_STATE;
  -prop.data = textInfo.fs;
  -curWordArea.addProperty(prop);
  -        parentLM.addChild(curWordArea);
  +                        Word curWordArea = new Word();
  +                        curWordArea.setWidth(wordWidth);
  +                        curWordArea.setWord( new String(chars, wordStart + 1,
  +                                                        wordLength));
  +                        Property prop = new Property();
  +                        prop.propType = Property.FONT_STATE;
  +                        prop.data = textInfo.fs;
  +                        curWordArea.addProperty(prop);
  +                        parentLM.addChild(curWordArea);
   
                           // reset word width
                           wordWidth = 0;
  @@ -173,28 +172,32 @@
   
                       spaceWidth = CharUtilities.getCharWidth(c, textInfo.fs);
   
  -                    if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE) {
  -                        if (c == '\n' || c == '\u2028') {
  +                    if (textInfo.whiteSpaceCollapse ==
  +                            WhiteSpaceCollapse.FALSE) {
  +                        if (c == NEWLINE || c == LINEBREAK) {
                               // force a line break
  -                        } else if (c == '\t') {
  +                        } else if (c == TAB) {
                               spaceWidth = whitespaceWidth;
                           }
  -                    } else if (c == '\u2028') {
  +                    } else if (c == LINEBREAK) {
                       }
                   } else {
   
                       // if current is WHITESPACE and no previous
   
  -                    if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE) {
  +                    if (textInfo.whiteSpaceCollapse ==
  +                            WhiteSpaceCollapse.FALSE) {
                           if (CharUtilities.isSpace(c)) {
                               prev = WHITESPACE;
  -                            spaceWidth = CharUtilities.getCharWidth(c, textInfo.fs);
  -                        } else if (c == '\n') {
  +                            spaceWidth = CharUtilities.getCharWidth(c,
  +                                                                    textInfo.fs);
  +                        } else if (c == NEWLINE) {
                               // force line break
                               // textdecoration not used because spaceWidth is 0
  -                            /*InlineSpace is = new InlineSpace(spaceWidth);
  -                            addChild(is);*/
  -                        } else if (c == '\t') {
  +                            Space is = new Space();
  +                            is.setWidth(spaceWidth);
  +                            parentLM.addChild(is);
  +                        } else if (c == TAB) {
                               prev = WHITESPACE;
                               spaceWidth = 8 * whitespaceWidth;
                           }
  @@ -204,27 +207,28 @@
                           wordStart++;
                       }
                   }
  -                        wordStart = i;
  -wordLength = 0;
  +                wordStart = i;
  +                wordLength = 0;
               }
           } // end of iteration over text
   
           if (wordLength > 0) {
               // The word might contain nonbreaking
  -            // spaces. Split the word and add InlineSpace
  +            // spaces. Split the word and add Space
               // as necessary. All spaces inside the word
               // Have a fixed width.
  -if(wordStart + wordLength > chars.length - 1) {
  -wordLength = chars.length - 1 - wordStart;
  -}
  +            if (wordStart + wordLength > chars.length - 1) {
  +                wordLength = chars.length - 1 - wordStart;
  +            }
   
               Word curWordArea = new Word();
  -curWordArea.setWidth(wordWidth);
  -            curWordArea.setWord(new String(chars, wordStart, wordLength + 1));
  -Property prop = new Property();
  -prop.propType = Property.FONT_STATE;
  -prop.data = textInfo.fs;
  -curWordArea.addProperty(prop);
  +            curWordArea.setWidth(wordWidth);
  +            curWordArea.setWord(
  +              new String(chars, wordStart + 1, wordLength));
  +            Property prop = new Property();
  +            prop.propType = Property.FONT_STATE;
  +            prop.data = textInfo.fs;
  +            curWordArea.addProperty(prop);
               parentLM.addChild(curWordArea);
   
           }
  
  
  
  1.3       +4 -1      xml-fop/src/org/apache/fop/render/pdf/CIDFont.java
  
  Index: CIDFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/CIDFont.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CIDFont.java	30 Jul 2001 20:29:33 -0000	1.2
  +++ CIDFont.java	11 Feb 2002 09:45:39 -0000	1.3
  @@ -1,5 +1,5 @@
   /*
  - * $Id: CIDFont.java,v 1.2 2001/07/30 20:29:33 tore Exp $
  + * $Id: CIDFont.java,v 1.3 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -42,4 +42,7 @@
           return null;
       }
   
  +    public boolean isMultiByte() {
  +        return true;
  +    }
   }
  
  
  
  1.10      +5 -3      xml-fop/src/org/apache/fop/render/pdf/Font.java
  
  Index: Font.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/Font.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Font.java	30 Jul 2001 20:29:33 -0000	1.9
  +++ Font.java	11 Feb 2002 09:45:39 -0000	1.10
  @@ -1,5 +1,5 @@
   /*
  - * $Id: Font.java,v 1.9 2001/07/30 20:29:33 tore Exp $
  + * $Id: Font.java,v 1.10 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -48,7 +48,9 @@
           return c;
       }
   
  -}
  -
  +    public boolean isMultiByte() {
  +        return false;
  +    }
   
  +}
   
  
  
  
  1.96      +3 -9      xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- PDFRenderer.java	8 Jan 2002 09:52:17 -0000	1.95
  +++ PDFRenderer.java	11 Feb 2002 09:45:39 -0000	1.96
  @@ -1,5 +1,5 @@
   /*
  - * $Id: PDFRenderer.java,v 1.95 2002/01/08 09:52:17 keiron Exp $
  + * $Id: PDFRenderer.java,v 1.96 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -237,15 +237,9 @@
               int size = fs.getFontSize();
   
               // This assumes that *all* CIDFonts use a /ToUnicode mapping
  -            boolean useMultiByte = false;
               Font f = (Font)fs.getFontInfo().getFonts().get(name);
  -            if (f instanceof LazyFont){
  -                if(((LazyFont) f).getRealFont() instanceof CIDFont){
  -                    useMultiByte = true;
  -                }
  -            } else if (f instanceof CIDFont){
  -                useMultiByte = true;
  -            }
  +            boolean useMultiByte = f.isMultiByte();
  +
               // String startText = useMultiByte ? "<FEFF" : "(";
               String startText = useMultiByte ? "<" : "(";
               String endText = useMultiByte ? "> " : ") ";
  
  
  
  1.5       +5 -1      xml-fop/src/org/apache/fop/render/pdf/fonts/LazyFont.java
  
  Index: LazyFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/fonts/LazyFont.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LazyFont.java	22 Nov 2001 07:11:41 -0000	1.4
  +++ LazyFont.java	11 Feb 2002 09:45:39 -0000	1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: LazyFont.java,v 1.4 2001/11/22 07:11:41 keiron Exp $
  + * $Id: LazyFont.java,v 1.5 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -54,6 +54,10 @@
           return realFont;
       }
       
  +    public boolean isMultiByte() {
  +        return realFont.isMultiByte();
  +    }
  +
       // Font
       public String encoding(){
           load();
  
  
  
  1.7       +1 -10     xml-fop/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java
  
  Index: MultiByteFont.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MultiByteFont.java	22 Nov 2001 07:11:41 -0000	1.6
  +++ MultiByteFont.java	11 Feb 2002 09:45:39 -0000	1.7
  @@ -1,5 +1,5 @@
   /*
  - * $Id: MultiByteFont.java,v 1.6 2001/11/22 07:11:41 keiron Exp $
  + * $Id: MultiByteFont.java,v 1.7 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -334,13 +334,4 @@
       }
   
   }
  -
  -
  -
  -
  -
  -
  -
  -
  -
   
  
  
  
  1.5       +13 -2     xml-fop/src/org/apache/fop/tools/AreaTreeBuilder.java
  
  Index: AreaTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/tools/AreaTreeBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AreaTreeBuilder.java	9 Nov 2001 22:14:37 -0000	1.4
  +++ AreaTreeBuilder.java	11 Feb 2002 09:45:39 -0000	1.5
  @@ -1,5 +1,5 @@
   /*
  - * $Id: AreaTreeBuilder.java,v 1.4 2001/11/09 22:14:37 klease Exp $
  + * $Id: AreaTreeBuilder.java,v 1.5 2002/02/11 09:45:39 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
  @@ -490,7 +490,7 @@
                         new FontState(fontInfo, "sans-serif", "normal",
                                       "normal", 12000, 0);
                   } catch (FOPException e) {
  -
  +                    e.printStackTrace();
                   }
   
                   ch.setWidth(currentFontState.width(ch.getChar()));
  @@ -513,7 +513,18 @@
                       list.add(leader);
                   }
               } else if (obj.getNodeName().equals("word")) {
  +                try {
  +                    currentFontState =
  +                      new FontState(fontInfo, "sans-serif", "normal",
  +                                    "normal", 12000, 0);
  +                } catch (FOPException e) {
  +                    e.printStackTrace();
  +                }
                   Word word = getWord((Element) obj);
  +                Property prop = new Property();
  +                prop.propType = Property.FONT_STATE;
  +                prop.data = currentFontState;
  +                word.addProperty(prop);
                   if (word != null) {
                       list.add(word);
                   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org