X11 updates for Onyx2D changes

This commit is contained in:
Christopher Lloyd 2010-11-01 21:18:47 -04:00
parent 0f1a73fd84
commit 575fad7708
4 changed files with 51 additions and 55 deletions

View File

@ -31,7 +31,7 @@
case kCTFontMenuItemFontType:
if(size==0)
size=12;
font=[O2Font createWithFontName:@"Arial"];
font=O2FontCreateWithFontName(@"Arial");
break;
default:

View File

@ -9,10 +9,6 @@
return YES;
}
static inline O2GState *currentState(O2Context *self){
return [self->_stateStack lastObject];
}
-initWithSurface:(O2Surface *)surface flipped:(BOOL)flipped {
if([super initWithSurface:surface flipped:flipped]==nil)
return nil;
@ -26,7 +22,7 @@ static inline O2GState *currentState(O2Context *self){
}
-(void)establishFontStateInDeviceIfDirty {
O2GState *gState=currentState(self);
O2GState *gState=O2ContextCurrentGState(self);
if(gState->_fontIsDirty){
O2GStateClearFontIsDirty(gState);
@ -107,9 +103,11 @@ static void drawFreeTypeBitmap(O2Context_builtin_FT *self,O2Surface *surface,FT_
}
-(void)showGlyphs:(const O2Glyph *)glyphs count:(unsigned)count {
-(void)showGlyphs:(const O2Glyph *)glyphs advances:(const O2Size *)advances count:(unsigned)count {
// FIXME: use advances if not NULL
O2AffineTransform transformToDevice=O2ContextGetUserSpaceToDeviceSpaceTransform(self);
O2GState *gState=currentState(self);
O2GState *gState=O2ContextCurrentGState(self);
O2Paint *paint=paintFromColor(gState->_fillColor);
O2AffineTransform Trm=O2AffineTransformConcat(gState->_textTransform,transformToDevice);
O2Point point=O2PointApplyAffineTransform(NSMakePoint(0,0),Trm);
@ -163,8 +161,8 @@ static void drawFreeTypeBitmap(O2Context_builtin_FT *self,O2Surface *surface,FT_
total=(total/O2FontGetUnitsPerEm(font))*gState->_pointSize;
currentState(self)->_textTransform.tx+=total;
currentState(self)->_textTransform.ty+=0;
O2ContextCurrentGState(self)->_textTransform.tx+=total;
O2ContextCurrentGState(self)->_textTransform.ty+=0;
}
@end

View File

@ -24,10 +24,6 @@
@implementation O2Context_cairo
static inline O2GState *currentState(O2Context *self){
return [self->_stateStack lastObject];
}
+(BOOL)canInitWithWindow:(CGWindow *)window {
return YES;
}
@ -75,10 +71,6 @@ static inline O2GState *currentState(O2Context *self){
return [[O2Surface_cairo alloc] initWithWidth:width height:height compatibleWithContext:self];
}
-(void)deviceClipReset {
cairo_reset_clip(_context);
}
-(void)setCurrentColor:(O2Color*)color
{
const float *c=O2ColorGetComponents(color);
@ -138,8 +130,8 @@ static inline O2GState *currentState(O2Context *self){
-(void)synchronizeFontCTM
{
O2AffineTransform ctm=[currentState(self) textMatrix];
O2Float size=O2GStatePointSize(currentState(self));
O2AffineTransform ctm=[O2ContextCurrentGState(self) textMatrix];
O2Float size=O2GStatePointSize(O2ContextCurrentGState(self));
ctm = O2AffineTransformScale(ctm, size, -size);
@ -158,7 +150,7 @@ static inline O2GState *currentState(O2Context *self){
-(void)synchronizeLineAttributes
{
O2GState *gState=currentState(self);
O2GState *gState=O2ContextCurrentGState(self);
int i;
cairo_set_line_width(_context, gState->_lineWidth);
@ -235,13 +227,36 @@ static inline O2GState *currentState(O2Context *self){
}
}
-(void)deviceClipToNonZeroPath:(O2Path*)path
{
-(void)clipToState:(O2ClipState *)clipState {
NSArray *phases=[O2GStateClipState(gState) clipPhases];
int i,count=[phases count];
cairo_reset_clip(_context);
for(i=0;i<count;i++){
O2ClipPhase *phase=[phases objectAtIndex:i];
switch(O2ClipPhasePhaseType(phase)){
case O2ClipPhaseNonZeroPath:;
O2Path *path=O2ClipPhaseObject(phase);
[self setCurrentPath:path];
cairo_set_fill_rule(_context, CAIRO_FILL_RULE_WINDING);
cairo_clip(_context);
break;
case O2ClipPhaseEOPath:{
O2Path *path=O2ClipPhaseObject(phase);
// not handled
}
break;
case O2ClipPhaseMask:
break;
}
}
}
-(void)drawPath:(O2PathDrawingMode)mode
{
@ -251,7 +266,7 @@ static inline O2GState *currentState(O2Context *self){
switch(mode)
{
case kCGPathStroke:
[self setCurrentColor:[self strokeColor]];
[self setCurrentColor:O2ContextStrokeColor(self)];
[self synchronizeLineAttributes];
cairo_stroke_preserve(_context);
break;
@ -273,7 +288,7 @@ static inline O2GState *currentState(O2Context *self){
[self setCurrentColor:O2ContextFillColor(self)];
cairo_set_fill_rule(_context, CAIRO_FILL_RULE_WINDING);
cairo_fill_preserve(_context);
[self setCurrentColor:[self strokeColor]];
[self setCurrentColor:O2ContextStrokeColor(self)];
[self synchronizeLineAttributes];
cairo_stroke_preserve(_context);
break;
@ -282,7 +297,7 @@ static inline O2GState *currentState(O2Context *self){
[self setCurrentColor:O2ContextFillColor(self)];
cairo_set_fill_rule(_context, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill_preserve(_context);
[self setCurrentColor:[self strokeColor]];
[self setCurrentColor:O2ContextStrokeColor(self)];
[self synchronizeLineAttributes];
cairo_stroke_preserve(_context);
break;
@ -370,12 +385,12 @@ static inline O2GState *currentState(O2Context *self){
}
-(void)establishFontStateInDeviceIfDirty {
O2GState *gState=currentState(self);
O2GState *gState=O2ContextCurrentGState(self);
if(gState->_fontIsDirty){
O2GStateClearFontIsDirty(gState);
O2Font_FT *cgFont=(O2Font_FT *)[gState font];
O2Font_FT *cgFont=(O2Font_FT *)O2GStateFont(gState);
KTFont *fontState=[[O2FontState_cairo alloc] initWithFreeTypeFont:cgFont size:O2GStatePointSize(gState)];
[gState setFontState:fontState];
@ -384,11 +399,13 @@ static inline O2GState *currentState(O2Context *self){
}
-(void)showGlyphs:(const O2Glyph *)glyphs count:(unsigned)count {
-(void)showGlyphs:(const O2Glyph *)glyphs advances:(const O2Size *)advances count:(unsigned)count {
// FIXME: use advances if not NULL
[self establishFontStateInDeviceIfDirty];
O2GState *gState=currentState(self);
O2Font *font=[gState font];
O2GState *gState=O2ContextCurrentGState(self);
O2Font *font=O2GStateFont(gState);
O2FontState_cairo *fontState=[gState fontState];
cairo_font_face_t *face=[fontState cairo_font_face];
cairo_glyph_t *cg=alloca(sizeof(cairo_glyph_t)*count);
@ -438,26 +455,6 @@ cairo_status_t writeToData(void *closure,
return CAIRO_STATUS_SUCCESS;
}
-(NSData *)captureBitmapInRect:(CGRect)rect {
id ret=[NSMutableData data];
cairo_surface_t *surf=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect.size.width, rect.size.height);
cairo_t *ctx=cairo_create(surf);
cairo_identity_matrix(ctx);
cairo_reset_clip(ctx);
cairo_set_source_surface (ctx, _surface, -rect.origin.x, -rect.origin.y);
cairo_paint(ctx);
cairo_destroy(ctx);
cairo_surface_write_to_png_stream(surf, writeToData, ret);
cairo_surface_destroy(surf);
return ret;
}
-(void)drawBackingContext:(O2Context *)other size:(NSSize)size {
cairo_surface_t *otherSurface=NULL;

View File

@ -591,11 +591,12 @@ static int errorHandler(Display *display,XErrorEvent *errorEvent) {
#import <AppKit/NSGraphicsStyle.h>
@implementation NSGraphicsStyle (Overrides)
-(void)drawMenuBranchArrowAtPoint:(NSPoint)point selected:(BOOL)selected {
-(void)drawMenuBranchArrowInRect:(NSRect)rect selected:(BOOL)selected {
NSImage* arrow=[NSImage imageNamed:@"NSMenuArrow"];
point.y+=5;
point.x-=2;
[arrow compositeToPoint:point operation:NSCompositeSourceOver];
// ??? magic numbers
rect.origin.y+=5;
rect.origin.x-=2;
[arrow drawInRect:rect operation:NSCompositeSourceOver];
}
@end