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)
   Accessing the control points of a font?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Accessing the control points of a font?  (Read 929 times)
Ricard


Accessing the control points of a font?
« on: Jan 14th, 2005, 9:14pm »

Otra vez,
 
Is there a way to access the control points of a letter, so that we can maybe stretch them in order to deform the letter?
 
thanks
ricard
 
liminal


Re: Accessing the control points of a font?
« Reply #1 on: Jan 14th, 2005, 10:04pm »

I don't know how to do this with p5, but with straight Java version 1.4+, you can use the java.awt.font.GlyphVector class. It will return a java.awt.Shape object which will give you the control points.
 
Ricard


Re: Accessing the control points of a font?
« Reply #2 on: Jan 15th, 2005, 4:03pm »

Muchas gracias for the post, I'll try it as soon as I can.
 
The people on this forum are very helpful.  When I know a bit more P5 I'm going to start posting replies to help.
 
Ricard
 
Ricard


Re: Accessing the control points of a font?
« Reply #3 on: Jan 31st, 2005, 5:55pm »

Hi again,
 
I've been looking into the java.awt.font.GlyphVector and java.awt.Shape classes, an I'm having a little bit of problems integrating them into P5.
 
When I try to use the createGlyphVector(FontRenderContext frc, String str) from the Font class, I don't know how to get a FontRenderContext.
Is there anyway to get a FontRenderContext from a BApplet class?
 
Thanks,
Ricard
 
here is the code, so you can understand better what I'm trying to do.
 
as a suggestion, would it be possible to have easier access to the fonts' glyphvectors??
 
thanks again
 
 
Code:

import java.awt.geom.*;
import java.awt.font.*;
import java.awt.*;
 
public class Fonting extends BApplet {
Font f;
 
void setup()
{
  size(400,400);
  f = new Font("times new roman",Font.PLAIN,33);
  background(255);
}
 
void loop()
{
 background(255);
 image(g,0,0);
 
   String str = String.valueOf("a");
   
   // HERE IS MY PROBLEM
   // -------------------
   GlyphVector gv = f.createGlyphVector(new FontRenderContext(),str);
   // -------------------
   Shape shp = gv.getOutline();
   PathIterator pathIt = shp.getPathIterator(null);
   processPathIterator(pathIt);  
}
 
void keypressed()
{
  String str = String.valueOf("a");
 
  GlyphVector gv = f.createGlyphVector(null,str);
  Shape shp = gv.getOutline();
  PathIterator pathIt = shp.getPathIterator(null);
  processPathIterator(pathIt);  
}
 
void processPathIterator(PathIterator iter) {
   float[] vals = new float[6];
   int type;
 
   while (!iter.isDone()) {    
  type = iter.currentSegment(vals);
  switch (type) {
  case PathIterator.SEG_CUBICTO:
   // do nothing yet
      break;
  case PathIterator.SEG_LINETO:
   // do nothing yet
      break;
  case PathIterator.SEG_MOVETO:
      break;
  case PathIterator.SEG_QUADTO:
   // do nothing yet
      break;
  case PathIterator.SEG_CLOSE:
      break;
  default:
      break;
  }
  iter.next();
   
   }
}
}
 
fjen

WWW
Re: Accessing the control points of a font?
« Reply #4 on: Jan 31st, 2005, 7:55pm »

very interesting project! i'm currently putting together a list with project's that explore the creation of letterforms via code ... anyway, try this:
 
Code:

 import java.awt.geom.*;  
 import java.awt.font.*;  
 import java.awt.*;  
   
 public class Fonting extends BApplet {  
 Font f;
 FontRenderContext fontRenderContext;
   
 void setup()  
 {  
 size(400,400);  
 framerate(1);
 
 f = new Font("times roman",Font.PLAIN,33);
 println(f.toString());
   
 AffineTransform affineTransform = f.getTransform();
 fontRenderContext = new FontRenderContext(affineTransform, false, false);
 
 System.out.println("Setup done.");
 }  
   
 void loop()  
 {  
 background(255);
 }  
   
 void keyReleased()  
 {  
   String str = String.valueOf("a");
   
   //((Graphics2D)getGraphics()).getFontRenderContext()
   GlyphVector gv = f.createGlyphVector(fontRenderContext,str);  
 
   Shape shp = gv.getOutline();  
   PathIterator pathIt = shp.getPathIterator(null);  
   processPathIterator(pathIt);
 
 }  
 
String arrayToString (float[] arr)
{
 String s = "------------------";
 for (int i=0; i<arr.length; i++) s += "\n\t"+arr[i];
 return s;
}
 
 void processPathIterator(PathIterator iter) {  
 float[] vals = new float[6];  
 int type;  
   
 while (!iter.isDone()) {
  type = iter.currentSegment(vals);  
  switch (type) {
   
   case PathIterator.SEG_CUBICTO:
    System.out.println( arrayToString(vals) );
    break;
     
   case PathIterator.SEG_LINETO:  
    System.out.println( arrayToString(vals) );
    break;
     
   case PathIterator.SEG_MOVETO:
    System.out.println( arrayToString(vals) );
    break;
     
   case PathIterator.SEG_QUADTO:
    System.out.println( arrayToString(vals) );
    break;
     
   case PathIterator.SEG_CLOSE:
    System.out.println( arrayToString(vals) );
    break;
     
   default:
    System.out.println( arrayToString(vals) );
    break;  
  }  
  iter.next();
  }  
  }
}

 
/F
 
fjen

WWW
Re: Accessing the control points of a font?
« Reply #5 on: Jan 31st, 2005, 8:02pm »

oh ... two things:
 
(1) not sure why it does, but keypressed() should not compile at all ...
change to: keyReleased()
---> correction: the reason why it compiles is that it's treated as a new function ... keypressed != keyPressed since java is case-sensitive ... so it's not overriding the internal one and won't work .. that's confusing i think.
 
(2) and try not to create objects  _every_  loop (the garbage collection will be thankful).
rather create them once in setup and only use them in loop ...
 
/F
« Last Edit: Jan 31st, 2005, 8:07pm by fjen »  
Ricard


Re: Accessing the control points of a font?
« Reply #6 on: Jan 31st, 2005, 10:38pm »

wow!!!
 
thank you VERY much fjen.  This must have been the best reply I have ever got in a Forum, very useful and clear.  I even learned a little bit about how the garbage collector works.
 
thanks.  when I finish this little experiment I will send you the link so you can add it to your list if you find it interesting enough.
 
thanks again,
ricard
 
Pages: 1 

« Previous topic | Next topic »