Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | Haskell2010 |
Reexports the functionality for reading and writing Ipe files.
Synopsis
- data IpeFile r = IpeFile (Maybe IpePreamble) [IpeStyle] (NonEmpty (IpePage r))
- preamble :: forall r. Lens' (IpeFile r) (Maybe IpePreamble)
- styles :: forall r. Lens' (IpeFile r) [IpeStyle]
- pages :: forall r r. Lens (IpeFile r) (IpeFile r) (NonEmpty (IpePage r)) (NonEmpty (IpePage r))
- ipeFile :: NonEmpty (IpePage r) -> IpeFile r
- singlePageFile :: IpePage r -> IpeFile r
- singlePageFromContent :: [IpeObject r] -> IpeFile r
- readIpeFile :: (Coordinate r, Eq r) => FilePath -> IO (Either ConversionError (IpeFile r))
- readSinglePageFile :: (Coordinate r, Eq r) => FilePath -> IO (Either ConversionError (IpePage r))
- readSinglePageFileThrow :: (Coordinate r, Eq r) => FilePath -> IO (IpePage r)
- readRawIpeFile :: (Coordinate r, Eq r) => FilePath -> IO (Either ConversionError (IpeFile r))
- type ConversionError = Text
- readAll :: forall g r. (HasDefaultFromIpe g, r ~ NumType g) => IpePage r -> [g :+ IpeAttributes (DefaultFromIpe g) r]
- readAllFrom :: forall g r. (HasDefaultFromIpe g, r ~ NumType g, Coordinate r, Eq r) => FilePath -> IO [g :+ IpeAttributes (DefaultFromIpe g) r]
- writeIpeFile :: IpeWriteText r => FilePath -> IpeFile r -> IO ()
- writeIpeFile' :: IpeWrite t => t -> FilePath -> IO ()
- writeIpePage :: IpeWriteText r => FilePath -> IpePage r -> IO ()
- toIpeXML :: IpeWrite t => t -> Maybe ByteString
- printAsIpeSelection :: IpeWrite t => t -> IO ()
- toIpeSelectionXML :: IpeWrite t => t -> Maybe ByteString
- data IpePage r = IpePage [LayerName] [View] [IpeObject r]
- layers :: forall r. Lens' (IpePage r) [LayerName]
- views :: forall r. Lens' (IpePage r) [View]
- content :: forall r r. Lens (IpePage r) (IpePage r) [IpeObject r] [IpeObject r]
- emptyPage :: IpePage r
- fromContent :: [IpeObject r] -> IpePage r
- onLayer :: LayerName -> Getting (Endo [IpeObject r]) [IpeObject r] (IpeObject r)
- contentInView :: Word -> Getter (IpePage r) [IpeObject r]
- withDefaults :: IpePage r -> IpePage r
- data IpeObject r
- = IpeGroup (IpeObject' Group r)
- | IpeImage (IpeObject' Image r)
- | IpeTextLabel (IpeObject' TextLabel r)
- | IpeMiniPage (IpeObject' MiniPage r)
- | IpeUse (IpeObject' IpeSymbol r)
- | IpePath (IpeObject' Path r)
- _IpePath :: forall r. Prism' (IpeObject r) (IpeObject' Path r)
- _IpeUse :: forall r. Prism' (IpeObject r) (IpeObject' IpeSymbol r)
- _IpeGroup :: forall r. Prism' (IpeObject r) (IpeObject' Group r)
- _IpeTextLabel :: forall r. Prism' (IpeObject r) (IpeObject' TextLabel r)
- _IpeMiniPage :: forall r. Prism' (IpeObject r) (IpeObject' MiniPage r)
- _IpeImage :: forall r. Prism' (IpeObject r) (IpeObject' Image r)
- type IpeObject' g r = g r :+ IpeAttributes g r
- ipeObject' :: ToObject i => i r -> IpeAttributes i r -> IpeObject r
- class ToObject i where
- mkIpeObject :: IpeObject' i r -> IpeObject r
- newtype Path r = Path (LSeq 1 (PathSegment r))
- pathSegments :: forall r r. Iso (Path r) (Path r) (LSeq 1 (PathSegment r)) (LSeq 1 (PathSegment r))
- data PathSegment r
- = PolyLineSegment (PolyLine 2 () r)
- | PolygonPath (SimplePolygon () r)
- | CubicBezierSegment (BezierSpline 3 2 r)
- | QuadraticBezierSegment (BezierSpline 2 2 r)
- | EllipseSegment (Ellipse r)
- | ArcSegment
- | SplineSegment
- | ClosedSplineSegment
- data IpeSymbol r = Symbol (Point 2 r) Text
- symbolPoint :: forall r r. Lens (IpeSymbol r) (IpeSymbol r) (Point 2 r) (Point 2 r)
- symbolName :: forall r. Lens' (IpeSymbol r) Text
- newtype Group r = Group [IpeObject r]
- groupItems :: Lens (Group r) (Group s) [IpeObject r] [IpeObject s]
- data TextLabel r = Label Text (Point 2 r)
- data MiniPage r = MiniPage Text (Point 2 r) r
- width :: MiniPage t -> t
- data Image r = Image () (Rectangle () r)
- imageData :: forall r. Lens' (Image r) ()
- rect :: forall r r. Lens (Image r) (Image r) (Rectangle () r) (Rectangle () r)
- type IpeBitmap = Text
- type IpeAttributes g r = Attributes' r (AttributesOf g)
- type Attributes' r = Attributes (AttrMapSym1 r)
- type family AttributesOf (t :: * -> *) :: [AttributeUniverse] where ...
- type family AttrMap (r :: *) (l :: AttributeUniverse) :: * where ...
- data AttrMapSym1 a6989586621679197913 a6989586621679197914
- attributes :: Lens' (IpeObject' g r) (IpeAttributes g r)
- traverseIpeAttrs :: (Applicative f, AllConstrained TraverseIpeAttr (AttributesOf g)) => proxy g -> (r -> f s) -> IpeAttributes g r -> f (IpeAttributes g s)
- commonAttributes :: Lens' (IpeObject r) (Attributes (AttrMapSym1 r) CommonAttributes)
- newtype LayerName = LayerName Text
- layerName :: Iso' LayerName Text
- data View = View [LayerName] LayerName
- layerNames :: Lens' View [LayerName]
- activeLayer :: Lens' View LayerName
- data IpeStyle = IpeStyle (Maybe Text) (Node Text Text)
- styleName :: Lens' IpeStyle (Maybe Text)
- styleData :: Lens' IpeStyle (Node Text Text)
- basicIpeStyle :: IpeStyle
- readIpeStylesheet :: FilePath -> IO (Either ConversionError IpeStyle)
- addStyleSheetFrom :: FilePath -> IpeFile r -> IO (IpeFile r)
- data IpePreamble = IpePreamble (Maybe Text) Text
- encoding :: Lens' IpePreamble (Maybe Text)
- preambleData :: Lens' IpePreamble Text
- class IpeRead t where
- _asPoint :: Prism' (IpeSymbol r) (Point 2 r)
- _asLineSegment :: Prism' (Path r) (LineSegment 2 () r)
- _asRectangle :: forall r. (Num r, Ord r) => Prism' (Path r) (Rectangle () r)
- _asTriangle :: Prism' (Path r) (Triangle 2 () r)
- _asPolyLine :: Prism' (Path r) (PolyLine 2 () r)
- _asSomePolygon :: Prism' (Path r) (SomePolygon () r)
- _asSimplePolygon :: Prism' (Path r) (Polygon Simple () r)
- _asMultiPolygon :: Prism' (Path r) (MultiPolygon () r)
- _withAttrs :: Prism' (IpeObject r) (i r :+ IpeAttributes i r) -> Prism' (i r) g -> Prism' (IpeObject r) (g :+ IpeAttributes i r)
- class HasDefaultFromIpe g where
- type DefaultFromIpe g :: * -> *
- defaultFromIpe :: r ~ NumType g => Prism' (IpeObject r) (g :+ IpeAttributes (DefaultFromIpe g) r)
- class IpeWrite t where
- class IpeWriteText t where
- ipeWriteText :: t -> Maybe Text
- module Ipe.IpeOut
- module Ipe.Types
- module Ipe.FromIpe
- module Ipe.Attributes
- module Ipe.Value
- newtype IpeColor r = IpeColor (IpeValue (RGB r))
- named :: Text -> IpeColor r
Ipe Files
A complete ipe file
pages :: forall r r. Lens (IpeFile r) (IpeFile r) (NonEmpty (IpePage r)) (NonEmpty (IpePage r)) Source #
ipeFile :: NonEmpty (IpePage r) -> IpeFile r Source #
Convenience constructor for creating an ipe file without preamble and with the default stylesheet.
singlePageFile :: IpePage r -> IpeFile r Source #
Convenience function to construct an ipe file consisting of a single page.
singlePageFromContent :: [IpeObject r] -> IpeFile r Source #
Create a single page ipe file from a list of IpeObjects
Reading Ipe files
readIpeFile :: (Coordinate r, Eq r) => FilePath -> IO (Either ConversionError (IpeFile r)) Source #
Given a file path, tries to read an ipe file.
This function applies all matrices to objects.
readSinglePageFile :: (Coordinate r, Eq r) => FilePath -> IO (Either ConversionError (IpePage r)) Source #
Since most Ipe file contain only one page, we provide a shortcut for that as well.
This function applies all matrices, and it makes sure there is at least one layer and view in the page.
readSinglePageFileThrow :: (Coordinate r, Eq r) => FilePath -> IO (IpePage r) Source #
Tries to read a single page file, throws an error when this
fails. See readSinglePageFile
for further details.
readRawIpeFile :: (Coordinate r, Eq r) => FilePath -> IO (Either ConversionError (IpeFile r)) Source #
Given a file path, tries to read an ipe file
type ConversionError = Text Source #
Reading all Geometries from a single page ipe file
readAll :: forall g r. (HasDefaultFromIpe g, r ~ NumType g) => IpePage r -> [g :+ IpeAttributes (DefaultFromIpe g) r] Source #
Read all g's from some ipe page(s).
readAllFrom :: forall g r. (HasDefaultFromIpe g, r ~ NumType g, Coordinate r, Eq r) => FilePath -> IO [g :+ IpeAttributes (DefaultFromIpe g) r] Source #
Convenience function from reading all g's from an ipe file. If there is an error reading or parsing the file the error is "thrown away".
Writing ipe files
writeIpeFile :: IpeWriteText r => FilePath -> IpeFile r -> IO () Source #
Given a prism to convert something of type g into an ipe file, a file path, and a g. Convert the geometry and write it to file.
Write an IpeFiele to file.
writeIpeFile' :: IpeWrite t => t -> FilePath -> IO () Source #
Convert to ipe XML and write the output to a file.
writeIpePage :: IpeWriteText r => FilePath -> IpePage r -> IO () Source #
Creates a single page ipe file with the given page
printAsIpeSelection :: IpeWrite t => t -> IO () Source #
Convert the input to ipeXml, and prints it to standard out in such a way that the copied text can be pasted into ipe as a geometry object.
toIpeSelectionXML :: IpeWrite t => t -> Maybe ByteString Source #
Convert input into an ipe selection.
Ipe Pages
An IpePage is essentially a Group, together with a list of layers and a list of views.
fromContent :: [IpeObject r] -> IpePage r Source #
Creates a simple page with a single view.
onLayer :: LayerName -> Getting (Endo [IpeObject r]) [IpeObject r] (IpeObject r) Source #
This allows you to filter the objects on some layer.
>>>
let page = IpePage [] [] []
>>>
page^..content.onLayer "myLayer"
[]
contentInView :: Word -> Getter (IpePage r) [IpeObject r] Source #
Gets all objects that are visible in the given view.
Note that views are indexed starting from 0. If the page does not have any explicit view definitions, this function returns an empty list.
>>>
let page = IpePage [] [] []
>>>
page^.contentInView 0
[]
withDefaults :: IpePage r -> IpePage r Source #
Makes sure that the page has at least one layer and at least one view, essentially matching the behaviour of ipe. In particular,
- if the page does not have any layers, it creates a layer named "alpha", and
- if the page does not have any views, it creates a view in which all layers are visible.
Content: Ipe Objects
IpeGroup (IpeObject' Group r) | |
IpeImage (IpeObject' Image r) | |
IpeTextLabel (IpeObject' TextLabel r) | |
IpeMiniPage (IpeObject' MiniPage r) | |
IpeUse (IpeObject' IpeSymbol r) | |
IpePath (IpeObject' Path r) |
Instances
_IpeTextLabel :: forall r. Prism' (IpeObject r) (IpeObject' TextLabel r) Source #
_IpeMiniPage :: forall r. Prism' (IpeObject r) (IpeObject' MiniPage r) Source #
type IpeObject' g r = g r :+ IpeAttributes g r Source #
An IpeObject' is essentially the oject ogether with its attributes
ipeObject' :: ToObject i => i r -> IpeAttributes i r -> IpeObject r Source #
Shorthand for constructing ipeObjects
class ToObject i where Source #
mkIpeObject :: IpeObject' i r -> IpeObject r Source #
Instances
ToObject Path Source # | |
Defined in Ipe.Content mkIpeObject :: IpeObject' Path r -> IpeObject r Source # | |
ToObject Image Source # | |
Defined in Ipe.Content mkIpeObject :: IpeObject' Image r -> IpeObject r Source # | |
ToObject IpeSymbol Source # | |
Defined in Ipe.Content mkIpeObject :: IpeObject' IpeSymbol r -> IpeObject r Source # | |
ToObject MiniPage Source # | |
Defined in Ipe.Content mkIpeObject :: IpeObject' MiniPage r -> IpeObject r Source # | |
ToObject TextLabel Source # | |
Defined in Ipe.Content mkIpeObject :: IpeObject' TextLabel r -> IpeObject r Source # | |
ToObject Group Source # | |
Defined in Ipe.Content mkIpeObject :: IpeObject' Group r -> IpeObject r Source # |
Specific Ipe-Objects
A path is a non-empty sequence of PathSegments.
Path (LSeq 1 (PathSegment r)) |
Instances
pathSegments :: forall r r. Iso (Path r) (Path r) (LSeq 1 (PathSegment r)) (LSeq 1 (PathSegment r)) Source #
data PathSegment r Source #
Paths
Paths consist of Path Segments. PathSegments come in the following forms:
PolyLineSegment (PolyLine 2 () r) | |
PolygonPath (SimplePolygon () r) | |
CubicBezierSegment (BezierSpline 3 2 r) | |
QuadraticBezierSegment (BezierSpline 2 2 r) | |
EllipseSegment (Ellipse r) | |
ArcSegment | |
SplineSegment | |
ClosedSplineSegment |
Instances
Ipe Symbols, i.e. Points
A symbol (point) in ipe
Instances
Groups and Objects
Group Attributes
A group is essentially a list of IpeObjects.
Instances
Text Objects
Instances
Instances
Image Objects
Instances
Attributes
type IpeAttributes g r = Attributes' r (AttributesOf g) Source #
type Attributes' r = Attributes (AttrMapSym1 r) Source #
Attributes' :: * -> [AttributeUniverse] -> *
type family AttributesOf (t :: * -> *) :: [AttributeUniverse] where ... Source #
type family AttrMap (r :: *) (l :: AttributeUniverse) :: * where ... Source #
The mapping between the labels of the the attributes and the types of the
attributes with these labels. For example, the Matrix
label/attribute should
have a value of type 'Matrix 3 3 r'.
AttrMap r 'Layer = LayerName | |
AttrMap r Matrix = Matrix 3 3 r | |
AttrMap r Pin = PinType | |
AttrMap r Transformations = TransformationTypes | |
AttrMap r Stroke = IpeColor r | |
AttrMap r Pen = IpePen r | |
AttrMap r Fill = IpeColor r | |
AttrMap r Size = IpeSize r | |
AttrMap r Dash = IpeDash r | |
AttrMap r LineCap = Int | |
AttrMap r LineJoin = Int | |
AttrMap r FillRule = FillType | |
AttrMap r Arrow = IpeArrow r | |
AttrMap r RArrow = IpeArrow r | |
AttrMap r StrokeOpacity = IpeOpacity | |
AttrMap r Opacity = IpeOpacity | |
AttrMap r Tiling = IpeTiling | |
AttrMap r Gradient = IpeGradient | |
AttrMap r Clip = Path r |
data AttrMapSym1 a6989586621679197913 a6989586621679197914 Source #
Instances
SuppressUnusedWarnings (AttrMapSym1 a6989586621679197913 :: TyFun AttributeUniverse Type -> Type) Source # | |
Defined in Ipe.Content suppressUnusedWarnings :: () # | |
type Apply (AttrMapSym1 a6989586621679197913 :: TyFun AttributeUniverse Type -> Type) (a6989586621679197914 :: AttributeUniverse) Source # | |
Defined in Ipe.Content type Apply (AttrMapSym1 a6989586621679197913 :: TyFun AttributeUniverse Type -> Type) (a6989586621679197914 :: AttributeUniverse) |
attributes :: Lens' (IpeObject' g r) (IpeAttributes g r) Source #
traverseIpeAttrs :: (Applicative f, AllConstrained TraverseIpeAttr (AttributesOf g)) => proxy g -> (r -> f s) -> IpeAttributes g r -> f (IpeAttributes g s) Source #
traverse for ipe attributes
commonAttributes :: Lens' (IpeObject r) (Attributes (AttrMapSym1 r) CommonAttributes) Source #
Layers and Views
Defines an Layer in Ipe.
Instances
Eq LayerName Source # | |
Ord LayerName Source # | |
Defined in Ipe.Layer | |
Read LayerName Source # | |
Show LayerName Source # | |
IsString LayerName Source # | |
Defined in Ipe.Layer fromString :: String -> LayerName # | |
IpeRead LayerName Source # | |
Defined in Ipe.Reader | |
IpeReadText LayerName Source # | |
Defined in Ipe.Reader | |
IpeWrite LayerName Source # | |
IpeWriteText LayerName Source # | |
Defined in Ipe.Writer |
The definition of a view make active layer into an index ?
Ipe Syles and Preamble
for now we pretty much ignore these
readIpeStylesheet :: FilePath -> IO (Either ConversionError IpeStyle) Source #
Reads an Ipe stylesheet from Disk.
addStyleSheetFrom :: FilePath -> IpeFile r -> IO (IpeFile r) Source #
Given a path to a stylesheet, add it to the ipe file with the highest priority. Throws an error when this fails.
data IpePreamble Source #
The maybe string is the encoding
Instances
Eq IpePreamble Source # | |
Defined in Ipe.Types (==) :: IpePreamble -> IpePreamble -> Bool # (/=) :: IpePreamble -> IpePreamble -> Bool # | |
Ord IpePreamble Source # | |
Defined in Ipe.Types compare :: IpePreamble -> IpePreamble -> Ordering # (<) :: IpePreamble -> IpePreamble -> Bool # (<=) :: IpePreamble -> IpePreamble -> Bool # (>) :: IpePreamble -> IpePreamble -> Bool # (>=) :: IpePreamble -> IpePreamble -> Bool # max :: IpePreamble -> IpePreamble -> IpePreamble # min :: IpePreamble -> IpePreamble -> IpePreamble # | |
Read IpePreamble Source # | |
Defined in Ipe.Types readsPrec :: Int -> ReadS IpePreamble # readList :: ReadS [IpePreamble] # readPrec :: ReadPrec IpePreamble # readListPrec :: ReadPrec [IpePreamble] # | |
Show IpePreamble Source # | |
Defined in Ipe.Types showsPrec :: Int -> IpePreamble -> ShowS # show :: IpePreamble -> String # showList :: [IpePreamble] -> ShowS # | |
IpeWrite IpePreamble Source # | |
Defined in Ipe.Writer |
Reading Geometries *From* Ipe
class IpeRead t where Source #
Reading an ipe lement from Xml
Instances
IpeRead LayerName Source # | |
Defined in Ipe.Reader | |
IpeRead View Source # | |
Defined in Ipe.Reader | |
IpeRead IpeStyle Source # | |
Defined in Ipe.Reader | |
(Coordinate r, Fractional r, Eq r) => IpeRead (Path r) Source # | |
Defined in Ipe.Reader | |
Coordinate r => IpeRead (Image r) Source # | |
Defined in Ipe.Reader | |
Coordinate r => IpeRead (IpeSymbol r) Source # | Ipe read instances |
Defined in Ipe.Reader | |
Coordinate r => IpeRead (MiniPage r) Source # | |
Defined in Ipe.Reader | |
Coordinate r => IpeRead (TextLabel r) Source # | |
Defined in Ipe.Reader | |
(Coordinate r, Fractional r, Eq r) => IpeRead (IpeObject r) Source # | |
Defined in Ipe.Reader | |
(Coordinate r, Eq r) => IpeRead (Group r) Source # | |
Defined in Ipe.Reader | |
(Coordinate r, Eq r) => IpeRead (IpePage r) Source # | |
Defined in Ipe.Reader | |
(Coordinate r, Eq r) => IpeRead (IpeFile r) Source # | |
Defined in Ipe.Reader |
Converting *from* IpeObjects
_asPoint :: Prism' (IpeSymbol r) (Point 2 r) Source #
Extracts the point from a Symbol. When creating a symbol this creates a disk that supports a stroke color.
_asLineSegment :: Prism' (Path r) (LineSegment 2 () r) Source #
Try to convert a path into a line segment, fails if the path is not a line segment or a polyline with more than two points.
_asRectangle :: forall r. (Num r, Ord r) => Prism' (Path r) (Rectangle () r) Source #
Tries to convert a path into a rectangle.
_asPolyLine :: Prism' (Path r) (PolyLine 2 () r) Source #
Convert to a polyline. Ignores all non-polyline parts
>>>
testPath ^? _asPolyLine
Just (PolyLine {_points = LSeq (fromList [Point2 [0,0] :+ (),Point2 [10,10] :+ (),Point2 [200,100] :+ ()])})
_asSomePolygon :: Prism' (Path r) (SomePolygon () r) Source #
_asMultiPolygon :: Prism' (Path r) (MultiPolygon () r) Source #
Convert to a multipolygon
Dealing with Attributes
_withAttrs :: Prism' (IpeObject r) (i r :+ IpeAttributes i r) -> Prism' (i r) g -> Prism' (IpeObject r) (g :+ IpeAttributes i r) Source #
Use the first prism to select the ipe object to depicle with, and the second how to select the geometry object from there on. Then we can select the geometry object, directly with its attributes here.
>>>
testObject ^? _withAttrs _IpePath _asPolyLine
Just (PolyLine {_points = LSeq (fromList [Point2 [0,0] :+ (),Point2 [10,10] :+ (),Point2 [200,100] :+ ()])} :+ Attrs {NoAttr, NoAttr, NoAttr, NoAttr, Attr IpeColor (Named "red"), NoAttr, NoAttr, NoAttr, NoAttr, NoAttr, NoAttr, NoAttr, NoAttr, NoAttr, NoAttr, NoAttr})
Default readers
class HasDefaultFromIpe g where Source #
type DefaultFromIpe g :: * -> * Source #
defaultFromIpe :: r ~ NumType g => Prism' (IpeObject r) (g :+ IpeAttributes (DefaultFromIpe g) r) Source #
Instances
Converting *to* IpeObjects
IpeWrite
class IpeWrite t where Source #
Types that correspond to an XML Element. All instances should produce an
Element. If the type should produce a Node with the Text constructor, use
the IpeWriteText
typeclass instead.
Instances
class IpeWriteText t where Source #
For types that can produce a text value
ipeWriteText :: t -> Maybe Text Source #
Instances
IpeOut
module Ipe.IpeOut
Batch reexports
module Ipe.Types
module Ipe.FromIpe
module Ipe.Attributes
module Ipe.Value
Defines a color in Ipe. Colors are either RGB Values or Named values.