use of java.awt.font.FontRenderContext in project poi by apache.
the class DrawTextParagraph method tab2space.
/**
* Replace a tab with the effective number of white spaces.
*/
private String tab2space(TextRun tr) {
AttributedString string = new AttributedString(" ");
String fontFamily = tr.getFontFamily();
if (fontFamily == null) {
fontFamily = "Lucida Sans";
}
string.addAttribute(TextAttribute.FAMILY, fontFamily);
Double fs = tr.getFontSize();
if (fs == null) {
fs = 12d;
}
string.addAttribute(TextAttribute.SIZE, fs.floatValue());
TextLayout l = new TextLayout(string.getIterator(), new FontRenderContext(null, true, true));
double wspace = l.getAdvance();
Double tabSz = paragraph.getDefaultTabSize();
if (tabSz == null) {
tabSz = wspace * 4;
}
int numSpaces = (int) Math.ceil(tabSz / wspace);
StringBuilder buf = new StringBuilder();
for (int i = 0; i < numSpaces; i++) {
buf.append(' ');
}
return buf.toString();
}
use of java.awt.font.FontRenderContext in project android_frameworks_base by crdroidandroid.
the class BidiRenderer method render.
/**
* Renders the text to the right of the bounds with the given font.
* @param font The font to render the text with.
*/
private void render(int start, int limit, Font font, int flag, float[] advances, int advancesIndex, boolean draw) {
FontRenderContext frc;
if (mGraphics != null) {
frc = mGraphics.getFontRenderContext();
} else {
frc = Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
// Metrics obtained this way don't have anti-aliasing set. So,
// we create a new FontRenderContext with anti-aliasing set.
frc = new FontRenderContext(font.getTransform(), mPaint.isAntiAliased(), frc.usesFractionalMetrics());
}
GlyphVector gv = font.layoutGlyphVector(frc, mText, start, limit, flag);
int ng = gv.getNumGlyphs();
int[] ci = gv.getGlyphCharIndices(0, ng, null);
if (advances != null) {
for (int i = 0; i < ng; i++) {
int adv_idx = advancesIndex + ci[i];
advances[adv_idx] += gv.getGlyphMetrics(i).getAdvanceX();
}
}
if (draw && mGraphics != null) {
mGraphics.drawGlyphVector(gv, mBounds.right, mBaseline);
}
// Update the bounds.
Rectangle2D awtBounds = gv.getLogicalBounds();
RectF bounds = awtRectToAndroidRect(awtBounds, mBounds.right, mBaseline);
// coordinates from the bounds as an offset.
if (Math.abs(mBounds.right - mBounds.left) == 0) {
mBounds = bounds;
} else {
mBounds.union(bounds);
}
}
use of java.awt.font.FontRenderContext in project vcell by virtualcell.
the class ShapePaintUtil method paintLinkMark.
public static void paintLinkMark(Graphics2D g, Shape shape, Color color) {
Font fontOld = g.getFont();
Color colorOld = g.getColor();
Font font = fontOld.deriveFont((float) (shape.getHeight() / 2)).deriveFont(Font.BOLD);
g.setFont(font);
g.setColor(color);
FontRenderContext fontRenderContext = g.getFontRenderContext();
String text = "L";
TextLayout textLayout = new TextLayout(text, font, fontRenderContext);
Rectangle2D textBounds = textLayout.getBounds();
int xText = (int) (shape.getAbsX() + (shape.getWidth() - textBounds.getWidth()) / 2);
int yText = (int) (shape.getAbsY() + (shape.getHeight() + textBounds.getHeight()) / 2 + 1);
textLayout.draw(g, xText, yText);
g.setFont(fontOld);
g.setColor(colorOld);
}
use of java.awt.font.FontRenderContext in project vcell by virtualcell.
the class ShapePaintUtil method paintLinkMarkRule.
public static void paintLinkMarkRule(Graphics2D g, Shape shape, Color color) {
Font fontOld = g.getFont();
Color colorOld = g.getColor();
Font font = fontOld.deriveFont((float) (shape.getHeight() / 2)).deriveFont(Font.BOLD);
g.setFont(font);
g.setColor(color);
FontRenderContext fontRenderContext = g.getFontRenderContext();
String text = "L";
TextLayout textLayout = new TextLayout(text, font, fontRenderContext);
Rectangle2D textBounds = textLayout.getBounds();
int xText = (int) (shape.getAbsX() + (shape.getWidth() + 4 - textBounds.getWidth()) / 2 - 1);
int yText = (int) (shape.getAbsY() + (shape.getHeight() - 2 + textBounds.getHeight()) / 2 + 1);
textLayout.draw(g, xText, yText);
g.setFont(fontOld);
g.setColor(colorOld);
}
Aggregations