Skip to content

Commit

Permalink
Merge branch 'dev' into app_uninstall_settings_crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng authored Jan 26, 2024
2 parents 4da263a + a7bb785 commit bfc9990
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Easydict/Feature/Service/Apple/EZAppleService.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

static NSArray *const kAllowedCharactersInPoetryList = @[ @"", @"", @"", @"" ];

static CGFloat const kParagraphLineHeightRatio = 1.2;
static CGFloat const kParagraphLineHeightRatio = 1.5;

static NSInteger const kShortPoetryCharacterCountOfLine = 12;

Expand Down Expand Up @@ -1211,18 +1211,6 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
CGFloat deltaY = prevBoundingBox.origin.y - (boundingBox.origin.y + boundingBox.size.height);
CGFloat deltaX = boundingBox.origin.x - (prevBoundingBox.origin.x + prevBoundingBox.size.width);

// Note that line spacing is inaccurate, sometimes it's too small 😢
BOOL isNewParagraph = NO;
if (deltaY > 0) {
// averageLineSpacing may too small, so deltaY should be much larger than averageLineSpacing
BOOL isBigLineSpacing = [self isBigSpacingLineOfTextObservation:textObservation
prevTextObservation:prevTextObservation
greaterThanLineHeightRatio:kParagraphLineHeightRatio];
if (isBigLineSpacing) {
isNewParagraph = YES;
}
}

// Note that sometimes the line frames will overlap a little, then deltaY will less then 0
BOOL isNewLine = NO;
if (deltaY > 0) {
Expand Down Expand Up @@ -1251,10 +1239,9 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
if (isNeedRemoveLastDashOfText) {
mergedText = [mergedText substringToIndex:mergedText.length - 1].mutableCopy;
}
} else if (isNewParagraph || isNewLine) {
} else if (isNewLine) {
joinedString = [self joinedStringOfTextObservation:textObservation
prevTextObservation:prevTextObservation
isNewParagraph:isNewParagraph];
prevTextObservation:prevTextObservation];
} else {
joinedString = @" "; // if the same line, just join two texts
}
Expand Down Expand Up @@ -1489,9 +1476,10 @@ - (BOOL)isPoetryOftextObservations:(NSArray<VNRecognizedTextObservation *> *)tex
/// Get joined string of text, according to its last char.
- (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textObservation
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation
isNewParagraph:(BOOL)isNewParagraph {
{
NSString *joinedString = @"";
BOOL needLineBreak = NO;
BOOL isNewParagraph = NO;

CGRect prevBoundingBox = prevTextObservation.boundingBox;
CGFloat prevLineLength = prevBoundingBox.size.width;
Expand All @@ -1509,7 +1497,7 @@ - (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textO

BOOL hasPrevIndentation = [self hasIndentationOfTextObservation:prevTextObservation];
BOOL hasIndentation = [self hasIndentationOfTextObservation:textObservation];

BOOL isPrevLongText = [self isLongTextObservation:prevTextObservation isStrict:NO];

BOOL isEqualChineseText = [self isEqualChineseTextObservation:textObservation prevTextObservation:prevTextObservation];
Expand Down Expand Up @@ -1895,6 +1883,20 @@ - (BOOL)hasIndentationOfTextObservation:(VNRecognizedTextObservation *)textObser
return hasIndentation;
}

- (BOOL)hasIndentationOfTextObservation:(VNRecognizedTextObservation *)textObservation
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation {
BOOL isEqualX = [self isEqualXOfTextObservation:textObservation prevTextObservation:prevTextObservation];

CGFloat lineX = CGRectGetMinX(textObservation.boundingBox);
CGFloat prevLineX = CGRectGetMinX(prevTextObservation.boundingBox);
CGFloat dx = lineX - prevLineX;

if (!isEqualX && dx < 0) {
return YES;
}
return NO;
}

- (BOOL)isEqualTextObservation:(VNRecognizedTextObservation *)textObservation
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation {
// 0.06 - 0.025
Expand Down

0 comments on commit bfc9990

Please sign in to comment.