packages feed

webify (empty) → 0.1.5.0

raw patch · 4 files changed

+199/−0 lines, 4 filesdep +basedep +binarydep +binary-strictsetup-changed

Dependencies added: base, binary, binary-strict, bytestring, containers, filepath, hopfli, optparse-applicative, text, vector, xmlgen, zlib

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)+Copyright (c) 2013 Anantha Kumaran <ananthakumaran@gmail.com>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Webify.hs view
@@ -0,0 +1,133 @@+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}+{-# LANGUAGE RecordWildCards #-}++import           Control.Exception+import           Control.Monad+import           Data.Binary.Strict.Get+import qualified Data.ByteString        as B+import           Data.Monoid+import           EOT+import           Font                   hiding (str)+import           Options.Applicative    hiding (header)+import           OTF+import           SVG+import           System.FilePath+import           TTF+import           Utils+import           WOFF+++-- platformAppleUnicode = 0+-- platformMacintosh = 1+-- platformISO = 2+platformMicrosoft = 3++-- encodingUndefined = 0+encodingUGL = 1++data Opts = Opts { noEot         :: Bool+                 , noWoff        :: Bool+                 , noSvg         :: Bool+                 , enableSvgKern :: Bool+                 , zopfli        :: Bool+                 , svgPlatformId :: UShort+                 , svgEncodingId :: UShort+                 , inputs        :: [String]}++optsDef :: Parser Opts+optsDef = Opts <$> switch (long "no-eot" <> help "Disable eot")+          <*> switch (long "no-woff" <> help "Disable woff")+          <*> switch (long "no-svg" <> help "Disable eot")+          <*> switch (long "svg-enable-kerning" <> help "Enable svg kerning")+          <*> switch (long "zopfli" <> help "Use Zopfli Compression Algorithm")+          <*> option (long "svg-cmap-platform-id" <> value platformMicrosoft <> help "Svg cmap platform id")+          <*> option (long "svg-cmap-encoding-id" <> value encodingUGL  <> help "Svg cmap encoding id")+          <*> arguments1 str (metavar "FONTS")++changeExtension :: FilePath -> FilePath -> FilePath+changeExtension ext = flip addExtension ext . dropExtension++cmapDescription :: (Integral a) => a -> a -> String+cmapDescription 0 0 = "Unicode 1.0 semantics"+cmapDescription 0 1 = "Unicode 1.1 semantics"+cmapDescription 0 2 = "ISO/IEC 10646 semantics"+cmapDescription 0 3 = "Unicode 2.0 and onwards semantics, Unicode BMP only"+cmapDescription 0 4 = "Unicode 2.0 and onwards semantics, Unicode full repertoire"+cmapDescription 0 5 = "Unicode Variation Sequences"+cmapDescription 0 6 = "Unicode full repertoire"+cmapDescription 0 _ = "Unicode unknown"+cmapDescription 1 0 = "Macintosh Roman 8-bit simple"+cmapDescription 1 _ = "Macintosh unknown"+cmapDescription 3 0 = "Microsoft Symbol"+cmapDescription 3 1 = "Microsoft Unicode BMP (UCS-2)"+cmapDescription 3 2 = "Microsoft ShiftJIS"+cmapDescription 3 3 = "Microsoft PRC"+cmapDescription 3 4 = "Microsoft Big5"+cmapDescription 3 5 = "Microsoft Wansung"+cmapDescription 3 6 = "Microsoft Johab"+cmapDescription 3 7 = "Microsoft Reserved"+cmapDescription 3 8 = "Microsoft Reserved"+cmapDescription 3 9 = "Microsoft Reserved"+cmapDescription 3 10 = "Microsoft Unicode UCS-4"+cmapDescription 3 _ = "Microsoft Unknown"+cmapDescription _ _ = "Unknown"++showCmap :: Cmap -> String+showCmap cmap' =+  formatTable $ header : map pluck (encodingDirectories cmap')+  where header = ["PlatformId", "EncodingId", "Description"]+        pluck dir = [show $ cmapPlatformId dir, show $ cmapEncodingId dir, cmapDescription (cmapPlatformId dir) (cmapEncodingId dir)]++eotgen :: Font f => f -> B.ByteString -> FilePath -> IO ()+eotgen font input filename = do+  putStrLn $ "Generating " ++ target+  B.writeFile target $ EOT.generate font input+  where target = changeExtension "eot" filename++woffgen :: Font f => f -> B.ByteString -> FilePath -> Opts -> IO ()+woffgen font input filename Opts{..}= do+  putStrLn $ "Generating " ++ target+  B.writeFile target $ WOFF.generate font input zopfli+  where target = changeExtension "woff" filename++svggen :: TTF -> B.ByteString -> FilePath -> Opts -> IO ()+svggen ttf input filename Opts{..} = do+  putStrLn $ "Generating " ++ target+  putStrLn "Available cmaps"+  putStr $ showCmap $ cmap ttf+  putStrLn $ "Selecting platformId " ++ show svgPlatformId ++ " encodingId " ++ show svgEncodingId ++ " -- " ++ cmapDescription svgPlatformId svgEncodingId+  B.writeFile target $ SVG.generate ttf input cmapTable enableSvgKern+  where target = changeExtension "svg" filename+        cmapTable = cmapTableFind ttf svgPlatformId svgEncodingId++convert :: Opts -> FilePath -> IO ()+convert opts@Opts{..} filename = do+  input <- B.readFile filename+  if takeExtension filename == ".otf"+    then let otf = fromRight $ runGet (OTF.parse input) input in+    do+      unless noEot (eotgen otf input filename)+      unless noWoff (woffgen otf input filename opts)+    else let ttf = fromRight $ runGet (TTF.parse input) input in+    do+      unless noEot (eotgen ttf input filename)+      unless noWoff (woffgen ttf input filename opts)+      unless noSvg (svggen ttf input filename opts)++convertFiles :: Opts -> IO ()+convertFiles opts@Opts{inputs = fonts} =+  forM_ fonts $ safeConvert opts+  where safeConvert opts' file = convert opts' file `catch` displayError file+        displayError :: FilePath -> SomeException -> IO ()+        displayError file e = (putStrLn $ "Failed to convert " ++ file) >> (putStrLn $ show e)++webifyVersion = "0.1.5.0"++main :: IO ()+main = do+  opts <- execParser optsSpec+  maybe (putStrLn $ "webify " ++ webifyVersion) convertFiles opts+  where+    parser = flag' Nothing (long "version" <> help "Display version") <|> (Just <$> optsDef)+    optsSpec = info (helper <*> parser) mempty+
+ webify.cabal view
@@ -0,0 +1,43 @@+name:                webify+version:             0.1.5.0+synopsis:            webfont generator+description:+        A command line tool to convert ttf file to woff, eot & svg files++homepage:            http://github.com/ananthakumaran/webify+license:             MIT+license-file:        LICENSE+author:              Anantha Kumaran+maintainer:          ananthakumaran@gmail.com+copyright:           (c) 2013 Anantha Kumaran+category:            Web+build-type:          Simple+cabal-version:       >=1.8++Flag debug+     Default: False++executable webify+  hs-source-dirs:   src+  main-is:             Webify.hs++  if flag(debug)+    ghc-prof-options: -prof, -fprof-auto++  -- other-modules:+  build-depends:       base ==4.6.*,+                       containers >= 0.4.2.1,+                       bytestring >= 0.9,+                       binary >= 0.5.1,+                       binary-strict >= 0.4.8,+                       text >= 0.7.2,+                       filepath >= 1.3.0,+                       zlib >= 0.5.4,+                       xmlgen == 0.4.0.3,+                       optparse-applicative >= 0.5.2,+                       vector >= 0.10.0,+                       hopfli >= 0.1.0.0++source-repository head+  type:     git+  location: https://github.com/ananthakumaran/webify.git