Function Repository Resource:

CharacterCurves

Source Notebook

Turn any character into a graphics object

Contributed by: Mark Greenberg

ResourceFunction["CharacterCurves"][ch]

turns a text character ch into a graphics object of the character's shape.

ResourceFunction["CharacterCurves"][ch,format]

turns a text character ch into either a graphics object, a curve primitive or a list of segments based on the value of format.

Details and Options

ResourceFunction["CharacterCurves"][ch] can take the option "Filled" (default False) that determines if the graphics are rendered as filled or joined curves.
For ResourceFunction["CharacterCurves"][ch,format], the following values of format are allowed :
"Graphics"returns a graphics object in the shape of ch
"Curves"returns the curve(s) that make up ch's shape
"Segments"returns a list of lists of Line and BezierCurve objects, complete with proper end points
Lists of segments are nested in a list because the shape may contain more than one curve.
ResourceFunction["CharacterCurves"][ch] accepts text of any length.
Use ResourceFunction["CharacterCurves"][Style[ch,]] to get the curves of different fonts, weights, etc.
ResourceFunction["CharacterCurves"][ch] accepts any unicode character that is supported by the chosen font.

Examples

Basic Examples (1) 

Get a graphics object of the shape of the letter "j":

In[1]:=
ResourceFunction["CharacterCurves"]["j"]
Out[1]=

Scope (2) 

Get a graphics object from a character code:

In[2]:=
ResourceFunction["CharacterCurves"][FromCharacterCode[16308]]
Out[2]=

Get a graphics object for a styled character:

In[3]:=
ResourceFunction["CharacterCurves"][
 Style["f", Italic, FontFamily -> "Times New Roman"]]
Out[3]=

Options (3) 

Get a filled curve instead of a joined curve:

In[4]:=
ResourceFunction["CharacterCurves"]["x", "Filled" -> True]
Out[5]=

Get the curves themselves instead of the graphics object:

In[6]:=
ResourceFunction["CharacterCurves"]["'", "Curves"]
Out[6]=

Get the lines and Bézier curves with the end points restored:

In[7]:=
ResourceFunction["CharacterCurves"]["'", "Segments"]
Out[7]=

Applications (3) 

Display the axes and grid to analyze the shape of a character:

In[8]:=
x = Show[ResourceFunction["CharacterCurves"]["x"], Axes -> True, GridLines -> Automatic]
Out[8]=

Include a character's shape with other graphics primitives:

In[9]:=
xCurve = ResourceFunction["CharacterCurves"]["x", "Curves"];
Graphics[{Red, Disk[{3, 20}, 10], Thick, Blue, xCurve}]
Out[10]=

Change a character's shape:

In[11]:=
newSegs = ResourceFunction["CharacterCurves"]["x", "Segments"] /. Line[{a_, b_}] -> BezierCurve[{a, 1.07 a, .93 b, b}, SplineDegree -> 3];
Graphics[{Thick, newSegs}]
Out[12]=

Neat Examples (1) 

Extract curve information from a character's shape:

In[13]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/176b44d6-7777-42ea-8935-7af988673ab0"]

Publisher

Mark Greenberg

Version History

  • 1.0.0 – 28 December 2020

Related Resources

Author Notes

The definition of this function does rely on a largely undocumented side-effect of exporting and then immediately importing a string in "PDF" format. It contains the function GeometricFunctions`DecodeFilledCurve which is also undocumented.

License Information