コード例 #1
0
 // renders font characters to be used for text painting in tests (to make font rendering
 // platform-independent)
 public static void main(String[] args) throws Exception {
   Font font =
       Font.createFont(
           Font.TRUETYPE_FONT,
           EditorPaintingTest.class.getResourceAsStream("/fonts/Inconsolata.ttf"));
   BitmapFont bitmapFont = BitmapFont.createFromFont(font);
   bitmapFont.saveToFile(getFontFile());
 }
コード例 #2
0
  private void checkResult(@TestDataFile String expectedResultFileName) throws IOException {
    myEditor.getSettings().setAdditionalLinesCount(0);
    myEditor.getSettings().setAdditionalColumnsCount(1);
    JComponent editorComponent = myEditor.getContentComponent();
    Dimension size = editorComponent.getPreferredSize();
    editorComponent.setSize(size);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    BitmapFont bitmapFont = BitmapFont.loadFromFile(getFontFile());
    MyGraphics graphics = new MyGraphics(image.createGraphics(), bitmapFont);
    try {
      editorComponent.paint(graphics);
    } finally {
      graphics.dispose();
    }

    File fileWithExpectedResult = getTestDataFile(expectedResultFileName);
    if (OVERWRITE_TESTDATA) {
      ImageIO.write(image, "png", fileWithExpectedResult);
      System.out.println("File " + fileWithExpectedResult.getPath() + " created.");
    }
    if (fileWithExpectedResult.exists()) {
      BufferedImage expectedResult = ImageIO.read(fileWithExpectedResult);
      if (expectedResult.getWidth() != image.getWidth()) {
        fail("Unexpected image width", fileWithExpectedResult, image);
      }
      if (expectedResult.getHeight() != image.getHeight()) {
        fail("Unexpected image height", fileWithExpectedResult, image);
      }
      for (int i = 0; i < expectedResult.getWidth(); i++) {
        for (int j = 0; j < expectedResult.getHeight(); j++) {
          if (expectedResult.getRGB(i, j) != image.getRGB(i, j)) {
            fail("Unexpected image contents", fileWithExpectedResult, image);
          }
        }
      }
    } else {
      ImageIO.write(image, "png", fileWithExpectedResult);
      fail("Missing test data created: " + fileWithExpectedResult.getPath());
    }
  }
コード例 #3
0
 private void drawChar(char c, int x, int y) {
   myBitmapFont.draw(myDelegate, c, x, y);
 }