• Advertisement
Sign in to follow this  

Designing a vectored font engine

This topic is 1865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

0 down vote favorite
I'm trying to design a vectored font engine like the one in Atari 1979. I have problem of saving the predefined character set and their co-ordinates, I don't know what is the best data-structure to save those polygons or what is the best way for to design a class for that. Here is my trial which I'm not comfortable about it at all.




class Character
{
public:
Character();
public:
int ascii;
int strokes;
std::vector<ci::Vec2i> points;
};
void VectorFont::Init_Chars()
{
for (int i=0; i<1;i++)
{
Character char_A;
char_A.ascii = 65;
char_A.strokes = 6;
ci::Vec2i point_1 = ci::Vec2i(-6,-4);
ci::Vec2i point_2 = ci::Vec2i(0,8);
ci::Vec2i point_3 = ci::Vec2i(0,8);
ci::Vec2i point_4 = ci::Vec2i(6,-4);
ci::Vec2i point_5 = ci::Vec2i(4,0);
ci::Vec2i point_6 = ci::Vec2i(-4,0);
char_A.points.push_back(point_1);
char_A.points.push_back(point_2);
char_A.points.push_back(point_3);
char_A.points.push_back(point_4);
char_A.points.push_back(point_5);
char_A.points.push_back(point_6);
chars.push_back(char_A);
}
}

Share this post


Link to post
Share on other sites
Advertisement
Nothing wrong with a list of points :) Your character class looks like it will work just fine.
If you enter the data by hand like that it's going to be a pain no matter what your structure is.

Share this post


Link to post
Share on other sites
You are assuming there's just one continuous stroke, so if you wanted to use that structure to represent something like big "E", you'd have two lines on top of each other in the middle part, one going right and one going left. That doesn't seem very elegant. You also can't represent non-continuous characters like "=" at all.

The usual way to represent a bunch of primitives like that is to define the points and lines separately; think "std::vector<ci::Vec2i> points; std::vector<unsigned[2]> lines" where every item describes a line via giving the indices of the points of that line. However, since in this special case you have 2D points, it may be equally convenient to skip separate point definition and just describe every line segment with four coordinates ("std::vector<ci::Vec4i> lines").

Entering this stuff by hand sucks but is doable if your characters are simple enough (e.g. do not have round shapes). Otherwise you have the choice of writing yourself a simple graphical editor for drawing the line segments, or using an existing editor for that purpose. Basically any vector drawing program where you can get the points/lines exported sufficiently cleanly is fine. Edited by Stroppy Katamari

Share this post


Link to post
Share on other sites
The usual way to represent a bunch of primitives like that is to define the points and lines separately; think "std::vector<ci::Vec2i> points; std::vector<unsigned[2]> lines" where every item describes a line via giving the indices of the points of that line[/quote]

Would you please explain this in details by a pseudo code ? I'm interested.

Share this post


Link to post
Share on other sites
// points (9,9), (3,4) and (5,5) in a vector like you had before
std::vector<ci::Vec2i> points{{9,9}, {3,4}, {5,5}};
// there's a line between points[0] and points[1], and another line between points[1] and points[2]
std::vector<unsigned[2]> lines{{0,1}, {1,2}};
// drawing all lines
for(unsigned i=0; i<lines.size(); ++i) { /* draw a line between points[lines[0]] and points[lines[1]] */ }

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement