discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Vertical text rears its ugly head again...


From: Pete French
Subject: Vertical text rears its ugly head again...
Date: Mon, 16 Jun 2003 21:15:34 +0100

I originally wrote the code below as a test/demo of how to draw vertical
text. I was going to send it to the person who was trying to do
this (it works very nnicely under back-art and also OpenStep).

But I'm posting it here because I am wondering if anyone can explain why this
code doesnt work properly under OSX. With the gsave/grestore pairs in place
it generates errors grom the core graphics saying that the path is
not NULL, and if those sections are commented out then it runs without error
but produces no output in the window.

as far as I know yoou dont get much simpler than this drawing into a window,
anybody got any ideas ?

cheers,

-bat.

--------------------------------------------------------------------

/*
 * This test sets up a window, draws some simple text and quits. The
 * text is at 90 degrees - if only one piece of text is displayed then
 * test rotation is not working.
 *
 * -bat. 16/06/2003
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <AppKit/AppKit.h>

/*
 * An opaque view - simply over-ride the boolean
 */

@interface BitView : NSView
- (BOOL)isOpaque;
@end

@implementation BitView : NSView
- (BOOL)isOpaque
{
        return YES;
}
@end

/*
 * Create the window and do some drawing into it
 */

int
main(int argc, char *argv[])
{
        char temp[100];
        NSWindow *theWindow = nil;
        BitView *theView = nil;
        NSAutoreleasePool *pool;
        NSRect theRect;

        /* supprounding pool and application object */
        pool = [NSAutoreleasePool new];
        NSApp = [[NSApplication sharedApplication] retain];

        /* create a window */
        theWindow = [[NSWindow alloc]
                        initWithContentRect:(NSRect){ {50,100}, {200,150} }
                        styleMask:NSTitledWindowMask
                        backing:NSBackingStoreRetained
                        defer:NO];
        [theWindow setTitle:@"My Test Window"];
        [theWindow setReleasedWhenClosed:YES];

        /* create the view and allocate a graphics state */
        theView = [[BitView alloc] initWithFrame:
                        [[theWindow contentView] frame]];
        [theView allocateGState];
        [theWindow setContentView:theView];

        /* send it to the front */
        [theWindow orderFrontRegardless];
        [theView setNeedsDisplay:YES];
        [theWindow displayIfNeeded];

#ifdef NeXT
        PSWait();
#else
        [[NSGraphicsContext currentContext] flushGraphics];
#endif
        puts("You should have a blank window, press return");
        gets(temp);

        [theView lockFocus];

        /* set the font and colour */
        [[NSColor blackColor] set];
        [[NSFont systemFontOfSize:12] set];
        theRect = [theView bounds];

        /* draw a triangle */
        PSnewpath();
        PSmoveto(0,0);
        PSlineto(theRect.size.width/2.0, 0);
        PSlineto(0, theRect.size.height/2.0);
        PSclosepath();
        PSstroke();

        /* draw two bits of text */
        PSgsave();
        PSmoveto(theRect.size.width/2.0, theRect.size.height/2.0);
        PSshow("Testing");
        PSgrestore();

        PSgsave();
        PSmoveto(theRect.size.width/2.0, theRect.size.height/2.0);
        PSrotate(90);
        PSshow("Testing");
        PSgrestore();

        [theView unlockFocus];
        [theView setNeedsDisplay:YES];
        [theWindow displayIfNeeded];
#ifdef NeXT
        PSWait();
#else
        [[NSGraphicsContext currentContext] flushGraphics];
#endif

        puts("You should have a triangle and two bits of text");
        gets(temp);

        puts("Finished");
        [pool release];
        return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]