summaryrefslogtreecommitdiff
path: root/frontends/cocoa/plotter.m
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/cocoa/plotter.m')
-rw-r--r--frontends/cocoa/plotter.m66
1 files changed, 31 insertions, 35 deletions
diff --git a/frontends/cocoa/plotter.m b/frontends/cocoa/plotter.m
index dea3245bb..e4659ef80 100644
--- a/frontends/cocoa/plotter.m
+++ b/frontends/cocoa/plotter.m
@@ -74,7 +74,7 @@ static void cocoa_plot_path_set_stroke_pattern(NSBezierPath *path,const plot_sty
[path setLineWidth: cocoa_px_to_pt( pstyle->stroke_width > 0 ? pstyle->stroke_width : 1 )];
}
-static bool plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle)
+static nserror plot_line(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *line)
{
if (pstyle->stroke_type == PLOT_OP_TYPE_NONE) return true;
@@ -82,12 +82,12 @@ static bool plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle
[NSBezierPath clipRect: cocoa_plot_clip_rect];
NSBezierPath *path = [NSBezierPath bezierPath];
- [path moveToPoint: cocoa_point( x0, y0 )];
- [path lineToPoint: cocoa_point( x1, y1 )];
+ [path moveToPoint: cocoa_point( line->x0, line->y0 )];
+ [path lineToPoint: cocoa_point( line->x1, line->y1 )];
cocoa_plot_path_set_stroke_pattern( path, pstyle );
const bool horizontal = y0 == y1;
- const bool vertical = x0 == x1;
+ const bool vertical = line->x0 == line->x1;
const bool oddThickness = pstyle->stroke_width != 0 ? (pstyle->stroke_width % 2) != 0 : true;
if (oddThickness) cocoa_center_pixel( !horizontal, !vertical );
@@ -97,20 +97,19 @@ static bool plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle
[NSGraphicsContext restoreGraphicsState];
- return true;
+ return NSERROR_OK;
}
-static bool plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *pstyle)
+static nserror plot_rectangle(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *r)
{
- NSRect rect = cocoa_rect( x0, y0, x1, y1 );
+ NSRect rect = cocoa_rect( r->x0, r->y0, r->x1, r->y1 );
NSBezierPath *path = [NSBezierPath bezierPathWithRect: rect];
cocoa_plot_render_path( path, pstyle );
- return true;
+ return NSERROR_OK;
}
-static bool plot_text(int x, int y, const char *text, size_t length,
- const plot_font_style_t *fstyle)
+static nserror plot_text(const struct redraw_context *ctx, const plot_font_style_t *fstyle, int x, int y, const char *text, size_t length)
{
[NSGraphicsContext saveGraphicsState];
[NSBezierPath clipRect: cocoa_plot_clip_rect];
@@ -119,7 +118,7 @@ static bool plot_text(int x, int y, const char *text, size_t length,
[NSGraphicsContext restoreGraphicsState];
- return true;
+ return NSERROR_OK;
}
void cocoa_set_clip( NSRect rect )
@@ -127,10 +126,10 @@ void cocoa_set_clip( NSRect rect )
cocoa_plot_clip_rect = rect;
}
-static bool plot_clip(const struct rect *clip)
+static nserror plot_clip(const struct redraw_context *ctx, const struct rect *clip)
{
cocoa_plot_clip_rect = cocoa_rect( clip->x0, clip->y0, clip->x1, clip->y1 );
- return true;
+ return NSERROR_OK;
}
void cocoa_plot_render_path(NSBezierPath *path,const plot_style_t *pstyle)
@@ -156,7 +155,7 @@ void cocoa_plot_render_path(NSBezierPath *path,const plot_style_t *pstyle)
[NSGraphicsContext restoreGraphicsState];
}
-static bool plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle)
+static nserror plot_arc(const struct redraw_context *ctx, const plot_style_t *pstyle, int x, int y, int radius, int angle1, int angle2)
{
NSBezierPath *path = [NSBezierPath bezierPath];
[path appendBezierPathWithArcWithCenter: NSMakePoint( x, y ) radius: radius
@@ -165,22 +164,22 @@ static bool plot_arc(int x, int y, int radius, int angle1, int angle2, const plo
cocoa_plot_render_path( path, pstyle);
- return true;
+ return NSERROR_OK;
}
-static bool plot_disc(int x, int y, int radius, const plot_style_t *pstyle)
+static nserror plot_disc(const struct redraw_context *ctx, const plot_style_t *pstyle, int x, int y, int radius)
{
NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:
NSMakeRect( x - radius, y-radius, 2*radius, 2*radius )];
cocoa_plot_render_path( path, pstyle );
- return true;
+ return NSERROR_OK;
}
-static bool plot_polygon(const int *p, unsigned int n, const plot_style_t *pstyle)
+static nserror plot_polygon(const struct redraw_context *ctx, const plot_style_t *pstyle, const int *p, unsigned int n)
{
- if (n <= 1) return true;
+ if (n <= 1) return NSERROR_OK;
NSBezierPath *path = [NSBezierPath bezierPath];
[path moveToPoint: cocoa_point( p[0], p[1] )];
@@ -191,23 +190,22 @@ static bool plot_polygon(const int *p, unsigned int n, const plot_style_t *pstyl
cocoa_plot_render_path( path, pstyle );
- return true;
+ return NSERROR_OK;
}
/* complex path (for SVG) */
-static bool plot_path(const float *p, unsigned int n, colour fill, float width,
- colour c, const float transform[6])
+static nserror plot_path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, float width, const float transform[6])
{
- if (n == 0) return true;
+ if (n == 0) return NSERROR_OK;
if (*p != PLOTTER_PATH_MOVE) {
LOG("Path does not start with move");
- return false;
+ return NSERROR_INVALID;
}
NSBezierPath *path = [NSBezierPath bezierPath];
-#define NEXT_POINT() NSMakePoint( *p++, *p++ )
+#define NEXT_POINT() ({ const float *c = p; p += 2; NSMakePoint( c[0], c[1] ); })
while (n--) {
switch ((int)*p++) {
@@ -237,7 +235,7 @@ static bool plot_path(const float *p, unsigned int n, colour fill, float width,
default:
LOG("Invalid path");
- return false;
+ return NSERROR_INVALID;
}
}
@@ -253,14 +251,14 @@ static bool plot_path(const float *p, unsigned int n, colour fill, float width,
CGContextConcatCTM( context, CGAffineTransformMake( transform[0], transform[1], transform[2],
transform[3], transform[4], transform[5] ) );
- if (fill != NS_TRANSPARENT) {
- [cocoa_convert_colour( fill ) setFill];
+ if (pstyle->fill_colour != NS_TRANSPARENT) {
+ [cocoa_convert_colour(pstyle->fill_colour) setFill];
[path fill];
}
- if (c != NS_TRANSPARENT) {
+ if (pstyle->stroke_colour != NS_TRANSPARENT) {
cocoa_center_pixel( true, true );
- [cocoa_convert_colour( c ) set];
+ [cocoa_convert_colour( pstyle->stroke_colour ) set];
[path stroke];
}
@@ -270,9 +268,7 @@ static bool plot_path(const float *p, unsigned int n, colour fill, float width,
}
/* Image */
-static bool plot_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bitmap_flags_t flags)
+static nserror plot_bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
{
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState( context );
@@ -294,7 +290,7 @@ static bool plot_bitmap(int x, int y, int width, int height,
CGContextRestoreGState( context );
- return true;
+ return NSERROR_OK;
}
const struct plotter_table cocoa_plotters = {
@@ -321,7 +317,7 @@ static CGFloat cocoa_half_pixel;
void cocoa_update_scale_factor( void )
{
- const CGFloat scale = [[NSScreen mainScreen] userSpaceScaleFactor];
+ const CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];
cocoa_scale_factor = scale == 1.0 ? 1.0 : 1.0 / scale;
cocoa_half_pixel = 0.5 * cocoa_scale_factor;
browser_set_dpi( points_per_inch * scale );