diff options
author | Keiron Liddle <keiron@apache.org> | 2002-02-11 09:45:39 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-02-11 09:45:39 +0000 |
commit | 1a486a3ed41557e416f1cb4ca6dad48af5e87096 (patch) | |
tree | 968fe7e0ce9695dde6fc508ee2bf7235a80f81bc /src/org/apache | |
parent | cd1d43ba4746f80ab4ca9b03ca2eb73343d50357 (diff) | |
download | xmlgraphics-fop-1a486a3ed41557e416f1cb4ca6dad48af5e87096.tar.gz xmlgraphics-fop-1a486a3ed41557e416f1cb4ca6dad48af5e87096.zip |
does a bit better job at adding text to line area
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194637 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r-- | src/org/apache/fop/layoutmgr/TextLayoutManager.java | 150 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/CIDFont.java | 3 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/Font.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 10 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/fonts/LazyFont.java | 4 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/fonts/MultiByteFont.java | 9 | ||||
-rw-r--r-- | src/org/apache/fop/tools/AreaTreeBuilder.java | 13 |
7 files changed, 102 insertions, 93 deletions
diff --git a/src/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/org/apache/fop/layoutmgr/TextLayoutManager.java index 2aa848ada..635aa8792 100644 --- a/src/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -12,6 +12,7 @@ import org.apache.fop.fo.FOText; // For TextInfo: TODO: make independent! 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 @@ public class TextLayoutManager extends LeafNodeLayoutManager { 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 @@ public class TextLayoutManager extends LeafNodeLayoutManager { // 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 @@ parseChars(); 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 @@ wordWidth += charWidth; // 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 @@ wordWidth += charWidth; 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 @@ curWordArea.addProperty(prop); 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 @@ curWordArea.addProperty(prop); 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); } diff --git a/src/org/apache/fop/render/pdf/CIDFont.java b/src/org/apache/fop/render/pdf/CIDFont.java index 0e5c089ac..92ad2a5e8 100644 --- a/src/org/apache/fop/render/pdf/CIDFont.java +++ b/src/org/apache/fop/render/pdf/CIDFont.java @@ -42,4 +42,7 @@ public abstract class CIDFont extends Font { return null; } + public boolean isMultiByte() { + return true; + } } diff --git a/src/org/apache/fop/render/pdf/Font.java b/src/org/apache/fop/render/pdf/Font.java index d0142ef87..760200b22 100644 --- a/src/org/apache/fop/render/pdf/Font.java +++ b/src/org/apache/fop/render/pdf/Font.java @@ -48,7 +48,9 @@ public abstract class Font implements FontMetric { return c; } -} - + public boolean isMultiByte() { + return false; + } +} diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 45bcee788..a8ba5ad93 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -237,15 +237,9 @@ public class PDFRenderer extends PrintRenderer { 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 ? "> " : ") "; diff --git a/src/org/apache/fop/render/pdf/fonts/LazyFont.java b/src/org/apache/fop/render/pdf/fonts/LazyFont.java index ae453dbfd..dd55d636e 100644 --- a/src/org/apache/fop/render/pdf/fonts/LazyFont.java +++ b/src/org/apache/fop/render/pdf/fonts/LazyFont.java @@ -54,6 +54,10 @@ public class LazyFont extends Font implements FontDescriptor { return realFont; } + public boolean isMultiByte() { + return realFont.isMultiByte(); + } + // Font public String encoding(){ load(); diff --git a/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java b/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java index 9cc624fd1..a59239dc9 100644 --- a/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java +++ b/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java @@ -335,12 +335,3 @@ public class MultiByteFont extends CIDFont implements FontDescriptor { } - - - - - - - - - diff --git a/src/org/apache/fop/tools/AreaTreeBuilder.java b/src/org/apache/fop/tools/AreaTreeBuilder.java index dcf007b48..3528f8b97 100644 --- a/src/org/apache/fop/tools/AreaTreeBuilder.java +++ b/src/org/apache/fop/tools/AreaTreeBuilder.java @@ -490,7 +490,7 @@ class TreeLoader { new FontState(fontInfo, "sans-serif", "normal", "normal", 12000, 0); } catch (FOPException e) { - + e.printStackTrace(); } ch.setWidth(currentFontState.width(ch.getChar())); @@ -513,7 +513,18 @@ class TreeLoader { 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); } |