2
* Java-Gnome Bindings Library
4
* Copyright 1998-2005 the Java-Gnome Team, all rights reserved.
6
* The Java-Gnome bindings library is free software distributed under
7
* the terms of the GNU Library General Public License version 2.
9
package org.freedesktop.cairo;
11
import org.gnu.glib.Struct;
12
import org.gnu.glib.Handle;
14
public class Context extends CairoObject {
17
* Creates a new Context with all graphics state parameters set to default
18
* values and with target as a target surface. The target surface should be
19
* constructed with a backend-specific function such as ImageSurface.create.
22
* target surface for the context.
24
public Context(Surface target) {
25
super(cairo_create(target.getHandle()));
28
protected Context(Handle hndl) {
33
* Disposes all the native resources used by the object.
35
protected void finalize() throws Throwable {
36
cairo_destroy(getHandle());
41
* Makes a copy of the current state and saves it on an internal stack of
42
* saved states. When {@link #restore()} is called, the saved state will be
43
* restored. Multiple calls <tt>save()</tt> and <tt>restore()</tt> can
44
* be nested; each call to <tt>restore()</tt> restores the state from the
45
* matching paired <tt>save()</tt>.
48
cairo_save(getHandle());
52
* Restores the state saved by a preceding call to {@link #save()} and
53
* removes that state from the stack of saved states.
55
public void restore() {
56
cairo_restore(getHandle());
60
* Sets the compositing operator to be used for all drawing operations.
64
public void setOperator(Operator op) {
65
cairo_set_operator(getHandle(), op.getValue());
69
* Sets the source pattern within the Cairo object. This pattern will then
70
* be used for any subsequent drawing operation until a new source pattern
75
public void setSource(Pattern pattern) {
76
cairo_set_source(getHandle(), pattern.getHandle());
80
* Sets a constant color for filling and stroking. The color components are
81
* floating point numbers in the range 0 to 1. If the values passed in are
82
* outside that range, they will be clamped.
88
public void setSourceRGB(double red, double green, double blue) {
89
cairo_set_source_rgb(getHandle(), red, green, blue);
93
* Sets the source pattern within this Cairo object to a translucent color.
94
* This color will then be used for any subsequent drawing operation until a
95
* new source pattern is set.
97
* The color and alpha components are floating point numbers in the range 0
98
* to 1. If the values passed in are outside that range, they will be
106
public void setSourceRGBA(double red, double green, double blue,
108
cairo_set_source_rgba(getHandle(), red, green, blue, alpha);
117
public void setSource(Surface surface, double x, double y) {
118
cairo_set_source_surface(getHandle(), surface.getHandle(), x, y);
122
* Sets the tolerance used when converting paths into trapezoids. Curved
123
* segments of the path will be subdivided until the maximum deviation
124
* between the original path and the polygonal approximation is less than
125
* tolerance. The default value is 0.1. A larger value will give better
126
* performance, a smaller value, better appearance. (Reducing the value from
127
* the default value of 0.1 is unlikely to improve appearance
132
public void setTolerance(double tolerance) {
133
cairo_set_tolerance(getHandle(), tolerance);
137
* Set the current fill rule within the Context. The fill rule is used to
138
* determine which regions are inside or outside a complex (potentially
139
* self-intersecting) path. The current fill rule affects both <tt>fill</tt>
144
public void setFillRule(FillRule fillrule) {
145
cairo_set_fill_rule(getHandle(), fillrule.getValue());
149
* Sets the current line width within the cairo context. The line width
150
* specifies the diameter of a pen that is circular in user-space.
152
* As with the other stroke parameters, the current line cap style is
153
* examined by <tt>stroke()</tt>, <tt>strokeExtents()</tt>, and
154
* <tt>strokeToPath(), but does not have any effect during path
158
public void setLineWidth(double width) {
159
cairo_set_line_width(getHandle(), width);
163
* Sets the current line cap style within the cairo context. See
164
* <tt>LineCap</tt> for details about how the available line cap styles
169
public void setLineCap(LineCap linecap) {
170
cairo_set_line_cap(getHandle(), linecap.getValue());
174
* Sets the current line join style within the cairo context. See
175
* <tt>LineJoin</tt> for details about how the available line join styles
180
public void setLineJoin(LineJoin linejoin) {
181
cairo_set_line_join(getHandle(), linejoin.getValue());
185
* Sets the line dash.
190
public void setDash(double[] dashes, double offset) {
191
cairo_set_dash(getHandle(), dashes, offset);
195
* Sets the miter limit.
199
public void setMiterLimit(double limit) {
200
cairo_set_miter_limit(getHandle(), limit);
204
* Modifies the current transformation matrix (CTM) by tanslating the
205
* user-space origin by (tx, ty). This offset is interpreted as a user-space
206
* coordinate according to the CTM in place before the new call to
207
* translate. In other words, the translation of the user-space origin takes
208
* place after any existing transformation.
213
public void translate(double tx, double ty) {
214
cairo_translate(getHandle(), tx, ty);
218
* Modifies the current transformation matrix (CTM) by scaling the X and Y
219
* user-space axes by sx and sy respectively. The scaling of the axes takes
220
* place after any existing transformation of user space.
225
public void scale(double sx, double sy) {
226
cairo_scale(getHandle(), sx, sy);
230
* Modifies the current transformation matrix (CTM) by rotating the
231
* user-space axes by angle radians. The rotation of the axes takes places
232
* after any existing transformation of user space. The rotation direction
233
* for positive angles is from the positive X axis toward the positive Y
238
public void rotate(double angle) {
239
cairo_rotate(getHandle(), angle);
243
* Modifies the current transformation matrix (CTM) by applying matrix as an
244
* additional transformation. The new transformation of user space takes
245
* place after any existing transformation.
248
* the transformation matrix to append
250
public void transform(Matrix matrix) {
251
cairo_transform(getHandle(), matrix.getHandle());
255
* Modifies the current transformation matrix (CTM) by setting it equal to
259
* the transformation matrix
261
public void setMatrix(Matrix matrix) {
262
cairo_set_matrix(getHandle(), matrix.getHandle());
266
* Resets the current transformation matrix (CTM) by setting it equal to the
267
* identity matrix. That is, the user-space and device-space axes will be
268
* aligned and one user-space unit will transform to one device-space unit.
270
public void identityMatrix() {
271
cairo_identity_matrix(getHandle());
275
* Transform a coordinate from user space to device space by multiplying the
276
* given point by the current transformation matrix (CTM).
278
public Point userToDevice(Point point) {
279
double[] px = new double[] { point.getX() };
280
double[] py = new double[] { point.getY() };
281
cairo_user_to_device(getHandle(), px, py);
282
return new Point(px[0], py[0]);
286
* Transform a distance vector from user space to device space. This
287
* function is similar to userToDevice() except that the translation
288
* components of the CTM will be ignored when transforming the Point.
290
public Point userToDeviceDistance(Point distance) {
291
double[] dx = new double[] { distance.getX() };
292
double[] dy = new double[] { distance.getY() };
293
cairo_user_to_device_distance(getHandle(), dx, dy);
294
return new Point(dx[0], dy[0]);
298
* Transform a coordinate from device space to user space by multiplying the
299
* given point by the inverse of the current transformation matrix (CTM).
301
public Point deviceToUser(Point point) {
302
double[] px = new double[] { point.getX() };
303
double[] py = new double[] { point.getY() };
304
cairo_device_to_user(getHandle(), px, py);
305
return new Point(px[0], py[0]);
309
* Transform a distance vector from device space to user space. This
310
* function is similar to deviceToUser() except that the translation
311
* components of the inverse CTM will be ignored when transforming the
314
public Point deviceToUserDistance(Point distance) {
315
double[] dx = new double[] { distance.getX() };
316
double[] dy = new double[] { distance.getY() };
317
cairo_device_to_user_distance(getHandle(), dx, dy);
318
return new Point(dx[0], dy[0]);
322
* Starts a new path. You can add path segments to this path using the path
323
* extension methods (xxxxTo()).
325
public void newPath() {
326
cairo_new_path(getHandle());
330
* Moves the current point in the path to the given co-ordinates.
333
* the point co-ordinate of the point to move to
335
public void moveTo(Point p) {
336
cairo_move_to(getHandle(), p.getX(), p.getY());
339
public void moveTo(double x, double y) {
340
cairo_move_to(getHandle(), x, y);
344
* Draws a line segment as part of the current path. The line is drawn from
345
* the current point of the path to the new co-ordinates.
348
* the point coordinate for the end point for the line segment
350
public void lineTo(Point p) {
351
cairo_line_to(getHandle(), p.getX(), p.getY());
354
public void lineTo(double x, double y) {
355
cairo_line_to(getHandle(), x, y);
359
* Draws a cubic bezier curve from the current point to (x3, y3) using 2
360
* control points (x1, y1) and (x2, y2).
363
* x co-ordinate of the first control point
365
* x co-ordinate of the second control point
367
* x co-ordinate of the end point
369
public void curveTo(Point p1, Point p2, Point p3) {
370
cairo_curve_to(getHandle(), p1.getX(), p1.getY(), p2.getX(), p2.getY(),
371
p3.getX(), p3.getY());
374
public void curveTo(double x1, double y1, double x2, double y2, double x3,
376
cairo_curve_to(getHandle(), x1, y1, x2, y2, x3, y3);
380
* Adds an arc from angle1 to angle2 to the current path. If there is a
381
* current point, that point is connected to the start of the arc by a
382
* straight line segment. Angles are measured in radians with an angle of 0
383
* along the X axis and an angle of %M_PI radians (90 degrees) along the Y
384
* axis, so with the default transformation matrix, positive angles are
385
* clockwise. (To convert from degrees to radians, use <literal>degrees *
386
* (M_PI / 180.)</literal>.) This function gives the arc in the direction
387
* of increasing angle; see arcNegative() to get the arc in the direction of
390
* A full arc is drawn as a circle. To make an oval arc, you can scale the
391
* current transformation matrix by different amounts in the X and Y
399
public void arc(Point point, double radius, double angle1, double angle2) {
400
cairo_arc(getHandle(), point.getX(), point.getY(), radius, angle1,
404
public void arc(double x, double y, double radius, double angle1,
406
cairo_arc(getHandle(), x, y, radius, angle1, angle2);
410
* Adds an arc from angle1 to angle2 to the current path. The function
411
* behaves identically to <tt>arc()</tt> except that instead of giving the
412
* arc in the direction of increasing angle, it gives the arc in the
413
* direction of decreasing angle.
420
public void arcNegative(Point point, double radius, double angle1,
422
cairo_arc_negative(getHandle(), point.getX(), point.getY(), radius,
426
public void arcNegative(double x, double y, double radius, double angle1,
428
cairo_arc_negative(getHandle(), x, y, radius, angle1, angle2);
432
* Moves to the current path to a new point. The co-ordinates of the new
433
* point are given in relation to the current point of the state.
436
* relative distance between current point and the new point
438
public void relMoveTo(Point p) {
439
cairo_rel_move_to(getHandle(), p.getX(), p.getY());
442
public void relMoveTo(double x, double y) {
443
cairo_rel_move_to(getHandle(), x, y);
447
* Draws a line segment as part of the current path. The line is drawn from
448
* the current point of the path to the new co-ordinates. The new
449
* co-ordinates are given relative to the current point.
452
* The relative coordinate for the end point for the line segment
454
public void relLineTo(Point p) {
455
cairo_rel_line_to(getHandle(), p.getX(), p.getY());
458
public void relLineTo(double x, double y) {
459
cairo_rel_line_to(getHandle(), x, y);
463
* Draws a cubic bezier curve from the current point to p3 using 2 control
464
* points p1 and p2. The co-ordinates are specified relative to current
468
* relative co-ordinate of the first control point
470
* relative co-ordinate of the second control point
472
* relative co-ordinate of the end point
474
public void relCurveTo(Point p1, Point p2, Point p3) {
475
cairo_rel_curve_to(getHandle(), p1.getX(), p1.getY(), p2.getX(), p2
476
.getY(), p3.getX(), p3.getY());
479
public void relCurveTo(double x1, double y1, double x2, double y2,
480
double x3, double y3) {
481
cairo_rel_curve_to(getHandle(), x1, y1, x2, y2, x3, y3);
485
* Draws a rectangle defined by the upper-left point p1 and the
486
* lower-right point p2.
489
* x and y coordinates of the upper-left point
491
* x and y coordinates of the lower-right point
493
public void rectangle(Point upperLeft, Point lowerRight) {
494
Rectangle r = new Rectangle(upperLeft, lowerRight);
499
* Draws a rectangle defined by the Rectangle object rect.
502
* Rectangle defining the coordinate of the shape to draw
504
public void rectangle(Rectangle rect) {
505
cairo_rectangle(getHandle(), rect.getX(), rect.getY(), rect.getWidth(),
510
* Closes the current path by connecting current point to the starting point
511
* with a line segment.
513
public void closePath() {
514
cairo_close_path(getHandle());
518
* A drawing operator that paints the current source everywhere within the
519
* current clip region.
521
public void paint() {
522
cairo_paint(getHandle());
526
* A drawing operator that paints the current source everywhere within the
527
* current clip region using a mask of constant alpha value alpha. The
528
* effect is similar to <tt>paint()</tt>, but the drawing is faded out
529
* using the alpha value.
533
public void paintWithAlpha(double alpha) {
534
cairo_paint_with_alpha(getHandle(), alpha);
538
* A drawing operator that paints the current source using the alpha channel
539
* of pattern as a mask. (Opaque areas of mask are painted with the source,
540
* transparent areas are not painted.)
544
public void mask(Pattern pattern) {
545
cairo_mask(getHandle(), pattern.getHandle());
549
* A drawing operator that paints the current source using the alpha channel
550
* of surface as a mask. (Opaque areas of surface are painted with the
551
* source, transparent areas are not painted.)
557
public void mask(Surface surface, double sx, double sy) {
558
cairo_mask_surface(getHandle(), surface.getHandle(), sx, sy);
562
* A drawing operator that strokes the current path according to the current
563
* line width, line join, line cap, and dash settings. After stroke, the
564
* current path will be cleared from the cairo context.
566
public void stroke() {
567
cairo_stroke(getHandle());
571
* A drawing operator that strokes the current path according to the current
572
* line width, line join, line cap, and dash settings. Unlike stroke(),
573
* strokePreserve preserves the path within the cairo context.
575
public void strokePreserve() {
576
cairo_stroke_preserve(getHandle());
580
* A drawing operator that fills the current path according to the current
581
* fill rule. After fill, the current path will be cleared from the cairo
585
cairo_fill(getHandle());
589
* A drawing operator that fills the current path according to the current
590
* fill rule. Unlike fill(), fillPreserve preserves the path within the
593
public void fillPreserve() {
594
cairo_fill_preserve(getHandle());
597
public void copyPage() {
598
cairo_copy_page(getHandle());
601
public void showPage() {
602
cairo_show_page(getHandle());
606
* Determines whether the point specified by (x, y) lies inside
607
* the area bounded by the current path, including the path's
611
* x coordinate of the point to test
613
* y coordinate of the point to test
615
public boolean inStroke(double x, double y) {
616
return cairo_in_stroke(getHandle(), x, y);
619
public boolean inStroke(Point p) {
620
return cairo_in_stroke(getHandle(), p.getX(), p.getY());
624
* Determines whether the point specified by (x, y) lies inside
625
* the area bounded by the current path, excluding the path's
629
* x coordinate of the point to test
631
* y coordinate of the point to test
633
public boolean inFill(double x, double y) {
634
return cairo_in_fill(getHandle(), x, y);
637
public boolean inFill(Point p) {
638
return cairo_in_fill(getHandle(), p.getX(), p.getY());
641
public Rectangle strokeExtents() {
642
double[] x1 = new double[1];
643
double[] y1 = new double[1];
644
double[] x2 = new double[1];
645
double[] y2 = new double[1];
646
cairo_stroke_extents(getHandle(), x1, y1, x2, y2);
647
return new Rectangle(x1[0], y1[0], x2[0], y2[0]);
650
public Rectangle fillExtents() {
651
double[] x1 = new double[1];
652
double[] y1 = new double[1];
653
double[] x2 = new double[1];
654
double[] y2 = new double[1];
655
cairo_fill_extents(getHandle(), x1, y1, x2, y2);
656
return new Rectangle(x1[0], y1[0], x2[0], y2[0]);
660
* Reset the current clip region to its original, unrestricted state. That
661
* is, set the clip region to an infinitely large shape containing the
662
* target surface. Equivalently, if infinity is too hard to grasp, one can
663
* imagine the clip region being reset to the exact bounds of the target
666
* Note that code meant to be reusable should not call resetClip() as it
667
* will cause results unexpected by higher-level code which calls clip().
668
* Consider using save() and restore() around clip() as a more robust means
669
* of temporarily restricting the clip region.
671
public void resetClip() {
672
cairo_reset_clip(getHandle());
676
* Establishes a new clip region by intersecting the current clip region
677
* with the current path as it would be filled by fill() and according to
678
* the current fill rule (see setFillRule()).
680
* After clip, the current path will be cleared from the cairo context.
682
* The current clip region affects all drawing operations by effectively
683
* masking out any changes to the surface that are outside the current clip
686
* Calling clip() can only make the clip region smaller, never larger. But
687
* the current clip is part of the graphics state, so a tempoarary
688
* restriction of the clip region can be achieved by calling clip() within a
689
* save()/restore() pair. The only other means of increasing the size of the
690
* clip region is resetClip().
693
cairo_clip(getHandle());
697
* Establishes a new clip region by intersecting the current clip region
698
* with the current path as it would be filled by fill() and according to
699
* the current fill rule (see setFillRule()).
701
* Unlike clip(), clipPreserve preserves the path within the cairo context.
703
* The current clip region affects all drawing operations by effectively
704
* masking out any changes to the surface that are outside the current clip
707
* Calling clip() can only make the clip region smaller, never larger. But
708
* the current clip is part of the graphics state, so a tempoarary
709
* restriction of the clip region can be achieved by calling clip() within a
710
* save()/restore() pair. The only other means of increasing the size of the
711
* clip region is resetClip().
713
public void clipPreserve() {
714
cairo_clip_preserve(getHandle());
718
* Selects a family and style of font from a simplified description as a
719
* family name, slant and weight. This method is meant to be used only for
720
* applications with simple font needs: Cairo doesn't provide for operations
721
* such as listing all available fonts on the system, and it is expected
722
* that most applications will need to use a more comprehensive font
723
* handling and text layout library in addition to Cairo.
732
public void selectFontFace(String family, FontSlant slant, FontWeight weight) {
733
cairo_select_font_face(getHandle(), family, slant.getValue(), weight
738
* Sets the current font matrix to a scale by a factor of size, replacing
739
* any font matrix previously set with cairo_setFontSize() or
740
* setFontMatrix(). This results in a font size of size user space units.
741
* (More precisely, this matrix will result in the font's em-square being a
742
* size by size square in user space.)
745
* the scaling factor.
747
public void setFontSize(double scale) {
748
cairo_set_font_size(getHandle(), scale);
752
* Sets the current font matrix to matrix. The font matrix gives a
753
* transformation from the design space of the font (in this space, the
754
* em-square is 1 unit by 1 unit) to user space. Normally, a simple scale is
755
* used (see setFontSize()), but a more complex font matrix can be used to
756
* shear the font or stretch it unequally along the two axes
759
* transformation matrix.
761
public void setFontMatrix(Matrix matrix) {
762
cairo_set_font_matrix(getHandle(), matrix.getHandle());
766
* Gets the current font matrix. See setFontMatrix()
768
* @return the current font matrix
770
public Matrix getFontMatrix() {
771
return new Matrix(cairo_get_font_matrix(getHandle()));
775
* Draws the given text on the screen.
778
* String to draw on the screen.
780
public void showText(String text) {
781
cairo_show_text(getHandle(), text);
784
public void showGlyphs(Glyph[] glyphs) {
785
if (null == glyphs || glyphs.length < 1)
787
Handle[] hndls = new Handle[glyphs.length];
788
for (int i = 0; i < glyphs.length; i++)
789
hndls[i] = glyphs[i].getHandle();
790
cairo_show_glyphs(getHandle(), hndls);
794
* Gets the current font face.
796
public FontFace getFontFace() {
797
return new FontFace(cairo_get_font_face(getHandle()));
801
* Gets the font extents for the currently selected font.
803
public FontExtents fontExtents() {
804
Handle hndl = Struct.getNullHandle();
805
cairo_font_extents(getHandle(), hndl);
806
return new FontExtents(hndl);
810
* Replaces the current FontFace object in the context with fontFace. The
811
* replaced font face in the context will be destroyed if there are no other
816
public void setFontFace(FontFace fontFace) {
817
cairo_set_font_face(getHandle(), fontFace.getHandle());
821
* Gets the extents for a string of text. The extents describe a user-space
822
* rectangle that encloses the "inked" portion of the text, (as it would be
823
* drawn by showText). Additionally, the xAdvance and yAdvance values
824
* indicate the amount by which the current point would be advanced by
827
* Note that whitespace characters do not directly contribute to the size of
828
* the rectangle (extents.width and extents.height). They do contribute
829
* indirectly by changing the position of non-whitespace characters. In
830
* particular, trailing whitespace characters are likely to not affect the
831
* size of the rectangle, though they will affect the xAdvance and yAdvance
834
public TextExtents textExtents(String text) {
835
Handle hndl = Struct.getNullHandle();
836
cairo_text_extents(getHandle(), text, hndl);
837
return new TextExtents(hndl);
841
* Gets the extents for an array of glyphs. The extents describe a
842
* user-space rectangle that encloses the "inked" portion of the glyphs, (as
843
* they would be drawn by showGlyphs). Additionally, the xAdvance and
844
* yAdvance values indicate the amount by which the current point would be
845
* advanced by cairo_show_glyphs.
847
* Note that whitespace glyphs do not contribute to the size of the
848
* rectangle (extents.width and extents.height).
850
public TextExtents glyphExtents(Glyph[] glyphs) {
851
Handle hndl = Struct.getNullHandle();
852
Handle[] gHndls = new Handle[glyphs.length];
853
for (int i = 0; i < glyphs.length; i++)
854
gHndls[i] = glyphs[i].getHandle();
855
cairo_glyph_extents(getHandle(), gHndls, hndl);
856
return new TextExtents(hndl);
859
public void textPath(String text) {
860
cairo_text_path(getHandle(), text);
863
public void glyphPath(Glyph[] glyphs) {
864
Handle[] gHndls = new Handle[glyphs.length];
865
for (int i = 0; i < glyphs.length; i++)
866
gHndls[i] = glyphs[i].getHandle();
867
cairo_glyph_path(getHandle(), gHndls);
871
* Returns the current surface operator
873
* @return The surface operator.
875
public Operator getOperator() {
876
return Operator.intern(cairo_get_operator(getHandle()));
880
* Gets the current source pattern for this object.
882
public Pattern getSource() {
883
Handle hndl = cairo_get_source(getHandle());
884
return new Pattern(hndl);
888
* Returns the tesselation tolerance of the current state.
890
* @return tesselation tolerance
892
public double getTolerance() {
893
return cairo_get_tolerance(getHandle());
897
* Returns the current point of the surface.
899
* The current point is returned in the user-space coordinate system. If
900
* there is no defined current point then Point will be set to (0,0)
902
* @return Current point for drawing
904
public Point getCurrentPoint() {
905
double[] x = new double[1];
906
double[] y = new double[1];
907
cairo_get_current_point(getHandle(), x, y);
908
return new Point(x[0], y[0]);
912
* Gets the current fill rule, as set by setFillRule().
914
public FillRule getFillRule() {
915
return FillRule.intern(cairo_get_fill_rule(getHandle()));
919
* Returns the stroke line width.
921
* @return The stroke line width
923
public double getLineWidth() {
924
return cairo_get_line_width(getHandle());
928
* Returns current linecap style.
930
* @return The line cap style
932
public LineCap getLineCap() {
933
return LineCap.intern(cairo_get_line_cap(getHandle()));
937
* Return current line join style.
939
* @return Line join style
941
public LineJoin getLineJoin() {
942
return LineJoin.intern(cairo_get_line_join(getHandle()));
946
* Returns the miter limit for miter style line joins
948
* @return The miter limit
950
public double getMiterLimit() {
951
return cairo_get_miter_limit(getHandle());
955
* Returns the current transformation matrix
957
* @return the current transformation matrix
959
public Matrix getMatrix() {
960
Handle handle = cairo_get_matrix(getHandle());
961
return new Matrix(handle);
965
* Gets the target surface for the cairo context as passed to the
968
* @return the target surface
970
public Surface getTarget() {
971
return new Surface(cairo_get_target(getHandle()));
974
public Status status() {
975
return Status.intern(cairo_status(getHandle()));
978
public void setAntialias(Antialias antialias) {
979
cairo_set_antialias(getHandle(), antialias.getValue());
982
public Antialias getAntialias() {
983
return Antialias.intern(cairo_get_antialias(getHandle()));
986
public void setFontOptions(FontOptions fontOptions) {
987
cairo_set_font_options(getHandle(), fontOptions.getHandle());
990
public FontOptions getFontOptions() {
991
return new FontOptions(cairo_get_font_options(getHandle()));
994
/** Constant use for drawing ellipse */
995
private static final double SVG_ARC_MAGIC = 0.5522847498;
998
* Creates an ellipse path.
1001
* X co-ordinate of the center of ellipse
1003
* Y co-ordinate of the center of ellipse
1005
* X radius of the ellipse
1007
* Y radius of the ellipse
1009
public void ellipse(double cx, double cy, double rx, double ry) {
1011
/* approximate an ellipse using 4 bezier curves */
1012
cairo_new_path(getHandle());
1013
cairo_move_to(getHandle(), cx + rx, cy);
1014
cairo_curve_to(getHandle(), cx + rx, cy + ry * SVG_ARC_MAGIC, cx + rx
1015
* SVG_ARC_MAGIC, cy + ry, cx, cy + ry);
1016
cairo_curve_to(getHandle(), cx - rx * SVG_ARC_MAGIC, cy + ry, cx - rx,
1017
cy + ry * SVG_ARC_MAGIC, cx - rx, cy);
1018
cairo_curve_to(getHandle(), cx - rx, cy - ry * SVG_ARC_MAGIC, cx - rx
1019
* SVG_ARC_MAGIC, cy - ry, cx, cy - ry);
1020
cairo_curve_to(getHandle(), cx + rx * SVG_ARC_MAGIC, cy - ry, cx + rx,
1021
cy - ry * SVG_ARC_MAGIC, cx + rx, cy);
1022
cairo_close_path(getHandle());
1028
native static final private Handle cairo_create(Handle surface);
1030
native static final private void cairo_destroy(Handle obj);
1032
native static final private void cairo_save(Handle obj);
1034
native static final private void cairo_restore(Handle obj);
1036
native static final private void cairo_set_operator(Handle obj, int operator);
1038
native static final private void cairo_set_source(Handle obj, Handle pattern);
1040
native static final private void cairo_set_source_rgb(Handle obj,
1041
double red, double green, double blue);
1043
native static final private void cairo_set_source_rgba(Handle object,
1044
double red, double green, double glue, double alpha);
1046
native static final private void cairo_set_source_surface(Handle object,
1047
Handle surface, double x, double y);
1049
native static final private void cairo_set_tolerance(Handle obj,
1052
native static final private void cairo_set_fill_rule(Handle obj,
1055
native static final private void cairo_set_line_width(Handle obj,
1058
native static final private void cairo_set_line_cap(Handle obj, int lineCap);
1060
native static final private void cairo_set_line_join(Handle obj,
1063
native static final private void cairo_set_dash(Handle obj,
1064
double[] dashes, double offset);
1066
native static final private void cairo_set_miter_limit(Handle obj,
1069
native static final private void cairo_translate(Handle obj, double tx,
1072
native static final private void cairo_scale(Handle obj, double sx,
1075
native static final private void cairo_rotate(Handle obj, double angle);
1077
native static final private void cairo_transform(Handle obj, Handle matrix);
1079
native static final private void cairo_set_matrix(Handle obj, Handle matrix);
1081
native static final private void cairo_identity_matrix(Handle obj);
1083
native static final private void cairo_user_to_device(Handle obj,
1084
double[] x, double[] y);
1086
native static final private void cairo_user_to_device_distance(Handle obj,
1087
double[] dx, double[] dy);
1089
native static final private void cairo_device_to_user(Handle obj,
1090
double[] x, double[] y);
1092
native static final private void cairo_device_to_user_distance(Handle obj,
1093
double[] dx, double[] dy);
1095
native static final private void cairo_new_path(Handle obj);
1097
native static final private void cairo_move_to(Handle obj, double x,
1100
native static final private void cairo_line_to(Handle obj, double x,
1103
native static final private void cairo_curve_to(Handle obj, double x1,
1104
double y1, double x2, double y2, double x3, double y3);
1106
native static final private void cairo_arc(Handle obj, double xc,
1107
double yc, double radius, double angle1, double angle2);
1109
native static final private void cairo_arc_negative(Handle obj, double xc,
1110
double yc, double radius, double angle1, double angle2);
1112
native static final private void cairo_rel_move_to(Handle obj, double dx,
1115
native static final private void cairo_rel_line_to(Handle obj, double dx,
1118
native static final private void cairo_rel_curve_to(Handle obj, double dx1,
1119
double dy1, double dx2, double dy2, double dx3, double dy3);
1121
native static final private void cairo_rectangle(Handle obj, double x,
1122
double y, double width, double height);
1124
native static final private void cairo_close_path(Handle obj);
1126
native static final private void cairo_paint(Handle obj);
1128
native static final private void cairo_paint_with_alpha(Handle obj,
1131
native static final private void cairo_mask(Handle obj, Handle pattern);
1133
native static final private void cairo_mask_surface(Handle obj,
1134
Handle surface, double sx, double sy);
1136
native static final private void cairo_stroke(Handle obj);
1138
native static final private void cairo_stroke_preserve(Handle obj);
1140
native static final private void cairo_fill(Handle obj);
1142
native static final private void cairo_fill_preserve(Handle obj);
1144
native static final private void cairo_copy_page(Handle obj);
1146
native static final private void cairo_show_page(Handle obj);
1148
native static final private boolean cairo_in_stroke(Handle obj, double x,
1151
native static final private boolean cairo_in_fill(Handle obj, double x,
1154
native static final private void cairo_stroke_extents(Handle obj,
1155
double[] x1, double[] y1, double[] x2, double[] y2);
1157
native static final private void cairo_fill_extents(Handle obj,
1158
double[] x1, double[] y1, double[] x2, double[] y2);
1160
native static final private void cairo_reset_clip(Handle obj);
1162
native static final private void cairo_clip(Handle ojb);
1164
native static final private void cairo_clip_preserve(Handle obj);
1166
native static final private void cairo_select_font_face(Handle obj,
1167
String family, int slant, int weight);
1169
native static final private void cairo_set_font_size(Handle obj,
1172
native static final private void cairo_set_font_matrix(Handle obj,
1175
native static final private Handle cairo_get_font_matrix(Handle obj);
1177
native static final private void cairo_show_text(Handle obj, String utf8);
1179
native static final private void cairo_show_glyphs(Handle obj,
1182
native static final private Handle cairo_get_font_face(Handle obj);
1184
native static final private void cairo_font_extents(Handle obj,
1187
native static final private void cairo_set_font_face(Handle obj, Handle font);
1189
native static final private void cairo_text_extents(Handle obj,
1190
String utf8, Handle extents);
1192
native static final private void cairo_glyph_extents(Handle obj,
1193
Handle[] glyphs, Handle extents);
1195
native static final private void cairo_text_path(Handle obj, String utf8);
1197
native static final private void cairo_glyph_path(Handle obj,
1200
native static final private int cairo_get_operator(Handle obj);
1202
native static final private Handle cairo_get_source(Handle obj);
1204
native static final private double cairo_get_tolerance(Handle obj);
1206
native static final private void cairo_get_current_point(Handle obj,
1207
double[] x, double[] y);
1209
native static final private int cairo_get_fill_rule(Handle obj);
1211
native static final private double cairo_get_line_width(Handle obj);
1213
native static final private int cairo_get_line_cap(Handle obj);
1215
native static final private int cairo_get_line_join(Handle obj);
1217
native static final private double cairo_get_miter_limit(Handle obj);
1219
native static final private Handle cairo_get_matrix(Handle obj);
1221
native static final private Handle cairo_get_target(Handle obj);
1223
native static final private int cairo_status(Handle obj);
1225
native static final private void cairo_set_antialias(Handle obj,
1228
native static final private int cairo_get_antialias(Handle obj);
1230
native static final private void cairo_set_font_options(Handle obj,
1233
native static final private Handle cairo_get_font_options(Handle obj);
1235
// TODO: add the following
1237
// cairo_copy_path (cairo_t *cr);
1240
// cairo_copy_path_flat (cairo_t *cr);
1243
// cairo_append_path (cairo_t *cr,
1244
// cairo_path_t *path);
1247
// cairo_path_destroy (cairo_path_t *path);