From 007e498a028ffdfbafd3a4f54542178003e7e623 Mon Sep 17 00:00:00 2001 From: Dennis Vennink Date: Fri, 31 Aug 2012 10:40:49 +0200 Subject: [PATCH] fixup! Incorporated scalable icons. Implemented proper alignment of the icons with the line number font. --- Frameworks/OakTextView/src/GutterView.mm | 7 +++++-- Frameworks/OakTextView/src/OakDocumentView.mm | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Frameworks/OakTextView/src/GutterView.mm b/Frameworks/OakTextView/src/GutterView.mm index ce423941..7afdc1f4 100644 --- a/Frameworks/OakTextView/src/GutterView.mm +++ b/Frameworks/OakTextView/src/GutterView.mm @@ -343,8 +343,11 @@ static void DrawText (std::string const& text, CGRect const& rect, CGFloat basel NSImage* image = [self imageForColumn:dataSource->identifier atLine:record.lineNumber hovering:isHoveringRect && NSEqualPoints(mouseDownAtPoint, NSMakePoint(-1, -1)) pressed:isHoveringRect && isDownInRect]; if([image size].height > 0 && [image size].width > 0) { - CGFloat x = round((NSWidth(columnRect) - [image size].width) / 2); - CGFloat y = round((NSHeight(columnRect) - [image size].height) / 2); + // The placement of the center of image is aligned with the center of the capHeight. + CGFloat center = record.baseline - ([self.lineNumberFont capHeight] / 2); + + CGFloat x = round((NSWidth(columnRect) - [image size].width) / 2); + CGFloat y = round(center - ([image size].height / 2)); NSImage* overlayImage = [[[NSImage alloc] initWithSize:[image size]] autorelease]; diff --git a/Frameworks/OakTextView/src/OakDocumentView.mm b/Frameworks/OakTextView/src/OakDocumentView.mm index 825e5219..805776d3 100644 --- a/Frameworks/OakTextView/src/OakDocumentView.mm +++ b/Frameworks/OakTextView/src/OakDocumentView.mm @@ -173,9 +173,21 @@ private: { if(NSImage* res = [[[NSImage imageNamed:aName inSameBundleAsClass:[self class]] copy] autorelease]) { - CGFloat height = [gutterView.lineNumberFont xHeight] * ([aName hasPrefix:@"Bookmark"] ? 1.125 : 1.5); + // We use capHeight instead of x-height since most fonts have the numbers + // extend to this height, so centering around the x-height would look off + CGFloat height = [gutterView.lineNumberFont capHeight]; CGFloat width = [res size].width * height / [res size].height; - [res setSize:NSMakeSize(round(width), round(height))]; + + CGFloat scaleFactor = 1.0; + + // Since all images are vector based and don’t contain any spacing to + // align it, we need to set the individual scaleFactor per image. + if([aName hasPrefix:@"Bookmark"]) scaleFactor = 1.0; + if([aName hasPrefix:@"Folding"]) scaleFactor = 1.2; + if([aName hasPrefix:@"Search"]) scaleFactor = 1.2; + + [res setSize:NSMakeSize(round(width * scaleFactor), round(height * scaleFactor))]; + return res; } NSLog(@"%s no image named ‘%@’", sel_getName(_cmd), aName);