Some info on the framework:
1.To choose between GDI+ and OpenVG just instantiate the respective class: GraphicsGDIP or GraphicsOVG
2.To choose between AmanithVG and ShivaVG change the #define at the top of GraphicsOVG.cpp
3.The TrueType parsing code is located in _FontFileOVG.h/cpp:
VGFont font;
map<wchar_t, float> advances;
FT_Outline_Funcs FontFileOVG::outline_funcs =
{
FontFileOVG::Outline_MoveTo,
FontFileOVG::Outline_LineTo,
FontFileOVG::Outline_ConicTo,
FontFileOVG::Outline_CubicTo,
0, 0
};
bool FontFileOVG::Load(void *data, int size)
{
FT_Face face;
if (FT_New_Memory_Face(ft_library, (FT_Byte *)data, size, 0, &face))
return false;
if (!face->face_flags & FT_FACE_FLAG_SCALABLE)
return false;
units_per_EM = face->units_per_EM;
ascent = face->ascender;
descent = -face->descender;
height = face->height;
if (font) vgDestroyFont(font);
font = vgCreateFont(face->num_glyphs);
advances.clear();
FT_UInt glyph_index;
FT_ULong char_code = FT_Get_First_Char(face, &glyph_index);
while (glyph_index != 0)
{
// NO_SCALE = NO_HINTING, NO_BITMAP, and keeps font in design units
FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_SCALE);
PathOVG path;
FT_GlyphSlot glyph = face->glyph;
FT_Outline_Decompose(&glyph->outline, &outline_funcs, (void *)&path);
VGfloat glyph_origin[2] = { 0.0f, 0.0f };
VGfloat glyph_escapement[2] = { glyph->advance.x, glyph->advance.y };
vgSetGlyphToPath(font, char_code, path.Get(), VG_FALSE, glyph_origin, glyph_escapement);
advances[char_code] = glyph->advance.x;
char_code = FT_Get_Next_Char(face, char_code, &glyph_index);
}
FT_Done_Face(face);
return true;
}
int FontFileOVG::Outline_MoveTo(const FT_Vector *to, void *user)
{
PathOVG *path = (PathOVG *)user;
path->MoveTo(to->x, to->y);
return 0;
}
int FontFileOVG::Outline_LineTo(const FT_Vector *to, void *user)
{
PathOVG *path = (PathOVG *)user;
path->LineTo(to->x, to->y);
return 0;
}
int FontFileOVG::Outline_ConicTo(const FT_Vector *control, const FT_Vector *to, void *user)
{
VGPath path = ((PathOVG *)user)->Get();
VGubyte segments[1] = {VG_QUAD_TO_ABS};
VGfloat coords[4] = {control->x, control->y, to->x, to->y};
vgAppendPathData(path, 1, segments, coords);
return 0;
}
int FontFileOVG::Outline_CubicTo(const FT_Vector* control1, const FT_Vector *control2, const FT_Vector* to, void *user)
{
PathOVG *path = (PathOVG *)user;
path->CubicTo(to->x, to->y, control1->x, control1->y, control2->x, control2->y);
return 0;
}