Skip to content

Commit

Permalink
Fix bug where label is not properly aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Aug 16, 2020
1 parent 8bf4e56 commit b5b5967
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b5b5967

Please sign in to comment.