예제 #1
0
 private boolean canDisplayImpl(char c) {
   if (USE_ALTERNATIVE_CAN_DISPLAY_PROCEDURE) {
     return myFont.createGlyphVector(DUMMY_CONTEXT, new char[] {c}).getGlyphCode(0) > 0;
   } else {
     return myFont.canDisplay(c);
   }
 }
예제 #2
0
 /**
  * This deals with a bug/peculiarity for the default Mac font: several pixels of the ascent are
  * actually empty. This screws up certain measurements which assume the font is actually a few
  * pixels taller than it really is.
  */
 private static int getUnusedAscent(FontMetrics fm, Font font) {
   Integer value = ascentTable.get(font);
   if (value == null) {
     int recordedAscent = fm.getAscent();
     FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false);
     GlyphVector gv = font.createGlyphVector(frc, "XYZ");
     Rectangle2D bounds = ShapeBounds.getBounds(gv.getOutline());
     int observedAscent = (int) (Math.ceil(bounds.getHeight()) + .5);
     value = new Integer(recordedAscent - observedAscent);
     ascentTable.put(font, value);
   }
   return value.intValue();
 }
예제 #3
0
  private Shape generateShapeFromText() {
    Font font = new Font(fontFamily, Font.PLAIN, fontSize);
    BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = img.createGraphics();

    try {
      GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), str);
      float dispX = x;
      float dispY = (float) (y - vect.getVisualBounds().getY());
      Shape shape = vect.getOutline(dispX, dispY);

      return shape;
    } finally {
      g2.dispose();
    }
  }
예제 #4
0
    private static BufferedImage createImage(String s, boolean valid) {
      FontRenderContext frc = new FontRenderContext(null, true, true);
      Font font = new Font("dialog", Font.BOLD, 12);

      GlyphVector glyphs = font.createGlyphVector(frc, s);
      Shape shape = glyphs.getOutline();
      Rectangle bounds = shape.getBounds();

      int imageW = bounds.width;
      int imageH = bounds.height;
      BufferedImage image = new BufferedImage(imageW, imageH, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = (Graphics2D) image.getGraphics();

      g.setColor(valid ? Color.blue : Color.red);
      g.translate(bounds.x, -bounds.y);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
      g.fill(shape);

      return image;
    }
예제 #5
0
 private void parseProblemGlyphs() {
   myCheckedForProblemGlyphs = true;
   BufferedImage buffer = UIUtil.createImage(20, 20, BufferedImage.TYPE_INT_RGB);
   final Graphics graphics = buffer.getGraphics();
   if (!(graphics instanceof Graphics2D)) {
     return;
   }
   final FontRenderContext context = ((Graphics2D) graphics).getFontRenderContext();
   char[] charBuffer = new char[1];
   for (char c = 0; c < 128; c++) {
     if (!myFont.canDisplay(c)) {
       continue;
     }
     charBuffer[0] = c;
     final GlyphVector vector = myFont.createGlyphVector(context, charBuffer);
     final float y = vector.getGlyphMetrics(0).getAdvanceY();
     if (Math.round(y) != 0) {
       mySymbolsToBreakDrawingIteration.add(c);
     }
   }
   myHasGlyphsToBreakDrawingIteration = !mySymbolsToBreakDrawingIteration.isEmpty();
 }