-
Notifications
You must be signed in to change notification settings - Fork 5
/
context.lua
2847 lines (2280 loc) · 92.9 KB
/
context.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local argcheck = require 'argcheck'
local class = require 'class'
local ffi = require 'ffi'
local cairo = require 'cairo.env'
local utils = require 'cairo.utils'
local C = cairo.C
local doc = require 'argcheck.doc'
local Context = class.new('cairo.Context')
cairo.Context = Context
doc[[
### Drawing Context
]]
Context.__init = argcheck{
doc = [[
<a name="Context.new">
#### Context.new(@ARGP)
@ARGT
Creates a new [`Context`](#Context) with all graphics state parameters set to
default values and with `target` as a target surface. The target
surface should be constructed with a backend-specific function such
as [`ImageSurface.new()`](imagesurface.md#ImageSurface.new) (or any other
Cairo image surface backend variant).
This function references `target`, so you can immediately
call [`Surface.destroy()`](surface.md#Surface.destroy) on it if you don't need to
maintain a separate reference to it.
_Return value_: a newly allocated [`Context`](#Context) with a reference
count of 1. The initial reference count should be released
with [`Context.destroy()`](#Context.destroy) when you are done using the [`Context`](#Context).
This function never returns `nil`. If memory cannot be
allocated, a special [`Context`](#Context) object will be returned on
which [`Context.status()`](#Context.status) returns [`"no-memory"`](enums.md#Status). If
you attempt to target a surface which does not support
writing (such as [`MimeSurface`](mimesurface.md#MimeSurface)) then a
[`"write-error"`](enums.md#Status) will be raised. You can use this
object normally, but no drawing will be done.
]],
{name="self", type="cairo.Context"},
{name="surface", type="cairo.Surface"},
call =
function(self, surface)
self.C = C.cairo_create(surface.C)
ffi.gc(self.C, C.cairo_destroy)
return self
end
}
Context.status = argcheck{
doc = [[
<a name="Context.status">
#### Context.status(@ARGP)
@ARGT
Checks whether an error has previously occurred for this context.
_Returns_: the current status of this context, see [`Status`](enums.md#Status)
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.enums.Status[ tonumber(C.cairo_status(self.C)) ]
end
}
Context.save = argcheck{
doc = [[
<a name="Context.save">
#### Context.save(@ARGP)
@ARGT
Makes a copy of the current state of `cr` and saves it
on an internal stack of saved states for `cr`. When
[`Context.restore()`](#Context.restore) is called, `cr` will be restored to
the saved state. Multiple calls to [`Context.save()`](#Context.save) and
[`Context.restore()`](#Context.restore) can be nested; each call to [`Context.restore()`](#Context.restore)
restores the state from the matching paired [`Context.save()`](#Context.save).
It isn't necessary to clear all saved states before
a [`Context`](#Context) is freed. If the reference count of a [`Context`](#Context)
drops to zero in response to a call to [`Context.destroy()`](#Context.destroy),
any saved states will be freed along with the [`Context`](#Context).
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
call =
function(self)
C.cairo_save(self.C)
end
}
Context.restore = argcheck{
doc = [[
<a name="Context.restore">
#### Context.restore(@ARGP)
@ARGT
Restores `cr` to the state saved by a preceding call to
[`Context.save()`](#Context.save) and removes that state from the stack of
saved states.
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
call =
function(self)
C.cairo_restore(self.C)
end
}
Context.getTarget = argcheck{
doc = [[
<a name="Context.getTarget">
#### Context.getTarget(@ARGP)
@ARGT
Gets the target surface for the cairo context as passed to
[`Context.new()`](#Context.new).
This function will always return a valid pointer, but the result
can be a "nil" surface if `cr` is already in an error state,
(ie. [`Context.status()`](#Context.status) `!=` [`"success"`](enums.md#Status)).
A nil surface is indicated by [`Surface.status()`](surface.md#Surface.status)
`!=` [`"success"`](enums.md#Status).
_Return value_: the target surface. This object is owned by cairo. To
keep a reference to it, you must call [`Surface.reference()`](surface.md#Surface.reference).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.Surface(C.cairo_get_target(self.C), true)
end
}
Context.pushGroup = argcheck{
doc = [[
<a name="Context.pushGroup">
#### Context.pushGroup(@ARGP)
@ARGT
Temporarily redirects drawing to an intermediate surface known as a
group. The redirection lasts until the group is completed by a call
to [`Context.popGroup()`](#Context.popGroup) or [`Context.popGroupToSource()`](#Context.popGroupToSource). These calls
provide the result of any drawing to the group as a pattern,
(either as an explicit object, or set as the source pattern).
This group functionality can be convenient for performing
intermediate compositing. One common use of a group is to render
objects as opaque within the group, (so that they occlude each
other), and then blend the result with translucence onto the
destination.
Groups can be nested arbitrarily deep by making balanced calls to
[`Context.pushGroup()/cairoPopGroup()`](#Context.pushGroup()/cairoPopGroup). Each call pushes/pops the new
target group onto/from a stack.
The [`Context.pushGroup()`](#Context.pushGroup) function calls [`Context.save()`](#Context.save) so that any
changes to the graphics state will not be visible outside the
group, (the pop_group functions call [`Context.restore()`](#Context.restore)).
By default the intermediate group will have a content type of
[`"color-alpha"`](enums.md#Content). Other content types can be chosen for
the group by using [`Context.pushGroupWithContent()`](#Context.pushGroupWithContent) instead.
As an example, here is how one might fill and stroke a path with
translucence, but without any portion of the fill being visible
under the stroke:
```lua
cairo_push_group (cr);
cairo_set_source (cr, fill_pattern);
cairo_fill_preserve (cr);
cairo_set_source (cr, stroke_pattern);
cairo_stroke (cr);
cairo_pop_group_to_source (cr);
cairo_paint_with_alpha (cr, alpha);
```
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
C.cairo_push_group(self.C)
end
}
Context.pushGroupWithContent = argcheck{
doc = [[
<a name="Context.pushGroupWithContent">
#### Context.pushGroupWithContent(@ARGP)
@ARGT
Temporarily redirects drawing to an intermediate surface known as a
group. The redirection lasts until the group is completed by a call
to [`Context.popGroup()`](#Context.popGroup) or [`Context.popGroupToSource()`](#Context.popGroupToSource). These calls
provide the result of any drawing to the group as a pattern,
(either as an explicit object, or set as the source pattern).
The group will have a content type of `content`. The ability to
control this content type is the only distinction between this
function and [`Context.pushGroup()`](#Context.pushGroup) which you should see for a more
detailed description of group rendering.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="content", type="string", doc="a [`Content`](enums.md#Content) indicating the type of group that will be created"},
call =
function(self, content)
C.cairo_push_group_with_content(self.C, cairo.enums.Content[content])
end
}
Context.popGroup = argcheck{
doc = [[
<a name="Context.popGroup">
#### Context.popGroup(@ARGP)
@ARGT
Terminates the redirection begun by a call to [`Context.pushGroup()`](#Context.pushGroup) or
[`Context.pushGroupWithContent()`](#Context.pushGroupWithContent) and returns a new pattern
containing the results of all drawing operations performed to the
group.
The [`Context.popGroup()`](#Context.popGroup) function calls [`Context.restore()`](#Context.restore), (balancing a
call to [`Context.save()`](#Context.save) by the push_group function), so that any
changes to the graphics state will not be visible outside the
group.
_Return value_: a newly created (surface) pattern containing the
results of all drawing operations performed to the group. The
caller owns the returned object and should call
[`Pattern.destroy()`](pattern.md#Pattern.destroy) when finished with it.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.Pattern(C.cairo_pop_group(self.C))
end
}
Context.popGroupToSource = argcheck{
doc = [[
<a name="Context.popGroupToSource">
#### Context.popGroupToSource(@ARGP)
@ARGT
Terminates the redirection begun by a call to [`Context.pushGroup()`](#Context.pushGroup) or
[`Context.pushGroupWithContent()`](#Context.pushGroupWithContent) and installs the resulting pattern
as the source pattern in the given cairo context.
The behavior of this function is equivalent to the sequence of
operations:
```lua
cairo_pattern_t *group = cairo_pop_group (cr);
cairo_set_source (cr, group);
cairo_pattern_destroy (group);
```
but is more convenient as their is no need for a variable to store
the short-lived pointer to the pattern.
The [`Context.popGroup()`](#Context.popGroup) function calls [`Context.restore()`](#Context.restore), (balancing a
call to [`Context.save()`](#Context.save) by the push_group function), so that any
changes to the graphics state will not be visible outside the
group.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
C.cairo_pop_group_to_source(self.C)
end
}
Context.getGroupTarget = argcheck{
doc = [[
<a name="Context.getGroupTarget">
#### Context.getGroupTarget(@ARGP)
@ARGT
Gets the current destination surface for the context. This is either
the original target surface as passed to [`Context.new()`](#Context.new) or the target
surface for the current group as started by the most recent call to
[`Context.pushGroup()`](#Context.pushGroup) or [`Context.pushGroupWithContent()`](#Context.pushGroupWithContent).
This function will always return a valid pointer, but the result
can be a "nil" surface if `cr` is already in an error state,
(ie. [`Context.status()`](#Context.status) `!=` [`"success"`](enums.md#Status)).
A nil surface is indicated by [`Surface.status()`](surface.md#Surface.status)
`!=` [`"success"`](enums.md#Status).
_Return value_: the target surface. This object is owned by cairo. To
keep a reference to it, you must call [`Surface.reference()`](surface.md#Surface.reference).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.Surface(C.cairo_get_group_target(self.C), true)
end
}
Context.setSourceRGB = argcheck{
doc = [[
<a name="Context.setSourceRGB">
#### Context.setSourceRGB(@ARGP)
@ARGT
Sets the source pattern within `cr` to an opaque color. This opaque
color will then be used for any subsequent drawing operation until
a new source pattern is set.
The color components are floating point numbers in the range 0 to
1. If the values passed in are outside that range, they will be
clamped.
The default source pattern is opaque black, (that is, it is
equivalent to cairo_set_source_rgb(cr, 0.0, 0.0, 0.0)).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="red", type="number", doc="red component of color"},
{name="green", type="number", doc="green component of color"},
{name="blue", type="number", doc="blue component of color"},
call =
function(self, red, green, blue)
C.cairo_set_source_rgb(self.C, red, green, blue)
end
}
Context.setSourceRGBA = argcheck{
doc = [[
<a name="Context.setSourceRGBA">
#### Context.setSourceRGBA(@ARGP)
@ARGT
Sets the source pattern within `cr` to a translucent color. This
color will then be used for any subsequent drawing operation until
a new source pattern is set.
The color and alpha components are floating point numbers in the
range 0 to 1. If the values passed in are outside that range, they
will be clamped.
The default source pattern is opaque black, (that is, it is
equivalent to cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0)).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="red", type="number", doc="red component of color"},
{name="green", type="number", doc="green component of color"},
{name="blue", type="number", doc="blue component of color"},
{name="alpha", type="number", doc="alpha component of color"},
call =
function(self, red, green, blue, alpha)
C.cairo_set_source_rgba(self.C, red, green, blue, alpha)
end
}
Context.setSource = argcheck{
doc = [[
<a name="Context.setSource">
#### Context.setSource(@ARGP)
@ARGT
Sets the source pattern within `cr` to `source`. This pattern
will then be used for any subsequent drawing operation until a new
source pattern is set.
Note: The pattern's transformation matrix will be locked to the
user space in effect at the time of [`Context.setSource()`](#Context.setSource). This means
that further modifications of the current transformation matrix
will not affect the source pattern. See [`Pattern.setMatrix()`](pattern.md#Pattern.setMatrix).
The default source pattern is a solid pattern that is opaque black,
(that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0,
0.0)).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="source", type="cairo.Pattern", doc="a [`Pattern`](pattern.md#Pattern) to be used as the source for subsequent drawing operations."},
call =
function(self, source)
C.cairo_set_source(self.C, source.C)
end
}
Context.setSourceSurface = argcheck{
doc = [[
<a name="Context.setSourceSurface">
#### Context.setSourceSurface(@ARGP)
@ARGT
This is a convenience function for creating a pattern from `surface`
and setting it as the source in `cr` with [`Context.setSource()`](#Context.setSource).
The `x` and `y` parameters give the user-space coordinate at which
the surface origin should appear. (The surface origin is its
upper-left corner before any transformation has been applied.) The
`x` and `y` parameters are negated and then set as translation values
in the pattern matrix.
Other than the initial translation pattern matrix, as described
above, all other pattern attributes, (such as its extend mode), are
set to the default values as in [`Pattern.createForSurface()`](pattern.md#Pattern.createForSurface).
The resulting pattern can be queried with [`Context.getSource()`](#Context.getSource) so
that these attributes can be modified if desired, (eg. to create a
repeating pattern with [`Pattern.setExtend()`](pattern.md#Pattern.setExtend)).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="surface", type="cairo.Surface", doc="a surface to be used to set the source pattern"},
{name="x", type="number", default=0, doc="User-space X coordinate for surface origin"},
{name="y", type="number", default=0, doc="User-space Y coordinate for surface origin"},
call =
function(self, surface, x, y)
C.cairo_set_source_surface(self.C, surface.C, x, y)
end
}
Context.getSource = argcheck{
doc = [[
<a name="Context.getSource">
#### Context.getSource(@ARGP)
@ARGT
Gets the current source pattern for `cr`.
_Return value_: the current source pattern. This object is owned by
cairo. To keep a reference to it, you must call
[`Pattern.reference()`](pattern.md#Pattern.reference).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.Pattern(C.cairo_get_source(self.C), true)
end
}
Context.setAntialias = argcheck{
doc = [[
<a name="Context.setAntialias">
#### Context.setAntialias(@ARGP)
@ARGT
Set the antialiasing mode of the rasterizer used for drawing shapes.
This value is a hint, and a particular backend may or may not support
a particular value. At the current time, no backend supports
[`"subpixel"`](enums.md#Antialias) when drawing shapes.
Note that this option does not affect text rendering, instead see
[`FontOptions.setAntialias()`](fontoptions.md#FontOptions.setAntialias).
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
{name="antialias", type="string", doc="the new antialiasing mode"},
call =
function(self, antialias)
C.cairo_set_antialias(self.C, cairo.enums.AntiAlias[antialias])
end
}
Context.getAntialias = argcheck{
doc = [[
<a name="Context.getAntialias">
#### Context.getAntialias(@ARGP)
@ARGT
Gets the current shape antialiasing mode, as set by
[`Context.setAntialias()`](#Context.setAntialias).
_Return value_: the current shape antialiasing mode.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.enums.Antialias[ tonumber(C.cairo_get_antialias(self.C)) ]
end
}
Context.setDash = argcheck{
doc = [[
<a name="Context.setDash">
#### Context.setDash(@ARGP)
@ARGT
Sets the dash pattern to be used by [`Context.stroke()`](#Context.stroke). A dash pattern
is specified by `dashes`, an array of positive values. Each value
provides the length of alternate "on" and "off" portions of the
stroke. The `offset` specifies an offset into the pattern at which
the stroke begins.
Each "on" segment will have caps applied as if the segment were a
separate sub-path. In particular, it is valid to use an "on" length
of 0.0 with [`"round"`](enums.md#LineCap) or [`"square"`](enums.md#LineCap) in order
to distributed dots or squares along a path.
Note: The length values are in user-space units as evaluated at the
time of stroking. This is not necessarily the same as the user
space at the time of [`Context.setDash()`](#Context.setDash).
If `num_dashes` is 0 dashing is disabled.
If `num_dashes` is 1 a symmetric pattern is assumed with alternating
on and off portions of the size specified by the single value in
`dashes`.
If any value in `dashes` is negative, or if all values are 0, then
`cr` will be put into an error state with a status of
[`"invalid-dash"`](enums.md#Status).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="dashes", type="table", doc="an array specifying alternate lengths of on and off stroke portions"},
{name="offset", type="number", doc="an offset into the dash pattern at which the stroke should start"},
call =
function(self, dashes, offset)
local num_dashes = #dashes
local dashes_p = ffi.new('double[?]', num_dashes, dashes)
C.cairo_set_dash(self.C, dashes_p, num_dashes, offset)
end
}
Context.getDashCount = argcheck{
doc = [[
<a name="Context.getDashCount">
#### Context.getDashCount(@ARGP)
@ARGT
This function returns the length of the dash array in `cr` (0 if dashing
is not currently in effect).
See also [`Context.setDash()`](#Context.setDash) and [`Context.getDash()`](#Context.getDash).
_Return value_: the length of the dash array, or 0 if no dash array set.
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
call =
function(self)
return C.cairo_get_dash_count(self.C)
end
}
Context.getDash = argcheck{
doc = [[
<a name="Context.getDash">
#### Context.getDash(@ARGP)
@ARGT
Gets the current dash array. If not `nil`, `dashes` should be big
enough to hold at least the number of values returned by
[`Context.getDashCount()`](#Context.getDashCount).
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
call =
function(self, dashes, offset)
local n_dash = self:getDashCount()
local dashes_p = ffi.new('double[?]', n_dash)
local offset_p = ffi.new('double[1]')
C.cairo_get_dash(self.C, dashes_p, offset)
local dashes = {}
for i=0,n_dash-1 do
table.insert(dashes, dashes_p[i])
end
return dashes, offset
end
}
Context.setFillRule = argcheck{
doc = [[
<a name="Context.setFillRule">
#### Context.setFillRule(@ARGP)
@ARGT
Set the current fill rule within the cairo context. The fill rule
is used to determine which regions are inside or outside a complex
(potentially self-intersecting) path. The current fill rule affects
both [`Context.fill()`](#Context.fill) and [`Context.clip()`](#Context.clip). See [`FillRule`](enums.md#FillRule) for details
on the semantics of each available fill rule.
The default fill rule is [`"winding"`](enums.md#FillRule).
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
{name="fill_rule", type="string", doc="a fill rule, specified as a [`FillRule`](enums.md#FillRule)"},
call =
function(self, fill_rule)
C.cairo_set_fill_rule(self.C, cairo.enums.FillRule[fill_rule])
end
}
Context.getFillRule = argcheck{
doc = [[
<a name="Context.getFillRule">
#### Context.getFillRule(@ARGP)
@ARGT
Gets the current fill rule, as set by [`Context.setFillRule()`](#Context.setFillRule).
_Return value_: the current fill rule.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.enums.FillRule[ tonumber(C.cairo_get_fill_rule(self.C)) ]
end
}
Context.setLineCap = argcheck{
doc = [[
<a name="Context.setLineCap">
#### Context.setLineCap(@ARGP)
@ARGT
Sets the current line cap style within the cairo context. See
[`LineCap`](enums.md#LineCap) for details about how the available line cap
styles are drawn.
As with the other stroke parameters, the current line cap style is
examined by [`Context.stroke()`](#Context.stroke), [`Context.strokeExtents()`](#Context.strokeExtents), and
[`Context.strokeToPath()`](#Context.strokeToPath), but does not have any effect during path
construction.
The default line cap style is [`"butt"`](enums.md#LineCap).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="line_cap", type="string", doc="a line cap style"},
call =
function(self, line_cap)
C.cairo_set_line_cap(self.C, cairo.enums.LineCap[line_cap])
end
}
Context.getLineCap = argcheck{
doc = [[
<a name="Context.getLineCap">
#### Context.getLineCap(@ARGP)
@ARGT
Gets the current line cap style, as set by [`Context.setLineCap()`](#Context.setLineCap).
_Return value_: the current line cap style.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.enums.LineCap[ tonumber(C.cairo_get_line_cap(self.C)) ]
end
}
Context.setLineJoin = argcheck{
doc = [[
<a name="Context.setLineJoin">
#### Context.setLineJoin(@ARGP)
@ARGT
Sets the current line join style within the cairo context. See
[`LineJoin`](enums.md#LineJoin) for details about how the available line join
styles are drawn.
As with the other stroke parameters, the current line join style is
examined by [`Context.stroke()`](#Context.stroke), [`Context.strokeExtents()`](#Context.strokeExtents), and
[`Context.strokeToPath()`](#Context.strokeToPath), but does not have any effect during path
construction.
The default line join style is [`"miter"`](enums.md#LineJoin).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="line_join", type="string", doc="a line join style"},
call =
function(self, line_join)
C.cairo_set_line_join(self.C, cairo.enums.LineJoin[line_join])
end
}
Context.getLineJoin = argcheck{
doc = [[
<a name="Context.getLineJoin">
#### Context.getLineJoin(@ARGP)
@ARGT
Gets the current line join style, as set by [`Context.setLineJoin()`](#Context.setLineJoin).
_Return value_: the current line join style.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.enums.LineJoin[ tonumber(C.cairo_get_line_join(self.C)) ]
end
}
Context.setLineWidth = argcheck{
doc = [[
<a name="Context.setLineWidth">
#### Context.setLineWidth(@ARGP)
@ARGT
Sets the current line width within the cairo context. The line
width value specifies the diameter of a pen that is circular in
user space, (though device-space pen may be an ellipse in general
due to scaling/shear/rotation of the CTM).
Note: When the description above refers to user space and CTM it
refers to the user space and CTM in effect at the time of the
stroking operation, not the user space and CTM in effect at the
time of the call to [`Context.setLineWidth()`](#Context.setLineWidth). The simplest usage
makes both of these spaces identical. That is, if there is no
change to the CTM between a call to [`Context.setLineWidth()`](#Context.setLineWidth) and the
stroking operation, then one can just pass user-space values to
[`Context.setLineWidth()`](#Context.setLineWidth) and ignore this note.
As with the other stroke parameters, the current line width is
examined by [`Context.stroke()`](#Context.stroke), [`Context.strokeExtents()`](#Context.strokeExtents), and
[`Context.strokeToPath()`](#Context.strokeToPath), but does not have any effect during path
construction.
The default line width value is 2.0.
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
{name="width", type="number", doc="a line width"},
call =
function(self, width)
C.cairo_set_line_width(self.C, width)
end
}
Context.getLineWidth = argcheck{
doc = [[
<a name="Context.getLineWidth">
#### Context.getLineWidth(@ARGP)
@ARGT
This function returns the current line width value exactly as set by
[`Context.setLineWidth()`](#Context.setLineWidth). Note that the value is unchanged even if
the CTM has changed between the calls to [`Context.setLineWidth()`](#Context.setLineWidth) and
[`Context.getLineWidth()`](#Context.getLineWidth).
_Return value_: the current line width.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return C.cairo_get_line_width(self.C)
end
}
Context.setMiterLimit = argcheck{
doc = [[
<a name="Context.setMiterLimit">
#### Context.setMiterLimit(@ARGP)
@ARGT
Sets the current miter limit within the cairo context.
If the current line join style is set to [`"miter"`](enums.md#LineJoin)
(see [`Context.setLineJoin()`](#Context.setLineJoin)), the miter limit is used to determine
whether the lines should be joined with a bevel instead of a miter.
Cairo divides the length of the miter by the line width.
If the result is greater than the miter limit, the style is
converted to a bevel.
As with the other stroke parameters, the current line miter limit is
examined by [`Context.stroke()`](#Context.stroke), [`Context.strokeExtents()`](#Context.strokeExtents), and
[`Context.strokeToPath()`](#Context.strokeToPath), but does not have any effect during path
construction.
The default miter limit value is 10.0, which will convert joins
with interior angles less than 11 degrees to bevels instead of
miters. For reference, a miter limit of 2.0 makes the miter cutoff
at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90
degrees.
A miter limit for a desired angle can be computed as: miter limit =
1/sin(angle/2)
]],
{name="self", type="cairo.Context", doc="a cairo context"},
{name="limit", type="number", doc="miter limit to set"},
call =
function(self, limit)
C.cairo_set_miter_limit(self.C, limit)
end
}
Context.getMiterLimit = argcheck{
doc = [[
<a name="Context.getMiterLimit">
#### Context.getMiterLimit(@ARGP)
@ARGT
Gets the current miter limit, as set by [`Context.setMiterLimit()`](#Context.setMiterLimit).
_Return value_: the current miter limit.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return C.cairo_get_miter_limit(self.C)
end
}
Context.setOperator = argcheck{
doc = [[
<a name="Context.setOperator">
#### Context.setOperator(@ARGP)
@ARGT
Sets the compositing operator to be used for all drawing
operations. See [`Operator`](enums.md#Operator) for details on the semantics of
each available compositing operator.
The default operator is [`"over"`](enums.md#Operator).
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
{name="op", type="string", doc="a compositing operator, specified as a [`Operator`](enums.md#Operator)"},
call =
function(self, op)
C.cairo_set_operator(self.C, cairo.enums.Operator[op])
end
}
Context.getOperator = argcheck{
doc = [[
<a name="Context.getOperator">
#### Context.getOperator(@ARGP)
@ARGT
Gets the current compositing operator for a cairo context.
_Return value_: the current compositing operator.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return cairo.enums.Operator[ tonumber(C.cairo_get_operator(self.C)) ]
end
}
Context.setTolerance = argcheck{
doc = [[
<a name="Context.setTolerance">
#### Context.setTolerance(@ARGP)
@ARGT
Sets the tolerance used when converting paths into trapezoids.
Curved segments of the path will be subdivided until the maximum
deviation between the original path and the polygonal approximation
is less than `tolerance`. The default value is 0.1. A larger
value will give better performance, a smaller value, better
appearance. (Reducing the value from the default value of 0.1
is unlikely to improve appearance significantly.) The accuracy of paths
within Cairo is limited by the precision of its internal arithmetic, and
the prescribed `tolerance` is restricted to the smallest
representable internal value.
]],
{name="self", type="cairo.Context", doc="a [`Context`](#Context)"},
{name="tolerance", type="number", doc="the tolerance, in device units (typically pixels)"},
call =
function(self, tolerance)
C.cairo_set_tolerance(self.C, tolerance)
end
}
Context.getTolerance = argcheck{
doc = [[
<a name="Context.getTolerance">
#### Context.getTolerance(@ARGP)
@ARGT
Gets the current tolerance value, as set by [`Context.setTolerance()`](#Context.setTolerance).
_Return value_: the current tolerance value.
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
return C.cairo_get_tolerance(self.C)
end
}
Context.clip = argcheck{
doc = [[
<a name="Context.clip">
#### Context.clip(@ARGP)
@ARGT
Establishes a new clip region by intersecting the current clip
region with the current path as it would be filled by [`Context.fill()`](#Context.fill)
and according to the current fill rule (see [`Context.setFillRule()`](#Context.setFillRule)).
After [`Context.clip()`](#Context.clip), the current path will be cleared from the cairo
context.
The current clip region affects all drawing operations by
effectively masking out any changes to the surface that are outside
the current clip region.
Calling [`Context.clip()`](#Context.clip) can only make the clip region smaller, never
larger. But the current clip is part of the graphics state, so a
temporary restriction of the clip region can be achieved by
calling [`Context.clip()`](#Context.clip) within a [`Context.save()/cairoRestore()`](#Context.save()/cairoRestore)
pair. The only other means of increasing the size of the clip
region is [`Context.resetClip()`](#Context.resetClip).
]],
{name="self", type="cairo.Context", doc="a cairo context"},
call =
function(self)
C.cairo_clip(self.C)
end
}
Context.clipPreserve = argcheck{
doc = [[
<a name="Context.clipPreserve">
#### Context.clipPreserve(@ARGP)
@ARGT
Establishes a new clip region by intersecting the current clip
region with the current path as it would be filled by [`Context.fill()`](#Context.fill)
and according to the current fill rule (see [`Context.setFillRule()`](#Context.setFillRule)).
Unlike [`Context.clip()`](#Context.clip), [`Context.clipPreserve()`](#Context.clipPreserve) preserves the path within
the cairo context.
The current clip region affects all drawing operations by
effectively masking out any changes to the surface that are outside
the current clip region.
Calling [`Context.clipPreserve()`](#Context.clipPreserve) can only make the clip region smaller, never
larger. But the current clip is part of the graphics state, so a
temporary restriction of the clip region can be achieved by
calling [`Context.clipPreserve()`](#Context.clipPreserve) within a [`Context.save()/cairoRestore()`](#Context.save()/cairoRestore)
pair. The only other means of increasing the size of the clip
region is [`Context.resetClip()`](#Context.resetClip).