Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

java - CreateFont() from String

It is posible to make a variable in Processing or Java that self contain the typography (ttf or otf) in format of String to be able to load it in the same way that you can do it with images, since LoadImage () works from an array of integers. I can do it with the Images. Is there any way to do it for the case of typography? Thanks!

int[][] var = {
     // R    G    B    A
     {255,   0,   0, 128},
     {  0, 255,   0, 128}
};  

PImage loadPixelsArray(int xDiv, int yDiv, float[][] dots) {

   PImage img = createImage(xDiv, yDiv, ARGB);
   img.loadPixels();
   int size = img.pixels.length;
   for (int i = 0; i < size; i++) {
          img.pixels[i] = color(dots[i][0], dots[i][1], dots[i][2], dots[i][3]);
   }
   img.updatePixels();
   return img;
}

ps: returns PImage of 2 pixels. I need the same for PFont.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There isn't a way to do this without resorting to some pretty gross hacks.

If you're curious, the way you might approach this is by first creating a .vlw font using George's answer. Then you'd need to write a utility program that reads in the bytes of the file as a byte array, then outputs some syntax that lets you store this as a variable. Copy that variable into your target sketch, and then you could then use a ByteArrayInputStream to pass the bytes into the PFont constructor that takes an InputStream.

So sure, it's possible to do this. But this is very hacky and you should definitely not bother trying it.

Instead, I encourage you to take a step back and think about exactly what you're trying to do. It sounds like you're trying to export a single .exe file from Processing. Note that this is not possible, even if you use the above hack to get rid of the font file!

Processing exports itself as a directory of run scripts and .jar files. It is not a single packaged executable file. To convert your Processing sketch into a .exe file, you're going to have to use something like Launch4J or JWrapper.

Note that these kinds of applications all offer support for packaging external files, which is how you should deal with your font file.

Also note that you could just store your font on the web, and then pass the URL into the loadFont() function. But again, you'll still have to deal with the multiple .jar files that Processing exports.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...