24
24
25
25
static NSArray *const kAllowedCharactersInPoetryList = @[ @" 《" , @" 》" , @" 〔" , @" 〕" ];
26
26
27
- static CGFloat const kParagraphLineHeightRatio = 1.2 ;
27
+ static CGFloat const kParagraphLineHeightRatio = 1.5 ;
28
28
29
29
static NSInteger const kShortPoetryCharacterCountOfLine = 12 ;
30
30
@@ -1211,18 +1211,6 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
1211
1211
CGFloat deltaY = prevBoundingBox.origin .y - (boundingBox.origin .y + boundingBox.size .height );
1212
1212
CGFloat deltaX = boundingBox.origin .x - (prevBoundingBox.origin .x + prevBoundingBox.size .width );
1213
1213
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
-
1226
1214
// Note that sometimes the line frames will overlap a little, then deltaY will less then 0
1227
1215
BOOL isNewLine = NO ;
1228
1216
if (deltaY > 0 ) {
@@ -1251,10 +1239,9 @@ - (void)setupOCRResult:(EZOCRResult *)ocrResult
1251
1239
if (isNeedRemoveLastDashOfText) {
1252
1240
mergedText = [mergedText substringToIndex: mergedText.length - 1 ].mutableCopy ;
1253
1241
}
1254
- } else if (isNewParagraph || isNewLine) {
1242
+ } else if (isNewLine) {
1255
1243
joinedString = [self joinedStringOfTextObservation: textObservation
1256
- prevTextObservation: prevTextObservation
1257
- isNewParagraph: isNewParagraph];
1244
+ prevTextObservation: prevTextObservation];
1258
1245
} else {
1259
1246
joinedString = @" " ; // if the same line, just join two texts
1260
1247
}
@@ -1489,9 +1476,10 @@ - (BOOL)isPoetryOftextObservations:(NSArray<VNRecognizedTextObservation *> *)tex
1489
1476
// / Get joined string of text, according to its last char.
1490
1477
- (NSString *)joinedStringOfTextObservation : (VNRecognizedTextObservation *)textObservation
1491
1478
prevTextObservation : (VNRecognizedTextObservation *)prevTextObservation
1492
- isNewParagraph : ( BOOL ) isNewParagraph {
1479
+ {
1493
1480
NSString *joinedString = @" " ;
1494
1481
BOOL needLineBreak = NO ;
1482
+ BOOL isNewParagraph = NO ;
1495
1483
1496
1484
CGRect prevBoundingBox = prevTextObservation.boundingBox ;
1497
1485
CGFloat prevLineLength = prevBoundingBox.size .width ;
@@ -1509,7 +1497,7 @@ - (NSString *)joinedStringOfTextObservation:(VNRecognizedTextObservation *)textO
1509
1497
1510
1498
BOOL hasPrevIndentation = [self hasIndentationOfTextObservation: prevTextObservation];
1511
1499
BOOL hasIndentation = [self hasIndentationOfTextObservation: textObservation];
1512
-
1500
+
1513
1501
BOOL isPrevLongText = [self isLongTextObservation: prevTextObservation isStrict: NO ];
1514
1502
1515
1503
BOOL isEqualChineseText = [self isEqualChineseTextObservation: textObservation prevTextObservation: prevTextObservation];
@@ -1895,6 +1883,20 @@ - (BOOL)hasIndentationOfTextObservation:(VNRecognizedTextObservation *)textObser
1895
1883
return hasIndentation;
1896
1884
}
1897
1885
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
+
1898
1900
- (BOOL )isEqualTextObservation : (VNRecognizedTextObservation *)textObservation
1899
1901
prevTextObservation : (VNRecognizedTextObservation *)prevTextObservation {
1900
1902
// 0.06 - 0.025
0 commit comments