Portability | GHC |
---|---|
Stability | highly unstable |
Maintainer | Stephen Tetley <stephen.tetley@gmail.com> |
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.
- data DrawingContext = DrawingContext {
- dc_font_metrics_table :: FontTable
- dc_font_load_log :: FontLoadLog
- dc_fallback_metrics :: FontMetrics
- dc_font_face :: FontFace
- dc_font_size :: !FontSize
- dc_snap_grid_factors :: (Double, Double)
- dc_stroke_props :: StrokeAttr
- dc_stroke_colour :: RGBi
- dc_fill_colour :: RGBi
- dc_text_colour :: RGBi
- dc_line_spacing_factor :: Double
- dc_text_margin :: TextMargin
- type DrawingContextF = DrawingContext -> DrawingContext
- data TextMargin = TextMargin {
- text_margin_x :: !Em
- text_margin_y :: !Em
- standardContext :: FontSize -> DrawingContext
- metricsContext :: FontSize -> FontLoadResult -> DrawingContext
- addFontTables :: FontLoadResult -> DrawingContextF
- reset_drawing_properties :: DrawingContextF
- reset_drawing_metrics :: DrawingContextF
- class (Applicative m, Monad m) => DrawingCtxM m where
- askDC :: m DrawingContext
- asksDC :: (DrawingContext -> a) -> m a
- localize :: (DrawingContext -> DrawingContext) -> m a -> m a
- withFontMetrics :: (FontMetrics -> FontSize -> u) -> DrawingContext -> u
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.
TextMargin | |
|
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)
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.
askDC :: m DrawingContextSource
asksDC :: (DrawingContext -> a) -> m aSource
localize :: (DrawingContext -> DrawingContext) -> m a -> m aSource
DrawingCtxM (Query u) | |
DrawingCtxM (Image u) | |
DrawingCtxM (ConnectorQuery u) | |
DrawingCtxM (ConnectorImage u) | |
DrawingCtxM (LocQuery u) | |
DrawingCtxM (LocImage u) | |
DrawingCtxM (AdvObject u) | |
DrawingCtxM (LocThetaQuery u) | |
DrawingCtxM (LocThetaImage u) | |
DrawingCtxM (GenChain st u) | |
DrawingCtxM (GenLocDrawing st u) | |
DrawingCtxM (GenLocTrace st u) | |
DrawingCtxM (GenTraceDrawing st u) | |
DrawingCtxM (GenPosObject st u) |
Glyph metrics
withFontMetrics :: (FontMetrics -> FontSize -> u) -> DrawingContext -> uSource