]> granicus.if.org Git - graphviz/commitdiff
ps_txt: fuse array strings, accelerating 'cat_libfile'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 10 Oct 2021 20:56:47 +0000 (13:56 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 13 Oct 2021 14:55:32 +0000 (07:55 -0700)
The `ps_txt` array is only used in calls to `cat_libfile`, which does not need a
single line per array entry. By fusing all strings into the first `ps_txt` array
entry, we can reduce the number of eventual `gvputs` calls, accelerating the
entire operation.

plugin/core/ps.h

index ed8bfba564ddf7d33e83a893ccaaf0e0838bf752..46d7fac168c2e6f0c8005ef85272670252ff59ec 100644 (file)
 
 static const char *ps_txt[] = {
     // clang-format off
-    "%%BeginProlog",
-    "/DotDict 200 dict def",
-    "DotDict begin",
-    "",
-    "/setupLatin1 {",
-    "mark",
-    "/EncodingVector 256 array def",
-    " EncodingVector 0",
-    "",
-    "ISOLatin1Encoding 0 255 getinterval putinterval",
-    "EncodingVector 45 /hyphen put",
-    "",
-    "% Set up ISO Latin 1 character encoding",
-    "/starnetISO {",
-    "        dup dup findfont dup length dict begin",
-    "        { 1 index /FID ne { def }{ pop pop } ifelse",
-    "        } forall",
-    "        /Encoding EncodingVector def",
-    "        currentdict end definefont",
-    "} def",
-    "/Times-Roman starnetISO def",
-    "/Times-Italic starnetISO def",
-    "/Times-Bold starnetISO def",
-    "/Times-BoldItalic starnetISO def",
-    "/Helvetica starnetISO def",
-    "/Helvetica-Oblique starnetISO def",
-    "/Helvetica-Bold starnetISO def",
-    "/Helvetica-BoldOblique starnetISO def",
-    "/Courier starnetISO def",
-    "/Courier-Oblique starnetISO def",
-    "/Courier-Bold starnetISO def",
-    "/Courier-BoldOblique starnetISO def",
-    "cleartomark",
-    "} bind def",
-    "",
-    "%%BeginResource: procset graphviz 0 0",
-    "/coord-font-family /Times-Roman def",
-    "/default-font-family /Times-Roman def",
-    "/coordfont coord-font-family findfont 8 scalefont def",
-    "",
-    "/InvScaleFactor 1.0 def",
-    "/set_scale {",
-    "       dup 1 exch div /InvScaleFactor exch def",
-    "       scale",
-    "} bind def",
-    "",
-    "% styles",
-    "/solid { [] 0 setdash } bind def",
-    "/dashed { [9 InvScaleFactor mul dup ] 0 setdash } bind def",
-    "/dotted { [1 InvScaleFactor mul 6 InvScaleFactor mul] 0 setdash } bind def",
-    "/invis {/fill {newpath} def /stroke {newpath} def /show {pop newpath} def} bind def",
-    "/bold { 2 setlinewidth } bind def",
-    "/filled { } bind def",
-    "/unfilled { } bind def",
-    "/rounded { } bind def",
-    "/diagonals { } bind def",
-    "/tapered { } bind def",
-    "",
-    "% hooks for setting color ",
-    "/nodecolor { sethsbcolor } bind def",
-    "/edgecolor { sethsbcolor } bind def",
-    "/graphcolor { sethsbcolor } bind def",
-    "/nopcolor {pop pop pop} bind def",
-    "",
-    "/beginpage {      % i j npages",
-    "  /npages exch def",
-    "  /j exch def",
-    "  /i exch def",
-    "  /str 10 string def",
-    "  npages 1 gt {",
-    "          gsave",
-    "                  coordfont setfont",
-    "                  0 0 moveto",
-    "                  (\\() show i str cvs show (,) show j str cvs show (\\)) show",
-    "          grestore",
-    "  } if",
-    "} bind def",
-    "",
-    "/set_font {",
-    "  findfont exch",
-    "  scalefont setfont",
-    "} def",
-    "",
-    "% draw text fitted to its expected width",
-    "/alignedtext {                    % width text",
-    "  /text exch def",
-    "  /width exch def",
-    "  gsave",
-    "          width 0 gt {",
-    "                  [] 0 setdash",
-    "                  text stringwidth pop width exch sub text length div 0 text ashow",
-    "          } if",
-    "  grestore",
-    "} def",
-    "",
-    "/boxprim {                                % xcorner ycorner xsize ysize",
-    "          4 2 roll",
-    "          moveto",
-    "          2 copy",
-    "          exch 0 rlineto",
-    "          0 exch rlineto",
-    "          pop neg 0 rlineto",
-    "          closepath",
-    "} bind def",
-    "",
-    "/ellipse_path {",
-    "  /ry exch def",
-    "  /rx exch def",
-    "  /y exch def",
-    "  /x exch def",
-    "  matrix currentmatrix",
-    "  newpath",
-    "  x y translate",
-    "  rx ry scale",
-    "  0 0 1 0 360 arc",
-    "  setmatrix",
-    "} bind def",
-    "",
-    "/endpage { showpage } bind def",
-    "/showpage { } def",
-    "",
-    "/layercolorseq",
-    "  [       % layer color sequence - darkest to lightest",
-    "          [0 0 0]",
-    "          [.2 .8 .8]",
-    "          [.4 .8 .8]",
-    "          [.6 .8 .8]",
-    "          [.8 .8 .8]",
-    "  ]",
-    "def",
-    "",
-    "/layerlen layercolorseq length def",
-    "",
-    "/setlayer {/maxlayer exch def /curlayer exch def",
-    "  layercolorseq curlayer 1 sub layerlen mod get",
-    "  aload pop sethsbcolor",
-    "  /nodecolor {nopcolor} def",
-    "  /edgecolor {nopcolor} def",
-    "  /graphcolor {nopcolor} def",
-    "} bind def",
-    "",
-    "/onlayer { curlayer ne {invis} if } def",
-    "",
-    "/onlayers {",
-    "  /myupper exch def",
-    "  /mylower exch def",
-    "  curlayer mylower lt",
-    "  curlayer myupper gt",
-    "  or",
-    "  {invis} if",
-    "} def",
-    "",
-    "/curlayer 0 def",
-    "",
-    "%%EndResource",
-    "%%EndProlog",
-    "%%BeginSetup",
-    "14 default-font-family set_font",
-    "% /arrowlength 10 def",
-    "% /arrowwidth 5 def",
-    "",
-    "% make sure pdfmark is harmless for PS-interpreters other than Distiller",
-    "/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse",
-    "% make '<<' and '>>' safe on PS Level 1 devices",
-    "/languagelevel where {pop languagelevel}{1} ifelse",
-    "2 lt {",
-    "    userdict (<<) cvn ([) cvn load put",
-    "    userdict (>>) cvn ([) cvn load put",
-    "} if",
-    "",
+    "%%BeginProlog\n"
+    "/DotDict 200 dict def\n"
+    "DotDict begin\n"
+    "\n"
+    "/setupLatin1 {\n"
+    "mark\n"
+    "/EncodingVector 256 array def\n"
+    " EncodingVector 0\n"
+    "\n"
+    "ISOLatin1Encoding 0 255 getinterval putinterval\n"
+    "EncodingVector 45 /hyphen put\n"
+    "\n"
+    "% Set up ISO Latin 1 character encoding\n"
+    "/starnetISO {\n"
+    "        dup dup findfont dup length dict begin\n"
+    "        { 1 index /FID ne { def }{ pop pop } ifelse\n"
+    "        } forall\n"
+    "        /Encoding EncodingVector def\n"
+    "        currentdict end definefont\n"
+    "} def\n"
+    "/Times-Roman starnetISO def\n"
+    "/Times-Italic starnetISO def\n"
+    "/Times-Bold starnetISO def\n"
+    "/Times-BoldItalic starnetISO def\n"
+    "/Helvetica starnetISO def\n"
+    "/Helvetica-Oblique starnetISO def\n"
+    "/Helvetica-Bold starnetISO def\n"
+    "/Helvetica-BoldOblique starnetISO def\n"
+    "/Courier starnetISO def\n"
+    "/Courier-Oblique starnetISO def\n"
+    "/Courier-Bold starnetISO def\n"
+    "/Courier-BoldOblique starnetISO def\n"
+    "cleartomark\n"
+    "} bind def\n"
+    "\n"
+    "%%BeginResource: procset graphviz 0 0\n"
+    "/coord-font-family /Times-Roman def\n"
+    "/default-font-family /Times-Roman def\n"
+    "/coordfont coord-font-family findfont 8 scalefont def\n"
+    "\n"
+    "/InvScaleFactor 1.0 def\n"
+    "/set_scale {\n"
+    "       dup 1 exch div /InvScaleFactor exch def\n"
+    "       scale\n"
+    "} bind def\n"
+    "\n"
+    "% styles\n"
+    "/solid { [] 0 setdash } bind def\n"
+    "/dashed { [9 InvScaleFactor mul dup ] 0 setdash } bind def\n"
+    "/dotted { [1 InvScaleFactor mul 6 InvScaleFactor mul] 0 setdash } bind def\n"
+    "/invis {/fill {newpath} def /stroke {newpath} def /show {pop newpath} def} bind def\n"
+    "/bold { 2 setlinewidth } bind def\n"
+    "/filled { } bind def\n"
+    "/unfilled { } bind def\n"
+    "/rounded { } bind def\n"
+    "/diagonals { } bind def\n"
+    "/tapered { } bind def\n"
+    "\n"
+    "% hooks for setting color \n"
+    "/nodecolor { sethsbcolor } bind def\n"
+    "/edgecolor { sethsbcolor } bind def\n"
+    "/graphcolor { sethsbcolor } bind def\n"
+    "/nopcolor {pop pop pop} bind def\n"
+    "\n"
+    "/beginpage {      % i j npages\n"
+    "  /npages exch def\n"
+    "  /j exch def\n"
+    "  /i exch def\n"
+    "  /str 10 string def\n"
+    "  npages 1 gt {\n"
+    "          gsave\n"
+    "                  coordfont setfont\n"
+    "                  0 0 moveto\n"
+    "                  (\\() show i str cvs show (,) show j str cvs show (\\)) show\n"
+    "          grestore\n"
+    "  } if\n"
+    "} bind def\n"
+    "\n"
+    "/set_font {\n"
+    "  findfont exch\n"
+    "  scalefont setfont\n"
+    "} def\n"
+    "\n"
+    "% draw text fitted to its expected width\n"
+    "/alignedtext {                    % width text\n"
+    "  /text exch def\n"
+    "  /width exch def\n"
+    "  gsave\n"
+    "          width 0 gt {\n"
+    "                  [] 0 setdash\n"
+    "                  text stringwidth pop width exch sub text length div 0 text ashow\n"
+    "          } if\n"
+    "  grestore\n"
+    "} def\n"
+    "\n"
+    "/boxprim {                                % xcorner ycorner xsize ysize\n"
+    "          4 2 roll\n"
+    "          moveto\n"
+    "          2 copy\n"
+    "          exch 0 rlineto\n"
+    "          0 exch rlineto\n"
+    "          pop neg 0 rlineto\n"
+    "          closepath\n"
+    "} bind def\n"
+    "\n"
+    "/ellipse_path {\n"
+    "  /ry exch def\n"
+    "  /rx exch def\n"
+    "  /y exch def\n"
+    "  /x exch def\n"
+    "  matrix currentmatrix\n"
+    "  newpath\n"
+    "  x y translate\n"
+    "  rx ry scale\n"
+    "  0 0 1 0 360 arc\n"
+    "  setmatrix\n"
+    "} bind def\n"
+    "\n"
+    "/endpage { showpage } bind def\n"
+    "/showpage { } def\n"
+    "\n"
+    "/layercolorseq\n"
+    "  [       % layer color sequence - darkest to lightest\n"
+    "          [0 0 0]\n"
+    "          [.2 .8 .8]\n"
+    "          [.4 .8 .8]\n"
+    "          [.6 .8 .8]\n"
+    "          [.8 .8 .8]\n"
+    "  ]\n"
+    "def\n"
+    "\n"
+    "/layerlen layercolorseq length def\n"
+    "\n"
+    "/setlayer {/maxlayer exch def /curlayer exch def\n"
+    "  layercolorseq curlayer 1 sub layerlen mod get\n"
+    "  aload pop sethsbcolor\n"
+    "  /nodecolor {nopcolor} def\n"
+    "  /edgecolor {nopcolor} def\n"
+    "  /graphcolor {nopcolor} def\n"
+    "} bind def\n"
+    "\n"
+    "/onlayer { curlayer ne {invis} if } def\n"
+    "\n"
+    "/onlayers {\n"
+    "  /myupper exch def\n"
+    "  /mylower exch def\n"
+    "  curlayer mylower lt\n"
+    "  curlayer myupper gt\n"
+    "  or\n"
+    "  {invis} if\n"
+    "} def\n"
+    "\n"
+    "/curlayer 0 def\n"
+    "\n"
+    "%%EndResource\n"
+    "%%EndProlog\n"
+    "%%BeginSetup\n"
+    "14 default-font-family set_font\n"
+    "% /arrowlength 10 def\n"
+    "% /arrowwidth 5 def\n"
+    "\n"
+    "% make sure pdfmark is harmless for PS-interpreters other than Distiller\n"
+    "/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse\n"
+    "% make '<<' and '>>' safe on PS Level 1 devices\n"
+    "/languagelevel where {pop languagelevel}{1} ifelse\n"
+    "2 lt {\n"
+    "    userdict (<<) cvn ([) cvn load put\n"
+    "    userdict (>>) cvn ([) cvn load put\n"
+    "} if\n"
+    "\n"
     "%%EndSetup",
     NULL,
     // clang-format on