Loading...
Logo
Processing Forum
I'm doing some work with preparing vector files for CNC cutting, and it would be useful to be able to label objects with type for easy assembly after they've been cut. Since the CNC mill uses a drill bit it's not good to use a regular font with outlines since it will have to follow the entire path of the letter and make a mess.

I was wondering if anyone worked on a hairline (i.e. single-line, no "body") font library or used something similar in the past? Would be useful for digital fabrication purposes...

Replies(8)

Hi Marius, i remember one of the very first font libraries listed on the processing Libraries page.
it might be perfect for what you need.

http://www.foobarquarium.de/blog/processing/MovingLetters/

Best
Cedric


Thanks for the link, it looks like the right kind of thing but doesn't allow you to access the underlying geometry. I'm writing PDF files directly using the iText library, so I need to be able to explicitly describe all geometry. 

I just started writing a simple class to output numbers as part of my new ModelBuilder lib, feels like it should be there anyway since I'm looking to support digital fabrication uses...
hmm, i suspected that this might be a problem.
so as you said, it is probably the easiest to come up with some simple numbers and letters similar to the mentioned library.
Yeah, I had a brainflash and figured SVG and PShape might be the way to go, but hadn't reckoned with the recursive nature of SVGs. Now I have to write a PShape translation utility too.
If you still need vector stroke fonts =) , i made an implementation of 19 Hershey fonts in processing, dont know where to upload the scene to (it uses a text file and a csv for the vector locations so just the code wont work). I could email the scene however.
Awesome! How about posting it on OpenProcessing.org? You could pre-bake the values as arrays in the code, email me (marius at mariuswatz com) if you want some tips on how to do it.
Not 100% sure if this helps, but...

WordCram will support SVG output in its 0.6.0 release (I'm working on that now). To get it working, I had to get a PathIterator from the java.awt.Shape, and run through it to generate SVG XML. It was really easy, once I figured it out, but figuring it out to me an embarrassingly long time. I found very little documentation.

You can see the relevant code here:

It shouldn't be *too* hard to turn a PShape into a java.awt.Shape...
IMHO simpliest thing is to draw your own harline fonts, save them as SVG and load to processing.


Step1 : draw your own font outline in Inkscape. You only need 26 letters and 10 digits, so it will take just few minutes. In Inkscape xml-editor assign "id" fields to each path. You probably would want to draw all charactrers in a single stroke.





As the result you will get SVG which looks simiar to this  http://pastebin.com/graEwYNN


Step 2: Load the SVG in Processing and get access to individual letter shapes

Copy code
  1. PShape shpSvg;

  2. PShape shpLetterA;
  3. PShape shpLetterB;
  4. final String C_SVG = "c:\\Users\\Ernesto Guevara\\Desktop\\processing\\assets\\vector\\hairline_letters.svg";
  5. final int C_POINT_DIAMETER = 3;

  6. void setup(){
  7.    size(640, 480);
  8.    shpSvg = loadShape(C_SVG);
  9.    
  10.    PShape layer1 =  getShapeByNameOrThrow("layer1", shpSvg);
  11.    
  12.    shpLetterA = getShapeByNameOrThrow("letter_a", layer1);
  13.    shpLetterB = getShapeByNameOrThrow("letter_b", layer1);
  14.      
  15. }

  16. void draw(){
  17.    drawPoints(shpLetterA);
  18.    drawPoints(shpLetterB);
  19. }


  20. void drawPoints(PShape shp){
  21.    int count = shp.getVertexCount();
  22.    println("Found " + count + " vertices in shape "  + shp.getName() );
  23.    shape(shp);
  24.    PVector v = new PVector();
  25.    for( int i = 0 ; i < count ; i++){
  26.       shp.getVertex(i, v);
  27.       ellipse(v.x, v.y, C_POINT_DIAMETER, C_POINT_DIAMETER);
  28.    }
  29. }


  30. /**
  31. * Gets shape with id {nodeId} from the root of the given shape.
  32. * Or throws RuntimeException()
  33. */
  34. PShape getShapeByNameOrThrow(String nodeId, PShape rootShape){
  35.       PShape[] children = rootShape.getChildren();
  36.       for( PShape child : children ){
  37.          if ( child.getName().equals(nodeId) ){
  38.             return child;
  39.          }
  40.       }  
  41.       throw new RuntimeException("Cannot find shape with id [" + nodeId + "] inside of shape " + rootShape); 
  42. }


Step 3: enjoy your own beautiful hairline letters 


ps. how come this thread was started 2 years ago and mariusz is still interested in it?? :)