FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   fonts
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: fonts  (Read 2706 times)
Martin

122417302122417302martingomez_listsmg1ph WWW Email
fonts
« on: Jan 8th, 2003, 1:12am »

have always wondered how one can make his/her own font like those under fonts/
 
fry


WWW
Re: fonts
« Reply #1 on: Jan 8th, 2003, 5:37am »

hrm.. yeah.. well..
 
it's a <insert adjective here> format that dates back to the early 90s with the 'visible language workshop' the predecessor to the acg at the mit media lab.
 
unfortunately there isn't currently a way to make the fonts (except with a bizarre tool that we use internally that was written five or so years ago for macos).  
 
it's one of those things for which we need a better solution.. this is just an interim one until we get a font generator built into the app..
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: fonts
« Reply #2 on: Jan 8th, 2003, 4:11pm »

ah... the brainchild of muriel cooper. ok ok. thanks for the info now i know what .vlw.gz stands for looking forward to 'p5 helper apps'
 
fjen

WWW
Re: fonts
« Reply #3 on: Jul 18th, 2004, 12:50pm »

fry,
 
could you possibly make the .vlw file-format public? i'd like to generate my own fonts directly from within fontlab (using python) ..
 
flo
 
fry


WWW
Re: fonts
« Reply #4 on: Jul 18th, 2004, 4:26pm »

sure.. i don't actually have a 'reference' or spec or anything, but this is the code for reading and writing the fonts. BFont has become PFont in rev 70, so this is the latest code.  
 
Code:
public class PFont implements PConstants {
 
  //int firstChar = 33; // always
  int charCount;
  PImage images[];
 
  // image width, a power of 2
  // note! these will always be the same
  int iwidth, iheight;  
  // float versions of the above
  float iwidthf, iheightf;
 
  // mbox is just the font size (i.e. 48 for most vlw fonts)
  int mbox;
 
  int value[];  // char code
  int height[]; // height of the bitmap data
  int width[];  // width of bitmap data
  int setWidth[];  // width displaced by the char
  int topExtent[];  // offset for the top
  int leftExtent[];  // offset for the left
 
  // scaling, for convenience
  float size;  
  float leading;
 
  int ascii[];  // quick lookup for the ascii chars
  boolean cached;
 
 
  public PFont() { }  // for PFontAI subclass and font builder
 
 
  public PFont(InputStream input) throws IOException {
    DataInputStream is = new DataInputStream(input);
 
    charCount   = is.readInt();
    int numBits = is.readInt();
    int mboxX   = is.readInt();  // not used, just fontsize (48)
    int mboxY   = is.readInt();  // also just fontsize (48)
 
    // only store this one for leading calc
    mbox = mboxY;  
 
    // size for image ("texture") is next power of 2
    // over the font size. for most vlw fonts, the size is 48
    // so the next power of 2 is 64.  
    iwidth = (int)  
 Math.pow(2, Math.ceil(Math.log(mboxX) / Math.log(2)));
    iheight = (int)  
 Math.pow(2, Math.ceil(Math.log(mboxY) / Math.log(2)));
 
    iwidthf = (float) iwidth;
    iheightf = (float) iheight;
 
    // font size is 48, so default leading is 48 * 1.2
    // this is same as what illustrator uses for the default
    //defaultLeading = ((float)mboxY / iheightf) * 1.2f;
 
    int baseHt = is.readInt(); // zero, ignored
    is.readInt(); // ignore 4 for struct padding
 
    // allocate enough space for the character info
    value  = new int[charCount];
    height = new int[charCount];
    width  = new int[charCount];
    setWidth    = new int[charCount];
    topExtent   = new int[charCount];
    leftExtent  = new int[charCount];
 
    ascii = new int[128];
    for (int i = 0; i < 128; i++) ascii[i] = -1;
 
    // read the information about the individual characters
    for (int i = 0; i < charCount; i++) {
 value[i] = is.readInt();
 height[i]     = is.readInt();
 width[i] = is.readInt();
 setWidth[i]   = is.readInt();
 topExtent[i]  = is.readInt();
 leftExtent[i] = is.readInt();
 
 // pointer in the c version, ignored
 is.readInt();  
 
 // cache locations of the ascii charset
 if (value[i] < 128) ascii[value[i]] = i;
    }
 
    images = new PImage[charCount];
    for (int i = 0; i < charCount; i++) {
 //int pixels[] = new int[64 * 64];
 int pixels[] = new int[iwidth * iheight];
 //images[i] = new PImage(pixels, 64, 64, ALPHA);
 images[i] = new PImage(pixels, iwidth, iheight, ALPHA);
 int bitmapSize = height[i] * width[i];
 
 byte temp[] = new byte[bitmapSize];
 is.readFully(temp);
 
 // convert the bitmap to an alpha channel
 int w = width[i];
 int h = height[i];
 for (int x = 0; x < w; x++) {
   for (int y = 0; y < h; y++) {
     int valu = temp[y*w + x] & 0xff;
     //images[i].pixels[y*64 + x] = valu;
     images[i].pixels[y * iwidth + x] = valu;
     // the following makes javagl more happy..  
     // not sure what's going on
     //(valu << 24) | (valu << 16) | (valu << 8) | valu; //0xffffff;
     //System.out.print((images[i].pixels[y*64+x] > 128) ? "*" : ".");
   }
   //System.out.println();
 }
 //System.out.println();
    }
    cached = false;
    resetSize();
    resetLeading(); // ??
  }
 
 
  public void write(OutputStream output) throws IOException {
    DataOutputStream os = new DataOutputStream(output);
 
    os.writeInt(charCount);  
    os.writeInt(8);     // numBits
    os.writeInt(mbox);  // mboxX (font size)
    os.writeInt(mbox);  // mboxY (font size)
    os.writeInt(0);     // baseHt, ignored
    os.writeInt(0);     // struct padding for c version
 
    for (int i = 0; i < charCount; i++) {
 os.writeInt(value[i]);
 os.writeInt(height[i]);
 os.writeInt(width[i]);
 os.writeInt(setWidth[i]);
 os.writeInt(topExtent[i]);
 os.writeInt(leftExtent[i]);
 os.writeInt(0); // padding
    }
 
    for (int i = 0; i < charCount; i++) {
 //int bitmapSize = height[i] * width[i];
 //byte bitmap[] = new byte[bitmapSize];
 
 for (int y = 0; y < height[i]; y++) {
   for (int x = 0; x < width[i]; x++) {
     os.write(images[i].pixels[y * width[i] + x] & 0xff);
   }
 }
    }
    os.flush();
    os.close();  // can/should i do this?
  }
}
 
fry


WWW
Re: fonts
« Reply #5 on: Jul 18th, 2004, 4:27pm »

even simpler, you can also just use "Create Font" under the sketch menu to make a new font (since that hadn't been complete when this thread started a year or so ago).
 
fjen

WWW
Re: fonts
« Reply #6 on: Jul 18th, 2004, 5:58pm »

thanks very much fry. i know about create font, it's just that i do a lot with letterror's robofab inside of fontlab's python and i wanted to limit production steps a little. i'm not sure how to get this all to work together but i'll make an example once it works.
 
best,
F
 
Pages: 1 

« Previous topic | Next topic »