xournal-parser 0.2.0 → 0.3
raw patch · 4 files changed
+82/−227 lines, 4 filesdep +xournal-types
Dependencies added: xournal-types
Files
- src/Text/Xournal/Parse.hs +70/−31
- src/Text/Xournal/Predefined.hs +0/−91
- src/Text/Xournal/Type.hs +0/−99
- xournal-parser.cabal +12/−6
src/Text/Xournal/Parse.hs view
@@ -6,7 +6,8 @@ import Data.Attoparsec-import Data.Attoparsec.Char8 (char, double, skipSpace, isHorizontalSpace)+import Data.Attoparsec.Char8 ( char, decimal, double, skipSpace+ , isHorizontalSpace) import qualified Data.ByteString.Char8 as B hiding (map) @@ -17,7 +18,7 @@ import Data.Char -import Text.Xournal.Type+import Data.Xournal.Simple import Text.Xournal.Parse.Zlib import Data.Strict.Tuple@@ -94,20 +95,20 @@ parser_xournal :: Parser Xournal parser_xournal = do trim- xmlheader+ xmlheader <?> "xmlheader" trim- xournal+ xournal <?> "xournal" xournal :: Parser Xournal xournal = do trim - xournalheader+ xournalheader <?> "xournalheader" trim- t <- title+ t <- title <?> "title" trim (try (preview >> return ()) <|> return ()) - pgs <- many1 page+ pgs <- many1 (page <?> "page") trim xournalclose return $ Xournal t pgs @@ -116,7 +117,7 @@ page = do trim dim <- pageheader trim - bkg <- background + bkg <- background <?> "background" trim layers <- many1 layer trim@@ -204,29 +205,59 @@ layerclose = string "</layer>" background :: Parser Background -background = do trim- backgroundheader- trim - string "type=" - char '"'- typ <- alphabet- char '"'- trim - string "color="- char '"' - col <- alphanumsharp - char '"'- trim - string "style="- trim - char '"'- sty <- alphabet - char '"' - trim - takeTill (inClass "/>") -- ( many . satisfy . notInClass ) "/>"- backgroundclose- return $ Background typ col sty - +background = do + trim+ backgroundheader+ trim + string "type=" + char '"'+ typ <- alphabet+ char '"'+ case typ of + "solid" -> do + trim + string "color="+ char '"' + col <- alphanumsharp + char '"'+ trim + string "style="+ trim + char '"'+ sty <- alphabet + char '"' + trim + takeTill (inClass "/>") -- ( many . satisfy . notInClass ) "/>"+ backgroundclose+ return $ Background typ col sty + "pdf" -> do + trim <?> "trim0"+ (mdomain,mfilename) <- (try $ do + string "domain="+ char '"' + domain <- alphabet + char '"'+ trim <?> "trim1"+ string "filename="+ trim <?> "trim2"+ char '"'+ filename <- parseFileName <?> "filename parse"+ char '"' + return (Just domain, Just filename))+ <|> return (Nothing,Nothing)+ trim <?> "trim3"+ string "pageno="+ trim <?> "trim4"+ char '"' + pnum <- decimal <?> "decimal"+ char '"'+ trim + takeTill (inClass "/>") <?> "here takeTill"+ backgroundclose+ return $ BackgroundPdf typ mdomain mfilename pnum + + + alphabet :: Parser B.ByteString alphabet = takeWhile1 (\w -> (w >= 65 && w <= 90) || (w >= 97 && w <= 122)) @@ -235,6 +266,14 @@ || (w >= 97 && w <= 122) || ( w >= 48 && w<= 57 ) || ( w== 35) ) ++-- | need to be reimplemented+parseFileName :: Parser B.ByteString+parseFileName = takeTill (inClass ['"'])+ -- takeWhilw1 (\w -> (w >= 65 && w <= 90) + -- || (w >= 97 && w <= 122)+ -- || (w >= 48 && w <= 57)+ -- || (w == 35) backgroundheader :: Parser B.ByteString backgroundheader = string "<background"
− src/Text/Xournal/Predefined.hs
@@ -1,91 +0,0 @@-{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}--module Text.Xournal.Predefined where--import qualified Data.Map as M-import qualified Data.ByteString.Char8 as B--import Text.Printf --hexToRGBA :: Integer -> (Double,Double,Double,Double) -hexToRGBA n = - let r = n `div` (256*256*256)- g = (n-r*256*256*256) `div` (256*256)- b = (n-r*256*256*256-g*256*256) `div` 256 - a = n-r*256*256*256-g*256*256-b*256 - in (fromIntegral r/255.0,fromIntegral g/255.0,fromIntegral b/255.0,fromIntegral a/255.0)--rgbaToHEX :: (Double,Double,Double,Double) -> String-rgbaToHEX (r,g,b,a) = - let i :: Integer = round (255*a) + round (256*255*b) + round (256*256*255*g) + round (256*256*256*255*r) - in printf "#%08x" i--predefined_pencolor :: M.Map B.ByteString (Double,Double,Double,Double)-predefined_pencolor = - M.fromList [ ("black" , hexToRGBA 0x000000ff)- , ("blue" , hexToRGBA 0x3333ccff)- , ("red" , hexToRGBA 0xff0000ff)- , ("green" , hexToRGBA 0x008000ff)- , ("gray" , hexToRGBA 0x808080ff)- , ("lightblue" , hexToRGBA 0x00c0ffff)- , ("lightgreen", hexToRGBA 0x00ff00ff)- , ("magenta" , hexToRGBA 0xff00ffff)- , ("orange" , hexToRGBA 0xff8000ff)- , ("yellow" , hexToRGBA 0xffff00ff)- , ("white" , hexToRGBA 0xffffffff) ] --{--getPenColor :: B.ByteString -> Maybe (Double,Double,Double,Double) -getPenColor b | (not . B.null) b = - case B.head b of - '#' -> B.tail b --}--predefined_bkgcolor :: M.Map B.ByteString (Double,Double,Double,Double)-predefined_bkgcolor = - M.fromList [ ("" , hexToRGBA 0xffffffff) - , ("blue" , hexToRGBA 0xa0e8ffff)- , ("pink" , hexToRGBA 0xffc0d4ff)- , ("green" , hexToRGBA 0x80ffc0ff)- , ("orange", hexToRGBA 0xffc080ff)- , ("yellow", hexToRGBA 0xffff80ff)- , ("white" , hexToRGBA 0xffffffff) ]--predefined_veryfine :: Double-predefined_veryfine = 0.42 --predefined_fine :: Double-predefined_fine = 0.85--predefined_medium :: Double-predefined_medium = 1.41--predefined_thick :: Double-predefined_thick = 2.26--predefined_verythick :: Double -predefined_verythick = 5.67--predefined_RULING_MARGIN_COLOR :: (Double,Double,Double,Double)-predefined_RULING_MARGIN_COLOR = hexToRGBA 0xff0080ff--predefined_RULING_COLOR :: (Double,Double,Double,Double)-predefined_RULING_COLOR = hexToRGBA 0x40a0ffff--predefined_RULING_THICKNESS :: Double-predefined_RULING_THICKNESS = 0.5--predefined_RULING_LEFTMARGIN :: Double-predefined_RULING_LEFTMARGIN = 72.0--predefined_RULING_TOPMARGIN :: Double-predefined_RULING_TOPMARGIN = 80.0--predefined_RULING_SPACING :: Double-predefined_RULING_SPACING = 24.0--predefined_RULING_BOTTOMMARGIN :: Double -predefined_RULING_BOTTOMMARGIN = predefined_RULING_SPACING--predefined_RULING_GRAPHSPACING :: Double-predefined_RULING_GRAPHSPACING = 14.17
− src/Text/Xournal/Type.hs
@@ -1,99 +0,0 @@-{-# LANGUAGE BangPatterns, OverloadedStrings, - TypeFamilies, FlexibleContexts #-}--module Text.Xournal.Type where--import qualified Data.ByteString as S-import Data.Strict.Tuple--import Prelude hiding (fst,snd,curry,uncurry)--class IStroke a where- strokeTool :: a -> S.ByteString - strokeColor :: a -> S.ByteString- strokeWidth :: a -> Double - strokeData :: a -> [Pair Double Double]--class (IStroke (TStroke a)) => ILayer a where- type TStroke a :: * - layerStrokes :: a -> [TStroke a]--class (ILayer (TLayer a)) => IPage a where - type TLayer a :: * - pageDim :: a -> Dimension- pageBkg :: a -> Background - pageLayers :: a -> [TLayer a] --class (IPage (TPage a)) => IXournal a where- type TPage a :: *- xournalPages :: a -> [TPage a]--type Title = S.ByteString--data Stroke = Stroke { stroke_tool :: !S.ByteString- , stroke_color :: !S.ByteString- , stroke_width :: !Double- , stroke_data :: ![Pair Double Double]- }- deriving Show--data Dimension = Dim { dim_width :: !Double, dim_height :: !Double }- deriving Show--data Background = Background { bkg_type :: !S.ByteString - , bkg_color :: !S.ByteString - , bkg_style :: !S.ByteString - }- deriving Show --data Xournal = Xournal { xoj_title :: !Title, xoj_pages :: ![Page] }- deriving Show --data Page = Page { page_dim :: !Dimension- , page_bkg :: !Background - , page_layers :: ![Layer] }- deriving Show --data Layer = Layer { layer_strokes :: ![Stroke] } - deriving Show --emptyXournal :: Xournal-emptyXournal = Xournal "" [] --defaultBackground :: Background-defaultBackground = Background { bkg_type = "solid"- , bkg_color = "white"- , bkg_style = "lined" - }--defaultLayer :: Layer-defaultLayer = Layer { layer_strokes = [] } --defaultPage :: Page-defaultPage = Page { page_dim = Dim 612.0 792.0 - , page_bkg = defaultBackground- , page_layers = [ defaultLayer ] - } --defaultXournal :: Xournal -defaultXournal = Xournal "untitled" [ defaultPage ] --instance IStroke Stroke where- strokeTool = stroke_tool- strokeColor = stroke_color- strokeWidth = stroke_width- strokeData = stroke_data- -instance ILayer Layer where- type TStroke Layer = Stroke- layerStrokes = layer_strokes --instance IPage Page where- type TLayer Page = Layer - pageDim = page_dim - pageBkg = page_bkg - pageLayers = page_layers--instance IXournal Xournal where- type TPage Xournal = Page - xournalPages = xoj_pages
xournal-parser.cabal view
@@ -1,14 +1,20 @@ Name: xournal-parser-Version: 0.2.0+Version: 0.3 Synopsis: Xournal file parser-Description: Define Xournal type and parser for xournal xml file+Description: Text parser for xournal xml file+Homepage: http://ianwookim.org/hxournal 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+Source-repository head+ type: git+ location: http://www.github.com/wavewave/xournal-parser + Library hs-source-dirs: src ghc-options: -Wall -O2 -threaded -funbox-strict-fields -fno-warn-unused-do-bind@@ -24,14 +30,14 @@ xml-enumerator < 0.4, enumerator >= 0.4.13 && < 0.5, strict == 0.3.*, - iteratee-compress == 0.2.1.*+ iteratee-compress == 0.2.1.*, + xournal-types == 0.1.* Exposed-Modules: - Text.Xournal.Type Text.Xournal.Parse- Text.Xournal.Predefined Text.Xournal.Parse.Enumerator Text.Xournal.Parse.Zlib-+ -- Text.Xournal.Type+ -- Text.Xournal.Predefined