We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Outline Coordinates / Vectors of Font
Page Index Toggle Pages: 1
Outline Coordinates / Vectors of Font (Read 2998 times)
Outline Coordinates / Vectors of Font
Aug 28th, 2008, 12:52pm
 
Hello,

is there a library or possibility to load a font, write a text and then get the coordinates or the vectors of this written Text?

Thanks a lot!
Re: Outline Coordinates / Vectors of Font
Reply #1 - Aug 28th, 2008, 2:26pm
 
In Processing, by default, fonts are actually bitmaps generated at a given size from the chosen font. So there is no vector information there. One advantage is speed, another is avoiding (more or less) font distribution issues.

To use vector fonts, I suppose you can use java.awt.Font class. It has createGlyphVector() methods, which return a GlyphVector object. The java.awt.font.GlyphVector class has a methods returning a java.awt.Shape object.
This is theoretical knowledge taken out of JavaDoc, I never used these yet...

More info (as I research the topic): Google gave me two interesting files: http://merganser.math.gvsu.edu/david/reed03/lectures/CharacterImage.java (a sample Java program) and http://merganser.math.gvsu.edu/david/reed03/notes/chap3.pdf (Chapter 3: Beginning graphics: Working with shapes) which gives some explanations (how to use PathIterator to access primitive shapes within the Shape of a Glyph).
Re: Outline Coordinates / Vectors of Font
Reply #2 - Aug 28th, 2008, 3:19pm
 
Thanks,
right now i try to make this library work http://www.nexttext.net/examples.html

but i don't really know if it has, what i need:
I take the TextObjectGlyph Class, which has a vector containing the contours. But i never worked with vectors so i am trying to do some Math-Homework in this area since i don't really know how / which format the contours look?
Hope that that gives me the outline-coordinates of the font somehow...

If someone has inspiratrion, please go ahead
Re: Outline Coordinates / Vectors of Font
Reply #3 - Aug 28th, 2008, 4:23pm
 
I reall don't get how to extract the numbers which i can use to e.g draw the outline of the font.

Here is what i do:

import net.nexttext.*;
import net.nexttext.behaviour.*;
import net.nexttext.behaviour.control.*;
import net.nexttext.behaviour.standard.*;
import net.nexttext.behaviour.dform.*;
import net.nexttext.processing.*;

Font typo;
TextObjectGlyph  textObjectGlyph;
Vector v = new Vector();

void setup(){

...
typo = book.loadFont("HelveticaRdBd.ttf");
textObjectGlyph = new TextObjectGlyph("I", typo);

}

void draw(){

 v = textObjectGlyph.contours;
 println(v.size());
 for(int i = 0; i < v.size();i++){
   println(v.get(i));
 }

}


--------------------
What i get printed:
--------------------

1
[0] 0
[1] 1
[2] 2
[3] 3
[4] 4
[5] 5
[6] 5
[7] 6
[8] 7
[9] 7
[10] 8
[11] 9
[12] 10
[13] 11
--------------------

How can I use this?
Are this Vectors (x/y) or something?
Re: Outline Coordinates / Vectors of Font
Reply #4 - Aug 28th, 2008, 5:03pm
 
ok, different approach. I found this, which is very useful:
http://processing.org/hacks/doku.php?id=hacks:fontoutline#demo-usage
Re: Outline Coordinates / Vectors of Font
Reply #5 - Aug 28th, 2008, 6:34pm
 
nah, check out geomerative: it has all you need.

http://ricardmarxer.com/geomerative/

F
Re: Outline Coordinates / Vectors of Font
Reply #6 - Aug 28th, 2008, 6:48pm
 
Well, I suppose I re-invented the wheel, but I had fun doing this (and learned some stuff in the way).
Using the references I gave above, I made a little (dual) demo, doing something not unlike what is done in the fontoutline hack. Which is slightly wrong, if I am not mistaken, as the point in a QUAD is in [2], [3], not in [0], [1] which is a control point. Same issue with CUBIC. Should use FlattenedPathIterator anyway.

Find my test sketch at: http://www.autohotkey.net/~PhiLho/Glyph.pde
(someday I should make a Processing page on my site).

[EDIT] Updated the sketch, to make it a bit less hackish (better handling of colors), and improve the support of cubic curves and display of control points.
Re: Outline Coordinates / Vectors of Font
Reply #7 - Aug 29th, 2008, 10:42am
 
Great Guys, thanks a lot!
Re: Outline Coordinates / Vectors of Font
Reply #8 - Dec 7th, 2009, 12:23pm
 
I just came across this posting. PhiLho you really should create a processing page where you collect your work. This is some really helpful stuff you made.
Page Index Toggle Pages: 1