我处理 postscript 对象,我需要转换如下行
109.8516 58.404 moveto
102.7108 70.7583 88.4258 67.3824 82.4704 64.0235 curveto
或者
109.8516 58.404 m
102.7108 70.7583 88.4258 67.3824 82.4704 64.0235 c
以 PGF/TikZ 格式。我有 20,000 行,而且我还需要使用尽可能少的字符。一个好的解决方案是避免使用括号并保留空格。实际上,我使用以下代码:
\def\p#1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\m #1 #2 {\pgfpathmoveto{\p{#1}{#2}}}%
\def\l #1 #2 {\pgfpathlineto{\p{#1}{#2}}}%
\def\c #1 #2 #3 #4 #5 #6 {\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
和
\m 109.8516 58.404
\c 102.7108 70.7583 88.4258 67.3824 82.4704 64.0235
问题:我需要在每行末尾使用空格,我想避免这个空格。此外,我不确定我的代码是否正确。
补充:我的想法是创建一个版本的 向量PGF/TikZ 的软件包。我正在将文件转换psvectorian.pro
为文件pgflibraryvectorian.code.tex
。所有矢量装饰都是用 pgf 基本层创建的。也许这不是一个好主意,我可能会尝试压缩这个文件。我的项目在这里:向量
答案1
我将重新格式化内容pgflibraryvectorian.code.tex
如下:
\makeatletter
\def\pgf@@vectorian@p#1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\pgf@@vectorian@m #1 #2Z{\pgfpathmoveto{\p{#1}{#2}}}%
\def\pgf@@vectorian@l #1 #2Z{\pgfpathlineto{\p{#1}{#2}}}%
\def\pgf@@vectorian@c #1 #2 #3 #4 #5 #6Z{%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%
\def\pgf@@vectorian#1{%
\begingroup
\let\p\pgf@@vectorian@p
\let\m\pgf@@vectorian@m
\let\l\pgf@@vectorian@l
\let\c\pgf@@vectorian@c
\@nameuse{pgf@@vectorian@#1}%
\endgroup}
\@namedef{pgf@@vectorian@1}{%
%def\@pgfvectorianX{136}\def\@pgfvectorianY{107}% vec1
\m 109.8516 58.404Z
\c 102.7108 70.7583 88.4258 67.3824 82.4704 64.0235Z
\c 76.5236 60.6518 72.9472 60.6518 69.3794 75.2496Z
\c 65.7988 89.856 49.1309 90.9713 38.418 90.9713Z
\c 27.7056 90.9713 32.4678 106.6973 32.4678 106.6973Z
\c 9.8485 79.7409 25.3228 66.2628 38.418 62.8953Z
\c 51.5219 59.5279 49.2228 58.0494 34.8502 49.4172Z
\c 21.7545 41.5499 27.7056 31.4434 24.1335 19.0934Z
...
\c 87.4827 79.2025 91.3928 77.6427 105.0731 80.4119Z
\pgfpathclose
\pgfusepath{fill,stroke}}
\@namedef{pgf@@vectorian@2}{%
%def\@pgfvectorianX{133}\def\@pgfvectorianY{48}% vec2
\m 132.9548 23.3771Z
\c 131.3683 31.9185 119.1886 48.1506 83.3983 47.7588Z
...
\pgfpathclose
\pgfusepath{fill,stroke}}
...
\makeatother
\endinput
\ifcase
这避免了在一个宏中出现巨大的问题以及用不可见的最终空格\l
终止\m
和\c
宏参数的问题。