diff options
author | angelozerr | 2018-03-12 13:29:53 +0000 |
---|---|---|
committer | angelozerr | 2018-03-12 16:49:55 +0000 |
commit | bebb5a000948239f296a4452c35595b51b5c26da (patch) | |
tree | 743aaf9224f85cff56c6234e8f979bce5fee520f /org.eclipse.jface.text/src/org/eclipse/jface/text/source | |
parent | a2350cfe776b5a00973350637e238cf622e336a4 (diff) | |
download | eclipse.platform.text-bebb5a000948239f296a4452c35595b51b5c26da.tar.gz eclipse.platform.text-bebb5a000948239f296a4452c35595b51b5c26da.tar.xz eclipse.platform.text-bebb5a000948239f296a4452c35595b51b5c26da.zip |
Bug 532326 - [CodeMining] Fix redraw of character with custom font style
Change-Id: I88dca0a515269803e9afaaf63072589ad5e797ba
Signed-off-by: angelozerr <angelo.zerr@gmail.com>
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface/text/source')
3 files changed, 88 insertions, 2 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java index cdd5952f1a3..7cc4baf696e 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java @@ -16,6 +16,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.jface.text.ITextViewerExtension5; @@ -178,4 +179,16 @@ public abstract class AbstractInlinedAnnotation extends Annotation { protected boolean isInVisibleLines(int offset) { return support.isInVisibleLines(offset); } + + /** + * Returns the font according the specified <code>style</code> that the receiver will use to + * paint textual information. + * + * @param style the style of Font widget to get. + * @return the receiver's font according the specified <code>style</code> + * + */ + protected Font getFont(int style) { + return support.getFont(style); + } } diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java index 30bb8a7dbfd..42be75000d6 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java @@ -200,6 +200,7 @@ class InlinedAnnotationDrawingStrategy implements IDrawingStrategy { if (style.foreground != null) { gc.setForeground(style.foreground); } + gc.setFont(annotation.getFont(style.fontStyle)); } gc.drawString(s, charX, charY, true); } diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java index ee972ce0175..7ab62bcdec2 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java @@ -16,8 +16,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import java.util.Map.Entry; import java.util.function.Consumer; import org.eclipse.swt.SWT; @@ -29,6 +29,9 @@ import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.MouseMoveListener; import org.eclipse.swt.events.MouseTrackListener; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.GlyphMetrics; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Display; @@ -50,11 +53,11 @@ import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TextPresentation; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.AnnotationPainter; -import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.IAnnotationModelExtension2; import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy; /** * Support to draw inlined annotations: @@ -79,6 +82,11 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { private static final String INLINED_STRATEGY_ID= "inlined"; //$NON-NLS-1$ /** + * The StyledText font normal, bold, italic and bold itlaic both. + */ + private Font regularFont, boldFont, italicFont, boldItalicFont; + + /** * Listener used to update {@link GlyphMetrics} width style for {@link LineContentAnnotation}. */ private ITextPresentationListener updateStylesWidth; @@ -388,6 +396,7 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { visibleLines.uninstall(); visibleLines= null; } + disposeFont(); fViewer= null; fPainter= null; } @@ -694,4 +703,67 @@ public class InlinedAnnotationSupport implements StyledTextLineSpacingProvider { boolean isInVisibleLines(int offset) { return visibleLines.isInVisibleLines(offset); } + + /** + * Returns the font according the specified <code>style</code> that the receiver will use to + * paint textual information. + * + * @param style the style of Font widget to get. + * @return the receiver's font according the specified <code>style</code> + * + */ + Font getFont(int style) { + StyledText styledText= fViewer != null ? fViewer.getTextWidget() : null; + if (styledText == null) { + return null; + } + if (!styledText.getFont().equals(regularFont)) { + disposeFont(); + regularFont= styledText.getFont(); + } + Device device= styledText.getDisplay(); + switch (style) { + case SWT.BOLD: + if (boldFont != null) + return boldFont; + return boldFont= new Font(device, getFontData(style)); + case SWT.ITALIC: + if (italicFont != null) + return italicFont; + return italicFont= new Font(device, getFontData(style)); + case SWT.BOLD | SWT.ITALIC: + if (boldItalicFont != null) + return boldItalicFont; + return boldItalicFont= new Font(device, getFontData(style)); + default: + return regularFont; + } + } + + /** + * Returns the font data array according the given style. + * + * @param style the style + * @return the font data array according the given style. + */ + FontData[] getFontData(int style) { + FontData[] fontDatas= regularFont.getFontData(); + for (int i= 0; i < fontDatas.length; i++) { + fontDatas[i].setStyle(style); + } + return fontDatas; + } + + /** + * Dispose the font. + */ + void disposeFont() { + if (boldFont != null) + boldFont.dispose(); + if (italicFont != null) + italicFont.dispose(); + if (boldItalicFont != null) + boldItalicFont.dispose(); + boldFont= italicFont= boldItalicFont= null; + } } |