Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

55
LINES

< > BotCompany Repo | #1004630 // Make Glyph Sheet For Learning A Font

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (4338L/30K/96K).

!752

sS fontID = "#1004569"; // "Ticketing"
static float fontSize = 30f;

static int tooLong = 60; // << glyphs with that many unicode chars assigned are usually just empty boxes

sclass Glyph {
  BWImage img;
  new StringBuilder chars;
}

static Map<S, Glyph> map = litorderedmap(); // key = md5
static BWImage img;

p {
  setConsoleDelay(2000); // saves time, 14 instead of 21s
  
  long time = now();
  for (int uc = 0; uc <= 0xFFFF; uc++) {
    print(intToHex(uc) + " " + l(map));
    BufferedImage bufImg = renderText(fontID, fontSize, str((char) uc));
    if (bufImg == null) continue;
    BWImage img = new BWImage(bufImg);
    S md5 = md5OfBWImage(img);
    Glyph g = map.get(md5);
    if (g == null) {
      map.put(md5, g = new Glyph);
      g.img = img;
    }
    g.chars.append((char) uc);
  }
  done_always(time, "Got " + l(map) + " different glyphs!");
  
  time = now();
  /*Glyph longest = (Glyph) highest(makeMap(
    func(Glyph g) { l(g.chars) }, values(map)));*/
  new L<BWImage> images;
  for (Glyph g : values(map)) {
    //S title = g == longest ? "the rest"
    S title = l(g.chars) > tooLong ? "...."
      : formatCharRange(str(g.chars));
    print(title);
    images.add(subtitle(g.img, title));
  }
    
  img = clusterImages(images);
  done_always(time, "Making glyph image (" + img.getWidth() + "/" + img.getHeight() + ")");
  
  final S title = "Glyph Sheet For Font " 
    + quote(getSnippetTitle(fontID)) + " (" + fsi(fontID) + ") Size " + fontSize;
  addToWindow(showBWImage(title, img), jbutton("Upload", r {
    messageBox(uploadImage(title, toPNG(img.getBufferedImage())));
  }));
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004630
Snippet name: Make Glyph Sheet For Learning A Font
Eternal ID of this version: #1004630/1
Text MD5: 0e4460efa226f349a269418eba419d2f
Transpilation MD5: 938bed75f640246cd4644152bd7c8c0d
Author: stefan
Category: javax / images
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-24 20:18:16
Source code size: 1675 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 624 / 761
Referenced in: #1004648 - Make Word Glyph Sheet For Learning A Font