packages feed

xournal-builder (empty) → 0.1

raw patch · 5 files changed

+165/−0 lines, 5 filesdep +basedep +blaze-builderdep +bytestringsetup-changed

Dependencies added: base, blaze-builder, bytestring, double-conversion, strict, xournal-types

Files

+ CHANGES view
@@ -0,0 +1,4 @@+0.1: 18 Dec 2011+   * First public release. ++ 
+ 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+>   --  } 
+ src/Text/Xournal/Builder.hs view
@@ -0,0 +1,92 @@+{-# LANGUAGE OverloadedStrings #-}++module Text.Xournal.Builder where++import Data.Xournal.Simple+import qualified Data.ByteString as S+import qualified Data.ByteString.Lazy as L+import Blaze.ByteString.Builder+import Blaze.ByteString.Builder.Char8 (fromChar, fromString)+import Data.Double.Conversion.ByteString +import Data.Monoid+import Data.Strict.Tuple++infixl 4 <>++(<>) :: Monoid a => a -> a -> a +(<>) = mappend +++builder :: Xournal -> L.ByteString+builder = toLazyByteString . fromXournal++fromXournal :: Xournal -> Builder +fromXournal xoj = fromByteString "<?xml version=\"1.0\" standalone=\"no\"?>\n<xournal version=\"0.4.2.1\">\n"+                  <> fromTitle (xoj_title xoj) <> mconcat (map fromPage (xoj_pages xoj))+                  <> fromByteString "</xournal>\n"+  +fromTitle :: S.ByteString -> Builder+fromTitle title = fromByteString "<title>"+                  <> fromByteString title+                  <> fromByteString "</title>\n"++  +fromPage :: Page -> Builder +fromPage page = fromByteString "<page width=\""+                <> fromByteString (toFixed 2 w)+                <> fromByteString "\" height=\""+                <> fromByteString (toFixed 2 h)+                <> fromByteString "\">\n"   +                <> fromBackground (page_bkg page)+                <> mconcat (map fromLayer (page_layers page))+                <> fromByteString "</page>\n"+  where Dim w h = page_dim page+  +fromBackground :: Background -> Builder +fromBackground bkg = +  case bkg of  +    Background typ col sty -> +      fromByteString "<background type=\""+      <> fromByteString typ+      <> fromByteString "\" color=\""+      <> fromByteString col+      <> fromByteString "\" style=\""+      <> fromByteString sty+      <> fromByteString "\"/>\n"+    BackgroundPdf typ mdom mfile pageno -> +      fromByteString "<background type=\""+      <> fromByteString typ+      <> case mdom of +           Nothing -> fromByteString  S.empty +           Just dom -> fromByteString "\" domain=\""+                       <> fromByteString dom+      <> case mfile of +           Nothing -> fromByteString S.empty +           Just file ->  fromByteString "\" filename=\""+                         <> fromByteString file+      <> fromByteString "\" pageno=\""+      <> fromString (show pageno)+      <> fromByteString "\"/>\n"+      ++fromLayer :: Layer -> Builder+fromLayer layer = fromByteString "<layer>\n"+                  <> mconcat (map fromStroke (layer_strokes layer))+                  <> fromByteString "</layer>\n"++fromStroke :: Stroke -> Builder+fromStroke stroke = fromByteString "<stroke tool=\""+                    <> fromByteString (stroke_tool stroke)+                    <> fromByteString "\" color=\""+                    <> fromByteString (stroke_color stroke)+                    <> fromByteString "\" width=\""+                    <> fromByteString (toFixed 2 (stroke_width stroke))+                    <> fromByteString "\">\n"+                    <> mconcat (map fromCoord (stroke_data stroke))+                    <> fromByteString "\n</stroke>\n"++fromCoord :: Pair Double Double -> Builder +fromCoord (x :!: y) = fromByteString (toFixed 2 x) +                      <> fromChar ' ' +                      <> fromByteString (toFixed 2 y) +                      <> fromChar ' ' 
+ xournal-builder.cabal view
@@ -0,0 +1,34 @@+Name:		xournal-builder+Version:	0.1+Synopsis:	text builder for xournal file format +Description: 	This library builds text xoj format file from xournal data structure+License: 	BSD3+License-file:	LICENSE+Author:		Ian-Woo Kim+Maintainer: 	Ian-Woo Kim <ianwookim@gmail.com>+Category:       Text+Build-Type: 	Simple+Cabal-Version:  >= 1.8+data-files:     CHANGES+Source-repository head+  type: git+  location: http://www.github.com/wavewave/xournal-builder++Library+  hs-source-dirs: src+  ghc-options: 	-Wall -O2 -threaded -funbox-strict-fields -fno-warn-unused-do-bind+  ghc-prof-options: -caf-all -auto-all+  Build-Depends: +                   base == 4.*,+                   xournal-types == 0.1.*, +                   blaze-builder == 0.3.*, +                   strict == 0.3.*, +                   double-conversion == 0.2.*, +                   bytestring == 0.9.*+                 +  Exposed-Modules: +                   Text.Xournal.Builder+  Other-Modules: ++ +