re: getCharacterAsPoints(...)

[attachment=0:1sg7ayvd]HLL.TTF.zip[/attachment:1sg7ayvd][attachment=0:1sg7ayvd]HLL.TTF.zip[/attachment:1sg7ayvd]Hi there, I posted some questions on this in the beginners section, as that’s what I am, but as I’ve had no responses perhaps it’s an advanced question, or I can’t explain myself. Either way, here’s the sketch.

Basically I’m trying to use OF to control a drawing machine which will be writing text, not interactive, just quite simply writing a single line of text. Slightly better/more convoluted descriptions of the project can be found on my blog at http://dm.ncl.ac.uk/peterevans/blog

I figure using the getCharacterAsPoints command I should be able to spit out the X,Y data which I can then with some translation of course, output to control mechanical motors.

Attached is the src folder from the project, pretty much a hacked up font shapes example, at present I’m just looking at one character. btw what’s the norm for attaching code examples - the project folder for that example is 10mb but without it anyone looking will have to build up their own example, or are the code lines enough? Anyway on to the issue at hand.

The bit that’s getting me

  
  
  
[color=#0000FF][b]ofBeginShape();  
for(int k = 0; k <testChar.contours.size(); k++){   
	if( k!= 0)ofNextContour(true);  
	for(int i = 0; i < testChar.contours[k].pts.size(); i++){   
					  
	ofVertex(testChar.contours[k].pts[i].x, testChar.contours[k].pts[i].y);  
					  
ofDrawBitmapString("x: "+ ofToString(testChar.contours[k].pts[i].x), -400, -300+i*15);  
ofDrawBitmapString("y: "+ ofToString(testChar.contours[k].pts[i].y), -200, -300+i*15);[/b] [/color]  

Got some questions now, will save up others for later on!

1: Why with using
ofDrawBitmapString("x: "+ ofToString(testChar.contours[k].pts[i].x), -400, -300+i*15);

do I get three overlapping figures at the top of this list - I’m making the list to get an idea of how many pieces of data will be traveling through and to test/firgure out what’s actually getting given out from the getCharacterAsPoints command.

2: What’s really happening in getCharacterAsPoints seeing as ttf are made up of quadratic béziers and stright line info there must be some translation wrapped up in there?

2: what is going on in the following command - this is the one where I’m properly lost.
testChar.contours[k].pts.size

If I need to look at further resources just send me the links and lastly if you know of any similar projects using OF that I could take a look at please get in touch,

many thanks,

thx1742.

src.zip

HLL.TTF.zip

do I get three overlapping figures at the top of this list - I’m making the list to get an idea of how many pieces of data will be traveling through and to test/firgure out what’s actually getting given out from the getCharacterAsPoints command.

Screenshots always help when trying to debug issues like this.

I’ll comment this code so you can understand the steps.

  
	ofFill();  
	ofPushMatrix();  
		ofTranslate(250, 250, 0);  
		ofBeginShape();  
			//for each contour within a shape - letter O has two contours - interior and exterior - letter T has one contour.  
			for(int k = 0; k <testChar.contours.size(); k++){  
				//If we have more then one contour we need to start a new contour  
				if( k!= 0)ofNextContour(true);  
				//now for that contour lets go through for every point in it  
				for(int i = 0; i < testChar.contours[k].pts.size(); i++){  
					//now we send each point as x and y to be drawn  
					ofVertex(testChar.contours[k].pts[i].x, testChar.contours[k].pts[i].y);  
				}  
			}  
		ofEndShape( true );  
	ofPopMatrix();  

Hi Theo,

many thanks for your response, sorry for delayed appreciation. Your post clarified things a lot as well as a good friend (dataprole) helping me out as well which got rid of the overlapping numbers issue. He also managed to get the contours to print up onto the screen which was a very useful thing to have via the following

  
for(int k = 0; k <testChar.contours.size(); k++){ //goes through the character and gets all contour data?  
				ofDrawBitmapString("NUMBER OF CONTOURS = "+ofToString(getSize), -400, -360);  
				if( k!= 0)ofNextContour(true);  
				int getPOINTS = testChar.contours[k].pts.size();  
				ofDrawBitmapString("NUMBER OF POINTS IN CONTOUR IS = "+ofToString(getPOINTS), -400, -340);  
				for(int i = 0; i < testChar.contours[k].pts.size(); i++){  
//and then  
   
ofVertex(testChar.contours[k].pts[i].x, testChar.contours[k].pts[i].y);	  
	ofDrawBitmapString("CONTOUR "+ ofToString(k), -400+(100*k), -320);  
        ofDrawBitmapString("x: "+ ofToString(testChar.contours[k].pts[i].x), -400+(100*k), -300+i*15);  
	ofDrawBitmapString("CONTOUR "+ ofToString(k), -200+(200*k), -320);  
	ofDrawBitmapString("y: "+ ofToString(testChar.contours[k].pts[i].y), -200+(100*k), -300+i*15);  

All very useful and I’m now forward into writing the next bit where I’ll be transposing all those points back to vectors so I can get some rather large arrays of points for my motors to follow.

Go here, am I here, yes, go next, am I there, yes etc.

Funny to translate something only to retranslate it back into something similar to what it was in the first place. But seeing as the function exists it kind of makes more sense to use it than to try and write my own thing to drag the data out of a TTF, much too advanced for me at present that’s for sure, if I tried - :shock:

One other question is that when I put the points pulled out into a graphing program and ask it to join the dots there are two gaps where the line would go and indeed does go in OF. Any idea why that might be the case?

Many thanks

thx1742

![](http://forum.openframeworks.cc/uploads/default/561/Picture 1.png)

![](http://forum.openframeworks.cc/uploads/default/562/Picture 2.png)

i think you just need to join the last point of each polygon with the first one

Arturo,

that would be happening already inside OF as part of the loop which is in there, but I’m guessing to make it happen physically with my motors I’d have to program something into
the loop to make it occur.
Maybe something that asks string length for each contour and then if the for loop (i++ style) is finished then take first point and last point and draw vector between?

In any case it’s kind of a null point I now realise as I’m going to be designing my own TTF for the project in which each character will only have one contour as I want the machine
to write as we would write, so single line rather than outlines and hence shouldn’t need to connect a first point to the last - though saying that if it was super fancy calligraphy!

many thanks

thx1742