diff --git a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm index e5fb88ff1..8792214ad 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm +++ b/src/drivers/Cocoa/Fl_Cocoa_Printer_Driver.mm @@ -44,8 +44,6 @@ typedef OSStatus CFStringRef graphicsContextType, void ** graphicsContext); -extern void fl_quartz_restore_line_style_(CGContextRef gc); - /** Support for printing on the Apple OS X platform */ class Fl_Cocoa_Printer_Driver : public Fl_Paged_Device { @@ -324,7 +322,7 @@ int Fl_Cocoa_Printer_Driver::start_page (void) else CGContextTranslateCTM(gc, margins.top, margins.right + h); CGContextScaleCTM(gc, win_scale_x, - win_scale_y); - fl_quartz_restore_line_style_(gc); + ((Fl_Quartz_Graphics_Driver*)driver())->quartz_restore_line_style(); CGContextSetShouldAntialias(gc, false); CGContextSaveGState(gc); CGContextSaveGState(gc); diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H index b46b94000..94830acc1 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H @@ -49,8 +49,18 @@ protected: XPOINT *p; bool high_resolution_; driver_feature is_printer_; + float quartz_line_width_; + CGLineCap quartz_line_cap_; + CGLineJoin quartz_line_join_; + CGFloat *quartz_line_pattern; + int quartz_line_pattern_size; // protected constructor to ensure only derived classes are allocated Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL), p_size(0), p(NULL) { + quartz_line_width_ = 1.f; + quartz_line_cap_ = kCGLineCapButt; + quartz_line_join_ = kCGLineJoinMiter; + quartz_line_pattern = 0; + quartz_line_pattern_size = 0; high_resolution_ = false; is_printer_ = (driver_feature)0; } @@ -157,6 +167,7 @@ protected: virtual void set_fontname_in_fontdesc(Fl_Fontdesc *f); virtual void descriptor_init(const char* name, Fl_Fontsize Size, Fl_Font_Descriptor *d) {} // end of function group + void quartz_restore_line_style(); }; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 @@ -182,7 +193,6 @@ class Fl_ATSU_Graphics_Driver : public Fl_Quartz_Graphics_Driver { }; #endif -extern float fl_quartz_line_width_; #endif // FL_QUARTZ_GRAPHICS_DRIVER_H diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx index a9583474b..bcf721eed 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_line_style.cxx @@ -31,17 +31,11 @@ extern int fl_line_width_; #include "Fl_Quartz_Graphics_Driver.h" -float fl_quartz_line_width_ = 1.0f; -static /*enum*/ CGLineCap fl_quartz_line_cap_ = kCGLineCapButt; -static /*enum*/ CGLineJoin fl_quartz_line_join_ = kCGLineJoinMiter; -static CGFloat *fl_quartz_line_pattern = 0; -static int fl_quartz_line_pattern_size = 0; - -void fl_quartz_restore_line_style_(CGContextRef gc) { - CGContextSetLineWidth(gc, fl_quartz_line_width_); - CGContextSetLineCap(gc, fl_quartz_line_cap_); - CGContextSetLineJoin(gc, fl_quartz_line_join_); - CGContextSetLineDash(gc, 0, fl_quartz_line_pattern, fl_quartz_line_pattern_size); +void Fl_Quartz_Graphics_Driver::quartz_restore_line_style() { + CGContextSetLineWidth(gc_, quartz_line_width_); + CGContextSetLineCap(gc_, quartz_line_cap_); + CGContextSetLineJoin(gc_, quartz_line_join_); + CGContextSetLineDash(gc_, 0, quartz_line_pattern, quartz_line_pattern_size); } void Fl_Quartz_Graphics_Driver::line_style(int style, int width, char* dashes) { @@ -50,27 +44,27 @@ void Fl_Quartz_Graphics_Driver::line_style(int style, int width, char* dashes) { if (width == 0) fl_line_width_ = 1; else fl_line_width_ = width>0 ? width : -width; - static /*enum*/ CGLineCap Cap[4] = { kCGLineCapButt, kCGLineCapButt, + static CGLineCap Cap[4] = { kCGLineCapButt, kCGLineCapButt, kCGLineCapRound, kCGLineCapSquare }; - static /*enum*/ CGLineJoin Join[4] = { kCGLineJoinMiter, kCGLineJoinMiter, + static CGLineJoin Join[4] = { kCGLineJoinMiter, kCGLineJoinMiter, kCGLineJoinRound, kCGLineJoinBevel }; if (width<1) width = 1; - fl_quartz_line_width_ = (float)width; - fl_quartz_line_cap_ = Cap[(style>>8)&3]; + quartz_line_width_ = (float)width; + quartz_line_cap_ = Cap[(style>>8)&3]; // when printing kCGLineCapSquare seems better for solid lines if ( Fl_Surface_Device::surface() != Fl_Display_Device::display_device() && style == FL_SOLID && dashes == NULL ) { - fl_quartz_line_cap_ = kCGLineCapSquare; + quartz_line_cap_ = kCGLineCapSquare; } - fl_quartz_line_join_ = Join[(style>>12)&3]; + quartz_line_join_ = Join[(style>>12)&3]; char *d = dashes; static CGFloat pattern[16]; if (d && *d) { CGFloat *p = pattern; while (*d) { *p++ = (float)*d++; } - fl_quartz_line_pattern = pattern; - fl_quartz_line_pattern_size = d-dashes; + quartz_line_pattern = pattern; + quartz_line_pattern_size = d-dashes; } else if (style & 0xff) { char dash, dot, gap; // adjust lengths to account for cap: @@ -89,13 +83,13 @@ void Fl_Quartz_Graphics_Driver::line_style(int style, int width, char* dashes) { case FL_DASHDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; break; case FL_DASHDOTDOT: *p++ = dash; *p++ = gap; *p++ = dot; *p++ = gap; *p++ = dot; *p++ = gap; break; } - fl_quartz_line_pattern_size = p-pattern; - fl_quartz_line_pattern = pattern; + quartz_line_pattern_size = p-pattern; + quartz_line_pattern = pattern; } else { - fl_quartz_line_pattern = 0; - fl_quartz_line_pattern_size = 0; + quartz_line_pattern = 0; + quartz_line_pattern_size = 0; } - fl_quartz_restore_line_style_((CGContextRef)gc()); + quartz_restore_line_style(); } #endif // FL_CFG_GFX_QUARTZ diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx index caa5dc64c..a15d8e2f3 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx @@ -33,9 +33,6 @@ #include "Fl_Quartz_Graphics_Driver.h" -extern float fl_quartz_line_width_; - - // --- line and polygon drawing with integer coordinates void Fl_Quartz_Graphics_Driver::point(int x, int y) { @@ -44,10 +41,10 @@ void Fl_Quartz_Graphics_Driver::point(int x, int y) { void Fl_Quartz_Graphics_Driver::rect(int x, int y, int w, int h) { if (w<=0 || h<=0) return; - if ( (!has_feature(PRINTER)) && fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if ( (!has_feature(PRINTER)) && quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGRect rect = CGRectMake(x, y, w-1, h-1); CGContextStrokeRect(gc_, rect); - if ( (!has_feature(PRINTER)) && fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if ( (!has_feature(PRINTER)) && quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::rectf(int x, int y, int w, int h) { @@ -57,24 +54,24 @@ void Fl_Quartz_Graphics_Driver::rectf(int x, int y, int w, int h) { } void Fl_Quartz_Graphics_Driver::line(int x, int y, int x1, int y1) { - if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x1, y1); CGContextStrokePath(gc_); - if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::line(int x, int y, int x1, int y1, int x2, int y2) { - if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x1, y1); CGContextAddLineToPoint(gc_, x2, y2); CGContextStrokePath(gc_); - if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1) { - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x1, y); CGContextStrokePath(gc_); @@ -83,76 +80,76 @@ void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1) { (or one pixel) too short at both ends. This is corrected by filling at both ends rectangles of size one unit by line-width. */ - CGContextFillRect(gc_, CGRectMake(x-0.5 , y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); - CGContextFillRect(gc_, CGRectMake(x1-0.5 , y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); + CGContextFillRect(gc_, CGRectMake(x-0.5 , y - quartz_line_width_/2, 1 , quartz_line_width_)); + CGContextFillRect(gc_, CGRectMake(x1-0.5 , y - quartz_line_width_/2, 1 , quartz_line_width_)); } - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1, int y2) { - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x1, y); CGContextAddLineToPoint(gc_, x1, y2); CGContextStrokePath(gc_); if (high_resolution()) { - CGContextFillRect(gc_, CGRectMake(x-0.5, y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); - CGContextFillRect(gc_, CGRectMake(x1 - fl_quartz_line_width_/2, y2-0.5, fl_quartz_line_width_, 1)); + CGContextFillRect(gc_, CGRectMake(x-0.5, y - quartz_line_width_/2, 1 , quartz_line_width_)); + CGContextFillRect(gc_, CGRectMake(x1 - quartz_line_width_/2, y2-0.5, quartz_line_width_, 1)); } - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::xyline(int x, int y, int x1, int y2, int x3) { - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x1, y); CGContextAddLineToPoint(gc_, x1, y2); CGContextAddLineToPoint(gc_, x3, y2); CGContextStrokePath(gc_); if (high_resolution()) { - CGContextFillRect(gc_, CGRectMake(x-0.5, y - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); - CGContextFillRect(gc_, CGRectMake(x3-0.5, y2 - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); + CGContextFillRect(gc_, CGRectMake(x-0.5, y - quartz_line_width_/2, 1 , quartz_line_width_)); + CGContextFillRect(gc_, CGRectMake(x3-0.5, y2 - quartz_line_width_/2, 1 , quartz_line_width_)); } - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::yxline(int x, int y, int y1) { - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x, y1); CGContextStrokePath(gc_); if (high_resolution()) { - CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1)); - CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y1-0.5, fl_quartz_line_width_, 1)); + CGContextFillRect(gc_, CGRectMake(x - quartz_line_width_/2, y-0.5, quartz_line_width_, 1)); + CGContextFillRect(gc_, CGRectMake(x - quartz_line_width_/2, y1-0.5, quartz_line_width_, 1)); } - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::yxline(int x, int y, int y1, int x2) { - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x, y1); CGContextAddLineToPoint(gc_, x2, y1); CGContextStrokePath(gc_); if (high_resolution()) { - CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1)); - CGContextFillRect(gc_, CGRectMake(x2-0.5, y1 - fl_quartz_line_width_/2, 1 , fl_quartz_line_width_)); + CGContextFillRect(gc_, CGRectMake(x - quartz_line_width_/2, y-0.5, quartz_line_width_, 1)); + CGContextFillRect(gc_, CGRectMake(x2-0.5, y1 - quartz_line_width_/2, 1 , quartz_line_width_)); } - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::yxline(int x, int y, int y1, int x2, int y3) { - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); CGContextAddLineToPoint(gc_, x, y1); CGContextAddLineToPoint(gc_, x2, y1); CGContextAddLineToPoint(gc_, x2, y3); CGContextStrokePath(gc_); if (high_resolution()) { - CGContextFillRect(gc_, CGRectMake(x - fl_quartz_line_width_/2, y-0.5, fl_quartz_line_width_, 1)); - CGContextFillRect(gc_, CGRectMake(x2 - fl_quartz_line_width_/2, y3-0.5, fl_quartz_line_width_, 1)); + CGContextFillRect(gc_, CGRectMake(x - quartz_line_width_/2, y-0.5, quartz_line_width_, 1)); + CGContextFillRect(gc_, CGRectMake(x2 - quartz_line_width_/2, y3-0.5, quartz_line_width_, 1)); } - if (has_feature(PRINTER) || fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); + if (has_feature(PRINTER) || quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::loop(int x, int y, int x1, int y1, int x2, int y2) { @@ -291,9 +288,6 @@ void Fl_Quartz_Graphics_Driver::pop_clip() { restore_clip(); } -// helper function to manage the current CGContext gc -extern void fl_quartz_restore_line_style_(CGContextRef gc); - void Fl_Quartz_Graphics_Driver::restore_clip() { fl_clip_state_number++; Fl_Region r = rstack[rstackptr]; @@ -316,7 +310,7 @@ void Fl_Quartz_Graphics_Driver::restore_clip() { CGContextScaleCTM(gc_, 1.0f, -1.0f); // now 0,0 is top-left point of the context } color(color()); - fl_quartz_restore_line_style_(gc_); + quartz_restore_line_style(); if (r) { //apply program clip CGContextClipToRects(gc_, r->rects, r->count); } diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx index 0de553c87..33e307fa9 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_vertex.cxx @@ -41,13 +41,13 @@ void Fl_Quartz_Graphics_Driver::vertex(double x,double y) { } void Fl_Quartz_Graphics_Driver::end_points() { - if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); + if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, true); for (int i=0; i 1.5f) CGContextSetShouldAntialias(gc_, false); + if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } void Fl_Quartz_Graphics_Driver::end_line() {