use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.
the class LineLayout method createFragments.
private static List<BidiRun> createFragments(@NotNull EditorView view, @NotNull CharSequence text, @JdkConstants.FontStyle int fontStyle) {
if (text.length() == 0)
return Collections.emptyList();
FontRenderContext fontRenderContext = view.getFontRenderContext();
FontPreferences fontPreferences = view.getEditor().getColorsScheme().getFontPreferences();
char[] chars = CharArrayUtil.fromSequence(text);
List<BidiRun> runs = createRuns(view, chars, -1);
for (BidiRun run : runs) {
for (Chunk chunk : run.getChunks(text, 0)) {
chunk.fragments = new ArrayList<>();
addFragments(run, chunk, chars, chunk.startOffset, chunk.endOffset, fontStyle, fontPreferences, fontRenderContext, null);
}
}
return runs;
}
use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.
the class ComplexTextFragmentTest method assertCaretPositionsForGlyphVector.
private static void assertCaretPositionsForGlyphVector(MyGlyphVector gv, int... expectedPositions) {
FontLayoutService.setInstance(new MockFontLayoutService(TEST_CHAR_WIDTH, TEST_LINE_HEIGHT, TEST_DESCENT) {
@NotNull
@Override
public GlyphVector layoutGlyphVector(@NotNull Font font, @NotNull FontRenderContext fontRenderContext, @NotNull char[] chars, int start, int end, boolean isRtl) {
return gv;
}
});
try {
int length = gv.getNumChars();
char[] text = new char[length];
FontInfo fontInfo = new FontInfo(Font.MONOSPACED, 1, Font.PLAIN, false, new FontRenderContext(null, false, false));
ComplexTextFragment fragment = new ComplexTextFragment(text, 0, length, (gv.getLayoutFlags() & GlyphVector.FLAG_RUN_RTL) != 0, fontInfo);
int[] charPositions = new int[length];
for (int i = 0; i < length; i++) {
charPositions[i] = (int) fragment.visualColumnToX(0, i + 1);
}
assertArrayEquals(expectedPositions, charPositions);
} finally {
FontLayoutService.setInstance(null);
}
}
use of java.awt.font.FontRenderContext in project intellij-community by JetBrains.
the class UIUtil method getHighestGlyphHeight.
/**
* @param string {@code String} to examine
* @param font {@code Font} that is used to render the string
* @param graphics {@link Graphics} that should be used to render the string
* @return height of the tallest glyph in a string. If string is empty, returns 0
*/
public static int getHighestGlyphHeight(@NotNull String string, @NotNull Font font, @NotNull Graphics graphics) {
FontRenderContext frc = ((Graphics2D) graphics).getFontRenderContext();
GlyphVector gv = font.createGlyphVector(frc, string);
int maxHeight = 0;
for (int i = 0; i < string.length(); i++) {
maxHeight = Math.max(maxHeight, (int) gv.getGlyphMetrics(i).getBounds2D().getHeight());
}
return maxHeight;
}
use of java.awt.font.FontRenderContext in project android by JetBrains.
the class BlueprintLayer method drawComponent.
/**
* Draw the given component and its children
*
* @param gc the graphics context
* @param component the component we want to draw
* @param viewHandlerManager the view handler
*/
private boolean drawComponent(@NotNull Graphics2D gc, @NotNull NlComponent component, @NotNull ViewHandlerManager viewHandlerManager, boolean parentHandlesPainting) {
boolean needsRepaint = false;
boolean handlesPainting = false;
if (component.viewInfo != null) {
ViewHandler handler = component.getViewHandler();
// Check if the view handler handles the painting
if (handler != null && handler instanceof ViewGroupHandler) {
ViewGroupHandler viewGroupHandler = (ViewGroupHandler) handler;
if (viewGroupHandler.handlesPainting()) {
if (handler.paintConstraints(myScreenView, gc, component)) {
return needsRepaint;
}
needsRepaint |= viewGroupHandler.drawGroup(gc, myScreenView, component);
handlesPainting = true;
}
}
if (!handlesPainting && !parentHandlesPainting) {
// If not, layout the component ourselves
Graphics2D g = (Graphics2D) gc.create();
int x = getSwingX(myScreenView, component.x);
int y = getSwingY(myScreenView, component.y);
int w = getSwingDimension(myScreenView, component.w);
int h = getSwingDimension(myScreenView, component.h);
drawComponentBackground(g, component);
String name = component.getTagName();
name = name.substring(name.lastIndexOf('.') + 1);
Font font = BLUEPRINT_TEXT_FONT;
g.setFont(font);
g.setColor(BLUEPRINT_FG_COLOR);
String id = component.getId();
int lineHeight = g.getFontMetrics().getHeight();
FontRenderContext fontRenderContext = g.getFontRenderContext();
if (id != null && h > lineHeight * 2) {
// Can fit both
Rectangle2D classBounds = font.getStringBounds(name, fontRenderContext);
Rectangle2D idBounds = font.getStringBounds(id, fontRenderContext);
int textY = y + h / 2;
int textX = x + w / 2 - ((int) classBounds.getWidth()) / 2;
if (component.isRoot()) {
textX = x + lineHeight;
textY = y - (int) (classBounds.getHeight() + idBounds.getHeight());
}
g.drawString(name, textX, textY);
if (component.isRoot()) {
textX = x + lineHeight;
textY = y - (int) (idBounds.getHeight());
} else {
textX = x + w / 2 - ((int) idBounds.getWidth()) / 2;
textY += (int) (idBounds.getHeight());
}
g.drawString(id, textX, textY);
} else {
// Only room for a single line: prioritize the id if it's available, otherwise the class name
String text = id != null ? id : name;
Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext);
int textX = x + w / 2 - ((int) stringBounds.getWidth()) / 2;
int textY = y + h / 2 + ((int) stringBounds.getHeight()) / 2;
g.drawString(text, textX, textY);
}
g.dispose();
}
}
// Draw the children of the component...
for (NlComponent child : component.getChildren()) {
needsRepaint |= drawComponent(gc, child, viewHandlerManager, handlesPainting);
}
return needsRepaint;
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class FontDesignMetrics method readObject.
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
if (serVersion != CURRENT_VERSION) {
frc = getDefaultFrc();
isAntiAliased = frc.isAntiAliased();
usesFractionalMetrics = frc.usesFractionalMetrics();
frcTx = frc.getTransform();
} else {
frc = new FontRenderContext(frcTx, isAntiAliased, usesFractionalMetrics);
}
// when deserialized, members are set to their default values for their type--
// not to the values assigned during initialization before the constructor
// body!
height = -1;
cache = null;
initMatrixAndMetrics();
initAdvCache();
}
Aggregations