本文整理汇总了Java中java.awt.font.LineMetrics类的典型用法代码示例。如果您正苦于以下问题:Java LineMetrics类的具体用法?Java LineMetrics怎么用?Java LineMetrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LineMetrics类属于java.awt.font包,在下文中一共展示了LineMetrics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showTextOnStream
import java.awt.font.LineMetrics; //导入依赖的package包/类
private void showTextOnStream(IFontTextDrawerEnv env, PDPageContentStream contentStream, Font attributeFont,
PDFont font, boolean isStrikeThrough, boolean isUnderline, boolean isLigatures, String text)
throws IOException {
if (isStrikeThrough || isUnderline) {
// noinspection unused
float stringWidth = font.getStringWidth(text);
// noinspection unused
LineMetrics lineMetrics = attributeFont.getLineMetrics(text, env.getFontRenderContext());
/*
* TODO: We can not draw that yet, we must do that later. While in textmode its
* not possible to draw lines...
*/
}
// noinspection StatementWithEmptyBody
if (isLigatures) {
/*
* No idea how to map this ...
*/
}
contentStream.showText(text);
}
示例2: paintComponent
import java.awt.font.LineMetrics; //导入依赖的package包/类
public void paintComponent(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, fpd.width, fpd.height);
g.setColor(Color.RED);
FontRenderContext frc = ((Graphics2D)g).getFontRenderContext();
LineMetrics lm = f.getLineMetrics(fps, frc);
int h = (int)(fpd.height - 20 - lm.getAscent());
g.drawLine(20, h, fpd.width - 20, h);
h = fpd.height - 20;
g.drawLine(20, h, fpd.width - 20, h);
h = (int)(fpd.height - 20 + lm.getDescent());
g.drawLine(20, h, fpd.width - 20, h);
g.setColor(Color.BLACK);
g.setFont(f);
g.drawString(fps, 50, fpd.height - 20);
}
示例3: paintToRect
import java.awt.font.LineMetrics; //导入依赖的package包/类
public void paintToRect(Graphics2D g2d, int x, int y, int w, int h) {
g2d = createGraphics(g2d,x,y,w,h);
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font font = g2d.getFont();
FontMetrics fm = g2d.getFontMetrics();
FontRenderContext frc = g2d.getFontRenderContext();
LineMetrics lm = font.getLineMetrics(text,frc);
//int fh = round(lm.getHeight());
//int fa = round(lm.getAscent());
int fd = round(lm.getDescent());
int wt = fm.stringWidth(text);
int xt = max(0,(w-wt)/2);
int yt = h-1-2*fd;
g2d.drawString(text,xt,yt);
g2d.dispose();
}
示例4: getLogicalBounds
import java.awt.font.LineMetrics; //导入依赖的package包/类
public Rectangle2D getLogicalBounds() {
setFRCTX();
initPositions();
LineMetrics lm = font.getLineMetrics("", frc);
float minX, minY, maxX, maxY;
// horiz only for now...
minX = 0;
minY = -lm.getAscent();
maxX = 0;
maxY = lm.getDescent() + lm.getLeading();
if (glyphs.length > 0) {
maxX = positions[positions.length - 2];
}
return new Rectangle2D.Float(minX, minY, maxX - minX, maxY - minY);
}
示例5: getLogicalBounds
import java.awt.font.LineMetrics; //导入依赖的package包/类
@Override
public Rectangle2D getLogicalBounds() {
initPositions();
LineMetrics lm = font.getLineMetrics("", frc);
float minX, minY, maxX, maxY;
// horiz only for now...
minX = 0;
minY = -lm.getAscent();
maxX = 0;
maxY = lm.getDescent() + lm.getLeading();
if (glyphs.length() > 0) {
maxX = positions[positions.length - 2];
}
return new Rectangle2D.Float(minX, minY, maxX - minX, maxY - minY);
}
示例6: createImageWithOverlay
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* Add overlay text to the image and save as a .jpg file.
*
* @param image a java.awt.Image to add the text overlay to
* @param overlayText The text to overlay onto the image
* @return
*/
public static BufferedImage createImageWithOverlay(final Image image, final String[] overlayText) {
// Copy BufferedImage and set .jpg file name
final BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.drawImage(image, 0, 0, null);
final Font font = new Font("Monospaced", Font.PLAIN, 14);
g.setFont(font);
g.setColor(Color.CYAN);
final FontRenderContext frc = g.getFontRenderContext();
int x = 1;
int n = 1;
for (String s : overlayText) {
LineMetrics lineMetrics = font.getLineMetrics(s, frc);
float y = (lineMetrics.getHeight() + 1) * n + lineMetrics.getHeight();
g.drawString(s, x, y);
n++;
}
g.dispose();
return bi;
}
示例7: drawStringInRect
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* A utility method that draws a string inside a rectangle.
*
* @param g2 the graphics device.
* @param bounds the rectangle.
* @param font the font.
* @param text the text.
*/
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
String text) {
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics(font);
Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
double x = bounds.getX();
if (r.getWidth() < bounds.getWidth()) {
x = x + (bounds.getWidth() - r.getWidth()) / 2;
}
LineMetrics metrics = font.getLineMetrics(text, g2.getFontRenderContext());
g2.drawString(
text,
(float) x, (float) (bounds.getMaxY() - this.bottomInnerGap - metrics.getDescent())
);
}
示例8: drawStringInRect
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* A utility method that draws a string inside a rectangle.
*
* @param g2 the graphics device.
* @param bounds the rectangle.
* @param font the font.
* @param text the text.
*/
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
String text) {
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics(font);
Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
double x = bounds.getX();
if (r.getWidth() < bounds.getWidth()) {
x = x + (bounds.getWidth() - r.getWidth()) / 2;
}
LineMetrics metrics = font.getLineMetrics(
text, g2.getFontRenderContext()
);
g2.drawString(
text, (float) x, (float) (bounds.getMaxY()
- this.bottomInnerGap - metrics.getDescent())
);
}
示例9: toString
import java.awt.font.LineMetrics; //导入依赖的package包/类
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("{text=");
for (int i = 0; i < length(); i++) {
buf.append(aStrings[i].getIterator().current());
}
final String RS = "\n\t";
buf.append(RS);
for (int i = 0; i < length(); i++) {
buf.append(bounds[i].toString());
final String FS = " ";
final LineMetrics m = metrics[i];
// height = ascent + descent + leading
buf.append(" ascent=").append(m.getAscent()).append(FS);
buf.append("descent=").append(m.getDescent()).append(FS);
buf.append("leading=").append(m.getLeading()).append(FS);
buf.append(RS);
}
buf.append("}");
return buf.toString();
}
示例10: finishInit
import java.awt.font.LineMetrics; //导入依赖的package包/类
private void finishInit() {
font = source.getFont();
Map<TextAttribute, ?> atts = font.getAttributes();
baseTX = AttributeValues.getBaselineTransform(atts);
if (baseTX == null){
cm = source.getCoreMetrics();
} else {
AffineTransform charTX = AttributeValues.getCharTransform(atts);
if (charTX == null) {
charTX = new AffineTransform();
}
font = font.deriveFont(charTX);
LineMetrics lm = font.getLineMetrics(source.getChars(), source.getStart(),
source.getStart() + source.getLength(), source.getFRC());
cm = CoreMetrics.get(lm);
}
}
示例11: drawStringInRect
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* A utility method that draws a string inside a rectangle.
*
* @param g2 the graphics device.
* @param bounds the rectangle.
* @param font the font.
* @param text the text.
*/
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
String text) {
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics(font);
Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
double x = bounds.getX();
if (r.getWidth() < bounds.getWidth()) {
x = x + (bounds.getWidth() - r.getWidth()) / 2;
}
LineMetrics metrics = font.getLineMetrics(
text, g2.getFontRenderContext()
);
g2.drawString(
text, (float) x, (float) (bounds.getMaxY()
- this.bottomInnerGap - metrics.getDescent())
);
}
示例12: calculateBaselineOffset
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* Calculates the vertical offset between the baseline and the specified
* text anchor.
*
* @param g2 the graphics device.
* @param anchor the anchor.
*
* @return the offset.
*/
public float calculateBaselineOffset(Graphics2D g2, TextAnchor anchor) {
float result = 0.0f;
final FontMetrics fm = g2.getFontMetrics(this.font);
final LineMetrics lm = fm.getLineMetrics("ABCxyz", g2);
if (anchor.isTop()) {
result = lm.getAscent();
}
else if (anchor.isHalfAscent()) {
result = lm.getAscent() / 2.0f;
}
else if (anchor.isVerticalCenter()) {
result = lm.getAscent() / 2.0f - lm.getDescent() / 2.0f;
}
else if (anchor.isBottom()) {
result = -lm.getDescent() - lm.getLeading();
}
return result;
}
示例13: getTextBounds
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* Returns the bounds for the specified text.
*
* @param text the text (<code>null</code> permitted).
* @param g2 the graphics context (not <code>null</code>).
* @param fm the font metrics (not <code>null</code>).
*
* @return The text bounds (<code>null</code> if the <code>text</code>
* argument is <code>null</code>).
*/
public static Rectangle2D getTextBounds(String text, Graphics2D g2,
FontMetrics fm) {
Rectangle2D bounds;
if (TextUtilities.useFontMetricsGetStringBounds) {
bounds = fm.getStringBounds(text, g2);
// getStringBounds() can return incorrect height for some Unicode
// characters...see bug parade 6183356, let's replace it with
// something correct
LineMetrics lm = fm.getFont().getLineMetrics(text,
g2.getFontRenderContext());
bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(),
lm.getHeight());
}
else {
double width = fm.stringWidth(text);
double height = fm.getHeight();
if (logger.isDebugEnabled()) {
logger.debug("Height = " + height);
}
bounds = new Rectangle2D.Double(0.0, -fm.getAscent(), width,
height);
}
return bounds;
}
示例14: drawHeaderOrFooterLine
import java.awt.font.LineMetrics; //导入依赖的package包/类
private double drawHeaderOrFooterLine(Graphics2D g, double x, double y, double w, String headerText,
String alignment) {
FontRenderContext fontRenderContext = g.getFontRenderContext();
LineMetrics lineMetrics = getHeaderFooterLineMetrics(g);
float lineHeight = lineMetrics.getHeight();
if (myPerformActualDrawing) {
headerText = convertHeaderText(headerText);
g.setFont(myHeaderFont);
g.setColor(Color.black);
float descent = lineMetrics.getDescent();
double width = myHeaderFont.getStringBounds(headerText, fontRenderContext).getWidth() + getCharWidth(g);
float yPos = (float) (lineHeight - descent + y);
if (PrintSettings.LEFT.equals(alignment)) {
drawStringToGraphics(g, headerText, x, yPos);
} else if (PrintSettings.CENTER.equals(alignment)) {
drawStringToGraphics(g, headerText, (float) (x + (w - width) / 2), yPos);
} else if (PrintSettings.RIGHT.equals(alignment)) {
drawStringToGraphics(g, headerText, (float) (x + w - width), yPos);
}
}
return lineHeight;
}
示例15: getTextBounds
import java.awt.font.LineMetrics; //导入依赖的package包/类
/**
* Returns the bounds for the specified text.
*
* @param text the text ({@code null} permitted).
* @param g2 the graphics context (not {@code null}).
* @param fm the font metrics (not {@code null}).
*
* @return The text bounds ({@code null} if the {@code text}
* argument is {@code null}).
*/
public static Rectangle2D getTextBounds(String text, Graphics2D g2,
FontMetrics fm) {
Rectangle2D bounds;
if (TextUtils.useFontMetricsGetStringBounds) {
bounds = fm.getStringBounds(text, g2);
// getStringBounds() can return incorrect height for some Unicode
// characters...see bug parade 6183356, let's replace it with
// something correct
LineMetrics lm = fm.getFont().getLineMetrics(text,
g2.getFontRenderContext());
bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(),
lm.getHeight());
}
else {
double width = fm.stringWidth(text);
double height = fm.getHeight();
bounds = new Rectangle2D.Double(0.0, -fm.getAscent(), width,
height);
}
return bounds;
}