Fix line number drawing (fix #535)

This commit is contained in:
1024jp 2016-03-29 15:04:00 +09:00
parent d09ba88bad
commit 790b043415
2 changed files with 12 additions and 9 deletions

View File

@ -42,9 +42,9 @@ develop
- Fix an issue where the background of navigation/status bars were not drawn under a specific condition.
- Fix an issue where the numbers in the line number view could be drawn in a wrong place if the editor is vertical text mode and unwrapped.
- Fix an issue where document could not be drawn until the end of the file on legacy OS if the file contains control characters.
- Fix an issue on Mavericks and earlier where the application hung up if tried to print line numbers by vertical text layout on printing.
- Fix an issue where printing area could be cropped.
- Fix an issue where print panel displayed a wrong total page number after changing the paper size.
- Fix vertical line numbers position on printing.
- Fix an issue where line numbers could be drawn at a bit shifted position or even cropped on printing.
- Fix an unlocalized action name.

View File

@ -109,8 +109,14 @@ static NSString *_Nonnull const PageNumberPlaceholder = @"PAGENUM";
{
[self loadPrintSettings];
// store graphics state to keep line number area drawable
// -> Otherwise, line numbers can be cropped. (2016-03 by 1024jp)
[NSGraphicsContext saveGraphicsState];
[super drawRect:dirtyRect];
[NSGraphicsContext restoreGraphicsState];
// draw line numbers if needed
if ([self printsLineNum]) {
// prepare text attributes for line numbers
@ -120,8 +126,7 @@ static NSString *_Nonnull const PageNumberPlaceholder = @"PAGENUM";
NSDictionary<NSString *, id> *attrs = @{NSFontAttributeName: font,
NSForegroundColorAttributeName: [NSColor textColor]};
// calculate character width as mono-space font
// (hetima)
// calculate character width by treating the font as a mono-space font
NSSize charSize = [@"8" sizeWithAttributes:attrs];
// setup the variables we need for the loop
@ -133,11 +138,9 @@ static NSString *_Nonnull const PageNumberPlaceholder = @"PAGENUM";
// vertical text
BOOL isVerticalText = [self layoutOrientation] == NSTextLayoutOrientationVertical;
CGContextRef context;
if (isVerticalText) {
// rotate axis
context = [[NSGraphicsContext currentContext] CGContext];
CGContextSaveGState(context);
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextConcatCTM(context, CGAffineTransformMakeRotation(-M_PI_2));
}
@ -187,7 +190,7 @@ static NSString *_Nonnull const PageNumberPlaceholder = @"PAGENUM";
}
if (isVerticalText) {
CGContextRestoreGState(context);
[NSGraphicsContext restoreGraphicsState];
}
}
}