foray-commit Mailing List for FOray (Page 300)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(139) |
Apr
(98) |
May
(250) |
Jun
(394) |
Jul
(84) |
Aug
(13) |
Sep
(420) |
Oct
(186) |
Nov
(1) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(108) |
Feb
(202) |
Mar
(291) |
Apr
(247) |
May
(374) |
Jun
(227) |
Jul
(231) |
Aug
(60) |
Sep
(31) |
Oct
(45) |
Nov
(18) |
Dec
|
| 2008 |
Jan
(38) |
Feb
(71) |
Mar
(142) |
Apr
|
May
(59) |
Jun
(6) |
Jul
(10) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
(12) |
Feb
(4) |
Mar
(88) |
Apr
(121) |
May
(17) |
Jun
(30) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2010 |
Jan
(11) |
Feb
(76) |
Mar
(11) |
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
(44) |
Sep
(14) |
Oct
(7) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(168) |
| 2017 |
Jan
(77) |
Feb
(11) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(88) |
Mar
(118) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(141) |
| 2021 |
Jan
(170) |
Feb
(20) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(62) |
Nov
(189) |
Dec
(162) |
| 2022 |
Jan
(201) |
Feb
(118) |
Mar
(8) |
Apr
|
May
(2) |
Jun
(47) |
Jul
(19) |
Aug
(14) |
Sep
(3) |
Oct
|
Nov
(28) |
Dec
(235) |
| 2023 |
Jan
(112) |
Feb
(23) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(70) |
Sep
(92) |
Oct
(20) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(14) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(10) |
Feb
(29) |
Mar
|
Apr
(162) |
May
(245) |
Jun
(83) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(4) |
Dec
(23) |
| 2026 |
Jan
(119) |
Feb
(335) |
Mar
(103) |
Apr
(43) |
May
(154) |
Jun
(107) |
Jul
(187) |
Aug
(4) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <vic...@us...> - 2006-06-08 21:39:13
|
Revision: 7465 Author: victormote Date: 2006-06-08 14:39:07 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7465&view=rev Log Message: ----------- Implement overloaded axsl method. Modified Paths: -------------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 21:15:02 UTC (rev 7464) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 21:39:07 UTC (rev 7465) @@ -310,6 +310,9 @@ */ public int wordStarts(char[] characters, int startIndex, String language, String country) { + if (characters == null) { + return -1; + } /* TODO: We need to handle language and country here. */ for (int i = startIndex; i < characters.length; i++) { char c = characters[i]; @@ -327,4 +330,16 @@ return -1; } + /** + * {@inheritDoc} + */ + public int wordStarts(CharSequence characters, int startIndex, + String language, String country) { + if (characters == null) { + return -1; + } + return wordStarts(characters.toString().toCharArray(), startIndex, + language, country); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 21:15:13
|
Revision: 7464 Author: victormote Date: 2006-06-08 14:15:02 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7464&view=rev Log Message: ----------- Conform to axsl changes: Add method parameters to allow i18n. Modified Paths: -------------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 21:14:53 UTC (rev 7463) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 21:15:02 UTC (rev 7464) @@ -308,7 +308,9 @@ /** * {@inheritDoc} */ - public int wordStarts(char[] characters, int startIndex) { + public int wordStarts(char[] characters, int startIndex, String language, + String country) { + /* TODO: We need to handle language and country here. */ for (int i = startIndex; i < characters.length; i++) { char c = characters[i]; switch(c) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 21:15:00
|
Revision: 7463 Author: victormote Date: 2006-06-08 14:14:53 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7463&view=rev Log Message: ----------- Conform to axsl changes: Add method parameters to allow i18n. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 20:57:44 UTC (rev 7462) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 21:14:53 UTC (rev 7463) @@ -351,8 +351,11 @@ * LineText items to find the beginning of the word. */ HyphenationServer server = this.getHyphenationServer(); + String language = this.currentLineText.inlineLanguage(); + String country = this.currentLineText.inlineCountry(); // Count the number of chars at the beginning that should be ignored. - int actualWordStart = server.wordStarts(this.currentChars, wordStart); + int actualWordStart = server.wordStarts(this.currentChars, wordStart, + language, country); if (actualWordStart < 0) { return this.wordStart; } @@ -362,9 +365,7 @@ this.currentChars, actualWordStart); // See if there are discretionary hyphenation points. Hyphenation hyph = server.hyphenate(wordToHyphenate, 0, - wordToHyphenate.length(), - this.currentLineText.inlineLanguage(), - this.currentLineText.inlineCountry(), + wordToHyphenate.length(), language, country, this.currentLineText.inlineHyphenationRemainCount(), this.currentLineText.inlineHyphenationPushCount()); // If none, the word cannot be hyphenated. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 20:57:51
|
Revision: 7462 Author: victormote Date: 2006-06-08 13:57:44 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7462&view=rev Log Message: ----------- Conform to axsl changes: Rename method and change its meaning from returning the number of characters to skip to the index to the first character to be used. Modified Paths: -------------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 20:57:37 UTC (rev 7461) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 20:57:44 UTC (rev 7462) @@ -306,22 +306,23 @@ } /** - * Returns the count of non-word characters at the beginning of the text - * being evaluated. This includes characters like " and ' which are not - * really part of the word, but which must be passed through to the output. - * @param characters The char array being evaluated. - * @param startIndex Index into the first character in characters that - * should be evaluated. - * @return The number of characters at the start that should be ignored for - * purposes of forming a word to be evaluated for hyphenation. + * {@inheritDoc} */ - public int nonWordChars(char[] characters, int startIndex) { - int count = 0; - // Look for ' or " at the beginning of the word. - if (characters[startIndex] == '"' || characters[startIndex] == '\'') { - count ++; + public int wordStarts(char[] characters, int startIndex) { + for (int i = startIndex; i < characters.length; i++) { + char c = characters[i]; + switch(c) { + case '"': + case '\'': { + + continue; + } + default: { + return i; + } + } } - return count; + return -1; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 20:57:42
|
Revision: 7461 Author: victormote Date: 2006-06-08 13:57:37 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7461&view=rev Log Message: ----------- Conform to axsl changes: Rename method and change its meaning from returning the number of characters to skip to the index to the first character to be used. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 20:34:50 UTC (rev 7460) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 20:57:37 UTC (rev 7461) @@ -352,10 +352,14 @@ */ HyphenationServer server = this.getHyphenationServer(); // Count the number of chars at the beginning that should be ignored. - int nonWordChars = server.nonWordChars(this.currentChars, wordStart); + int actualWordStart = server.wordStarts(this.currentChars, wordStart); + if (actualWordStart < 0) { + return this.wordStart; + } + int nonWordChars = actualWordStart - wordStart; // Extract the word that should be evaluated by the hyphenation system. String wordToHyphenate = server.getHyphenationWord( - this.currentChars, this.wordStart + nonWordChars); + this.currentChars, actualWordStart); // See if there are discretionary hyphenation points. Hyphenation hyph = server.hyphenate(wordToHyphenate, 0, wordToHyphenate.length(), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 20:34:57
|
Revision: 7460 Author: victormote Date: 2006-06-08 13:34:50 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7460&view=rev Log Message: ----------- Conform to axsl changes: Allow the CharSequence version to use a subset as well. Modified Paths: -------------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 20:34:43 UTC (rev 7459) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 20:34:50 UTC (rev 7460) @@ -264,13 +264,11 @@ return null; } - public org.axsl.hyphenR.Hyphenation hyphenate(CharSequence word, - String language, String country, int remainCount, int pushCount) { - HyphenationTree hTree = getHyphenationTree(language, country); - if (hTree == null) { - return null; - } - return hTree.hyphenate(word, remainCount, pushCount); + public org.axsl.hyphenR.Hyphenation hyphenate(CharSequence word, int offset, + int len, String language, String country, int remainCount, + int pushCount) { + return this.hyphenate(word.toString().toCharArray(), offset, len, + language, country, remainCount, pushCount); } public org.axsl.hyphenR.Hyphenation hyphenate(char[] word, int offset, Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 20:34:43 UTC (rev 7459) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 20:34:50 UTC (rev 7460) @@ -274,22 +274,6 @@ } /** - * Hyphenate word and return a Hyphenation object. - * @param word the word to be hyphenated - * @param remainCharCount Minimum number of characters allowed - * before the hyphenation point. - * @param pushCharCount Minimum number of characters allowed after - * the hyphenation point. - * @return a {@link Hyphenation Hyphenation} object representing - * the hyphenated word or null if word is not hyphenated. - */ - public org.axsl.hyphenR.Hyphenation hyphenate(CharSequence word, - int remainCharCount, int pushCharCount) { - char[] w = word.toString().toCharArray(); - return hyphenate(w, 0, w.length, remainCharCount, pushCharCount); - } - - /** * Hyphenate word and return an array of hyphenation points. * @param w char array that contains the word * @param offset Offset to first character in word @@ -494,8 +478,8 @@ logger.info("Word: "); token = in.readLine().trim(); logger.info("Hyphenation points: "); - logger.info(ht.hyphenate(token, minCharCount, - minCharCount).toString()); + logger.info(ht.hyphenate(token.toCharArray(), 0, token.length(), + minCharCount, minCharCount).toString()); } else if (token.equals("b")) { if (ht == null) { logger.info("No patterns has been loaded."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 20:34:49
|
Revision: 7459 Author: victormote Date: 2006-06-08 13:34:43 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7459&view=rev Log Message: ----------- Conform to axsl changes: Allow the CharSequence version to use a subset as well. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 20:22:55 UTC (rev 7458) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 20:34:43 UTC (rev 7459) @@ -357,7 +357,8 @@ String wordToHyphenate = server.getHyphenationWord( this.currentChars, this.wordStart + nonWordChars); // See if there are discretionary hyphenation points. - Hyphenation hyph = server.hyphenate(wordToHyphenate, + Hyphenation hyph = server.hyphenate(wordToHyphenate, 0, + wordToHyphenate.length(), this.currentLineText.inlineLanguage(), this.currentLineText.inlineCountry(), this.currentLineText.inlineHyphenationRemainCount(), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 20:23:04
|
Revision: 7458 Author: victormote Date: 2006-06-08 13:22:55 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7458&view=rev Log Message: ----------- Conform to axsl change: Allow any CharSequence to be the "word". Modified Paths: -------------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 19:45:27 UTC (rev 7457) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 20:22:55 UTC (rev 7458) @@ -264,8 +264,8 @@ return null; } - public org.axsl.hyphenR.Hyphenation hyphenate(String word, String language, - String country, int remainCount, int pushCount) { + public org.axsl.hyphenR.Hyphenation hyphenate(CharSequence word, + String language, String country, int remainCount, int pushCount) { HyphenationTree hTree = getHyphenationTree(language, country); if (hTree == null) { return null; Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 19:45:27 UTC (rev 7457) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 20:22:55 UTC (rev 7458) @@ -283,9 +283,9 @@ * @return a {@link Hyphenation Hyphenation} object representing * the hyphenated word or null if word is not hyphenated. */ - public org.axsl.hyphenR.Hyphenation hyphenate(String word, + public org.axsl.hyphenR.Hyphenation hyphenate(CharSequence word, int remainCharCount, int pushCharCount) { - char[] w = word.toCharArray(); + char[] w = word.toString().toCharArray(); return hyphenate(w, 0, w.length, remainCharCount, pushCharCount); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 19:45:33
|
Revision: 7457 Author: victormote Date: 2006-06-08 12:45:27 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7457&view=rev Log Message: ----------- Conform to axsl changes: Remove not-particularly-useful method. Modified Paths: -------------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java 2006-06-08 19:45:20 UTC (rev 7456) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java 2006-06-08 19:45:27 UTC (rev 7457) @@ -46,20 +46,6 @@ } /** - * @return the pre-break text, not including the hyphen character - */ - public String getPreHyphenText(int index) { - return word.substring(0, hyphenPoints[index]); - } - - /** - * @return the post-break text - */ - public String getPostHyphenText(int index) { - return word.substring(hyphenPoints[index]); - } - - /** * @return the hyphenation points */ public int[] getHyphenationPoints() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 19:45:25
|
Revision: 7456 Author: victormote Date: 2006-06-08 12:45:20 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7456&view=rev Log Message: ----------- Conform to axsl changes: Remove not-particularly-useful method. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 19:15:17 UTC (rev 7455) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 19:45:20 UTC (rev 7456) @@ -368,7 +368,7 @@ } // Select a hyphenation point. int index = selectDiscretionaryHyphenationPoint(this.currentLineText, - hyph); + wordToHyphenate, hyph); // If none fit, then the word cannot be hyphenated. if (index < 0) { return wordStart; @@ -383,18 +383,17 @@ * extracts from a hyphenated word the best (most greedy) fit */ private int selectDiscretionaryHyphenationPoint(LineText lineText, - Hyphenation hyph) throws TextException { + String word, Hyphenation hyph) throws TextException { int remainingWidth = this.currentLineWidthRemaining() - finalWidth - spaceWidth - getHyphenWidth(this.currentLineText); int[] hyphenationPoints = hyph.getHyphenationPoints(); - int numberOfHyphenationPoints = hyphenationPoints.length; int index = -1; String wordBegin = ""; - for (int i = 0; i < numberOfHyphenationPoints; i++) { - wordBegin = hyph.getPreHyphenText(i); + for (int i = 0; i < hyphenationPoints.length; i++) { + wordBegin = word.substring(0, hyphenationPoints[i]); int provisionalWordWidth = getWordWidth(lineText, wordBegin); if (provisionalWordWidth > remainingWidth) { break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 19:15:23
|
Revision: 7455 Author: victormote Date: 2006-06-08 12:15:17 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7455&view=rev Log Message: ----------- Simplify the code by just using the value returned by the hyphenation results. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 18:25:45 UTC (rev 7454) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 19:15:17 UTC (rev 7455) @@ -374,7 +374,7 @@ return wordStart; } // Compute the number of characters that should be included. - int charsToInclude = hyph.getPreHyphenText(index).length(); + int charsToInclude = hyph.getHyphenationPoints()[index]; // Add it and the non-word characters to the count to be returned. return wordStart + nonWordChars + charsToInclude; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 18:25:50
|
Revision: 7454 Author: victormote Date: 2006-06-08 11:25:45 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7454&view=rev Log Message: ----------- Complete fix of Ant build process. Modified Paths: -------------- trunk/foray/foray-text/scripts/build.xml Modified: trunk/foray/foray-text/scripts/build.xml =================================================================== --- trunk/foray/foray-text/scripts/build.xml 2006-06-08 18:14:49 UTC (rev 7453) +++ trunk/foray/foray-text/scripts/build.xml 2006-06-08 18:25:45 UTC (rev 7454) @@ -82,23 +82,6 @@ <!-- =================================================================== --> - <!-- compiles hyphenation patterns --> - <!-- =================================================================== --> - <target name="hyphenation" depends="compile" > - <path id="hyph-classpath"> - <path refid="libs-build-classpath"/> - <pathelement location="${classes.dir}"/> - </path> - <taskdef name="serHyph" - classname="org.foray.text.hyphen.SerializeHyphPattern" - classpathref="hyph-classpath"/> - <serHyph includes="*.xml" - sourceDir="${hyph.source}" - targetDir="${hyph.build}" /> - </target> - - - <!-- =================================================================== --> <!-- Compiles the source directory --> <!-- =================================================================== --> <target name="compile" depends="prepare"> @@ -119,7 +102,7 @@ <!-- =================================================================== --> <!-- Creates the class package --> <!-- =================================================================== --> - <target name="package" depends="compile, style, hyphenation" + <target name="package" depends="compile, style" description="Generates the jar files (default target)"> <echo message="Creating the jar file ${build.dir}/${name}.jar"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 18:15:03
|
Revision: 7453 Author: victormote Date: 2006-06-08 11:14:49 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7453&view=rev Log Message: ----------- Steps toward getting the Ant build working. Modified Paths: -------------- trunk/foray/foray-app/scripts/build.xml trunk/foray/scripts/build.xml Modified: trunk/foray/foray-app/scripts/build.xml =================================================================== --- trunk/foray/foray-app/scripts/build.xml 2006-06-08 18:10:35 UTC (rev 7452) +++ trunk/foray/foray-app/scripts/build.xml 2006-06-08 18:14:49 UTC (rev 7453) @@ -55,6 +55,9 @@ <fileset dir="${foray.home}/foray-pdf/build/ant"> <include name="*.jar"/> </fileset> + <fileset dir="${foray.home}/foray-hyphen-r/build/ant"> + <include name="*.jar"/> + </fileset> <fileset dir="${foray.home}/foray-text/build/ant"> <include name="*.jar"/> </fileset> Modified: trunk/foray/scripts/build.xml =================================================================== --- trunk/foray/scripts/build.xml 2006-06-08 18:10:35 UTC (rev 7452) +++ trunk/foray/scripts/build.xml 2006-06-08 18:14:49 UTC (rev 7453) @@ -105,6 +105,12 @@ <property name="foray.config" value="${foray.config}"/> </ant> + <ant antfile="${foray.home}/foray-hyphen-r/scripts/build.xml" + inheritall="false" + target="package"> + <property name="foray.config" value="${foray.config}"/> + </ant> + <ant antfile="${foray.home}/foray-text/scripts/build.xml" inheritall="false" target="package"> @@ -206,14 +212,18 @@ dir="${foray.home}/foray-font/build/ant/classes"> <include name="**"/> </fileset> + <fileset id="foray-hyphen-classes" + dir="${foray.home}/foray-hyphen-r/build/ant/classes"> + <include name="**"/> + </fileset> + <fileset id="foray-hyphen-resources" + dir="${foray.home}/foray-hyphen-r/build/ant"> + <include name="hyph/**"/> + </fileset> <fileset id="foray-text-classes" dir="${foray.home}/foray-text/build/ant/classes"> <include name="**"/> </fileset> - <fileset id="foray-text-resources" - dir="${foray.home}/foray-text/build/ant"> - <include name="hyph/**"/> - </fileset> <fileset id="foray-fotree-classes" dir="${foray.home}/foray-fotree/build/ant/classes"> <include name="**"/> @@ -256,8 +266,9 @@ <fileset refid="foray-ps-classes"/> <fileset refid="foray-pdf-classes"/> <fileset refid="foray-font-classes"/> + <fileset refid="foray-hyphen-classes"/> + <fileset refid="foray-hyphen-resources"/> <fileset refid="foray-text-classes"/> - <fileset refid="foray-text-resources"/> <fileset refid="foray-fotree-classes"/> <fileset refid="foray-areatree-classes"/> <fileset refid="foray-layout-classes"/> @@ -389,6 +400,7 @@ <pathelement path="${foray.home}/foray-ps/src/java"/> <pathelement path="${foray.home}/foray-graphic/src/java"/> <pathelement path="${foray.home}/foray-font/src/java"/> + <pathelement path="${foray.home}/foray-hyphen-r/src/java"/> <pathelement path="${foray.home}/foray-fotree/src/java"/> <pathelement path="${foray.home}/foray-areatree/src/java"/> <pathelement path="${foray.home}/foray-layout/src/java"/> @@ -425,6 +437,10 @@ <package name="org.foray.font"/> <package name="org.foray.font.*"/> </group> + <group title="The FOray Hyphenation Module"> + <package name="org.foray.hyphenR"/> + <package name="org.foray.hyphenR.*"/> + </group> <group title="The FOray Text Module"> <package name="org.foray.text"/> <package name="org.foray.text.*"/> @@ -514,6 +530,10 @@ inheritall="false" target="clean"/> + <ant antfile="${foray.home}/foray-hyphen-r/scripts/build.xml" + inheritall="false" + target="clean"/> + <ant antfile="${foray.home}/foray-text/scripts/build.xml" inheritall="false" target="clean"/> @@ -577,6 +597,9 @@ <ant antfile="${foray.home}/foray-font/scripts/build.xml" inheritall="false" target="style"/> + <ant antfile="${foray.home}/foray-hyphen-r/scripts/build.xml" + inheritall="false" + target="style"/> <ant antfile="${foray.home}/foray-text/scripts/build.xml" inheritall="false" target="style"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 18:10:45
|
Revision: 7452 Author: victormote Date: 2006-06-08 11:10:35 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7452&view=rev Log Message: ----------- Move hyphenation resource from text module to hyphenation module. Removed Paths: ------------- trunk/foray/foray-text/resource/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 18:10:05
|
Revision: 7451 Author: victormote Date: 2006-06-08 11:09:47 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7451&view=rev Log Message: ----------- Move hyphenation resource from text module to hyphenation module. Added Paths: ----------- trunk/foray/foray-hyphen-r/resource/ Copied: trunk/foray/foray-hyphen-r/resource (from rev 7265, trunk/foray/foray-text/resource) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 17:54:22
|
Revision: 7450 Author: victormote Date: 2006-06-08 10:53:54 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7450&view=rev Log Message: ----------- Get new hyphenation package usable from within Eclipse. Modified Paths: -------------- trunk/foray/foray-hyphen-r/.classpath trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java Modified: trunk/foray/foray-hyphen-r/.classpath =================================================================== --- trunk/foray/foray-hyphen-r/.classpath 2006-06-08 17:53:42 UTC (rev 7449) +++ trunk/foray/foray-hyphen-r/.classpath 2006-06-08 17:53:54 UTC (rev 7450) @@ -3,5 +3,9 @@ <classpathentry excluding=".#*" kind="src" path="src/java"/> <classpathentry kind="src" path="scripts"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="var" path="FORAY_LIB_ROOT/commons-logging.jar"/> + <classpathentry combineaccessrules="false" kind="src" path="/FOrayCommon"/> + <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> + <classpathentry combineaccessrules="false" kind="src" path="/axslHyphen-R"/> <classpathentry kind="output" path="build/eclipse"/> </classpath> Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 17:53:42 UTC (rev 7449) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 17:53:54 UTC (rev 7450) @@ -30,9 +30,8 @@ package org.foray.hyphenR; import org.foray.common.StringUtilPre5; -import org.foray.text.TextServer; -import org.axsl.text.TextException; +import org.axsl.hyphenR.HyphenationException; import org.apache.commons.logging.Log; @@ -52,10 +51,7 @@ */ public class HyphenationServer implements org.axsl.hyphenR.HyphenationServer { - /** - * The "parent" TextServer instance. - */ - private TextServer textServer; + private Log logger; /** * Collection of HyphenationTree instances that have been successfully @@ -76,11 +72,10 @@ /** * Constructor. - * @param textServer The TextServer instance that is the "parent" of this - * HyphenationServer. + * @param logger The Log instance for user messages. */ - public HyphenationServer(TextServer textServer, URL hyphenationDir) { - this.textServer = textServer; + public HyphenationServer(Log logger, URL hyphenationDir) { + this.logger = logger; // TODO: This is klunky. Use the URL. this.hyphenationDir = hyphenationDir.getFile(); } @@ -251,7 +246,7 @@ hTree.printStats(getLogger()); } return hTree; - } catch (TextException ex) { + } catch (HyphenationException ex) { if (errorDump) { getLogger().error("Can't load user patterns " + "from xml file " + this.hyphenationDir @@ -289,7 +284,7 @@ } public Log getLogger() { - return textServer.getLogger(); + return this.logger; } /** Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 17:53:42 UTC (rev 7449) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 17:53:54 UTC (rev 7450) @@ -26,7 +26,7 @@ import org.foray.common.Logging; -import org.axsl.text.TextException; +import org.axsl.hyphenR.HyphenationException; import org.apache.commons.logging.Log; @@ -128,7 +128,7 @@ * Read hyphenation patterns from an XML file. */ public void loadPatterns(String filename, Log logger) - throws TextException { + throws HyphenationException { PatternParser pp = new PatternParser(this, logger); ivalues = new TernaryTree(); Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-06-08 17:53:42 UTC (rev 7449) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-06-08 17:53:54 UTC (rev 7450) @@ -26,7 +26,7 @@ import org.foray.common.Logging; -import org.axsl.text.TextException; +import org.axsl.hyphenR.HyphenationException; import org.apache.commons.logging.Log; @@ -65,7 +65,7 @@ static final int ELEM_PATTERNS = 3; static final int ELEM_HYPHEN = 4; - public PatternParser(Log logger) throws TextException { + public PatternParser(Log logger) throws HyphenationException { this.logger = logger; token = new StringBuffer(); parser = createParser(); @@ -75,7 +75,7 @@ } public PatternParser(PatternConsumer consumer, Log logger) - throws TextException { + throws HyphenationException { this(logger); this.consumer = consumer; } @@ -84,17 +84,17 @@ this.consumer = consumer; } - public void parse(String filename) throws TextException { + public void parse(String filename) throws HyphenationException { InputSource uri = fileInputSource(filename); try { parser.parse(uri); } catch (SAXException e) { - throw new TextException(errMsg); + throw new HyphenationException(errMsg); } catch (IOException e) { - throw new TextException(e.getMessage()); + throw new HyphenationException(e.getMessage()); } catch (NullPointerException e) { - throw new TextException("SAX parser not available"); + throw new HyphenationException("SAX parser not available"); } } @@ -104,7 +104,7 @@ * * @return the created SAX parser */ - static XMLReader createParser() throws TextException { + static XMLReader createParser() throws HyphenationException { String parserClassName = System.getProperty("org.xml.sax.parser"); if (parserClassName == null) { parserClassName = "org.apache.xerces.parsers.SAXParser"; @@ -112,16 +112,16 @@ try { return (XMLReader)Class.forName(parserClassName).newInstance(); } catch (ClassNotFoundException e) { - throw new TextException("Could not find " + throw new HyphenationException("Could not find " + parserClassName); } catch (InstantiationException e) { - throw new TextException("Could not instantiate " + throw new HyphenationException("Could not instantiate " + parserClassName); } catch (IllegalAccessException e) { - throw new TextException("Could not access " + throw new HyphenationException("Could not access " + parserClassName); } catch (ClassCastException e) { - throw new TextException(parserClassName + throw new HyphenationException(parserClassName + " is not a SAX driver"); } } @@ -133,7 +133,7 @@ * @return the InputSource created */ protected static InputSource fileInputSource(String filename) - throws TextException { + throws HyphenationException { /* this code adapted from James Clark's in XT */ File file = new File(filename); @@ -148,7 +148,7 @@ try { return new InputSource(new URL("file", null, path).toString()); } catch (MalformedURLException e) { - throw new TextException("unexpected MalformedURLException"); + throw new HyphenationException("unexpected MalformedURLException"); } } Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java 2006-06-08 17:53:42 UTC (rev 7449) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java 2006-06-08 17:53:54 UTC (rev 7450) @@ -26,7 +26,7 @@ import org.foray.common.Logging; -import org.axsl.text.TextException; +import org.axsl.hyphenR.HyphenationException; import org.apache.commons.logging.Log; import org.apache.tools.ant.BuildException; @@ -117,7 +117,7 @@ getLogger().info("Stats: "); hTree.printStats(getLogger()); } - } catch (TextException ex) { + } catch (HyphenationException ex) { getLogger().error("Can't load patterns from xml file " + infile + " - Maybe hyphenation.dtd is missing?"); if (errorDump) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 17:53:57
|
Revision: 7449 Author: victormote Date: 2006-06-08 10:53:42 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7449&view=rev Log Message: ----------- Get new hyphenation package usable from within Eclipse. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/TextServer.java trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/TextServer.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/TextServer.java 2006-06-08 17:53:28 UTC (rev 7448) +++ trunk/foray/foray-text/src/java/org/foray/text/TextServer.java 2006-06-08 17:53:42 UTC (rev 7449) @@ -24,7 +24,7 @@ package org.foray.text; -import org.foray.hyphenR.HyphenationServer; +import org.axsl.hyphenR.HyphenationServer; import org.foray.text.line.solitary.SolitaryLBS; import org.axsl.fontR.FontConsumer; @@ -35,8 +35,6 @@ import org.apache.commons.logging.Log; -import java.net.URL; - /** * This class encapsulates the various text processing functions. */ @@ -59,9 +57,9 @@ * @param logger The logger instance that should be used to log * user messages. */ - public TextServer(Log logger, URL hyphenationDir) { + public TextServer(Log logger, HyphenationServer hyphenationServer) { this.logger = logger; - this.hyphenationServer = new HyphenationServer(this, hyphenationDir); + this.hyphenationServer = hyphenationServer; } public Log getLogger() { @@ -69,9 +67,6 @@ } public HyphenationServer getHyphenationServer() { - if (this.hyphenationServer == null) { - this.hyphenationServer = new HyphenationServer(this, null); - } return this.hyphenationServer; } Modified: trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java 2006-06-08 17:53:28 UTC (rev 7448) +++ trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java 2006-06-08 17:53:42 UTC (rev 7449) @@ -24,7 +24,7 @@ package org.foray.text.line; -import org.foray.hyphenR.HyphenationServer; +import org.axsl.hyphenR.HyphenationServer; import org.foray.text.TextServer; import org.axsl.fontR.Font; Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 17:53:28 UTC (rev 7448) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 17:53:42 UTC (rev 7449) @@ -25,7 +25,7 @@ package org.foray.text.line.solitary; import org.foray.common.StringUtilPre5; -import org.foray.hyphenR.HyphenationServer; +import org.axsl.hyphenR.HyphenationServer; import org.foray.text.line.EagerLineBreaker; import org.axsl.fontR.FontConsumer; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 17:53:43
|
Revision: 7448 Author: victormote Date: 2006-06-08 10:53:28 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7448&view=rev Log Message: ----------- Get new hyphenation package usable from within Eclipse. Modified Paths: -------------- trunk/foray/foray-app/.classpath trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java Modified: trunk/foray/foray-app/.classpath =================================================================== --- trunk/foray/foray-app/.classpath 2006-06-08 17:36:09 UTC (rev 7447) +++ trunk/foray/foray-app/.classpath 2006-06-08 17:53:28 UTC (rev 7448) @@ -34,5 +34,7 @@ <classpathentry combineaccessrules="false" kind="src" path="/axslLayout"/> <classpathentry combineaccessrules="false" kind="src" path="/FOrayCore"/> <classpathentry combineaccessrules="false" kind="src" path="/axslOutput"/> + <classpathentry combineaccessrules="false" kind="src" path="/axslHyphen-R"/> + <classpathentry combineaccessrules="false" kind="src" path="/FOrayHyphen-R"/> <classpathentry kind="output" path="build/eclipse"/> </classpath> Modified: trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java =================================================================== --- trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2006-06-08 17:36:09 UTC (rev 7447) +++ trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2006-06-08 17:53:28 UTC (rev 7448) @@ -40,6 +40,7 @@ import org.axsl.fontR.FontException; import org.axsl.fontR.FontServer; import org.axsl.graphicR.GraphicServer; +import org.axsl.hyphenR.HyphenationServer; import org.axsl.layout.LayoutFactory; import org.axsl.text.TextServer; @@ -118,8 +119,15 @@ public static TextServer makeTextServer(Log logger, SessionConfig configuration) throws FOrayException { + HyphenationServer hyphenationServer = makeHyphenationServer(logger, + configuration); + return new org.foray.text.TextServer(logger, hyphenationServer); + } + + public static HyphenationServer makeHyphenationServer(Log logger, + SessionConfig configuration) { URL hyphenationDir = configuration.optionHyphenationBaseDirectory(); - return new org.foray.text.TextServer(logger, hyphenationDir); + return new org.foray.hyphenR.HyphenationServer(logger, hyphenationDir); } public static GraphicServer makeGraphicServer(Log logger) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 17:36:42
|
Revision: 7447 Author: victormote Date: 2006-06-08 10:36:09 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7447&view=rev Log Message: ----------- Move hyphenation classes from text package to new hyphenation package (raw, compile errors left intact). Added Paths: ----------- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternConsumer.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/SerializeHyphPattern.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/TernaryTree.java trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/package.html Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java (from rev 7265, trunk/foray/foray-text/src/java/org/foray/text/hyphen/ByteVector.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ByteVector.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,133 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.hyphenR; + +import java.io.Serializable; + +/** + * This class implements a simple byte vector with access to the + * underlying array. + * + * @author Carlos Villegas <ca...@un...> + */ +public class ByteVector implements Serializable { + static final long serialVersionUID = 977379027446677063L; + + /** + * Capacity increment size + */ + private static final int DEFAULT_BLOCK_SIZE = 2048; + private int BLOCK_SIZE; + + /** + * The encapsulated array + */ + private byte[] array; + + /** + * Points to next free item + */ + private int n; + + public ByteVector() { + this(DEFAULT_BLOCK_SIZE); + } + + public ByteVector(int capacity) { + if (capacity > 0) { + BLOCK_SIZE = capacity; + } else { + BLOCK_SIZE = DEFAULT_BLOCK_SIZE; + } + array = new byte[BLOCK_SIZE]; + n = 0; + } + + public ByteVector(byte[] a) { + BLOCK_SIZE = DEFAULT_BLOCK_SIZE; + array = a; + n = 0; + } + + public ByteVector(byte[] a, int capacity) { + if (capacity > 0) { + BLOCK_SIZE = capacity; + } else { + BLOCK_SIZE = DEFAULT_BLOCK_SIZE; + } + array = a; + n = 0; + } + + public byte[] getArray() { + return array; + } + + /** + * return number of items in array + */ + public int length() { + return n; + } + + /** + * returns current capacity of array + */ + public int capacity() { + return array.length; + } + + public void put(int index, byte val) { + array[index] = val; + } + + public byte get(int index) { + return array[index]; + } + + /** + * This is to implement memory allocation in the array. Like malloc(). + */ + public int alloc(int size) { + int index = n; + int len = array.length; + if (n + size >= len) { + byte[] aux = new byte[len + BLOCK_SIZE]; + System.arraycopy(array, 0, aux, 0, len); + array = aux; + } + n += size; + return index; + } + + public void trimToSize() { + if (n < array.length) { + byte[] aux = new byte[n]; + System.arraycopy(array, 0, aux, 0, n); + array = aux; + } + } + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java (from rev 7265, trunk/foray/foray-text/src/java/org/foray/text/hyphen/CharVector.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/CharVector.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,143 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.hyphenR; + +import java.io.Serializable; + +/** + * This class implements a simple char vector with access to the + * underlying array. + * + * @author Carlos Villegas <ca...@un...> + */ +public class CharVector implements Cloneable, Serializable { + static final long serialVersionUID = 234670840738701586L; + + /** + * Capacity increment size + */ + private static final int DEFAULT_BLOCK_SIZE = 2048; + private int BLOCK_SIZE; + + /** + * The encapsulated array + */ + private char[] array; + + /** + * Points to next free item + */ + private int n; + + public CharVector() { + this(DEFAULT_BLOCK_SIZE); + } + + public CharVector(int capacity) { + if (capacity > 0) { + BLOCK_SIZE = capacity; + } else { + BLOCK_SIZE = DEFAULT_BLOCK_SIZE; + } + array = new char[BLOCK_SIZE]; + n = 0; + } + + public CharVector(char[] a) { + BLOCK_SIZE = DEFAULT_BLOCK_SIZE; + array = a; + n = a.length; + } + + public CharVector(char[] a, int capacity) { + if (capacity > 0) { + BLOCK_SIZE = capacity; + } else { + BLOCK_SIZE = DEFAULT_BLOCK_SIZE; + } + array = a; + n = a.length; + } + + /** + * Reset Vector but don't resize or clear elements + */ + public void clear() { + n = 0; + } + + public Object clone() { + CharVector cv = new CharVector((char[])array.clone(), BLOCK_SIZE); + cv.n = this.n; + return cv; + } + + public char[] getArray() { + return array; + } + + /** + * return number of items in array + */ + public int length() { + return n; + } + + /** + * returns current capacity of array + */ + public int capacity() { + return array.length; + } + + public void put(int index, char val) { + array[index] = val; + } + + public char get(int index) { + return array[index]; + } + + public int alloc(int size) { + int index = n; + int len = array.length; + if (n + size >= len) { + char[] aux = new char[len + BLOCK_SIZE]; + System.arraycopy(array, 0, aux, 0, len); + array = aux; + } + n += size; + return index; + } + + public void trimToSize() { + if (n < array.length) { + char[] aux = new char[n]; + System.arraycopy(array, 0, aux, 0, n); + array = aux; + } + } + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java (from rev 7265, trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphen.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphen.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,78 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.hyphenR; + +import java.io.Serializable; + +/** + * This class represents a hyphen. A 'full' hyphen is made of 3 parts: + * the pre-break text, post-break text and no-break. If no line-break + * is generated at this position, the no-break text is used, otherwise, + * pre-break and post-break are used. Typically, pre-break is equal to + * the hyphen character and the others are empty. However, this general + * scheme allows support for cases in some languages where words change + * spelling if they're split across lines, like german's 'backen' which + * hyphenates 'bak-ken'. BTW, this comes from TeX. + * + * @author Carlos Villegas <ca...@un...> + */ + +public class Hyphen implements Serializable { + static final long serialVersionUID = 990405609314441965L; + + public String preBreak; + public String noBreak; + public String postBreak; + + Hyphen(String pre, String no, String post) { + preBreak = pre; + noBreak = no; + postBreak = post; + } + + Hyphen(String pre) { + preBreak = pre; + noBreak = null; + postBreak = null; + } + + public String toString() { + if (noBreak == null + && postBreak == null + && preBreak != null + && preBreak.equals("-")) { + return "-"; + } + StringBuffer res = new StringBuffer("{"); + res.append(preBreak); + res.append("}{"); + res.append(postBreak); + res.append("}{"); + res.append(noBreak); + res.append('}'); + return res.toString(); + } + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java (from rev 7444, trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/Hyphenation.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,80 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +/* + * Known contributors: + * Carlos Villegas <ca...@un...> (original author) + */ + +package org.foray.hyphenR; + +/** + * This class represents a hyphenated word. + */ +public class Hyphenation implements org.axsl.hyphenR.Hyphenation { + int[] hyphenPoints; + String word; + + /** + * rawWord as made of alternating strings and {@link Hyphen Hyphen} + * instances + */ + Hyphenation(String word, int[] points) { + this.word = word; + hyphenPoints = points; + } + + /** + * @return the pre-break text, not including the hyphen character + */ + public String getPreHyphenText(int index) { + return word.substring(0, hyphenPoints[index]); + } + + /** + * @return the post-break text + */ + public String getPostHyphenText(int index) { + return word.substring(hyphenPoints[index]); + } + + /** + * @return the hyphenation points + */ + public int[] getHyphenationPoints() { + return hyphenPoints; + } + + public String toString() { + StringBuffer str = new StringBuffer(); + int start = 0; + for (int i = 0; i < hyphenPoints.length; i++) { + str.append(word.substring(start, hyphenPoints[i]) + "-"); + start = hyphenPoints[i]; + } + str.append(word.substring(start)); + return str.toString(); + } + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java (from rev 7444, trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationServer.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,334 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +/* + * Known contributors: + * @author Carlos Villegas <ca...@un...> (original author) + */ + +package org.foray.hyphenR; + +import org.foray.common.StringUtilPre5; +import org.foray.text.TextServer; + +import org.axsl.text.TextException; + +import org.apache.commons.logging.Log; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.lang.reflect.Method; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +/** + * This class is the main entry point to the hyphenation package. + */ +public class HyphenationServer implements org.axsl.hyphenR.HyphenationServer { + + /** + * The "parent" TextServer instance. + */ + private TextServer textServer; + + /** + * Collection of HyphenationTree instances that have been successfully + * deserialized or parsed. The key is the language or language and country + * connected by an underscore (e.g. en_US). + */ + HashMap hyphenTrees = new HashMap(); + + /** + * Collection of language and language_country combinations for which we + * already know we can't instantiate a HyphenationTree. This is used to + * log only one error message per language. + */ + ArrayList hyphenTreesNotFound = new ArrayList(); + + private boolean errorDump = false; + private String hyphenationDir; + + /** + * Constructor. + * @param textServer The TextServer instance that is the "parent" of this + * HyphenationServer. + */ + public HyphenationServer(TextServer textServer, URL hyphenationDir) { + this.textServer = textServer; + // TODO: This is klunky. Use the URL. + this.hyphenationDir = hyphenationDir.getFile(); + } + + private HyphenationTree getHyphenationTree(String lang, String country) { + String key = lang; + // check whether the country code has been used + if (country != null && !country.equals("none")) { + key += "_" + country; + } + // first try to find it in the cache + if (hyphenTrees.containsKey(key)) { + return (HyphenationTree)hyphenTrees.get(key); + } + if (hyphenTrees.containsKey(lang)) { + return (HyphenationTree)hyphenTrees.get(lang); + } + + /* See if it is one that we already have tried and failed. */ + Iterator iter = hyphenTreesNotFound.iterator(); + while (iter.hasNext()) { + String testedKey = (String) iter.next(); + if (key.equals(testedKey)) { + return null; + } + if (key.equals(lang)) { + return null; + } + } + + HyphenationTree hTree = getHyphenationTree(key); + if (hTree == null) { + hTree = loadHyphenationTree(key, lang); + } + // put it into the pattern cache + if (hTree != null) { + hyphenTrees.put(key, hTree); + } else { + getLogger().error("Couldn't find hyphenation pattern " + + key); + hyphenTreesNotFound.add(key); + } + return hTree; + } + + private InputStream getResourceStream(String key) { + InputStream is = null; + // Try to use Context Class Loader to load the properties file. + try { + Method getCCL = + Thread.class.getMethod("getContextClassLoader", new Class[0]); + if (getCCL != null) { + ClassLoader contextClassLoader = + (ClassLoader)getCCL.invoke(Thread.currentThread(), + new Object[0]); + is = contextClassLoader.getResourceAsStream("hyph/" + key + + ".hyp"); + } + } catch (Exception e) {} + + if (is == null) { + is = HyphenationServer.class.getResourceAsStream("/hyph/" + key + + ".hyp"); + } + + return is; + } + + private HyphenationTree getHyphenationTree(String key) { + HyphenationTree hTree = null; + ObjectInputStream ois = null; + InputStream is = null; + try { + is = getResourceStream(key); + if (is == null) { + if (key.length() == 5) { + is = getResourceStream(key.substring(0, 2)); + if (is != null) { + getLogger().error("Couldn't find hyphenation pattern " + + key + + "\nusing general language pattern " + + key.substring(0, 2) + + " instead."); + } else { + if (errorDump) { + getLogger().error("Couldn't find precompiled " + + "hyphenation pattern " + + key + ".hyp"); + } + return null; + } + } else { + if (errorDump) { + getLogger().error("Couldn't find precompiled " + + "hyphenation pattern " + + key + ".hyp"); + } + return null; + } + } + ois = new ObjectInputStream(is); + hTree = (HyphenationTree)ois.readObject(); + } catch (Exception e) { + e.printStackTrace(); + } + finally { + if (ois != null) { + try { + ois.close(); + } catch (IOException e) { + getLogger().error("can't close hyphenation object stream"); + } + } + } + return hTree; + } + + /** + * load tree from serialized file or xml file + * using configuration settings + */ + private HyphenationTree loadHyphenationTree(String key, + String language) { + if (this.hyphenationDir == null) { + return null; + } + HyphenationTree hTree = null; + // I use here the following convention. The file name specified in + // the configuration is taken as the base name. First we try + // name + ".hyp" assuming a serialized HyphenationTree. If that fails + // we try name + ".xml", assumming a raw hyphenation pattern file. + + // first try serialized object + File hyphenFile = new File(this.hyphenationDir, key + ".hyp"); + if (hyphenFile.exists()) { + ObjectInputStream ois = null; + try { + ois = new ObjectInputStream(new FileInputStream(hyphenFile)); + hTree = (HyphenationTree)ois.readObject(); + } catch (Exception e) { + e.printStackTrace(); + } + finally { + if (ois != null) { + try { + ois.close(); + } catch (IOException e) {} + } + } + return hTree; + } + + // try the raw XML file + hyphenFile = new File(this.hyphenationDir, key + ".xml"); + if (! hyphenFile.exists()) { + hyphenFile = new File(this.hyphenationDir, language + ".xml"); + } + if (hyphenFile.exists()) { + hTree = new HyphenationTree(); + if (errorDump) { + getLogger().error("reading " + this.hyphenationDir + key + + ".xml"); + } + try { + hTree.loadPatterns(hyphenFile.getPath(), getLogger()); + if (errorDump) { + getLogger().debug("Stats: "); + hTree.printStats(getLogger()); + } + return hTree; + } catch (TextException ex) { + if (errorDump) { + getLogger().error("Can't load user patterns " + + "from xml file " + this.hyphenationDir + + key + ".xml"); + } + return null; + } + } + if (errorDump) { + getLogger().error("Tried to load " + + hyphenFile.toString() + + "\nCannot find compiled nor xml file for " + + "hyphenation pattern" + key); + } + return null; + } + + public org.axsl.hyphenR.Hyphenation hyphenate(String word, String language, + String country, int remainCount, int pushCount) { + HyphenationTree hTree = getHyphenationTree(language, country); + if (hTree == null) { + return null; + } + return hTree.hyphenate(word, remainCount, pushCount); + } + + public org.axsl.hyphenR.Hyphenation hyphenate(char[] word, int offset, + int len, String language, String country, int remainCount, + int pushCount) { + HyphenationTree hTree = getHyphenationTree(language, country); + if (hTree == null) { + return null; + } + return hTree.hyphenate(word, offset, len, remainCount, pushCount); + } + + public Log getLogger() { + return textServer.getLogger(); + } + + /** + * extracts a complete word from the character data + */ + public String getHyphenationWord(char[] characters, int wordStart) { + boolean wordendFound = false; + int counter = 0; + int[] newWord = new int[characters.length]; // create a buffer + while ((!wordendFound) + && ((wordStart + counter) < characters.length)) { + int tk = characters[wordStart + counter]; + if (StringUtilPre5.isLetter(tk)) { + newWord[counter] = tk; + counter++; + } else { + wordendFound = true; + } + } + return StringUtilPre5.newString(newWord, 0, counter); + } + + /** + * Returns the count of non-word characters at the beginning of the text + * being evaluated. This includes characters like " and ' which are not + * really part of the word, but which must be passed through to the output. + * @param characters The char array being evaluated. + * @param startIndex Index into the first character in characters that + * should be evaluated. + * @return The number of characters at the start that should be ignored for + * purposes of forming a word to be evaluated for hyphenation. + */ + public int nonWordChars(char[] characters, int startIndex) { + int count = 0; + // Look for ' or " at the beginning of the word. + if (characters[startIndex] == '"' || characters[startIndex] == '\'') { + count ++; + } + return count; + } + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java (from rev 7444, trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,533 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.hyphenR; + +import org.foray.common.Logging; + +import org.axsl.text.TextException; + +import org.apache.commons.logging.Log; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * This tree structure stores the hyphenation patterns in an efficient + * way for fast lookup. It provides the provides the method to + * hyphenate a word. + * + * @author Carlos Villegas <ca...@un...> + */ +public class HyphenationTree extends TernaryTree implements PatternConsumer, + Serializable { + static final long serialVersionUID = 734862840356804663L; + + /** + * value space: stores the inteletter values + */ + protected ByteVector vspace; + + /** + * This map stores hyphenation exceptions + */ + protected HashMap stoplist; + + /** + * This map stores the character classes + */ + protected TernaryTree classmap; + + /** + * Temporary map to store interletter values on pattern loading. + */ + private transient TernaryTree ivalues; + + public HyphenationTree() { + stoplist = new HashMap(23); // usually a small table + classmap = new TernaryTree(); + vspace = new ByteVector(); + vspace.alloc(1); // this reserves index 0, which we don't use + } + + /** + * Packs the values by storing them in 4 bits, two values into a byte + * Values range is from 0 to 9. We use zero as terminator, + * so we'll add 1 to the value. + * @param values a string of digits from '0' to '9' representing the + * interletter values. + * @return the index into the vspace array where the packed values + * are stored. + */ + protected int packValues(String values) { + int i, n = values.length(); + int m = (n & 1) == 1 ? (n >> 1) + 2 : (n >> 1) + 1; + int offset = vspace.alloc(m); + byte[] va = vspace.getArray(); + for (i = 0; i < n; i++) { + int j = i >> 1; + byte v = (byte)((values.charAt(i) - '0' + 1) & 0x0f); + if ((i & 1) == 1) { + va[j + offset] = (byte)(va[j + offset] | v); + } else { + va[j + offset] = (byte)(v << 4); // big endian + } + } + va[m - 1 + offset] = 0; // terminator + return offset; + } + + protected String unpackValues(int k) { + StringBuffer buf = new StringBuffer(); + byte v = vspace.get(k++); + while (v != 0) { + char c = (char)((v >>> 4) - 1 + '0'); + buf.append(c); + c = (char)(v & 0x0f); + if (c == 0) { + break; + } + c = (char)(c - 1 + '0'); + buf.append(c); + v = vspace.get(k++); + } + return buf.toString(); + } + + /** + * Read hyphenation patterns from an XML file. + */ + public void loadPatterns(String filename, Log logger) + throws TextException { + PatternParser pp = new PatternParser(this, logger); + ivalues = new TernaryTree(); + + pp.parse(filename); + + // patterns/values should be now in the tree + // let's optimize a bit + trimToSize(); + vspace.trimToSize(); + classmap.trimToSize(); + + // get rid of the auxiliary map + ivalues = null; + } + + public String findPattern(String pat) { + int k = super.find(pat); + if (k >= 0) { + return unpackValues(k); + } + return ""; + } + + /** + * String compare, returns 0 if equal or + * t is a substring of s + */ + protected int hstrcmp(char[] s, int si, char[] t, int ti) { + for (; s[si] == t[ti]; si++, ti++) { + if (s[si] == 0) { + return 0; + } + } + if (t[ti] == 0) { + return 0; + } + return s[si] - t[ti]; + } + + protected byte[] getValues(int k) { + StringBuffer buf = new StringBuffer(); + byte v = vspace.get(k++); + while (v != 0) { + char c = (char)((v >>> 4) - 1); + buf.append(c); + c = (char)(v & 0x0f); + if (c == 0) { + break; + } + c = (char)(c - 1); + buf.append(c); + v = vspace.get(k++); + } + byte[] res = new byte[buf.length()]; + for (int i = 0; i < res.length; i++) { + res[i] = (byte)buf.charAt(i); + } + return res; + } + + /** + * <p>Search for all possible partial matches of word starting + * at index an update interletter values. In other words, it + * does something like:</p> + * <code> + * for(i=0; i<patterns.length; i++) { + * if ( word.substring(index).startsWidth(patterns[i]) ) + * update_interletter_values(patterns[i]); + * } + * </code> + * <p>But it is done in an efficient way since the patterns are + * stored in a ternary tree. In fact, this is the whole purpose + * of having the tree: doing this search without having to test + * every single pattern. The number of patterns for languages + * such as English range from 4000 to 10000. Thus, doing thousands + * of string comparisons for each word to hyphenate would be + * really slow without the tree. The tradeoff is memory, but + * using a ternary tree instead of a trie, almost halves the + * the memory used by Lout or TeX. It's also faster than using + * a hash table</p> + * @param word null terminated word to match + * @param index start index from word + * @param il interletter values array to update + */ + protected void searchPatterns(char[] word, int index, byte[] il) { + byte[] values; + int i = index; + char p, q; + char sp = word[i]; + p = root; + + while (p > 0 && p < sc.length) { + if (sc[p] == 0xFFFF) { + if (hstrcmp(word, i, kv.getArray(), lo[p]) == 0) { + values = getValues(eq[p]); // data pointer is in eq[] + int j = index; + for (int k = 0; k < values.length; k++) { + if (j < il.length && values[k] > il[j]) { + il[j] = values[k]; + } + j++; + } + } + return; + } + int d = sp - sc[p]; + if (d == 0) { + if (sp == 0) { + break; + } + sp = word[++i]; + p = eq[p]; + q = p; + + // look for a pattern ending at this position by searching for + // the null char ( splitchar == 0 ) + while (q > 0 && q < sc.length) { + if (sc[q] == 0xFFFF) { // stop at compressed branch + break; + } + if (sc[q] == 0) { + values = getValues(eq[q]); + int j = index; + for (int k = 0; k < values.length; k++) { + if (j < il.length && values[k] > il[j]) { + il[j] = values[k]; + } + j++; + } + break; + } + q = lo[q]; + /** + * actually the code should be: + * q = sc[q] < 0 ? hi[q] : lo[q]; + * but java chars are unsigned + */ + } + } else { + p = d < 0 ? lo[p] : hi[p]; + } + } + } + + /** + * Hyphenate word and return a Hyphenation object. + * @param word the word to be hyphenated + * @param remainCharCount Minimum number of characters allowed + * before the hyphenation point. + * @param pushCharCount Minimum number of characters allowed after + * the hyphenation point. + * @return a {@link Hyphenation Hyphenation} object representing + * the hyphenated word or null if word is not hyphenated. + */ + public org.axsl.hyphenR.Hyphenation hyphenate(String word, + int remainCharCount, int pushCharCount) { + char[] w = word.toCharArray(); + return hyphenate(w, 0, w.length, remainCharCount, pushCharCount); + } + + /** + * Hyphenate word and return an array of hyphenation points. + * @param w char array that contains the word + * @param offset Offset to first character in word + * @param len Length of word + * @param remainCharCount Minimum number of characters allowed + * before the hyphenation point. + * @param pushCharCount Minimum number of characters allowed after + * the hyphenation point. + * @return a {@link Hyphenation Hyphenation} object representing + * the hyphenated word or null if word is not hyphenated. + */ + public org.axsl.hyphenR.Hyphenation hyphenate(char[] w, int offset, int len, + int remainCharCount, int pushCharCount) { + char[] word = new char[len + 3]; + + // normalize word + char[] c = new char[2]; + for (int i = 1; i <= len; i++) { + c[0] = w[offset + i - 1]; + int nc = classmap.find(c, 0); + if (nc < 0) { // found a non-letter character, abort + return null; + } + word[i] = (char)nc; + } + int[] result = new int[len + 1]; + int k = 0; + + // check exception list first + String sw = new String(word, 1, len); + if (stoplist.containsKey(sw)) { + /* assume only simple hyphens (Hyphen.pre="-", + * Hyphen.post = Hyphen.no = null) */ + ArrayList hw = (ArrayList)stoplist.get(sw); + int j = 0; + for (int i = 0; i < hw.size(); i++) { + Object o = hw.get(i); + if (o instanceof String) { + j += ((String)o).length(); + if (j >= remainCharCount && j < (len - pushCharCount)) { + result[k++] = j; + } + } + } + } else { + // use algorithm to get hyphenation points + word[0] = '.'; // word start marker + word[len + 1] = '.'; // word end marker + word[len + 2] = 0; // null terminated + byte[] il = new byte[len + 3]; // initialized to zero + for (int i = 0; i < len + 1; i++) { + searchPatterns(word, i, il); + } + + // hyphenation points are located where interletter value is odd + for (int i = 0; i < len; i++) { + if (((il[i + 1] & 1) == 1) && i >= remainCharCount + && i <= (len - pushCharCount)) { + result[k++] = i; + } + } + } + + + if (k > 0) { + // trim result array + int[] res = new int[k]; + System.arraycopy(result, 0, res, 0, k); + return new Hyphenation(new String(w, offset, len), res); + } + return null; + } + + /** + * Add a character class to the tree. It is used by + * {@link PatternParser PatternParser} as callback to + * add character classes. Character classes define the + * valid word characters for hyphenation. If a word contains + * a character not defined in any of the classes, it is not hyphenated. + * It also defines a way to normalize the characters in order + * to compare them with the stored patterns. Usually pattern + * files use only lower case characters, in this case a class + * for letter 'a', for example, should be defined as "aA", the first + * character being the normalization char. + */ + public void addClass(String chargroup) { + if (chargroup.length() > 0) { + char equivChar = chargroup.charAt(0); + char[] key = new char[2]; + key[1] = 0; + for (int i = 0; i < chargroup.length(); i++) { + key[0] = chargroup.charAt(i); + classmap.insert(key, 0, equivChar); + } + } + } + + /** + * Add an exception to the tree. It is used by + * {@link PatternParser PatternParser} class as callback to + * store the hyphenation exceptions. + * @param word normalized word + * @param hyphenatedword a ArrayList of alternating strings and + * {@link Hyphen hyphen} objects. + */ + public void addException(String word, ArrayList hyphenatedword) { + stoplist.put(word, hyphenatedword); + } + + /** + * Add a pattern to the tree. Mainly, to be used by + * {@link PatternParser PatternParser} class as callback to + * add a pattern to the tree. + * @param pattern the hyphenation pattern + * @param ivalue interletter weight values indicating the + * desirability and priority of hyphenating at a given point + * within the pattern. It should contain only digit characters. + * (i.e. '0' to '9'). + */ + public void addPattern(String pattern, String ivalue) { + int k = ivalues.find(ivalue); + if (k <= 0) { + k = packValues(ivalue); + ivalues.insert(ivalue, (char)k); + } + insert(pattern, (char)k); + } + + public void printStats(Log logger) { + logger.info("Value space size = " + Integer.toString(vspace.length())); + super.printStats(logger); + } + + public static void main(String[] argv) throws Exception { + Log logger = Logging.makeDefaultLogger(); + HyphenationTree ht = null; + int minCharCount = 2; + BufferedReader in = + new BufferedReader(new InputStreamReader(System.in)); + for (; ; ) { + logger.info("l:\tload patterns from XML\n" + + "L:\tload patterns from serialized object\n" + + "s:\tset minimun character count\n" + + "w:\twrite hyphenation tree to object file\n" + + "h:\thyphenate\n" + + "f:\tfind pattern\n" + + "b:\tbenchmark\n" + + "q:\tquit\n" + + "\nCommand:"); + String token = in.readLine().trim(); + if (token.equals("f")) { + logger.info("Pattern: "); + token = in.readLine().trim(); + logger.info("Values: " + ht.findPattern(token)); + } else if (token.equals("s")) { + logger.info("Minimun value: "); + token = in.readLine().trim(); + minCharCount = Integer.parseInt(token); + } else if (token.equals("l")) { + ht = new HyphenationTree(); + logger.info("XML file name: "); + token = in.readLine().trim(); + ht.loadPatterns(token, logger); + } else if (token.equals("L")) { + ObjectInputStream ois = null; + logger.info("Object file name: "); + token = in.readLine().trim(); + try { + ois = new ObjectInputStream(new FileInputStream(token)); + ht = (HyphenationTree)ois.readObject(); + } catch (Exception e) { + e.printStackTrace(); + } + finally { + if (ois != null) { + try { + ois.close(); + } catch (IOException e) {} + } + } + } else if (token.equals("w")) { + logger.info("Object file name: "); + token = in.readLine().trim(); + ObjectOutputStream oos = null; + try { + oos = new ObjectOutputStream(new FileOutputStream(token)); + oos.writeObject(ht); + } catch (Exception e) { + e.printStackTrace(); + } + finally { + if (oos != null) { + try { + oos.flush(); + } catch (IOException e) {} + try { + oos.close(); + } catch (IOException e) {} + } + } + } else if (token.equals("h")) { + logger.info("Word: "); + token = in.readLine().trim(); + logger.info("Hyphenation points: "); + logger.info(ht.hyphenate(token, minCharCount, + minCharCount).toString()); + } else if (token.equals("b")) { + if (ht == null) { + logger.info("No patterns has been loaded."); + break; + } + logger.info("Word list filename: "); + token = in.readLine().trim(); + long starttime = 0; + int counter = 0; + ; + try { + BufferedReader reader = + new BufferedReader(new FileReader(token)); + + starttime = System.currentTimeMillis(); + while ((reader.readLine()) != null) { + counter++; + } + } catch (Exception ioe) { + logger.info("Exception " + ioe); + ioe.printStackTrace(); + } + long endtime = System.currentTimeMillis(); + long result = endtime - starttime; + logger.info(counter + " words hypehanted in " + result + + " milliseconds."); + + } else if (token.equals("q")) { + break; + } + } + + } + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternConsumer.java (from rev 7265, trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternConsumer.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternConsumer.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternConsumer.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,62 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.hyphenR; + +import java.util.ArrayList; + +/** + * This interface is used to connect the XML pattern file parser to + * the hyphenation tree. + * + * @author Carlos Villegas <ca...@un...> + */ +public interface PatternConsumer { + + /** + * Add a character class. + * A character class defines characters that are considered + * equivalent for the purpose of hyphenation (e.g. "aA"). It + * usually means to ignore case. + */ + void addClass(String chargroup); + + /** + * Add a hyphenation exception. An exception replaces the + * result obtained by the algorithm for cases for which this + * fails or the user wants to provide his own hyphenation. + * A hyphenatedword is a ArrayList of alternating String's and + * {@link Hyphen Hyphen} instances + */ + void addException(String word, ArrayList hyphenatedword); + + /** + * Add hyphenation patterns. + * @param pattern + * @param values interletter values expressed as a string of + * digit characters. + */ + void addPattern(String pattern, String values); + +} Copied: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java (from rev 7265, trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternParser.java) =================================================================== --- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java (rev 0) +++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/PatternParser.java 2006-06-08 17:36:09 UTC (rev 7447) @@ -0,0 +1,439 @@ +/* + * Copyright 2004 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.hyphenR; + +import org.foray.common.Logging; + +import org.axsl.text.TextException; + +import org.apache.commons.logging.Log; + +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.DefaultHandler; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; + +/** + * A SAX document handler to read and parse hyphenation patterns + * from a XML file. + * + * @author Carlos Villegas <ca...@un...> + */ +public class PatternParser extends DefaultHandler implements PatternConsumer { + + XMLReader parser; + int currElement; + PatternConsumer consumer; + StringBuffer token; + ArrayList exception; + char hyphenChar; + String errMsg; + Log logger; + + static final int ELEM_CLASSES = 1; + static final int ELEM_EXCEPTIONS = 2; + static final int ELEM_PATTERNS = 3; + static final int ELEM_HYPHEN = 4; + + public PatternParser(Log logger) throws TextException { + this.logger = logger; + token = new StringBuffer(); + parser = createParser(); + parser.setContentHandler(this); + parser.setErrorHandler(this); + hyphenChar = '-'; // default + } + + public PatternParser(PatternConsumer consumer, Log logger) + throws TextException { + this(logger); + this.consumer = consumer; + } + + public void setConsumer(PatternConsumer consumer) { + this.consumer = consumer; + } + + public void parse(String filename) throws TextException { + InputSource uri = fileInputSource(filename); + + try { + parser.parse(uri); + } catch (SAXException e) { + throw new TextException(errMsg); + } catch (IOException e) { + throw new TextException(e.getMessage()); + } catch (NullPointerException e) { + throw new TextException("SAX parser not available"); + } + } + + /** + * creates a SAX parser, using the value of org.xml.sax.parser + * defaulting to org.apache.xerces.parsers.SAXParser + * + * @return the created SAX parser + */ + static XMLReader createParser() throws TextException { + String parserClassName = System.getProperty("org.xml.sax.parser"); + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + try { + return (XMLReader)Class.forName(parserClassName).newInstance(); + } catch (ClassNotFoundException e) { + throw new TextException("Could not find " + + parserClassName); + } catch (InstantiationException e) { + throw new TextException("Could not instantiate " + + parserClassName); + } catch (IllegalAccessException e) { + throw new TextException("Could not access " + + parserClassName); + } catch (ClassCastException e) { + throw new TextException(parserClassName + + " is not a SAX driver"); + } + } + + /** + * create an InputSource from a file name + * + * @param filename the name of the file + * @return the InputSource created + */ + protected static InputSource fileInputSource(String filename) + throws TextException { + + /* this code adapted from James Clark's in XT */ + File file = new File(filename); + String path = file.getAbsolutePath(); + String fSep = System.getProperty("file.separator"); + if (fSep != null && fSep.length() == 1) { + path = path.replace(fSep.charAt(0), '/'); + } + if (path.length() > 0 && path.charAt(0) != '/') { + path = '/' + path; + } + try { + return new InputSource(new URL("file", null, path).toString()); + } catch (MalformedURLException e) { + throw new TextException("unexpected MalformedURLException"); + } + } + + protected String readToken(StringBuffer chars) { + String word; + boolean space = false; + int i; + for (i = 0; i < chars.length(); i++) { + if (Character.isWhitespace(chars.charAt(i))) { + space = true; + } else { + break; + } + } + if (space) { + for (int countr = i; countr < chars.length(); countr++) { + chars.setCharAt(countr - i, chars.charAt(countr)); + } + chars.setLength(chars.length() - i); + if (token.length() > 0) { + word = token.toString(); + token.setLength(0); + return word; + } + } + space = false; + for (i = 0; i < chars.length(); i++) { + if (Character.isWhitespace(chars.charAt(i))) { + space = true; + break; + } + } + token.append(chars.toString().substring(0, i)); + for (int countr = i; countr < chars.length(); countr++) { + chars.setCharAt(countr - i, chars.charAt(countr)); + } + chars.setLength(chars.length() - i); + if (space) { + word = token.toString(); + token.setLength(0); + return word; + } + token.append(chars); + return null; + } + + protected static String getPattern(String word) { + StringBuffer pat = new StringBuffer(); + int len = word.length(); + for (int i = 0; i < len; i++) { + if (!Character.isDigit(word.charAt(i))) { + pat.append(word.charAt(i)); + } + } + return pat.toString(); + } + + protected ArrayList normalizeException(ArrayList ex) { + ArrayList res = new ArrayList(); + for (int i = 0; i < ex.size(); i++) { + Object item = ex.get(i); + if (item instanceof String) { + String str = (String)item; + StringBuffer buf = new StringBuffer(); + for (int j = 0; j < str.length(); j++) { + char c = str.charAt(j); + if (c != hyphenChar) { + buf.append(c); + } else { + res.add(buf.toString()); + buf.setLength(0); + char[] h = new char[1]; + h[0] = hyphenChar; + // we use here hyphenChar which is not necessarily + // the one to be printed + res.add(new Hyphen(new String(h), null, null)); + } + } + if (buf.length() > 0) { + res.add(buf.toString()); + } + } else { + res.add(item); + } + } + return res; + } + + protected String getExceptionWord(ArrayList ex) { + StringBuffer res = new StringBuffer(); + for (int i = 0; i < ex.size(); i++) { + Object item = ex.get(i); + if (item instanceof String) { + res.append((String)item); + } else { + if (((Hyphen)item).noBreak != null) { + res.append(((Hyphen)item).noBreak); + } + } + } + return res.toString(); + } + + protected static String getInterletterValues(String pat) { + StringBuffer il = new StringBuffer(); + String word = pat + "a"; // add dummy letter to serve as sentinel + int len = word.length(); + for (int i = 0; i < len; i++) { + char c = word.charAt(i); + if (Character.isDigit(c)) { + il.append(c); + i++; + } else { + il.append('0'); + } + } + return il.toString(); + } + + // + // DocumentHandler methods + // + + /** + * Start element. + */ + public void startElement(String uri, String local, String raw, + Attributes attrs) { + if (local.equals("hyphen-char")) { + String h = attrs.getValue("value"); + if (h != null && h.length() == 1) { + hyphenChar = h.charAt(0); + } + } else if (local.equals("classes")) { + currElement = ELEM_CLASSES; + } else if (local.equals("patterns")) { + currElement = ELEM_PATTERNS; + } else if (local.equals("exceptions")) { + currElement = ELEM_EXCEPTIONS; + exception = new ArrayList(); + } else if (local.equals("hyphen")) { + if (token.length() > 0) { + exception.add(token.toString()); + } + exception.add(new Hyphen(attrs.getValue("pre"), + attrs.getValue("no"), attrs.getValue("post"))); + currElement = ELEM_HYPHEN; + } + token.setLength(0); + } + + public void endElement(String uri, String local, String raw) { + + if (token.length() > 0) { + String word = token.toString(); + switch (currElement) { + case ELEM_CLASSES: + consumer.addClass(word); + break; + case ELEM_EXCEPTIONS: + exception.add(word); + exception = normalizeException(exception); + consumer.addException(getExceptionWord(exception), + (ArrayList) exception.clone()); + break; + case ELEM_PATTERNS: + consumer.addPattern(getPattern(word), + getInterletterValues(word)); + break; + case ELEM_HYPHEN: + break; + }... [truncated message content] |
|
From: <vic...@us...> - 2006-06-08 17:36:07
|
Revision: 7446 Author: victormote Date: 2006-06-08 10:35:48 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7446&view=rev Log Message: ----------- Move hyphenation classes from text package to new hyphenation package (raw, compile errors left intact). Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/TextServer.java trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Removed Paths: ------------- trunk/foray/foray-text/src/java/org/foray/text/hyphen/ByteVector.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/CharVector.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphen.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternConsumer.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternParser.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/SerializeHyphPattern.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/TernaryTree.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/package.html Modified: trunk/foray/foray-text/src/java/org/foray/text/TextServer.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/TextServer.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/TextServer.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -24,7 +24,7 @@ package org.foray.text; -import org.foray.text.hyphen.HyphenationServer; +import org.foray.hyphenR.HyphenationServer; import org.foray.text.line.solitary.SolitaryLBS; import org.axsl.fontR.FontConsumer; Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/ByteVector.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/ByteVector.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/ByteVector.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,133 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.text.hyphen; - -import java.io.Serializable; - -/** - * This class implements a simple byte vector with access to the - * underlying array. - * - * @author Carlos Villegas <ca...@un...> - */ -public class ByteVector implements Serializable { - static final long serialVersionUID = 977379027446677063L; - - /** - * Capacity increment size - */ - private static final int DEFAULT_BLOCK_SIZE = 2048; - private int BLOCK_SIZE; - - /** - * The encapsulated array - */ - private byte[] array; - - /** - * Points to next free item - */ - private int n; - - public ByteVector() { - this(DEFAULT_BLOCK_SIZE); - } - - public ByteVector(int capacity) { - if (capacity > 0) { - BLOCK_SIZE = capacity; - } else { - BLOCK_SIZE = DEFAULT_BLOCK_SIZE; - } - array = new byte[BLOCK_SIZE]; - n = 0; - } - - public ByteVector(byte[] a) { - BLOCK_SIZE = DEFAULT_BLOCK_SIZE; - array = a; - n = 0; - } - - public ByteVector(byte[] a, int capacity) { - if (capacity > 0) { - BLOCK_SIZE = capacity; - } else { - BLOCK_SIZE = DEFAULT_BLOCK_SIZE; - } - array = a; - n = 0; - } - - public byte[] getArray() { - return array; - } - - /** - * return number of items in array - */ - public int length() { - return n; - } - - /** - * returns current capacity of array - */ - public int capacity() { - return array.length; - } - - public void put(int index, byte val) { - array[index] = val; - } - - public byte get(int index) { - return array[index]; - } - - /** - * This is to implement memory allocation in the array. Like malloc(). - */ - public int alloc(int size) { - int index = n; - int len = array.length; - if (n + size >= len) { - byte[] aux = new byte[len + BLOCK_SIZE]; - System.arraycopy(array, 0, aux, 0, len); - array = aux; - } - n += size; - return index; - } - - public void trimToSize() { - if (n < array.length) { - byte[] aux = new byte[n]; - System.arraycopy(array, 0, aux, 0, n); - array = aux; - } - } - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/CharVector.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/CharVector.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/CharVector.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,143 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.text.hyphen; - -import java.io.Serializable; - -/** - * This class implements a simple char vector with access to the - * underlying array. - * - * @author Carlos Villegas <ca...@un...> - */ -public class CharVector implements Cloneable, Serializable { - static final long serialVersionUID = 234670840738701586L; - - /** - * Capacity increment size - */ - private static final int DEFAULT_BLOCK_SIZE = 2048; - private int BLOCK_SIZE; - - /** - * The encapsulated array - */ - private char[] array; - - /** - * Points to next free item - */ - private int n; - - public CharVector() { - this(DEFAULT_BLOCK_SIZE); - } - - public CharVector(int capacity) { - if (capacity > 0) { - BLOCK_SIZE = capacity; - } else { - BLOCK_SIZE = DEFAULT_BLOCK_SIZE; - } - array = new char[BLOCK_SIZE]; - n = 0; - } - - public CharVector(char[] a) { - BLOCK_SIZE = DEFAULT_BLOCK_SIZE; - array = a; - n = a.length; - } - - public CharVector(char[] a, int capacity) { - if (capacity > 0) { - BLOCK_SIZE = capacity; - } else { - BLOCK_SIZE = DEFAULT_BLOCK_SIZE; - } - array = a; - n = a.length; - } - - /** - * Reset Vector but don't resize or clear elements - */ - public void clear() { - n = 0; - } - - public Object clone() { - CharVector cv = new CharVector((char[])array.clone(), BLOCK_SIZE); - cv.n = this.n; - return cv; - } - - public char[] getArray() { - return array; - } - - /** - * return number of items in array - */ - public int length() { - return n; - } - - /** - * returns current capacity of array - */ - public int capacity() { - return array.length; - } - - public void put(int index, char val) { - array[index] = val; - } - - public char get(int index) { - return array[index]; - } - - public int alloc(int size) { - int index = n; - int len = array.length; - if (n + size >= len) { - char[] aux = new char[len + BLOCK_SIZE]; - System.arraycopy(array, 0, aux, 0, len); - array = aux; - } - n += size; - return index; - } - - public void trimToSize() { - if (n < array.length) { - char[] aux = new char[n]; - System.arraycopy(array, 0, aux, 0, n); - array = aux; - } - } - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphen.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphen.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphen.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,78 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.text.hyphen; - -import java.io.Serializable; - -/** - * This class represents a hyphen. A 'full' hyphen is made of 3 parts: - * the pre-break text, post-break text and no-break. If no line-break - * is generated at this position, the no-break text is used, otherwise, - * pre-break and post-break are used. Typically, pre-break is equal to - * the hyphen character and the others are empty. However, this general - * scheme allows support for cases in some languages where words change - * spelling if they're split across lines, like german's 'backen' which - * hyphenates 'bak-ken'. BTW, this comes from TeX. - * - * @author Carlos Villegas <ca...@un...> - */ - -public class Hyphen implements Serializable { - static final long serialVersionUID = 990405609314441965L; - - public String preBreak; - public String noBreak; - public String postBreak; - - Hyphen(String pre, String no, String post) { - preBreak = pre; - noBreak = no; - postBreak = post; - } - - Hyphen(String pre) { - preBreak = pre; - noBreak = null; - postBreak = null; - } - - public String toString() { - if (noBreak == null - && postBreak == null - && preBreak != null - && preBreak.equals("-")) { - return "-"; - } - StringBuffer res = new StringBuffer("{"); - res.append(preBreak); - res.append("}{"); - res.append(postBreak); - res.append("}{"); - res.append(noBreak); - res.append('}'); - return res.toString(); - } - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,80 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -/* - * Known contributors: - * Carlos Villegas <ca...@un...> (original author) - */ - -package org.foray.text.hyphen; - -/** - * This class represents a hyphenated word. - */ -public class Hyphenation implements org.axsl.hyphenR.Hyphenation { - int[] hyphenPoints; - String word; - - /** - * rawWord as made of alternating strings and {@link Hyphen Hyphen} - * instances - */ - Hyphenation(String word, int[] points) { - this.word = word; - hyphenPoints = points; - } - - /** - * @return the pre-break text, not including the hyphen character - */ - public String getPreHyphenText(int index) { - return word.substring(0, hyphenPoints[index]); - } - - /** - * @return the post-break text - */ - public String getPostHyphenText(int index) { - return word.substring(hyphenPoints[index]); - } - - /** - * @return the hyphenation points - */ - public int[] getHyphenationPoints() { - return hyphenPoints; - } - - public String toString() { - StringBuffer str = new StringBuffer(); - int start = 0; - for (int i = 0; i < hyphenPoints.length; i++) { - str.append(word.substring(start, hyphenPoints[i]) + "-"); - start = hyphenPoints[i]; - } - str.append(word.substring(start)); - return str.toString(); - } - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,334 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -/* - * Known contributors: - * @author Carlos Villegas <ca...@un...> (original author) - */ - -package org.foray.text.hyphen; - -import org.foray.common.StringUtilPre5; -import org.foray.text.TextServer; - -import org.axsl.text.TextException; - -import org.apache.commons.logging.Log; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -/** - * This class is the main entry point to the hyphenation package. - */ -public class HyphenationServer implements org.axsl.hyphenR.HyphenationServer { - - /** - * The "parent" TextServer instance. - */ - private TextServer textServer; - - /** - * Collection of HyphenationTree instances that have been successfully - * deserialized or parsed. The key is the language or language and country - * connected by an underscore (e.g. en_US). - */ - HashMap hyphenTrees = new HashMap(); - - /** - * Collection of language and language_country combinations for which we - * already know we can't instantiate a HyphenationTree. This is used to - * log only one error message per language. - */ - ArrayList hyphenTreesNotFound = new ArrayList(); - - private boolean errorDump = false; - private String hyphenationDir; - - /** - * Constructor. - * @param textServer The TextServer instance that is the "parent" of this - * HyphenationServer. - */ - public HyphenationServer(TextServer textServer, URL hyphenationDir) { - this.textServer = textServer; - // TODO: This is klunky. Use the URL. - this.hyphenationDir = hyphenationDir.getFile(); - } - - private HyphenationTree getHyphenationTree(String lang, String country) { - String key = lang; - // check whether the country code has been used - if (country != null && !country.equals("none")) { - key += "_" + country; - } - // first try to find it in the cache - if (hyphenTrees.containsKey(key)) { - return (HyphenationTree)hyphenTrees.get(key); - } - if (hyphenTrees.containsKey(lang)) { - return (HyphenationTree)hyphenTrees.get(lang); - } - - /* See if it is one that we already have tried and failed. */ - Iterator iter = hyphenTreesNotFound.iterator(); - while (iter.hasNext()) { - String testedKey = (String) iter.next(); - if (key.equals(testedKey)) { - return null; - } - if (key.equals(lang)) { - return null; - } - } - - HyphenationTree hTree = getHyphenationTree(key); - if (hTree == null) { - hTree = loadHyphenationTree(key, lang); - } - // put it into the pattern cache - if (hTree != null) { - hyphenTrees.put(key, hTree); - } else { - getLogger().error("Couldn't find hyphenation pattern " - + key); - hyphenTreesNotFound.add(key); - } - return hTree; - } - - private InputStream getResourceStream(String key) { - InputStream is = null; - // Try to use Context Class Loader to load the properties file. - try { - Method getCCL = - Thread.class.getMethod("getContextClassLoader", new Class[0]); - if (getCCL != null) { - ClassLoader contextClassLoader = - (ClassLoader)getCCL.invoke(Thread.currentThread(), - new Object[0]); - is = contextClassLoader.getResourceAsStream("hyph/" + key - + ".hyp"); - } - } catch (Exception e) {} - - if (is == null) { - is = HyphenationServer.class.getResourceAsStream("/hyph/" + key - + ".hyp"); - } - - return is; - } - - private HyphenationTree getHyphenationTree(String key) { - HyphenationTree hTree = null; - ObjectInputStream ois = null; - InputStream is = null; - try { - is = getResourceStream(key); - if (is == null) { - if (key.length() == 5) { - is = getResourceStream(key.substring(0, 2)); - if (is != null) { - getLogger().error("Couldn't find hyphenation pattern " - + key - + "\nusing general language pattern " - + key.substring(0, 2) - + " instead."); - } else { - if (errorDump) { - getLogger().error("Couldn't find precompiled " - + "hyphenation pattern " - + key + ".hyp"); - } - return null; - } - } else { - if (errorDump) { - getLogger().error("Couldn't find precompiled " - + "hyphenation pattern " - + key + ".hyp"); - } - return null; - } - } - ois = new ObjectInputStream(is); - hTree = (HyphenationTree)ois.readObject(); - } catch (Exception e) { - e.printStackTrace(); - } - finally { - if (ois != null) { - try { - ois.close(); - } catch (IOException e) { - getLogger().error("can't close hyphenation object stream"); - } - } - } - return hTree; - } - - /** - * load tree from serialized file or xml file - * using configuration settings - */ - private HyphenationTree loadHyphenationTree(String key, - String language) { - if (this.hyphenationDir == null) { - return null; - } - HyphenationTree hTree = null; - // I use here the following convention. The file name specified in - // the configuration is taken as the base name. First we try - // name + ".hyp" assuming a serialized HyphenationTree. If that fails - // we try name + ".xml", assumming a raw hyphenation pattern file. - - // first try serialized object - File hyphenFile = new File(this.hyphenationDir, key + ".hyp"); - if (hyphenFile.exists()) { - ObjectInputStream ois = null; - try { - ois = new ObjectInputStream(new FileInputStream(hyphenFile)); - hTree = (HyphenationTree)ois.readObject(); - } catch (Exception e) { - e.printStackTrace(); - } - finally { - if (ois != null) { - try { - ois.close(); - } catch (IOException e) {} - } - } - return hTree; - } - - // try the raw XML file - hyphenFile = new File(this.hyphenationDir, key + ".xml"); - if (! hyphenFile.exists()) { - hyphenFile = new File(this.hyphenationDir, language + ".xml"); - } - if (hyphenFile.exists()) { - hTree = new HyphenationTree(); - if (errorDump) { - getLogger().error("reading " + this.hyphenationDir + key - + ".xml"); - } - try { - hTree.loadPatterns(hyphenFile.getPath(), getLogger()); - if (errorDump) { - getLogger().debug("Stats: "); - hTree.printStats(getLogger()); - } - return hTree; - } catch (TextException ex) { - if (errorDump) { - getLogger().error("Can't load user patterns " - + "from xml file " + this.hyphenationDir - + key + ".xml"); - } - return null; - } - } - if (errorDump) { - getLogger().error("Tried to load " - + hyphenFile.toString() - + "\nCannot find compiled nor xml file for " - + "hyphenation pattern" + key); - } - return null; - } - - public org.axsl.hyphenR.Hyphenation hyphenate(String word, String language, - String country, int remainCount, int pushCount) { - HyphenationTree hTree = getHyphenationTree(language, country); - if (hTree == null) { - return null; - } - return hTree.hyphenate(word, remainCount, pushCount); - } - - public org.axsl.hyphenR.Hyphenation hyphenate(char[] word, int offset, - int len, String language, String country, int remainCount, - int pushCount) { - HyphenationTree hTree = getHyphenationTree(language, country); - if (hTree == null) { - return null; - } - return hTree.hyphenate(word, offset, len, remainCount, pushCount); - } - - public Log getLogger() { - return textServer.getLogger(); - } - - /** - * extracts a complete word from the character data - */ - public String getHyphenationWord(char[] characters, int wordStart) { - boolean wordendFound = false; - int counter = 0; - int[] newWord = new int[characters.length]; // create a buffer - while ((!wordendFound) - && ((wordStart + counter) < characters.length)) { - int tk = characters[wordStart + counter]; - if (StringUtilPre5.isLetter(tk)) { - newWord[counter] = tk; - counter++; - } else { - wordendFound = true; - } - } - return StringUtilPre5.newString(newWord, 0, counter); - } - - /** - * Returns the count of non-word characters at the beginning of the text - * being evaluated. This includes characters like " and ' which are not - * really part of the word, but which must be passed through to the output. - * @param characters The char array being evaluated. - * @param startIndex Index into the first character in characters that - * should be evaluated. - * @return The number of characters at the start that should be ignored for - * purposes of forming a word to be evaluated for hyphenation. - */ - public int nonWordChars(char[] characters, int startIndex) { - int count = 0; - // Look for ' or " at the beginning of the word. - if (characters[startIndex] == '"' || characters[startIndex] == '\'') { - count ++; - } - return count; - } - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,533 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.text.hyphen; - -import org.foray.common.Logging; - -import org.axsl.text.TextException; - -import org.apache.commons.logging.Log; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; - -/** - * This tree structure stores the hyphenation patterns in an efficient - * way for fast lookup. It provides the provides the method to - * hyphenate a word. - * - * @author Carlos Villegas <ca...@un...> - */ -public class HyphenationTree extends TernaryTree implements PatternConsumer, - Serializable { - static final long serialVersionUID = 734862840356804663L; - - /** - * value space: stores the inteletter values - */ - protected ByteVector vspace; - - /** - * This map stores hyphenation exceptions - */ - protected HashMap stoplist; - - /** - * This map stores the character classes - */ - protected TernaryTree classmap; - - /** - * Temporary map to store interletter values on pattern loading. - */ - private transient TernaryTree ivalues; - - public HyphenationTree() { - stoplist = new HashMap(23); // usually a small table - classmap = new TernaryTree(); - vspace = new ByteVector(); - vspace.alloc(1); // this reserves index 0, which we don't use - } - - /** - * Packs the values by storing them in 4 bits, two values into a byte - * Values range is from 0 to 9. We use zero as terminator, - * so we'll add 1 to the value. - * @param values a string of digits from '0' to '9' representing the - * interletter values. - * @return the index into the vspace array where the packed values - * are stored. - */ - protected int packValues(String values) { - int i, n = values.length(); - int m = (n & 1) == 1 ? (n >> 1) + 2 : (n >> 1) + 1; - int offset = vspace.alloc(m); - byte[] va = vspace.getArray(); - for (i = 0; i < n; i++) { - int j = i >> 1; - byte v = (byte)((values.charAt(i) - '0' + 1) & 0x0f); - if ((i & 1) == 1) { - va[j + offset] = (byte)(va[j + offset] | v); - } else { - va[j + offset] = (byte)(v << 4); // big endian - } - } - va[m - 1 + offset] = 0; // terminator - return offset; - } - - protected String unpackValues(int k) { - StringBuffer buf = new StringBuffer(); - byte v = vspace.get(k++); - while (v != 0) { - char c = (char)((v >>> 4) - 1 + '0'); - buf.append(c); - c = (char)(v & 0x0f); - if (c == 0) { - break; - } - c = (char)(c - 1 + '0'); - buf.append(c); - v = vspace.get(k++); - } - return buf.toString(); - } - - /** - * Read hyphenation patterns from an XML file. - */ - public void loadPatterns(String filename, Log logger) - throws TextException { - PatternParser pp = new PatternParser(this, logger); - ivalues = new TernaryTree(); - - pp.parse(filename); - - // patterns/values should be now in the tree - // let's optimize a bit - trimToSize(); - vspace.trimToSize(); - classmap.trimToSize(); - - // get rid of the auxiliary map - ivalues = null; - } - - public String findPattern(String pat) { - int k = super.find(pat); - if (k >= 0) { - return unpackValues(k); - } - return ""; - } - - /** - * String compare, returns 0 if equal or - * t is a substring of s - */ - protected int hstrcmp(char[] s, int si, char[] t, int ti) { - for (; s[si] == t[ti]; si++, ti++) { - if (s[si] == 0) { - return 0; - } - } - if (t[ti] == 0) { - return 0; - } - return s[si] - t[ti]; - } - - protected byte[] getValues(int k) { - StringBuffer buf = new StringBuffer(); - byte v = vspace.get(k++); - while (v != 0) { - char c = (char)((v >>> 4) - 1); - buf.append(c); - c = (char)(v & 0x0f); - if (c == 0) { - break; - } - c = (char)(c - 1); - buf.append(c); - v = vspace.get(k++); - } - byte[] res = new byte[buf.length()]; - for (int i = 0; i < res.length; i++) { - res[i] = (byte)buf.charAt(i); - } - return res; - } - - /** - * <p>Search for all possible partial matches of word starting - * at index an update interletter values. In other words, it - * does something like:</p> - * <code> - * for(i=0; i<patterns.length; i++) { - * if ( word.substring(index).startsWidth(patterns[i]) ) - * update_interletter_values(patterns[i]); - * } - * </code> - * <p>But it is done in an efficient way since the patterns are - * stored in a ternary tree. In fact, this is the whole purpose - * of having the tree: doing this search without having to test - * every single pattern. The number of patterns for languages - * such as English range from 4000 to 10000. Thus, doing thousands - * of string comparisons for each word to hyphenate would be - * really slow without the tree. The tradeoff is memory, but - * using a ternary tree instead of a trie, almost halves the - * the memory used by Lout or TeX. It's also faster than using - * a hash table</p> - * @param word null terminated word to match - * @param index start index from word - * @param il interletter values array to update - */ - protected void searchPatterns(char[] word, int index, byte[] il) { - byte[] values; - int i = index; - char p, q; - char sp = word[i]; - p = root; - - while (p > 0 && p < sc.length) { - if (sc[p] == 0xFFFF) { - if (hstrcmp(word, i, kv.getArray(), lo[p]) == 0) { - values = getValues(eq[p]); // data pointer is in eq[] - int j = index; - for (int k = 0; k < values.length; k++) { - if (j < il.length && values[k] > il[j]) { - il[j] = values[k]; - } - j++; - } - } - return; - } - int d = sp - sc[p]; - if (d == 0) { - if (sp == 0) { - break; - } - sp = word[++i]; - p = eq[p]; - q = p; - - // look for a pattern ending at this position by searching for - // the null char ( splitchar == 0 ) - while (q > 0 && q < sc.length) { - if (sc[q] == 0xFFFF) { // stop at compressed branch - break; - } - if (sc[q] == 0) { - values = getValues(eq[q]); - int j = index; - for (int k = 0; k < values.length; k++) { - if (j < il.length && values[k] > il[j]) { - il[j] = values[k]; - } - j++; - } - break; - } - q = lo[q]; - /** - * actually the code should be: - * q = sc[q] < 0 ? hi[q] : lo[q]; - * but java chars are unsigned - */ - } - } else { - p = d < 0 ? lo[p] : hi[p]; - } - } - } - - /** - * Hyphenate word and return a Hyphenation object. - * @param word the word to be hyphenated - * @param remainCharCount Minimum number of characters allowed - * before the hyphenation point. - * @param pushCharCount Minimum number of characters allowed after - * the hyphenation point. - * @return a {@link Hyphenation Hyphenation} object representing - * the hyphenated word or null if word is not hyphenated. - */ - public org.axsl.hyphenR.Hyphenation hyphenate(String word, - int remainCharCount, int pushCharCount) { - char[] w = word.toCharArray(); - return hyphenate(w, 0, w.length, remainCharCount, pushCharCount); - } - - /** - * Hyphenate word and return an array of hyphenation points. - * @param w char array that contains the word - * @param offset Offset to first character in word - * @param len Length of word - * @param remainCharCount Minimum number of characters allowed - * before the hyphenation point. - * @param pushCharCount Minimum number of characters allowed after - * the hyphenation point. - * @return a {@link Hyphenation Hyphenation} object representing - * the hyphenated word or null if word is not hyphenated. - */ - public org.axsl.hyphenR.Hyphenation hyphenate(char[] w, int offset, int len, - int remainCharCount, int pushCharCount) { - char[] word = new char[len + 3]; - - // normalize word - char[] c = new char[2]; - for (int i = 1; i <= len; i++) { - c[0] = w[offset + i - 1]; - int nc = classmap.find(c, 0); - if (nc < 0) { // found a non-letter character, abort - return null; - } - word[i] = (char)nc; - } - int[] result = new int[len + 1]; - int k = 0; - - // check exception list first - String sw = new String(word, 1, len); - if (stoplist.containsKey(sw)) { - /* assume only simple hyphens (Hyphen.pre="-", - * Hyphen.post = Hyphen.no = null) */ - ArrayList hw = (ArrayList)stoplist.get(sw); - int j = 0; - for (int i = 0; i < hw.size(); i++) { - Object o = hw.get(i); - if (o instanceof String) { - j += ((String)o).length(); - if (j >= remainCharCount && j < (len - pushCharCount)) { - result[k++] = j; - } - } - } - } else { - // use algorithm to get hyphenation points - word[0] = '.'; // word start marker - word[len + 1] = '.'; // word end marker - word[len + 2] = 0; // null terminated - byte[] il = new byte[len + 3]; // initialized to zero - for (int i = 0; i < len + 1; i++) { - searchPatterns(word, i, il); - } - - // hyphenation points are located where interletter value is odd - for (int i = 0; i < len; i++) { - if (((il[i + 1] & 1) == 1) && i >= remainCharCount - && i <= (len - pushCharCount)) { - result[k++] = i; - } - } - } - - - if (k > 0) { - // trim result array - int[] res = new int[k]; - System.arraycopy(result, 0, res, 0, k); - return new Hyphenation(new String(w, offset, len), res); - } - return null; - } - - /** - * Add a character class to the tree. It is used by - * {@link PatternParser PatternParser} as callback to - * add character classes. Character classes define the - * valid word characters for hyphenation. If a word contains - * a character not defined in any of the classes, it is not hyphenated. - * It also defines a way to normalize the characters in order - * to compare them with the stored patterns. Usually pattern - * files use only lower case characters, in this case a class - * for letter 'a', for example, should be defined as "aA", the first - * character being the normalization char. - */ - public void addClass(String chargroup) { - if (chargroup.length() > 0) { - char equivChar = chargroup.charAt(0); - char[] key = new char[2]; - key[1] = 0; - for (int i = 0; i < chargroup.length(); i++) { - key[0] = chargroup.charAt(i); - classmap.insert(key, 0, equivChar); - } - } - } - - /** - * Add an exception to the tree. It is used by - * {@link PatternParser PatternParser} class as callback to - * store the hyphenation exceptions. - * @param word normalized word - * @param hyphenatedword a ArrayList of alternating strings and - * {@link Hyphen hyphen} objects. - */ - public void addException(String word, ArrayList hyphenatedword) { - stoplist.put(word, hyphenatedword); - } - - /** - * Add a pattern to the tree. Mainly, to be used by - * {@link PatternParser PatternParser} class as callback to - * add a pattern to the tree. - * @param pattern the hyphenation pattern - * @param ivalue interletter weight values indicating the - * desirability and priority of hyphenating at a given point - * within the pattern. It should contain only digit characters. - * (i.e. '0' to '9'). - */ - public void addPattern(String pattern, String ivalue) { - int k = ivalues.find(ivalue); - if (k <= 0) { - k = packValues(ivalue); - ivalues.insert(ivalue, (char)k); - } - insert(pattern, (char)k); - } - - public void printStats(Log logger) { - logger.info("Value space size = " + Integer.toString(vspace.length())); - super.printStats(logger); - } - - public static void main(String[] argv) throws Exception { - Log logger = Logging.makeDefaultLogger(); - HyphenationTree ht = null; - int minCharCount = 2; - BufferedReader in = - new BufferedReader(new InputStreamReader(System.in)); - for (; ; ) { - logger.info("l:\tload patterns from XML\n" - + "L:\tload patterns from serialized object\n" - + "s:\tset minimun character count\n" - + "w:\twrite hyphenation tree to object file\n" - + "h:\thyphenate\n" - + "f:\tfind pattern\n" - + "b:\tbenchmark\n" - + "q:\tquit\n" - + "\nCommand:"); - String token = in.readLine().trim(); - if (token.equals("f")) { - logger.info("Pattern: "); - token = in.readLine().trim(); - logger.info("Values: " + ht.findPattern(token)); - } else if (token.equals("s")) { - logger.info("Minimun value: "); - token = in.readLine().trim(); - minCharCount = Integer.parseInt(token); - } else if (token.equals("l")) { - ht = new HyphenationTree(); - logger.info("XML file name: "); - token = in.readLine().trim(); - ht.loadPatterns(token, logger); - } else if (token.equals("L")) { - ObjectInputStream ois = null; - logger.info("Object file name: "); - token = in.readLine().trim(); - try { - ois = new ObjectInputStream(new FileInputStream(token)); - ht = (HyphenationTree)ois.readObject(); - } catch (Exception e) { - e.printStackTrace(); - } - finally { - if (ois != null) { - try { - ois.close(); - } catch (IOException e) {} - } - } - } else if (token.equals("w")) { - logger.info("Object file name: "); - token = in.readLine().trim(); - ObjectOutputStream oos = null; - try { - oos = new ObjectOutputStream(new FileOutputStream(token)); - oos.writeObject(ht); - } catch (Exception e) { - e.printStackTrace(); - } - finally { - if (oos != null) { - try { - oos.flush(); - } catch (IOException e) {} - try { - oos.close(); - } catch (IOException e) {} - } - } - } else if (token.equals("h")) { - logger.info("Word: "); - token = in.readLine().trim(); - logger.info("Hyphenation points: "); - logger.info(ht.hyphenate(token, minCharCount, - minCharCount).toString()); - } else if (token.equals("b")) { - if (ht == null) { - logger.info("No patterns has been loaded."); - break; - } - logger.info("Word list filename: "); - token = in.readLine().trim(); - long starttime = 0; - int counter = 0; - ; - try { - BufferedReader reader = - new BufferedReader(new FileReader(token)); - - starttime = System.currentTimeMillis(); - while ((reader.readLine()) != null) { - counter++; - } - } catch (Exception ioe) { - logger.info("Exception " + ioe); - ioe.printStackTrace(); - } - long endtime = System.currentTimeMillis(); - long result = endtime - starttime; - logger.info(counter + " words hypehanted in " + result - + " milliseconds."); - - } else if (token.equals("q")) { - break; - } - } - - } - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternConsumer.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternConsumer.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternConsumer.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,62 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.text.hyphen; - -import java.util.ArrayList; - -/** - * This interface is used to connect the XML pattern file parser to - * the hyphenation tree. - * - * @author Carlos Villegas <ca...@un...> - */ -public interface PatternConsumer { - - /** - * Add a character class. - * A character class defines characters that are considered - * equivalent for the purpose of hyphenation (e.g. "aA"). It - * usually means to ignore case. - */ - void addClass(String chargroup); - - /** - * Add a hyphenation exception. An exception replaces the - * result obtained by the algorithm for cases for which this - * fails or the user wants to provide his own hyphenation. - * A hyphenatedword is a ArrayList of alternating String's and - * {@link Hyphen Hyphen} instances - */ - void addException(String word, ArrayList hyphenatedword); - - /** - * Add hyphenation patterns. - * @param pattern - * @param values interletter values expressed as a string of - * digit characters. - */ - void addPattern(String pattern, String values); - -} Deleted: trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternParser.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternParser.java 2006-06-08 17:21:04 UTC (rev 7445) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/PatternParser.java 2006-06-08 17:35:48 UTC (rev 7446) @@ -1,439 +0,0 @@ -/* - * Copyright 2004 The FOray Project. - * http://www.foray.org - * - * Licensed 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. - * - * This work is in part derived from the following work(s), used with the - * permission of the licensor: - * Apache FOP, licensed by the Apache Software Foundation - * - */ - -/* $Id$ */ - -package org.foray.text.hyphen; - -import org.foray.common.Logging; - -import org.axsl.text.TextException; - -import org.apache.commons.logging.Log; - -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.DefaultHandler; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; - -/** - * A SAX document handler to read and parse hyphenation patterns - * from a XML file. - * - * @author Carlos Villegas <ca...@un...> - */ -public class PatternParser extends DefaultHandler implements PatternConsumer { - - XMLReader parser; - int currElement; - PatternConsumer consumer; - StringBuffer token; - ArrayList exception; - char hyphenChar; - String errMsg; - Log logger; - - static final int ELEM_CLASSES = 1; - static final int ELEM_EXCEPTIONS = 2; - static final int ELEM_PATTERNS = 3; - static final int ELEM_HYPHEN = 4; - - public PatternParser(Log logger) throws TextException { - this.logger = logger; - token = new StringBuffer(); - parser = createParser(); - parser.setContentHandler(this); - parser.setErrorHandler(this); - hyphenChar = '-'; // default - } - - public PatternParser(PatternConsumer consumer, Log logger) - throws TextException { - this(logger); - this.consumer = consumer; - } - - public void setConsumer(PatternConsumer consumer) { - this.consumer = consumer; - } - - public void parse(String filename) throws TextException { - InputSource uri = fileInputSource(filename); - - try { - parser.parse(uri); - } catch (SAXException e) { - throw new TextException(errMsg); - } catch (IOException e) { - throw new TextException(e.getMessage()); - } catch (NullPointerException e) { - throw new TextException("SAX parser not available"); - } - } - - /** - * creates a SAX parser, using the value of org.xml.sax.parser - * defaulting to org.apache.xerces.parsers.SAXParser - * - * @return the created SAX parser - */ - static XMLReader createParser() throws TextException { - String parserClassName = System.getProperty("org.xml.sax.parser"); - if (parserClassName == null) { - parserClassName = "org.apache.xerces.parsers.SAXParser"; - } - try { - return (XMLReader)Class.forName(parserClassName).newInstance(); - } catch (ClassNotFoundException e) { - throw new TextException("Could not find " - + parserClassName); - } catch (InstantiationException e) { - throw new TextException("Could not instantiate " - + parserClassName); - } catch (IllegalAccessException e) { - throw new TextException("Could not access " - + parserClassName); - } catch (ClassCastException e) { - throw new TextException(parserClassName - + " is not a SAX driver"); - } - } - - /** - * create an InputSource from a file name - * - * @param filename the name of the file - * @return the InputSource created - */ - protected static InputSource fileInputSource(String filename) - throws TextException { - - /* this code adapted from James Clark's in XT */ - File file = new File(filename); - String path = file.getAbsolutePath(); - String fSep = System.getProperty("file.separator"); - if (fSep != null && fSep.length() == 1) { - path = path.replace(fSep.charAt(0), '/'); - } - if (path.length() > 0 && path.charAt(0) != '/') { - path = '/' + path; - } - try { - return new InputSource(new URL("file", null, path).toString()); - } catch (MalformedURLException e) { - throw new TextException("unexpected MalformedURLException"); - } - } - - protected String readToken(StringBuffer chars) { - String word; - boolean space = false; - int i; - for (i = 0; i < chars.length(); i++) { - if (Character.isWhitespace(chars.charAt(i))) { - space = true; - } else { - break; - } - } - if (space) { - for (int countr = i; countr < chars.length(); countr++) { - chars.setCharAt(countr - i, chars.charAt(countr)); - } - chars.setLength(chars.length() - i); - if (token.length() > 0) { - word = token.toString(); - token.setLength(0); - return word; - } - } - space = false; - for (i = 0; i < chars.length(); i++) { - if (Character.isWhitespace(chars.charAt(i))) { - space = true; - break; - } - } - token.append(chars.toString().substring(0, i)); - for (int countr = i; countr < chars.length(); countr++) { - chars.setCharAt(countr - i, chars.charAt(countr)); - } - chars.setLength(chars.length() - i); - if (space) { - word = token.toString(); - token.setLength(0); - return word; - } - token.append(chars); - return null; - } - - protected static String getPattern(String word) { - StringBuffer pat = new StringBuffer(); - int len = word.length(); - for (int i = 0; i < len; i++) { - if (!Character.isDigit(word.charAt(i))) { - pat.append(word.charAt(i)); - } - } - return pat.toString(); - } - - protected ArrayList normalizeException(ArrayList ex) { - ArrayList res = new ArrayList(); - for (int i = 0; i < ex.size(); i++) { - Object item = ex.get(i); - if (item instanceof String) { - String str = (String)item; - StringBuffer buf = new StringBuffer(); - for (int j = 0; j < str.length(); j++) { - char c = str.charAt(j); - if (c != hyphenChar) { - buf.append(c); - } else { - res.add(buf.toString()); - buf.setLength(0); - char[] h = new char[1]; - h[0] = hyphenChar; - // we use here hyphenChar which is not necessarily - // the one to be printed - res.add(new Hyphen(new String(h), null, null)); - } - } - if (buf.length() > 0) { - res.add(buf.toString()); - } - } else { - res.add(item); - } - } - return res; - } - - protected String getExceptionWord(ArrayList ex) { - StringBuffer res = new StringBuffer(); - for (int i = 0; i < ex.size(); i++) { - Object item = ex.get(i); - if (item instanceof String) { - res.append((String)item); - } else { - if (((Hyphen)item).noBreak != null) { - res.append(((Hyphen)item).noBreak); - } - } - } - return res.toString(); - } - - protected static String getInterletterValues(String pat) { - StringBuffer il = new StringBuffer(); - String word = pat + "a"; // add dummy letter to serve as sentinel - int len = word.length(); - for (int i = 0; i < len; i++) { - char c = word.charAt(i); - if (Character.isDigit(c)) { - il.append(c); - i++; - } else { - il.append('0'); - } - } - return il.toString(); - } - - // - // DocumentHandler methods - // - - /** - * Start element. - */ - public void startElement(String uri, String local, String raw, - Attributes attrs) { - if (local.equals("hyphen-char")) { - String h = attrs.getValue("value"); - if (h != null && h.length() == 1) { - hyphenChar = h.charAt(0); - } - } else if (local.equals("classes")) { - currElement = ELEM_CLASSES; - } else if (local.equals("patterns")) { - currElement = ELEM_PATTERNS; - } else if (local.equals("exceptions")) { - currElement = ELEM_EXCEPTIONS; - exception = new ArrayList(); - } else if (local.equals("hyphen")) { - if (token.length() > 0) { - exception.add(token.toString()); - } - exception.add(new Hyphen(attrs.getValue("pre"), - attrs.getValue("no"), attrs.getValue("post"))); - currElement = ELEM_HYPHEN; - } - token.setLength(0); - } - - public void endElement(String uri, String local, String raw) { - - if (token.length() > 0) { - String word = token.toString(); - switch (currElement) { - case ELEM_CLASSES: - consumer.addClass(word); - break; - case ELEM_EXCEPTIONS: - exception.add(word); - exception = normalizeException(exception); - consumer.addException(getExceptionWord(exception), - (ArrayList) exception.clone()); - break; - case ELEM_PATTERNS: - ... [truncated message content] |
|
From: <vic...@us...> - 2006-06-08 17:21:23
|
Revision: 7445 Author: victormote Date: 2006-06-08 10:21:04 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7445&view=rev Log Message: ----------- Initial creation of separate hyphenation package. Added Paths: ----------- trunk/foray/foray-hyphen-r/ trunk/foray/foray-hyphen-r/.checkstyle trunk/foray/foray-hyphen-r/.classpath trunk/foray/foray-hyphen-r/.project trunk/foray/foray-hyphen-r/scripts/ trunk/foray/foray-hyphen-r/scripts/build.bat trunk/foray/foray-hyphen-r/scripts/build.sh trunk/foray/foray-hyphen-r/scripts/build.xml trunk/foray/foray-hyphen-r/src/ trunk/foray/foray-hyphen-r/src/java/ trunk/foray/foray-hyphen-r/src/java/org/ trunk/foray/foray-hyphen-r/src/java/org/foray/ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/ Property changes on: trunk/foray/foray-hyphen-r ___________________________________________________________________ Name: svn:ignore + build zzlocal Added: trunk/foray/foray-hyphen-r/.checkstyle =================================================================== --- trunk/foray/foray-hyphen-r/.checkstyle (rev 0) +++ trunk/foray/foray-hyphen-r/.checkstyle 2006-06-08 17:21:04 UTC (rev 7445) @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<fileset-config file-format-version="1.2.0" simple-config="true"> + <fileset name="all" enabled="true" check-config-name="FOray Checkstyle" local="false"> + <file-match-pattern match-pattern="." include-pattern="true"/> + </fileset> +</fileset-config> Added: trunk/foray/foray-hyphen-r/.classpath =================================================================== --- trunk/foray/foray-hyphen-r/.classpath (rev 0) +++ trunk/foray/foray-hyphen-r/.classpath 2006-06-08 17:21:04 UTC (rev 7445) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry excluding=".#*" kind="src" path="src/java"/> + <classpathentry kind="src" path="scripts"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="build/eclipse"/> +</classpath> Added: trunk/foray/foray-hyphen-r/.project =================================================================== --- trunk/foray/foray-hyphen-r/.project (rev 0) +++ trunk/foray/foray-hyphen-r/.project 2006-06-08 17:21:04 UTC (rev 7445) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>FOrayHyphenR</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature> + </natures> +</projectDescription> Added: trunk/foray/foray-hyphen-r/scripts/build.bat =================================================================== --- trunk/foray/foray-hyphen-r/scripts/build.bat (rev 0) +++ trunk/foray/foray-hyphen-r/scripts/build.bat 2006-06-08 17:21:04 UTC (rev 7445) @@ -0,0 +1,27 @@ +@echo off + +echo "FOray Build System" +echo "------------------" + +IF "%JAVA_HOME%" == "" GOTO JAVA_HOME_ERR +IF "%ANT_HOME%" == "" GOTO ANT_HOME_ERR + +call %ANT_HOME%\bin\ant.bat %* + +GOTO END + +:JAVA_HOME_ERR + echo ERROR: JAVA_HOME not found in your environment. + echo + echo Please set the JAVA_HOME variable in your environment to match the + echo location of the Java Virtual Machine you want to use. +GOTO END + +:ANT_HOME_ERR + echo ERROR: ANT_HOME not found in your environment. + echo + echo Please set the ANT_HOME variable in your environment to match the + echo location of the root of your ANT installation. +GOTO END + +:END Added: trunk/foray/foray-hyphen-r/scripts/build.sh =================================================================== --- trunk/foray/foray-hyphen-r/scripts/build.sh (rev 0) +++ trunk/foray/foray-hyphen-r/scripts/build.sh 2006-06-08 17:21:04 UTC (rev 7445) @@ -0,0 +1,29 @@ +#!/bin/sh + +# This file must be executable. + +echo +echo "FOray Build System" +echo "------------------" + +if [ "$JAVA_HOME" = "" ] +then + echo "ERROR: JAVA_HOME not found in your environment." + echo + echo "Please set the JAVA_HOME variable in your environment to match the" + echo "location of the Java Virtual Machine you want to use." + exit 1 +fi + +if [ "$ANT_HOME" = "" ] +then + echo "ERROR: ANT_HOME not found in your environment." + echo + echo "Please set the ANT_HOME variable in your environment to match the" + echo "location of the root of your ANT installation." + exit 1 +fi + +"$ANT_HOME"/bin/ant "$@" + +##### Last Line of $RCSfile$ ##### Property changes on: trunk/foray/foray-hyphen-r/scripts/build.sh ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native Added: trunk/foray/foray-hyphen-r/scripts/build.xml =================================================================== --- trunk/foray/foray-hyphen-r/scripts/build.xml (rev 0) +++ trunk/foray/foray-hyphen-r/scripts/build.xml 2006-06-08 17:21:04 UTC (rev 7445) @@ -0,0 +1,204 @@ +<?xml version="1.0"?> +<!-- $Id$ --> + +<project default="package" basedir="."> + + <!-- Set up a prefix to designate environment variables. --> + <property environment="env"/> + + <target name="env"> + <!-- If the environment variable FORAY_CONFIG is set, use it. --> + <condition property="foray.config" value="${env.FORAY_CONFIG}"> + <and> + <isset property="env.FORAY_CONFIG"/> + <available file="${env.FORAY_CONFIG}"/> + </and> + </condition> + <!-- Otherwise, set it to the FOray scripts directory. --> + <property name="foray.config" location="../../scripts"/> + <echo>foray.config: ${foray.config}</echo> + + <!-- Retrieve externally-configured properties. --> + <property file="${foray.config}/foray-build.properties"/> + + <!-- Get a default for {foray.home}. --> + <property name="foray.home" location="../.."/> + <echo>foray.home: ${foray.home}</echo> + + <!-- Set up dependent properties. --> + <property name="lib.dir" location="${foray.home}/lib"/> + <property name="axsl.build" location="${lib.dir}"/> + + <path id="libs-build-classpath"> + <fileset dir="${axsl.build}"> + <include name="**/axsl*.jar"/> + </fileset> + <fileset dir="${lib.dir}"> + <include name="avalon-framework*.jar"/> + <include name="xml-apis*.jar"/> + <include name="xerces*.jar"/> + <include name="axsl*.jar"/> + <include name="commons-logging.jar"/> + </fileset> + <fileset dir="${foray.home}/foray-common/build/ant"> + <include name="*.jar"/> + </fileset> + </path> + </target> + + <!-- =================================================================== --> + <!-- Initialization target --> + <!-- =================================================================== --> + <target name="init" depends="env"> + <tstamp/> + <property name="name" value="foray"/> + <property name="contact.info" + value="The FOray project http://www.foray.org"/> + <property name="module" value="hyphen-r"/> + <property name="module.dir" value="${foray.home}/foray-${module}"/> + <property name="version" value="0.1"/> + <property name="src.dir" value="${module.dir}/src"/> + <property name="build.dir" value="${module.dir}/build/ant"/> + <property name="classes.dir" value="${build.dir}/classes"/> + <property name="resource.dir" value="${module.dir}/resource"/> + <property name="debug" value="on"/> + <property name="optimize" value="off"/> + <property name="deprecation" value="off"/> + <property name="source" value="1.4"/> + <property name="hyph.source" value="${resource.dir}/hyph-patterns"/> + <property name="hyph.build" value="${build.dir}/hyph"/> + </target> + + <!-- =================================================================== --> + <!-- Prepares the build directory --> + <!-- =================================================================== --> + <target name="prepare" depends="init"> + <!-- create directories --> + <echo message="Preparing the build directories"/> + <mkdir dir="${build.dir}"/> + <mkdir dir="${classes.dir}"/> + <mkdir dir="${hyph.build}"/> + </target> + + + <!-- =================================================================== --> + <!-- compiles hyphenation patterns --> + <!-- =================================================================== --> + <target name="hyphenation" depends="compile" > + <path id="hyph-classpath"> + <path refid="libs-build-classpath"/> + <pathelement location="${classes.dir}"/> + </path> + <taskdef name="serHyph" + classname="org.foray.hyphenR.SerializeHyphPattern" + classpathref="hyph-classpath"/> + <serHyph includes="*.xml" + sourceDir="${hyph.source}" + targetDir="${hyph.build}" /> + </target> + + + <!-- =================================================================== --> + <!-- Compiles the source directory --> + <!-- =================================================================== --> + <target name="compile" depends="prepare"> + <echo message="Compiling the sources "/> + <!-- create directories --> + <mkdir dir="${build.dir}"/> + <javac srcdir="${src.dir}" + destdir="${classes.dir}" + debug="${debug}" + deprecation="${deprecation}" + optimize="${optimize}" + source="${source}" + > + <classpath refid="libs-build-classpath"/> + </javac> + </target> + + <!-- =================================================================== --> + <!-- Creates the class package --> + <!-- =================================================================== --> + <target name="package" depends="compile, style, hyphenation" + description="Generates the jar files (default target)"> + <echo message="Creating the jar file ${build.dir}/${name}.jar"/> + + <tstamp> + <format property="ts" pattern="yyyyMMdd-HHmmss-z"/> + </tstamp> + <fileset id="foray-hyphen-classes" + dir="${foray.home}/foray-hyphen-r/build/ant/classes"> + <include name="**"/> + </fileset> + <fileset id="foray-hyphen-resources" + dir="${foray.home}/foray-hyphen-r/build/ant"> + <include name="hyph/**"/> + </fileset> + <jar jarfile="${build.dir}/${name}-${module}.jar"> + <fileset refid="foray-hyphen-classes"/> + <fileset refid="foray-hyphen-resources"/> + <manifest> + <attribute name="Implementation-Title" value="${name}-${module}"/> + <attribute name="Implementation-Version" value="${version}"/> + <attribute name="Implementation-Vendor" + value="${contact.info}"/> + </manifest> + </jar> + + </target> + + <target name="javadoc-api" depends="init" description="Creates API + documentation"> + <echo message="Producing the javadoc files "/> + <mkdir dir="${build.dir}/javadoc-api"/> + <javadoc + packagenames="org.foray.hyphenR" + sourcepath="${src.dir}/java" + destdir="${build.dir}/javadoc-api" + classpathref="libs-build-classpath" + author="true" + version="true" + windowtitle="FOray Hyphenation API" + doctitle="FOray Hyphenation API" + bottom="Copyright © 2004 The FOray Project. All Rights Reserved." + overview="${src.dir}/java/org/foray/hyphenR/overview.html" + use="true" + access="public" + failonerror="true"> + <classpath refid="libs-build-classpath"/> + <classpath> + <fileset dir="${lib.dir}"> + <include name="ant*.jar"/> + </fileset> + </classpath> + </javadoc> + </target> + + <!-- =================================================================== --> + <!-- Clean targets --> + <!-- =================================================================== --> + <target name="clean" depends="init" description="Cleans the build directory"> + <delete dir="${build.dir}"/> + </target> + + <!-- =================================================================== --> + <!-- Checkstyle --> + <!-- =================================================================== --> + <target name="style" depends="init" description="Runs checkstyle" + if="checkstyle.home"> + <taskdef name="checkstyle" + classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"> + <classpath> + <fileset dir="${checkstyle.home}"> + <include name="checkstyle-all-*.jar"/> + </fileset> + </classpath> + </taskdef> + <checkstyle config="../../scripts/checkstyle-config.xml"> + <fileset dir="${src.dir}" includes="**/*.java"/> + </checkstyle> + </target> + +</project> + +<!-- Last Line of $RCSfile$ --> Property changes on: trunk/foray/foray-hyphen-r/scripts/build.xml ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 16:35:15
|
Revision: 7444 Author: victormote Date: 2006-06-08 09:34:58 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7444&view=rev Log Message: ----------- 1. Make dependent on axsl-HyphenR package. 2. Make the hyphenation classes implement the axsl interfaces (Doh!!). Modified Paths: -------------- trunk/foray/foray-text/.classpath trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/.classpath =================================================================== --- trunk/foray/foray-text/.classpath 2006-06-08 16:31:23 UTC (rev 7443) +++ trunk/foray/foray-text/.classpath 2006-06-08 16:34:58 UTC (rev 7444) @@ -9,5 +9,6 @@ <classpathentry kind="src" path="/FOrayCommon"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> <classpathentry kind="var" path="FORAY_LIB_ROOT/commons-logging.jar"/> + <classpathentry combineaccessrules="false" kind="src" path="/axslHyphen-R"/> <classpathentry kind="output" path="build/eclipse"/> </classpath> Modified: trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java 2006-06-08 16:31:23 UTC (rev 7443) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/Hyphenation.java 2006-06-08 16:34:58 UTC (rev 7444) @@ -32,7 +32,7 @@ /** * This class represents a hyphenated word. */ -public class Hyphenation { +public class Hyphenation implements org.axsl.hyphenR.Hyphenation { int[] hyphenPoints; String word; Modified: trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java 2006-06-08 16:31:23 UTC (rev 7443) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationServer.java 2006-06-08 16:34:58 UTC (rev 7444) @@ -33,7 +33,6 @@ import org.foray.text.TextServer; import org.axsl.text.TextException; -import org.axsl.text.line.LineText; import org.apache.commons.logging.Log; @@ -51,7 +50,7 @@ /** * This class is the main entry point to the hyphenation package. */ -public class HyphenationServer { +public class HyphenationServer implements org.axsl.hyphenR.HyphenationServer { /** * The "parent" TextServer instance. @@ -270,29 +269,23 @@ return null; } - public Hyphenation hyphenate(String word, LineText lineText) { - String lang = lineText.inlineLanguage(); - String country = lineText.inlineCountry(); - int leftMin = lineText.inlineHyphenationRemainCount(); - int rightMin = lineText.inlineHyphenationPushCount(); - HyphenationTree hTree = getHyphenationTree(lang, country); + public org.axsl.hyphenR.Hyphenation hyphenate(String word, String language, + String country, int remainCount, int pushCount) { + HyphenationTree hTree = getHyphenationTree(language, country); if (hTree == null) { return null; } - return hTree.hyphenate(word, leftMin, rightMin); + return hTree.hyphenate(word, remainCount, pushCount); } - public Hyphenation hyphenate(char[] word, int offset, int len, - LineText lineText) { - String lang = lineText.inlineLanguage(); - String country = lineText.inlineCountry(); - int leftMin = lineText.inlineHyphenationRemainCount(); - int rightMin = lineText.inlineHyphenationPushCount(); - HyphenationTree hTree = getHyphenationTree(lang, country); + public org.axsl.hyphenR.Hyphenation hyphenate(char[] word, int offset, + int len, String language, String country, int remainCount, + int pushCount) { + HyphenationTree hTree = getHyphenationTree(language, country); if (hTree == null) { return null; } - return hTree.hyphenate(word, offset, len, leftMin, rightMin); + return hTree.hyphenate(word, offset, len, remainCount, pushCount); } public Log getLogger() { @@ -302,7 +295,7 @@ /** * extracts a complete word from the character data */ - public String getHyphenationWord(int[] characters, int wordStart) { + public String getHyphenationWord(char[] characters, int wordStart) { boolean wordendFound = false; int counter = 0; int[] newWord = new int[characters.length]; // create a buffer @@ -329,7 +322,7 @@ * @return The number of characters at the start that should be ignored for * purposes of forming a word to be evaluated for hyphenation. */ - public int nonWordChars(int[] characters, int startIndex) { + public int nonWordChars(char[] characters, int startIndex) { int count = 0; // Look for ' or " at the beginning of the word. if (characters[startIndex] == '"' || characters[startIndex] == '\'') { Modified: trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java 2006-06-08 16:31:23 UTC (rev 7443) +++ trunk/foray/foray-text/src/java/org/foray/text/hyphen/HyphenationTree.java 2006-06-08 16:34:58 UTC (rev 7444) @@ -283,8 +283,8 @@ * @return a {@link Hyphenation Hyphenation} object representing * the hyphenated word or null if word is not hyphenated. */ - public Hyphenation hyphenate(String word, int remainCharCount, - int pushCharCount) { + public org.axsl.hyphenR.Hyphenation hyphenate(String word, + int remainCharCount, int pushCharCount) { char[] w = word.toCharArray(); return hyphenate(w, 0, w.length, remainCharCount, pushCharCount); } @@ -301,7 +301,7 @@ * @return a {@link Hyphenation Hyphenation} object representing * the hyphenated word or null if word is not hyphenated. */ - public Hyphenation hyphenate(char[] w, int offset, int len, + public org.axsl.hyphenR.Hyphenation hyphenate(char[] w, int offset, int len, int remainCharCount, int pushCharCount) { char[] word = new char[len + 3]; Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 16:31:23 UTC (rev 7443) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-06-08 16:34:58 UTC (rev 7444) @@ -24,13 +24,12 @@ package org.foray.text.line.solitary; -import org.foray.common.StringUtil; import org.foray.common.StringUtilPre5; -import org.foray.text.hyphen.Hyphenation; import org.foray.text.hyphen.HyphenationServer; import org.foray.text.line.EagerLineBreaker; import org.axsl.fontR.FontConsumer; +import org.axsl.hyphenR.Hyphenation; import org.axsl.text.TextException; import org.axsl.text.line.LineBreakControl; import org.axsl.text.line.LineBreakHandler; @@ -91,7 +90,6 @@ private LineText currentLineText = null; private char[] currentChars = null; - private int[] currentCodePoints = null; private boolean canEatLeadingSpaces = true; @@ -108,7 +106,6 @@ throws TextException { this.currentLineText = lineText; this.currentChars = currentLineText.inlineText(); - this.currentCodePoints = StringUtil.toCodePoints(currentChars); String language = lineText.inlineLanguage(); finalWidth = 0; @@ -355,14 +352,16 @@ */ HyphenationServer server = this.getHyphenationServer(); // Count the number of chars at the beginning that should be ignored. - int nonWordChars = server.nonWordChars(this.currentCodePoints, - wordStart); + int nonWordChars = server.nonWordChars(this.currentChars, wordStart); // Extract the word that should be evaluated by the hyphenation system. String wordToHyphenate = server.getHyphenationWord( - this.currentCodePoints, this.wordStart + nonWordChars); + this.currentChars, this.wordStart + nonWordChars); // See if there are discretionary hyphenation points. Hyphenation hyph = server.hyphenate(wordToHyphenate, - this.currentLineText); + this.currentLineText.inlineLanguage(), + this.currentLineText.inlineCountry(), + this.currentLineText.inlineHyphenationRemainCount(), + this.currentLineText.inlineHyphenationPushCount()); // If none, the word cannot be hyphenated. if (hyph == null) { return this.wordStart; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 16:31:31
|
Revision: 7443 Author: victormote Date: 2006-06-08 09:31:23 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7443&view=rev Log Message: ----------- Fix index-out-of-bounds exception. Modified Paths: -------------- trunk/foray/foray-fotree/src/java/org/foray/fotree/FOText.java Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/FOText.java =================================================================== --- trunk/foray/foray-fotree/src/java/org/foray/fotree/FOText.java 2006-06-07 21:36:17 UTC (rev 7442) +++ trunk/foray/foray-fotree/src/java/org/foray/fotree/FOText.java 2006-06-08 16:31:23 UTC (rev 7443) @@ -673,7 +673,8 @@ default: { // If first element, only check next. if (index == 0) { - if (charArray[index + 1] == 0x000a) { + if (index < charArray.length - 1 + && charArray[index + 1] == 0x000a) { return DISCARD_CHAR; } return c; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 02:11:37
|
Revision: 7442 Author: victormote Date: 2006-06-07 14:36:17 -0700 (Wed, 07 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7442&view=rev Log Message: ----------- 1. Add implementation of new MarkerContentArea interface. 2. Add abstract superclass for above that handles the "not an area" Area logic. 3. Add logic for getting the new class used in the AreaTree creation. Modified Paths: -------------- trunk/foray/foray-pioneer/src/java/org/foray/pioneer/RetrieveMarkerPL.java Modified: trunk/foray/foray-pioneer/src/java/org/foray/pioneer/RetrieveMarkerPL.java =================================================================== --- trunk/foray/foray-pioneer/src/java/org/foray/pioneer/RetrieveMarkerPL.java 2006-06-07 21:36:05 UTC (rev 7441) +++ trunk/foray/foray-pioneer/src/java/org/foray/pioneer/RetrieveMarkerPL.java 2006-06-07 21:36:17 UTC (rev 7442) @@ -25,9 +25,9 @@ package org.foray.pioneer; import org.axsl.areaW.Area; +import org.axsl.areaW.AreaWException; +import org.axsl.areaW.MarkerContentArea; import org.axsl.areaW.PageArea; - -import org.axsl.areaW.AreaWException; import org.axsl.foR.FONode; import org.axsl.foR.fo.Marker; import org.axsl.foR.fo.RetrieveMarker; @@ -55,13 +55,15 @@ if (bestMarker == null) { return Status.OK; } + MarkerContentArea markerArea = area.makeMarkerContentArea(node, + bestMarker); MarkerPL markerPL = (MarkerPL) this.getLayoutProxy(bestMarker); // Necessary because the marker may get used multiple times. markerPL.resetProgress(); markerPL.setProgress(0); for (int i = 0; i < bestMarker.getChildren().size(); i++) { FONode fo = (FONode) bestMarker.getChildren().get(i); - getLayoutProxy(fo).layout(area); + getLayoutProxy(fo).layout(markerArea); } return Status.OK; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <vic...@us...> - 2006-06-08 02:11:34
|
Revision: 7441 Author: victormote Date: 2006-06-07 14:36:05 -0700 (Wed, 07 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7441&view=rev Log Message: ----------- 1. Add implementation of new MarkerContentArea interface. 2. Add abstract superclass for above that handles the "not an area" Area logic. 3. Add logic for getting the new class used in the AreaTree creation. Modified Paths: -------------- trunk/foray/foray-areatree/src/java/org/foray/area/Area.java Added Paths: ----------- trunk/foray/foray-areatree/src/java/org/foray/area/AbstractPlaceholder.java trunk/foray/foray-areatree/src/java/org/foray/area/MarkerContentArea.java Added: trunk/foray/foray-areatree/src/java/org/foray/area/AbstractPlaceholder.java =================================================================== --- trunk/foray/foray-areatree/src/java/org/foray/area/AbstractPlaceholder.java (rev 0) +++ trunk/foray/foray-areatree/src/java/org/foray/area/AbstractPlaceholder.java 2006-06-07 21:36:05 UTC (rev 7441) @@ -0,0 +1,117 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.area; + +import org.axsl.areaW.AreaWException; +import org.axsl.foR.FObj; + +/** + * Marks a place in the AreaTree, but does not have any area itself. + * Pretends to be its parent for most purposes. + */ +public abstract class AbstractPlaceholder extends Area { + + public AbstractPlaceholder(FObj generatedBy, Area parentArea) { + super(generatedBy, parentArea); + } + + /** + * {@inheritDoc} + */ + public int pdUsedBySiblings() { + return this.getParentArea().pdUsedBySiblings(); + } + + /** + * {@inheritDoc} + */ + public int crIPD() { + return this.getParentArea().crIPD(); + } + + /** + * {@inheritDoc} + */ + public int crBPD() { + return this.getParentArea().crBPD(); + } + + /** + * {@inheritDoc} + */ + public int crOriginIPDOffset() { + return this.getParentArea().crOriginIPDOffset(); + } + + /** + * {@inheritDoc} + */ + public int crOriginBPDOffset() { + return this.getParentArea().crOriginBPDOffset(); + } + + /** + * {@inheritDoc} + */ + public Area getOverflowArea(Area childRequesting) throws AreaWException { + return this.getParentArea().getOverflowArea(childRequesting); + } + + /** + * {@inheritDoc} + */ + public int getProgressionDimension() { + return 0; + } + + /** + * {@inheritDoc} + */ + public int progressionDimensionAvailable() { + return this.getParentArea().progressionDimensionAvailable(); + } + + /** + * {@inheritDoc} + */ + public void setProgressionDimension(int progressionDimension) { + return; + } + + /** + * {@inheritDoc} + */ + public void setMinimumProgressionDimension(int minimumPD) { + return; + } + + /** + * {@inheritDoc} + */ + public void incrementProgressionDimension(int incrementAmount) { + return; + } + +} Property changes on: trunk/foray/foray-areatree/src/java/org/foray/area/AbstractPlaceholder.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native Modified: trunk/foray/foray-areatree/src/java/org/foray/area/Area.java =================================================================== --- trunk/foray/foray-areatree/src/java/org/foray/area/Area.java 2006-06-07 18:29:27 UTC (rev 7440) +++ trunk/foray/foray-areatree/src/java/org/foray/area/Area.java 2006-06-07 21:36:05 UTC (rev 7441) @@ -36,6 +36,8 @@ import org.axsl.foR.fo.Block; import org.axsl.foR.fo.BlockContainer; import org.axsl.foR.fo.ListBlock; +import org.axsl.foR.fo.Marker; +import org.axsl.foR.fo.RetrieveMarker; import org.axsl.foR.fo.Table; import org.axsl.fontR.Font; import org.axsl.fontR.FontUse; @@ -1243,4 +1245,9 @@ return true; } + public org.axsl.areaW.MarkerContentArea makeMarkerContentArea( + RetrieveMarker retrieve, Marker marker) { + return new MarkerContentArea(retrieve, this, marker); + } + } Added: trunk/foray/foray-areatree/src/java/org/foray/area/MarkerContentArea.java =================================================================== --- trunk/foray/foray-areatree/src/java/org/foray/area/MarkerContentArea.java (rev 0) +++ trunk/foray/foray-areatree/src/java/org/foray/area/MarkerContentArea.java 2006-06-07 21:36:05 UTC (rev 7441) @@ -0,0 +1,64 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * Licensed 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. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +package org.foray.area; + +import org.axsl.common.ConstantsAreaTree; +import org.axsl.foR.fo.Marker; +import org.axsl.foR.fo.RetrieveMarker; + +/** + * A non-area that is a marker in the Area Tree to allow the AreaTree to + * remember which RetrieveMarker and Marker items combined to create the + * content below it. + */ +public class MarkerContentArea extends AbstractPlaceholder + implements org.axsl.areaW.MarkerContentArea { + + private Marker marker; + + public MarkerContentArea(RetrieveMarker generatedBy, Area parentArea, + Marker marker) { + super(generatedBy, parentArea); + this.marker = marker; + } + + public byte getAreaType() { + return ConstantsAreaTree.AREATYPE_MARKER_CONTENT; + } + + public String getAreaName() { + return "marker-content"; + } + + public Marker getMarker() { + return this.marker; + } + + public RetrieveMarker getRetrieveMarker() { + /* Cast verified at construction. */ + return (RetrieveMarker) this.generatedBy; + } + +} Property changes on: trunk/foray/foray-areatree/src/java/org/foray/area/MarkerContentArea.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |