本文整理汇总了Java中com.intellij.openapi.editor.ex.util.EditorUtil.fontForChar方法的典型用法代码示例。如果您正苦于以下问题:Java EditorUtil.fontForChar方法的具体用法?Java EditorUtil.fontForChar怎么用?Java EditorUtil.fontForChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.editor.ex.util.EditorUtil
的用法示例。
在下文中一共展示了EditorUtil.fontForChar方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawCharsCached
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void drawCharsCached(@NotNull Graphics g,
CharSequence data,
int start,
int end,
int x,
int y,
@JdkConstants.FontStyle int fontType,
Color color,
boolean drawWhitespace) {
FontInfo fnt = EditorUtil.fontForChar(data.charAt(start), fontType, this);
if (myLastCache != null && spacesOnly(data, start, end) && fnt.charWidth(' ') == myLastCache.spaceWidth) {
// we don't care about font if we only need to paint spaces and space width matches
myLastCache.addContent(g, data, start, end, x, y, null, drawWhitespace);
}
else {
drawCharsCached(g, data, start, end, x, y, fnt, color, drawWhitespace);
}
}
示例2: reinit
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
/**
* Tries to find fonts that are capable to display all unicode symbols used by the current painter.
*/
@Override
public void reinit() {
// We use dummy component here in order to being able to work with font metrics.
JLabel component = new JLabel();
myCanUse = true;
for (Map.Entry<SoftWrapDrawingType, char[]> entry : mySymbols.entrySet()) {
SoftWrapDrawingType type = entry.getKey();
char c = entry.getValue()[0];
FontInfo fontInfo = EditorUtil.fontForChar(c, Font.PLAIN, myEditor);
if (!fontInfo.canDisplay(c)) {
myCanUse = false;
myFonts.put(type, null);
myVGaps.put(type, null);
myWidths[type.ordinal()] = 0;
}
else {
myFonts.put(type, fontInfo);
FontMetrics metrics = component.getFontMetrics(fontInfo.getFont());
myWidths[type.ordinal()] = metrics.charWidth(c);
int vGap = metrics.getDescent();
myVGaps.put(type, vGap);
}
}
}
示例3: drawTablessString
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private int drawTablessString(final CharSequence text,
int start,
final int end,
@NotNull final Graphics g,
int x,
final int y,
@JdkConstants.FontStyle final int fontType,
final Color fontColor,
@NotNull final Rectangle clip,
WhitespacePaintingStrategy context) {
int endX = x;
if (start < end) {
FontInfo font = null;
boolean drawWhitespace = false;
for (int j = start; j < end; j++) {
if (x > clip.x + clip.width) {
return endX;
}
final char c = text.charAt(j);
FontInfo newFont = EditorUtil.fontForChar(c, fontType, this);
boolean newDrawWhitespace = context.showWhitespaceAtOffset(j);
boolean isRtlChar = myDisableRtl && isRtlCharacter(c);
if (j > start && (endX < clip.x || endX > clip.x + clip.width || newFont != font || newDrawWhitespace != drawWhitespace || isRtlChar)) {
if (isOverlappingRange(clip, x, endX)) {
drawCharsCached(g, text, start, j, x, y, fontType, fontColor, drawWhitespace);
}
start = j;
x = endX;
}
font = newFont;
drawWhitespace = newDrawWhitespace;
endX += font.charWidth(c);
if (font.hasGlyphsToBreakDrawingIteration() && font.getSymbolsToBreakDrawingIteration().contains(c) || isRtlChar) {
drawCharsCached(g, text, start, j + 1, x, y, fontType, fontColor, drawWhitespace);
start = j + 1;
x = endX;
}
}
if (isOverlappingRange(clip, x, endX)) {
drawCharsCached(g, text, start, end, x, y, fontType, fontColor, drawWhitespace);
}
}
return endX;
}
示例4: paintAt
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void paintAt(@NotNull Graphics g, int x, int y, int width, Caret caret) {
int lineHeight = getLineHeight();
Rectangle viewRectangle = getScrollingModel().getVisibleArea();
if (x - viewRectangle.x < 0) {
return;
}
g.setColor(myScheme.getColor(EditorColors.CARET_COLOR));
Graphics2D originalG = IdeBackgroundUtil.getOriginalGraphics(g);
if (!paintBlockCaret()) {
if (UIUtil.isRetina()) {
originalG.fillRect(x, y, mySettings.getLineCursorWidth(), lineHeight);
}
else {
g.fillRect(x, y, JBUI.scale(mySettings.getLineCursorWidth()), lineHeight);
}
}
else {
Color caretColor = myScheme.getColor(EditorColors.CARET_COLOR);
if (caretColor == null) caretColor = new JBColor(Gray._0, Gray._255);
g.setColor(caretColor);
originalG.fillRect(x, y, width, lineHeight - 1);
final LogicalPosition startPosition = caret == null ? getCaretModel().getLogicalPosition() : caret.getLogicalPosition();
final int offset = logicalPositionToOffset(startPosition);
CharSequence chars = myDocument.getImmutableCharSequence();
if (chars.length() > offset && myDocument.getTextLength() > offset) {
FoldRegion folding = myFoldingModel.getCollapsedRegionAtOffset(offset);
final char ch;
if (folding == null || folding.isExpanded()) {
ch = chars.charAt(offset);
}
else {
VisualPosition visual = caret == null ? getCaretModel().getVisualPosition() : caret.getVisualPosition();
VisualPosition foldingPosition = offsetToVisualPosition(folding.getStartOffset());
if (visual.line == foldingPosition.line) {
ch = folding.getPlaceholderText().charAt(visual.column - foldingPosition.column);
}
else {
ch = chars.charAt(offset);
}
}
//don't worry it's cheap. Cache is not required
IterationState state = new IterationState(EditorImpl.this, offset, offset + 1, true);
TextAttributes attributes = state.getMergedAttributes();
FontInfo info = EditorUtil.fontForChar(ch, attributes.getFontType(), EditorImpl.this);
g.setFont(info.getFont());
//todo[kb]
//in case of italic style we paint out of the cursor block. Painting the symbol to a dedicated buffered image
//solves the problem, but still looks weird because it leaves colored pixels at right.
g.setColor(ColorUtil.isDark(caretColor) ? CURSOR_FOREGROUND_LIGHT : CURSOR_FOREGROUND_DARK);
g.drawChars(new char[]{ch}, 0, 1, x, y + getAscent());
}
}
}
示例5: drawTablessString
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private int drawTablessString(final CharSequence text,
int start,
final int end,
@NotNull final Graphics g,
int x,
final int y,
@JdkConstants.FontStyle final int fontType,
final Color fontColor,
@NotNull final Rectangle clip,
WhitespacePaintingStrategy context) {
int endX = x;
if (start < end) {
FontInfo font = null;
boolean drawWhitespace = false;
for (int j = start; j < end; j++) {
if (x > clip.x + clip.width) {
return endX;
}
final char c = text.charAt(j);
FontInfo newFont = EditorUtil.fontForChar(c, fontType, this);
boolean newDrawWhitespace = context.showWhitespaceAtOffset(j);
boolean isRtlChar = myDisableRtl && isRtlCharacter(c);
if (j > start &&
(endX < clip.x || endX > clip.x + clip.width || newFont != font || newDrawWhitespace != drawWhitespace || isRtlChar)) {
if (isOverlappingRange(clip, x, endX)) {
drawCharsCached(g, text, start, j, x, y, fontType, fontColor, drawWhitespace);
}
start = j;
x = endX;
}
font = newFont;
drawWhitespace = newDrawWhitespace;
endX += font.charWidth(c);
if (font.hasGlyphsToBreakDrawingIteration() && font.getSymbolsToBreakDrawingIteration().contains(c) || isRtlChar) {
drawCharsCached(g, text, start, j + 1, x, y, fontType, fontColor, drawWhitespace);
start = j + 1;
x = endX;
}
}
if (isOverlappingRange(clip, x, endX)) {
drawCharsCached(g, text, start, end, x, y, fontType, fontColor, drawWhitespace);
}
}
return endX;
}
示例6: paintAt
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void paintAt(@NotNull Graphics g, int x, int y, int width, Caret caret) {
int lineHeight = getLineHeight();
Rectangle viewRectangle = getScrollingModel().getVisibleArea();
if (x - viewRectangle.x < 0) {
return;
}
g.setColor(myScheme.getColor(EditorColors.CARET_COLOR));
Graphics2D originalG = IdeBackgroundUtil.getOriginalGraphics(g);
if (!paintBlockCaret()) {
if (UIUtil.isRetina()) {
originalG.fillRect(x, y, mySettings.getLineCursorWidth(), lineHeight);
}
else {
for (int i = 0; i < mySettings.getLineCursorWidth(); i++) {
UIUtil.drawLine(g, x + i, y, x + i, y + lineHeight - 1);
}
}
}
else {
Color caretColor = myScheme.getColor(EditorColors.CARET_COLOR);
if (caretColor == null) caretColor = new JBColor(Gray._0, Gray._255);
g.setColor(caretColor);
originalG.fillRect(x, y, width, lineHeight - 1);
final LogicalPosition startPosition = caret == null ? getCaretModel().getLogicalPosition() : caret.getLogicalPosition();
final int offset = logicalPositionToOffset(startPosition);
CharSequence chars = myDocument.getImmutableCharSequence();
if (chars.length() > offset && myDocument.getTextLength() > offset) {
FoldRegion folding = myFoldingModel.getCollapsedRegionAtOffset(offset);
final char ch;
if (folding == null || folding.isExpanded()) {
ch = chars.charAt(offset);
}
else {
VisualPosition visual = caret == null ? getCaretModel().getVisualPosition() : caret.getVisualPosition();
VisualPosition foldingPosition = offsetToVisualPosition(folding.getStartOffset());
if (visual.line == foldingPosition.line) {
ch = folding.getPlaceholderText().charAt(visual.column - foldingPosition.column);
}
else {
ch = chars.charAt(offset);
}
}
//don't worry it's cheap. Cache is not required
IterationState state = new IterationState(EditorImpl.this, offset, offset + 1, true);
TextAttributes attributes = state.getMergedAttributes();
FontInfo info = EditorUtil.fontForChar(ch, attributes.getFontType(), EditorImpl.this);
if (info != null) {
g.setFont(info.getFont());
}
//todo[kb]
//in case of italic style we paint out of the cursor block. Painting the symbol to a dedicated buffered image
//solves the problem, but still looks weird because it leaves colored pixels at right.
g.setColor(ColorUtil.isDark(caretColor) ? CURSOR_FOREGROUND_LIGHT : CURSOR_FOREGROUND_DARK);
g.drawChars(new char[]{ch}, 0, 1, x, y + getAscent());
}
}
}
示例7: paintImmediately
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
private void paintImmediately(Graphics g, int offset, char c, boolean insert) {
if (g == null) return; // editor component is currently not displayable
TextAttributes attributes = ((LexerEditorHighlighter)getHighlighter()).getAttributes((DocumentImpl)getDocument(), offset, c);
int fontType = attributes.getFontType();
FontInfo fontInfo = EditorUtil.fontForChar(c, attributes.getFontType(), myEditor);
Font font = fontInfo.getFont();
// it's more reliable to query actual font metrics
FontMetrics fontMetrics = myEditor.getFontMetrics(fontType);
int charWidth = fontMetrics.charWidth(c);
int delta = charWidth;
if (!insert && offset < getDocument().getTextLength()) {
delta -= fontMetrics.charWidth(getDocument().getCharsSequence().charAt(offset));
}
Rectangle tailArea = lineRectangleBetween(offset, getDocument().getLineEndOffset(myEditor.offsetToLogicalLine(offset)));
if (tailArea.isEmpty()) {
tailArea.width += EditorUtil.getSpaceWidth(fontType, myEditor); // include caret
}
Color background = attributes.getBackgroundColor() == null ? getCaretRowBackground() : attributes.getBackgroundColor();
Rectangle newArea = lineRectangleBetween(offset, offset);
newArea.width += charWidth;
String newText = Character.toString(c);
Point point = newArea.getLocation();
int ascent = myEditor.getAscent();
Color foreground = attributes.getForegroundColor() == null ? myEditor.getForegroundColor() : attributes.getForegroundColor();
EditorUIUtil.setupAntialiasing(g);
// pre-compute all the arguments beforehand to minimize delays between the calls (as there's no double-buffering)
if (delta != 0) {
shift(g, tailArea, delta);
}
fill(g, newArea, background);
print(g, newText, point, ascent, font, foreground);
// flush changes (there can be batching / buffering in video driver)
Toolkit.getDefaultToolkit().sync();
if (isZeroLatencyTypingDebugEnabled()) {
pause();
}
}
示例8: paintAt
import com.intellij.openapi.editor.ex.util.EditorUtil; //导入方法依赖的package包/类
void paintAt(@NotNull Graphics g, int x, int y, int width, Caret caret) {
int lineHeight = getLineHeight();
Rectangle viewRectangle = getScrollingModel().getVisibleArea();
if (x - viewRectangle.x < 0) {
return;
}
g.setColor(myScheme.getColor(EditorColors.CARET_COLOR));
Graphics2D originalG = IdeBackgroundUtil.getOriginalGraphics(g);
if (!paintBlockCaret()) {
if (UIUtil.isRetina()) {
originalG.fillRect(x, y, mySettings.getLineCursorWidth(), lineHeight);
}
else {
g.fillRect(x, y, JBUI.scale(mySettings.getLineCursorWidth()), lineHeight);
}
}
else {
Color caretColor = myScheme.getColor(EditorColors.CARET_COLOR);
if (caretColor == null) caretColor = new JBColor(Gray._0, Gray._255);
g.setColor(caretColor);
originalG.fillRect(x, y, width, lineHeight - 1);
final LogicalPosition startPosition = caret == null ? getCaretModel().getLogicalPosition() : caret.getLogicalPosition();
final int offset = logicalPositionToOffset(startPosition);
CharSequence chars = myDocument.getImmutableCharSequence();
if (chars.length() > offset && myDocument.getTextLength() > offset) {
FoldRegion folding = myFoldingModel.getCollapsedRegionAtOffset(offset);
final char ch;
if (folding == null || folding.isExpanded()) {
ch = chars.charAt(offset);
}
else {
VisualPosition visual = caret == null ? getCaretModel().getVisualPosition() : caret.getVisualPosition();
VisualPosition foldingPosition = offsetToVisualPosition(folding.getStartOffset());
if (visual.line == foldingPosition.line) {
ch = folding.getPlaceholderText().charAt(visual.column - foldingPosition.column);
}
else {
ch = chars.charAt(offset);
}
}
//don't worry it's cheap. Cache is not required
IterationState state = new IterationState(EditorImpl.this, offset, offset + 1, true);
TextAttributes attributes = state.getMergedAttributes();
FontInfo info = EditorUtil.fontForChar(ch, attributes.getFontType(), EditorImpl.this);
g.setFont(info.getFont());
//todo[kb]
//in case of italic style we paint out of the cursor block. Painting the symbol to a dedicated buffered image
//solves the problem, but still looks weird because it leaves colored pixels at right.
g.setColor(ColorUtil.isDark(caretColor) ? CURSOR_FOREGROUND_LIGHT : CURSOR_FOREGROUND_DARK);
g.drawChars(new char[]{ch}, 0, 1, x, y + getAscent());
}
}
}