5

Consider this code:

fc = ImportString[ExportString[Style["Ma"], "PDF"], "PDF"][[1, 1, 2, 1, 1]];
lines = GeometricFunctions`DecodeFilledCurve[fc][[1]];
{lines // Length,Graphics[JoinedCurve[#]] & /@ lines}

will give what is expected:

enter image description here

but this code:

fc = ImportString[ExportString[Style["Ma", FontFamily -> "Times"], "PDF"], "PDF"][[1, 1, 2, 1, 1]];
lines = GeometricFunctions`DecodeFilledCurve[fc][[1]];
{lines // Length, Graphics[JoinedCurve[#]] & /@ lines}

gives four things, with the fourth element is just a point:

enter image description here

lines[[-1]]
(*{Line[{{10.5607,9.40406},{10.5607,9.40406}}]}*)

Why there is an extra point in the second case? I'm using version 9 on Mac.

Update

screenshots of the problem on version 8 and 9 on mac, and version 8 on windows 7, the results seems different:

enter image description here

enter image description here enter image description here

cormullion
  • 24,243
  • 4
  • 64
  • 133
xslittlegrass
  • 27,549
  • 9
  • 97
  • 186

1 Answers1

3

I've encountered this problem, coming from a slightly different direction. I think the compound paths contain an extra pair of coordinates that you're noticing when you split up the results of a FilledCurve.

Here's how I first came across this:

glyph[code_, font_, size_] := 
  First[First[
    ImportString[
     ExportString[
      Style[FromCharacterCode[code], FontSize -> size, 
       FontFamily -> font], "PDF"], "TextMode" -> "Outlines"]]]; 

a = glyph[97, "Times", 24] 
{Thickness[0.130073],
  {FilledCurve[
    {
      {{1,4,3},{1,3,3},{0,1,0},{1,3,3},{1,3,3},{1,3,3},{1,3,3}},
      {{1,4,3},{1,3,3},{0,1,0},{1,3,3},{1,3,3},{1,3,3}, ...
      {{0,2,0}}},
     {
      {{3.74836,5.265},{4.01063,5.265},{4.25426,5.35078}, ...
      {{0.405,5.96742},{0.405,6.74086},{0.77502,7.35469}, ...
      {{4.1175,12.4875},{4.1175,12.4875}}}]}}

The {{4.1175,12.4875},{4.1175,12.4875}} is a short zero-length line that I think might be causing the problems.

I noticed it when I selected the graphic. I could see that there was something odd there:

Graphics[{Gray, a}] 

the letter a selected

The short line registers oddly as a large dot.

Looking at all the letter forms, it appears that you definitely get this extra line for many letters, not just for "compound paths".

Length[#[[2, 1, 1, 2]]] & /@ (glyph[#, "Helvetica", 24] & /@ 
   ToCharacterCode /@ Characters["abcdefghijklmnopqrstuvwxyz"]);
BarChart[%, ChartLabels -> Characters["abcdefghijklmnopqrstuvwxyz"]]

chart

There's "a", "e", and "o" which have three elements in the relevant FilledCurve. "b" has two, like it should have, but "c" should only have one. "n", "s", and "u" also have more elements than they need. And so on.

You could probably fix this by adding a rule that makes zero-length lines get deleted from the FilledCurve, but that's proved beyond my expertise...

tl;dr I think it's a bug, but who knows whether in Mathematica or the Mac OS system.

cormullion
  • 24,243
  • 4
  • 64
  • 133