Re: Drawing same text and graphics in different CGContextRef
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1695401073; bh=6wG0qMaGJOLNlL0B2LS90T4e5q16mhnQm7HN+mp7ocs=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=JmlNPZLcmASTaOmGYel6Lw4Vqz3VDSAxpTgiloNFmATvbpnll4RIzJIbMuEJURNLu rR+LCjLWojH4BFL5hxGc2zxyGzQZbZlkxEAgECtet6qJ80J+4itPr+YLmlXcLR7yUs +NqtfdXcQeHEtY5DF0sdRiOPy6N5oseuFu1PfmKC6HoksXmXwCHjRx3saOprYAsvx0 8dQnmom7vpHUxwoA/3jWq79ZnsIqcHkGgQKEluKGdqC85Mb/PhpM1GyiHjO/4QbX8Q 7eWKMuRB9B6Fp9hOL8eHLXpm+DgxZ+9rYEV6H4u+UBiymfoMgijXgiJSNMtd+N+KaM 26HPiULJ9ZuwA== Hi David, Trying to understand the mechanism you suggest ( I am not familiar with the concept of context pushing - poping :(I ) NSGraphicsContext <apple-reference-documentation://hcmXlh9fv1> * newcontext= [NSGraphicsContex <apple-reference-documentation://hcmXlh9fv1> graphicsContextWithCGContext:theprintContext flipped:YES] // theprintContext obtained from PMSessionGetCGGraphicsContext(printSession, &theprintContext) [newcontext saveGraphicsState]; //Saves the current graphics state and creates a new graphics state on the top of the stack. myDrawMethod( newcontext.CGContext) [NSGraphicsContext <apple-reference-documentation://hcmXlh9fv1> restoreGraphicsState;] Is this correct ? All the best JP a graphic context created by myself ( hence not the supplied on by the printing framework )
Le 22 sept. 2023 à 17:59, David Duncan <david.duncan@apple.com> a écrit :
On Sep 22, 2023, at 11:12 AM, JPH via Cocoa-dev <cocoa-dev@lists.apple.com> wrote:
I am facing the following problems in drawing text and graphics in CGContextRef of an NSview and Printing framework:
1) drawing text using: [finalString drawInRect:textBox withAttributes:attributes]; Works nicely in my sub-classed NSViews in a CGContextRef obtained in the drawRect : method with CGContextRef viewCtx= [[NSGraphicsContext currentContext] CGContext]; But draws nothing in a print context obtained PMSessionGetCGGraphicsContext(printSession, &ctx); //( geometry is perfectly previewed,Pdf’ed and printed except texts .. )
2) filling a bezier path with a pattern Color
NSImage* nsPatImage= [[NSImage alloc] initWithCGImage:cgPatImage size:NSZeroSize]; NSColor* patternColor= [NSColor colorWithPatternImage:nsPatImage]; [patternColor setFill]; [bezierPath fill];
Works like a charm in the graphic context of NSView and print nothing in a print context.
I suspect this has something to do with the notion of « Current context » , as the context in NSView is explicitly the « currentContext » But not sure if the printing context is the « current one » in the usual print sequence ;
Correct. The current context is an AppKit concept, and you are working below AppKit in this code sequence – so you need to ensure the context is made current yourself. So you need to create an NSGraphicsContext, push it, and pop it, around your drawing code that relies on the current context. Since you pass the CGContext to myDrawMethod:, you could do this inside that method.
err= PMSessionBeginPageNoDialog(printSession, format ) ctx = PMSessionGetCGGraphicsContext(printSession, &ctx) [myDrawMethode: ctx] // [finalString drawInRect:textBox withAttributes:attributes]; draws nothing in the printing context PMSessionEndPageNoDialog(printSession);
I would appreciate any advice or suggestion regarding these points King regards JP
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
This email sent to david.duncan@apple.com
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
JPH via Cocoa-dev