On 9/12/2015 7:53 AM, Kane O'Donnell wrote:
For a pet project, I'm looking to make a wordcloud generator (e.g.
http://www.wordle.net/) that is as fast as possible, and as someone
quite new to text rendering, etc., I was wondering if the community
could offer thoughts about terms of using FreeType for this? What I
effectively need to be able to do is:
1. map a given string (font + rotation) to some sort of binary pixel
array so I can tell what space the word fills.
2. store that to a "canvas" pixel array (this is used to store word
positions and make sure they don't overlap, etc)
3. once word placement is done, then be able to save the canvas (i.e.
drawn words) to a vector format (for printing etc) that faithfully
represents the original canvas.
From what I've read, FreeType will allow me to handle 1. and 2.
relatively easily. However, I'm not sure about 3. While it's easy to,
for example, save the position/rotation of all placed words, and then
naively convert that to e.g. SVG, I'm not sure whether e.g. font size 32
means the same in FreeType as it will in SVG, and hence whether or not
my non-overlapping word layout will be preserved. I guess that's my key
question.
More than happy to get general feedback on such a project, including
other suitable libraries -- though a key requirement is for it to be as
fast as possible.
Kane
PS -- I've done something in Python but there was a messy and imperfect
hack to convert from PIL (bitmap) to matplotlib (PDF), which basically
failed point 3 as outlined above. I've also done this in Java, and I
managed to find two libraries which did the job well. However, now I'm
keen to learn a new language, and I enjoy using this as an example.
PPS -- I'm aware there are other methods (quad-tree + bounding boxes),
though they're not as simple as the "does this pixel overlap that one"
approach, and sometimes less functional and performant.
Hi Kane!
For text rendering to SVG, PDF and PS you should really check out cairo.
It's a reasonably fast vector drawing library that can generate a whole
set of outputs from the same code. See also http://www.cairographics.org.
And I have to disagree with the statement about bounding boxes and quad
trees. Methods based on spatial accceleration structures (grids,
BSP-tree, kD-tree, Quadtree, bounding volume hierarchies...) exist
because they are way faster than the brute force tests that you are
suggesting when it comes to intersection testing. They were invented
specifically for problems very similar to yours. In your case I'd
recommend that you search the web for some (maybe older) tutorials on
fast pixel-perfect collision detection for 2d games. This is the exact
problem that you're trying to solve here. A quick Google search turned
up this tutorial, for example. On first glance it seems to be quite
reasonable:
http://www.gamedev.net/page/resources/_/technical/game-programming/intelligent-2d-collision-and-pixel-perfect-precision-r3311
Gregor
_______________________________________________
Freetype mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/freetype