-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
88 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ let () = | |
let r = rectangle 200 200 |> with_fill (rgb 255 0 0) in | ||
show [ r ]; | ||
write ~filename:"fill-rect.png" () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ type context = unit | |
|
||
let show _ctx _shapes = () | ||
let create _ = () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,41 @@ | ||
type context = | ||
CairoContext of Backend_cairo.context | ||
| CairoContext of Backend_cairo.context | ||
| SVGContext of Backend_svg.context | ||
| LazyContext of Backend_lazy.context | ||
|
||
exception No_context | ||
exception Unsupported_output_format of string | ||
|
||
let default = ref (LazyContext (Backend_lazy.create ())) | ||
|
||
let get_default _ = | ||
!default | ||
|
||
let set_default ctx = | ||
default := ctx | ||
let get_default _ = !default | ||
let set_default ctx = default := ctx | ||
|
||
let show ?ctx shapes = | ||
let ctx = match ctx with | ||
| Some ctx -> ctx | ||
| None -> get_default () | ||
in | ||
let ctx = match ctx with Some ctx -> ctx | None -> get_default () in | ||
match ctx with | ||
| CairoContext ctx -> Backend_cairo.show ctx shapes | ||
| SVGContext ctx -> Backend_svg.show ctx shapes | ||
| LazyContext ctx -> Backend_lazy.show ctx shapes | ||
|
||
let set_line_width ?ctx int = | ||
let ctx = match ctx with | ||
| Some ctx -> ctx | ||
| None -> get_default () | ||
in | ||
let ctx = match ctx with Some ctx -> ctx | None -> get_default () in | ||
match ctx with | ||
| CairoContext ctx -> Backend_cairo.set_line_width ctx int | ||
| SVGContext _ -> failwith "SVG.set_line_width ctx int" | ||
| LazyContext _ -> failwith "Backend_lazy.set_line_width ctx int" | ||
|
||
let writePNG ?ctx filename = | ||
let ctx = match ctx with | ||
| Some ctx -> ctx | ||
| None -> get_default () | ||
in | ||
let ctx = match ctx with Some ctx -> ctx | None -> get_default () in | ||
match ctx with | ||
| CairoContext ctx -> Backend_cairo.write ctx filename | ||
| SVGContext _ -> raise (Unsupported_output_format "SVG context cannot render to PNG") | ||
| SVGContext _ -> | ||
raise (Unsupported_output_format "SVG context cannot render to PNG") | ||
| LazyContext _ -> failwith "Lazy.writePNG ctx filename" | ||
|
||
let writeSVG ?ctx = | ||
let ctx = match ctx with | ||
| Some ctx -> ctx | ||
| None -> get_default () | ||
in | ||
let ctx = match ctx with Some ctx -> ctx | None -> get_default () in | ||
match ctx with | ||
| CairoContext _ -> raise (Unsupported_output_format "Cairo context cannot render to SVG") | ||
| CairoContext _ -> | ||
raise (Unsupported_output_format "Cairo context cannot render to SVG") | ||
| SVGContext _ -> failwith "SVG.writeSVG ctx" | ||
| LazyContext _ -> failwith "Lazy.writeSVG ctx" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.