Skip to content

Commit 7ca612c

Browse files
authored
Merge branch 'dev' into google-gemini
2 parents ac8a4ae + a7bb785 commit 7ca612c

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Easydict/Feature/Service/Apple/EZAppleService.m

+20-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

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

27-
static CGFloat const kParagraphLineHeightRatio = 1.2;
27+
static CGFloat const kParagraphLineHeightRatio = 1.5;
2828

2929
static NSInteger const kShortPoetryCharacterCountOfLine = 12;
3030

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

1214-
// Note that line spacing is inaccurate, sometimes it's too small 😢
1215-
BOOL isNewParagraph = NO;
1216-
if (deltaY > 0) {
1217-
// averageLineSpacing may too small, so deltaY should be much larger than averageLineSpacing
1218-
BOOL isBigLineSpacing = [self isBigSpacingLineOfTextObservation:textObservation
1219-
prevTextObservation:prevTextObservation
1220-
greaterThanLineHeightRatio:kParagraphLineHeightRatio];
1221-
if (isBigLineSpacing) {
1222-
isNewParagraph = YES;
1223-
}
1224-
}
1225-
12261214
// Note that sometimes the line frames will overlap a little, then deltaY will less then 0
12271215
BOOL isNewLine = NO;
12281216
if (deltaY > 0) {
@@ -1251,10 +1239,9 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
12511239
if (isNeedRemoveLastDashOfText) {
12521240
mergedText = [mergedText substringToIndex:mergedText.length - 1].mutableCopy;
12531241
}
1254-
} else if (isNewParagraph || isNewLine) {
1242+
} else if (isNewLine) {
12551243
joinedString = [self joinedStringOfTextObservation:textObservation
1256-
prevTextObservation:prevTextObservation
1257-
isNewParagraph:isNewParagraph];
1244+
prevTextObservation:prevTextObservation];
12581245
} else {
12591246
joinedString = @" "; // if the same line, just join two texts
12601247
}
@@ -1489,9 +1476,10 @@ - (BOOL)isPoetryOftextObservations:(NSArray<VNRecognizedTextObservation *> *)tex
14891476
/// Get joined string of text, according to its last char.
14901477
- (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textObservation
14911478
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation
1492-
isNewParagraph:(BOOL)isNewParagraph {
1479+
{
14931480
NSString *joinedString = @"";
14941481
BOOL needLineBreak = NO;
1482+
BOOL isNewParagraph = NO;
14951483

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

15101498
BOOL hasPrevIndentation = [self hasIndentationOfTextObservation:prevTextObservation];
15111499
BOOL hasIndentation = [self hasIndentationOfTextObservation:textObservation];
1512-
1500+
15131501
BOOL isPrevLongText = [self isLongTextObservation:prevTextObservation isStrict:NO];
15141502

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

1886+
- (BOOL)hasIndentationOfTextObservation:(VNRecognizedTextObservation *)textObservation
1887+
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation {
1888+
BOOL isEqualX = [self isEqualXOfTextObservation:textObservation prevTextObservation:prevTextObservation];
1889+
1890+
CGFloat lineX = CGRectGetMinX(textObservation.boundingBox);
1891+
CGFloat prevLineX = CGRectGetMinX(prevTextObservation.boundingBox);
1892+
CGFloat dx = lineX - prevLineX;
1893+
1894+
if (!isEqualX && dx < 0) {
1895+
return YES;
1896+
}
1897+
return NO;
1898+
}
1899+
18981900
- (BOOL)isEqualTextObservation:(VNRecognizedTextObservation *)textObservation
18991901
prevTextObservation:(VNRecognizedTextObservation *)prevTextObservation {
19001902
// 0.06 - 0.025

0 commit comments

Comments
 (0)