HPDF 1.6.1 → 1.6.2
raw patch · 12 files changed
+178/−212 lines, 12 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Graphics/PDF/Colors.hs +40/−40
- Graphics/PDF/Documentation.hs +26/−24
- Graphics/PDF/Draw.hs +14/−15
- Graphics/PDF/LowLevel/Serializer.hs +7/−21
- Graphics/PDF/Pattern.hs +27/−27
- Graphics/PDF/Shading.hs +4/−4
- Graphics/PDF/Shapes.hs +26/−26
- Graphics/PDF/Text.hs +26/−26
- HPDF.cabal +1/−7
- cbits/conversion.c +0/−17
- cbits/conversion.h +0/−5
- changelog.md +7/−0
Graphics/PDF/Colors.hs view
@@ -58,10 +58,10 @@ alphaMap <- gets strokeAlphas (newName,newMap) <- setResource "ExtGState" (StrokeAlpha alpha) alphaMap modifyStrict $ \s -> s { strokeAlphas = newMap }- tell . mconcat $[ serialize "\n/" - , serialize newName- , serialize " gs"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newName+ , serialize " gs"+ ] -- | Set alpha value for transparency setFillAlpha :: Double -> Draw ()@@ -69,10 +69,10 @@ alphaMap <- gets fillAlphas (newName,newMap) <- setResource "ExtGState" (FillAlpha alpha) alphaMap modifyStrict $ \s -> s { fillAlphas = newMap }- tell . mconcat $[ serialize "\n/" - , serialize newName- , serialize " gs"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newName+ , serialize " gs"+ ] -- | Init the PDF color space to RGB. setRGBColorSpace :: Draw ()@@ -84,46 +84,46 @@ fillColor :: MonadPath m => Color -- ^ Filling color -> m () fillColor (Rgb r g b) = do- tell . mconcat $[ serialize "\n"- , toPDF r- , serialize ' '- , toPDF g- , serialize ' '- , toPDF b- , serialize " rg" - ]+ tell . mconcat $ [ serialize "\n"+ , toPDF r+ , serialize ' '+ , toPDF g+ , serialize ' '+ , toPDF b+ , serialize " rg" + ] fillColor (Hsv h s v) = do let (r,g,b) = hsvToRgb (h,s,v)- tell . mconcat $[ serialize "\n"- , toPDF r- , serialize ' '- , toPDF g- , serialize ' '- , toPDF b- , serialize " rg" - ]+ tell . mconcat $ [ serialize "\n"+ , toPDF r+ , serialize ' '+ , toPDF g+ , serialize ' '+ , toPDF b+ , serialize " rg" + ] -- | Select the drawing color strokeColor :: MonadPath m => Color -- ^ Drawing color -> m () strokeColor (Rgb r g b) = do- tell . mconcat $[ serialize "\n"- , toPDF r- , serialize ' '- , toPDF g- , serialize ' '- , toPDF b- , serialize " RG" - ]+ tell . mconcat $ [ serialize "\n"+ , toPDF r+ , serialize ' '+ , toPDF g+ , serialize ' '+ , toPDF b+ , serialize " RG" + ] strokeColor (Hsv h s v) = do let (r,g,b) = hsvToRgb (h,s,v)- tell . mconcat $[ serialize "\n"- , toPDF r- , serialize ' '- , toPDF g- , serialize ' '- , toPDF b- , serialize " RG" - ]+ tell . mconcat $ [ serialize "\n"+ , toPDF r+ , serialize ' '+ , toPDF g+ , serialize ' '+ , toPDF b+ , serialize " RG" + ]
Graphics/PDF/Documentation.hs view
@@ -45,10 +45,12 @@ So, a standard way to start a PDF document is with: @+{-# LANGUAGE OverloadedStrings #-}+ main :: IO() main = do let rect = 'PDFRect' 0 0 600 400- 'runPdf' \"demo.pdf\" ('standardDocInfo' { author='toPDFString' \"alpheccar\", compressed = False}) rect $ do+ 'runPdf' \"demo.pdf\" ('standardDocInfo' { author=\"alpheccar\", compressed = False}) rect $ do myDocument @ @@ -65,8 +67,8 @@ myDocument :: 'PDF' () myDocument = do page1 <- 'addPage' Nothing- 'newSection' ('toPDFString' \"Section\") Nothing Nothing $ do- 'newSection' ('toPDFString' \"Subsection\") Nothing Nothing $ do+ 'newSection' (\"Section\") Nothing Nothing $ do+ 'newSection' (\"Subsection\") Nothing Nothing $ do createPageContent page1 @ @@ -80,16 +82,16 @@ To create content for a page, you have to use a page reference with 'drawWithPage'. -'drawWithPage' is using a 'Draw' monad value.+'drawWithPage' is using a 'PDF' monad value. -Element of the 'Draw' monad are built with geometry, text and color primitives.+Element of the 'PDF' monad are built with geometry, text and color primitives. @-createPageContent :: 'PDFReference' 'PDFPage' -> Draw ()+createPageContent :: 'PDFReference' 'PDFPage' -> PDF () createPageContent page = 'drawWithPage' page $ do 'strokeColor' 'red' 'setWidth' 0.5- 'stroke' $ 'Rectangle' 10 0 200 300+ 'stroke' $ 'Rectangle' (10 :+ 0) (200 :+ 300) @ -}@@ -99,16 +101,16 @@ Text is complex. You can use the low level 'PDFText' to create a text in the 'Draw' monad. For instance: @-textText :: 'PDFFont' -> 'PDFString' -> 'Draw' ()-textText f t = do+textText :: 'PDFFont' -> 'Text' -> 'Draw' ()+textText theFont@(PDFFont f s) t = do 'drawText' $ do- 'setFont' f+ 'setFont' theFont 'textStart' 10 200.0- 'leading' $ 'getHeight' f+ leading $ getHeight f s 'renderMode' 'FillText' 'displayText' t 'startNewLine'- 'displayText' $ 'toPDFString' \"Another little test\"+ 'displayText' \"Another little test\" @ It gives a detailed control on the position of characters and lines but it is too much work.@@ -118,7 +120,7 @@ Displaying a formatted text is done with 'displayFormattedText' and using a typesetting monad value: @-'displayFormattedText' ('Rectangle' (10 :+ 0) (110 :+ 300)) 'NormalPara' 'Normal' $ do+'displayFormattedText' ('Rectangle' (10 :+ 0) (110 :+ 300)) 'NormalPara' ('Normal' timesRoman) $ do 'paragraph' $ do 'txt' $ \"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \" 'txt' $ \"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \"@@ -134,20 +136,20 @@ @ data MyVertStyles = NormalPara- | CirclePara- | BluePara !PDFFloat+ | CirclePara AnyFont+ | BluePara AnyFont !PDFFloat @ and Normal is part of another algebraic data typec (from file test.hs): @-data MyParaStyles = Normal- | Bold- | Crazy- | SuperCrazy [Int] [PDFFloat]- | DebugStyle- | RedRectStyle- | BlueStyle+data MyParaStyles = Normal AnyFont+ | Bold AnyFont+ | Crazy AnyFont+ | SuperCrazy AnyFont [Int] [PDFFloat]+ | DebugStyle AnyFont+ | RedRectStyle AnyFont+ | BlueStyle AnyFont @ The library is coming with standard styles 'StandardParagraphStyle' and 'StandardStyle'.@@ -172,7 +174,7 @@ The other attributes like distance between two lines etc ... are controlled in the typesetting monad. @-'setParaStyle' (BluePara 0)+'setParaStyle' (BluePara helveticaBold 0) 'setFirstPassTolerance' 500 'unstyledGlue' 6 0.33 0 'paragraph' $ do@@ -319,7 +321,7 @@ display a link: @-'newAnnotation' ('URLLink' ('toPDFString' \"Go to my blog\") [0,0,200,100] \"http:\/\/www.alpheccar.org\" True)+'newAnnotation' ('URLLink' (\"Go to my blog\") [0,0,200,100] \"http:\/\/www.alpheccar.org\" True) @
Graphics/PDF/Draw.hs view
@@ -184,7 +184,6 @@ m >>= f = Draw $ \env -> do a <- unDraw m env unDraw (f a) env- return x = Draw $ \_env -> return x instance MonadReader DrawEnvironment Draw where ask = Draw $ \env -> return (drawEnvironment env)@@ -766,17 +765,17 @@ applyMatrix :: Matrix -> Draw () applyMatrix m@(Matrix a b c d e f) = do multiplyCurrentMatrixWith m- tell . mconcat $[ serialize '\n'- , toPDF a- , serialize ' '- , toPDF b- , serialize ' '- , toPDF c- , serialize ' '- , toPDF d- , serialize ' '- , toPDF e- , serialize ' '- , toPDF f- , serialize " cm"- ]+ tell . mconcat $ [ serialize '\n'+ , toPDF a+ , serialize ' '+ , toPDF b+ , serialize ' '+ , toPDF c+ , serialize ' '+ , toPDF d+ , serialize ' '+ , toPDF e+ , serialize ' '+ , toPDF f+ , serialize " cm"+ ]
Graphics/PDF/LowLevel/Serializer.hs view
@@ -1,5 +1,4 @@ {-# OPTIONS_GHC -fno-cse #-}-{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} ---------------------------------------------------------@@ -17,19 +16,13 @@ module Graphics.PDF.LowLevel.Serializer( SerializeValue(..) ) where- -import Data.Word + import qualified Data.ByteString.Lazy as B import qualified Data.Binary.Builder as BU import qualified Data.ByteString.Lazy.Char8 as C-import Foreign.Ptr(Ptr)-import Data.ByteString.Internal-import qualified Data.ByteString.Lazy.Internal as L(ByteString(..))--import System.IO.Unsafe--foreign import ccall "conversion.h c_floatToString" cfloatToString :: Double -> Ptr Word8 -> IO Int-foreign import ccall "conversion.h c_shortToString" cshortToString :: Int -> Ptr Word8 -> IO Int+import Data.ByteString.Internal (c2w)+import Data.Word (Word8)+import Text.Printf (printf) @@ -51,20 +44,13 @@ instance SerializeValue B.ByteString B.ByteString where serialize = id- -convertShort :: Int -> ByteString -convertShort a = unsafePerformIO (createAndTrim 12 (cshortToString a))-{-# NOINLINE convertShort #-} -convertFloat :: Double -> ByteString -convertFloat a = unsafePerformIO (createAndTrim 12 (cfloatToString a))-{-# NOINLINE convertFloat #-}- + instance SerializeValue B.ByteString Int where- serialize a = L.Chunk (convertShort a) L.Empty+ serialize = C.pack . show instance SerializeValue B.ByteString Double where- serialize a = L.Chunk (convertFloat a) L.Empty+ serialize = C.pack . printf "%.5f" instance SerializeValue BU.Builder Word8 where
Graphics/PDF/Pattern.hs view
@@ -103,10 +103,10 @@ (newName,newMap) <- setResource "Pattern" (PDFReference a) patternMap modifyStrict $ \s -> s { patterns = newMap } tell . serialize $ ("\n/Pattern cs")- tell . mconcat $[ serialize "\n/" - , serialize newName- , serialize " scn"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newName+ , serialize " scn"+ ] -- | Set the stroke pattern setColoredStrokePattern :: PDFReference PDFColoredPattern -> Draw ()@@ -115,10 +115,10 @@ (newName,newMap) <- setResource "Pattern" (PDFReference a) patternMap modifyStrict $ \s -> s { patterns = newMap } tell . serialize $ ("\n/Pattern CS")- tell . mconcat $[ serialize "\n/" - , serialize newName- , serialize " SCN"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newName+ , serialize " SCN"+ ] @@ -131,21 +131,21 @@ patternMap <- gets patterns (newName,newMap) <- setResource "Pattern" (PDFReference a) patternMap modifyStrict $ \s -> s { patterns = newMap }- tell . mconcat $[ serialize "\n/" - , serialize newColorName- , serialize " cs"- ]- tell . mconcat $[ serialize '\n'- , toPDF r- , serialize ' '- , toPDF g- , serialize ' '- , toPDF b- , serialize ' '- , serialize " /"- , serialize newName- , serialize " scn"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newColorName+ , serialize " cs"+ ]+ tell . mconcat $ [ serialize '\n'+ , toPDF r+ , serialize ' '+ , toPDF g+ , serialize ' '+ , toPDF b+ , serialize ' '+ , serialize " /"+ , serialize newName+ , serialize " scn"+ ] -- | Set the stroke pattern setUncoloredStrokePattern :: PDFReference PDFUncoloredPattern -> Color -> Draw ()@@ -156,10 +156,10 @@ patternMap <- gets patterns (newName,newMap) <- setResource "Pattern" (PDFReference a) patternMap modifyStrict $ \s -> s { patterns = newMap }- tell . mconcat $[ serialize "\n/" - , serialize newColorName- , serialize " CS"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newColorName+ , serialize " CS"+ ] tell . mconcat $ [ serialize '\n' , toPDF r , serialize ' '
Graphics/PDF/Shading.hs view
@@ -30,10 +30,10 @@ shadingMap <- gets shadings (newName,newMap) <- setResource "Shading" shade shadingMap modifyStrict $ \s -> s { shadings = newMap }- tell . mconcat $[ serialize "\n/" - , serialize newName- , serialize " sh"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize newName+ , serialize " sh"+ ] paintWithShading :: PDFShading -- ^ Shading -> Draw a -- ^ Shape to paint
Graphics/PDF/Shapes.hs view
@@ -151,17 +151,17 @@ -- | Set pen width setWidth :: MonadPath m => PDFFloat -> m ()-setWidth w = tell . mconcat $[ serialize "\n" - , toPDF w- , serialize " w"- ]+setWidth w = tell . mconcat $ [ serialize "\n" + , toPDF w+ , serialize " w"+ ] -- | Set pen width setMiterLimit :: MonadPath m => PDFFloat -> m ()-setMiterLimit w = tell . mconcat $[ serialize "\n" - , toPDF w- , serialize " M"- ]+setMiterLimit w = tell . mconcat $ [ serialize "\n" + , toPDF w+ , serialize " M"+ ] -- | Line cap styles data CapStyle = ButtCap@@ -177,29 +177,29 @@ -- | Set line cap setLineCap :: MonadPath m => CapStyle -> m ()-setLineCap w = tell . mconcat $[ serialize "\n " - , toPDF (fromEnum w)- , serialize " J"- ]+setLineCap w = tell . mconcat $ [ serialize "\n " + , toPDF (fromEnum w)+ , serialize " J"+ ] -- | Set line join setLineJoin :: MonadPath m => JoinStyle -> m ()-setLineJoin w = tell . mconcat $[ serialize "\n " - , toPDF (fromEnum w)- , serialize " j"- ]+setLineJoin w = tell . mconcat $ [ serialize "\n " + , toPDF (fromEnum w)+ , serialize " j"+ ] data DashPattern = DashPattern ![PDFFloat] PDFFloat deriving(Eq) -- | Set the dash pattern setDash :: MonadPath m => DashPattern -> m() setDash (DashPattern a p) = - tell . mconcat$ [ serialize "\n " - , toPDF a- , serialize ' '- , toPDF p- , serialize " d"- ]+ tell . mconcat $ [ serialize "\n " + , toPDF a+ , serialize ' '+ , toPDF p+ , serialize " d"+ ] -- | No dash pattern setNoDash :: MonadPath m => m ()@@ -247,10 +247,10 @@ lineto :: Point -> Draw () lineto a = do- tell . mconcat $[ serialize "\n" - , toPDF a- , serialize " l"- ]+ tell . mconcat $ [ serialize "\n" + , toPDF a+ , serialize " l"+ ] writeDrawST penPosition a curveto :: Point -> Point -> Point -> Draw ()
Graphics/PDF/Text.hs view
@@ -118,12 +118,12 @@ setFont :: PDFFont -> PDFText () setFont f@(PDFFont n size) = PDFText $ do lift (modifyStrict $ \s -> s {fontState = Set.insert n (fontState s), currentFont = Just f})- tell . mconcat$ [ serialize "\n/" - , serialize (name n)- , serialize ' '- , toPDF size- , serialize " Tf"- ]+ tell . mconcat $ [ serialize "\n/" + , serialize (name n)+ , serialize ' '+ , toPDF size+ , serialize " Tf"+ ] -- | Draw a text in the draw monad@@ -144,12 +144,12 @@ textStart :: PDFFloat -> PDFFloat -> PDFText ()-textStart x y = tell . mconcat $ [ serialize '\n'- , toPDF x- , serialize ' '- , toPDF y- , serialize " Td"- ]+textStart x y = tell . mconcat $ [ serialize '\n'+ , toPDF x+ , serialize ' '+ , toPDF y+ , serialize " Td"+ ] --writeCmd $ "\n" ++ (show x) ++ " " ++ (show y) ++ " Td" @@ -251,20 +251,20 @@ -- | Set the text transformation matrix setTextMatrix :: Matrix -> PDFText() setTextMatrix (Matrix a b c d e f) = - tell . mconcat $[ serialize '\n'- , toPDF a- , serialize ' '- , toPDF b- , serialize ' '- , toPDF c- , serialize ' '- , toPDF d- , serialize ' '- , toPDF e- , serialize ' '- , toPDF f- , serialize " Tm"- ]+ tell . mconcat $ [ serialize '\n'+ , toPDF a+ , serialize ' '+ , toPDF b+ , serialize ' '+ , toPDF c+ , serialize ' '+ , toPDF d+ , serialize ' '+ , toPDF e+ , serialize ' '+ , toPDF f+ , serialize " Tm"+ ] -- | Utility function to quickly display one line of text text :: PDFFont
HPDF.cabal view
@@ -1,5 +1,5 @@ Name: HPDF-Version: 1.6.1+Version: 1.6.2 cabal-version: >=1.10 License: BSD3 License-file:LICENSE@@ -12,7 +12,6 @@ homepage: http://www.alpheccar.org description: A PDF library with support for several pages, page transitions, outlines, annotations, compression, colors, shapes, patterns, jpegs, fonts, typesetting ... Have a look at the "Graphics.PDF.Documentation" module to see how to use it. Or, download the package and look at the test.hs file in the Test folder. That file is giving an example of each feature. extra-source-files:- cbits/conversion.h Test/logo.jpg Test/Makefile Test/Penrose.hs@@ -91,11 +90,6 @@ ghc-options: -Wall -funbox-strict-fields -O2 - C-Sources: - cbits/conversion.c- Include-Dirs: cbits- Install-Includes: - conversion.h exposed-Modules: Graphics.PDF Graphics.PDF.Colors
− cbits/conversion.c
@@ -1,17 +0,0 @@-#include <stdlib.h>-#include <stdio.h>-#include <string.h>-#include "conversion.h"---short c_floatToString(double f,char* s)-{- sprintf(s,"%.5f",f);- return(strlen(s));-}--short c_shortToString(short d,char* s)-{- sprintf(s,"%d",d);- return(strlen(s));-}
− cbits/conversion.h
@@ -1,5 +0,0 @@-#ifndef _CONVERSION_H_-#define _CONVERSION_H_-extern short c_floatToString(double f,char* s);-extern short c_shortToString(short d,char* s);-#endif
changelog.md view
@@ -1,5 +1,12 @@ # Changelog for [`HPDF` package](http://hackage.haskell.org/package/HPDF) +## 1.6.2++ * Removed use of cbits for float/int to string conversions for correctness+ (see https://github.com/hsyl20/HPDF/issues/14)++ * Fix build warnings due to -Woperator-whitespace-ext-conflict+ ## 1.6.1 * Fix for building with mtl-2.3