-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFMP.hs
146 lines (135 loc) · 5.74 KB
/
FMP.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{- |
Module : FMP
Copyright : (c) 2003-2010 Peter Simons
(c) 2002-2003 Ferenc Wágner
(c) 2002-2003 Meik Hellmund
(c) 1998-2002 Ralf Hinze
(c) 1998-2002 Joachim Korittky
(c) 1998-2002 Marco Kuhlmann
License : GPLv3
Maintainer : [email protected]
Stability : provisional
Portability : portable
-}
{-
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
-}
module FMP
( module FMP.Canvas
, module FMP.Color
, module FMP.Core
, module FMP.File
, module FMP.Frames
, module FMP.Matrix
, module FMP.Picture
, Doc
, module FMP.RedBlack
, module FMP.Resolve
, module FMP.Symbols
, module FMP.Syntax
, module FMP.Term
, module FMP.Tree
, module FMP.Turtle
, module FMP.Types
, metaPost, generate, funcmp
)
where
import FMP.Canvas
import FMP.Color
import FMP.Core
import FMP.File
import FMP.Frames
import FMP.Matrix
import FMP.Picture
import FMP.RedBlack
import FMP.Resolve
import FMP.Symbols
import FMP.Syntax
import FMP.Term
import FMP.Tree
import FMP.Turtle
import FMP.Types
import Paths_funcmp (getDataDir)
import System.Exit ( ExitCode(..) )
import System.FilePath ( combine )
import System.Process ( system )
import Text.PrettyPrint
-- Hauptkonvertierungsfunktion
--
-- ( wferi
--
-- This function is a simple wrapper containing some definitions and
-- default settings. Starts the Nth figure with PARAMs by translating
-- picture T via |mp|.
--
-- wferi )
metaPost :: Int -> Picture -> Parameters -> MetaPost
metaPost n t param = MPVerbatim "batchmode;"
& MPVerbatim (prolog param)
& MPFigure n (MPAssign (Id "warningcheck") 0
& MPVerbatim "picture p[], q[], r[];"
& MPVerbatim "transform t[],tr[];"
& MPVerbatim "pair s[];"
& MPVerbatim "pair pv[][];"
& MPVerbatim "pair pvi[][];"
& MPVerbatim "numeric nv[][];"
& MPVerbatim "numeric nvi[][];"
& MPVerbatim "path tempPath;"
-- & MPVerbatim "pickup pencircle scaled 1;"
& MPAssign defDX (Const (defaultDX param))
& MPAssign defDY (Const (defaultDY param))
& MPAssign txtDX (Const (textDX param))
& MPAssign txtDY (Const (textDY param))
& l & z)
& MPVerbatim (epilog param)
where (_, _, l, z ) = mp t (1, relax)
-- ( wferi
--
-- This is the main entry point. Given a NAME, a NUMBER and a PICTURE it
-- |emit|s a file called NAME.MP (or NAME.NUMBER.MP in not |newmp|) with
-- a beginfig(NUMBER) in it, and runs MetaPost on it. The conversion to
-- |MetaPost|, which |HasEmit|, is done by |metaPost|. Finally, the
-- emitted |Doc| is |show|n.
--
-- wferi )
generate :: IsPicture a => String -> Int -> a -> IO ()
generate prefix n pic = getParameters >>= doOutput
where
filePath = prefix ++ "." ++ show n
fileName param = if newmp param
then prefix ++ ".mp"
else filePath ++ ".mp"
mpDoc param = emit (metaPost n (toPicture pic) param)
doOutput param = do writeFile (fileName param)
(show (mpDoc param))
dataDir <- getDataDir
err <- system ("MPINPUTS=${MPINPUTS}:"
++ combine dataDir "texmf"
++ " " ++ mpBin param ++ " "
++ fileName param
++ " >> /dev/null")
if err==ExitSuccess
then putStr ("\\includegraphics{"
++filePath++"}")
else putStr ("Generation of picture "
++filePath++" failed!")
funcmp :: IsPicture a => String -> Int -> a -> IO ()
funcmp filePath n pic = do param <- getParameters
writeFile cacheName (show picture)
system (funcmpBin param
++ " " ++ filePath
++ " " ++ show n
++ " " ++ funcmpRTS param)
return ()
where
picture = toPicture pic
prefix = filePath ++ "." ++ show n
cacheName = prefix ++ ".cache"