wumpus-basic-0.18.0: Basic objects and system code built on Wumpus-Core.

PortabilityGHC
Stabilityhighly unstable
MaintainerStephen Tetley <stephen.tetley@gmail.com>

Wumpus.Basic.Kernel.Base.DrawingContext

Contents

Description

Drawing attributes

** WARNING ** - The drawing context modules need systematic naming schemes both for update functions (primaryColour, ...) and for synthesized selectors (e.g. lowerxHeight). The current names in QueryDC and UpdateDC are expected to change.

Synopsis

Drawing context types

data DrawingContext Source

DrawingContext - the "graphics state" of Wumpus-Basic. DrawingContext is operated on within a Reader monad rather than a State monad so "updates" are delineated within a local operation (called localize in Wumpus), rather than permanent until overridden as per set of a State monad.

Note - in contrast to most other drawing objects in Wumpus, none of the types of measurement values are parameteric (usually notated with the type variable u in Wumpus). Types are either Double representing PostScript points or Em - a contextual size that is interpreted according to the current font size.

It is easier to specialize all the measurement types and within the DrawingContext and add parametricity to the getters and setters instead.

type DrawingContextF = DrawingContext -> DrawingContextSource

Type synonym for DrawingContext update functions.

data TextMargin Source

The text margin is measured in Em so it is relative to the current font size.

The default value is 0.5.

Constructors

TextMargin 

Fields

text_margin_x :: !Em
 
text_margin_y :: !Em
 

data ConnectorProps Source

ConnectorProps control the drawing of connectors in Wumpus-Drawing.

 conn_src_space     :: Em
 conn_dst_space     :: Em

Source and destination spacers - these add spacing between the respective connector points and the tips of the drawn connector.

 conn_src_offset    :: Em
 conn_dst_offset    :: Em

Source and destination offsets - these offset the drawing of the connector perpendicular to the direction of line formed between the connector points (a positive offset is drawn above, a negative offset below). The main use of offsets is to draw parallel line connectors.

 conn_arc_ang       :: Radian 

Control the bend of an arc connector.

 conn_src_arm       :: Em
 conn_dst_arm       :: Em 

Control the arm length of a jointed connector - arms are the initial segments of the connector.

 conn_loop_size     :: Em

Control the height of a loop connector.

 conn_box_halfsize  :: Em

Control the size of a connector box. Connector boxes are drawn with the exterior lines projected out from the connector points a halfsize above and below.

Construction

standardContext :: FontSize -> DrawingContextSource

standardContext : font_size -> DrawingContext

Create a DrawingContext.

Note - font_size is used for sizing more than just text labels. Arrowheads, plot marks and other elements have their metrics derived from the font size.

No real font metrics are present in the DrawingContext created by standardContext. Static, hard-coded fallback metrics derived from the Courier font are available but these metrics might not accurately correspond to the Courier available to the the final renderer (GhostScript, an SVG viewer, etc.).

Use this constructor for drawings that make primitive use of text.

 font_metrics_table:  empty
 font_load_log:       empty
 fallback_metrics:    monospace_metrics
 font_face:           Courier
 font_size:           @supplied_font_size@
 stroke_props:        line_width 1, no dash_pattern, cap-butt, join-miter. 
 stroke_colour:       black
 fill_colour:         light_gray
 text_colour:         black
 line_spacing_factor: 0.2
 round_corner_factor: 0
 text_margin:         (0.5 em, 0.5 em) 
 conn_src_sep:        0
 conn_dst_sep:        0
 conn_src_offset:     0
 conn_dst_offset:     0
 conn_arc_ang:        pi / 12
 conn_src_arm:        1
 conn_dst_arm:        1
 conn_loop_size:      2 

metricsContext :: FontSize -> FontLoadResult -> DrawingContextSource

metricsContext : font_size * font_metrics -> DrawingContext

Create a DrawingContext with font metrics loaded from the file system.

Note - font_size is used for sizing more than just text labels. Arrowheads, plot marks and other elements have their metrics derived from the font size.

Use this constructor for drawings that make use of the text objects provided by Wumpus-Drawing (DocText and RotText).

addFontTables :: FontLoadResult -> DrawingContextFSource

addFontTables : font_load_result -> DrawinContextUpdate

Add the font metrics from the FontLoadResult, if a font with the same name alreay exists in the DrawingContext it will be replaced. Error and warning messages in the font_load_result will be appended to the font_load_log.

reset_drawing_properties :: DrawingContextFSource

reset_drawing_properties : DrawingContextF

Reset the drawing properties in the DrawingContext to their default values. This changes the following fields:

 stroke_props:        line_width 1, no dash_pattern, cap-butt, join-miter. 
 stroke_colour:       black
 fill_colour:         light_gray
 text_colour:         black
 line_spacing_factor: 0.2
 round_corner_factor: 0
 text_margin:         (0.5 em, 0.5 em) 

reset_drawing_metrics :: DrawingContextFSource

reset_drawing_metrics : DrawingContextF

Reset the drawing metrics in the DrawingContext to their default values. This is a more limited version of reset_drawing_properties and changes the following fields:

 stroke_props:        line_width 1, no dash_pattern, cap-butt, join-miter. 
 line_spacing_factor: 0.2
 round_corner_factor: 0
 text_margin:         (0.5 em, 0.5 em) 

DrawingCtxM (reader) monad

class (Applicative m, Monad m) => DrawingCtxM m whereSource

DrawingCtxM is equivalent to the to the MonadReader class, but the environment type is fixed to DrawingContext.

To avoid name clashes with mtl this scheme is used:

 askDC    = ask
 asksDC   = asks
 localize = local

Note, because the derived operation query (aka asks) is expected to be used more often than queryCtx (aka ask) it gets the more convenient name.

Glyph metrics