Skip to content
Snippets Groups Projects
Commit 4eefc2a3 authored by George Nachman's avatar George Nachman
Browse files

When minimum contrast is 0, don't break ligatures that have different background colors. Issue 5947

parent 7b5eae71
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -17,6 +17,8 @@
- (NSArray *)mapWithBlock:(id (^)(ObjectType anObject))block;
- (NSArray *)flatMapWithBlock:(NSArray *(^)(ObjectType anObject))block;
 
- (id)reduceWithBlock:(id (^)(ObjectType first, ObjectType second))block;
// Returns those elements of the array for which block(element) returns YES.
// block is called on every element in order.
- (NSArray *)filteredArrayUsingBlock:(BOOL (^)(ObjectType anObject))block;
Loading
Loading
Loading
Loading
@@ -65,5 +65,8 @@ NS_INLINE BOOL iTermBackgroundColorRunsEqual(iTermBackgroundColorRun *a,
@property(nonatomic, readonly) iTermBackgroundColorRun *valuePointer;
@property(nonatomic, retain) NSColor *backgroundColor;
@property(nonatomic, retain) NSColor *unprocessedBackgroundColor;
+ (instancetype)boxedBackgroundColorRunWithValue:(iTermBackgroundColorRun)value;
@end
 
Loading
Loading
@@ -125,6 +125,14 @@ static void iTermMakeBackgroundColorRun(iTermBackgroundColorRun *run,
iTermBackgroundColorRun _value;
}
 
+ (instancetype)boxedBackgroundColorRunWithValue:(iTermBackgroundColorRun)value {
iTermBoxedBackgroundColorRun *run = [[[self alloc] init] autorelease];
if (run) {
run->_value = value;
}
return run;
}
- (void)dealloc {
[_backgroundColor release];
[_unprocessedBackgroundColor release];
Loading
Loading
Loading
Loading
@@ -388,27 +388,12 @@ typedef struct iTermTextColorContext {
 
// Now iterate over the lines and paint the characters.
CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
iTermBackgroundColorRunsInLine *representativeRunArray = nil;
NSInteger count = 0;
for (iTermBackgroundColorRunsInLine *runArray in backgroundRunArrays) {
if (count == 0) {
representativeRunArray = runArray;
count = runArray.numberOfEquivalentRows;
}
count--;
[self drawCharactersForLine:runArray.line
atY:runArray.y
backgroundRuns:representativeRunArray.array
context:ctx];
[self drawNoteRangesOnLine:runArray.line];
if (_debug) {
NSString *s = [NSString stringWithFormat:@"%d", runArray.line];
[s drawAtPoint:NSMakePoint(0, runArray.y)
withAttributes:@{ NSForegroundColorAttributeName: [NSColor blackColor],
NSBackgroundColorAttributeName: [NSColor whiteColor],
NSFontAttributeName: [NSFont systemFontOfSize:8] }];
}
if (self.minimumContrast > 0) {
[self drawForegroundForBackgroundRunArrays:backgroundRunArrays
ctx:ctx];
} else {
[self drawNoMinimumContrastContrastForegroundWithBackgroundRunArrays:backgroundRunArrays
ctx:ctx];
}
 
[self drawTopMargin];
Loading
Loading
@@ -940,6 +925,82 @@ typedef struct iTermTextColorContext {
}
}
 
#pragma mark - Drawing: Foreground
// Draw assuming no minimum contrast. Keeps glyphs together in a single background color run across different background colors.
- (void)drawNoMinimumContrastContrastForegroundWithBackgroundRunArrays:(NSArray<iTermBackgroundColorRunsInLine *> *)backgroundRunArrays
ctx:(CGContextRef)ctx {
// Combine runs on each line, except those with different values of
// `selected` or `match`. Those properties affect foreground color and must
// split ligatures up.
NSArray<iTermBackgroundColorRunsInLine *> *fakeRunArrays = [backgroundRunArrays mapWithBlock:^id(iTermBackgroundColorRunsInLine *runs) {
NSMutableArray<iTermBoxedBackgroundColorRun *> *combinedRuns = [NSMutableArray array];
iTermBackgroundColorRun previousRun = { {0} };
BOOL havePreviousRun = NO;
for (iTermBoxedBackgroundColorRun *run in runs.array) {
if (!havePreviousRun) {
havePreviousRun = YES;
previousRun = *run.valuePointer;
} else if (run.valuePointer->selected == previousRun.selected &&
run.valuePointer->isMatch == previousRun.isMatch) {
previousRun.range = NSUnionRange(previousRun.range, run.valuePointer->range);
} else {
[combinedRuns addObject:[iTermBoxedBackgroundColorRun boxedBackgroundColorRunWithValue:previousRun]];
previousRun = *run.valuePointer;
}
}
if (havePreviousRun) {
[combinedRuns addObject:[iTermBoxedBackgroundColorRun boxedBackgroundColorRunWithValue:previousRun]];
}
iTermBackgroundColorRunsInLine *fakeRuns = [[[iTermBackgroundColorRunsInLine alloc] init] autorelease];
fakeRuns.line = runs.line;
fakeRuns.y = runs.y;
fakeRuns.numberOfEquivalentRows = fakeRuns.numberOfEquivalentRows;
fakeRuns.array = combinedRuns;
return fakeRuns;
}];
[self drawForegroundForBackgroundRunArrays:fakeRunArrays
ctx:ctx];
}
// Draws
- (void)drawForegroundForBackgroundRunArrays:(NSArray<iTermBackgroundColorRunsInLine *> *)backgroundRunArrays
ctx:(CGContextRef)ctx {
iTermBackgroundColorRunsInLine *representativeRunArray = nil;
NSInteger count = 0;
for (iTermBackgroundColorRunsInLine *runArray in backgroundRunArrays) {
if (count == 0) {
representativeRunArray = runArray;
count = runArray.numberOfEquivalentRows;
}
count--;
[self drawForegroundForLineNumber:runArray.line
y:runArray.y
backgroundRuns:representativeRunArray.array
context:ctx];
}
}
- (void)drawForegroundForLineNumber:(int)line
y:(CGFloat)y
backgroundRuns:(NSArray<iTermBoxedBackgroundColorRun *> *)backgroundRuns
context:(CGContextRef)ctx {
[self drawCharactersForLine:line
atY:y
backgroundRuns:backgroundRuns
context:ctx];
[self drawNoteRangesOnLine:line];
if (_debug) {
NSString *s = [NSString stringWithFormat:@"%d", line];
[s drawAtPoint:NSMakePoint(0, y)
withAttributes:@{ NSForegroundColorAttributeName: [NSColor blackColor],
NSBackgroundColorAttributeName: [NSColor whiteColor],
NSFontAttributeName: [NSFont systemFontOfSize:8] }];
}
}
#pragma mark - Drawing: Text
 
- (void)drawCharactersForLine:(int)line
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment