{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module Codec.Xlsx.Types.Drawing where

import Control.Arrow (first)
import Control.DeepSeq (NFData)
#ifdef USE_MICROLENS
import Lens.Micro.TH (makeLenses)
#else
import Control.Lens.TH
#endif
import Data.ByteString.Lazy (ByteString)
import Data.Default
import qualified Data.Map as M
import Data.Maybe (catMaybes, listToMaybe, mapMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics (Generic)
import Text.XML
import Text.XML.Cursor

import Codec.Xlsx.Parser.Internal
import Codec.Xlsx.Types.Drawing.Chart
import Codec.Xlsx.Types.Drawing.Common
import Codec.Xlsx.Types.Internal
import Codec.Xlsx.Types.Internal.Relationships
import Codec.Xlsx.Writer.Internal

-- | information about image file as a par of a drawing
data FileInfo = FileInfo
    { FileInfo -> FilePath
_fiFilename    :: FilePath
    -- ^ image filename, images are assumed to be stored under path "xl\/media\/"
    , FileInfo -> Text
_fiContentType :: Text
    -- ^ image content type, ECMA-376 advises to use "image\/png" or "image\/jpeg"
    -- if interoperability is wanted
    , FileInfo -> ByteString
_fiContents    :: ByteString
    -- ^ image file contents
    } deriving (FileInfo -> FileInfo -> Bool
(FileInfo -> FileInfo -> Bool)
-> (FileInfo -> FileInfo -> Bool) -> Eq FileInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileInfo -> FileInfo -> Bool
$c/= :: FileInfo -> FileInfo -> Bool
== :: FileInfo -> FileInfo -> Bool
$c== :: FileInfo -> FileInfo -> Bool
Eq, Int -> FileInfo -> ShowS
[FileInfo] -> ShowS
FileInfo -> FilePath
(Int -> FileInfo -> ShowS)
-> (FileInfo -> FilePath) -> ([FileInfo] -> ShowS) -> Show FileInfo
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [FileInfo] -> ShowS
$cshowList :: [FileInfo] -> ShowS
show :: FileInfo -> FilePath
$cshow :: FileInfo -> FilePath
showsPrec :: Int -> FileInfo -> ShowS
$cshowsPrec :: Int -> FileInfo -> ShowS
Show, (forall x. FileInfo -> Rep FileInfo x)
-> (forall x. Rep FileInfo x -> FileInfo) -> Generic FileInfo
forall x. Rep FileInfo x -> FileInfo
forall x. FileInfo -> Rep FileInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FileInfo x -> FileInfo
$cfrom :: forall x. FileInfo -> Rep FileInfo x
Generic)
instance NFData FileInfo

data Marker = Marker
    { Marker -> Int
_mrkCol    :: Int
    , Marker -> Coordinate
_mrkColOff :: Coordinate
    , Marker -> Int
_mrkRow    :: Int
    , Marker -> Coordinate
_mrkRowOff :: Coordinate
    } deriving (Marker -> Marker -> Bool
(Marker -> Marker -> Bool)
-> (Marker -> Marker -> Bool) -> Eq Marker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Marker -> Marker -> Bool
$c/= :: Marker -> Marker -> Bool
== :: Marker -> Marker -> Bool
$c== :: Marker -> Marker -> Bool
Eq, Int -> Marker -> ShowS
[Marker] -> ShowS
Marker -> FilePath
(Int -> Marker -> ShowS)
-> (Marker -> FilePath) -> ([Marker] -> ShowS) -> Show Marker
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Marker] -> ShowS
$cshowList :: [Marker] -> ShowS
show :: Marker -> FilePath
$cshow :: Marker -> FilePath
showsPrec :: Int -> Marker -> ShowS
$cshowsPrec :: Int -> Marker -> ShowS
Show, (forall x. Marker -> Rep Marker x)
-> (forall x. Rep Marker x -> Marker) -> Generic Marker
forall x. Rep Marker x -> Marker
forall x. Marker -> Rep Marker x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Marker x -> Marker
$cfrom :: forall x. Marker -> Rep Marker x
Generic)
instance NFData Marker

unqMarker :: (Int, Int) -> (Int, Int) -> Marker
unqMarker :: (Int, Int) -> (Int, Int) -> Marker
unqMarker (Int
col, Int
colOff) (Int
row, Int
rowOff) =
    Int -> Coordinate -> Int -> Coordinate -> Marker
Marker Int
col (Int -> Coordinate
UnqCoordinate Int
colOff) Int
row (Int -> Coordinate
UnqCoordinate Int
rowOff)

data EditAs
    = EditAsTwoCell
    | EditAsOneCell
    | EditAsAbsolute
    deriving (EditAs -> EditAs -> Bool
(EditAs -> EditAs -> Bool)
-> (EditAs -> EditAs -> Bool) -> Eq EditAs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EditAs -> EditAs -> Bool
$c/= :: EditAs -> EditAs -> Bool
== :: EditAs -> EditAs -> Bool
$c== :: EditAs -> EditAs -> Bool
Eq, Int -> EditAs -> ShowS
[EditAs] -> ShowS
EditAs -> FilePath
(Int -> EditAs -> ShowS)
-> (EditAs -> FilePath) -> ([EditAs] -> ShowS) -> Show EditAs
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [EditAs] -> ShowS
$cshowList :: [EditAs] -> ShowS
show :: EditAs -> FilePath
$cshow :: EditAs -> FilePath
showsPrec :: Int -> EditAs -> ShowS
$cshowsPrec :: Int -> EditAs -> ShowS
Show, (forall x. EditAs -> Rep EditAs x)
-> (forall x. Rep EditAs x -> EditAs) -> Generic EditAs
forall x. Rep EditAs x -> EditAs
forall x. EditAs -> Rep EditAs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EditAs x -> EditAs
$cfrom :: forall x. EditAs -> Rep EditAs x
Generic)
instance NFData EditAs

data Anchoring
    = AbsoluteAnchor
      { Anchoring -> Point2D
absaPos :: Point2D
      , Anchoring -> PositiveSize2D
absaExt :: PositiveSize2D
      }
    | OneCellAnchor
      { Anchoring -> Marker
onecaFrom :: Marker
      , Anchoring -> PositiveSize2D
onecaExt  :: PositiveSize2D
      }
    | TwoCellAnchor
      { Anchoring -> Marker
tcaFrom   :: Marker
      , Anchoring -> Marker
tcaTo     :: Marker
      , Anchoring -> EditAs
tcaEditAs :: EditAs
      }
    deriving (Anchoring -> Anchoring -> Bool
(Anchoring -> Anchoring -> Bool)
-> (Anchoring -> Anchoring -> Bool) -> Eq Anchoring
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Anchoring -> Anchoring -> Bool
$c/= :: Anchoring -> Anchoring -> Bool
== :: Anchoring -> Anchoring -> Bool
$c== :: Anchoring -> Anchoring -> Bool
Eq, Int -> Anchoring -> ShowS
[Anchoring] -> ShowS
Anchoring -> FilePath
(Int -> Anchoring -> ShowS)
-> (Anchoring -> FilePath)
-> ([Anchoring] -> ShowS)
-> Show Anchoring
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Anchoring] -> ShowS
$cshowList :: [Anchoring] -> ShowS
show :: Anchoring -> FilePath
$cshow :: Anchoring -> FilePath
showsPrec :: Int -> Anchoring -> ShowS
$cshowsPrec :: Int -> Anchoring -> ShowS
Show, (forall x. Anchoring -> Rep Anchoring x)
-> (forall x. Rep Anchoring x -> Anchoring) -> Generic Anchoring
forall x. Rep Anchoring x -> Anchoring
forall x. Anchoring -> Rep Anchoring x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Anchoring x -> Anchoring
$cfrom :: forall x. Anchoring -> Rep Anchoring x
Generic)
instance NFData Anchoring

data DrawingObject p g
  = Picture { DrawingObject p g -> Maybe Text
_picMacro :: Maybe Text
           ,  DrawingObject p g -> Bool
_picPublished :: Bool
           ,  DrawingObject p g -> PicNonVisual
_picNonVisual :: PicNonVisual
           ,  DrawingObject p g -> BlipFillProperties p
_picBlipFill :: BlipFillProperties p
           ,  DrawingObject p g -> ShapeProperties
_picShapeProperties :: ShapeProperties
              -- TODO: style
            }
  | Graphic { DrawingObject p g -> GraphNonVisual
_grNonVisual :: GraphNonVisual
           ,  DrawingObject p g -> g
_grChartSpace :: g
           ,  DrawingObject p g -> Transform2D
_grTransform :: Transform2D}
    -- TODO: sp, grpSp, graphicFrame, cxnSp, contentPart
  deriving (DrawingObject p g -> DrawingObject p g -> Bool
(DrawingObject p g -> DrawingObject p g -> Bool)
-> (DrawingObject p g -> DrawingObject p g -> Bool)
-> Eq (DrawingObject p g)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall p g.
(Eq p, Eq g) =>
DrawingObject p g -> DrawingObject p g -> Bool
/= :: DrawingObject p g -> DrawingObject p g -> Bool
$c/= :: forall p g.
(Eq p, Eq g) =>
DrawingObject p g -> DrawingObject p g -> Bool
== :: DrawingObject p g -> DrawingObject p g -> Bool
$c== :: forall p g.
(Eq p, Eq g) =>
DrawingObject p g -> DrawingObject p g -> Bool
Eq, Int -> DrawingObject p g -> ShowS
[DrawingObject p g] -> ShowS
DrawingObject p g -> FilePath
(Int -> DrawingObject p g -> ShowS)
-> (DrawingObject p g -> FilePath)
-> ([DrawingObject p g] -> ShowS)
-> Show (DrawingObject p g)
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
forall p g. (Show p, Show g) => Int -> DrawingObject p g -> ShowS
forall p g. (Show p, Show g) => [DrawingObject p g] -> ShowS
forall p g. (Show p, Show g) => DrawingObject p g -> FilePath
showList :: [DrawingObject p g] -> ShowS
$cshowList :: forall p g. (Show p, Show g) => [DrawingObject p g] -> ShowS
show :: DrawingObject p g -> FilePath
$cshow :: forall p g. (Show p, Show g) => DrawingObject p g -> FilePath
showsPrec :: Int -> DrawingObject p g -> ShowS
$cshowsPrec :: forall p g. (Show p, Show g) => Int -> DrawingObject p g -> ShowS
Show, (forall x. DrawingObject p g -> Rep (DrawingObject p g) x)
-> (forall x. Rep (DrawingObject p g) x -> DrawingObject p g)
-> Generic (DrawingObject p g)
forall x. Rep (DrawingObject p g) x -> DrawingObject p g
forall x. DrawingObject p g -> Rep (DrawingObject p g) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall p g x. Rep (DrawingObject p g) x -> DrawingObject p g
forall p g x. DrawingObject p g -> Rep (DrawingObject p g) x
$cto :: forall p g x. Rep (DrawingObject p g) x -> DrawingObject p g
$cfrom :: forall p g x. DrawingObject p g -> Rep (DrawingObject p g) x
Generic)
instance (NFData p, NFData g) => NFData (DrawingObject p g)

-- | basic function to create picture drawing object
--
-- /Note:/ specification says that drawing element ids need to be
-- unique within 1 document, otherwise /...document shall be
-- considered non-conformant/.
picture :: DrawingElementId -> FileInfo -> DrawingObject FileInfo c
picture :: DrawingElementId -> FileInfo -> DrawingObject FileInfo c
picture DrawingElementId
dId FileInfo
fi =
  Picture :: forall p g.
Maybe Text
-> Bool
-> PicNonVisual
-> BlipFillProperties p
-> ShapeProperties
-> DrawingObject p g
Picture
  { _picMacro :: Maybe Text
_picMacro = Maybe Text
forall a. Maybe a
Nothing
  , _picPublished :: Bool
_picPublished = Bool
False
  , _picNonVisual :: PicNonVisual
_picNonVisual = PicNonVisual
nonVis
  , _picBlipFill :: BlipFillProperties FileInfo
_picBlipFill = BlipFillProperties FileInfo
bfProps
  , _picShapeProperties :: ShapeProperties
_picShapeProperties = ShapeProperties
shProps
  }
  where
    nonVis :: PicNonVisual
nonVis =
      NonVisualDrawingProperties -> PicNonVisual
PicNonVisual (NonVisualDrawingProperties -> PicNonVisual)
-> NonVisualDrawingProperties -> PicNonVisual
forall a b. (a -> b) -> a -> b
$
      NonVisualDrawingProperties :: DrawingElementId
-> Text
-> Maybe Text
-> Bool
-> Maybe Text
-> NonVisualDrawingProperties
NonVisualDrawingProperties
      { _nvdpId :: DrawingElementId
_nvdpId = DrawingElementId
dId
      , _nvdpName :: Text
_nvdpName = FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ FileInfo -> FilePath
_fiFilename FileInfo
fi
      , _nvdpDescription :: Maybe Text
_nvdpDescription = Maybe Text
forall a. Maybe a
Nothing
      , _nvdpHidden :: Bool
_nvdpHidden = Bool
False
      , _nvdpTitle :: Maybe Text
_nvdpTitle = Maybe Text
forall a. Maybe a
Nothing
      }
    bfProps :: BlipFillProperties FileInfo
bfProps =
      BlipFillProperties :: forall a. Maybe a -> Maybe FillMode -> BlipFillProperties a
BlipFillProperties
      {_bfpImageInfo :: Maybe FileInfo
_bfpImageInfo = FileInfo -> Maybe FileInfo
forall a. a -> Maybe a
Just FileInfo
fi, _bfpFillMode :: Maybe FillMode
_bfpFillMode = FillMode -> Maybe FillMode
forall a. a -> Maybe a
Just FillMode
FillStretch}
    shProps :: ShapeProperties
shProps =
      ShapeProperties :: Maybe Transform2D
-> Maybe Geometry
-> Maybe FillProperties
-> Maybe LineProperties
-> ShapeProperties
ShapeProperties
      { _spXfrm :: Maybe Transform2D
_spXfrm = Maybe Transform2D
forall a. Maybe a
Nothing
      , _spGeometry :: Maybe Geometry
_spGeometry = Maybe Geometry
forall a. Maybe a
Nothing
      , _spFill :: Maybe FillProperties
_spFill = FillProperties -> Maybe FillProperties
forall a. a -> Maybe a
Just FillProperties
NoFill
      , _spOutline :: Maybe LineProperties
_spOutline = LineProperties -> Maybe LineProperties
forall a. a -> Maybe a
Just (LineProperties -> Maybe LineProperties)
-> LineProperties -> Maybe LineProperties
forall a b. (a -> b) -> a -> b
$ LineProperties
forall a. Default a => a
def {_lnFill :: Maybe FillProperties
_lnFill = FillProperties -> Maybe FillProperties
forall a. a -> Maybe a
Just FillProperties
NoFill}
      }

-- | helper to retrive information about all picture files in
-- particular drawing alongside with their anchorings (i.e. sizes and
-- positions)
extractPictures :: Drawing -> [(Anchoring, FileInfo)]
extractPictures :: Drawing -> [(Anchoring, FileInfo)]
extractPictures Drawing
dr = (Anchor FileInfo ChartSpace -> Maybe (Anchoring, FileInfo))
-> [Anchor FileInfo ChartSpace] -> [(Anchoring, FileInfo)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Anchor FileInfo ChartSpace -> Maybe (Anchoring, FileInfo)
forall t g. Anchor t g -> Maybe (Anchoring, t)
maybePictureInfo ([Anchor FileInfo ChartSpace] -> [(Anchoring, FileInfo)])
-> [Anchor FileInfo ChartSpace] -> [(Anchoring, FileInfo)]
forall a b. (a -> b) -> a -> b
$ Drawing -> [Anchor FileInfo ChartSpace]
forall p g. GenericDrawing p g -> [Anchor p g]
_xdrAnchors Drawing
dr
  where
    maybePictureInfo :: Anchor t g -> Maybe (Anchoring, t)
maybePictureInfo Anchor {ClientData
DrawingObject t g
Anchoring
_anchClientData :: forall p g. Anchor p g -> ClientData
_anchObject :: forall p g. Anchor p g -> DrawingObject p g
_anchAnchoring :: forall p g. Anchor p g -> Anchoring
_anchClientData :: ClientData
_anchObject :: DrawingObject t g
_anchAnchoring :: Anchoring
..} =
      case DrawingObject t g
_anchObject of
        Picture {Bool
Maybe Text
ShapeProperties
BlipFillProperties t
PicNonVisual
_picShapeProperties :: ShapeProperties
_picBlipFill :: BlipFillProperties t
_picNonVisual :: PicNonVisual
_picPublished :: Bool
_picMacro :: Maybe Text
_picShapeProperties :: forall p g. DrawingObject p g -> ShapeProperties
_picBlipFill :: forall p g. DrawingObject p g -> BlipFillProperties p
_picNonVisual :: forall p g. DrawingObject p g -> PicNonVisual
_picPublished :: forall p g. DrawingObject p g -> Bool
_picMacro :: forall p g. DrawingObject p g -> Maybe Text
..} -> (Anchoring
_anchAnchoring,) (t -> (Anchoring, t)) -> Maybe t -> Maybe (Anchoring, t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BlipFillProperties t -> Maybe t
forall a. BlipFillProperties a -> Maybe a
_bfpImageInfo BlipFillProperties t
_picBlipFill
        DrawingObject t g
_ -> Maybe (Anchoring, t)
forall a. Maybe a
Nothing

-- | This element is used to set certain properties related to a drawing
-- element on the client spreadsheet application.
--
-- see 20.5.2.3 "clientData (Client Data)" (p. 3156)
data ClientData = ClientData
    { ClientData -> Bool
_cldLcksWithSheet   :: Bool
    -- ^ This attribute indicates whether to disable selection on
    -- drawing elements when the sheet is protected.
    , ClientData -> Bool
_cldPrintsWithSheet :: Bool
    -- ^ This attribute indicates whether to print drawing elements
    -- when printing the sheet.
    } deriving (ClientData -> ClientData -> Bool
(ClientData -> ClientData -> Bool)
-> (ClientData -> ClientData -> Bool) -> Eq ClientData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClientData -> ClientData -> Bool
$c/= :: ClientData -> ClientData -> Bool
== :: ClientData -> ClientData -> Bool
$c== :: ClientData -> ClientData -> Bool
Eq, Int -> ClientData -> ShowS
[ClientData] -> ShowS
ClientData -> FilePath
(Int -> ClientData -> ShowS)
-> (ClientData -> FilePath)
-> ([ClientData] -> ShowS)
-> Show ClientData
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ClientData] -> ShowS
$cshowList :: [ClientData] -> ShowS
show :: ClientData -> FilePath
$cshow :: ClientData -> FilePath
showsPrec :: Int -> ClientData -> ShowS
$cshowsPrec :: Int -> ClientData -> ShowS
Show, (forall x. ClientData -> Rep ClientData x)
-> (forall x. Rep ClientData x -> ClientData) -> Generic ClientData
forall x. Rep ClientData x -> ClientData
forall x. ClientData -> Rep ClientData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ClientData x -> ClientData
$cfrom :: forall x. ClientData -> Rep ClientData x
Generic)
instance NFData ClientData

data PicNonVisual = PicNonVisual
  { PicNonVisual -> NonVisualDrawingProperties
_pnvDrawingProps :: NonVisualDrawingProperties
    -- TODO: cNvPicPr
  } deriving (PicNonVisual -> PicNonVisual -> Bool
(PicNonVisual -> PicNonVisual -> Bool)
-> (PicNonVisual -> PicNonVisual -> Bool) -> Eq PicNonVisual
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PicNonVisual -> PicNonVisual -> Bool
$c/= :: PicNonVisual -> PicNonVisual -> Bool
== :: PicNonVisual -> PicNonVisual -> Bool
$c== :: PicNonVisual -> PicNonVisual -> Bool
Eq, Int -> PicNonVisual -> ShowS
[PicNonVisual] -> ShowS
PicNonVisual -> FilePath
(Int -> PicNonVisual -> ShowS)
-> (PicNonVisual -> FilePath)
-> ([PicNonVisual] -> ShowS)
-> Show PicNonVisual
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PicNonVisual] -> ShowS
$cshowList :: [PicNonVisual] -> ShowS
show :: PicNonVisual -> FilePath
$cshow :: PicNonVisual -> FilePath
showsPrec :: Int -> PicNonVisual -> ShowS
$cshowsPrec :: Int -> PicNonVisual -> ShowS
Show, (forall x. PicNonVisual -> Rep PicNonVisual x)
-> (forall x. Rep PicNonVisual x -> PicNonVisual)
-> Generic PicNonVisual
forall x. Rep PicNonVisual x -> PicNonVisual
forall x. PicNonVisual -> Rep PicNonVisual x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PicNonVisual x -> PicNonVisual
$cfrom :: forall x. PicNonVisual -> Rep PicNonVisual x
Generic)
instance NFData PicNonVisual

data GraphNonVisual = GraphNonVisual
  { GraphNonVisual -> NonVisualDrawingProperties
_gnvDrawingProps :: NonVisualDrawingProperties
    -- TODO cNvGraphicFramePr
  } deriving (GraphNonVisual -> GraphNonVisual -> Bool
(GraphNonVisual -> GraphNonVisual -> Bool)
-> (GraphNonVisual -> GraphNonVisual -> Bool) -> Eq GraphNonVisual
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GraphNonVisual -> GraphNonVisual -> Bool
$c/= :: GraphNonVisual -> GraphNonVisual -> Bool
== :: GraphNonVisual -> GraphNonVisual -> Bool
$c== :: GraphNonVisual -> GraphNonVisual -> Bool
Eq, Int -> GraphNonVisual -> ShowS
[GraphNonVisual] -> ShowS
GraphNonVisual -> FilePath
(Int -> GraphNonVisual -> ShowS)
-> (GraphNonVisual -> FilePath)
-> ([GraphNonVisual] -> ShowS)
-> Show GraphNonVisual
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [GraphNonVisual] -> ShowS
$cshowList :: [GraphNonVisual] -> ShowS
show :: GraphNonVisual -> FilePath
$cshow :: GraphNonVisual -> FilePath
showsPrec :: Int -> GraphNonVisual -> ShowS
$cshowsPrec :: Int -> GraphNonVisual -> ShowS
Show, (forall x. GraphNonVisual -> Rep GraphNonVisual x)
-> (forall x. Rep GraphNonVisual x -> GraphNonVisual)
-> Generic GraphNonVisual
forall x. Rep GraphNonVisual x -> GraphNonVisual
forall x. GraphNonVisual -> Rep GraphNonVisual x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GraphNonVisual x -> GraphNonVisual
$cfrom :: forall x. GraphNonVisual -> Rep GraphNonVisual x
Generic)
instance NFData GraphNonVisual

newtype DrawingElementId = DrawingElementId
  { DrawingElementId -> Int
unDrawingElementId :: Int
  } deriving (DrawingElementId -> DrawingElementId -> Bool
(DrawingElementId -> DrawingElementId -> Bool)
-> (DrawingElementId -> DrawingElementId -> Bool)
-> Eq DrawingElementId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DrawingElementId -> DrawingElementId -> Bool
$c/= :: DrawingElementId -> DrawingElementId -> Bool
== :: DrawingElementId -> DrawingElementId -> Bool
$c== :: DrawingElementId -> DrawingElementId -> Bool
Eq, Int -> DrawingElementId -> ShowS
[DrawingElementId] -> ShowS
DrawingElementId -> FilePath
(Int -> DrawingElementId -> ShowS)
-> (DrawingElementId -> FilePath)
-> ([DrawingElementId] -> ShowS)
-> Show DrawingElementId
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [DrawingElementId] -> ShowS
$cshowList :: [DrawingElementId] -> ShowS
show :: DrawingElementId -> FilePath
$cshow :: DrawingElementId -> FilePath
showsPrec :: Int -> DrawingElementId -> ShowS
$cshowsPrec :: Int -> DrawingElementId -> ShowS
Show, (forall x. DrawingElementId -> Rep DrawingElementId x)
-> (forall x. Rep DrawingElementId x -> DrawingElementId)
-> Generic DrawingElementId
forall x. Rep DrawingElementId x -> DrawingElementId
forall x. DrawingElementId -> Rep DrawingElementId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DrawingElementId x -> DrawingElementId
$cfrom :: forall x. DrawingElementId -> Rep DrawingElementId x
Generic)
instance NFData DrawingElementId

-- see 20.1.2.2.8 "cNvPr (Non-Visual Drawing Properties)" (p. 2731)
data NonVisualDrawingProperties = NonVisualDrawingProperties
    { NonVisualDrawingProperties -> DrawingElementId
_nvdpId          :: DrawingElementId
    -- ^ Specifies a unique identifier for the current
    -- DrawingML object within the current
    --
    -- TODO: make ids internal and consistent by construction
    , NonVisualDrawingProperties -> Text
_nvdpName        :: Text
    -- ^ Specifies the name of the object.
    -- Typically, this is used to store the original file
    -- name of a picture object.
    , NonVisualDrawingProperties -> Maybe Text
_nvdpDescription :: Maybe Text
    -- ^ Alternative Text for Object
    , NonVisualDrawingProperties -> Bool
_nvdpHidden      :: Bool
    , NonVisualDrawingProperties -> Maybe Text
_nvdpTitle       :: Maybe Text
    } deriving (NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
(NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool)
-> (NonVisualDrawingProperties
    -> NonVisualDrawingProperties -> Bool)
-> Eq NonVisualDrawingProperties
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
$c/= :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
== :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
$c== :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
Eq, Int -> NonVisualDrawingProperties -> ShowS
[NonVisualDrawingProperties] -> ShowS
NonVisualDrawingProperties -> FilePath
(Int -> NonVisualDrawingProperties -> ShowS)
-> (NonVisualDrawingProperties -> FilePath)
-> ([NonVisualDrawingProperties] -> ShowS)
-> Show NonVisualDrawingProperties
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [NonVisualDrawingProperties] -> ShowS
$cshowList :: [NonVisualDrawingProperties] -> ShowS
show :: NonVisualDrawingProperties -> FilePath
$cshow :: NonVisualDrawingProperties -> FilePath
showsPrec :: Int -> NonVisualDrawingProperties -> ShowS
$cshowsPrec :: Int -> NonVisualDrawingProperties -> ShowS
Show, (forall x.
 NonVisualDrawingProperties -> Rep NonVisualDrawingProperties x)
-> (forall x.
    Rep NonVisualDrawingProperties x -> NonVisualDrawingProperties)
-> Generic NonVisualDrawingProperties
forall x.
Rep NonVisualDrawingProperties x -> NonVisualDrawingProperties
forall x.
NonVisualDrawingProperties -> Rep NonVisualDrawingProperties x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep NonVisualDrawingProperties x -> NonVisualDrawingProperties
$cfrom :: forall x.
NonVisualDrawingProperties -> Rep NonVisualDrawingProperties x
Generic)
instance NFData NonVisualDrawingProperties

data BlipFillProperties a = BlipFillProperties
    { BlipFillProperties a -> Maybe a
_bfpImageInfo :: Maybe a
    , BlipFillProperties a -> Maybe FillMode
_bfpFillMode  :: Maybe FillMode
    -- TODO: dpi, rotWithShape, srcRect
    } deriving (BlipFillProperties a -> BlipFillProperties a -> Bool
(BlipFillProperties a -> BlipFillProperties a -> Bool)
-> (BlipFillProperties a -> BlipFillProperties a -> Bool)
-> Eq (BlipFillProperties a)
forall a.
Eq a =>
BlipFillProperties a -> BlipFillProperties a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlipFillProperties a -> BlipFillProperties a -> Bool
$c/= :: forall a.
Eq a =>
BlipFillProperties a -> BlipFillProperties a -> Bool
== :: BlipFillProperties a -> BlipFillProperties a -> Bool
$c== :: forall a.
Eq a =>
BlipFillProperties a -> BlipFillProperties a -> Bool
Eq, Int -> BlipFillProperties a -> ShowS
[BlipFillProperties a] -> ShowS
BlipFillProperties a -> FilePath
(Int -> BlipFillProperties a -> ShowS)
-> (BlipFillProperties a -> FilePath)
-> ([BlipFillProperties a] -> ShowS)
-> Show (BlipFillProperties a)
forall a. Show a => Int -> BlipFillProperties a -> ShowS
forall a. Show a => [BlipFillProperties a] -> ShowS
forall a. Show a => BlipFillProperties a -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [BlipFillProperties a] -> ShowS
$cshowList :: forall a. Show a => [BlipFillProperties a] -> ShowS
show :: BlipFillProperties a -> FilePath
$cshow :: forall a. Show a => BlipFillProperties a -> FilePath
showsPrec :: Int -> BlipFillProperties a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> BlipFillProperties a -> ShowS
Show, (forall x. BlipFillProperties a -> Rep (BlipFillProperties a) x)
-> (forall x. Rep (BlipFillProperties a) x -> BlipFillProperties a)
-> Generic (BlipFillProperties a)
forall x. Rep (BlipFillProperties a) x -> BlipFillProperties a
forall x. BlipFillProperties a -> Rep (BlipFillProperties a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (BlipFillProperties a) x -> BlipFillProperties a
forall a x. BlipFillProperties a -> Rep (BlipFillProperties a) x
$cto :: forall a x. Rep (BlipFillProperties a) x -> BlipFillProperties a
$cfrom :: forall a x. BlipFillProperties a -> Rep (BlipFillProperties a) x
Generic)
instance NFData a => NFData (BlipFillProperties a)

-- see @a_EG_FillModeProperties@ (p. 4319)
data FillMode
    -- See 20.1.8.58 "tile (Tile)" (p. 2880)
    = FillTile    -- TODO: tx, ty, sx, sy, flip, algn
    -- See 20.1.8.56 "stretch (Stretch)" (p. 2879)
    | FillStretch -- TODO: srcRect
    deriving (FillMode -> FillMode -> Bool
(FillMode -> FillMode -> Bool)
-> (FillMode -> FillMode -> Bool) -> Eq FillMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FillMode -> FillMode -> Bool
$c/= :: FillMode -> FillMode -> Bool
== :: FillMode -> FillMode -> Bool
$c== :: FillMode -> FillMode -> Bool
Eq, Int -> FillMode -> ShowS
[FillMode] -> ShowS
FillMode -> FilePath
(Int -> FillMode -> ShowS)
-> (FillMode -> FilePath) -> ([FillMode] -> ShowS) -> Show FillMode
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [FillMode] -> ShowS
$cshowList :: [FillMode] -> ShowS
show :: FillMode -> FilePath
$cshow :: FillMode -> FilePath
showsPrec :: Int -> FillMode -> ShowS
$cshowsPrec :: Int -> FillMode -> ShowS
Show, (forall x. FillMode -> Rep FillMode x)
-> (forall x. Rep FillMode x -> FillMode) -> Generic FillMode
forall x. Rep FillMode x -> FillMode
forall x. FillMode -> Rep FillMode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FillMode x -> FillMode
$cfrom :: forall x. FillMode -> Rep FillMode x
Generic)
instance NFData FillMode

-- See @EG_Anchor@ (p. 4052)
data Anchor p g = Anchor
    { Anchor p g -> Anchoring
_anchAnchoring  :: Anchoring
    , Anchor p g -> DrawingObject p g
_anchObject     :: DrawingObject p g
    , Anchor p g -> ClientData
_anchClientData :: ClientData
    } deriving (Anchor p g -> Anchor p g -> Bool
(Anchor p g -> Anchor p g -> Bool)
-> (Anchor p g -> Anchor p g -> Bool) -> Eq (Anchor p g)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall p g. (Eq p, Eq g) => Anchor p g -> Anchor p g -> Bool
/= :: Anchor p g -> Anchor p g -> Bool
$c/= :: forall p g. (Eq p, Eq g) => Anchor p g -> Anchor p g -> Bool
== :: Anchor p g -> Anchor p g -> Bool
$c== :: forall p g. (Eq p, Eq g) => Anchor p g -> Anchor p g -> Bool
Eq, Int -> Anchor p g -> ShowS
[Anchor p g] -> ShowS
Anchor p g -> FilePath
(Int -> Anchor p g -> ShowS)
-> (Anchor p g -> FilePath)
-> ([Anchor p g] -> ShowS)
-> Show (Anchor p g)
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
forall p g. (Show p, Show g) => Int -> Anchor p g -> ShowS
forall p g. (Show p, Show g) => [Anchor p g] -> ShowS
forall p g. (Show p, Show g) => Anchor p g -> FilePath
showList :: [Anchor p g] -> ShowS
$cshowList :: forall p g. (Show p, Show g) => [Anchor p g] -> ShowS
show :: Anchor p g -> FilePath
$cshow :: forall p g. (Show p, Show g) => Anchor p g -> FilePath
showsPrec :: Int -> Anchor p g -> ShowS
$cshowsPrec :: forall p g. (Show p, Show g) => Int -> Anchor p g -> ShowS
Show, (forall x. Anchor p g -> Rep (Anchor p g) x)
-> (forall x. Rep (Anchor p g) x -> Anchor p g)
-> Generic (Anchor p g)
forall x. Rep (Anchor p g) x -> Anchor p g
forall x. Anchor p g -> Rep (Anchor p g) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall p g x. Rep (Anchor p g) x -> Anchor p g
forall p g x. Anchor p g -> Rep (Anchor p g) x
$cto :: forall p g x. Rep (Anchor p g) x -> Anchor p g
$cfrom :: forall p g x. Anchor p g -> Rep (Anchor p g) x
Generic)
instance (NFData p, NFData g) => NFData (Anchor p g)

data GenericDrawing p g = Drawing
    { GenericDrawing p g -> [Anchor p g]
_xdrAnchors :: [Anchor p g]
    } deriving (GenericDrawing p g -> GenericDrawing p g -> Bool
(GenericDrawing p g -> GenericDrawing p g -> Bool)
-> (GenericDrawing p g -> GenericDrawing p g -> Bool)
-> Eq (GenericDrawing p g)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall p g.
(Eq p, Eq g) =>
GenericDrawing p g -> GenericDrawing p g -> Bool
/= :: GenericDrawing p g -> GenericDrawing p g -> Bool
$c/= :: forall p g.
(Eq p, Eq g) =>
GenericDrawing p g -> GenericDrawing p g -> Bool
== :: GenericDrawing p g -> GenericDrawing p g -> Bool
$c== :: forall p g.
(Eq p, Eq g) =>
GenericDrawing p g -> GenericDrawing p g -> Bool
Eq, Int -> GenericDrawing p g -> ShowS
[GenericDrawing p g] -> ShowS
GenericDrawing p g -> FilePath
(Int -> GenericDrawing p g -> ShowS)
-> (GenericDrawing p g -> FilePath)
-> ([GenericDrawing p g] -> ShowS)
-> Show (GenericDrawing p g)
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
forall p g. (Show p, Show g) => Int -> GenericDrawing p g -> ShowS
forall p g. (Show p, Show g) => [GenericDrawing p g] -> ShowS
forall p g. (Show p, Show g) => GenericDrawing p g -> FilePath
showList :: [GenericDrawing p g] -> ShowS
$cshowList :: forall p g. (Show p, Show g) => [GenericDrawing p g] -> ShowS
show :: GenericDrawing p g -> FilePath
$cshow :: forall p g. (Show p, Show g) => GenericDrawing p g -> FilePath
showsPrec :: Int -> GenericDrawing p g -> ShowS
$cshowsPrec :: forall p g. (Show p, Show g) => Int -> GenericDrawing p g -> ShowS
Show, (forall x. GenericDrawing p g -> Rep (GenericDrawing p g) x)
-> (forall x. Rep (GenericDrawing p g) x -> GenericDrawing p g)
-> Generic (GenericDrawing p g)
forall x. Rep (GenericDrawing p g) x -> GenericDrawing p g
forall x. GenericDrawing p g -> Rep (GenericDrawing p g) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall p g x. Rep (GenericDrawing p g) x -> GenericDrawing p g
forall p g x. GenericDrawing p g -> Rep (GenericDrawing p g) x
$cto :: forall p g x. Rep (GenericDrawing p g) x -> GenericDrawing p g
$cfrom :: forall p g x. GenericDrawing p g -> Rep (GenericDrawing p g) x
Generic)
instance (NFData p, NFData g) => NFData (GenericDrawing p g)

-- See 20.5.2.35 "wsDr (Worksheet Drawing)" (p. 3176)
type Drawing = GenericDrawing FileInfo ChartSpace

type UnresolvedDrawing = GenericDrawing RefId RefId

makeLenses ''Anchor
makeLenses ''DrawingObject
makeLenses ''BlipFillProperties
makeLenses ''GenericDrawing

-- | simple drawing object anchoring using one cell as a top lelft
-- corner and dimensions of that object
simpleAnchorXY :: (Int, Int) -- ^ x+y coordinates of a cell used as
                             -- top left anchoring corner
               -> PositiveSize2D -- ^ size of drawing object to be
                                 -- anchored
               -> DrawingObject p g
               -> Anchor p g
simpleAnchorXY :: (Int, Int) -> PositiveSize2D -> DrawingObject p g -> Anchor p g
simpleAnchorXY (Int
x, Int
y) PositiveSize2D
sz DrawingObject p g
obj =
  Anchor :: forall p g.
Anchoring -> DrawingObject p g -> ClientData -> Anchor p g
Anchor
  { _anchAnchoring :: Anchoring
_anchAnchoring =
      OneCellAnchor :: Marker -> PositiveSize2D -> Anchoring
OneCellAnchor {onecaFrom :: Marker
onecaFrom = (Int, Int) -> (Int, Int) -> Marker
unqMarker (Int
x, Int
0) (Int
y, Int
0), onecaExt :: PositiveSize2D
onecaExt = PositiveSize2D
sz}
  , _anchObject :: DrawingObject p g
_anchObject = DrawingObject p g
obj
  , _anchClientData :: ClientData
_anchClientData = ClientData
forall a. Default a => a
def
  }

{-------------------------------------------------------------------------------
  Default instances
-------------------------------------------------------------------------------}

instance Default ClientData where
    def :: ClientData
def = Bool -> Bool -> ClientData
ClientData Bool
True Bool
True

{-------------------------------------------------------------------------------
  Parsing
-------------------------------------------------------------------------------}

instance FromCursor UnresolvedDrawing where
    fromCursor :: Cursor -> [UnresolvedDrawing]
fromCursor Cursor
cur = [[Anchor RefId RefId] -> UnresolvedDrawing
forall p g. [Anchor p g] -> GenericDrawing p g
Drawing ([Anchor RefId RefId] -> UnresolvedDrawing)
-> [Anchor RefId RefId] -> UnresolvedDrawing
forall a b. (a -> b) -> a -> b
$ Cursor
cur Cursor -> (Cursor -> [Anchor RefId RefId]) -> [Anchor RefId RefId]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Axis
anyElement Axis
-> (Cursor -> [Anchor RefId RefId])
-> Cursor
-> [Anchor RefId RefId]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Anchor RefId RefId]
forall a. FromCursor a => Cursor -> [a]
fromCursor]

instance FromCursor (Anchor RefId RefId) where
    fromCursor :: Cursor -> [Anchor RefId RefId]
fromCursor Cursor
cur = do
        Anchoring
_anchAnchoring  <- Cursor -> [Anchoring]
forall a. FromCursor a => Cursor -> [a]
fromCursor Cursor
cur
        DrawingObject RefId RefId
_anchObject     <- Cursor
cur Cursor
-> (Cursor -> [DrawingObject RefId RefId])
-> [DrawingObject RefId RefId]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Axis
anyElement Axis
-> (Cursor -> [DrawingObject RefId RefId])
-> Cursor
-> [DrawingObject RefId RefId]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [DrawingObject RefId RefId]
forall a. FromCursor a => Cursor -> [a]
fromCursor
        ClientData
_anchClientData <- Cursor
cur Cursor -> (Cursor -> [ClientData]) -> [ClientData]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"clientData") Axis -> (Cursor -> [ClientData]) -> Cursor -> [ClientData]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [ClientData]
forall a. FromCursor a => Cursor -> [a]
fromCursor
        Anchor RefId RefId -> [Anchor RefId RefId]
forall (m :: * -> *) a. Monad m => a -> m a
return Anchor :: forall p g.
Anchoring -> DrawingObject p g -> ClientData -> Anchor p g
Anchor{ClientData
DrawingObject RefId RefId
Anchoring
_anchClientData :: ClientData
_anchObject :: DrawingObject RefId RefId
_anchAnchoring :: Anchoring
_anchClientData :: ClientData
_anchObject :: DrawingObject RefId RefId
_anchAnchoring :: Anchoring
..}

instance FromCursor Anchoring where
    fromCursor :: Cursor -> [Anchoring]
fromCursor = Node -> [Anchoring]
anchoringFromNode (Node -> [Anchoring]) -> (Cursor -> Node) -> Cursor -> [Anchoring]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cursor -> Node
forall node. Cursor node -> node
node

anchoringFromNode :: Node -> [Anchoring]
anchoringFromNode :: Node -> [Anchoring]
anchoringFromNode Node
n | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
xdr Text
"twoCellAnchor" = do
                          EditAs
tcaEditAs <- Name -> EditAs -> Cursor -> [EditAs]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"editAs" EditAs
EditAsTwoCell Cursor
cur
                          Marker
tcaFrom <- Cursor
cur Cursor -> (Cursor -> [Marker]) -> [Marker]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"from") Axis -> (Cursor -> [Marker]) -> Cursor -> [Marker]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Marker]
forall a. FromCursor a => Cursor -> [a]
fromCursor
                          Marker
tcaTo <- Cursor
cur Cursor -> (Cursor -> [Marker]) -> [Marker]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"to") Axis -> (Cursor -> [Marker]) -> Cursor -> [Marker]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Marker]
forall a. FromCursor a => Cursor -> [a]
fromCursor
                          Anchoring -> [Anchoring]
forall (m :: * -> *) a. Monad m => a -> m a
return TwoCellAnchor :: Marker -> Marker -> EditAs -> Anchoring
TwoCellAnchor{EditAs
Marker
tcaTo :: Marker
tcaFrom :: Marker
tcaEditAs :: EditAs
tcaEditAs :: EditAs
tcaTo :: Marker
tcaFrom :: Marker
..}
                    | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
xdr Text
"oneCellAnchor" = do
                          Marker
onecaFrom <- Cursor
cur Cursor -> (Cursor -> [Marker]) -> [Marker]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"from") Axis -> (Cursor -> [Marker]) -> Cursor -> [Marker]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Marker]
forall a. FromCursor a => Cursor -> [a]
fromCursor
                          PositiveSize2D
onecaExt <- Cursor
cur Cursor -> (Cursor -> [PositiveSize2D]) -> [PositiveSize2D]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"ext") Axis -> (Cursor -> [PositiveSize2D]) -> Cursor -> [PositiveSize2D]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [PositiveSize2D]
forall a. FromCursor a => Cursor -> [a]
fromCursor
                          Anchoring -> [Anchoring]
forall (m :: * -> *) a. Monad m => a -> m a
return OneCellAnchor :: Marker -> PositiveSize2D -> Anchoring
OneCellAnchor{PositiveSize2D
Marker
onecaExt :: PositiveSize2D
onecaFrom :: Marker
onecaExt :: PositiveSize2D
onecaFrom :: Marker
..}
                    | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
xdr Text
"absolueAnchor" = do
                          Point2D
absaPos <- Cursor
cur Cursor -> (Cursor -> [Point2D]) -> [Point2D]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"pos") Axis -> (Cursor -> [Point2D]) -> Cursor -> [Point2D]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Point2D]
forall a. FromCursor a => Cursor -> [a]
fromCursor
                          PositiveSize2D
absaExt <- Cursor
cur Cursor -> (Cursor -> [PositiveSize2D]) -> [PositiveSize2D]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"ext") Axis -> (Cursor -> [PositiveSize2D]) -> Cursor -> [PositiveSize2D]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [PositiveSize2D]
forall a. FromCursor a => Cursor -> [a]
fromCursor
                          Anchoring -> [Anchoring]
forall (m :: * -> *) a. Monad m => a -> m a
return AbsoluteAnchor :: Point2D -> PositiveSize2D -> Anchoring
AbsoluteAnchor{PositiveSize2D
Point2D
absaExt :: PositiveSize2D
absaPos :: Point2D
absaExt :: PositiveSize2D
absaPos :: Point2D
..}
                    | Bool
otherwise = FilePath -> [Anchoring]
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"no matching anchoring node"
  where
    cur :: Cursor
cur = Node -> Cursor
fromNode Node
n

instance FromCursor Marker where
    fromCursor :: Cursor -> [Marker]
fromCursor Cursor
cur = do
        Int
_mrkCol <- Cursor
cur Cursor -> (Cursor -> [Int]) -> [Int]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"col") Axis -> (Cursor -> [Int]) -> Cursor -> [Int]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
content (Cursor -> [Text]) -> (Text -> [Int]) -> Cursor -> [Int]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Text -> [Int]
forall (m :: * -> *) a. (MonadFail m, Integral a) => Text -> m a
decimal
        Coordinate
_mrkColOff <- Cursor
cur Cursor -> (Cursor -> [Coordinate]) -> [Coordinate]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"colOff") Axis -> (Cursor -> [Coordinate]) -> Cursor -> [Coordinate]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
content (Cursor -> [Text])
-> (Text -> [Coordinate]) -> Cursor -> [Coordinate]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Text -> [Coordinate]
forall (m :: * -> *). MonadFail m => Text -> m Coordinate
coordinate
        Int
_mrkRow <- Cursor
cur Cursor -> (Cursor -> [Int]) -> [Int]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"row") Axis -> (Cursor -> [Int]) -> Cursor -> [Int]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
content (Cursor -> [Text]) -> (Text -> [Int]) -> Cursor -> [Int]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Text -> [Int]
forall (m :: * -> *) a. (MonadFail m, Integral a) => Text -> m a
decimal
        Coordinate
_mrkRowOff <- Cursor
cur Cursor -> (Cursor -> [Coordinate]) -> [Coordinate]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"rowOff") Axis -> (Cursor -> [Coordinate]) -> Cursor -> [Coordinate]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Cursor -> [Text]
content (Cursor -> [Text])
-> (Text -> [Coordinate]) -> Cursor -> [Coordinate]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Text -> [Coordinate]
forall (m :: * -> *). MonadFail m => Text -> m Coordinate
coordinate
        Marker -> [Marker]
forall (m :: * -> *) a. Monad m => a -> m a
return Marker :: Int -> Coordinate -> Int -> Coordinate -> Marker
Marker{Int
Coordinate
_mrkRowOff :: Coordinate
_mrkRow :: Int
_mrkColOff :: Coordinate
_mrkCol :: Int
_mrkRowOff :: Coordinate
_mrkRow :: Int
_mrkColOff :: Coordinate
_mrkCol :: Int
..}

instance FromCursor (DrawingObject RefId RefId) where
    fromCursor :: Cursor -> [DrawingObject RefId RefId]
fromCursor = Node -> [DrawingObject RefId RefId]
drawingObjectFromNode (Node -> [DrawingObject RefId RefId])
-> (Cursor -> Node) -> Cursor -> [DrawingObject RefId RefId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cursor -> Node
forall node. Cursor node -> node
node

drawingObjectFromNode :: Node -> [DrawingObject RefId RefId]
drawingObjectFromNode :: Node -> [DrawingObject RefId RefId]
drawingObjectFromNode Node
n
  | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
xdr Text
"pic" = do
    Maybe Text
_picMacro <- Name -> Cursor -> [Maybe Text]
forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"macro" Cursor
cur
    Bool
_picPublished <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"fPublished" Bool
False Cursor
cur
    PicNonVisual
_picNonVisual <- Cursor
cur Cursor -> (Cursor -> [PicNonVisual]) -> [PicNonVisual]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdr Text
"nvPicPr") Axis -> (Cursor -> [PicNonVisual]) -> Cursor -> [PicNonVisual]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [PicNonVisual]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    BlipFillProperties RefId
_picBlipFill <- Cursor
cur Cursor
-> (Cursor -> [BlipFillProperties RefId])
-> [BlipFillProperties RefId]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdr Text
"blipFill") Axis
-> (Cursor -> [BlipFillProperties RefId])
-> Cursor
-> [BlipFillProperties RefId]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [BlipFillProperties RefId]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    ShapeProperties
_picShapeProperties <- Cursor
cur Cursor -> (Cursor -> [ShapeProperties]) -> [ShapeProperties]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdr Text
"spPr") Axis
-> (Cursor -> [ShapeProperties]) -> Cursor -> [ShapeProperties]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [ShapeProperties]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    DrawingObject RefId RefId -> [DrawingObject RefId RefId]
forall (m :: * -> *) a. Monad m => a -> m a
return Picture :: forall p g.
Maybe Text
-> Bool
-> PicNonVisual
-> BlipFillProperties p
-> ShapeProperties
-> DrawingObject p g
Picture {Bool
Maybe Text
ShapeProperties
BlipFillProperties RefId
PicNonVisual
_picShapeProperties :: ShapeProperties
_picBlipFill :: BlipFillProperties RefId
_picNonVisual :: PicNonVisual
_picPublished :: Bool
_picMacro :: Maybe Text
_picShapeProperties :: ShapeProperties
_picBlipFill :: BlipFillProperties RefId
_picNonVisual :: PicNonVisual
_picPublished :: Bool
_picMacro :: Maybe Text
..}
  | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
xdr Text
"graphicFrame" = do
    GraphNonVisual
_grNonVisual <-
      Cursor
cur Cursor -> (Cursor -> [GraphNonVisual]) -> [GraphNonVisual]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdr Text
"nvGraphicFramePr") Axis -> (Cursor -> [GraphNonVisual]) -> Cursor -> [GraphNonVisual]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [GraphNonVisual]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    Transform2D
_grTransform <- Cursor
cur Cursor -> (Cursor -> [Transform2D]) -> [Transform2D]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdr Text
"xfrm") Axis -> (Cursor -> [Transform2D]) -> Cursor -> [Transform2D]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [Transform2D]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    RefId
_grChartSpace <-
      Cursor
cur Cursor -> (Cursor -> [RefId]) -> [RefId]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
a_ Text
"graphic") Axis -> (Cursor -> [RefId]) -> Cursor -> [RefId]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/ Name -> Axis
element (Text -> Name
a_ Text
"graphicData") Axis -> (Cursor -> [RefId]) -> Cursor -> [RefId]
forall node a.
Axis node -> (Cursor node -> [a]) -> Cursor node -> [a]
&/
      Name -> Axis
element (Text -> Name
c_ Text
"chart") Axis -> (Cursor -> [RefId]) -> Cursor -> [RefId]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (Text -> RefId) -> [Text] -> [RefId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> RefId
RefId ([Text] -> [RefId]) -> (Cursor -> [Text]) -> Cursor -> [RefId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  Name -> Cursor -> [Text]
attribute (Text -> Name
odr Text
"id")
    DrawingObject RefId RefId -> [DrawingObject RefId RefId]
forall (m :: * -> *) a. Monad m => a -> m a
return Graphic :: forall p g. GraphNonVisual -> g -> Transform2D -> DrawingObject p g
Graphic {RefId
Transform2D
GraphNonVisual
_grChartSpace :: RefId
_grTransform :: Transform2D
_grNonVisual :: GraphNonVisual
_grTransform :: Transform2D
_grChartSpace :: RefId
_grNonVisual :: GraphNonVisual
..}
  | Bool
otherwise = FilePath -> [DrawingObject RefId RefId]
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"no matching drawing object node"
  where
    cur :: Cursor
cur = Node -> Cursor
fromNode Node
n

instance FromCursor PicNonVisual where
    fromCursor :: Cursor -> [PicNonVisual]
fromCursor Cursor
cur = do
        NonVisualDrawingProperties
_pnvDrawingProps <- Cursor
cur Cursor
-> (Cursor -> [NonVisualDrawingProperties])
-> [NonVisualDrawingProperties]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdrText
"cNvPr") Axis
-> (Cursor -> [NonVisualDrawingProperties])
-> Cursor
-> [NonVisualDrawingProperties]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [NonVisualDrawingProperties]
forall a. FromCursor a => Cursor -> [a]
fromCursor
        PicNonVisual -> [PicNonVisual]
forall (m :: * -> *) a. Monad m => a -> m a
return PicNonVisual :: NonVisualDrawingProperties -> PicNonVisual
PicNonVisual{NonVisualDrawingProperties
_pnvDrawingProps :: NonVisualDrawingProperties
_pnvDrawingProps :: NonVisualDrawingProperties
..}

instance FromCursor GraphNonVisual where
  fromCursor :: Cursor -> [GraphNonVisual]
fromCursor Cursor
cur = do
    NonVisualDrawingProperties
_gnvDrawingProps <- Cursor
cur Cursor
-> (Cursor -> [NonVisualDrawingProperties])
-> [NonVisualDrawingProperties]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
xdr Text
"cNvPr") Axis
-> (Cursor -> [NonVisualDrawingProperties])
-> Cursor
-> [NonVisualDrawingProperties]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [NonVisualDrawingProperties]
forall a. FromCursor a => Cursor -> [a]
fromCursor
    GraphNonVisual -> [GraphNonVisual]
forall (m :: * -> *) a. Monad m => a -> m a
return GraphNonVisual :: NonVisualDrawingProperties -> GraphNonVisual
GraphNonVisual {NonVisualDrawingProperties
_gnvDrawingProps :: NonVisualDrawingProperties
_gnvDrawingProps :: NonVisualDrawingProperties
..}

instance FromCursor NonVisualDrawingProperties where
    fromCursor :: Cursor -> [NonVisualDrawingProperties]
fromCursor Cursor
cur = do
        DrawingElementId
_nvdpId <- Name -> Cursor -> [DrawingElementId]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"id" Cursor
cur
        Text
_nvdpName <- Name -> Cursor -> [Text]
forall a. FromAttrVal a => Name -> Cursor -> [a]
fromAttribute Name
"name" Cursor
cur
        Maybe Text
_nvdpDescription <- Name -> Cursor -> [Maybe Text]
forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"descr" Cursor
cur
        Bool
_nvdpHidden <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"hidden" Bool
False Cursor
cur
        Maybe Text
_nvdpTitle <- Name -> Cursor -> [Maybe Text]
forall a. FromAttrVal a => Name -> Cursor -> [Maybe a]
maybeAttribute Name
"title" Cursor
cur
        NonVisualDrawingProperties -> [NonVisualDrawingProperties]
forall (m :: * -> *) a. Monad m => a -> m a
return NonVisualDrawingProperties :: DrawingElementId
-> Text
-> Maybe Text
-> Bool
-> Maybe Text
-> NonVisualDrawingProperties
NonVisualDrawingProperties{Bool
Maybe Text
Text
DrawingElementId
_nvdpTitle :: Maybe Text
_nvdpHidden :: Bool
_nvdpDescription :: Maybe Text
_nvdpName :: Text
_nvdpId :: DrawingElementId
_nvdpTitle :: Maybe Text
_nvdpHidden :: Bool
_nvdpDescription :: Maybe Text
_nvdpName :: Text
_nvdpId :: DrawingElementId
..}

instance FromAttrVal DrawingElementId where
  fromAttrVal :: Reader DrawingElementId
fromAttrVal = ((Int, Text) -> (DrawingElementId, Text))
-> Either FilePath (Int, Text)
-> Either FilePath (DrawingElementId, Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Int -> DrawingElementId)
-> (Int, Text) -> (DrawingElementId, Text)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Int -> DrawingElementId
DrawingElementId) (Either FilePath (Int, Text)
 -> Either FilePath (DrawingElementId, Text))
-> (Text -> Either FilePath (Int, Text)) -> Reader DrawingElementId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either FilePath (Int, Text)
forall a. FromAttrVal a => Reader a
fromAttrVal

instance FromCursor (BlipFillProperties RefId) where
    fromCursor :: Cursor -> [BlipFillProperties RefId]
fromCursor Cursor
cur = do
        let _bfpImageInfo :: Maybe RefId
_bfpImageInfo = [RefId] -> Maybe RefId
forall a. [a] -> Maybe a
listToMaybe ([RefId] -> Maybe RefId) -> [RefId] -> Maybe RefId
forall a b. (a -> b) -> a -> b
$ Cursor
cur Cursor -> (Cursor -> [RefId]) -> [RefId]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Name -> Axis
element (Text -> Name
a_ Text
"blip") Axis -> (Cursor -> [RefId]) -> Cursor -> [RefId]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=>
                            (Text -> RefId) -> [Text] -> [RefId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> RefId
RefId ([Text] -> [RefId]) -> (Cursor -> [Text]) -> Cursor -> [RefId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Cursor -> [Text]
attribute (Text -> Name
odrText
"embed")
            _bfpFillMode :: Maybe FillMode
_bfpFillMode  = [FillMode] -> Maybe FillMode
forall a. [a] -> Maybe a
listToMaybe ([FillMode] -> Maybe FillMode) -> [FillMode] -> Maybe FillMode
forall a b. (a -> b) -> a -> b
$ Cursor
cur Cursor -> (Cursor -> [FillMode]) -> [FillMode]
forall node a. Cursor node -> (Cursor node -> [a]) -> [a]
$/ Axis
anyElement Axis -> (Cursor -> [FillMode]) -> Cursor -> [FillMode]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Cursor -> [FillMode]
forall a. FromCursor a => Cursor -> [a]
fromCursor
        BlipFillProperties RefId -> [BlipFillProperties RefId]
forall (m :: * -> *) a. Monad m => a -> m a
return BlipFillProperties :: forall a. Maybe a -> Maybe FillMode -> BlipFillProperties a
BlipFillProperties{Maybe RefId
Maybe FillMode
_bfpFillMode :: Maybe FillMode
_bfpImageInfo :: Maybe RefId
_bfpFillMode :: Maybe FillMode
_bfpImageInfo :: Maybe RefId
..}

instance FromCursor FillMode where
    fromCursor :: Cursor -> [FillMode]
fromCursor = Node -> [FillMode]
fillModeFromNode (Node -> [FillMode]) -> (Cursor -> Node) -> Cursor -> [FillMode]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cursor -> Node
forall node. Cursor node -> node
node

fillModeFromNode :: Node -> [FillMode]
fillModeFromNode :: Node -> [FillMode]
fillModeFromNode Node
n | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
a_ Text
"stretch" = FillMode -> [FillMode]
forall (m :: * -> *) a. Monad m => a -> m a
return FillMode
FillStretch
                   | Node
n Node -> Name -> Bool
`nodeElNameIs` Text -> Name
a_ Text
"stretch" = FillMode -> [FillMode]
forall (m :: * -> *) a. Monad m => a -> m a
return FillMode
FillTile
                   | Bool
otherwise = FilePath -> [FillMode]
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"no matching fill mode node"

-- see 20.5.3.2 "ST_EditAs (Resizing Behaviors)" (p. 3177)
instance FromAttrVal EditAs where
    fromAttrVal :: Reader EditAs
fromAttrVal Text
"absolute" = EditAs -> Either FilePath (EditAs, Text)
forall a. a -> Either FilePath (a, Text)
readSuccess EditAs
EditAsAbsolute
    fromAttrVal Text
"oneCell"  = EditAs -> Either FilePath (EditAs, Text)
forall a. a -> Either FilePath (a, Text)
readSuccess EditAs
EditAsOneCell
    fromAttrVal Text
"twoCell"  = EditAs -> Either FilePath (EditAs, Text)
forall a. a -> Either FilePath (a, Text)
readSuccess EditAs
EditAsTwoCell
    fromAttrVal Text
t          = Text -> Reader EditAs
forall a. Text -> Text -> Either FilePath (a, Text)
invalidText Text
"EditAs" Text
t

instance FromCursor ClientData where
    fromCursor :: Cursor -> [ClientData]
fromCursor Cursor
cur = do
        Bool
_cldLcksWithSheet   <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"fLocksWithSheet"  Bool
True Cursor
cur
        Bool
_cldPrintsWithSheet <- Name -> Bool -> Cursor -> [Bool]
forall a. FromAttrVal a => Name -> a -> Cursor -> [a]
fromAttributeDef Name
"fPrintsWithSheet" Bool
True Cursor
cur
        ClientData -> [ClientData]
forall (m :: * -> *) a. Monad m => a -> m a
return ClientData :: Bool -> Bool -> ClientData
ClientData{Bool
_cldPrintsWithSheet :: Bool
_cldLcksWithSheet :: Bool
_cldPrintsWithSheet :: Bool
_cldLcksWithSheet :: Bool
..}

{-------------------------------------------------------------------------------
  Rendering
-------------------------------------------------------------------------------}

instance ToDocument UnresolvedDrawing where
    toDocument :: UnresolvedDrawing -> Document
toDocument = Text -> Text -> Element -> Document
documentFromNsElement Text
"Drawing generated by xlsx" Text
xlDrawingNs
                 (Element -> Document)
-> (UnresolvedDrawing -> Element) -> UnresolvedDrawing -> Document
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> UnresolvedDrawing -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"wsDr"

instance ToElement UnresolvedDrawing where
    toElement :: Name -> UnresolvedDrawing -> Element
toElement Name
nm (Drawing [Anchor RefId RefId]
anchors) = Element :: Name -> Map Name Text -> [Node] -> Element
Element
        { elementName :: Name
elementName       = Name
nm
        , elementAttributes :: Map Name Text
elementAttributes = Map Name Text
forall k a. Map k a
M.empty
        , elementNodes :: [Node]
elementNodes      = (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
forall a b. (a -> b) -> a -> b
$
                              (Anchor RefId RefId -> Element)
-> [Anchor RefId RefId] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Anchor RefId RefId -> Element
anchorToElement [Anchor RefId RefId]
anchors
        }

anchorToElement :: Anchor RefId RefId -> Element
anchorToElement :: Anchor RefId RefId -> Element
anchorToElement Anchor{ClientData
DrawingObject RefId RefId
Anchoring
_anchClientData :: ClientData
_anchObject :: DrawingObject RefId RefId
_anchAnchoring :: Anchoring
_anchClientData :: forall p g. Anchor p g -> ClientData
_anchObject :: forall p g. Anchor p g -> DrawingObject p g
_anchAnchoring :: forall p g. Anchor p g -> Anchoring
..} = Element
el
    { elementNodes :: [Node]
elementNodes = Element -> [Node]
elementNodes Element
el [Node] -> [Node] -> [Node]
forall a. [a] -> [a] -> [a]
++
                     (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement [ Element
drawingObjEl, Element
cdEl ] }
  where
    el :: Element
el = Anchoring -> Element
anchoringToElement Anchoring
_anchAnchoring
    drawingObjEl :: Element
drawingObjEl = DrawingObject RefId RefId -> Element
drawingObjToElement DrawingObject RefId RefId
_anchObject
    cdEl :: Element
cdEl = Name -> ClientData -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"clientData" ClientData
_anchClientData

anchoringToElement :: Anchoring -> Element
anchoringToElement :: Anchoring -> Element
anchoringToElement Anchoring
anchoring = Name -> [(Name, Text)] -> [Element] -> Element
elementList Name
nm [(Name, Text)]
attrs [Element]
elements
  where
    (Name
nm, [(Name, Text)]
attrs, [Element]
elements) = case Anchoring
anchoring of
        AbsoluteAnchor{PositiveSize2D
Point2D
absaExt :: PositiveSize2D
absaPos :: Point2D
absaExt :: Anchoring -> PositiveSize2D
absaPos :: Anchoring -> Point2D
..} ->
            (Name
"absoluteAnchor", [],
             [ Name -> Point2D -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"pos" Point2D
absaPos, Name -> PositiveSize2D -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"ext" PositiveSize2D
absaExt ])
        OneCellAnchor{PositiveSize2D
Marker
onecaExt :: PositiveSize2D
onecaFrom :: Marker
onecaExt :: Anchoring -> PositiveSize2D
onecaFrom :: Anchoring -> Marker
..}  ->
            (Name
"oneCellAnchor", [],
             [ Name -> Marker -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"from" Marker
onecaFrom, Name -> PositiveSize2D -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"ext" PositiveSize2D
onecaExt ])
        TwoCellAnchor{EditAs
Marker
tcaEditAs :: EditAs
tcaTo :: Marker
tcaFrom :: Marker
tcaEditAs :: Anchoring -> EditAs
tcaTo :: Anchoring -> Marker
tcaFrom :: Anchoring -> Marker
..}  ->
            (Name
"twoCellAnchor", [ Name
"editAs" Name -> EditAs -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= EditAs
tcaEditAs ],
             [ Name -> Marker -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"from" Marker
tcaFrom, Name -> Marker -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"to" Marker
tcaTo ])

instance ToElement Marker where
    toElement :: Name -> Marker -> Element
toElement Name
nm Marker{Int
Coordinate
_mrkRowOff :: Coordinate
_mrkRow :: Int
_mrkColOff :: Coordinate
_mrkCol :: Int
_mrkRowOff :: Marker -> Coordinate
_mrkRow :: Marker -> Int
_mrkColOff :: Marker -> Coordinate
_mrkCol :: Marker -> Int
..} = Name -> [Element] -> Element
elementListSimple Name
nm [Element]
elements
      where
        elements :: [Element]
elements = [ Name -> Text -> Element
elementContent Name
"col"    (Int -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal Int
_mrkCol)
                   , Name -> Text -> Element
elementContent Name
"colOff" (Coordinate -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal Coordinate
_mrkColOff)
                   , Name -> Text -> Element
elementContent Name
"row"    (Int -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal Int
_mrkRow)
                   , Name -> Text -> Element
elementContent Name
"rowOff" (Coordinate -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal Coordinate
_mrkRowOff)]

drawingObjToElement :: DrawingObject RefId RefId -> Element
drawingObjToElement :: DrawingObject RefId RefId -> Element
drawingObjToElement Picture {Bool
Maybe Text
ShapeProperties
BlipFillProperties RefId
PicNonVisual
_picShapeProperties :: ShapeProperties
_picBlipFill :: BlipFillProperties RefId
_picNonVisual :: PicNonVisual
_picPublished :: Bool
_picMacro :: Maybe Text
_picShapeProperties :: forall p g. DrawingObject p g -> ShapeProperties
_picBlipFill :: forall p g. DrawingObject p g -> BlipFillProperties p
_picNonVisual :: forall p g. DrawingObject p g -> PicNonVisual
_picPublished :: forall p g. DrawingObject p g -> Bool
_picMacro :: forall p g. DrawingObject p g -> Maybe Text
..} = Name -> [(Name, Text)] -> [Element] -> Element
elementList Name
"pic" [(Name, Text)]
attrs [Element]
elements
  where
    attrs :: [(Name, Text)]
attrs =
      [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes [Name
"macro" Name -> Maybe Text -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Text
_picMacro, Name
"fPublished" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justTrue Bool
_picPublished]
    elements :: [Element]
elements =
      [ Name -> PicNonVisual -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"nvPicPr" PicNonVisual
_picNonVisual
      , Name -> BlipFillProperties RefId -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"blipFill" BlipFillProperties RefId
_picBlipFill
      , Name -> ShapeProperties -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"spPr" ShapeProperties
_picShapeProperties
      ]
drawingObjToElement Graphic {RefId
Transform2D
GraphNonVisual
_grTransform :: Transform2D
_grChartSpace :: RefId
_grNonVisual :: GraphNonVisual
_grTransform :: forall p g. DrawingObject p g -> Transform2D
_grChartSpace :: forall p g. DrawingObject p g -> g
_grNonVisual :: forall p g. DrawingObject p g -> GraphNonVisual
..} = Name -> [Element] -> Element
elementListSimple Name
"graphicFrame" [Element]
elements
  where
    elements :: [Element]
elements =
      [ Name -> GraphNonVisual -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"nvGraphicFramePr" GraphNonVisual
_grNonVisual
      , Name -> Transform2D -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"xfrm" Transform2D
_grTransform
      , Element
graphicEl
      ]
    graphicEl :: Element
graphicEl =
      Name -> [Element] -> Element
elementListSimple
        (Text -> Name
a_ Text
"graphic")
        [ Name -> [(Name, Text)] -> [Element] -> Element
elementList
            (Text -> Name
a_ Text
"graphicData")
            [Name
"uri" Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
chartNs]
            [Name -> [(Name, Text)] -> Element
leafElement (Text -> Name
c_ Text
"chart") [Text -> Name
odr Text
"id" Name -> RefId -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= RefId
_grChartSpace]]
        ]

instance ToElement PicNonVisual where
  toElement :: Name -> PicNonVisual -> Element
toElement Name
nm PicNonVisual {NonVisualDrawingProperties
_pnvDrawingProps :: NonVisualDrawingProperties
_pnvDrawingProps :: PicNonVisual -> NonVisualDrawingProperties
..} =
    Name -> [Element] -> Element
elementListSimple
      Name
nm
      [Name -> NonVisualDrawingProperties -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cNvPr" NonVisualDrawingProperties
_pnvDrawingProps, Name -> Element
emptyElement Name
"cNvPicPr"]

instance ToElement GraphNonVisual where
  toElement :: Name -> GraphNonVisual -> Element
toElement Name
nm GraphNonVisual {NonVisualDrawingProperties
_gnvDrawingProps :: NonVisualDrawingProperties
_gnvDrawingProps :: GraphNonVisual -> NonVisualDrawingProperties
..} =
    Name -> [Element] -> Element
elementListSimple
      Name
nm
      [Name -> NonVisualDrawingProperties -> Element
forall a. ToElement a => Name -> a -> Element
toElement Name
"cNvPr" NonVisualDrawingProperties
_gnvDrawingProps, Name -> Element
emptyElement Name
"cNvGraphicFramePr"]

instance ToElement NonVisualDrawingProperties where
    toElement :: Name -> NonVisualDrawingProperties -> Element
toElement Name
nm NonVisualDrawingProperties{Bool
Maybe Text
Text
DrawingElementId
_nvdpTitle :: Maybe Text
_nvdpHidden :: Bool
_nvdpDescription :: Maybe Text
_nvdpName :: Text
_nvdpId :: DrawingElementId
_nvdpTitle :: NonVisualDrawingProperties -> Maybe Text
_nvdpHidden :: NonVisualDrawingProperties -> Bool
_nvdpDescription :: NonVisualDrawingProperties -> Maybe Text
_nvdpName :: NonVisualDrawingProperties -> Text
_nvdpId :: NonVisualDrawingProperties -> DrawingElementId
..} =
        Name -> [(Name, Text)] -> Element
leafElement Name
nm [(Name, Text)]
attrs
      where
        attrs :: [(Name, Text)]
attrs = [ Name
"id"    Name -> DrawingElementId -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= DrawingElementId
_nvdpId
                , Name
"name"  Name -> Text -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= Text
_nvdpName ] [(Name, Text)] -> [(Name, Text)] -> [(Name, Text)]
forall a. [a] -> [a] -> [a]
++
                [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes [ Name
"descr"  Name -> Maybe Text -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Text
_nvdpDescription
                          , Name
"hidden" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justTrue Bool
_nvdpHidden
                          , Name
"title"  Name -> Maybe Text -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Maybe Text
_nvdpTitle ]

instance ToAttrVal DrawingElementId where
  toAttrVal :: DrawingElementId -> Text
toAttrVal = Int -> Text
forall a. ToAttrVal a => a -> Text
toAttrVal (Int -> Text)
-> (DrawingElementId -> Int) -> DrawingElementId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DrawingElementId -> Int
unDrawingElementId

instance ToElement (BlipFillProperties RefId) where
    toElement :: Name -> BlipFillProperties RefId -> Element
toElement Name
nm BlipFillProperties{Maybe RefId
Maybe FillMode
_bfpFillMode :: Maybe FillMode
_bfpImageInfo :: Maybe RefId
_bfpFillMode :: forall a. BlipFillProperties a -> Maybe FillMode
_bfpImageInfo :: forall a. BlipFillProperties a -> Maybe a
..} =
        Name -> [Element] -> Element
elementListSimple Name
nm [Element]
elements
      where
        elements :: [Element]
elements = [Maybe Element] -> [Element]
forall a. [Maybe a] -> [a]
catMaybes [ (\RefId
rId -> Name -> [(Name, Text)] -> Element
leafElement (Text -> Name
a_ Text
"blip") [ Text -> Name
odr Text
"embed" Name -> RefId -> (Name, Text)
forall a. ToAttrVal a => Name -> a -> (Name, Text)
.= RefId
rId ]) (RefId -> Element) -> Maybe RefId -> Maybe Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe RefId
_bfpImageInfo
                             , FillMode -> Element
fillModeToElement (FillMode -> Element) -> Maybe FillMode -> Maybe Element
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe FillMode
_bfpFillMode ]

fillModeToElement :: FillMode -> Element
fillModeToElement :: FillMode -> Element
fillModeToElement FillMode
FillStretch = Name -> Element
emptyElement (Text -> Name
a_ Text
"stretch")
fillModeToElement FillMode
FillTile    = Name -> Element
emptyElement (Text -> Name
a_ Text
"stretch")

instance ToElement ClientData where
    toElement :: Name -> ClientData -> Element
toElement Name
nm ClientData{Bool
_cldPrintsWithSheet :: Bool
_cldLcksWithSheet :: Bool
_cldPrintsWithSheet :: ClientData -> Bool
_cldLcksWithSheet :: ClientData -> Bool
..} = Name -> [(Name, Text)] -> Element
leafElement Name
nm [(Name, Text)]
attrs
      where
        attrs :: [(Name, Text)]
attrs = [Maybe (Name, Text)] -> [(Name, Text)]
forall a. [Maybe a] -> [a]
catMaybes [ Name
"fLocksWithSheet"  Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justFalse Bool
_cldLcksWithSheet
                          , Name
"fPrintsWithSheet" Name -> Maybe Bool -> Maybe (Name, Text)
forall a. ToAttrVal a => Name -> Maybe a -> Maybe (Name, Text)
.=? Bool -> Maybe Bool
justFalse Bool
_cldPrintsWithSheet
                          ]

instance ToAttrVal EditAs where
    toAttrVal :: EditAs -> Text
toAttrVal EditAs
EditAsAbsolute = Text
"absolute"
    toAttrVal EditAs
EditAsOneCell  = Text
"oneCell"
    toAttrVal EditAs
EditAsTwoCell  = Text
"twoCell"

-- | Add Spreadsheet DrawingML namespace to name
xdr :: Text -> Name
xdr :: Text -> Name
xdr Text
x = Name :: Text -> Maybe Text -> Maybe Text -> Name
Name
  { nameLocalName :: Text
nameLocalName = Text
x
  , nameNamespace :: Maybe Text
nameNamespace = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
xlDrawingNs
  , namePrefix :: Maybe Text
namePrefix = Maybe Text
forall a. Maybe a
Nothing
  }

xlDrawingNs :: Text
xlDrawingNs :: Text
xlDrawingNs = Text
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"