    {-# 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
    $c== :: FileInfo -> FileInfo -> Bool
    == :: FileInfo -> FileInfo -> Bool
    $c/= :: FileInfo -> FileInfo -> Bool
    /= :: 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
    $cshowsPrec :: Int -> FileInfo -> ShowS
    showsPrec :: Int -> FileInfo -> ShowS
    $cshow :: FileInfo -> FilePath
    show :: FileInfo -> FilePath
    $cshowList :: [FileInfo] -> ShowS
    showList :: [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
    $cfrom :: forall x. FileInfo -> Rep FileInfo x
    from :: forall x. FileInfo -> Rep FileInfo x
    $cto :: forall x. Rep FileInfo x -> FileInfo
    to :: forall x. Rep FileInfo x -> FileInfo
    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
    $c== :: Marker -> Marker -> Bool
    == :: Marker -> Marker -> Bool
    $c/= :: Marker -> Marker -> Bool
    /= :: 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
    $cshowsPrec :: Int -> Marker -> ShowS
    showsPrec :: Int -> Marker -> ShowS
    $cshow :: Marker -> FilePath
    show :: Marker -> FilePath
    $cshowList :: [Marker] -> ShowS
    showList :: [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
    $cfrom :: forall x. Marker -> Rep Marker x
    from :: forall x. Marker -> Rep Marker x
    $cto :: forall x. Rep Marker x -> Marker
    to :: forall x. Rep Marker x -> Marker
    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
    $c== :: EditAs -> EditAs -> Bool
    == :: EditAs -> EditAs -> Bool
    $c/= :: EditAs -> EditAs -> Bool
    /= :: 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
    $cshowsPrec :: Int -> EditAs -> ShowS
    showsPrec :: Int -> EditAs -> ShowS
    $cshow :: EditAs -> FilePath
    show :: EditAs -> FilePath
    $cshowList :: [EditAs] -> ShowS
    showList :: [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
    $cfrom :: forall x. EditAs -> Rep EditAs x
    from :: forall x. EditAs -> Rep EditAs x
    $cto :: forall x. Rep EditAs x -> EditAs
    to :: forall x. Rep EditAs x -> EditAs
    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
    $c== :: Anchoring -> Anchoring -> Bool
    == :: Anchoring -> Anchoring -> Bool
    $c/= :: Anchoring -> Anchoring -> Bool
    /= :: 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
    $cshowsPrec :: Int -> Anchoring -> ShowS
    showsPrec :: Int -> Anchoring -> ShowS
    $cshow :: Anchoring -> FilePath
    show :: Anchoring -> FilePath
    $cshowList :: [Anchoring] -> ShowS
    showList :: [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
    $cfrom :: forall x. Anchoring -> Rep Anchoring x
    from :: forall x. Anchoring -> Rep Anchoring x
    $cto :: forall x. Rep Anchoring x -> Anchoring
    to :: forall x. Rep Anchoring x -> Anchoring
    Generic)
    instance NFData Anchoring

    data DrawingObject p g
      = Picture { forall p g. DrawingObject p g -> Maybe Text
    _picMacro :: Maybe Text
               ,  forall p g. DrawingObject p g -> Bool
    _picPublished :: Bool
               ,  forall p g. DrawingObject p g -> PicNonVisual
    _picNonVisual :: PicNonVisual
               ,  forall p g. DrawingObject p g -> BlipFillProperties p
    _picBlipFill :: BlipFillProperties p
               ,  forall p g. DrawingObject p g -> ShapeProperties
    _picShapeProperties :: ShapeProperties
                  -- TODO: style
                }
      | Graphic { forall p g. DrawingObject p g -> GraphNonVisual
    _grNonVisual :: GraphNonVisual
               ,  forall p g. DrawingObject p g -> g
    _grChartSpace :: g
               ,  forall p 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
    $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
    /= :: 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
    $cshowsPrec :: forall p g. (Show p, Show g) => Int -> DrawingObject p g -> ShowS
    showsPrec :: Int -> DrawingObject p g -> ShowS
    $cshow :: forall p g. (Show p, Show g) => DrawingObject p g -> FilePath
    show :: DrawingObject p g -> FilePath
    $cshowList :: forall p g. (Show p, Show g) => [DrawingObject p g] -> ShowS
    showList :: [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
    $cfrom :: forall p g x. DrawingObject p g -> Rep (DrawingObject p g) x
    from :: forall x. DrawingObject p g -> Rep (DrawingObject p g) x
    $cto :: forall p g x. Rep (DrawingObject p g) x -> DrawingObject p g
    to :: forall x. Rep (DrawingObject p g) x -> DrawingObject p g
    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 :: forall c. DrawingElementId -> FileInfo -> DrawingObject FileInfo c
    picture DrawingElementId
    dId FileInfo
    fi =
      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
          { _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
          {_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
          { _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 = Just 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 {a} {g}. Anchor a g -> Maybe (Anchoring, a)
    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 a g -> Maybe (Anchoring, a)
    maybePictureInfo Anchor {ClientData
    DrawingObject a g
    Anchoring
    _anchAnchoring :: Anchoring
    _anchObject :: DrawingObject a g
    _anchClientData :: ClientData
    _anchAnchoring :: forall p g. Anchor p g -> Anchoring
    _anchObject :: forall p g. Anchor p g -> DrawingObject p g
    _anchClientData :: forall p g. Anchor p g -> ClientData
    ..} =
          case DrawingObject a g
    _anchObject of
            Picture {Bool
    Maybe Text
    ShapeProperties
    BlipFillProperties a
    PicNonVisual
    _picMacro :: forall p g. DrawingObject p g -> Maybe Text
    _picPublished :: forall p g. DrawingObject p g -> Bool
    _picNonVisual :: forall p g. DrawingObject p g -> PicNonVisual
    _picBlipFill :: forall p g. DrawingObject p g -> BlipFillProperties p
    _picShapeProperties :: forall p g. DrawingObject p g -> ShapeProperties
    _picMacro :: Maybe Text
    _picPublished :: Bool
    _picNonVisual :: PicNonVisual
    _picBlipFill :: BlipFillProperties a
    _picShapeProperties :: ShapeProperties
    ..} -> (Anchoring
    _anchAnchoring,) (a -> (Anchoring, a)) -> Maybe a -> Maybe (Anchoring, a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> BlipFillProperties a -> Maybe a
    forall a. BlipFillProperties a -> Maybe a
    _bfpImageInfo BlipFillProperties a
    _picBlipFill
            DrawingObject a g
    _ -> Maybe (Anchoring, a)
    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
    $c== :: ClientData -> ClientData -> Bool
    == :: ClientData -> ClientData -> Bool
    $c/= :: ClientData -> ClientData -> Bool
    /= :: 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
    $cshowsPrec :: Int -> ClientData -> ShowS
    showsPrec :: Int -> ClientData -> ShowS
    $cshow :: ClientData -> FilePath
    show :: ClientData -> FilePath
    $cshowList :: [ClientData] -> ShowS
    showList :: [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
    $cfrom :: forall x. ClientData -> Rep ClientData x
    from :: forall x. ClientData -> Rep ClientData x
    $cto :: forall x. Rep ClientData x -> ClientData
    to :: forall x. Rep ClientData x -> ClientData
    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
    $c== :: PicNonVisual -> PicNonVisual -> Bool
    == :: PicNonVisual -> PicNonVisual -> Bool
    $c/= :: PicNonVisual -> PicNonVisual -> Bool
    /= :: 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
    $cshowsPrec :: Int -> PicNonVisual -> ShowS
    showsPrec :: Int -> PicNonVisual -> ShowS
    $cshow :: PicNonVisual -> FilePath
    show :: PicNonVisual -> FilePath
    $cshowList :: [PicNonVisual] -> ShowS
    showList :: [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
    $cfrom :: forall x. PicNonVisual -> Rep PicNonVisual x
    from :: forall x. PicNonVisual -> Rep PicNonVisual x
    $cto :: forall x. Rep PicNonVisual x -> PicNonVisual
    to :: forall x. Rep PicNonVisual x -> PicNonVisual
    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
    $c== :: GraphNonVisual -> GraphNonVisual -> Bool
    == :: GraphNonVisual -> GraphNonVisual -> Bool
    $c/= :: GraphNonVisual -> GraphNonVisual -> Bool
    /= :: 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
    $cshowsPrec :: Int -> GraphNonVisual -> ShowS
    showsPrec :: Int -> GraphNonVisual -> ShowS
    $cshow :: GraphNonVisual -> FilePath
    show :: GraphNonVisual -> FilePath
    $cshowList :: [GraphNonVisual] -> ShowS
    showList :: [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
    $cfrom :: forall x. GraphNonVisual -> Rep GraphNonVisual x
    from :: forall x. GraphNonVisual -> Rep GraphNonVisual x
    $cto :: forall x. Rep GraphNonVisual x -> GraphNonVisual
    to :: forall x. Rep GraphNonVisual x -> GraphNonVisual
    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
    $c== :: DrawingElementId -> DrawingElementId -> Bool
    == :: DrawingElementId -> DrawingElementId -> Bool
    $c/= :: DrawingElementId -> DrawingElementId -> Bool
    /= :: 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
    $cshowsPrec :: Int -> DrawingElementId -> ShowS
    showsPrec :: Int -> DrawingElementId -> ShowS
    $cshow :: DrawingElementId -> FilePath
    show :: DrawingElementId -> FilePath
    $cshowList :: [DrawingElementId] -> ShowS
    showList :: [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
    $cfrom :: forall x. DrawingElementId -> Rep DrawingElementId x
    from :: forall x. DrawingElementId -> Rep DrawingElementId x
    $cto :: forall x. Rep DrawingElementId x -> DrawingElementId
    to :: forall x. Rep DrawingElementId x -> DrawingElementId
    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
    $c== :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
    == :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
    $c/= :: NonVisualDrawingProperties -> NonVisualDrawingProperties -> Bool
    /= :: 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
    $cshowsPrec :: Int -> NonVisualDrawingProperties -> ShowS
    showsPrec :: Int -> NonVisualDrawingProperties -> ShowS
    $cshow :: NonVisualDrawingProperties -> FilePath
    show :: NonVisualDrawingProperties -> FilePath
    $cshowList :: [NonVisualDrawingProperties] -> ShowS
    showList :: [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
    $cfrom :: forall x.
    NonVisualDrawingProperties -> Rep NonVisualDrawingProperties x
    from :: forall x.
    NonVisualDrawingProperties -> Rep NonVisualDrawingProperties x
    $cto :: forall x.
    Rep NonVisualDrawingProperties x -> NonVisualDrawingProperties
    to :: forall x.
    Rep NonVisualDrawingProperties x -> NonVisualDrawingProperties
    Generic)
    instance NFData NonVisualDrawingProperties

    data BlipFillProperties a = BlipFillProperties
        { forall a. BlipFillProperties a -> Maybe a
    _bfpImageInfo :: Maybe a
        , forall 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
    $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
    /= :: 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
    $cshowsPrec :: forall a. Show a => Int -> BlipFillProperties a -> ShowS
    showsPrec :: Int -> BlipFillProperties a -> ShowS
    $cshow :: forall a. Show a => BlipFillProperties a -> FilePath
    show :: BlipFillProperties a -> FilePath
    $cshowList :: forall a. Show a => [BlipFillProperties a] -> ShowS
    showList :: [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
    $cfrom :: forall a x. BlipFillProperties a -> Rep (BlipFillProperties a) x
    from :: forall x. BlipFillProperties a -> Rep (BlipFillProperties a) x
    $cto :: forall a x. Rep (BlipFillProperties a) x -> BlipFillProperties a
    to :: forall x. Rep (BlipFillProperties a) x -> BlipFillProperties a
    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
    $c== :: FillMode -> FillMode -> Bool
    == :: FillMode -> FillMode -> Bool
    $c/= :: FillMode -> FillMode -> Bool
    /= :: 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
    $cshowsPrec :: Int -> FillMode -> ShowS
    showsPrec :: Int -> FillMode -> ShowS
    $cshow :: FillMode -> FilePath
    show :: FillMode -> FilePath
    $cshowList :: [FillMode] -> ShowS
    showList :: [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
    $cfrom :: forall x. FillMode -> Rep FillMode x
    from :: forall x. FillMode -> Rep FillMode x
    $cto :: forall x. Rep FillMode x -> FillMode
    to :: forall x. Rep FillMode x -> FillMode
    Generic)
    instance NFData FillMode

    -- See @EG_Anchor@ (p. 4052)
    data Anchor p g = Anchor
        { forall p g. Anchor p g -> Anchoring
    _anchAnchoring  :: Anchoring
        , forall p g. Anchor p g -> DrawingObject p g
    _anchObject     :: DrawingObject p g
        , forall 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
    $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
    /= :: 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
    $cshowsPrec :: forall p g. (Show p, Show g) => Int -> Anchor p g -> ShowS
    showsPrec :: Int -> Anchor p g -> ShowS
    $cshow :: forall p g. (Show p, Show g) => Anchor p g -> FilePath
    show :: Anchor p g -> FilePath
    $cshowList :: forall p g. (Show p, Show g) => [Anchor p g] -> ShowS
    showList :: [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
    $cfrom :: forall p g x. Anchor p g -> Rep (Anchor p g) x
    from :: forall x. Anchor p g -> Rep (Anchor p g) x
    $cto :: forall p g x. Rep (Anchor p g) x -> Anchor p g
    to :: forall x. Rep (Anchor p g) x -> Anchor p g
    Generic)
    instance (NFData p, NFData g) => NFData (Anchor p g)

    data GenericDrawing p g = Drawing
        { forall p g. 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
    $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
    /= :: 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
    $cshowsPrec :: forall p g. (Show p, Show g) => Int -> GenericDrawing p g -> ShowS
    showsPrec :: Int -> GenericDrawing p g -> ShowS
    $cshow :: forall p g. (Show p, Show g) => GenericDrawing p g -> FilePath
    show :: GenericDrawing p g -> FilePath
    $cshowList :: forall p g. (Show p, Show g) => [GenericDrawing p g] -> ShowS
    showList :: [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
    $cfrom :: forall p g x. GenericDrawing p g -> Rep (GenericDrawing p g) x
    from :: forall x. GenericDrawing p g -> Rep (GenericDrawing p g) x
    $cto :: forall p g x. Rep (GenericDrawing p g) x -> GenericDrawing p g
    to :: forall x. Rep (GenericDrawing p g) x -> GenericDrawing p g
    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 :: forall p g.
    (Int, Int) -> PositiveSize2D -> DrawingObject p g -> Anchor p g
    simpleAnchorXY (Int
    x, Int
    y) PositiveSize2D
    sz DrawingObject p g
    obj =
      Anchor
      { _anchAnchoring :: Anchoring
    _anchAnchoring =
          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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return Anchor{ClientData
    DrawingObject RefId RefId
    Anchoring
    _anchAnchoring :: Anchoring
    _anchObject :: DrawingObject RefId RefId
    _anchClientData :: ClientData
    _anchAnchoring :: Anchoring
    _anchObject :: DrawingObject RefId RefId
    _anchClientData :: ClientData
    ..}

    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return TwoCellAnchor{EditAs
    Marker
    tcaFrom :: Marker
    tcaTo :: Marker
    tcaEditAs :: EditAs
    tcaEditAs :: EditAs
    tcaFrom :: Marker
    tcaTo :: 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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return OneCellAnchor{PositiveSize2D
    Marker
    onecaFrom :: Marker
    onecaExt :: PositiveSize2D
    onecaFrom :: Marker
    onecaExt :: PositiveSize2D
    ..}
                        | 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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return AbsoluteAnchor{PositiveSize2D
    Point2D
    absaPos :: Point2D
    absaExt :: PositiveSize2D
    absaPos :: Point2D
    absaExt :: PositiveSize2D
    ..}
                        | Bool
    otherwise = FilePath -> [Anchoring]
    forall a. FilePath -> [a]
    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return Marker{Int
    Coordinate
    _mrkCol :: Int
    _mrkColOff :: Coordinate
    _mrkRow :: Int
    _mrkRowOff :: Coordinate
    _mrkCol :: Int
    _mrkColOff :: Coordinate
    _mrkRow :: Int
    _mrkRowOff :: Coordinate
    ..}

    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return Picture {Bool
    Maybe Text
    ShapeProperties
    BlipFillProperties RefId
    PicNonVisual
    _picMacro :: Maybe Text
    _picPublished :: Bool
    _picNonVisual :: PicNonVisual
    _picBlipFill :: BlipFillProperties RefId
    _picShapeProperties :: ShapeProperties
    _picMacro :: Maybe Text
    _picPublished :: Bool
    _picNonVisual :: PicNonVisual
    _picBlipFill :: BlipFillProperties RefId
    _picShapeProperties :: ShapeProperties
    ..}
      | 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 a b. (a -> b) -> [a] -> [b]
    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return Graphic {RefId
    Transform2D
    GraphNonVisual
    _grNonVisual :: GraphNonVisual
    _grChartSpace :: RefId
    _grTransform :: Transform2D
    _grNonVisual :: GraphNonVisual
    _grTransform :: Transform2D
    _grChartSpace :: RefId
    ..}
      | Bool
    otherwise = FilePath -> [DrawingObject RefId RefId]
    forall a. FilePath -> [a]
    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return 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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return 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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return NonVisualDrawingProperties{Bool
    Maybe Text
    Text
    DrawingElementId
    _nvdpId :: DrawingElementId
    _nvdpName :: Text
    _nvdpDescription :: Maybe Text
    _nvdpHidden :: Bool
    _nvdpTitle :: Maybe Text
    _nvdpId :: DrawingElementId
    _nvdpName :: Text
    _nvdpDescription :: Maybe Text
    _nvdpHidden :: Bool
    _nvdpTitle :: Maybe Text
    ..}

    instance FromAttrVal DrawingElementId where
      fromAttrVal :: Reader DrawingElementId
    fromAttrVal = ((Int, Text) -> (DrawingElementId, Text))
    -> Either FilePath (Int, Text)
    -> Either FilePath (DrawingElementId, Text)
    forall a b. (a -> b) -> Either FilePath a -> Either FilePath b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap ((Int -> DrawingElementId)
    -> (Int, Text) -> (DrawingElementId, Text)
    forall b c d. (b -> c) -> (b, d) -> (c, d)
    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 a b. (a -> b) -> [a] -> [b]
    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return BlipFillProperties{Maybe RefId
    Maybe FillMode
    _bfpImageInfo :: Maybe RefId
    _bfpFillMode :: Maybe FillMode
    _bfpImageInfo :: Maybe RefId
    _bfpFillMode :: Maybe FillMode
    ..}

    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 a. a -> [a]
    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return FillMode
    FillTile
                       | Bool
    otherwise = FilePath -> [FillMode]
    forall a. FilePath -> [a]
    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 a. a -> [a]
    forall (m :: * -> *) a. Monad m => a -> m a
    return ClientData{Bool
    _cldLcksWithSheet :: Bool
    _cldPrintsWithSheet :: Bool
    _cldLcksWithSheet :: Bool
    _cldPrintsWithSheet :: 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
            { 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
    _anchAnchoring :: forall p g. Anchor p g -> Anchoring
    _anchObject :: forall p g. Anchor p g -> DrawingObject p g
    _anchClientData :: forall p g. Anchor p g -> ClientData
    _anchAnchoring :: Anchoring
    _anchObject :: DrawingObject RefId RefId
    _anchClientData :: ClientData
    ..} = Element
    el
        { elementNodes = elementNodes el ++
                         map NodeElement [ drawingObjEl, 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
    absaPos :: Anchoring -> Point2D
    absaExt :: Anchoring -> PositiveSize2D
    absaPos :: Point2D
    absaExt :: PositiveSize2D
    ..} ->
                (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
    onecaFrom :: Anchoring -> Marker
    onecaExt :: Anchoring -> PositiveSize2D
    onecaFrom :: Marker
    onecaExt :: PositiveSize2D
    ..}  ->
                (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
    tcaFrom :: Anchoring -> Marker
    tcaTo :: Anchoring -> Marker
    tcaEditAs :: Anchoring -> EditAs
    tcaFrom :: Marker
    tcaTo :: Marker
    tcaEditAs :: EditAs
    ..}  ->
                (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
    _mrkCol :: Marker -> Int
    _mrkColOff :: Marker -> Coordinate
    _mrkRow :: Marker -> Int
    _mrkRowOff :: Marker -> Coordinate
    _mrkCol :: Int
    _mrkColOff :: Coordinate
    _mrkRow :: Int
    _mrkRowOff :: Coordinate
    ..} = 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
    _picMacro :: forall p g. DrawingObject p g -> Maybe Text
    _picPublished :: forall p g. DrawingObject p g -> Bool
    _picNonVisual :: forall p g. DrawingObject p g -> PicNonVisual
    _picBlipFill :: forall p g. DrawingObject p g -> BlipFillProperties p
    _picShapeProperties :: forall p g. DrawingObject p g -> ShapeProperties
    _picMacro :: Maybe Text
    _picPublished :: Bool
    _picNonVisual :: PicNonVisual
    _picBlipFill :: BlipFillProperties RefId
    _picShapeProperties :: ShapeProperties
    ..} = 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
    _grNonVisual :: forall p g. DrawingObject p g -> GraphNonVisual
    _grChartSpace :: forall p g. DrawingObject p g -> g
    _grTransform :: forall p g. DrawingObject p g -> Transform2D
    _grNonVisual :: GraphNonVisual
    _grChartSpace :: RefId
    _grTransform :: Transform2D
    ..} = 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 :: PicNonVisual -> NonVisualDrawingProperties
    _pnvDrawingProps :: 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 :: GraphNonVisual -> NonVisualDrawingProperties
    _gnvDrawingProps :: 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
    _nvdpId :: NonVisualDrawingProperties -> DrawingElementId
    _nvdpName :: NonVisualDrawingProperties -> Text
    _nvdpDescription :: NonVisualDrawingProperties -> Maybe Text
    _nvdpHidden :: NonVisualDrawingProperties -> Bool
    _nvdpTitle :: NonVisualDrawingProperties -> Maybe Text
    _nvdpId :: DrawingElementId
    _nvdpName :: Text
    _nvdpDescription :: Maybe Text
    _nvdpHidden :: Bool
    _nvdpTitle :: Maybe Text
    ..} =
            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
    _bfpImageInfo :: forall a. BlipFillProperties a -> Maybe a
    _bfpFillMode :: forall a. BlipFillProperties a -> Maybe FillMode
    _bfpImageInfo :: Maybe RefId
    _bfpFillMode :: Maybe FillMode
    ..} =
            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
    _cldLcksWithSheet :: ClientData -> Bool
    _cldPrintsWithSheet :: ClientData -> Bool
    _cldLcksWithSheet :: Bool
    _cldPrintsWithSheet :: 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
      { 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"