use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.
the class OutlineTextRenderer method drawString.
public void drawString(SunGraphics2D g2d, String str, double x, double y) {
if ("".equals(str)) {
// TextLayout constructor throws IAE on "".
return;
}
TextLayout tl = new TextLayout(str, g2d.getFont(), g2d.getFontRenderContext());
Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
int textAAHint = g2d.getFontInfo().aaHint;
int prevaaHint = -1;
if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
g2d.validatePipe();
} else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF && g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
g2d.validatePipe();
}
g2d.fill(s);
if (prevaaHint != -1) {
g2d.antialiasHint = prevaaHint;
g2d.validatePipe();
}
}
use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.
the class GlyphListPipe method drawChars.
public void drawChars(SunGraphics2D sg2d, char[] data, int offset, int length, int ix, int iy) {
FontInfo info = sg2d.getFontInfo();
float x, y;
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
SurfaceData.outlineTextRenderer.drawChars(sg2d, data, offset, length, ix, iy);
return;
}
if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
double[] origin = { ix + info.originX, iy + info.originY };
sg2d.transform.transform(origin, 0, origin, 0, 1);
x = (float) origin[0];
y = (float) origin[1];
} else {
x = ix + info.originX + sg2d.transX;
y = iy + info.originY + sg2d.transY;
}
GlyphList gl = GlyphList.getInstance();
if (gl.setFromChars(info, data, offset, length, x, y)) {
drawGlyphList(sg2d, gl);
gl.dispose();
} else {
// release this asap.
gl.dispose();
TextLayout tl = new TextLayout(new String(data, offset, length), sg2d.getFont(), sg2d.getFontRenderContext());
tl.draw(sg2d, ix, iy);
}
}
use of java.awt.font.TextLayout in project chipKIT32-MAX by chipKIT32.
the class CompositionTextManager method getTextLayout.
private TextLayout getTextLayout(AttributedCharacterIterator text, int committed_count) {
AttributedString composed = new AttributedString(text, committed_count, text.getEndIndex());
Font font = textArea.getPainter().getFont();
FontRenderContext context = ((Graphics2D) (textArea.getPainter().getGraphics())).getFontRenderContext();
composed.addAttribute(TextAttribute.FONT, font);
TextLayout layout = new TextLayout(composed.getIterator(), context);
return layout;
}
use of java.awt.font.TextLayout in project OpenNotebook by jaltekruse.
the class AnswerBoxGUI method drawMathObject.
public void drawMathObject(AnswerBoxObject object, Graphics g, Point pageOrigin, float zoomLevel) {
ScaledSizeAndPosition sap = getSizeAndPositionWithFontSize(object, pageOrigin, zoomLevel, object.getFontSize());
// TODO - decide how extra whitespace should be handled, should it always be stored?
// students may use it to format a multi-line answer
// although useful whitespace will likely not coming at the very beginning or very end
// of an answer
List<? extends MathObjectAttribute> correctAnswers = object.getListWithName(AnswerBoxObject.CORRECT_ANSWERS).getValues();
if (!object.getStudentAnswer().trim().equals("") || !correctAnswers.isEmpty()) {
Font f = g.getFont();
g.setColor(new Color(150, 210, 255));
g.fillRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
String message = object.getStudentAnswer();
for (MathObjectAttribute mAtt : correctAnswers) {
message += mAtt.getValue().toString() + ";";
}
message = message.substring(0, message.length() - 1);
if (message.isEmpty()) {
// cannot have an empty string in AttributedString
message = " ";
}
g.setFont(f.deriveFont(sap.getFontSize()));
g.setColor(Color.BLACK);
Graphics2D graphics2D = (Graphics2D) g;
GraphicsEnvironment.getLocalGraphicsEnvironment();
AttributedString messageAS = new AttributedString(message);
messageAS.addAttribute(TextAttribute.FONT, g.getFont());
AttributedCharacterIterator messageIterator = messageAS.getIterator();
FontRenderContext messageFRC = graphics2D.getFontRenderContext();
LineBreakMeasurer messageLBM = new LineBreakMeasurer(messageIterator, messageFRC);
Insets insets = new Insets(2, 2, 2, 2);
float wrappingWidth = sap.getWidth() - insets.left - insets.right;
float x = sap.getxOrigin() + insets.left;
float y = sap.getyOrigin() + insets.top;
while (messageLBM.getPosition() < messageIterator.getEndIndex()) {
TextLayout textLayout = messageLBM.nextLayout(wrappingWidth);
y += textLayout.getAscent();
textLayout.draw(graphics2D, x, y);
y += textLayout.getDescent() + textLayout.getLeading();
x = sap.getxOrigin() + insets.left;
}
g.setFont(f);
} else {
g.setColor(new Color(230, 230, 230));
g.fillRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
}
g.setColor(Color.BLACK);
g.drawRect(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), sap.getHeight());
}
use of java.awt.font.TextLayout in project binnavi by google.
the class ZyCaret method calcCaretPosition.
private int calcCaretPosition(final int hitLine, final double x, final double y) {
final ZyLineContent content = m_content.getLineContent(hitLine);
final TextLayout textlayout = m_content.getLineContent(hitLine).getTextLayout();
final TextHitInfo hitInfo = textlayout.hitTestChar((float) x, (float) y, content.getBounds());
return hitInfo.getInsertionIndex();
}
Aggregations