vmote 2003/10/10 08:56:57
Modified: src/java/org/apache/fop/fo/flow PageNumberCitation.java
src/java/org/apache/fop/fonts Font.java
src/java/org/apache/fop/layoutmgr AddLMVisitor.java
TextLayoutManager.java
src/java/org/apache/fop/util CharUtilities.java
Log:
move static methods getCharWidth and getWordWidth from util.CharUtilities to
instance methods in fonts.Font
Revision Changes Path
1.17 +1 -2 xml-fop/src/java/org/apache/fop/fo/flow/PageNumberCitation.java
Index: PageNumberCitation.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/PageNumberCitation.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- PageNumberCitation.java 19 Sep 2003 14:33:15 -0000 1.16
+++ PageNumberCitation.java 10 Oct 2003 15:56:57 -0000 1.17
@@ -96,8 +96,7 @@
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;
}
1.5 +96 -1 xml-fop/src/java/org/apache/fop/fonts/Font.java
Index: Font.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fonts/Font.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Font.java 14 Aug 2003 19:16:41 -0000 1.4
+++ Font.java 10 Oct 2003 15:56:57 -0000 1.5
@@ -207,7 +207,102 @@
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;
+ }
+
+}
1.20 +4 -4 xml-fop/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
Index: AddLMVisitor.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- AddLMVisitor.java 16 Sep 2003 05:21:07 -0000 1.19
+++ AddLMVisitor.java 10 Oct 2003 15:56:57 -0000 1.20
@@ -387,7 +387,7 @@
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 @@
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);
1.5 +6 -7 xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
Index: TextLayoutManager.java
===================================================================
RCS file:
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TextLayoutManager.java 8 Sep 2003 17:00:54 -0000 1.4
+++ TextLayoutManager.java 10 Oct 2003 15:56:57 -0000 1.5
@@ -134,9 +134,9 @@
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 @@
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 @@
bSawNonSuppressible = true;
spaceIPD.add(pendingSpace.resolve(false));
pendingSpace.clear();
- wordIPD += CharUtilities.getCharWidth(c, textInfo.fs);
+ wordIPD += textInfo.fs.getCharWidth(c);
}
}
@@ -381,8 +381,7 @@
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 @@
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.
}
1.6 +1 -95 xml-fop/src/java/org/apache/fop/util/CharUtilities.java
Index: CharUtilities.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/util/CharUtilities.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CharUtilities.java 7 Oct 2003 00:43:06 -0000 1.5
+++ CharUtilities.java 10 Oct 2003 15:56:57 -0000 1.6
@@ -108,100 +108,6 @@
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
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]