Skip to content

Commit 3855c27

Browse files
Merge pull request #733 from dynamsoft-docs/preview
update to internal commit 55276328
2 parents 141d0f5 + e97c790 commit 3855c27

File tree

3 files changed

+136
-10
lines changed

3 files changed

+136
-10
lines changed

faq/general/unprintable-character.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Since `barcodeText` is a string value that generated from the `barcodeBytes`, is
2222

2323
<div class="sample-code-prefix template2"></div>
2424
>- C++
25+
>- Android
26+
>- Objective-C
27+
>- Swift
2528
>
2629
>
2730
```c++
@@ -96,3 +99,127 @@ int main()
9699
return 0;
97100
}
98101
```
102+
>
103+
```java
104+
mRouter.addResultReceiver(new CapturedResultReceiver() {
105+
@Override
106+
// Implement the callback method to receive DecodedBarcodesResult.
107+
// The method returns a DecodedBarcodesResult object that contains an array of BarcodeResultItems.
108+
// BarcodeResultItems is the basic unit from which you can get the basic info of the barcode like the barcode text and barcode format.
109+
public void onDecodedBarcodesReceived(DecodedBarcodesResult result) {
110+
process = new ProcessBarcodeResultUtil();
111+
if (result!=null && result.getItems().length!=0){
112+
for (int i=0; i< result.getItems().length; i++){
113+
// The return value is the modified barcode text.
114+
String processedResult = process.processBarcodeByte(result.getItems().getBytes(),ProcessBarcodeResultUtil.ProcessNonPrintingCharsMode.PNPCM_REMOVE,true);
115+
Log.i("ProcessByte", "onDecodedBarcodesReceived: processeResult = "+processedResult);
116+
}
117+
}
118+
}
119+
});
120+
// Create a ProcessBarcodeResultUtil class
121+
public class ProcessBarcodeResultUtil {
122+
enum ProcessNonPrintingCharsMode{
123+
PNPCM_KEEP,
124+
PNPCM_REMOVE,
125+
PNPCM_CONVERT
126+
}
127+
final HashMap<Integer, String> charValueToStringDict = new HashMap<Integer, String>();
128+
ProcessBarcodeResultUtil(){
129+
final int[] NonPrintingAsciiCharsValue = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,127};
130+
final String[] NonPrintingAsciiCharsString = {
131+
"{NUL}","{SOH}","{STX}","{ETX}","{EOT}","{ENQ}","{ACK}","{BEL}","{BS}","{HT}","{LF}","{VT}","{FF}","{CR}","{SO}","{SI}",
132+
"{DLE}","{DC1}","{DC2}","{DC3}","{DC4}","{NAK}","{SYN}","{ETB}","{CAN}","{EM}","{SUB}","{ESC}","{FS}","{GS}","{RS}","{US}","{DEL}"
133+
};
134+
for (int i = 0; i < 33; ++i){
135+
charValueToStringDict.put(NonPrintingAsciiCharsValue[i], NonPrintingAsciiCharsString[i]);
136+
}
137+
}
138+
public String processBarcodeByte(byte[] barcodeByte, ProcessNonPrintingCharsMode mode, boolean keepLineBreak){
139+
StringBuilder processedResult = new StringBuilder();
140+
for (int i=0; i<barcodeByte.length; i++){
141+
int byteValue = (int)barcodeByte[i];
142+
if ((!charValueToStringDict.containsKey(byteValue)) || ((byteValue == 10 || byteValue == 13) && keepLineBreak) || mode == ProcessNonPrintingCharsMode.PNPCM_KEEP){
143+
processedResult.append((char)barcodeByte[i]);
144+
}
145+
else if(mode == ProcessNonPrintingCharsMode.PNPCM_CONVERT){
146+
processedResult.append(charValueToStringDict.get(byteValue));
147+
}
148+
}
149+
return processedResult.toString();
150+
}
151+
}
152+
```
153+
>
154+
```objc
155+
typedef NS_ENUM(NSInteger,EnumResultProcessMode)
156+
{
157+
RPM_KEEP = 0,
158+
RPM_CONVERT = 1,
159+
RPM_REMOVE = 2
160+
};
161+
...
162+
- (void)onDecodedBarcodesReceived:(DSDecodedBarcodesResult *)result {
163+
if (result.items.count > 0) {
164+
for (DSBarcodeResultItem *item in result.items) {
165+
NSString *modifiedBarcodeText = [self processResult:item.bytes mode:RPM_CONVERT isBreaklineKept:NO];
166+
msgText = [msgText stringByAppendingString:[NSString stringWithFormat:@"\nFormat: %@\nText: %@\n", item.formatString, modifiedBarcodeText]];
167+
}
168+
}
169+
}
170+
- (NSString *)processBarcodeBytes:(NSData *)byte
171+
mode:(EnumResultProcessMode)mode
172+
isBreaklineKept:(BOOL)isKept{
173+
NSArray<NSNumber*>* _nonPrintingAsciiCharsKey = @[@0,@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,@24,@25,@26,@27,@28,@29,@30,@31,@127];
174+
NSArray<NSString*>* _nonPrintingAsciiCharsString = @[@"{NUL}",@"{SOH}",@"{STX}",@"{ETX}",@"{EOT}",@"{ENQ}",@"{ACK}",@"{BEL}",@"{BS}",@"{HT}",@"{LF}",@"{VT}",@"{FF}",@"{CR}",@"{SO}",@"{SI}",@"{DLE}",@"{DC1}",@"{DC2}",@"{DC3}",@"{DC4}",@"{NAK}",@"{SYN}",@"{ETB}",@"{CAN}",@"{EM}",@"{SUB}",@"{ESC}",@"{FS}",@"{GS}",@"{RS}",@"{US}",@"{DEL}"];
175+
NSMapTable<NSNumber*,NSString *> * _charValueToStringDict = [NSMapTable strongToStrongObjectsMapTable];
176+
for (int i=0; i<_nonPrintingAsciiCharsKey.count;i++){
177+
[_charValueToStringDict setObject:_nonPrintingAsciiCharsString[i] forKey:_nonPrintingAsciiCharsKey[i]];
178+
}
179+
const char* _Nonnull barcodeByteChar = byte.bytes;
180+
NSString *processedText = @"";
181+
for (int i=0;i<byte.length;i++){
182+
if ((isKept && (barcodeByteChar[i]==10 || barcodeByteChar[i]==13)) || mode==RPM_KEEP || ((int)barcodeByteChar[i]>31 && (int)barcodeByteChar[i]!=127 && (int)barcodeByteChar[i]!=0)){
183+
NSString *nextString = [NSString stringWithFormat:@"%c",barcodeByteChar[i]];
184+
processedText = [processedText stringByAppendingString:nextString];
185+
}
186+
else if (mode == RPM_CONVERT){
187+
NSNumber *keyValue = [[NSNumber alloc] initWithInt:(int)barcodeByteChar[i]];
188+
NSString *nextString = [_charValueToStringDict objectForKey:@2];
189+
processedText = [processedText stringByAppendingString:nextString];
190+
}
191+
}
192+
return processedText;
193+
}
194+
```
195+
>
196+
```swift
197+
enum EnumResultProcessMode{
198+
case keep
199+
case convert
200+
case remove
201+
}
202+
func onDecodedBarcodesReceived(_ result: DecodedBarcodesResult) {
203+
if let items = result.items, items.count > 0 {
204+
for item in items {
205+
let processedBarcodeText = processBarcodeBytes(byte: item.bytes, processMode: EnumResultProcessMode.convert, isKeep: true)
206+
item.barcodeText = processedBarcodeText
207+
}
208+
}
209+
}
210+
private func processBarcodeBytes(byte:Data, processMode:EnumResultProcessMode, isKeep:Bool) -> String{
211+
let charValueToStringDict:NSDictionary = [0:"{NUL}",1:"{SOH}",2:"{STX}",3:"{ETX}",4:"{EOT}",5:"{ENQ}",6:"{ACK}",7:"{BEL}",8:"{BS}",9:"{HT}",10:"{LF}",11:"{VT}",12:"{FF}",13:"{CR}",14:"{SO}",15:"{SI}",16:"{DLE}",17:"{DC1}",18:"{DC2}",19:"{DC3}",20:"{DC4}",21:"{NAK}",22:"{SYN}",23:"{ETB}",24:"{CAN}",25:"{EM}",26:"{SUB}",27:"{ESC}",28:"{FS}",29:"{GS}",30:"{RS}",31:"{US}",127:"{DEL}"]
212+
var processedString = ""
213+
for i in 0...byte.count-1{
214+
if ((isKeep && ((byte[i]==10) || (byte[i]==13))) || (processMode == EnumResultProcessMode.keep) || ((byte[i]>31) && (byte[i] != 127) && (byte[i] != 0))){
215+
let nextText:String = String(bytes: [byte[i]], encoding: String.Encoding.utf8)!
216+
processedString += nextText as String
217+
}
218+
else if (processMode == EnumResultProcessMode.convert){
219+
let nextText:NSString = charValueToStringDict.object(forKey: byte[i]) as! NSString
220+
processedString += nextText as String
221+
}
222+
}
223+
return processedString
224+
}
225+
```

programming/features/read-images-with-lots-of-text.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ Below is an example illustrating how to configure the parameters to control text
5252
"ImageParameterOptions": [
5353
{
5454
"Name": "IP_0",
55-
"TextDetectionMode": [
56-
{
57-
"Mode": "TTDM_LINE",
58-
"Direction": "HORIZONTAL",
59-
"CharHeightRange": [1, 100, 1],
60-
"MaxSpacingInALine": -1,
61-
"Sensitivity": 3
62-
}
63-
],
55+
"TextDetectionMode":
56+
{
57+
"Mode": "TTDM_LINE",
58+
"Direction": "UNKNOWN",
59+
"CharHeightRange": [1, 100, 1],
60+
"MaxSpacingInALine": -1,
61+
"Sensitivity": 3
62+
},
6463
"IfEraseTextZone": 1
6564
}
6665
]

release-notes/dbr-rn-10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ noTitleIndex: true
3333
| Versions | Available Editions |
3434
| -------- | ------------------ |
3535
| 10.0.21 | [Android]({{ site.android_release_notes }}android-10.html#10021-12122023){:target="_blank"} / [iOS]({{ site.oc_release_notes }}ios-10.html#10021-12122023){:target="_blank"} |
36-
| 10.0.20 | [C++]({{ site.cpp_release_notes}}cpp-10.html#10020-10262023){:target="_blank"} / [Android]({{ site.android_release_notes }}android-10.html#10020-10262023){:target="_blank"} / [iOS]({{ site.oc_release_notes }}ios-10.html#10020-10262023){:target="_blank"} |
36+
| 10.0.20 | [C++]({{ site.cpp_release_notes}}cpp-10.html#10020-10262023){:target="_blank"} / [Android]({{ site.android_release_notes }}android-10.html#10020-10262023){:target="_blank"} / [iOS]({{ site.oc_release_notes }}ios-10.html#10020-10262023){:target="_blank"} / [JavaScript]({{ site.js_release_notes }}js-10.html#10020-01292024{:target="_blank"}) |
3737
| 10.0.10 | [C++]({{ site.cpp_release_notes}}cpp-10.html#10010-08082023){:target="_blank"} |
3838
| 10.0.0 | [C++]({{ site.cpp_release_notes}}cpp-10.html#1000-07042023){:target="_blank"} |

0 commit comments

Comments
 (0)