Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I try to create some symbols from bc-logo with pgf. These symbols are defined in .mps file. I have some difficulties with

  0 0.19284 dtransform truncate idtransform setlinewidth 
  pop [] 0 setdash 1 setlinejoin
  10 setmiterlimit   

I understand some parts but I can't translate this expression with some commands from th system base layer of pgf.

About these functions : for example it's possible to write and the to compile with pdflatex:

  \includegraphics[height=3in]{/Users/ego/Desktop/latex/bclogo/latex/bc-dfrance.mps}

You can find this file here : bc-logo So I suppose that the postscript functions used in the bc-dfrance.mps are also PDF functions.

Another function that I found in this file is rlineto. I would like to know if there is an equivalent function in the basic layer of PGF (not in tikz because we can use relative coordinates)

Here a part of my work, I can't use something like scale=2 for example because \pgfsetlinewidth{10pt} are never modified. I think the code below is useful to set up the line width. I need to do the same thing with \pgflinewidth. Is it correct ?

\documentclass{scrartcl}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[dvipsnames]{xcolor} 
\usepackage{tikz}
 \begin{document}

\includegraphics[height=3in]{/Users/ego/Desktop/latex/bclogo/latex/bc-dfrance.mps}

\begin{tikzpicture}[scale=10]
\def\i{\pgfusepath{clip}}
\let\o\pgfpathclose
\let\s\pgfusepathqfillstroke
\def\f{\pgfusepath{fill}}
\def\p #1#2{\pgfqpoint{#1bp}{#2bp}}
\def\m #1 #2 {\pgfpathmoveto{\p{#1}{#2}}}
\def\r #1 #2 #3 #4 {\pgfpathrectangle{\p{#1}{#2}}{\p{#3}{#4}}} 
\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}}}% 
\definecolor{cola}{rgb}{0,0.13672,0.58203} 
\definecolor{colb}{rgb}{1,1,1}  
\definecolor{colc}{rgb}{ 0.92578,0.16016,0.22266}
\definecolor{cold}{rgb}{ 0,0,0}      
\m 69.29587 697.21698 
\l 86.23233 697.21698
\l 86.23233 676.1185
\l 69.29587 676.1185
\i   
\m 69.68298 690.30095
\l 69.68298 695.78268
\l 70.17444 695.84264
\l 70.63571 695.88812
\l 71.07422 695.91524
\l 71.4901 695.92976
\l 71.88321 695.93361
\l 72.25758 695.92297
\l 72.60909 695.90366
\l 72.94183 695.87366
\l 73.25937 695.832
\l 73.55804 695.78268
\l 73.84538 695.72556
\l 74.11375 695.66171
\l 74.37468 695.59395
\l 74.62419 695.52135
\l 74.86237 695.44586
\l 75.0929 695.36263
\l 75.31598 695.28323
\l 75.53151 695.19711
\l 75.71677 695.12451
\l 75.71677 684.15721
\l 75.53151 684.2288 
\l 75.31598 684.31204
\l 75.0929 684.39526
\l 74.86237 684.4785
\l 74.62419 684.554
\l 74.37468 684.62659
\l 74.11375 684.69435
\l 73.84538 684.75821
\l 73.55804 684.81532
\l 73.25937 684.86472
\l 72.94183 684.90245
\l 72.60909 684.93631
\l 72.25758 684.95467
\l 71.88321 684.96631
\l 71.4901 684.96242
\l 71.07422 684.94794
\l 70.63571 684.91693
\l 70.17444 684.87534
\l 69.68298 684.81532
\pgfsetfillcolor{cola}%
\o   
\f
\m 75.72807 689.63504
\l 75.74318 695.11388
\l 75.95117 695.03065
\l 76.15906 694.95132
\l 76.36316 694.87193
\l 76.56737 694.79259
\l 76.77525 694.72
\l 76.98703 694.65614
\l 77.19867 694.59222
\l 77.41798 694.539
\l 77.64485 694.49352
\l 77.87924 694.45193
\l 78.1212 694.42577
\l 78.37448 694.40639
\l 78.6391 694.40254
\l 78.91888 694.40639
\l 79.20999 694.42577
\l 79.51622 694.45576
\l 79.83754 694.50516
\l 80.1816 694.56902
\l 80.54076 694.64835
\l 80.65031 694.67451
\l 80.65031 683.70715
\l 80.54076 683.68105
\l 80.1816 683.59781
\l 79.83754 683.5378
\l 79.51622 683.48848
\l 79.20999 683.45456
\l 78.91888 683.43909
\l 78.6391 683.43135
\l 78.37448 683.43909
\l 78.1212 683.45847
\l 77.87924 683.48457
\l 77.64485 683.52232
\l 77.41798 683.5717
\l 77.19867 683.62392
\l 76.98703 683.68494
\l 76.77525 683.75264
\l 76.56737 683.82524
\l 76.36316 683.90463
\l 76.15906 683.98012
\l 75.95117 684.06335
\l 75.71677 684.15721
\pgfsetfillcolor{colb}%
\o
\f  
\m 80.65031 689.19278
\l 80.65031 694.67451
\l 80.92256 694.74321
\l 81.3271 694.86035
\l 81.75052 694.9958
\l 82.20036 695.15163
\l 82.67673 695.32872
\l 83.1795 695.52519
\l 83.70882 695.74878
\l 84.26831 695.99463
\l 84.85811 696.2627
\l 85.48186 696.55788
\l 86.13591 696.88306
\l 86.13591 685.91187
\l 85.48186 685.59058
\l 84.85811 685.29533
\l 84.26831 685.02344
\l 83.70882 684.78148
\l 83.1795 684.55789
\l 82.67673 684.36142
\l 82.20036 684.18433
\l 81.75052 684.0285
\l 81.3271 683.89299
\l 80.92256 683.77591
\l 80.65031 683.70715
\pgfsetfillcolor{colc}%
\o 
\f
\pgfsetlinewidth{2pt}% this is a problem when i scale the picture  
\m 69.68298 690.30095
\l 69.68298 695.78268
\l 70.17444 695.84264
\l 70.63571 695.88812
\l 71.07422 695.91524
\l 71.4901 695.92976
\l 71.88321 695.93361
\l 72.25758 695.92297
\l 72.60909 695.90366
\l 72.94183 695.87366
\l 73.25937 695.832
\l 73.55804 695.78268
\l 73.84538 695.72556
\l 74.11375 695.66171
\l 74.37468 695.59395
\l 74.62419 695.52135
\l 74.86237 695.44586
\l 75.0929 695.36263
\l 75.31598 695.28323
\l 75.53151 695.19711
\l 75.74318 695.11388
\l 75.95117 695.03065
\l 76.15906 694.95132
\l 76.36316 694.87193
\l 76.56737 694.79259
\l 76.77525 694.72
\l 76.98703 694.65614
\l 77.19867 694.59222
\l 77.41798 694.539
\l 77.64485 694.49352
\l 77.87924 694.45193
\l 78.1212 694.42577
\l 78.37448 694.40639
\l 78.6391 694.40254
\l 78.91888 694.40639
\l 79.20999 694.42577
\l 79.51622 694.45576
\l 79.83754 694.50516
\l 80.1816 694.56902
\l 80.54076 694.64835
\l 80.92256 694.74321
\l 81.3271 694.86035 
\l 81.75052 694.9958 
\l 82.20036 695.15163
\l 82.67673 695.32872
\l 83.1795 695.52519
\l 83.70882 695.74878
\l 84.26831 695.99463
\l 84.85811 696.2627
\l 85.48186 696.55788
\l 86.13591 696.88306
\l 86.13591 685.91187
\l 85.48186 685.59058
\l 84.85811 685.29533
\l 84.26831 685.02344
\l 83.70882 684.78148
\l 83.1795 684.55789 
\l 82.67673 684.36142
\l 82.20036 684.18433
\l 81.75052 684.0285 
\l 81.3271 683.89299 
\l 80.92256 683.77591
\l 80.54076 683.68105
\l 80.1816 683.59781
\l 79.83754 683.5378
\l 79.51622 683.48848
\l 79.20999 683.45456
\l 78.91888 683.43909
\l 78.6391 683.43135 
\l 78.37448 683.43909
\l 78.1212 683.45847 
\l 77.87924 683.48457
\l 77.64485 683.52232
\l 77.41798 683.5717
\l 77.19867 683.62392
\l 76.98703 683.68494
\l 76.77525 683.75264
\l 76.56737 683.82524
\l 76.36316 683.90463
\l 76.15906 683.98012
\l 75.95117 684.06335
\l 75.74318 684.14658
\l 75.53151 684.2288
\l 75.31598 684.31204
\l 75.0929 684.39526
\l 74.86237 684.4785
\l 74.62419 684.554
\l 74.37468 684.62659
\l 74.11375 684.69435
\l 73.84538 684.75821
\l 73.55804 684.81532
\l 73.25937 684.86472
\l 72.94183 684.90245
\l 72.60909 684.93631
\l 72.25758 684.95467
\l 71.88321 684.96631
\l 71.4901 684.96242
\l 71.07422 684.94794
\l 70.63571 684.91693
\l 70.17444 684.87534
\l 69.68298 684.81532
\pgfsetfillcolor{cold}%   
\pgfusepath{stroke}%  
\pgfsetlinewidth{10pt}% not fine big problem when I scale
\m 69.68298 676.50563 
\l 69.68298 696.82983
\pgfusepath{stroke}   
\end{tikzpicture}
\end{document} 

enter image description here

Because I don't understand some functions, I get a problem with the width of the lines. I can't scale properly the flag. I can find a personal method but it will be more easy to translate directly the postscript functions with pgf commands.

share|improve this question
3  
The translation of those commands to pdf is done by Hans' context module (even under latex) so you might find /texmf-dist/tex/context/base/supp-pdf.mkii, that may be a useful starting point if you wanted to parse mpost output to something othetr than pdf (tikz code for example:-) –  David Carlisle Jun 1 '12 at 8:24
    
Also the postscript reference manual is available now eg dtransform is on page 574 of adobe.com/products/postscript/pdfs/PLRM.pdf it translates the specified vector by the current transformation matrix in the graphics state. –  David Carlisle Jun 1 '12 at 8:34

2 Answers 2

up vote 3 down vote accepted

dtransform (delta transformation) converts coordinates (as distance vector) from user into system coordinates, eg 1 1 dtransform => -1.20570683 1.20570683. It uses the default transformation matrix [1.20570683 0.0 0.0 -1.20570683 0.0 954.0].

truncate cuts the decimal part of the upper stack value but let it be a real, eg: 1.11 truncate => 1.0

idtransform (inverse delta transformation) the opposite to dtransform, eg: -1.20570683 1.20570683 idtransform => 1 1

setmiterlimit if 0 setlinejoin then there can be a problem if the two lines build an angle less than 15 degrees. With 10 setmiterlimit the lines are cut (which is 2 setlinejoin) if the angle is less than 10 degrees.

share|improve this answer

If we go through the commands step by step

  0 0.19284 dtransform truncate idtransform setlinewidth 
  pop [] 0 setdash 1 setlinejoin
  10 setmiterlimit   

We take the coordinate (0,0.19284) and apply current transformation matrix without the translation part i.e. it would be equal to applying \pgftransform{a}{b}{c}{d}{\pgfpointorigin}. Then the resulting coordinate would be (a.decimals, b.decimals) and since y coordinate is higher on the stack it gets truncated i.e. the result would be (a.decimals,b). After that we apply the inverse coordinate transform to get (c,d). Again y coordinate would be used as the line width specification.

Note however that d=0 is allowed and it is mapped to 1px line width. Now I don't know whether this is possible with TikZ but zero can be mapped to a very thin line as a workaround.

Then since the y coordinate is used we are left with a single number on the stack and it is discarded by the pop command. setdash command requires an array and an offset to set up a dash pattern very much like TikZ hence the empty array and 0 sets a solid line.

1 setlinejoin sets the equivalent of line join=round in TikZ and 10 setmiterlimit is, as far as I know, not available in TikZ. It basically checks if the miter join is causing a too sharp corner that results with a thick corner. The manual has a nice formula on page 690.


Why would one wants to do this for a clip-art? The reason, as you have mentioned in the code, is probably dynamic line width scaling. Consider for example the following two simple cases:

\begin{tikzpicture}[scale=0.1]
\pgfgettransformentries{\mya}{\myb}{\myc}{\myd}{\myshiftx}{\myshifty}
\draw[fill=yellow,line width=\myd*0.05mm,draw=blue] (0,0) -- (0,1)  -- (1,1) -- cycle;
\draw[fill=yellow,line width=0.05mm,draw=blue] (1.5,0) -- (1.5,1)  -- (2.5,1) -- cycle;
\node[transform shape] at (1,1.5) {Scale = \myd};
\end{tikzpicture}

This gives enter image description here

But if we change the scaling to 10 with identical code we get

\begin{tikzpicture}[scale=0.1]
\pgfgettransformentries{\mya}{\myb}{\myc}{\myd}{\myshiftx}{\myshifty}
\draw[fill=yellow,line width=\myd*0.05mm,draw=blue] (0,0) -- (0,1)  -- (1,1) -- cycle;
\draw[fill=yellow,line width=0.05mm,draw=blue] (1.5,0) -- (1.5,1)  -- (2.5,1) -- cycle;
\node[transform shape] at (1,1.5) {Scale = \myd};
\end{tikzpicture}

enter image description here

I have taken arbitrarily the yscale as a variable but we can indeed take a coordinate and multiply the entries with the transformation entries to see where it goes after the transformation and I chose 0.05mm initially since it is roughly 0.19284pt as the authors use to adjust with the PS code. So we can see that once it was too thick becomes too thin compared to the dynamically scaled one depending on the scale range. One can also add a min or max case for mapping zero line width =1px of PS to a nonzero minimum line width of TikZ say 0.01pt.

Here are two results side by side (PS left - Tikz right): For scale = 10,1 and also 0.1 with zoomed in version. The 1px effect is visible as the left one has a thin pole.

enter image description here enter image description here enter image description here

rlinetocan be done via moving to a point as usual and then adding the relative point to the last known point as

\pgfpathmoveto{\pgfpoint{2cm}{4cm}}
\pgfgetlastxy{\macrox}{\macroy} 
\pgfpathlineto{\pgfpointadd{\pgfpoint{\macrox}{\macroy}}{\pgfpoint{1cm}{-1cm}}}
\pgfusepath{stroke} 

This would would draw the equivalent of \draw (2,4) -- ++ (1,-1)

share|improve this answer
    
Thanks because there are important remarks between PS ans PGF. I accept Herbert's answer because he was the first to give the informations. I found another way to scale the line width with \pgfsetlinewidth{0.8pt}\pgflowlevelsynccm and a tex's group. –  Alain Matthes Jun 4 '12 at 13:48
    
@Altermundus No problem, it's my pleasure. –  percusse Jun 4 '12 at 15:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.