aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Victor Mote <vmote@apache.org>2003-10-10 15:56:57 +0000
committerWilliam Victor Mote <vmote@apache.org>2003-10-10 15:56:57 +0000
commit11b030a2ae8561afeda28e199b42abab6e4ec567 (patch)
tree78df283100e7c189811a969c509877085515f3b0
parent0b9f02cb3bc69164b856e409f5ad84d80a374a31 (diff)
downloadxmlgraphics-fop-11b030a2ae8561afeda28e199b42abab6e4ec567.tar.gz
xmlgraphics-fop-11b030a2ae8561afeda28e199b42abab6e4ec567.zip
move static methods getCharWidth and getWordWidth from util.CharUtilities to instance methods in fonts.Font
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196954 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/fo/flow/PageNumberCitation.java3
-rw-r--r--src/java/org/apache/fop/fonts/Font.java97
-rw-r--r--src/java/org/apache/fop/layoutmgr/AddLMVisitor.java6
-rw-r--r--src/java/org/apache/fop/layoutmgr/TextLayoutManager.java13
-rw-r--r--src/java/org/apache/fop/util/CharUtilities.java94
5 files changed, 106 insertions, 107 deletions
diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java
index 005bfa620..d82f400ef 100644
--- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java
+++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java
@@ -96,8 +96,7 @@ public class PageNumberCitation extends FObj {
public int getStringWidth(String str) {
int width = 0;
for (int count = 0; count < str.length(); count++) {
- width += CharUtilities.getCharWidth(str.charAt(count),
- fontState);
+ width += fontState.getCharWidth(str.charAt(count));
}
return width;
}
diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java
index b23b58f72..887462809 100644
--- a/src/java/org/apache/fop/fonts/Font.java
+++ b/src/java/org/apache/fop/fonts/Font.java
@@ -207,7 +207,102 @@ public class Font {
sbuf.append(')');
return sbuf.toString();
}
-}
+ /**
+ * Helper method for getting the width of a unicode char
+ * from the current fontstate.
+ * This also performs some guessing on widths on various
+ * versions of space that might not exists in the font.
+ * @param c character to inspect
+ * @param fs FontState to use
+ * @return the width of the character
+ */
+ public int getCharWidth(char c) {
+ int width;
+
+ if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) {
+ width = getCharWidth(' ');
+ } else {
+ width = getWidth(mapChar(c));
+ if (width <= 0) {
+ // Estimate the width of spaces not represented in
+ // the font
+ int em = getWidth(mapChar('m'));
+ int en = getWidth(mapChar('n'));
+ if (em <= 0) {
+ em = 500 * getFontSize();
+ }
+ if (en <= 0) {
+ en = em - 10;
+ }
+
+ if (c == ' ') {
+ width = em;
+ }
+ if (c == '\u2000') {
+ width = en;
+ }
+ if (c == '\u2001') {
+ width = em;
+ }
+ if (c == '\u2002') {
+ width = em / 2;
+ }
+ if (c == '\u2003') {
+ width = getFontSize();
+ }
+ if (c == '\u2004') {
+ width = em / 3;
+ }
+ if (c == '\u2005') {
+ width = em / 4;
+ }
+ if (c == '\u2006') {
+ width = em / 6;
+ }
+ if (c == '\u2007') {
+ width = getCharWidth(' ');
+ }
+ if (c == '\u2008') {
+ width = getCharWidth('.');
+ }
+ if (c == '\u2009') {
+ width = em / 5;
+ }
+ if (c == '\u200A') {
+ width = 5;
+ }
+ if (c == '\u200B') {
+ width = 100;
+ }
+ if (c == '\u202F') {
+ width = getCharWidth(' ') / 2;
+ }
+ if (c == '\u3000') {
+ width = getCharWidth(' ') * 2;
+ }
+ }
+ }
+
+ return width;
+ }
+
+ /**
+ * Calculates the word width.
+ */
+ public int getWordWidth(String word) {
+ if (word == null)
+ return 0;
+ int wordLength = word.length();
+ int width = 0;
+ char[] characters = new char[wordLength];
+ word.getChars(0, wordLength, characters, 0);
+ for (int i = 0; i < wordLength; i++) {
+ width += getCharWidth(characters[i]);
+ }
+ return width;
+ }
+
+}
diff --git a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
index 0537c3ec8..bd5e83644 100644
--- a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
+++ b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
@@ -387,7 +387,7 @@ public class AddLMVisitor implements FOTreeVisitor {
new Integer(node.getFontState().getFontSize()));
// set offset of dot within inline parent
w.setOffset(node.getFontState().getAscender());
- int width = CharUtilities.getCharWidth(dot, node.getFontState());
+ int width = node.getFontState().getCharWidth(dot);
Space spacer = null;
if (node.getPatternWidth() > width) {
spacer = new Space();
@@ -742,8 +742,8 @@ public class AddLMVisitor implements FOTreeVisitor {
String str = parentLM.getCurrentPageNumber();
int width = 0;
for (int count = 0; count < str.length(); count++) {
- width += CharUtilities.getCharWidth(
- str.charAt(count), node.getFontState());
+ width += node.getFontState().getCharWidth(
+ str.charAt(count));
}
inline.setWord(str);
inline.setIPD(width);
diff --git a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
index 53254e604..46a72f224 100644
--- a/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
@@ -134,9 +134,9 @@ public class TextLayoutManager extends AbstractLayoutManager {
this.vecAreaInfo = new java.util.ArrayList();
// With CID fonts, space isn't neccesary currentFontState.width(32)
- spaceCharIPD = CharUtilities.getCharWidth(' ', textInfo.fs);
+ spaceCharIPD = textInfo.fs.getCharWidth(' ');
// Use hyphenationChar property
- hyphIPD = CharUtilities.getCharWidth('-', textInfo.fs);
+ hyphIPD = textInfo.fs.getCharWidth('-');
// Make half-space: <space> on either side of a word-space)
SpaceVal ws = textInfo.wordSpacing;
halfWS = new SpaceVal(MinOptMax.multiply(ws.getSpace(), 0.5),
@@ -237,7 +237,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
for (; iNextStart < iStopIndex; iNextStart++) {
char c = chars[iNextStart];
- hyphIPD.opt += CharUtilities.getCharWidth(c, textInfo.fs);
+ hyphIPD.opt += textInfo.fs.getCharWidth(c);
// letter-space?
}
// Need to include hyphen size too, but don't count it in the
@@ -344,7 +344,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
bSawNonSuppressible = true;
spaceIPD.add(pendingSpace.resolve(false));
pendingSpace.clear();
- wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
+ wordIPD += textInfo.fs.getCharWidth(c);
}
}
@@ -381,8 +381,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
if (c != SPACE) {
iNextStart++;
if (c != NEWLINE) {
- wordIPD += CharUtilities.getCharWidth(c,
- textInfo.fs);
+ wordIPD += textInfo.fs.getCharWidth(c);
} else {
iFlags |= BreakPoss.FORCE;
}
@@ -402,7 +401,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
context.getLeadingSpace(), null, iFlags,
iWScount);
}
- wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
+ wordIPD += textInfo.fs.getCharWidth(c);
// Note, if a normal non-breaking space, is it stretchable???
// If so, keep a count of these embedded spaces.
}
diff --git a/src/java/org/apache/fop/util/CharUtilities.java b/src/java/org/apache/fop/util/CharUtilities.java
index d8b5a3ab0..c03c407ba 100644
--- a/src/java/org/apache/fop/util/CharUtilities.java
+++ b/src/java/org/apache/fop/util/CharUtilities.java
@@ -108,100 +108,6 @@ public class CharUtilities {
return NONWHITESPACE;
}
- /**
- * Helper method for getting the width of a unicode char
- * from the current fontstate.
- * This also performs some guessing on widths on various
- * versions of space that might not exists in the font.
- * @param c character to inspect
- * @param fs FontState to use
- * @return the width of the character
- */
- public static int getCharWidth(char c, Font fs) {
- int width;
-
- if ((c == '\n') || (c == '\r') || (c == '\t') || (c == '\u00A0')) {
- width = getCharWidth(' ', fs);
- } else {
- width = fs.getWidth(fs.mapChar(c));
- if (width <= 0) {
- // Estimate the width of spaces not represented in
- // the font
- int em = fs.getWidth(fs.mapChar('m'));
- int en = fs.getWidth(fs.mapChar('n'));
- if (em <= 0) {
- em = 500 * fs.getFontSize();
- }
- if (en <= 0) {
- en = em - 10;
- }
-
- if (c == ' ') {
- width = em;
- }
- if (c == '\u2000') {
- width = en;
- }
- if (c == '\u2001') {
- width = em;
- }
- if (c == '\u2002') {
- width = em / 2;
- }
- if (c == '\u2003') {
- width = fs.getFontSize();
- }
- if (c == '\u2004') {
- width = em / 3;
- }
- if (c == '\u2005') {
- width = em / 4;
- }
- if (c == '\u2006') {
- width = em / 6;
- }
- if (c == '\u2007') {
- width = getCharWidth(' ', fs);
- }
- if (c == '\u2008') {
- width = getCharWidth('.', fs);
- }
- if (c == '\u2009') {
- width = em / 5;
- }
- if (c == '\u200A') {
- width = 5;
- }
- if (c == '\u200B') {
- width = 100;
- }
- if (c == '\u202F') {
- width = getCharWidth(' ', fs) / 2;
- }
- if (c == '\u3000') {
- width = getCharWidth(' ', fs) * 2;
- }
- }
- }
-
- return width;
- }
-
- /**
- * Calculates the word width.
- */
- public static int getWordWidth(String word, Font fs) {
- if (word == null)
- return 0;
- int wordLength = word.length();
- int width = 0;
- char[] characters = new char[wordLength];
- word.getChars(0, wordLength, characters, 0);
- for (int i = 0; i < wordLength; i++) {
- width += getCharWidth(characters[i], fs);
- }
- return width;
- }
/**
* Helper method to determine if the character is a