hsexif 0.6.0.3 → 0.6.0.4
raw patch · 4 files changed
+40/−14 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Graphics/HsExif.hs +4/−0
- Graphics/PrettyPrinters.hs +19/−7
- hsexif.cabal +14/−6
- tests/Tests.hs +3/−1
Graphics/HsExif.hs view
@@ -530,3 +530,7 @@ -- -- There are also a couple of higher-level helpers like 'getOrientation', -- 'getDateTimeOriginal', 'wasFlashFired' and 'getGpsLatitudeLongitude'.+--+-- When building on Windows if you have trouble with the @iconv@ library,+-- you may build without that dependency: @cabal install -f-iconv@.+-- That way you loose nice decoding of the EXIF User Comment though.
Graphics/PrettyPrinters.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables, OverloadedStrings, CPP #-} module Graphics.PrettyPrinters where import Text.Printf (printf)@@ -6,13 +6,15 @@ import Data.Maybe import qualified Data.Map as Map import qualified Data.ByteString as BS-import qualified Data.ByteString.Lazy as BL import Control.Arrow (first) import Control.Applicative-import Data.Text.Encoding (decodeUtf8)+import Data.Text.Encoding import qualified Data.Text as T import Data.Text (Text)+#if ICONV+import qualified Data.ByteString.Lazy as BL import Codec.Text.IConv (convertFuzzy, EncodingName, Fuzzy(Transliterate))+#endif import Graphics.Types (ExifValue(..), formatAsFloatingPoint) @@ -196,6 +198,12 @@ asStr = T.unpack $ decodeUtf8 s formatVersion _ v@_ = unknown v +#if ICONV++getIconvEncodingName :: Text -> EncodingName+getIconvEncodingName "JIS" = "SJIS"+getIconvEncodingName x@_ = T.unpack x -- ASCII and UNICODE work out of the box.+ ppUserComment :: ExifValue -> Text ppUserComment (ExifUndefined v) = decodeUtf8 $ BL.toStrict $ convertFuzzy Transliterate encoding "UTF8" rawText where@@ -203,16 +211,20 @@ rawText = BL.fromStrict $ BS.drop 8 v ppUserComment v@_ = unknown v +#else++ppUserComment :: ExifValue -> Text+ppUserComment (ExifUndefined v) = decodeUtf8 $ BS.drop 8 v+ppUserComment v@_ = unknown v++#endif+ -- | Pretty printer for the FileSource tag ppFileSource :: ExifValue -> Text ppFileSource (ExifUndefined v) | BS.head v == 3 = "DSC" | otherwise = "(unknown)" ppFileSource v = unknown v--getIconvEncodingName :: Text -> EncodingName-getIconvEncodingName "JIS" = "SJIS"-getIconvEncodingName x@_ = T.unpack x -- ASCII and UNICODE work out of the box. fromNumberMap :: [(Int, Text)] -> ExifValue -> Text fromNumberMap m = fromMap convertedMap
hsexif.cabal view
@@ -1,8 +1,5 @@--- Initial hsexif.cabal generated by cabal init. For further--- documentation, see http://haskell.org/cabal/users-guide/- name: hsexif-version: 0.6.0.3+version: 0.6.0.4 synopsis: EXIF handling library in pure Haskell description: The hsexif library provides functions for working with EXIF data contained in JPEG files. Currently it only supports reading the data.@@ -17,6 +14,11 @@ extra-source-files: tests/*.jpg tests/*.png cabal-version: >=1.10 +Flag iconv+ Description: Enable encoding conversion of the User Comment tag with iconv.+ It's a nice thing to have but iconv is difficult to install on windows.+ Default: True+ library exposed-modules: Graphics.HsExif other-modules: Graphics.Types, Graphics.PrettyPrinters, Graphics.ExifTags, Graphics.Helpers@@ -26,8 +28,11 @@ bytestring >=0.10 && <0.11, containers >= 0.5 && <0.6, time >= 1.4 && <1.6,- iconv >= 0.4 && <0.5, text >= 0.9+ if flag(iconv)+ build-depends: iconv >= 0.4 && <0.5+ cpp-Options: -DICONV+ -- hs-source-dirs: default-language: Haskell2010 Ghc-Options: -Wall@@ -44,6 +49,9 @@ bytestring >=0.10 && <0.11, containers >= 0.5 && <0.6, time >= 1.4 && <1.6,- iconv >= 0.4 && <0.5, text >= 0.9+ if flag(iconv)+ build-depends: iconv >= 0.4 && <0.5+ cpp-Options: -DICONV+ Ghc-Options: -Wall
tests/Tests.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings, CPP #-} import Test.Hspec import Test.HUnit @@ -175,7 +175,9 @@ checkPrettyPrinter gpsAltitude "2681.1111" gps2ExifData checkPrettyPrinter gpsTimeStamp "09:12:32.21" gps2ExifData checkPrettyPrinter userComment "Test Exif comment" exifData+#if ICONV checkPrettyPrinter userComment "Test Exif commentčšž" stdExifData+#endif checkPrettyPrinter :: ExifTag -> Text -> Maybe (Map ExifTag ExifValue) -> Assertion checkPrettyPrinter tag str exifData = assertEqual' (Just str) $ prettyPrinter tag <$> (exifData >>= Map.lookup tag)