Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text not drawing on OS X 10.11 (El Capitan) #210

Closed
corysullivan opened this issue Jul 20, 2015 · 15 comments
Closed

Text not drawing on OS X 10.11 (El Capitan) #210

corysullivan opened this issue Jul 20, 2015 · 15 comments
Assignees
Milestone

Comments

@corysullivan
Copy link

I just installed the latest Beta for 10.11 and noticed that the text for all the core-plot graphs aren't appearing . Initially I though this may be related to issue #167 , but my app (including dependencies) do not use the stylemask

NSFullSizeContentViewWindowMask

Any thoughts on what else could be causing this? Has anyone else tested 10.11? I'm currently using coreplot 1.6

Thanks

@eskroch
Copy link
Member

eskroch commented Jul 21, 2015

I don't have access to 10.11 for testing yet. Any troubleshooting you can do would be a big help in fixing this.

@corysullivan
Copy link
Author

Sure I will see what I can come up with.

@kepowell
Copy link

I am having the same problem with text on El Capitan. I haven't had a chance to debug the code but an observation that might give some ideas. When running the CPTTestApp the vertical zoom causes the tick numbers to appear and the horizontal zoom out causes the numbers that were outside the previous view to appear. If you then move the graph around any numbers that get moved outside the view disappear until re-zooming. It seems to me that this means that once a text item is masked out for any reason that it is not drawn on refreshes.

@tvlc
Copy link

tvlc commented Sep 14, 2015

Same issues with 10.11 El Capitan GM Candidate. Any progress and fix planned for 1.6 release?

@Dirk-
Copy link

Dirk- commented Sep 14, 2015

I see this too. The version of my app which uses Core Plot 1.6 does not display any text on 10.11 GM (runs fine on 10.10.5), the former version which uses Core Plot 1.5.1 does display the text. I only switched from 1.5.1 to 1.6 the day before yesterday and did not change my plotting code.

Well, I am not exactly using 1.6, I use the master repository with these 24 commits since 1.6.

@eskroch
Copy link
Member

eskroch commented Sep 14, 2015

@tvlc Not for version 1.x, but this issue is the last showstopper holding up release 2.0.

@vrbaski
Copy link

vrbaski commented Sep 15, 2015

The following change works for me:
I set the current graphics context (CPTTextStylePlatformSpecific.m) to a context passed to the drawInRect.
I had to clear it at the end or I was getting exceptions later. I'm not sure if that is a good fix, but it works for me.

-(void)drawInRect:(CGRect)rect withTextStyle:(CPTTextStyle *)style inContext:(CGContextRef)context
{
if ( style.color == nil ) {
return;
}

CGColorRef textColor = style.color.cgColor;

BOOL currenContextIsNIL = NO;
NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
if(currentContext ==nil)
{
    [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]];
    currenContextIsNIL = YES;
}

CGContextSetStrokeColorWithColor(context, textColor);
CGContextSetFillColorWithColor(context, textColor);

CPTPushCGContext(context);

NSFont *theFont    = nil;
NSString *fontName = style.fontName;

if ( fontName ) {
    theFont = [NSFont fontWithName:fontName size:style.fontSize];
}

if ( theFont ) {
    NSColor *foregroundColor                = style.color.nsColor;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment     = (NSTextAlignment)style.textAlignment;
    paragraphStyle.lineBreakMode = style.lineBreakMode;

    NSDictionary *attributes = @{
        NSFontAttributeName: theFont,
        NSForegroundColorAttributeName: foregroundColor,
        NSParagraphStyleAttributeName: paragraphStyle
    };
    [self drawWithRect:NSRectFromCGRect(rect)
               options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine
            attributes:attributes];
}
CPTPopCGContext();

if(currenContextIsNIL)
{
    [NSGraphicsContext setCurrentContext:nil];
}

}

@canpoyrazoglu
Copy link

Having the same here, I think I should go back to old version until this is fixed.

@Dirk-
Copy link

Dirk- commented Sep 17, 2015

@vrbaski: I tried your code suggestion and it partly worked: Without your code change, I get no text at all, with your code change I get text in the legend, graph title, axis title and annotations, but not for axis labels! Strange...

@Dirk-
Copy link

Dirk- commented Sep 17, 2015

I added the same code additions to drawRect of the NSAttributedString category in CPTPlatformSpecificCategories.m and now I get text everywhere I want:

-(void)drawInRect:(CGRect)rect inContext:(CGContextRef)context
{
    // -------- Addition for OS X 10.11
    BOOL currentContextIsNIL = NO;
    if([NSGraphicsContext currentContext] == nil)
    {
        [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]];
        currentContextIsNIL = YES;
    }
    // -------- End Addition

    CPTPushCGContext(context);

    [self drawWithRect:NSRectFromCGRect(rect)
               options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine];

    CPTPopCGContext();

    // -------- Addition for OS X 10.11
    if(currentContextIsNIL)
    {
        [NSGraphicsContext setCurrentContext:nil];
    }
    // -------- End Addition
}

And it still works in OS X 10.10. Great! Thanks, @vrbaski and, of course, thanks @eskroch et al. for Core Plot!

@mike-lischke
Copy link

I wonder why there is this need to check for the current context first. Does it not work on older OS versions otherwise? There is a context passed in and that should be used for drawing, no? In all cases. And resetting the current context always, also seems reasonable. Other drawing code will exactly do the same like here, namely set a proper drawing context first. Maybe I'm missing something here?

@eskroch
Copy link
Member

eskroch commented Sep 18, 2015

The fix needs to be in the CPTPushCGContext() and CPTPopCGContext() functions. This keeps the context handling code in one place making it easier to maintain in the future.

@eskroch eskroch added this to the Release 2.0 milestone Sep 19, 2015
@eskroch eskroch self-assigned this Sep 19, 2015
@eskroch
Copy link
Member

eskroch commented Sep 19, 2015

This should be fixed now on both the master and release-2.0 branches. Please test and let me know if it's working. If so, I'll move forward with the 2.0 release.

@pascalfribi
Copy link
Contributor

Hi,

I have pulled the Xcode 7 branch and tested it on my application. This seems to work fine again! Thanks for this great library! Do you plan to make a small Apple Watch API? :-)

@eskroch
Copy link
Member

eskroch commented Sep 20, 2015

Good to hear. I'm thinking about adding watchOS and tvOS frameworks to release 2.1. :-)

@eskroch eskroch closed this as completed Sep 20, 2015
shinjukunian pushed a commit to shinjukunian/core-plot that referenced this issue Oct 1, 2015
* commit 'fa8aa0994df11b38512afea9eb45edcf7744406a':
  Fixed a bad link in the project readme file.
  Shared the Mac and iOS framework schemes for Carthage compatibility.
  Created separate xcconfig files for debug and release configurations. Removed build settings that override the defaults set in the config files.
  Fixed a memory management error in CPTUtilitiesTests.
  Enabled the standard Core Plot warnings in all of the example apps.
  Fixed a compiler warning in CPTLineStyle.
  Enabled some new compiler and static analyzer warnings.
  Automatically resolve git merge conflicts in Xcode project.pbxproj files.
  Fixed text drawing on OS X 10.11 (El Capitan). Fixed issue core-plot#210.
  Added the iOS framework to the release script.
  Removed the "RunUnitTests" script from the Mac unit test target which is obsolete in Xcode 7.
  Added type annotations to all arrays, sets, and dictionaries.
  Swift 2 updates for the iPhone CPTTestApp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants