From b5b59673d09385c466cc4d2001042e7a67480e57 Mon Sep 17 00:00:00 2001 From: LEOYoon-Tsaw Date: Sun, 16 Aug 2020 10:58:52 -0400 Subject: [PATCH] Fix bug where label is not properly aligned --- SquirrelPanel.m | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SquirrelPanel.m b/SquirrelPanel.m index 8dbaa33e3..e99a882df 100644 --- a/SquirrelPanel.m +++ b/SquirrelPanel.m @@ -135,15 +135,16 @@ @implementation SquirrelPanel { NSTimer *_statusTimer; } -- (void)convertToVerticalGlyph:(NSMutableAttributedString *)originalText { +- (void)convertToVerticalGlyph:(NSMutableAttributedString *)originalText inRange:(NSRange)stringRange { // Use the width of the character to determin if they should be upright in vertical writing mode. // Adjust font base line for better alignment. const NSAttributedString *cjkChar = [[NSAttributedString alloc] initWithString:@"漢" attributes:_attrs]; const NSRect cjkRect = [cjkChar boundingRectWithSize:NSMakeSize(0, 0) options:NULL]; const NSAttributedString *hangulChar = [[NSAttributedString alloc] initWithString:@"한" attributes:_attrs]; const NSSize hangulSize = [hangulChar boundingRectWithSize:NSMakeSize(0, 0) options:NULL].size; - NSUInteger i = 0; - while (i < originalText.length) { + stringRange = [originalText.string rangeOfComposedCharacterSequencesForRange:stringRange]; + NSUInteger i = stringRange.location; + while (i < stringRange.location+stringRange.length) { NSRange range = [originalText.string rangeOfComposedCharacterSequenceAtIndex:i]; i = range.location + range.length; NSRect charRect = [[originalText attributedSubstringFromRange:range] boundingRectWithSize:NSMakeSize(0, 0) options:NULL]; @@ -400,7 +401,7 @@ - (void)showPreedit:(NSString *)preedit [text appendAttributedString:line]; if (_vertical) { - [self convertToVerticalGlyph:text]; + [self convertToVerticalGlyph:text inRange:NSMakeRange(0, line.length)]; } [text addAttribute:NSParagraphStyleAttributeName value:_preeditParagraphStyle @@ -456,7 +457,7 @@ - (void)showPreedit:(NSString *)preedit attributes:labelAttrs]]; // get the label size for indent if (_vertical) { - [self convertToVerticalGlyph:line]; + [self convertToVerticalGlyph:line inRange:NSMakeRange(0, line.length)]; labelWidth = [line boundingRectWithSize:NSMakeSize(0.0, 0.0) options:NSStringDrawingUsesLineFragmentOrigin].size.width; } } @@ -509,7 +510,7 @@ - (void)showPreedit:(NSString *)preedit } if (_vertical) { - [self convertToVerticalGlyph:line]; + [self convertToVerticalGlyph:line inRange:NSMakeRange(candidateStart, line.length-candidateStart)]; } NSMutableParagraphStyle *paragraphStyleCandidate = [_paragraphStyle mutableCopy]; paragraphStyleCandidate.headIndent = labelWidth;