View | Details | Raw Unified | Return to bug 69253 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java (-6 / +73 lines)
Lines 47-53 Link Here
47
	StyleItem[] allRuns;
47
	StyleItem[] allRuns;
48
	StyleItem[][] runs;
48
	StyleItem[][] runs;
49
	int[] lineOffset, lineY, lineWidth;
49
	int[] lineOffset, lineY, lineWidth;
50
	
50
51
	boolean forceMonospace;
52
51
	static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F';	
53
	static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F';	
52
	static final int SCRIPT_VISATTR_SIZEOF = 2;
54
	static final int SCRIPT_VISATTR_SIZEOF = 2;
53
	static final int GOFFSET_SIZEOF = 8;
55
	static final int GOFFSET_SIZEOF = 8;
Lines 146-151 Link Here
146
	styles[1] = new StyleItem();
148
	styles[1] = new StyleItem();
147
	text = ""; //$NON-NLS-1$
149
	text = ""; //$NON-NLS-1$
148
	if (device.tracking) device.new_Object(this);
150
	if (device.tracking) device.new_Object(this);
151
152
	forceMonospace = false;
149
}
153
}
150
154
151
void breakRun(StyleItem run) {
155
void breakRun(StyleItem run) {
Lines 172-179 Link Here
172
	allRuns = itemize();
176
	allRuns = itemize();
173
	for (int i=0; i<allRuns.length - 1; i++) {
177
	for (int i=0; i<allRuns.length - 1; i++) {
174
		StyleItem run = allRuns[i];
178
		StyleItem run = allRuns[i];
175
		OS.SelectObject(srcHdc, getItemFont(run));
179
		int hFont = getItemFont(run);
180
		OS.SelectObject(srcHdc, hFont);
176
		shape(srcHdc, run);
181
		shape(srcHdc, run);
182
183
		if (forceMonospace && font != null && hFont != font.handle) {
184
			forceMonospace(srcHdc, run);
185
		}
177
	}
186
	}
178
	SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR();
187
	SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR();
179
	SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES();
188
	SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES();
Lines 280-288 Link Here
280
				newRun.analysis = run.analysis;
289
				newRun.analysis = run.analysis;
281
				run.free();
290
				run.free();
282
				run.length = start;
291
				run.length = start;
283
				OS.SelectObject(srcHdc, getItemFont(run));
292
				int hFont = getItemFont(run);
293
				OS.SelectObject(srcHdc, hFont);
284
				shape (srcHdc, run);
294
				shape (srcHdc, run);
285
				shape (srcHdc, newRun);
295
				shape (srcHdc, newRun);
296
				if (forceMonospace && font != null && hFont != font.handle) {
297
					forceMonospace(srcHdc, run);
298
					forceMonospace(srcHdc, newRun);
299
				}
286
				StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1];
300
				StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1];
287
				System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1);
301
				System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1);
288
				System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1);
302
				System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1);
Lines 491-505 Link Here
491
			drawX += run.width;
505
			drawX += run.width;
492
		}
506
		}
493
		drawX = alignmentX;
507
		drawX = alignmentX;
508
		boolean endsWithLineBreak = false;
494
		for (int i = 0; i < lineRuns.length; i++) {
509
		for (int i = 0; i < lineRuns.length; i++) {
495
			StyleItem run = lineRuns[i];
510
			StyleItem run = lineRuns[i];
496
			if (run.length == 0) continue;
511
			if (run.length == 0) continue;
497
			if (drawX > clip.x + clip.width) break;
512
			if (drawX > clip.x + clip.width) break;
498
			if (drawX + run.width >= clip.x) {
513
			if (drawX + run.width >= clip.x) {
514
				int end = run.start + run.length - 1;
515
				boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
499
				if (!run.tab && (!run.lineBreak || run.softBreak)) {
516
				if (!run.tab && (!run.lineBreak || run.softBreak)) {
500
					int end = run.start + run.length - 1;
501
					int fg = foreground;
517
					int fg = foreground;
502
					boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end;
503
					if (fullSelection) {
518
					if (fullSelection) {
504
						fg = selectionForeground.handle;
519
						fg = selectionForeground.handle;
505
					} else {
520
					} else {
Lines 527-534 Link Here
527
						rect.bottom = drawY + lineHeight;
542
						rect.bottom = drawY + lineHeight;
528
						OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, OS.ETO_CLIPPED, rect, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, null, run.goffsets);
543
						OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, OS.ETO_CLIPPED, rect, run.analysis , 0, 0, run.glyphs, run.glyphCount, run.advances, null, run.goffsets);
529
					}
544
					}
530
				}
545
				} 
531
			}
546
			}
547
			endsWithLineBreak = run.lineBreak && !run.softBreak;
532
			drawX += run.width;
548
			drawX += run.width;
533
		}
549
		}
534
	}
550
	}
Lines 1963-1966 Link Here
1963
	}
1979
	}
1964
	return offset;
1980
	return offset;
1965
}
1981
}
1982
1983
/**
1984
 * Sets whether using the force monospace operation.
1985
 * 
1986
 * @param forceMonospace whether using the force monospace operation
1987
 */
1988
public void setForceMonospace (boolean forceMonospace) {
1989
	this.forceMonospace = forceMonospace;
1990
}
1991
1992
/**
1993
 * return whether using the force monospace operation.
1994
 * 
1995
 * @return whether using the force monospace operation.
1996
 */
1997
public boolean getForceMonospace () {
1998
	return forceMonospace;
1999
}
2000
2001
/**
2002
 * Force monospace.
2003
 * For example, MS Gothic is a monospaced font. 
2004
 * However width of regular is not same as bold.
2005
 * This method resolve this problem.
2006
 * 
2007
 * This method does not include the resolution of the problem 417434 in Microsoft Knowledge Base. 
2008
 * 417434 described a problem related to east asian full width characters.
2009
 * In monospace font, full width characters need twice width of half width characters.
2010
 * However, before WindowsXP, full width characters is not twich width of half width charcters in specific size.
2011
 * 
2012
 * @param forceMonospace whether using the force monospace operation
2013
 * 
2014
 * @see http://support.microsoft.com/default.aspx?scid=kb;ja;JP417434
2015
 */
2016
void forceMonospace(int srcHdc, StyleItem run) {
2017
	StyleItem dummyRun = new StyleItem();
2018
2019
	dummyRun.style = new TextStyle(font, run.style.foreground, run.style.background);
2020
	dummyRun.analysis = run.analysis;
2021
	dummyRun.start = run.start;
2022
	dummyRun.length = run.length;
2023
	OS.SelectObject(srcHdc, font.handle);
2024
	shape(srcHdc, dummyRun);
2025
	int temp;
2026
	temp = run.advances; run.advances = dummyRun.advances; dummyRun.advances = temp;
2027
	temp = run.goffsets; run.goffsets = dummyRun.goffsets; dummyRun.goffsets = temp;
2028
	run.width = dummyRun.width;
2029
2030
	dummyRun.free();
2031
}
2032
1966
}
2033
}
(-)Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java (+45 lines)
Lines 150-155 Link Here
150
	Caret defaultCaret = null;
150
	Caret defaultCaret = null;
151
	boolean updateCaretDirection = true;
151
	boolean updateCaretDirection = true;
152
152
153
	boolean forceMonospace;
154
153
	final static boolean IS_CARBON;
155
	final static boolean IS_CARBON;
154
	final static boolean DOUBLE_BUFFERED;	
156
	final static boolean DOUBLE_BUFFERED;	
155
	static {
157
	static {
Lines 5323-5328 Link Here
5323
		renderer.dispose();
5325
		renderer.dispose();
5324
	}
5326
	}
5325
	renderer = new DisplayRenderer(getDisplay(), getFont(), this, tabLength);
5327
	renderer = new DisplayRenderer(getDisplay(), getFont(), this, tabLength);
5328
	renderer.forceMonospace = forceMonospace;
5329
5326
	lineHeight = renderer.getLineHeight();
5330
	lineHeight = renderer.getLineHeight();
5327
	if (wordWrap) {
5331
	if (wordWrap) {
5328
	    content = new WrappedContent(renderer, logicalContent);
5332
	    content = new WrappedContent(renderer, logicalContent);
Lines 7793-7796 Link Here
7793
	// word wrap may have changed on one of the visible lines
7797
	// word wrap may have changed on one of the visible lines
7794
    super.redraw();
7798
    super.redraw();
7795
}
7799
}
7800
7801
/**
7802
 * Sets whether using the force monospace operation.
7803
 * 
7804
 * @param forceMonospace whether using the force monospace operation
7805
 * 
7806
 * @see org.eclipse.swt.graphics.TextLayout#forceMonospace(int, StyleItem)
7807
 */
7808
public void setForceMonospace (boolean forceMonospace) {
7809
7810
	if (this.forceMonospace != forceMonospace) {
7811
		this.forceMonospace = forceMonospace;
7812
7813
		//same as #setFont(Font)
7814
		initializeRenderer();
7815
7816
		//line height is not change.
7817
		//// keep the same top line visible. fixes 5815
7818
		//if (lineHeight != oldLineHeight) {
7819
		//	setVerticalScrollOffset(verticalScrollOffset * lineHeight / oldLineHeight, true);
7820
		//	claimBottomFreeSpace();
7821
		//}
7822
		calculateContentWidth();
7823
		calculateScrollBars();
7824
		if (isBidi()) createCaretBitmaps();
7825
		caretDirection = SWT.NULL;
7826
		// always set the caret location. Fixes 6685
7827
		setCaretLocation();
7828
		super.redraw();
7829
	}
7830
}
7831
7832
/**
7833
 * return whether using the force monospace operation.
7834
 * 
7835
 * @return whether using the force monospace operation.
7836
 */
7837
public boolean getForceMonospace () {
7838
	return forceMonospace;
7839
}
7840
	
7796
}
7841
}
(-)Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java (-1 / +5 lines)
Lines 26-32 Link Here
26
	private int tabWidth;					// width in pixels of a tab character
26
	private int tabWidth;					// width in pixels of a tab character
27
	private int ascent, descent;
27
	private int ascent, descent;
28
	private int lineEndSpaceWidth;			// width in pixels of the space used to represent line delimiters
28
	private int lineEndSpaceWidth;			// width in pixels of the space used to represent line delimiters
29
	
29
30
	boolean forceMonospace;
31
30
/**
32
/**
31
 * Creates an instance of <class>StyledTextRenderer</class>.
33
 * Creates an instance of <class>StyledTextRenderer</class>.
32
 * </p>
34
 * </p>
Lines 414-419 Link Here
414
	layout.setOrientation(getOrientation());
416
	layout.setOrientation(getOrientation());
415
	layout.setSegments(getBidiSegments(lineOffset, line));
417
	layout.setSegments(getBidiSegments(lineOffset, line));
416
	layout.setTabs(new int[]{tabWidth});
418
	layout.setTabs(new int[]{tabWidth});
419
	layout.setForceMonospace (forceMonospace);
417
	int length = line.length();
420
	int length = line.length();
418
	StyledTextEvent event = getLineStyleData(lineOffset, line);
421
	StyledTextEvent event = getLineStyleData(lineOffset, line);
419
	StyleRange[] styles = event != null ? event.styles : null;
422
	StyleRange[] styles = event != null ? event.styles : null;
Lines 442-447 Link Here
442
	if (lastOffset != length) layout.setStyle(null, lastOffset, length);
445
	if (lastOffset != length) layout.setStyle(null, lastOffset, length);
443
	return layout;
446
	return layout;
444
}
447
}
448
445
TextLayout createTextLayout(int lineOffset) {
449
TextLayout createTextLayout(int lineOffset) {
446
	return new TextLayout(device);
450
	return new TextLayout(device);
447
}
451
}

Return to bug 69253