xournal-render 0.5.1 → 0.6
raw patch · 5 files changed
+87/−42 lines, 5 filesdep ~xournal-types
Dependency ranges changed: xournal-types
Files
- src/Graphics/Xournal/Render/BBox.hs +18/−15
- src/Graphics/Xournal/Render/BBoxMapPDF.hs +1/−0
- src/Graphics/Xournal/Render/HitTest.hs +17/−7
- src/Graphics/Xournal/Render/Simple.hs +48/−17
- xournal-render.cabal +3/−3
src/Graphics/Xournal/Render/BBox.hs view
@@ -53,16 +53,24 @@ case M.lookup (stroke_color s) predefined_pencolor of Just (r,g,b,a) -> setSourceRGBA r g b a Nothing -> setSourceRGBA 0 0 0 1 - setLineWidth (stroke_width s * 4.0) - setLineCap LineCapRound- setLineJoin LineJoinRound- drawOneStrokeCurve . stroke_data $ s - stroke - setSourceRGBA 1 1 1 1- setLineWidth (stroke_width s)- drawOneStrokeCurve . stroke_data $ s - stroke-+ case s of+ Stroke _ _ w d -> do + setLineWidth (w * 4.0) + setLineCap LineCapRound+ setLineJoin LineJoinRound+ drawOneStrokeCurve d+ stroke+ setSourceRGBA 1 1 1 1+ setLineWidth w+ drawOneStrokeCurve . stroke_data $ s + stroke+ VWStroke _ _ d -> do + setFillRule FillRuleWinding+ drawOneVWStrokeCurve $ map (\(x,y,z)->(x,y,4*z)) d+ fill + setSourceRGBA 1 1 1 1+ drawOneVWStrokeCurve d + fill cairoOneStrokeBBoxOnly :: StrokeBBox -> Render () cairoOneStrokeBBoxOnly sbbox = do @@ -83,11 +91,6 @@ cairoDrawLayerBBoxOnly :: TLayerBBox -> Render () cairoDrawLayerBBoxOnly = mapM_ cairoOneStrokeBBoxOnly . gstrokes --------inflate :: BBox -> Double -> BBox -inflate (BBox (x1,y1) (x2,y2)) r = BBox (x1-r,y1-r) (x2+r,y2+r) ----
src/Graphics/Xournal/Render/BBoxMapPDF.hs view
@@ -12,6 +12,7 @@ -- Stability : experimental -- Portability : GHC --+----------------------------------------------------------------------------- module Graphics.Xournal.Render.BBoxMapPDF where
src/Graphics/Xournal/Render/HitTest.hs view
@@ -10,6 +10,7 @@ -- Stability : experimental -- Portability : GHC --+----------------------------------------------------------------------------- module Graphics.Xournal.Render.HitTest where @@ -35,19 +36,27 @@ x43 = x4-x3 y21 = y2-y1 y43 = y4-y3- -- denom = y21*x43-y43*x21 xc = (x21*x43*(y3-y1)+y21*x43*x1-y43*x21*x3)/(y21*x43-y43*x21) hitTestLineStroke :: ((Double,Double),(Double,Double)) -> Stroke -> Bool-hitTestLineStroke line1 str = test (stroke_data str) +hitTestLineStroke line1 str@(Stroke _t _c _w _d) = test (stroke_data str) where test [] = False test ((_:!:_):[]) = False test ((x0:!:y0):(x:!:y):rest) = hitTestLineLine line1 ((x0,y0),(x,y)) || test ((x:!:y) : rest)+hitTestLineStroke line1 (VWStroke _t _c d) = test d + where test [] = False+ test ((_,_,_):[]) = False+ test ((x0,y0,_):(x,y,z):rest) + = hitTestLineLine line1 ((x0,y0),(x,y))+ || test ((x,y,z) : rest) +++ mkHitTestAL :: (StrokeBBox -> Bool) -> [StrokeBBox] -> AlterList (NotHitted StrokeBBox) (Hitted StrokeBBox)@@ -110,6 +119,9 @@ h' <- mkHitTestStroke line (unHitted h) (n:-) . (h':-) <$> hitTestStrokes line rest ++-- | + elimHitted :: AlterList (NotHitted StrokeBBox) (Hitted StrokeBBox) -> State (Maybe BBox) [StrokeBBox] elimHitted Empty = error "something wrong in elimHitted" elimHitted (n:-Empty) = return (unNotHitted n)@@ -119,6 +131,7 @@ put (merge bbox bbox2) return . (unNotHitted n ++) =<< elimHitted rest +-- | merge :: Maybe BBox -> Maybe BBox -> Maybe BBox merge Nothing Nothing = Nothing@@ -127,12 +140,9 @@ merge (Just (BBox (x1,y1) (x2,y2))) (Just (BBox (x3,y3) (x4,y4))) = Just (BBox (min x1 x3, min y1 y3) (max x2 x4,max y2 y4)) +-- | + getTotalBBox :: [StrokeBBox] -> Maybe BBox getTotalBBox = foldl f Nothing where f acc = merge acc . Just . strokebbox_bbox-----
src/Graphics/Xournal/Render/Simple.hs view
@@ -10,33 +10,44 @@ -- Stability : experimental -- Portability : GHC --+----------------------------------------------------------------------------- module Graphics.Xournal.Render.Simple where import Graphics.Rendering.Cairo-import Data.Strict.Tuple-+import Control.Applicative+import Control.Monad+import Data.Strict.Tuple hiding (fst,snd) import Data.Xournal.Simple import Data.Xournal.Predefined - import qualified Data.Map as M import qualified Data.ByteString.Char8 as S ++-- | + drawOneStroke :: Stroke -> Render () drawOneStroke s = do let opacity = if stroke_tool s == "highlighter" then predefined_highlighter_opacity else 1.0- case M.lookup (stroke_color s) predefined_pencolor of Just (r,g,b,a) -> setSourceRGBA r g b (a*opacity) Nothing -> setSourceRGBA 0 0 0 1- setLineWidth . stroke_width $ s - setLineCap LineCapRound- setLineJoin LineJoinRound- drawOneStrokeCurve . stroke_data $ s- stroke-+ case s of+ Stroke _ _ w d -> do + setLineWidth w+ setLineCap LineCapRound+ setLineJoin LineJoinRound+ drawOneStrokeCurve d+ stroke+ VWStroke _ _ d -> do + setFillRule FillRuleWinding+ drawOneVWStrokeCurve d+ fill + +-- | + drawOneStrokeCurve :: [Pair Double Double] -> Render () drawOneStrokeCurve ((x0 :!: y0) : xs) = do x0 `seq` y0 `seq` moveTo x0 y0@@ -44,23 +55,43 @@ where f (x :!: y) = x `seq` y `seq` lineTo x y drawOneStrokeCurve [] = return () ++drawOneVWStrokeCurve :: [(Double,Double,Double)] -> Render ()+drawOneVWStrokeCurve [] = return ()+drawOneVWStrokeCurve (_:[]) = return ()+drawOneVWStrokeCurve ((xo,yo,_zo) : xs) = do + moveTo xo yo+ let ((xlast,ylast,_zlast):rxs) = reverse xs + foldM_ forward (xo,yo) xs + foldM_ backward (xlast,ylast) rxs + where (dx,dy) = (,) <$> fst <*> snd $ predefinedPenShapeAspectXY+ dir (x,y) = x * dy - y * dx+ forward (x0,y0) (x,y,z) = do if (dir (x-x0,y-y0) > 0) + then lineTo (x+0.5*dx*z) (y+0.5*dy*z)+ else lineTo (x-0.5*dx*z) (y-0.5*dy*z) + return (x,y) + backward (x0,y0) (x,y,z) = do if (dir (x-x0,y-y0) < 0) + then lineTo (x-0.5*dx*z) (y-0.5*dy*z)+ else lineTo (x+0.5*dx*z) (y+0.5*dy*z)+ return (x,y)++ -- | general background drawing (including pdf file) + cairoDrawBackground :: Page -> Render () cairoDrawBackground page = do let Dim w h = page_dim page case page_bkg page of Background typ col sty -> cairoDrawBkg (Dim w h) (Background typ col sty)- BackgroundPdf _ mdomain mfilename pagenum -> - cairoDrawPdfBkg (Dim w h) mdomain mfilename pagenum + BackgroundPdf _ _mdomain _mfilename _pagenum -> + error "in cairoDrawBackground, pdf drawing is not defined yet"+ -- cairoDrawPdfBkg (Dim w h) mdomain mfilename pagenum -cairoDrawPdfBkg :: Dimension -> Maybe S.ByteString - -> Maybe S.ByteString -> Int - -> Render () -cairoDrawPdfBkg = do - error "pdf bkg is not implemented" +-- | + cairoDrawBkg :: Dimension -> Background -> Render () cairoDrawBkg (Dim w h) (Background _typ col sty) = do let c = M.lookup col predefined_bkgcolor
xournal-render.cabal view
@@ -1,5 +1,5 @@ Name: xournal-render-Version: 0.5.1+Version: 0.6 Synopsis: Xournal file renderer Description: Rendering library using cairo for xournal file format License: BSD3@@ -32,7 +32,7 @@ bytestring == 0.9.*, poppler == 0.12.*, fclabels == 1.0.*, - xournal-types >= 0.3.1 && < 0.4,+ xournal-types == 0.4.*, TypeCompose == 0.9.* else Build-Depends: base == 4.*, @@ -42,7 +42,7 @@ strict == 0.3.*, bytestring == 0.9.*, fclabels == 1.0.*, - xournal-types >= 0.3.1 && < 0.4,+ xournal-types == 0.4.*, TypeCompose == 0.9.*