HPDF 1.4.3 → 1.4.4
raw patch · 5 files changed
+95/−18 lines, 5 filesdep +vectordep −haskell98dep ~basedep ~mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: vector
Dependencies removed: haskell98
Dependency ranges changed: base, mtl
API changes (from Hackage documentation)
+ Graphics.PDF.Image: createPDFRawImage :: Double -> Double -> Bool -> Vector Word32 -> PDF (PDFReference RawImage)
+ Graphics.PDF.Image: data RawImage
+ Graphics.PDF.Image: instance PDFXObject RawImage
+ Graphics.PDF.Image: instance PdfObject RawImage
+ Graphics.PDF.Image: instance PdfResourceObject (PDFReference RawImage)
Files
- Graphics/PDF/Image.hs +55/−1
- HPDF.cabal +14/−12
- LICENSE +1/−1
- Test/Makefile +1/−1
- Test/test.hs +24/−3
Graphics/PDF/Image.hs view
@@ -20,10 +20,12 @@ -- ** Types PDFJpeg , JpegFile+ , RawImage -- ** Functions , createPDFJpeg , readJpegFile , jpegBounds+ , createPDFRawImage ) where import Graphics.PDF.LowLevel.Types@@ -44,6 +46,9 @@ import Graphics.PDF.Coordinates import Data.Binary.Builder(Builder,fromLazyByteString) import Control.Exception as E+import qualified Data.Vector.Unboxed as U+import qualified Data.Bits as BI+import Data.Word m_sof0 :: Int m_sof0 = 0xc0 @@ -300,7 +305,39 @@ ] ++ color color_space } tell img - + +createPDFRawImage :: Double -- ^ Width+ -> Double -- ^ Height+ -> Bool -- ^ Interpolation+ -> U.Vector Word32 -- ^ RGBA pixels (A component not used y the PDF document)+ -> PDF (PDFReference RawImage) +createPDFRawImage width height interpolate stream = do+ PDFReference s <- createContent a' Nothing + recordBound s width height+ return (PDFReference s) + where+ img = fromLazyByteString . pack24 . U.toList $ stream+ pack24 :: [Word32] -> B.ByteString+ pack24 [] = B.empty + pack24 (a:l) = B.cons xa . B.cons xb . B.cons xc $ (pack24 l)+ where + xa = fromIntegral $ (a `shiftR` 16) .&. 0x0FF+ xb = fromIntegral $ (a `shiftR` 8) .&. 0x0FF+ xc = fromIntegral $ (a `shiftR` 0) .&. 0x0FF++ a' = + do modifyStrict $ \s -> s {otherRsrcs = PDFDictionary. M.fromList $ + [ (PDFName "Type",AnyPdfObject . PDFName $ "XObject")+ , (PDFName "Subtype",AnyPdfObject . PDFName $ "Image")+ , (PDFName "Width",AnyPdfObject . PDFInteger $ round width)+ , (PDFName "Height",AnyPdfObject . PDFInteger $ round height)+ , (PDFName "BitsPerComponent",AnyPdfObject . PDFInteger $ 8)+ , (PDFName "ColorSpace",AnyPdfObject $ PDFName "DeviceRGB")+ , (PDFName "Interpolate", AnyPdfObject interpolate)+ ]+ }+ tell img + -- | A Jpeg file data JpegFile = JpegFile !Int !PDFFloat !PDFFloat !Int !Builder @@ -316,3 +353,20 @@ toPDF _ = noPdfObject instance PdfResourceObject (PDFReference PDFJpeg) where toRsrc = AnyPdfObject++-- | A raw image+data RawImage++instance PDFXObject RawImage where+ drawXObject a = withNewContext $ do+ (width,height) <- bounds a+ applyMatrix (scale width height)+ privateDrawXObject a+ +instance PdfObject RawImage where+ toPDF _ = noPdfObject+instance PdfResourceObject (PDFReference RawImage) where+ toRsrc = AnyPdfObject+++
HPDF.cabal view
@@ -1,14 +1,14 @@ Name: HPDF-Version: 1.4.3+Version: 1.4.4 cabal-version: >=1.6 License: LGPL License-file:LICENSE-Copyright: Copyright (c) 2007-2012, alpheccar.org+Copyright: Copyright (c) 2007-2013, alpheccar.org category: Graphics synopsis: Generation of PDF documents maintainer: misc@NOSPAMalpheccar.org build-type: Simple-tested-with: GHC==7.4.2+tested-with: GHC==7.6.1 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:@@ -24,16 +24,18 @@ NEWS.txt TODO.txt -flag splitBase- description: Choose the new smaller, split-up base package.- library- if flag(splitBase)- build-depends: base >= 3 && < 5 , containers, random >= 1.0, bytestring >= 0.9, array >= 0.1, zlib >= 0.5, binary >= 0.4, mtl- else- build-depends: base >= 2 && < 3, haskell98, mtl ,zlib >= 0.5, binary >= 0.4- if impl(ghc >= 6.10)- build-depends: base >= 4+ build-depends: + base >= 4 && < 5, + containers, + random >= 1.0, + bytestring >= 0.9, + array >= 0.1, + zlib >= 0.5, + binary >= 0.4, + mtl,+ vector >=0.10+ ghc-options: -Wall -funbox-strict-fields -O2 C-Sources:
LICENSE view
@@ -1,4 +1,4 @@-* Copyright (c) 2006-2012, alpheccar.org+* Copyright (c) 2006-2013, alpheccar.org * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met:
Test/Makefile view
@@ -8,7 +8,7 @@ ./test +RTS -p -hc demo:- ghc -o test -fglasgow-exts -O2 --make test.hs+ ghc -o test -O2 --make test.hs buildafm: ghc -o afm --make AFMParser.hs
Test/test.hs view
@@ -1,7 +1,7 @@-{-# OPTIONS_GHC -fglasgow-exts #-}+{-# LANGUAGE ScopedTypeVariables, MultiParamTypeClasses #-} --------------------------------------------------------- -- |--- Copyright : (c) 2006-2012, alpheccar.org+-- Copyright : (c) 2006-2013, alpheccar.org -- License : BSD-style -- -- Maintainer : misc@NOSPAMalpheccar.org@@ -18,6 +18,7 @@ import Graphics.PDF import Penrose import System.Random+import qualified Data.Vector.Unboxed as U fontDebug :: PDFFont -> PDFString -> Draw () fontDebug f t = do@@ -135,7 +136,25 @@ applyMatrix $ translate (200 :+ 200) applyMatrix $ scale 2 2 drawXObject jpg- + +rawImage :: PDFReference PDFPage -> PDF ()+rawImage page = do+ let nb = 200+ getPixel i | i < nb*(3*nb) = 0x00FF0000+ | i < 2*nb*(3*nb) = 0x0000FF00+ | otherwise = 0x000000FF+ pixels = U.generate (9*nb*nb) getPixel+ jpg <- createPDFRawImage (fromIntegral $ 3*nb) (fromIntegral $ 3*nb) True pixels+ drawWithPage page $ do+ withNewContext $ do+ setFillAlpha 0.4+ applyMatrix $ scale 0.2 0.2+ drawXObject jpg+ withNewContext $ do+ applyMatrix $ rotate (Degree 20)+ applyMatrix $ translate (200 :+ 200)+ applyMatrix $ scale 0.1 0.1+ drawXObject jpg data MyParaStyles = Normal | Bold@@ -629,6 +648,8 @@ newSection (toPDFString "Text box") Nothing Nothing $ do drawWithPage page12 $ do textBoxes+ page13 <- addPage Nothing+ rawImage page13 main :: IO()