Merge with revision 39619 of GUI main branch

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@39633 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2016-04-06 18:44:24 +00:00
parent b7b6533b10
commit 2db13a0647
2 changed files with 40 additions and 93 deletions

View file

@ -39,6 +39,7 @@
#import <Foundation/NSFileManager.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSRange.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
@ -50,6 +51,7 @@
#import "AppKit/NSColor.h"
#import "AppKit/NSFileWrapper.h"
#import "AppKit/NSFont.h"
#import "AppKit/NSFontDescriptor.h"
#import "AppKit/NSFontManager.h"
// For the colour name spaces
#import "AppKit/NSGraphics.h"
@ -1519,9 +1521,20 @@ static NSMutableDictionary *cachedCSets = nil;
return nil;
}
- (NSFontDescriptor*)_substituteFontDescriptorFor: (unichar)uchar
{
NSString *chars = [NSString stringWithCharacters: &uchar length: 1];
NSCharacterSet *requiredCharacterSet = [NSCharacterSet characterSetWithCharactersInString: chars];
NSDictionary *fontAttributes = [NSDictionary dictionaryWithObjectsAndKeys: requiredCharacterSet, NSFontCharacterSetAttribute, nil];
NSSet *mandatoryKeys = [NSSet setWithObjects: NSFontCharacterSetAttribute, nil];
NSFontDescriptor *fd = [NSFontDescriptor fontDescriptorWithFontAttributes: fontAttributes];
return [fd matchingFontDescriptorWithMandatoryKeys: mandatoryKeys];
}
- (NSFont*)_substituteFontFor: (unichar)uchar font: (NSFont*)baseFont
{
NSFont *subFont;
NSFontDescriptor *descriptor;
// Caching one font may lead to the selected substitution font not being
// from the prefered list, although there is one there with this character.
@ -1538,6 +1551,22 @@ static NSMutableDictionary *cachedCSets = nil;
return subFont;
}
// Fast way with font descriptors
descriptor = [self _substituteFontDescriptorFor: uchar];
if (descriptor != nil)
{
NSCharacterSet *newSet = [descriptor objectForKey: NSFontCharacterSetAttribute];
if ([newSet characterIsMember: uchar])
{
NSString *fName = [descriptor objectForKey: NSFontFamilyAttribute];
ASSIGN(lastFont, fName);
ASSIGN(lastSet, newSet);
return [self _substituteFontWithName: fName font: baseFont];
}
}
subFont = [self _substituteFontFor: uchar font: baseFont fromList:
[[NSFontManager sharedFontManager] availableFonts]];
if (subFont != nil)

View file

@ -40,13 +40,11 @@
#import "AppKit/NSEvent.h"
#import "AppKit/NSWindow.h"
#import "GSGuiPrivate.h"
#import "GNUstepGUI/GSTheme.h"
/*
* Class variables
*/
static NSImage *_branch_image;
static NSImage *_highlight_image;
static Class _colorClass;
// GNUstep user default to have NSBrowserCell in bold if non leaf
@ -66,8 +64,6 @@ static NSFont *_leafFont;
if (self == [NSBrowserCell class])
{
[self setVersion: 1];
ASSIGN(_branch_image, [NSImage imageNamed: @"common_3DArrowRight"]);
ASSIGN(_highlight_image, [NSImage imageNamed: @"common_3DArrowRightH"]);
/*
* Cache classes to avoid overheads of poor compiler implementation.
@ -90,7 +86,7 @@ static NSFont *_leafFont;
*/
+ (NSImage*) branchImage
{
return _branch_image;
return [[GSTheme theme] branchImage];
}
/**<p>Returns the default hightlited branch image</p>
@ -98,7 +94,7 @@ static NSFont *_leafFont;
*/
+ (NSImage*) highlightedBranchImage
{
return _highlight_image;
return [[GSTheme theme] highlightedBranchImage];
}
/*
@ -330,93 +326,15 @@ static NSFont *_leafFont;
*/
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
NSRect title_rect = cellFrame;
NSImage *branch_image = nil;
NSImage *cell_image = [self image];
if (_cell.is_highlighted || _cell.state)
{
if (!_browsercell_is_leaf)
branch_image = [object_getClass(self) highlightedBranchImage];
if (nil != [self alternateImage])
cell_image = [self alternateImage];
// If we are highlighted, fill the background
[[self highlightColorInView: controlView] setFill];
NSRectFill(cellFrame);
[[GSTheme theme] drawBrowserInteriorWithFrame: cellFrame
withCell: self
inView: controlView
withImage: [self image]
alternateImage: [self alternateImage]
isHighlighted: [self isHighlighted]
state: [self state]
isLeaf: [self isLeaf]];
}
else
{
if (!_browsercell_is_leaf)
branch_image = [object_getClass(self) branchImage];
// (Don't fill the background)
}
// Draw the branch image if there is one
if (branch_image)
{
NSRect imgRect;
imgRect.size = [branch_image size];
imgRect.origin.x = MAX(NSMaxX(title_rect) - imgRect.size.width - 4.0, 0.);
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.), 0.);
if (controlView != nil)
{
imgRect = [controlView centerScanRect: imgRect];
}
[branch_image drawInRect: imgRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
title_rect.size.width -= imgRect.size.width + 8;
}
// Skip 2 points from the left border
title_rect.origin.x += 2;
title_rect.size.width -= 2;
// Draw the cell image if there is one
if (cell_image)
{
NSRect imgRect;
imgRect.size = [cell_image size];
imgRect.origin.x = NSMinX(title_rect);
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.);
if (controlView != nil)
{
imgRect = [controlView centerScanRect: imgRect];
}
[cell_image drawInRect: imgRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
title_rect.origin.x += imgRect.size.width + 4;
title_rect.size.width -= imgRect.size.width + 4;
}
// Draw the body of the cell
if (_cell.in_editing)
{
[self _drawEditorWithFrame: cellFrame inView: controlView];
}
else
{
[self _drawAttributedText: [self attributedStringValue]
inFrame: title_rect];
}
}
/*
* NSCoding protocol