java.awt.Graphics2D.getFont()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中java.awt.Graphics2D.getFont()方法的一些代码示例,展示了Graphics2D.getFont()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics2D.getFont()方法的具体详情如下:
包路径:java.awt.Graphics2D
类名称:Graphics2D
方法名:getFont

Graphics2D.getFont介绍

暂无

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

protected FontMetrics pickFont(Graphics2D g2, Tree tree, Dimension space) {
 Font font = g2.getFont();
 String fontName = font.getName();
 int style = font.getStyle();
 for (int size = maxFontSize; size > minFontSize; size--) {
  font = new Font(fontName, style, size);
  g2.setFont(font);
  FontMetrics fontMetrics = g2.getFontMetrics();
  if (height(tree, fontMetrics) > space.getHeight()) {
   continue;
  }
  if (width(tree, fontMetrics) > space.getWidth()) {
   continue;
  }
  //System.out.println("Chose: "+size+" for space: "+space.getWidth());
  return fontMetrics;
 }
 font = new Font(fontName, style, minFontSize);
 g2.setFont(font);
 return g2.getFontMetrics();
}

代码示例来源:origin: jphp-group/jphp

@Getter
protected Font getFont() {
  return gc.getFont();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

Font font = graphics.getFont();

代码示例来源:origin: nodebox/nodebox

public static void drawCenteredShadowText(Graphics2D g2, String s, int x, int y, Color shadowColor) {
  FontRenderContext frc = g2.getFontRenderContext();
  Rectangle2D bounds = g2.getFont().getStringBounds(s, frc);
  int leftX = (int) (x - (float) bounds.getWidth() / 2);
  drawShadowText(g2, s, leftX, y, shadowColor, 1);
}

代码示例来源:origin: stanfordnlp/CoreNLP

Font font;
if ("".equals(fontName)) {
 font = g2.getFont();
 fontName = font.getName();
 style = font.getStyle();

代码示例来源:origin: org.apache.poi/poi-ooxml

protected void drawText(XDGFShape shape) {
  XDGFText text = shape.getText();
  if (text != null) {
    if (text.getTextContent().equals("Header"))
      text.getTextBounds();
    Font oldFont = _graphics.getFont();
    _graphics.setFont(oldFont.deriveFont(shape.getFontSize()
        .floatValue()));
    _graphics.setColor(shape.getFontColor());
    text.draw(_graphics);
    _graphics.setFont(oldFont);
  }
}

代码示例来源:origin: geotools/geotools

final List<Rectangle2D> bounds = new ArrayList<Rectangle2D>();
final int length = message.length();
final Font font = graphics.getFont();
final FontRenderContext context = graphics.getFontRenderContext();
for (int i = 0; i < length; ) {

代码示例来源:origin: kiegroup/optaplanner

g.drawImage(europaBackground.getImage(), 0, 0, translator.getImageWidth(), translator.getImageHeight(), this);
g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
g.setColor(TangoColorFactory.PLUM_2);
List<Visit> visitList = tspSolution.getVisitList();
if (score != null) {
  String distanceString = tspSolution.getDistanceString(NUMBER_FORMAT);
  g.setFont(g.getFont().deriveFont(Font.BOLD, (float) TEXT_SIZE * 2));
  g.drawString(distanceString,
      (int) width - g.getFontMetrics().stringWidth(distanceString) - 10, (int) height - 15 - 2 * TEXT_SIZE);

代码示例来源:origin: org.apache.poi/poi-ooxml

@Override
protected Path2D drawPath(XDGFShape shape) {
  Path2D path = super.drawPath(shape);
  if (_debugAcceptor == null || _debugAcceptor.accept(shape)) {
    // show numbers to associate shapes with ids.. doesn't always work
    Font f = _graphics.getFont();
    _graphics.scale(1, -1);
    _graphics.setFont(f.deriveFont(0.05F));
    String shapeId = "" + shape.getID();
    float shapeOffset = -0.1F;
    if (shape.hasMasterShape()) {
      shapeId += " MS:" + shape.getMasterShape().getID();
      shapeOffset -= 0.15F;
    }
    _graphics.drawString(shapeId, shapeOffset, 0);
    _graphics.setFont(f);
    _graphics.scale(1, -1);
  }
  return path;
}

代码示例来源:origin: kiegroup/optaplanner

g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));
g.setStroke(TangoColorFactory.NORMAL_STROKE);
for (Customer customer : solution.getCustomerList()) {
    distanceString = solution.getDistanceString(NUMBER_FORMAT);
  g.setFont(g.getFont().deriveFont(Font.BOLD, (float) TEXT_SIZE * 2));
  g.drawString(distanceString,
      (int) width - g.getFontMetrics().stringWidth(distanceString) - 10, (int) height - 10 - TEXT_SIZE);

代码示例来源:origin: kiegroup/optaplanner

g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
g.setColor(TangoColorFactory.PLUM_2);
for (Airport airport : solution.getAirportList()) {
      true, false);
g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));

代码示例来源:origin: nodebox/nodebox

@Override
  protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    if (isEnabled()) {
      g2.setColor(Theme.TEXT_NORMAL_COLOR);
    } else {
      g2.setColor(Theme.TEXT_DISABLED_COLOR);
    }
    g2.setFont(Theme.SMALL_BOLD_FONT);
    int textX = Theme.LABEL_WIDTH - g2.getFontMetrics().stringWidth(getText()) - 10;
    // Add some padding to align it to 30px high components.
    int textY = (getHeight() - g2.getFont().getSize()) / 2 + 10;
    SwingUtils.drawShadowText(g2, getText(), textX, textY, Theme.DEFAULT_SHADOW_COLOR, 1);
  }
}

代码示例来源:origin: kiegroup/optaplanner

g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
List<RockShow> showList = solution.getShowList();
int maxAvailableDateSetSize = showList.stream().mapToInt(show -> show.getAvailableDateSet().size()).max().orElse(-1);
g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));

代码示例来源:origin: apache/pdfbox

@Override
public Font getFont()
{
  return groupG2D.getFont();
}

代码示例来源:origin: geotools/geotools

public Font getFont() {
  return delegate.getFont();
}

代码示例来源:origin: haraldk/TwelveMonkeys

void setTextFace(final int face) {
  int style = 0;
  if ((face & QuickDraw.TX_BOLD_MASK) > 0) {
    style |= Font.BOLD;
  }
  if ((face & QuickDraw.TX_ITALIC_MASK) > 0) {
    style |= Font.ITALIC;
  }
  // TODO: Other face options, like underline, shadow, etc...
  graphics.setFont(graphics.getFont().deriveFont(style));
}

代码示例来源:origin: haraldk/TwelveMonkeys

public void setTextSize(int pSize) {
  graphics.setFont(graphics.getFont().deriveFont((float) pSize));
}

代码示例来源:origin: kiegroup/optaplanner

g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
for (Bus bus : busList) {
  RoadLocation location = bus.getLocation();

代码示例来源:origin: haraldk/TwelveMonkeys

public void setTextFont(final String fontName) {
  // TODO: Need mapping between known QD font names and Java font names?
  Font current = graphics.getFont();
  graphics.setFont(Font.decode(fontName).deriveFont(current.getStyle(), (float) current.getSize()));
}

代码示例来源:origin: locationtech/jts

private void setup(Graphics2D graphics) {
 originalColor = graphics.getColor();
 originalStroke = graphics.getStroke();
 originalFont = graphics.getFont();
 graphics.setFont(new Font(FontGlyphReader.FONT_SANSSERIF, Font.PLAIN, 14));
 graphics.setColor(bandColor);
 graphics.setXORMode(Color.white);
}

相关文章

Graphics2D类方法