How to convert any text/font to its bezier path representation? - text

I have a bezier path library to draw complex bezier paths without problem. Now, I need to know how to read a text or font and extract its path information to draw it as a path instead of as text.
I came across a C application, FontForge. It does exactly what I need, picks any font and extract its path information. But what I need to know is how it does it to add that feature to my drawing library.

You can use windows GDI function GetGlyphOutline.
Alternatively use BeginPath, TextOut, EndPath and GetPath. You will obtain a list of straight segments and Beziers. See this article for inspiration (a bit dated, but relevant).

Related

How to read a map into octave

This is a follow up to my post three weeks ago here How do I use m_map in octave, without really being a nuissance to kind and busy people. My problem is simply how does one overlay a basemap on an octave contour plot. After interpolating my irregularly spaced data (works for both contour lines and filled contours) I plot with the code:
contour(xi, yi, obsi, cstart:cstep:cend)
colorbar;
xlabel('Longitude'),ylabel('Latitude')
title('Mean Rain Onset')
saveas(gcf,'rainzam.pdf')
And I get
I have downloaded several map formats: ne_50m_admin_0_countries.zip, the apparently obsolete m_map (with associated tbase.Z, gshhg-bin-2.3.2.zip), soa.7z, world-bounds.7z, gshhg-gmt-2.3.2.tar.gz, dcw-gmt-1.1.1.tar.gz.
My question is has anyone used any of these maps in octave or gnuplot, and how to? I would appreciate any assistance.
Basically you have to load those maps in octave, they represent borders or coastlines with two variables (x,y) which you can then add to your plot with
hold on
plot(x,y)
That's the easy part, the hard part is to load the maps. All of them have different formats, which means it is a completely different story how to load them. For instance, the ne_50m_admin_0_countries.zip has a dbf format. Either you convert it first to ascii text and load it easily with the load function of octave or you need the OI package (http://wiki.octave.org/IO_package), which in turn demands java (http://wiki.octave.org/Java_package). I don't think this is the easy way for a newbie, so I suggest to convert the maps individually to text: google for "convert dbf to csv", "convert dbf to text", "convert dbf to ascii", etc... Perhaps some of those maps can be even loaded with excel and then saved as text (csv), the important issue is to convert them to text!
If you want to draw physical coastlines, you may download them from this link
https://www.naturalearthdata.com/downloads/
Then, after the drawing of a contour map of your own datas, you may add the coastlines using the following commands:
pkg load mapping
hold on
h = shapedraw ('FileName.shp','r','linewidth',1)

Can I create a Calligraphy look with SVG?

is it possible to create a stroke with a dynamic width with SVG? I want to achieve a Calligraphy look like here, here or here.
Is this even possible? It seems customization of strokes in SVG is fairly limited. Even gradients in strokes seem to be non-trivial (see here).
There is a proposal to add into SVG standard a mechanism, that does exactly what you want:
http://www.w3.org/Graphics/SVG/WG/wiki/Proposals/Variable_width_stroke
http://lists.w3.org/Archives/Public/www-svg/2013May/0041.html
There's even an example implementation available here:
https://rawgit.com/birtles/curvy/master/index.html
It is, however, by no means official and we cannot be even sure it'll ever be.
Until then you'll need to stick to Bezier curves and object filling:
You can also use calligraphic fonts, for example - Tangerine available on Google CDN:
This approach requires less work since you don't need to draw everything from scratch, but then again, using third party fonts leaves you with little control over the final result.
You can't dynamically adjust the stroke of a path element. However you could draw a path, use a fill color on it instead of stroke, then double back upon the letters at a slight distance away from the original line.
Also, if you are using the SVG on the web then you can use css fonts on text elements. There are some pretty good cursive fonts that you can use for free... just check google web fonts.

Modifying a SVG path to create word art like effects

I am trying to modify a SVG file which has a path converted from a text. I want to be able to manipulate it to create Word Art like effects (eg: Wedge, Widen, Curved text etc).
I've tried many options like parsing the file and modifying each point, but the results are bizarre and curves go wild. There is no tool/library to do this kinda stuff to an svg file.
In short, I am looking for a tool like ImageMagick but for svg. Please Help!!!
Inkscape can do some of this I think, also see this writeup by Tavmjong Bah. Inkscape uses a library called lib2geom to do these effects, and there seems to be a python wrapper for that library.

Inkscape moveTo coords way off in Raphael

I am trying to copy paths from inkscape into Raphael (individual countries), the problem is the moveTo is way off, how do I make it display on the relatively correct position on the canvas?
If you're trying to draw a path on a canvas in a relative position, you need to transform all of the absolute coordinates to relative coordinates. I had the same problem recently and resorted to a calculator and paper (it was a short path, and wasn't worth it to attack programatically). There are a few tools out there that claim to be able to do these transformations, but in my experience they were either incomplete or outdated links.
The problem is that Inkscape has already decided for you that you want your SVG files optimized for size, and will switch back and forth from relative to absolute whenever it would save a few bytes. Essentially, what you would need to do is iterate through the path, keeping track of your position, compare each absolute node to the previous node (or the origin, if it's the initial moveTo), and replace any absolute coordinates with the difference.
The Inkscape preferences have an option to force absolute coordinates, (uncheck Preferences->SVG Output->Allow relative coordinates) which may make the transformation a little easier.

Alternatives to using text() to adding text to a plot

This may be a naive question, but I was wondering if there's a better way than using text() to adding text to a plot. Note, I'm also using layout() as well. Specifically, I have a section of a plot where I would like to add some text with headings followed by regular text.
text() is fine it seems for simple annotations, but to get the spacing right for several lines of text seems to require a lot of manual manipulation of the x and y and cex parameters. Any suggestions?
Here are some alternative options to consider:
- the gplots package has a textplot function to add some text output in a base graphics plot.
- plotrix has a function addtable2plot
- for grid graphics grid.text() is available and in gridExtra there is a function grid.table() (see, e.g., R-Wiki)
If you're using base graphics, then text() is probably your best bet, and fiddling with coordinates etc is part of the game. If you want to learn a new framework, the lattice package is a reworking of the basic approach to plotting in R. It be installed by default so help(package='lattice') will get you started.
Here's a pretty good guide (pdf) to graphics in general in R, with a substantial section on lattice:
download

Resources