From: <k_s...@us...> - 2010-01-01 16:40:24
|
Revision: 16799 http://jedit.svn.sourceforge.net/jedit/?rev=16799&view=rev Author: k_satoda Date: 2010-01-01 16:39:57 +0000 (Fri, 01 Jan 2010) Log Message: ----------- Clarified and simplified the implementation of soft wrap in class DisplayTokenHandler. This change is extracted from SF.net patch #2483695 excluding the actual changes in behavior. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2009-12-31 13:45:53 UTC (rev 16798) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2010-01-01 16:39:57 UTC (rev 16799) @@ -23,10 +23,9 @@ package org.gjt.sp.jedit.syntax; //{{{ Imports -import org.gjt.sp.jedit.buffer.JEditBuffer; - -import javax.swing.text.*; -import java.awt.font.*; +import javax.swing.text.Segment; +import javax.swing.text.TabExpander; +import java.awt.font.FontRenderContext; import java.util.List; //}}} @@ -59,7 +58,7 @@ { super.init(); - x = 0.0f; + endX = 0.0f; this.styles = styles; this.fontRenderContext = fontRenderContext; @@ -74,8 +73,8 @@ this.out = out; seenNonWhitespace = false; - endX = endOfWhitespace = 0.0f; - end = null; + endOfWhitespace = 0.0f; + afterTrailingWhitespace = false; } //}}} //{{{ getChunkList() method @@ -104,8 +103,7 @@ { if(id == Token.END) { - if(firstToken != null) - out.add(merge((Chunk)firstToken,seg)); + terminateScreenLine(seg); return; } @@ -113,52 +111,35 @@ { int splitLength = Math.min(length - splitOffset,MAX_CHUNK_LEN); Chunk chunk = createChunk(id,offset + splitOffset,splitLength,context); - addToken(chunk,context); - if(wrapMargin != 0.0f) { initChunk(chunk,seg); - x += chunk.width; - if(Character.isWhitespace(seg.array[ seg.offset + chunk.offset])) { - if(seenNonWhitespace) + if (seenNonWhitespace) { - end = lastToken; - endX = x; + afterTrailingWhitespace = true; } - else - endOfWhitespace = x; } else { - if(x > wrapMargin - && end != null - && seenNonWhitespace) + if (!seenNonWhitespace) { - Chunk nextLine = new Chunk(endOfWhitespace, - end.offset + end.length, - getParserRuleSet(context)); - initChunk(nextLine,seg); - - nextLine.next = end.next; - end.next = null; - - if(firstToken != null) - out.add(merge((Chunk)firstToken,seg)); - - firstToken = nextLine; - - x = x - endX + endOfWhitespace; - - end = null; - endX = x; + endOfWhitespace = endX; + seenNonWhitespace = true; } - - seenNonWhitespace = true; + if(endX + chunk.width > wrapMargin + && afterTrailingWhitespace + && endX > endOfWhitespace) + { + wrapLine(seg, context); + } + afterTrailingWhitespace = false; } + endX += chunk.width; } + addToken(chunk,context); } } //}}} @@ -168,15 +149,14 @@ private SyntaxStyle[] styles; private FontRenderContext fontRenderContext; private TabExpander expander; - private float x; + private float endX; private List<Chunk> out; private float wrapMargin; - private float endX; - private Token end; private boolean seenNonWhitespace; private float endOfWhitespace; + private boolean afterTrailingWhitespace; //}}} //{{{ createChunk() method @@ -189,12 +169,16 @@ } //}}} //{{{ initChunk() method - protected void initChunk(Chunk chunk, Segment seg) + private void initChunk(Chunk chunk, Segment seg) { - chunk.init(seg,expander,x,fontRenderContext); + chunk.init(seg,expander,endX,fontRenderContext); } //}}} //{{{ merge() method + /** + * Merges each adjucent chunks if possible, to reduce the number + * of chunks for rendering performance. + */ private Chunk merge(Chunk first, Segment seg) { if(first == null) @@ -218,7 +202,7 @@ { initChunk(chunk,seg); if(wrapMargin == 0.0f) - x += chunk.width; + endX += chunk.width; } chunk = next; } @@ -244,5 +228,39 @@ && (c1.length + c2.length <= MAX_CHUNK_LEN)); } //}}} + //{{{ wrapLine() method + /** + * Starts a new screen line. + */ + private void wrapLine(Segment seg, TokenMarker.LineContext context) + { + // Wrap can't happen at the start of a screen line. + assert lastToken != null; + + int eolOffset = lastToken.offset + lastToken.length; + terminateScreenLine(seg); + + Chunk indent = new Chunk(endOfWhitespace, eolOffset, + getParserRuleSet(context)); + initChunk(indent, seg); + addToken(indent, context); + + endX = endOfWhitespace; + } //}}} + + //{{{ terminateScreenLine() method + /** + * Makes the list of tokens into a screen line. + * The list becomes empty. + */ + private void terminateScreenLine(Segment seg) + { + if (firstToken != null) + { + out.add(merge((Chunk)firstToken, seg)); + firstToken = lastToken = null; + } + } //}}} + //}}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2010-01-03 11:27:24
|
Revision: 16822 http://jedit.svn.sourceforge.net/jedit/?rev=16822&view=rev Author: k_satoda Date: 2010-01-03 11:27:15 +0000 (Sun, 03 Jan 2010) Log Message: ----------- Reverted the change at r16799 since it caused unexpected change in behavior, which prohibited soft wraps at middle of chunk list (not only at the tail of the chunk list). Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2010-01-03 09:27:57 UTC (rev 16821) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2010-01-03 11:27:15 UTC (rev 16822) @@ -23,9 +23,10 @@ package org.gjt.sp.jedit.syntax; //{{{ Imports -import javax.swing.text.Segment; -import javax.swing.text.TabExpander; -import java.awt.font.FontRenderContext; +import org.gjt.sp.jedit.buffer.JEditBuffer; + +import javax.swing.text.*; +import java.awt.font.*; import java.util.List; //}}} @@ -58,7 +59,7 @@ { super.init(); - endX = 0.0f; + x = 0.0f; this.styles = styles; this.fontRenderContext = fontRenderContext; @@ -73,8 +74,8 @@ this.out = out; seenNonWhitespace = false; - endOfWhitespace = 0.0f; - afterTrailingWhitespace = false; + endX = endOfWhitespace = 0.0f; + end = null; } //}}} //{{{ getChunkList() method @@ -103,7 +104,8 @@ { if(id == Token.END) { - terminateScreenLine(seg); + if(firstToken != null) + out.add(merge((Chunk)firstToken,seg)); return; } @@ -111,35 +113,52 @@ { int splitLength = Math.min(length - splitOffset,MAX_CHUNK_LEN); Chunk chunk = createChunk(id,offset + splitOffset,splitLength,context); + addToken(chunk,context); + if(wrapMargin != 0.0f) { initChunk(chunk,seg); + x += chunk.width; + if(Character.isWhitespace(seg.array[ seg.offset + chunk.offset])) { - if (seenNonWhitespace) + if(seenNonWhitespace) { - afterTrailingWhitespace = true; + end = lastToken; + endX = x; } + else + endOfWhitespace = x; } else { - if (!seenNonWhitespace) + if(x > wrapMargin + && end != null + && seenNonWhitespace) { - endOfWhitespace = endX; - seenNonWhitespace = true; + Chunk nextLine = new Chunk(endOfWhitespace, + end.offset + end.length, + getParserRuleSet(context)); + initChunk(nextLine,seg); + + nextLine.next = end.next; + end.next = null; + + if(firstToken != null) + out.add(merge((Chunk)firstToken,seg)); + + firstToken = nextLine; + + x = x - endX + endOfWhitespace; + + end = null; + endX = x; } - if(endX + chunk.width > wrapMargin - && afterTrailingWhitespace - && endX > endOfWhitespace) - { - wrapLine(seg, context); - } - afterTrailingWhitespace = false; + + seenNonWhitespace = true; } - endX += chunk.width; } - addToken(chunk,context); } } //}}} @@ -149,14 +168,15 @@ private SyntaxStyle[] styles; private FontRenderContext fontRenderContext; private TabExpander expander; - private float endX; + private float x; private List<Chunk> out; private float wrapMargin; + private float endX; + private Token end; private boolean seenNonWhitespace; private float endOfWhitespace; - private boolean afterTrailingWhitespace; //}}} //{{{ createChunk() method @@ -169,16 +189,12 @@ } //}}} //{{{ initChunk() method - private void initChunk(Chunk chunk, Segment seg) + protected void initChunk(Chunk chunk, Segment seg) { - chunk.init(seg,expander,endX,fontRenderContext); + chunk.init(seg,expander,x,fontRenderContext); } //}}} //{{{ merge() method - /** - * Merges each adjucent chunks if possible, to reduce the number - * of chunks for rendering performance. - */ private Chunk merge(Chunk first, Segment seg) { if(first == null) @@ -202,7 +218,7 @@ { initChunk(chunk,seg); if(wrapMargin == 0.0f) - endX += chunk.width; + x += chunk.width; } chunk = next; } @@ -228,39 +244,5 @@ && (c1.length + c2.length <= MAX_CHUNK_LEN)); } //}}} - //{{{ wrapLine() method - /** - * Starts a new screen line. - */ - private void wrapLine(Segment seg, TokenMarker.LineContext context) - { - // Wrap can't happen at the start of a screen line. - assert lastToken != null; - - int eolOffset = lastToken.offset + lastToken.length; - terminateScreenLine(seg); - - Chunk indent = new Chunk(endOfWhitespace, eolOffset, - getParserRuleSet(context)); - initChunk(indent, seg); - addToken(indent, context); - - endX = endOfWhitespace; - } //}}} - - //{{{ terminateScreenLine() method - /** - * Makes the list of tokens into a screen line. - * The list becomes empty. - */ - private void terminateScreenLine(Segment seg) - { - if (firstToken != null) - { - out.add(merge((Chunk)firstToken, seg)); - firstToken = lastToken = null; - } - } //}}} - //}}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2010-09-14 17:23:00
|
Revision: 18562 http://jedit.svn.sourceforge.net/jedit/?rev=18562&view=rev Author: kpouer Date: 2010-09-14 17:22:54 +0000 (Tue, 14 Sep 2010) Log Message: ----------- removed unnecessary import Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2010-09-14 17:04:51 UTC (rev 18561) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2010-09-14 17:22:54 UTC (rev 18562) @@ -23,8 +23,6 @@ package org.gjt.sp.jedit.syntax; //{{{ Imports -import org.gjt.sp.jedit.buffer.JEditBuffer; - import javax.swing.text.*; import java.awt.font.*; import java.util.List; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2011-03-22 14:08:11
|
Revision: 19480 http://jedit.svn.sourceforge.net/jedit/?rev=19480&view=rev Author: kpouer Date: 2011-03-22 14:08:05 +0000 (Tue, 22 Mar 2011) Log Message: ----------- minor changes Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2011-03-22 13:59:41 UTC (rev 19479) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2011-03-22 14:08:05 UTC (rev 19480) @@ -99,6 +99,7 @@ * @param context The line context * @since jEdit 4.2pre3 */ + @Override public void handleToken(Segment seg, byte id, int offset, int length, TokenMarker.LineContext context) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-09 19:03:08
|
Revision: 21104 http://jedit.svn.sourceforge.net/jedit/?rev=21104&view=rev Author: k_satoda Date: 2012-02-09 19:02:57 +0000 (Thu, 09 Feb 2012) Log Message: ----------- Eliminated wasteful argument passings; always passing a same instance variable to a method in a same class. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-09 18:47:29 UTC (rev 21103) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-09 19:02:57 UTC (rev 21104) @@ -115,7 +115,7 @@ if(wrapMargin != 0.0f) { - initChunk(chunk,seg, physicalLineOffset); + initChunk(chunk,seg); x += chunk.width; if(Character.isWhitespace(seg.array[ @@ -138,7 +138,7 @@ Chunk nextLine = new Chunk(endOfWhitespace, end.offset + end.length, getParserRuleSet(context)); - initChunk(nextLine,seg, physicalLineOffset); + initChunk(nextLine,seg); nextLine.next = end.next; end.next = null; @@ -191,7 +191,7 @@ } //}}} //{{{ initChunk() method - private void initChunk(Chunk chunk, Segment seg, int physicalLineOffset) + private void initChunk(Chunk chunk, Segment seg) { chunk.init(seg,expander,x,fontRenderContext, physicalLineOffset); } //}}} @@ -218,7 +218,7 @@ { if(!chunk.initialized) { - initChunk(chunk,seg, physicalLineOffset); + initChunk(chunk,seg); if(wrapMargin == 0.0f) x += chunk.width; } @@ -227,7 +227,7 @@ } if(!chunk.initialized) - initChunk(chunk,seg, physicalLineOffset); + initChunk(chunk,seg); return first; } //}}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-11 15:36:09
|
Revision: 21115 http://jedit.svn.sourceforge.net/jedit/?rev=21115&view=rev Author: k_satoda Date: 2012-02-11 15:36:02 +0000 (Sat, 11 Feb 2012) Log Message: ----------- Isolated soft wrap algorithm into a single function to make further changes clearer. This was from SF.net patch #2483695. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-11 11:28:50 UTC (rev 21114) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-11 15:36:02 UTC (rev 21115) @@ -54,13 +54,10 @@ float wrapMargin, int physicalLineOffset) { super.init(); - - x = 0.0f; - this.styles = styles; this.fontRenderContext = fontRenderContext; this.expander = expander; - this.physicalLineOffset = physicalLineOffset; + this.out = out; // SILLY: allow for anti-aliased characters' "fuzz" if(wrapMargin != 0.0f) @@ -68,11 +65,7 @@ else this.wrapMargin = 0.0f; - this.out = out; - - seenNonWhitespace = false; - endX = endOfWhitespace = 0.0f; - end = null; + this.physicalLineOffset = physicalLineOffset; } //}}} //{{{ getChunkList() method @@ -102,11 +95,9 @@ public void handleToken(Segment seg, byte id, int offset, int length, TokenMarker.LineContext context) { - final Segment lineText = seg; if(id == Token.END) { - if(firstToken != null) - out.add(mergeAdjucentChunks((Chunk)firstToken,lineText)); + makeScreenLine(seg); return; } @@ -115,51 +106,6 @@ int splitLength = Math.min(length - splitOffset,MAX_CHUNK_LEN); Chunk chunk = createChunk(id,offset + splitOffset,splitLength,context); addToken(chunk,context); - - if(wrapMargin != 0.0f) - { - initChunk(chunk,lineText); - x += chunk.width; - - if(Character.isWhitespace(lineText.array[ - lineText.offset + chunk.offset])) - { - if(seenNonWhitespace) - { - end = lastToken; - endX = x; - } - else - endOfWhitespace = x; - } - else - { - if(x > wrapMargin - && end != null - && seenNonWhitespace) - { - Chunk nextLine = new Chunk(endOfWhitespace, - end.offset + end.length, - getParserRuleSet(context)); - initChunk(nextLine,lineText); - - nextLine.next = end.next; - end.next = null; - - if(firstToken != null) - out.add(mergeAdjucentChunks((Chunk)firstToken,lineText)); - - firstToken = nextLine; - - x = x - endX + endOfWhitespace; - - end = null; - endX = x; - } - - seenNonWhitespace = true; - } - } } } //}}} @@ -173,16 +119,9 @@ private SyntaxStyle[] styles; private FontRenderContext fontRenderContext; private TabExpander expander; - private float x; - private int physicalLineOffset; - private List<Chunk> out; private float wrapMargin; - private float endX; - private Token end; - - private boolean seenNonWhitespace; - private float endOfWhitespace; + private int physicalLineOffset; //}}} //{{{ createChunk() method @@ -195,7 +134,7 @@ } //}}} //{{{ initChunk() method - private void initChunk(Chunk chunk, Segment lineText) + private void initChunk(Chunk chunk, float x, Segment lineText) { chunk.init(lineText,expander,x,fontRenderContext, physicalLineOffset); } //}}} @@ -210,6 +149,12 @@ if(first == null) return null; + // x is accurate only when soft wrap is off. + // It's OK because when soft wrap is on, chunks are + // already initialized, and un-initialization never + // happens on tabs which are sole user of the value. + float x = 0.0f; + Chunk chunk = first; while(chunk.next != null) { @@ -226,7 +171,7 @@ { if(!chunk.initialized) { - initChunk(chunk,lineText); + initChunk(chunk, x, lineText); if(wrapMargin == 0.0f) x += chunk.width; } @@ -235,7 +180,7 @@ } if(!chunk.initialized) - initChunk(chunk,lineText); + initChunk(chunk, x, lineText); return first; } //}}} @@ -249,5 +194,72 @@ && (c1.length + c2.length) <= MAX_CHUNK_LEN; } //}}} + //{{{ makeScreenLineInWrapMargin() method + /** + * Do the main job for soft wrap feature. + */ + private void makeScreenLineInWrapMargin(Segment lineText) + { + Chunk lineHead = (Chunk)firstToken; + boolean seenNonWhitespace = false; + float endOfWhitespace = 0.0f; + float x = 0.0f; + Chunk end = null; + float endX = 0.0f; + for (Chunk chunk = lineHead; chunk != null; chunk = (Chunk)chunk.next) + { + initChunk(chunk, x, lineText); + x += chunk.width; + if(Character.isWhitespace(lineText.array[ + lineText.offset + chunk.offset])) + { + if(seenNonWhitespace) + { + end = chunk; + endX = x; + } + else + endOfWhitespace = x; + } + else + { + if(x > wrapMargin + && end != null + && seenNonWhitespace) + { + Chunk nextLine = new Chunk(endOfWhitespace, + end.offset + end.length, end.rules); + initChunk(nextLine, x, lineText); + nextLine.next = end.next; + end.next = null; + out.add(mergeAdjucentChunks(lineHead,lineText)); + lineHead = nextLine; + x = x - endX + endOfWhitespace; + end = null; + endX = x; + } + seenNonWhitespace = true; + } + } + out.add(mergeAdjucentChunks(lineHead,lineText)); + } //}}} + + //{{{ makeScreenLine() method + private void makeScreenLine(Segment lineText) + { + if(firstToken == null) + { + assert out.isEmpty(); + } + else if(wrapMargin > 0.0f) + { + makeScreenLineInWrapMargin(lineText); + } + else + { + out.add(mergeAdjucentChunks((Chunk)firstToken, lineText)); + } + } //}}} + //}}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-11 18:10:04
|
Revision: 21117 http://jedit.svn.sourceforge.net/jedit/?rev=21117&view=rev Author: k_satoda Date: 2012-02-11 18:09:58 +0000 (Sat, 11 Feb 2012) Log Message: ----------- Removed unnecessary access to Chunk.width. The access was also invalid for uninitialized Chunk. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-11 17:21:15 UTC (rev 21116) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-11 18:09:58 UTC (rev 21117) @@ -167,7 +167,6 @@ if(canMerge(chunk,next,lineText)) { chunk.length += next.length; - chunk.width += next.width; chunk.next = next.next; } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-20 17:04:17
|
Revision: 21154 http://jedit.svn.sourceforge.net/jedit/?rev=21154&view=rev Author: k_satoda Date: 2012-02-20 17:04:10 +0000 (Mon, 20 Feb 2012) Log Message: ----------- Avoided rendering errors caused by Chunk splitting in DisplayTokenHander. An example can be found in SF.net bug #3487005. Note that this fixes the problem with the example only on text mode. Original problem reported on html mode will need another fix. See also SF.net patch #3488908 as a related work. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-20 11:46:58 UTC (rev 21153) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-20 17:04:10 UTC (rev 21154) @@ -103,12 +103,52 @@ return; } - for(int splitOffset = 0; splitOffset < length; splitOffset += MAX_CHUNK_LEN) + // first branch to avoid unnecessary instansiation of + // BreakIterator. + if(length <= MAX_CHUNK_LEN) { - int splitLength = Math.min(length - splitOffset,MAX_CHUNK_LEN); - Chunk chunk = createChunk(id,offset + splitOffset,splitLength,context); - addToken(chunk,context); + Chunk chunk = createChunk(id, offset, length, context); + addToken(chunk, context); + return; } + + // split the token but at character breaks not to affect + // the result of painting. + final BreakIterator charBreaker = BreakIterator.getCharacterInstance(); + charBreaker.setText(seg); + final int tokenBeinIndex = seg.offset + offset; + final int tokenEndIndex = tokenBeinIndex + length; + int splitOffset = 0; + do + { + final int beginIndex = tokenBeinIndex + splitOffset; + int charBreakIndex = charBreaker.preceding(beginIndex + MAX_CHUNK_LEN + 1); + // {{{ care for unrealistic case, to be complete ... + // There must be a char break at beginning of token. + assert charBreakIndex != BreakIterator.DONE; + if(charBreakIndex <= beginIndex) + { + // try splitting after the limit, to + // make the chunk shorter anyway. + charBreakIndex = charBreaker.following(beginIndex + MAX_CHUNK_LEN); + // There must be a char break at end of token. + assert charBreakIndex != BreakIterator.DONE; + if(charBreakIndex >= tokenEndIndex) + { + // can't split + break; + } + } //}}} + final int splitLength = charBreakIndex - beginIndex; + Chunk chunk = createChunk(id, offset + splitOffset, + splitLength, context); + addToken(chunk, context); + splitOffset += splitLength; + } + while(splitOffset + MAX_CHUNK_LEN < length); + Chunk chunk = createChunk(id, offset + splitOffset, + length - splitOffset, context); + addToken(chunk, context); } //}}} //{{{ Private members This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-23 16:36:36
|
Revision: 21190 http://jedit.svn.sourceforge.net/jedit/?rev=21190&view=rev Author: k_satoda Date: 2012-02-23 16:36:27 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Eliminated quadratic iteration in DisplayTokenHandler.recalculateTabWidth() which could choke CPU when wrapping very long lines. If a line consists of 1000 chunks and the line is wrapped at every second chunk, the iteration goes roughly 998 + 996 + ... + 2 = 249500 times. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-23 09:32:46 UTC (rev 21189) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-23 16:36:27 UTC (rev 21190) @@ -244,7 +244,9 @@ } //}}} //{{{ recalculateTabWidth() method - private float recalculateTabWidth(Chunk lineHead, Segment lineText) + // Returns true if all chunks are recaluculated and the total + // width fits in wrap margin. + private boolean recalculateTabWidthInWrapMargin(Chunk lineHead, Segment lineText) { float x = 0.0f; for(Chunk chunk = lineHead; chunk != null; chunk = (Chunk)chunk.next) @@ -254,8 +256,12 @@ initChunk(chunk, x, lineText); } x += chunk.width; + if(x > wrapMargin) + { + return false; + } } - return x; + return true; } //}}} //{{{ countLeadingWhitespaces() method @@ -362,7 +368,7 @@ lineHead = remaining; } lineHead = makeWrappedLine(lineHead, virtualIndentWidth, lineText); - if(recalculateTabWidth(lineHead, lineText) <= wrapMargin) + if(recalculateTabWidthInWrapMargin(lineHead, lineText)) { // Fits in the margin. No more need to wrap. out.add(lineHead); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-26 18:54:54
|
Revision: 21215 http://jedit.svn.sourceforge.net/jedit/?rev=21215&view=rev Author: k_satoda Date: 2012-02-26 18:54:48 +0000 (Sun, 26 Feb 2012) Log Message: ----------- Added (prev > 0x7f) as a condition to accept a line break to be consistent with (next > 0x7f). With a non-ASCII character "*", rejecting a break between "*a" is not consistent while accepting a break between "a*". Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-26 16:30:03 UTC (rev 21214) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-26 18:54:48 UTC (rev 21215) @@ -577,11 +577,17 @@ char next = text.setIndex(baseBreak); char prev = text.previous(); text.setIndex(originalIndex); - // breaking without white spaces are wanted only - // for some natural languages which uses non-ASCII - // characters. + // When breaking at whitespace, jEdit treat the + // whitespaces as belonging to the previous line and + // make them editable. return !Character.isWhitespace(next) - && (Character.isWhitespace(prev) || next > 0x7f); + // Assuming that breaking without white spaces + // are wanted only for some natural languages + // which uses non-ASCII characters. Otherwise + // keep traditional jEdit behavior (break only + // at whitespaces). + && (Character.isWhitespace(prev) + || prev > 0x7f || next > 0x7f); } } //}}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-02-27 17:33:15
|
Revision: 21221 http://jedit.svn.sourceforge.net/jedit/?rev=21221&view=rev Author: k_satoda Date: 2012-02-27 17:33:04 +0000 (Mon, 27 Feb 2012) Log Message: ----------- Put hard coded workarounds not to cause unexpected soft wrap at starts/ends of quotes with some non-ASCII quotation marks. The cause of the problem seem to be in the implementation of BreakIterator, and seems not to be fixed in near future. (originally reported as SF.net bug #3488310, analyzed in a derived FR #3489523) Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-27 16:07:18 UTC (rev 21220) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-27 17:33:04 UTC (rev 21221) @@ -587,7 +587,25 @@ // keep traditional jEdit behavior (break only // at whitespaces). && (Character.isWhitespace(prev) - || prev > 0x7f || next > 0x7f); + || prev > 0x7f || next > 0x7f) + // Workarounds for the problem reported at + // SF.net bug #3488310; unexpected soft wrap + // happens at closing "“". + // Probably the cause is in the implementation + // of BreakIterator for line breaks. Some + // similer problems are also reported in + // bugs.sun.com. + // http://www.google.co.jp/search?q=site%3Abugs.sun.com+BreakIterator+getLineInstance + // There seems to be some problems in handling + // of quotation marks. + // The followings are accumulated cases that + // exhibits the problem under a local test on + // JRE 7u3 with samples taken from Wikipedia. + // http://en.wikipedia.org/wiki/Non-English_usage_of_quotation_marks + && !("”’»›".indexOf(prev) >= 0 + && !Character.isWhitespace(next)) + && !(!Character.isWhitespace(prev) + && "“„‘‚«‹".indexOf(next) >= 0); } } //}}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-03-01 15:22:55
|
Revision: 21236 http://jedit.svn.sourceforge.net/jedit/?rev=21236&view=rev Author: k_satoda Date: 2012-03-01 15:22:48 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Added another check before rejecting line breaks at quotation marks not to reject valid ones in CJK text. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-03-01 02:59:00 UTC (rev 21235) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-03-01 15:22:48 UTC (rev 21236) @@ -598,15 +598,52 @@ // http://www.google.co.jp/search?q=site%3Abugs.sun.com+BreakIterator+getLineInstance // There seems to be some problems in handling // of quotation marks. - // The followings are accumulated cases that - // exhibits the problem under a local test on - // JRE 7u3 with samples taken from Wikipedia. - // http://en.wikipedia.org/wiki/Non-English_usage_of_quotation_marks - && !("”’»›".indexOf(prev) >= 0 - && !Character.isWhitespace(next)) - && !(!Character.isWhitespace(prev) - && "“„‘‚«‹".indexOf(next) >= 0); + && !isUnacceptableBreakInsideQuote(baseBreak, + text, prev, next); } + + // Retrieves char at specified index without altering + // the current index of CharacterIterator. + private static char charAt(CharacterIterator text, int index) + { + int originalIndex = text.getIndex(); + char c = text.setIndex(index); + text.setIndex(originalIndex); + return c; + } + + private static boolean isUnacceptableBreakInsideQuote( + int baseBreak, CharacterIterator text, + char prev, char next) + { + // The following quotation marks are accumulated + // cases that exhibits the problem under a local + // test on JRE 7u3 with samples taken from Wikipedia. + // http://en.wikipedia.org/wiki/Non-English_usage_of_quotation_marks + // + // The last check for enclosing whitespace avoids + // unwanted rejection of line breaks in CJK text + // (which don't have such whitespace) where default + // behavior of BreakIterator is reasonable. + // + if ("”’»›".indexOf(prev) >= 0 + && !Character.isWhitespace(next)) + { + int beforeQuote = baseBreak - 2; + return beforeQuote < text.getBeginIndex() + || Character.isWhitespace(charAt(text, + beforeQuote)); + } + else if (!Character.isWhitespace(prev) + && "“„‘‚«‹".indexOf(next) >= 0) + { + int afterQuote = baseBreak + 1; + return afterQuote >= text.getEndIndex() + || Character.isWhitespace(charAt(text, + afterQuote)); + } + return false; + } } //}}} //}}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-03-06 17:34:46
|
Revision: 21252 http://jedit.svn.sourceforge.net/jedit/?rev=21252&view=rev Author: k_satoda Date: 2012-03-06 17:34:40 +0000 (Tue, 06 Mar 2012) Log Message: ----------- Fixed an inverted and always failing assertion. I had missed "-ea" in my testing command line. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-03-05 22:01:50 UTC (rev 21251) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-03-06 17:34:40 UTC (rev 21252) @@ -295,7 +295,7 @@ for(;;) { final int offsetInMargin = Chunk.xToOffset(lineHead, wrapMargin, false); - assert offsetInMargin == -1; + assert offsetInMargin != -1; lineBreaker.skipToNearest(offsetInMargin); final int lineBreak = lineBreaker.currentBreak(); if(lineBreak == LineBreaker.DONE) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-03-07 17:01:25
|
Revision: 21261 http://jedit.svn.sourceforge.net/jedit/?rev=21261&view=rev Author: k_satoda Date: 2012-03-07 17:01:14 +0000 (Wed, 07 Mar 2012) Log Message: ----------- Added another check not to cause unexpected soft wrap after punctuation apostrophe U+2019 which forms contracted words. (SF.net bug #3497312) Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-03-07 15:39:40 UTC (rev 21260) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-03-07 17:01:14 UTC (rev 21261) @@ -589,8 +589,10 @@ && (Character.isWhitespace(prev) || prev > 0x7f || next > 0x7f) // Workarounds for the problem reported at - // SF.net bug #3488310; unexpected soft wrap - // happens at closing "“". + // - SF.net bug #3497312; Unexpected softwrap + // in contracted words with ’ as apostrophe. + // - SF.net bug #3488310; unexpected soft wrap + // happens at closing "“". // Probably the cause is in the implementation // of BreakIterator for line breaks. Some // similer problems are also reported in @@ -598,6 +600,12 @@ // http://www.google.co.jp/search?q=site%3Abugs.sun.com+BreakIterator+getLineInstance // There seems to be some problems in handling // of quotation marks. + && !(prev == '’' + // This test excludes CJK characters + // which may come after a closing + // quote. + && (Character.isLowerCase(next) + || Character.isUpperCase(next))) && !isUnacceptableBreakInsideQuote(baseBreak, text, prev, next); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jar...@us...> - 2012-04-29 06:31:22
|
Revision: 21614 http://jedit.svn.sourceforge.net/jedit/?rev=21614&view=rev Author: jarekczek Date: 2012-04-29 06:31:16 +0000 (Sun, 29 Apr 2012) Log Message: ----------- Added :encoding=utf-8: property to DisplayTokenHandler.java Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-04-28 21:18:30 UTC (rev 21613) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-04-29 06:31:16 UTC (rev 21614) @@ -1,7 +1,7 @@ /* * DisplayTokenHandler.java - converts tokens to chunks * :tabSize=8:indentSize=8:noTabs=false: - * :folding=explicit:collapseFolds=1: + * :folding=explicit:collapseFolds=1:encoding=utf-8: * * Copyright (C) 2003 Slava Pestov * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-04-30 20:24:45
|
Revision: 21620 http://jedit.svn.sourceforge.net/jedit/?rev=21620&view=rev Author: k_satoda Date: 2012-04-30 20:24:39 +0000 (Mon, 30 Apr 2012) Log Message: ----------- Extended the workaround for unacceptable break inside quote for the case where the quote mark is enclosed by something like a parenthesis. (SF.net bug #3502384) Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-04-30 18:05:30 UTC (rev 21619) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-04-30 20:24:39 UTC (rev 21620) @@ -638,17 +638,39 @@ && !Character.isWhitespace(next)) { int beforeQuote = baseBreak - 2; - return beforeQuote < text.getBeginIndex() - || Character.isWhitespace(charAt(text, - beforeQuote)); + int beginIndex = text.getBeginIndex(); + while (beforeQuote >= beginIndex) + { + char c = charAt(text, beforeQuote); + if (Character.isWhitespace(c)) + return true; + if (Character.isLetterOrDigit(c)) + return false; + // Look farther in case where the + // opening quote is enclosed by + // something like a opening parenthesis. + --beforeQuote; + } + return true; } else if (!Character.isWhitespace(prev) && "“„‘‚«‹".indexOf(next) >= 0) { int afterQuote = baseBreak + 1; - return afterQuote >= text.getEndIndex() - || Character.isWhitespace(charAt(text, - afterQuote)); + int endIndex = text.getEndIndex(); + while (afterQuote < endIndex) + { + char c = charAt(text, afterQuote); + if (Character.isWhitespace(c)) + return true; + if (Character.isLetterOrDigit(c)) + return false; + // Look farther in case where the + // closing quote is enclosed by + // something like a closing parenthesis. + ++afterQuote; + } + return true; } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-05-05 16:12:06
|
Revision: 21633 http://jedit.svn.sourceforge.net/jedit/?rev=21633&view=rev Author: k_satoda Date: 2012-05-05 16:11:59 +0000 (Sat, 05 May 2012) Log Message: ----------- Fixed an unexpected change of behavior that break a line shorter than before when a whitespace or a span of whitespaces strides over the wrap margin. (Now any number of whitespaces go beyond the wrap margin as before.) Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-05-05 08:59:39 UTC (rev 21632) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-05-05 16:11:59 UTC (rev 21633) @@ -264,17 +264,17 @@ return true; } //}}} - //{{{ countLeadingWhitespaces() method - private static int countLeadingWhitespaces(Segment lineText) + //{{{ endOffsetOfWhitespaces() method + private static int endOffsetOfWhitespaces(Segment lineText, int origin) { - int count = 0; - while((count < lineText.count) + int offset = origin; + while((offset < lineText.count) && Character.isWhitespace( - lineText.array[lineText.offset + count])) + lineText.array[lineText.offset + offset])) { - ++count; + ++offset; } - return count; + return offset; } //}}} //{{{ makeScreenLineInWrapMargin() method @@ -283,7 +283,7 @@ */ private void makeScreenLineInWrapMargin(Chunk lineHead, Segment lineText) { - final int endOfWhitespace = countLeadingWhitespaces(lineText); + final int endOfWhitespace = endOffsetOfWhitespaces(lineText, 0); final float virtualIndentWidth = Chunk.offsetToX(lineHead, endOfWhitespace); final LineBreaker lineBreaker = new LineBreaker(lineText, endOfWhitespace); if(lineBreaker.currentBreak() == LineBreaker.DONE) @@ -296,7 +296,8 @@ { final int offsetInMargin = Chunk.xToOffset(lineHead, wrapMargin, false); assert offsetInMargin != -1; - lineBreaker.skipToNearest(offsetInMargin); + lineBreaker.skipToNearest(endOffsetOfWhitespaces( + lineText, offsetInMargin)); final int lineBreak = lineBreaker.currentBreak(); if(lineBreak == LineBreaker.DONE) { @@ -352,7 +353,8 @@ { final int offsetInRoom = lineEnd.xToOffset(processedWidth + remainingRoom, false); assert offsetInRoom != -1; - lineBreaker.skipToNearest(offsetInRoom); + lineBreaker.skipToNearest(endOffsetOfWhitespaces( + lineText, offsetInRoom)); final int moreBreak = lineBreaker.currentBreak(); assert moreBreak != LineBreaker.DONE; lineBreaker.advance(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <k_s...@us...> - 2012-05-19 19:44:22
|
Revision: 21688 http://jedit.svn.sourceforge.net/jedit/?rev=21688&view=rev Author: k_satoda Date: 2012-05-19 19:44:16 +0000 (Sat, 19 May 2012) Log Message: ----------- Fixed invalid splitting of Chunk which became possible after r21633. Revision Links: -------------- http://jedit.svn.sourceforge.net/jedit/?rev=21633&view=rev Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-05-19 18:55:33 UTC (rev 21687) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-05-19 19:44:16 UTC (rev 21688) @@ -357,6 +357,11 @@ lineText, offsetInRoom)); final int moreBreak = lineBreaker.currentBreak(); assert moreBreak != LineBreaker.DONE; + if (moreBreak >= (remaining.offset + remaining.length)) + { + // This can happen if remaining ends with whitespaces. + break; + } lineBreaker.advance(); final Chunk moreShortened = remaining.snippetBeforeLineOffset(moreBreak); initChunk(moreShortened, virtualIndentWidth, lineText); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kp...@us...> - 2020-05-29 16:42:59
|
Revision: 25345 http://sourceforge.net/p/jedit/svn/25345 Author: kpouer Date: 2020-05-29 16:42:56 +0000 (Fri, 29 May 2020) Log Message: ----------- disable chunk cache merging by giving a max chunk length to 1, it seems it is drasticly faster (because of chunk cache) Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2020-05-28 21:50:15 UTC (rev 25344) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2020-05-29 16:42:56 UTC (rev 25345) @@ -149,7 +149,7 @@ // Don't have chunks longer than a limit to avoid slowing things down. // For example, too long chunks are hardly clipped out at rendering. - private static final int MAX_CHUNK_LEN = 100; + public static int MAX_CHUNK_LEN = 1; //{{{ Instance variables private SyntaxStyle[] styles; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |