An interim update for anybody that wants to test the new system (dynamic font loading, shape and paint objects).
Due to several differences in how fonts are handled, this version is not binary compatible with the old one. I updated the version number for the library, but I don't think ajstark's original sets it properly so any code compiled to use the old library may try loading the new version if it's installed at the same time. If this is a problem then don't install this version, but rather link directly to it in the way the demos do in client/Makefile - I may change the library name to something like shapes-exp instead to avoid this in future.
https://github.com/paeryn/openvg/tree/newfonts
Documentation will come in a few days, along with new demos - Best information at the moment is found reading the source code and the demos
client/chars.c and
client/ptest.c
Things might change in the future at any time, this is experimental work-in-progress based on how I see potential improvements. ajstarks is ultimately in-charge of his library, this is just my testbed, I'll try to keep compatibility a priority but if I think things need to be different (hello Fontinfo)... I'm keeping ajstarks up-to-date with what I'm doing and I'll be working with him to integrate any changes he wants. Oh, and the Go integration will probably be messed up - I won't attempt to update that whilst the C code is in flux.
In addition to the libraries that ajstark's original requires, this version requires libfontconfig1 to be installed (not sure if libfontconfig1 is installed by default, but you'll need to install libfontconfig1-dev anyway to compile the library)
Code: Select all
sudo apt-get install libfontconfig1-dev
The new font system is up and running so you can load fonts easily at runtime. At the moment it requires setting the ctype locale property properly within your program if you want to print anything other than basic ascii strings (like UTF-8 or accented characters), if you don't then it will ignore any string that doesn't conform. I'm probably going to go back to defaulting to UTF-8 since this is a pain. To do this put something like this at the start
Code: Select all
#include <locale.h> // Needed for setlocale()
int main()
{
setlocale(LC_CTYPE, "");
...
}
New fonts can be loaded either by giving their filename, or if the font is installed, by using it's family name (the system will then pick the nearest font it can find if what you asked for isn't available).
Code: Select all
Fontinfo myFont = LoadTTFFile("/path/to/myfont.ttf"); // Loads a font by filename
Fontinfo myFont = LoadTTF("DejaVuSans"); // Loads a font by family name
unloadfont(myFont); // Frees the font
Fonts don't have to be truetype, it handles postscript-type1 too (although it doesn't seem to load the kerning data for those even though I ask it to) - and any other outline font that freetype handles - though I don't have any to check.
Kerning (adjusting inter-character spacing for combinations like
WA) will happen too for fonts loaded like this as long as the font provides it (so the default 3 fonts won't), this can be switched off on a font-by-font basis.
The new system causes programs that do a lot of drawing to have stalls (I've seen anywhere between 5-30 seconds). From what I've seen this could happen previously anyway - but the new system causes it to happen sooner. I think (from several days trying to follow what the system is doing) is that because the library originally created and destroyed paths constantly, the gpu is keeping old data around (it needs to if it hasn't gotten around to drawing before you destroy the object) then the stall happens when it finally tries to clean up. I've added a bunch of functions that rather than drawing the shapes, just create an object and return a handle to it. You create all the shapes you need outside the main drawing routines (where possible), and in the drawing loop you call the function to draw them. This is how OpenVG is meant to work anyway.
I've not gotten around to documenting, but the file
client/chars.c shows drawing the new fonts, and
client/ptest.c shows using the new paths (it's a modified version of
client/particles.c).
Quick example usage
Code: Select all
#include "shapes.h"
VGPath myCircle;
VGPath MyRect;
VGPaint myRed;
VGPaint myWhite;
void allocData()
{
myCircle = CirclePath(0, 0, 20); // a circle, radius 20 units, origin is it's centre at (0,0)
myRect = RectPath(0, 0, 15, 30); // A rectangle, origin is bottom-left corner at (0,0) 15 units wide by 30 high
myWhite = Paint(255, 255, 255, 1.0f); // White paint
myRed = Paint(color_red, 1.0f); // Red paint using the color_ define
}
void drawScene()
{
StrokeWidth(1); // 1 pixel wide outlines
WindowClear(); // Clear the screen
StrokePaint(myRed); // Set the outline to the red we defined
FillPaint(myWhite); // Set the fill to the white we defined
DrawPath(myRect); // Draw the rectangle we defined with the origin at 0,0
DrawPathAt(100, 100, myCircle); // Draw the circle with it's origin translated to (100,100)
End();
}
void freeData()
{
DeletePaint(myRed);
DeletePaint(myWhite);
DeletePath(myRect);
DeletePath(myCircle);
}
int main()
{
int w, h, i;
init(&w, &h);
allocData();
for (i = 0; i < 60; i++) {
drawScene();
}
freeData();
finish();
return 0;
}
Compiling needs to include freetype and fontconfig since the library needs them now.
Code: Select all
gcc -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -o demo demo.c -L/opt/vc/lib -lshapes -lEGL -lGLESv2 -lbcm_host -pthread -ljpeg -lfreetype -lfontconfig