summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenningThielemann <>2018-01-12 19:04:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-01-12 19:04:00 (GMT)
commitc197071859ba8eb0445625aca79702691558a438 (patch)
tree14be081cf1254ec6515c06f089780e55dd95b1d9
parentc346a1b037bf85b5cef2d830f43847e5055f7544 (diff)
version 0.5.50.5.5
-rw-r--r--Changes.md7
-rw-r--r--gnuplot.cabal7
-rw-r--r--src/Graphics/Gnuplot/Encoding.hs53
-rw-r--r--src/Graphics/Gnuplot/Private/Encoding.hs11
-rw-r--r--src/Graphics/Gnuplot/Private/Plot.hs2
-rw-r--r--src/Graphics/Gnuplot/Private/Terminal.hs4
-rw-r--r--src/Graphics/Gnuplot/Terminal/Default.hs1
-rw-r--r--src/Graphics/Gnuplot/Terminal/PNG.hs12
-rw-r--r--src/Graphics/Gnuplot/Terminal/PostScript.hs23
-rw-r--r--src/Graphics/Gnuplot/Terminal/SVG.hs16
-rw-r--r--src/Graphics/Gnuplot/Terminal/WXT.hs1
-rw-r--r--src/Graphics/Gnuplot/Terminal/X11.hs1
-rw-r--r--src/Graphics/Gnuplot/Utility.hs28
13 files changed, 153 insertions, 13 deletions
diff --git a/Changes.md b/Changes.md
new file mode 100644
index 0000000..09c9bed
--- /dev/null
+++ b/Changes.md
@@ -0,0 +1,7 @@
+# Change log for the `gnuplot` Haskell binding
+
+## 0.5.5:
+
+ * `Gnuplot.Utility.quote` bugfix:
+ Do not escape printable non-ASCII characters
+ because gnuplot has no universal escaping support for Unicode codepoints.
diff --git a/gnuplot.cabal b/gnuplot.cabal
index 3fb419f..65dec0c 100644
--- a/gnuplot.cabal
+++ b/gnuplot.cabal
@@ -1,5 +1,5 @@
Name: gnuplot
-Version: 0.5.4.2
+Version: 0.5.5
License: BSD3
License-File: LICENSE
Author: Henning Thielemann <haskell@henning-thielemann.de>
@@ -41,6 +41,7 @@ Cabal-Version: >=1.8
Build-Type: Simple
Extra-Source-Files:
Makefile
+ Changes.md
execute/tmp/Graphics/Gnuplot/Execute.hs
execute/pipe/Graphics/Gnuplot/Execute.hs
execute/shell/Graphics/Gnuplot/Execute.hs
@@ -50,7 +51,7 @@ Data-Files:
data/runtime.data
Source-Repository this
- Tag: 0.5.4.2
+ Tag: 0.5.5
Type: darcs
Location: http://code.haskell.org/gnuplot/
@@ -113,6 +114,7 @@ Library
Graphics.Gnuplot.Terminal.SVG
Graphics.Gnuplot.Terminal.WXT
Graphics.Gnuplot.Terminal.X11
+ Graphics.Gnuplot.Encoding
Graphics.Gnuplot.Frame
Graphics.Gnuplot.Frame.Option
Graphics.Gnuplot.Frame.OptionSet
@@ -144,6 +146,7 @@ Library
Graphics.Gnuplot.Private.Graph3DType
Graphics.Gnuplot.Private.GraphEmpty
Graphics.Gnuplot.Private.Terminal
+ Graphics.Gnuplot.Private.Encoding
Graphics.Gnuplot.Private.Display
Graphics.Gnuplot.Private.File
Graphics.Gnuplot.Private.Command
diff --git a/src/Graphics/Gnuplot/Encoding.hs b/src/Graphics/Gnuplot/Encoding.hs
new file mode 100644
index 0000000..1a503ca
--- /dev/null
+++ b/src/Graphics/Gnuplot/Encoding.hs
@@ -0,0 +1,53 @@
+{- |
+Support for special characters
+
+Gnuplot has no universal Unicode escaping mechanism,
+you can only work with encodings.
+However, not all terminals support all encodings,
+not all terminals even support utf-8.
+Some terminals seem to support only one encoding.
+E.g. WX seems to support only UTF-8,
+X11 seems to support only Latin-1.
+Postscript, SVG, PNG seem to support both UTF-8 and Latin-1.
+
+The @gnuplot@ Haskell bindings
+always write using the system-wide default encoding.
+Thus it is better not to set an encoding other than 'locale' explicitly.
+However, if you write the files yourself in a certain encoding
+you should use the @encoding@ option of the according terminal.
+-}
+module Graphics.Gnuplot.Encoding (
+ T,
+ locale, deflt,
+ iso_8859_1, iso_8859_15, iso_8859_2, iso_8859_9,
+ koi8r, koi8u,
+ cp437, cp850, cp852, cp950, cp1250, cp1251, cp1254,
+ sjis, utf8,
+ ) where
+
+import Graphics.Gnuplot.Private.Encoding (T(Cons))
+
+
+locale, deflt,
+ iso_8859_1, iso_8859_15, iso_8859_2, iso_8859_9,
+ koi8r, koi8u,
+ cp437, cp850, cp852, cp950, cp1250, cp1251, cp1254,
+ sjis, utf8 :: T
+
+locale = Cons "locale"
+deflt = Cons "default"
+iso_8859_1 = Cons "iso_8859_1"
+iso_8859_15 = Cons "iso_8859_15"
+iso_8859_2 = Cons "iso_8859_2"
+iso_8859_9 = Cons "iso_8859_9"
+koi8r = Cons "koi8r"
+koi8u = Cons "koi8u"
+cp437 = Cons "cp437"
+cp850 = Cons "cp850"
+cp852 = Cons "cp852"
+cp950 = Cons "cp950"
+cp1250 = Cons "cp1250"
+cp1251 = Cons "cp1251"
+cp1254 = Cons "cp1254"
+sjis = Cons "sjis"
+utf8 = Cons "utf8"
diff --git a/src/Graphics/Gnuplot/Private/Encoding.hs b/src/Graphics/Gnuplot/Private/Encoding.hs
new file mode 100644
index 0000000..5616245
--- /dev/null
+++ b/src/Graphics/Gnuplot/Private/Encoding.hs
@@ -0,0 +1,11 @@
+module Graphics.Gnuplot.Private.Encoding where
+
+import Graphics.Gnuplot.Utility (listFromMaybeWith)
+
+newtype T = Cons String
+
+format :: T -> String
+format (Cons enc) = "set encoding " ++ enc
+
+formatMaybe :: Maybe T -> [String]
+formatMaybe = listFromMaybeWith format
diff --git a/src/Graphics/Gnuplot/Private/Plot.hs b/src/Graphics/Gnuplot/Private/Plot.hs
index b2ee4e6..b5048d5 100644
--- a/src/Graphics/Gnuplot/Private/Plot.hs
+++ b/src/Graphics/Gnuplot/Private/Plot.hs
@@ -23,7 +23,7 @@ import Data.Function (($), (.), )
import qualified System.FilePath as Path
import System.FilePath (FilePath, (</>), )
-import Prelude (Functor, fmap, String, show, Int, succ, writeFile, undefined, )
+import Prelude (Functor, fmap, String, show, Int, succ, writeFile, )
{- |
diff --git a/src/Graphics/Gnuplot/Private/Terminal.hs b/src/Graphics/Gnuplot/Private/Terminal.hs
index 88fdc23..0dd6428 100644
--- a/src/Graphics/Gnuplot/Private/Terminal.hs
+++ b/src/Graphics/Gnuplot/Private/Terminal.hs
@@ -2,6 +2,7 @@ module Graphics.Gnuplot.Private.Terminal where
data T =
Cons {
+ precommands :: [String],
options :: [String],
commands :: [String],
interactive :: Bool
@@ -11,7 +12,8 @@ class C terminal where
canonical :: terminal -> T
format :: T -> [String]
-format (Cons opts cmds _ia) =
+format (Cons pre opts cmds _ia) =
+ pre ++
if null opts
then cmds
else (unwords $ "set" : "terminal" : opts) : cmds
diff --git a/src/Graphics/Gnuplot/Terminal/Default.hs b/src/Graphics/Gnuplot/Terminal/Default.hs
index b3fb0f9..e8e72db 100644
--- a/src/Graphics/Gnuplot/Terminal/Default.hs
+++ b/src/Graphics/Gnuplot/Terminal/Default.hs
@@ -14,6 +14,7 @@ cons = Cons
instance Terminal.C T where
canonical _term =
Terminal.Cons {
+ Terminal.precommands = [],
Terminal.options = [],
Terminal.commands = [],
Terminal.interactive = True -- Always true? I don't know.
diff --git a/src/Graphics/Gnuplot/Terminal/PNG.hs b/src/Graphics/Gnuplot/Terminal/PNG.hs
index 505fa4a..cb1540f 100644
--- a/src/Graphics/Gnuplot/Terminal/PNG.hs
+++ b/src/Graphics/Gnuplot/Terminal/PNG.hs
@@ -1,5 +1,6 @@
module Graphics.Gnuplot.Terminal.PNG (
T, cons,
+ encoding,
transparent, noTransparent,
interlace, noInterlace,
trueColor, noTrueColor,
@@ -7,6 +8,7 @@ module Graphics.Gnuplot.Terminal.PNG (
) where
import qualified Graphics.Gnuplot.Private.Terminal as Terminal
+import qualified Graphics.Gnuplot.Private.Encoding as Encoding
import Data.Maybe (catMaybes, )
import Graphics.Gnuplot.Utility (quote, formatBool, )
@@ -14,6 +16,7 @@ import Graphics.Gnuplot.Utility (quote, formatBool, )
data T =
Cons {
filename_ :: FilePath,
+ encoding_ :: Maybe Encoding.T,
transparent_ :: Maybe Bool,
interlace_ :: Maybe Bool,
trueColor_ :: Maybe Bool,
@@ -24,6 +27,7 @@ cons :: FilePath -> T
cons path =
Cons {
filename_ = path,
+ encoding_ = Nothing,
transparent_ = Nothing,
interlace_ = Nothing,
trueColor_ = Nothing,
@@ -31,6 +35,13 @@ cons path =
}
+{- |
+Setting the encoding to anything different
+from 'Graphics.Gnuplot.Encoding.locale'
+makes only sense if you write your gnuplot files manually using this encoding.
+-}
+encoding :: Encoding.T -> T -> T
+encoding enc term = term{encoding_ = Just enc}
transparent, noTransparent :: T -> T
transparent term = term{transparent_ = Just True}
@@ -77,6 +88,7 @@ setFontSize size term =
instance Terminal.C T where
canonical term =
Terminal.Cons {
+ Terminal.precommands = Encoding.formatMaybe $ encoding_ term,
Terminal.options =
"png" :
catMaybes (
diff --git a/src/Graphics/Gnuplot/Terminal/PostScript.hs b/src/Graphics/Gnuplot/Terminal/PostScript.hs
index fa69a4f..ffb4c55 100644
--- a/src/Graphics/Gnuplot/Terminal/PostScript.hs
+++ b/src/Graphics/Gnuplot/Terminal/PostScript.hs
@@ -1,18 +1,21 @@
module Graphics.Gnuplot.Terminal.PostScript (
T, cons,
+ encoding,
landscape, portrait, eps,
color, monochrome,
font, embedFont,
) where
import qualified Graphics.Gnuplot.Private.Terminal as Terminal
-import Graphics.Gnuplot.Utility (quote, )
-import Data.Maybe (maybeToList, )
+import qualified Graphics.Gnuplot.Private.Encoding as Encoding
+import Graphics.Gnuplot.Utility (listFromMaybeWith, quote, )
+import Data.Foldable (foldMap, )
data T =
Cons {
filename_ :: FilePath,
+ encoding_ :: Maybe Encoding.T,
mode_ :: Maybe Mode,
color_ :: Maybe Bool,
embedFont_ :: [FilePath],
@@ -23,6 +26,7 @@ cons :: FilePath -> T
cons path =
Cons {
filename_ = path,
+ encoding_ = Nothing,
mode_ = Nothing,
color_ = Nothing,
embedFont_ = [],
@@ -30,6 +34,14 @@ cons path =
}
+{- |
+Setting the encoding to anything different
+from 'Graphics.Gnuplot.Encoding.locale'
+makes only sense if you write your gnuplot files manually using this encoding.
+-}
+encoding :: Encoding.T -> T -> T
+encoding enc term = term{encoding_ = Just enc}
+
landscape :: T -> T
landscape = setMode Landscape
@@ -83,12 +95,13 @@ setMode mode term = term{mode_ = Just mode}
instance Terminal.C T where
canonical term =
Terminal.Cons {
+ Terminal.precommands = Encoding.formatMaybe $ encoding_ term,
Terminal.options =
"postscript" :
- (maybeToList $ fmap formatMode $ mode_ term) ++
- (maybeToList $ fmap (\b -> if b then "color" else "monochrome") $ color_ term) ++
+ (listFromMaybeWith formatMode $ mode_ term) ++
+ (listFromMaybeWith (\b -> if b then "color" else "monochrome") $ color_ term) ++
(concatMap (\path -> "fontfile" : quote path : []) $ embedFont_ term) ++
- (maybe [] (\(name,size) -> "font" : quote name : show size : []) $ font_ term) ++
+ (foldMap (\(name,size) -> "font" : quote name : show size : []) $ font_ term) ++
[],
Terminal.commands =
["set output " ++ (quote $ filename_ term)],
diff --git a/src/Graphics/Gnuplot/Terminal/SVG.hs b/src/Graphics/Gnuplot/Terminal/SVG.hs
index 2e8e085..3d49450 100644
--- a/src/Graphics/Gnuplot/Terminal/SVG.hs
+++ b/src/Graphics/Gnuplot/Terminal/SVG.hs
@@ -1,22 +1,33 @@
module Graphics.Gnuplot.Terminal.SVG (
T, cons,
+ encoding,
) where
import qualified Graphics.Gnuplot.Private.Terminal as Terminal
+import qualified Graphics.Gnuplot.Private.Encoding as Encoding
import Graphics.Gnuplot.Utility (quote, )
data T =
Cons {
- filename_ :: FilePath
+ filename_ :: FilePath,
+ encoding_ :: Maybe Encoding.T
}
cons :: FilePath -> T
cons path =
Cons {
- filename_ = path
+ filename_ = path,
+ encoding_ = Nothing
}
+{- |
+Setting the encoding to anything different
+from 'Graphics.Gnuplot.Encoding.locale'
+makes only sense if you write your gnuplot files manually using this encoding.
+-}
+encoding :: Encoding.T -> T -> T
+encoding enc term = term{encoding_ = Just enc}
-- private functions
@@ -24,6 +35,7 @@ cons path =
instance Terminal.C T where
canonical term =
Terminal.Cons {
+ Terminal.precommands = Encoding.formatMaybe $ encoding_ term,
Terminal.options =
"svg" :
[],
diff --git a/src/Graphics/Gnuplot/Terminal/WXT.hs b/src/Graphics/Gnuplot/Terminal/WXT.hs
index 58365ae..5cd46dc 100644
--- a/src/Graphics/Gnuplot/Terminal/WXT.hs
+++ b/src/Graphics/Gnuplot/Terminal/WXT.hs
@@ -41,6 +41,7 @@ noPersist term = term{persist_ = Just False}
instance Terminal.C T where
canonical term =
Terminal.Cons {
+ Terminal.precommands = [],
Terminal.options =
"wxt" :
catMaybes (
diff --git a/src/Graphics/Gnuplot/Terminal/X11.hs b/src/Graphics/Gnuplot/Terminal/X11.hs
index a0faa63..4195871 100644
--- a/src/Graphics/Gnuplot/Terminal/X11.hs
+++ b/src/Graphics/Gnuplot/Terminal/X11.hs
@@ -37,6 +37,7 @@ noPersist term = term{persist_ = Just False}
instance Terminal.C T where
canonical term =
Terminal.Cons {
+ Terminal.precommands = [],
Terminal.options =
"x11" :
catMaybes (
diff --git a/src/Graphics/Gnuplot/Utility.hs b/src/Graphics/Gnuplot/Utility.hs
index f3de4a1..c9af417 100644
--- a/src/Graphics/Gnuplot/Utility.hs
+++ b/src/Graphics/Gnuplot/Utility.hs
@@ -1,5 +1,8 @@
module Graphics.Gnuplot.Utility where
+import Text.Printf (printf, )
+
+import qualified Data.Char as Char
import Data.List (intersperse, )
@@ -22,8 +25,26 @@ commaConcat = concat . intersperse ", "
semiColonConcat = concat . intersperse "; "
-quote :: String -> String
-quote = show
+{-
+In former versions this was simply 'show'.
+However, Haskell formats non-ASCII characters with decimal backslash sequences
+whereas gnuplot expects octal ones.
+gnuplot does also not accept bigger octal numbers.
+The current version writes non-ASCII printable characters
+with the system default encoding.
+-}
+quote, _quote :: String -> String
+quote str = '"' : foldr (++) "\"" (map escapeChar str)
+_quote str = '"' : concatMap escapeChar str ++ "\""
+
+escapeChar :: Char -> String
+escapeChar c =
+ case c of
+ '"' -> "\\\""
+ '\\' -> "\\\\"
+ '\t' -> "\\t"
+ '\n' -> "\\n"
+ _ -> if Char.isPrint c then [c] else printf "\\%o" $ Char.ord c
assembleCells :: [[ShowS]] -> String
assembleCells ps =
@@ -35,6 +56,9 @@ assembleCells ps =
ps)
+listFromMaybeWith :: (a -> b) -> Maybe a -> [b]
+listFromMaybeWith f = maybe [] ((:[]) . f)
+
formatBool :: String -> Bool -> String
formatBool name b =
if b then name else "no"++name