use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class MissingCodePointLayoutTest method main.
public static void main(String[] args) {
Font font = new Font("Tahoma", Font.PLAIN, 12);
String text = "�";
FontRenderContext frc = new FontRenderContext(null, false, false);
TextLayout layout = new TextLayout(text, font, frc);
layout.getCaretShapes(0);
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class HelvLtOblTest method drawText.
BufferedImage drawText(boolean doGV) {
int w = 400;
int h = 50;
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
g.setColor(Color.black);
Font f = helvFont.deriveFont(Font.PLAIN, 40);
g.setFont(f);
int x = 5;
int y = h - 10;
if (doGV) {
FontRenderContext frc = new FontRenderContext(null, true, true);
GlyphVector gv = f.createGlyphVector(frc, codes);
g.drawGlyphVector(gv, 5, y);
} else {
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.drawString(str, x, y);
}
return bi;
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class StyledSpaceAdvance method test.
static void test(int sz) {
Font reg = new Font(name, Font.PLAIN, sz);
Font bold = new Font(name, Font.BOLD, sz);
//System.out.println("reg="+reg);
//System.out.println("bold="+bold);
FontRenderContext frc = new FontRenderContext(null, false, false);
if (reg.getFontName(Locale.ENGLISH).equals(name) && bold.getFontName(Locale.ENGLISH).equals(name)) {
Rectangle2D rb = reg.getStringBounds(" ", frc);
Rectangle2D bb = bold.getStringBounds(" ", frc);
if (bb.getWidth() > rb.getWidth() + 1.01f) {
System.err.println("reg=" + reg + " bds = " + rb);
System.err.println("bold=" + bold + " bds = " + bb);
throw new RuntimeException("Advance difference too great.");
}
} else {
System.out.println("Skipping test because fonts aren't as expected");
}
}
use of java.awt.font.FontRenderContext in project jdk8u_jdk by JetBrains.
the class ClassCastExceptionForInvalidSurface method main.
public static void main(final String[] args) throws InterruptedException {
// Catch all uncaught exceptions and treat them as test failure
Thread.setDefaultUncaughtExceptionHandler((t, e) -> failed = e);
// Data for rendering
BufferedImage bi = new BufferedImage(10, 10, TYPE_INT_ARGB);
FontRenderContext frc = new FontRenderContext(null, false, false);
Font font = new Font("Serif", Font.PLAIN, 12);
GlyphVector gv = font.createGlyphVector(frc, new char[] { 'a', '1' });
Thread t1 = new Thread(() -> {
while (!isComplete()) {
vi = gc.createCompatibleVolatileImage(10, 10);
if (!list.offer(vi)) {
vi.flush();
}
}
list.forEach(Image::flush);
});
Thread t2 = new Thread(() -> {
while (!isComplete()) {
VolatileImage vi = list.poll();
if (vi != null) {
vi.flush();
}
}
});
Thread t3 = new Thread(() -> {
while (!isComplete()) {
vi.createGraphics().drawImage(bi, 1, 1, null);
}
});
Thread t4 = new Thread(() -> {
while (!isComplete()) {
vi.createGraphics().drawGlyphVector(gv, 0, 0);
vi.createGraphics().drawOval(0, 0, 10, 10);
vi.createGraphics().drawLine(0, 0, 10, 10);
vi.createGraphics().drawString("123", 1, 1);
vi.createGraphics().draw(new Rectangle(0, 0, 10, 10));
vi.createGraphics().fillOval(0, 0, 10, 10);
final Graphics2D graphics = vi.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.fillPolygon(new int[] { 0, 10, 10, 0 }, new int[] { 0, 0, 10, 10 }, 4);
}
});
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();
if (failed != null) {
System.err.println("Test failed");
failed.printStackTrace();
}
}
use of java.awt.font.FontRenderContext in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method drawLabel.
public void drawLabel(String text, GraphicInfo graphicInfo, boolean centered) {
float interline = 1.0f;
// text
if (text != null && text.length() > 0) {
Paint originalPaint = g.getPaint();
Font originalFont = g.getFont();
g.setPaint(LABEL_COLOR);
g.setFont(LABEL_FONT);
int wrapWidth = 100;
int textY = (int) graphicInfo.getY();
// TODO: use drawMultilineText()
AttributedString as = new AttributedString(text);
as.addAttribute(TextAttribute.FOREGROUND, g.getPaint());
as.addAttribute(TextAttribute.FONT, g.getFont());
AttributedCharacterIterator aci = as.getIterator();
FontRenderContext frc = new FontRenderContext(null, true, false);
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
while (lbm.getPosition() < text.length()) {
TextLayout tl = lbm.nextLayout(wrapWidth);
textY += tl.getAscent();
Rectangle2D bb = tl.getBounds();
double tX = graphicInfo.getX();
if (centered) {
tX += (int) (graphicInfo.getWidth() / 2 - bb.getWidth() / 2);
}
tl.draw(g, (float) tX, textY);
textY += tl.getDescent() + tl.getLeading() + (interline - 1.0f) * tl.getAscent();
}
// restore originals
g.setFont(originalFont);
g.setPaint(originalPaint);
}
}
Aggregations