packages feed

xournal-convert (empty) → 0.1

raw patch · 9 files changed

+241/−0 lines, 9 filesdep +HStringTemplatedep +basedep +cairosetup-changed

Dependencies added: HStringTemplate, base, cairo, cmdargs, directory, filepath, mtl, xournal-convert, xournal-parser, xournal-render, xournal-types

Files

+ CHANGES view
@@ -0,0 +1,3 @@+0.1: 27 Dec 2011+   * First public release. can generate svg files for each page and index.html file for nagivating those pages +
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2011, Ian-Woo Kim. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,10 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> import Distribution.PackageDescription+> --import System.Process+> main = defaultMain+> --main = defaultMainWithHooks testUserHooks+> --testUserHooks = simpleUserHooks { +>  --   preConf = \_ _ -> runCommand "cd rootcode; make; cd .." >>return emptyHookedBuildInfo+>   --  } 
+ exe/xournal-convert.hs view
@@ -0,0 +1,13 @@+module Main where++import System.Console.CmdArgs++import Application.XournalConvert.ProgType+import Application.XournalConvert.Command++main :: IO () +main = do +  putStrLn "xournal-convert"+  param <- cmdArgs mode++  commandLineProcess param
+ lib/Application/XournalConvert/Command.hs view
@@ -0,0 +1,12 @@+module Application.XournalConvert.Command where++import Application.XournalConvert.ProgType+import Application.XournalConvert.Job++commandLineProcess :: Xournal_convert -> IO ()+commandLineProcess Test = do +  putStrLn "test called"+  startJob+commandLineProcess (MakeSVG fname mdest) = do +  putStrLn "makeSVG is called"+  startMakeSVG fname mdest
+ lib/Application/XournalConvert/Job.hs view
@@ -0,0 +1,93 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Application.XournalConvert.Job where++import Data.List +import Graphics.Xournal.Render.Simple+import Graphics.Rendering.Cairo++import Data.Xournal.Simple+import Text.Xournal.Parse++import Text.StringTemplate+-- import Text.StringTemplate.Helpers++import System.Directory +import System.FilePath+import System.IO++import Paths_xournal_convert++render1 :: [(String,String)] -> String -> String+render1 attribs tmpl = render . setManyAttrib attribs . newSTMP $ tmpl++svgFileName :: String -> Int -> String +svgFileName fname_wo_ext pnum =+  fname_wo_ext ++ "_Page_" ++ show pnum <.> "svg"+++startJob :: IO () +startJob = do +  putStrLn "job started"+++++startMakeSVG :: FilePath -> Maybe FilePath -> IO () +startMakeSVG fname mdest = do +  xojcontent <- read_xournal fname ++  case mdest of +    Nothing -> return ()+    Just dest -> setCurrentDirectory dest++  let (fname_wo_ext,_fname_ext) = splitExtension fname +  let pages = xoj_pages xojcontent+      names = map (svgFileName fname_wo_ext) [1..]+      -- names = map (\x -> fname_wo_ext ++ show x ++ ".svg") [1..] +      namePages = zip names pages +  let Dim w h = page_dim (head pages)++  putStrLn $ " w = " ++ show w+  putStrLn $ " h = " ++ show h  ++  let svgoutfn x = withSVGSurface (fst x) w h (\s -> renderWith s (cairoDrawPage (snd x)))++  mapM_ svgoutfn namePages++  makeHtmlJavascriptPage "index.html" $ zip [1..] (map fst namePages)+   +  putStrLn "test ended"++onePageTemplate :: String +onePageTemplate = "<p><div class=\"page\"> <a name=\"$page$\"> <img src=\"$filename$\" width=100% /> </a> </div> </p>\n\n"++onerule :: String +onerule = "<hr /> \n"++makeHtmlJavascriptPage :: FilePath -> [(Int,String)] -> IO ()+makeHtmlJavascriptPage fname names = do+  putStrLn $ "writing  " ++ fname+  putStrLn $ show names +  templateDir <- getDataDir >>= return . (</> "template")++  indexhtmlst <- readFile (templateDir </> "index.html.st")+  -- (templates :: STGroup String) <- directoryGroup templateDir + + ++  let mkstr :: (Int,String) -> String +      mkstr (p,n) = flip render1 onePageTemplate [ ("filename", "." </> n) +                                                 , ("page", show p) ]+      bodystr = intercalate onerule . map mkstr $ names++  let str = flip render1 indexhtmlst [ ("body", bodystr) ] ++  {- renderTemplateGroup +             templates +             [ ("body", bodystr) ] +             "index.html" -}++  withFile fname WriteMode $ \h -> do +    hPutStr h str+    
+ lib/Application/XournalConvert/ProgType.hs view
@@ -0,0 +1,23 @@+{-# LANGUAGE DeriveDataTypeable #-}++module Application.XournalConvert.ProgType where ++import System.Console.CmdArgs++data Xournal_convert = Test +                     | MakeSVG { xojfile :: FilePath+                               , dest :: Maybe FilePath +                               }+              deriving (Show,Data,Typeable)++test :: Xournal_convert+test = Test ++makeSVG :: Xournal_convert+makeSVG = MakeSVG { xojfile = "test.xoj" &= typ "FILENAME" &= argPos 0 +                  , dest = Nothing &= typ "DESTINATION" +                  }++mode :: Xournal_convert +mode = modes [test, makeSVG]+
+ template/index.html.st view
@@ -0,0 +1,8 @@+<html>+  <head>+    <title> XOJ file </title>+  </head>+  <body>+    $body$+  </body>+</html>
+ xournal-convert.cabal view
@@ -0,0 +1,54 @@+Name:		xournal-convert+Version:	0.1+Synopsis:	convert utility for xoj files+Description: 	convert xoj files into various formats (SVG,SVG+index.html..) +Homepage:       http://ianwookim.org/hxournal+License: 	BSD3+License-file:	LICENSE+Author:		Ian-Woo Kim+Maintainer: 	Ian-Woo Kim <ianwookim@gmail.com>+Category:       Application+Tested-with:    GHC == 7.0.4+Build-Type: 	Simple+Cabal-Version:  >= 1.8+data-files:     +                template/*.html.st+                CHANGES+Source-repository head+  type: git+  location: http://www.github.com/wavewave/xournal-convert++Executable xournal-convert+  Main-is: xournal-convert.hs+  hs-source-dirs: exe+  ghc-options: 	-Wall -threaded -funbox-strict-fields -fno-warn-unused-do-bind+  ghc-prof-options: -caf-all -auto-all+  Build-Depends: +                   base == 4.*, +                   cmdargs >= 0.7 && < 0.10, +                   xournal-convert++Library+  hs-source-dirs: lib+  ghc-options: 	-Wall -funbox-strict-fields -fno-warn-unused-do-bind+  ghc-prof-options: -caf-all -auto-all+  Build-Depends: +                   base == 4.*,+                   mtl == 2.*, +                   directory == 1.1.*, +                   filepath == 1.2.*,+                   cmdargs >= 0.7 && < 0.10, +                   HStringTemplate == 0.6.*,+                   xournal-types == 0.2.*,+                   xournal-parser == 0.3.*, +                   xournal-render == 0.4.*, +                   cairo == 0.12.*++  Exposed-Modules: +                   Application.XournalConvert.ProgType+                   Application.XournalConvert.Job+                   Application.XournalConvert.Command+  Other-Modules: +                   Paths_xournal_convert+ +