The R Project SVN R-packages

Rev

Rev 1366 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1366 Rev 1558
Line 289... Line 289...
289
    dd->deviceSpecific = (void *) xd;
289
    dd->deviceSpecific = (void *) xd;
290
    dd->displayListOn = TRUE;
290
    dd->displayListOn = TRUE;
291
 
291
 
292
	xd->DevView = [xd->QuartzDoc getDeviceView];
292
	xd->DevView = [xd->QuartzDoc getDeviceView];
293
	xd->DevWindow = [xd->QuartzDoc getDeviceWindow];
293
	xd->DevWindow = [xd->QuartzDoc getDeviceWindow];
294
	xd->DevTextStorage = [xd->DevView getDevTextStorage];
-
 
295
	xd->DevLayoutManager = [xd->DevView getDevLayoutManager];
-
 
296
	xd->DevTextContainer = [xd->DevView getDevTextContainer];	
-
 
297
	[xd->DevTextContainer setLineFragmentPadding:0.0];
-
 
298
	[xd->DevView setDevNum: xd->DevNum];
294
	[xd->DevView setDevNum: xd->DevNum];
299
	[xd->DevView setPDFDrawing: FALSE];
295
	[xd->DevView setPDFDrawing: FALSE];
300
	xd->topLeftPoint = NSMakePoint(0, 0);
296
	xd->topLeftPoint = NSMakePoint(0, 0);
301
    return 1;
297
    return 1;
302
 
298
 
Line 500... Line 496...
500
 
496
 
501
static double 	RQuartz_StrWidth(char *str, 
497
static double 	RQuartz_StrWidth(char *str, 
502
				R_GE_gcontext *gc,
498
				R_GE_gcontext *gc,
503
				NewDevDesc *dd)
499
				NewDevDesc *dd)
504
{
500
{
-
 
501
	NSString *text;
-
 
502
	
-
 
503
	if(gc->fontface==5  || strcmp(gc->fontfamily,"symbol")==0)
-
 
504
	    text = [[NSString alloc] initWithBytes:str length:strlen(str) encoding:NSSymbolStringEncoding];
-
 
505
	else 
505
	QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
506
		text = [[NSString stringWithUTF8String:str] retain];
-
 
507
	
-
 
508
	if (!text) return 0.0;
506
 
509
	
507
	NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
510
	NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
508
		RQuartz_Font(gc, dd), NSFontAttributeName,
511
		RQuartz_Font(gc, dd), NSFontAttributeName,
509
		NULL];
512
		NULL];
510
		
513
		
511
		
-
 
512
	NSAttributedString *attrStr;
-
 
513
	if(gc->fontface==5  || strcmp(gc->fontfamily,"symbol")==0){
-
 
514
	    NSString *tmp = [[NSString alloc] initWithBytes:str length:strlen(str) encoding:NSSymbolStringEncoding];
-
 
515
		attrStr = [[[NSAttributedString alloc] initWithString:tmp 
-
 
516
										attributes:attr] autorelease];
514
	NSSize bbox = [text sizeWithAttributes:attr];
517
	} else {
-
 
518
	 attrStr = [[[NSAttributedString alloc] initWithString:[NSString stringWithCString:str] 
-
 
519
										attributes:attr] autorelease];
-
 
520
	}
-
 
521
		
515
	
522
	[xd->DevTextStorage replaceCharactersInRange:NSMakeRange(0,[xd->DevTextStorage length])
-
 
523
						 withAttributedString:attrStr];
516
	[text release];
524
	[xd->DevLayoutManager glyphRangeForTextContainer:xd->DevTextContainer];
-
 
525
 
517
	
526
	return [xd->DevLayoutManager usedRectForTextContainer:xd->DevTextContainer].size.width;
518
	return bbox.width;
527
}
519
}
528
 
520
 
529
static void 	RQuartz_Text(double x, double y, char *str,
521
static void 	RQuartz_Text(double x, double y, char *str,
530
			    double rot, double hadj, 
522
			    double rot, double hadj, 
531
			    R_GE_gcontext *gc,
523
			    R_GE_gcontext *gc,
532
			    NewDevDesc *dd)
524
			    NewDevDesc *dd)
533
{
525
{
-
 
526
	NSString *text = nil;
534
	QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
527
	QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
-
 
528
 
-
 
529
	if(gc->fontface==5  || strcmp(gc->fontfamily,"symbol")==0)
-
 
530
	    text = [[NSString alloc] initWithBytes:str length:strlen(str) encoding:NSSymbolStringEncoding];
-
 
531
	else 
-
 
532
		text = [[NSString stringWithUTF8String:str] retain];
-
 
533
	
-
 
534
	if (!text) return; /* if for some reason the decoding didn't work, just get out, nothing to see */
-
 
535
	
535
	NSColor* clr       = [NSColor colorWithCalibratedRed:(float)R_RED(gc->col)/255.0
536
	NSColor* clr       = [NSColor colorWithCalibratedRed:(float)R_RED(gc->col)/255.0
536
		 green:(float)R_GREEN(gc->col)/255.0
537
												   green:(float)R_GREEN(gc->col)/255.0
537
		 blue:(float)R_BLUE(gc->col)/255.0
538
													blue:(float)R_BLUE(gc->col)/255.0
538
		 alpha:(float)R_ALPHA(gc->col)/255.0];
539
												   alpha:(float)R_ALPHA(gc->col)/255.0];
539
	
540
	
-
 
541
	NSFont *font = RQuartz_Font(gc,  dd);
540
	NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
542
	NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
541
		RQuartz_Font(gc,  dd), NSFontAttributeName,
543
		font, NSFontAttributeName,
542
		clr, NSForegroundColorAttributeName,
544
		clr, NSForegroundColorAttributeName,
543
		NULL];
545
		nil];
544
		NSAttributedString *attrStr;
-
 
545
	if(gc->fontface==5  || strcmp(gc->fontfamily,"symbol")==0){
-
 
546
	    NSString *tmp = [[NSString alloc] initWithBytes:str length:strlen(str) encoding:NSSymbolStringEncoding];
-
 
547
		attrStr = [[[NSAttributedString alloc] initWithString:tmp 
-
 
548
										attributes:attr] autorelease];
-
 
549
	} else {
-
 
550
	 attrStr = [[[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:str] 
-
 
551
										attributes:attr] autorelease];
-
 
552
	}
-
 
553
	
-
 
554
	[xd->DevTextStorage replaceCharactersInRange:NSMakeRange(0,[xd->DevTextStorage length])
-
 
555
						 withAttributedString:attrStr];
-
 
556
	[xd->DevLayoutManager glyphRangeForTextContainer:xd->DevTextContainer];
-
 
557
	NSRange glyphRange = [xd->DevLayoutManager glyphRangeForTextContainer: xd->DevTextContainer];
-
 
558
 
546
 
559
	
-
 
560
		[xd->DevView lockFocus];
547
	[xd->DevView lockFocus];
561
	NSRectClip(ClipArea);
548
	NSRectClip(ClipArea);
562
	double h = [xd->DevLayoutManager usedRectForTextContainer:xd->DevTextContainer].size.height;
549
	//NSSize bbox = [text sizeWithAttributes:attr];
563
	
550
		
564
	NSAffineTransform *tns = [NSAffineTransform transform];	
551
	NSAffineTransform *tns = [NSAffineTransform transform];	
565
	[tns translateXBy:x yBy:y];
552
	[tns translateXBy:x yBy:y];
566
	[tns rotateByDegrees:-rot];
553
	[tns rotateByDegrees:-rot];
-
 
554
	// in theory it should be sufficient to shift by the ascender, but obviously R is providing the wrong coordinates ...
-
 
555
	[tns translateXBy:0 yBy:-[font ascender]+[font descender]];	
567
	[tns translateXBy:0 yBy:-h];	// Adjust a bit, why?
556
	//[tns translateXBy:0 yBy:-bbox.height];
568
	[tns concat];
557
	[tns concat];
569
 
558
 
570
	[xd->DevLayoutManager drawGlyphsForGlyphRange: glyphRange atPoint: NSMakePoint(0,0)];
559
	[text drawAtPoint:NSMakePoint(0,0) withAttributes:attr];
-
 
560
	[text release];
571
	
561
	
572
		[xd->DevView unlockFocus];
562
	[xd->DevView unlockFocus];
573
}
563
}
574
 
564
 
575
static void 	RQuartz_Rect(double x0, double y0, double x1, double y1,
565
static void 	RQuartz_Rect(double x0, double y0, double x1, double y1,
576
			    R_GE_gcontext *gc,
566
			    R_GE_gcontext *gc,
577
			    NewDevDesc *dd)
567
			    NewDevDesc *dd)
Line 849... Line 839...
849
				  R_GE_gcontext *gc,
839
				  R_GE_gcontext *gc,
850
				  double* ascent, double* descent, 
840
				  double* ascent, double* descent, 
851
				  double* width,
841
				  double* width,
852
				  NewDevDesc *dd)
842
				  NewDevDesc *dd)
853
{
843
{
854
	QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
844
	//QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
855
	NSFont* font= RQuartz_Font(gc,dd);
845
	NSFont* font= RQuartz_Font(gc,dd);
856
	NSRect rect,rect2;
-
 
857
	unichar uc = (unichar)c;
846
	unichar uc = (unichar)c;
858
	char str[2];
847
	char str[2];
-
 
848
 
859
	str[1] = '\0';	
849
	str[1] = '\0';	
860
	str[0] = (char)c;
850
	str[0] = (char)c;
861
	
-
 
862
	if(c==0){
-
 
863
		rect = [font boundingRectForFont];
-
 
864
	 } else {
-
 
865
 
851
 
-
 
852
	*ascent = [font ascender];
-
 
853
	*descent = [font descender];
-
 
854
	*width = [font maximumAdvancement].width;
-
 
855
	if (c) {
866
		 NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
856
		NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
867
			font, NSFontAttributeName,
857
			font, NSFontAttributeName,
868
			NULL];
858
			nil];
869
		
859
		
870
		 NSAttributedString *attrStr;
860
		NSString *text = nil;
871
		
861
		
872
		if(gc->fontface==5  ||strcmp(gc->fontfamily,"symbol")==0){
862
		if(gc->fontface==5  ||strcmp(gc->fontfamily,"symbol")==0)
873
			NSString *tmp = [[NSString alloc] initWithBytes:str length:1 encoding:NSSymbolStringEncoding];
863
			text = [[NSString alloc] initWithBytes:str length:1 encoding:NSSymbolStringEncoding];
874
			attrStr = [[[NSAttributedString alloc] initWithString:tmp 
-
 
875
										attributes:attr] autorelease];
-
 
876
		} else {
864
		else
877
			attrStr = [[[NSAttributedString alloc] initWithString:[NSString stringWithCharacters:&uc length:1] 
865
			text = [[NSString stringWithCharacters:&uc length:1] retain];
878
										attributes:attr] autorelease];
-
 
879
		}
866
	
-
 
867
		*width = [text sizeWithAttributes: attr].width;
880
		
868
		
881
		[xd->DevTextStorage replaceCharactersInRange:NSMakeRange(0, [xd->DevTextStorage length])
-
 
882
						 withAttributedString:attrStr];
869
		[text release];
883
		[xd->DevLayoutManager glyphRangeForTextContainer:xd->DevTextContainer];
-
 
884
		//NSLog(@"glyphs=%d",  [xd->DevLayoutManager numberOfGlyphs] );
-
 
885
		rect = [xd->DevLayoutManager usedRectForTextContainer:xd->DevTextContainer];
-
 
886
		rect2 = [font boundingRectForGlyph: [xd->DevLayoutManager glyphAtIndex:0]];
-
 
887
	 }    
870
	}
888
    
871
    
889
 
-
 
890
	*ascent  =  NSMaxY(rect);
-
 
891
	*descent = -NSMinY(rect);
-
 
892
	*width   = NSWidth(rect);
-
 
893
	
-
 
894
	//fprintf(stderr,"c=%c,ascent=%f, descent=%f,width=%f,width2=%f,width3=%f\n",c,*ascent , *descent, *width, *width+rect2.origin.x,NSWidth(rect));
872
	//fprintf(stderr,"c=%c,ascent=%f, descent=%f,width=%f,width2=%f,width3=%f\n",c,*ascent , *descent, *width, *width+rect2.origin.x,NSWidth(rect));
895
 
873
 
896
//	NSLog(@"x=%f,y=%f,width=%f,height=%f",rect.origin.x, rect.origin.y,rect.size.width,rect.size.height);
874
//	NSLog(@"x=%f,y=%f,width=%f,height=%f",rect.origin.x, rect.origin.y,rect.size.width,rect.size.height);
897
//	NSLog(@"x=%f,y=%f,width=%f,height=%f",rect2.origin.x, rect2.origin.y,rect2.size.width,rect2.size.height);
875
//	NSLog(@"x=%f,y=%f,width=%f,height=%f",rect2.origin.x, rect2.origin.y,rect2.size.width,rect2.size.height);
898
	
876