|
@@ -36,6 +36,11 @@ class TextColorAutoTest : AutoTest {
|
|
|
let checkAlpha = self.selectedKeys().contains("透明度")
|
|
|
let needCompare = self.selectedKeys().contains("快照对比")
|
|
|
|
|
|
+ if !checkRGB && !checkAlpha && !needCompare {
|
|
|
+ _status = .Finished
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if checkRGB || checkAlpha {
|
|
|
//需要检测颜色 或 Alpha 值 至少其一
|
|
|
if checkRGB && checkAlpha {
|
|
@@ -48,7 +53,10 @@ class TextColorAutoTest : AutoTest {
|
|
|
reportString = NSMutableAttributedString.init(string: "\n【\(String(self.fileType())) - \(self.name())】转档暂不支持 Alpha!\n",
|
|
|
attributes:[.foregroundColor : NSColor.blue])
|
|
|
|
|
|
- return
|
|
|
+ if (!needCompare) {
|
|
|
+ _status = .Finished
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,169 +96,170 @@ class TextColorAutoTest : AutoTest {
|
|
|
|
|
|
if FileManager.default.fileExists(atPath: resultPath) && success {
|
|
|
// 转换成功
|
|
|
-
|
|
|
+ if (checkRGB) {
|
|
|
#if true // 新文档框排形式
|
|
|
-
|
|
|
- /// 转换结果信息
|
|
|
- // let resultData = NSData.init(contentsOfFile: resultPath) as! Data
|
|
|
- // var rDocumentAttributes:NSDictionary!
|
|
|
- // let resultAttString = NSAttributedString.init(rtf: resultData, documentAttributes: &rDocumentAttributes)
|
|
|
- // let resultStr = NSString.init(data: resultData, encoding: 0)
|
|
|
- let resultString = try? NSString.init(contentsOfFile: resultPath, encoding: 0)
|
|
|
-
|
|
|
- // 识别颜色
|
|
|
- // \colortbl ... }
|
|
|
- let colorSRange = resultString!.range(of: "\\colortbl")
|
|
|
- var colorString = resultString!.substring(from: Int(colorSRange.location + colorSRange.length)) as NSString
|
|
|
- let colorERange = colorString.range(of: "}")
|
|
|
- colorString = colorString.substring(to: Int(colorERange.location)) as NSString
|
|
|
-
|
|
|
- let colorItems = colorString.components(separatedBy: ";") as [String]
|
|
|
- var colors = NSMutableArray() //存储的颜色数组
|
|
|
-
|
|
|
- for ci in colorItems {
|
|
|
- var colorItem = ci as! NSString
|
|
|
- if colorItem.length > 0 {
|
|
|
- colorItem = colorItem.replacingOccurrences(of: "\\red", with: "(") as NSString
|
|
|
- colorItem = colorItem.replacingOccurrences(of: "\\green", with: ",") as NSString
|
|
|
- colorItem = colorItem.replacingOccurrences(of: "\\blue", with: ",") as NSString
|
|
|
- colorItem = colorItem.replacingOccurrences(of: "\\alpha", with: ",") as NSString
|
|
|
-
|
|
|
- colors.add(self.colorStringWithString(String(colorItem), withAlpha: false))
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //识别字符串 \shptxt\shptxt ... }
|
|
|
- let pageInfoStrings = resultString!.components(separatedBy: "\\shptxt\\shptxt")
|
|
|
- var finalString = ""
|
|
|
- for pageInfoString in pageInfoStrings {
|
|
|
- let endRange = NSString(string: pageInfoString).range(of: "}")
|
|
|
- finalString = finalString.appending(NSString(string: pageInfoString).substring(to: endRange.location))
|
|
|
- }
|
|
|
-
|
|
|
- let oItems = finalString.components(separatedBy: ")") // 用 ) 区分字符段落
|
|
|
-
|
|
|
- // 识别
|
|
|
- for oi in oItems {
|
|
|
- var oItem = oi as NSString
|
|
|
- if oItem.contains("[") {
|
|
|
- oItem = oItem.replacingOccurrences(of: "Color ", with: "Color") as NSString
|
|
|
-
|
|
|
- // 识别所有颜色值, 即带 \\s 标准整形值
|
|
|
- // Detect all color values, those with \\cf tags
|
|
|
- var cColors = NSMutableArray()
|
|
|
- var tItem = oItem as NSString
|
|
|
- while (tItem.contains("\\cf")) {
|
|
|
- let range = tItem.range(of: "\\cf") as NSRange
|
|
|
- tItem = tItem.substring(from: Int(range.location + range.length)) as NSString
|
|
|
+
|
|
|
+ /// 转换结果信息
|
|
|
+ // let resultData = NSData.init(contentsOfFile: resultPath) as! Data
|
|
|
+ // var rDocumentAttributes:NSDictionary!
|
|
|
+ // let resultAttString = NSAttributedString.init(rtf: resultData, documentAttributes: &rDocumentAttributes)
|
|
|
+ // let resultStr = NSString.init(data: resultData, encoding: 0)
|
|
|
+ let resultString = try? NSString.init(contentsOfFile: resultPath, encoding: 0)
|
|
|
+
|
|
|
+ // 识别颜色
|
|
|
+ // \colortbl ... }
|
|
|
+ let colorSRange = resultString!.range(of: "\\colortbl")
|
|
|
+ var colorString = resultString!.substring(from: Int(colorSRange.location + colorSRange.length)) as NSString
|
|
|
+ let colorERange = colorString.range(of: "}")
|
|
|
+ colorString = colorString.substring(to: Int(colorERange.location)) as NSString
|
|
|
+
|
|
|
+ let colorItems = colorString.components(separatedBy: ";") as [String]
|
|
|
+ var colors = NSMutableArray() //存储的颜色数组
|
|
|
+
|
|
|
+ for ci in colorItems {
|
|
|
+ var colorItem = ci as! NSString
|
|
|
+ if colorItem.length > 0 {
|
|
|
+ colorItem = colorItem.replacingOccurrences(of: "\\red", with: "(") as NSString
|
|
|
+ colorItem = colorItem.replacingOccurrences(of: "\\green", with: ",") as NSString
|
|
|
+ colorItem = colorItem.replacingOccurrences(of: "\\blue", with: ",") as NSString
|
|
|
+ colorItem = colorItem.replacingOccurrences(of: "\\alpha", with: ",") as NSString
|
|
|
|
|
|
- let colorValue = tItem.intValue
|
|
|
+ colors.add(self.colorStringWithString(String(colorItem), withAlpha: false))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //识别字符串 \shptxt\shptxt ... }
|
|
|
+ let pageInfoStrings = resultString!.components(separatedBy: "\\shptxt\\shptxt")
|
|
|
+ var finalString = ""
|
|
|
+ for pageInfoString in pageInfoStrings {
|
|
|
+ let endRange = NSString(string: pageInfoString).range(of: "}")
|
|
|
+ finalString = finalString.appending(NSString(string: pageInfoString).substring(to: endRange.location))
|
|
|
+ }
|
|
|
+
|
|
|
+ let oItems = finalString.components(separatedBy: ")") // 用 ) 区分字符段落
|
|
|
+
|
|
|
+ // 识别
|
|
|
+ for oi in oItems {
|
|
|
+ var oItem = oi as NSString
|
|
|
+ if oItem.contains("[") {
|
|
|
+ oItem = oItem.replacingOccurrences(of: "Color ", with: "Color") as NSString
|
|
|
|
|
|
- if !cColors.contains("\(colorValue)") {
|
|
|
- cColors.add("\(colorValue)")
|
|
|
+ // 识别所有颜色值, 即带 \\s 标准整形值
|
|
|
+ // Detect all color values, those with \\cf tags
|
|
|
+ var cColors = NSMutableArray()
|
|
|
+ var tItem = oItem as NSString
|
|
|
+ while (tItem.contains("\\cf")) {
|
|
|
+ let range = tItem.range(of: "\\cf") as NSRange
|
|
|
+ tItem = tItem.substring(from: Int(range.location + range.length)) as NSString
|
|
|
+
|
|
|
+ let colorValue = tItem.intValue
|
|
|
+
|
|
|
+ if !cColors.contains("\(colorValue)") {
|
|
|
+ cColors.add("\(colorValue)")
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //识别所有 【空格 ~ \】 之间的值,并进行缝合
|
|
|
- // Detect all strings between Spaces and \ and stitch
|
|
|
- let strings = oItem.components(separatedBy: " ")
|
|
|
- var resultStr = "" as NSString
|
|
|
- for str in strings {
|
|
|
- let markStr = str as NSString
|
|
|
|
|
|
- if (markStr.contains("\\")) {
|
|
|
- let endRange = markStr.range(of: "\\")
|
|
|
- resultStr = resultStr.appending(markStr.substring(to: endRange.location)) as NSString
|
|
|
- }else {
|
|
|
- resultStr = resultStr.appending(markStr as String) as NSString
|
|
|
+ //识别所有 【空格 ~ \】 之间的值,并进行缝合
|
|
|
+ // Detect all strings between Spaces and \ and stitch
|
|
|
+ let strings = oItem.components(separatedBy: " ")
|
|
|
+ var resultStr = "" as NSString
|
|
|
+ for str in strings {
|
|
|
+ let markStr = str as NSString
|
|
|
+
|
|
|
+ if (markStr.contains("\\")) {
|
|
|
+ let endRange = markStr.range(of: "\\")
|
|
|
+ resultStr = resultStr.appending(markStr.substring(to: endRange.location)) as NSString
|
|
|
+ }else {
|
|
|
+ resultStr = resultStr.appending(markStr as String) as NSString
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 识别 Mark 值
|
|
|
- let markRange = resultStr.range(of: "[")
|
|
|
- let markValue = NSString(string: resultStr.substring(from: Int(markRange.location + markRange.length))).intValue
|
|
|
- let colorRange = resultStr.range(of: "ColorCheck")
|
|
|
- let checkColor = self.colorStringWithString(resultStr.substring(from: Int(colorRange.location + colorRange.length)), withAlpha: false)
|
|
|
- maxCount = maxCount + 1
|
|
|
-
|
|
|
- //颜色值对比
|
|
|
- if cColors.count != 1 || nil == checkColor {
|
|
|
- reportString?.append(NSAttributedString.init(string: "【\(markValue)】识别颜色出错, 文本识别颜色:\(checkColor) 对照文档颜色:\(cColors)\n",
|
|
|
- attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
|
|
- NSLog("\(resultStr):\(cColors)")
|
|
|
- }else {
|
|
|
- let colorValue = cColors[0] as! String
|
|
|
- let detectColor = colors[Int(NSString(string: colorValue).intValue)] as! NSString
|
|
|
- if detectColor.isEqual(to: checkColor) {
|
|
|
- succCount = succCount+1
|
|
|
- }else {
|
|
|
- reportString?.append(NSAttributedString.init(string: "【\(markValue)】识别颜色出错, 文本识别颜色:\(checkColor ?? "") 对照文档颜色:\(detectColor)\n",
|
|
|
+ // 识别 Mark 值
|
|
|
+ let markRange = resultStr.range(of: "[")
|
|
|
+ let markValue = NSString(string: resultStr.substring(from: Int(markRange.location + markRange.length))).intValue
|
|
|
+ let colorRange = resultStr.range(of: "ColorCheck")
|
|
|
+ let checkColor = self.colorStringWithString(resultStr.substring(from: Int(colorRange.location + colorRange.length)), withAlpha: false)
|
|
|
+ maxCount = maxCount + 1
|
|
|
+
|
|
|
+ //颜色值对比
|
|
|
+ if cColors.count != 1 || nil == checkColor {
|
|
|
+ reportString?.append(NSAttributedString.init(string: "【\(markValue)】识别颜色出错, 文本识别颜色:\(checkColor) 对照文档颜色:\(cColors)\n",
|
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
|
|
NSLog("\(resultStr):\(cColors)")
|
|
|
-
|
|
|
+ }else {
|
|
|
+ let colorValue = cColors[0] as! String
|
|
|
+ let detectColor = colors[Int(NSString(string: colorValue).intValue)] as! NSString
|
|
|
+ if detectColor.isEqual(to: checkColor) {
|
|
|
+ succCount = succCount+1
|
|
|
+ }else {
|
|
|
+ reportString?.append(NSAttributedString.init(string: "【\(markValue)】识别颜色出错, 文本识别颜色:\(checkColor ?? "") 对照文档颜色:\(detectColor)\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.red]))
|
|
|
+
|
|
|
+ NSLog("\(resultStr):\(cColors)")
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
#else // 原富文本形式
|
|
|
/// 检测信息
|
|
|
- let resultData = NSData.init(contentsOfFile: resultPath)! as Data
|
|
|
- var rDocumentAttributes:NSDictionary!
|
|
|
- let resultAttString = NSAttributedString.init(rtf: resultData, documentAttributes: &rDocumentAttributes)
|
|
|
-
|
|
|
- let string = resultAttString?.string
|
|
|
-
|
|
|
-
|
|
|
- var maxCount = 0 as Int
|
|
|
- var succCount = 0 as Int
|
|
|
- let semaphore = DispatchSemaphore.init(value: 1)
|
|
|
- let items = resultAttString!.string.components(separatedBy: "\n")
|
|
|
-
|
|
|
- for item in items {
|
|
|
- let cItem = item as String
|
|
|
- if NSString(string: cItem).contains("Color Check(") {
|
|
|
-
|
|
|
- maxCount = maxCount+1
|
|
|
-
|
|
|
- var itemRange = NSString(string: string!).range(of: cItem)
|
|
|
- let subAttrString = (resultAttString?.attributedSubstring(from: itemRange))! as NSAttributedString
|
|
|
-
|
|
|
- let keys = resultAttString?.attributeKeys
|
|
|
- let attributes = resultAttString?.attributes(at: 1, effectiveRange: &itemRange)
|
|
|
-
|
|
|
- NSLog("\(attributes)")
|
|
|
-
|
|
|
- let currentString = cItem as! NSString
|
|
|
-
|
|
|
- let cColor = subAttrString.at
|
|
|
- let cColorString = self.colorStringWithColor(cColor, withAlpha: false) as! NSString
|
|
|
-
|
|
|
- let dRange = currentString.range(of: "Color Check(") as NSRange
|
|
|
- let mRange = currentString.range(of: "[") as NSRange
|
|
|
- let markString = currentString.substring(from: Int(mRange.location+mRange.length)) as! NSString
|
|
|
- let mark = markString.intValue
|
|
|
- let dColorString = self.colorStringWithString(currentString.substring(from: Int(dRange.location + dRange.length)), withAlpha: false)! as NSString
|
|
|
-
|
|
|
- if dColorString.isEqual(to: cColorString) {
|
|
|
- succCount = succCount+1
|
|
|
- }else {
|
|
|
- reportString?.append(NSAttributedString.init(string: "【\(mark)】识别颜色出错, 文本识别颜色:\(dColorString) RTF文档颜色:\(cColorString)\n",
|
|
|
- attributes:[.foregroundColor : NSColor.red]))
|
|
|
+ let resultData = NSData.init(contentsOfFile: resultPath)! as Data
|
|
|
+ var rDocumentAttributes:NSDictionary!
|
|
|
+ let resultAttString = NSAttributedString.init(rtf: resultData, documentAttributes: &rDocumentAttributes)
|
|
|
+
|
|
|
+ let string = resultAttString?.string
|
|
|
+
|
|
|
+
|
|
|
+ var maxCount = 0 as Int
|
|
|
+ var succCount = 0 as Int
|
|
|
+ let semaphore = DispatchSemaphore.init(value: 1)
|
|
|
+ let items = resultAttString!.string.components(separatedBy: "\n")
|
|
|
+
|
|
|
+ for item in items {
|
|
|
+ let cItem = item as String
|
|
|
+ if NSString(string: cItem).contains("Color Check(") {
|
|
|
+
|
|
|
+ maxCount = maxCount+1
|
|
|
+
|
|
|
+ var itemRange = NSString(string: string!).range(of: cItem)
|
|
|
+ let subAttrString = (resultAttString?.attributedSubstring(from: itemRange))! as NSAttributedString
|
|
|
+
|
|
|
+ let keys = resultAttString?.attributeKeys
|
|
|
+ let attributes = resultAttString?.attributes(at: 1, effectiveRange: &itemRange)
|
|
|
+
|
|
|
+ NSLog("\(attributes)")
|
|
|
|
|
|
- NSLog("\(item):\(dColorString)")
|
|
|
+ let currentString = cItem as! NSString
|
|
|
|
|
|
+ let cColor = subAttrString.at
|
|
|
+ let cColorString = self.colorStringWithColor(cColor, withAlpha: false) as! NSString
|
|
|
+
|
|
|
+ let dRange = currentString.range(of: "Color Check(") as NSRange
|
|
|
+ let mRange = currentString.range(of: "[") as NSRange
|
|
|
+ let markString = currentString.substring(from: Int(mRange.location+mRange.length)) as! NSString
|
|
|
+ let mark = markString.intValue
|
|
|
+ let dColorString = self.colorStringWithString(currentString.substring(from: Int(dRange.location + dRange.length)), withAlpha: false)! as NSString
|
|
|
+
|
|
|
+ if dColorString.isEqual(to: cColorString) {
|
|
|
+ succCount = succCount+1
|
|
|
+ }else {
|
|
|
+ reportString?.append(NSAttributedString.init(string: "【\(mark)】识别颜色出错, 文本识别颜色:\(dColorString) RTF文档颜色:\(cColorString)\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.red]))
|
|
|
+
|
|
|
+ NSLog("\(item):\(dColorString)")
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- semaphore.wait()
|
|
|
+
|
|
|
+ semaphore.wait()
|
|
|
#endif
|
|
|
-
|
|
|
- reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"颜色对比完成,准确率\(Float(succCount)/Float(maxCount) * 100)%(\(succCount)/\(maxCount))\n",
|
|
|
- attributes:[.foregroundColor : NSColor.blue]))
|
|
|
+
|
|
|
+ reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"颜色对比完成,准确率\(Float(succCount)/Float(maxCount) * 100)%(\(succCount)/\(maxCount))\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.blue]))
|
|
|
+ }
|
|
|
|
|
|
|
|
|
if needCompare {
|
|
@@ -264,8 +273,6 @@ class TextColorAutoTest : AutoTest {
|
|
|
let thumbnailQueue = DispatchQueue.global()
|
|
|
thumbnailQueue.async {
|
|
|
// processSuccess =
|
|
|
- ProcessThumbnal.process(resultPath, desPath: rComparePath, outputSize: CGSize.init(width: 2048, height: 2048))
|
|
|
-
|
|
|
if (ProcessThumbnal.process(resultPath, desPath: rComparePath, outputSize: CGSize.init(width: 2048, height: 2048)) &&
|
|
|
FileManager.default.fileExists(atPath: rComparePath)) {
|
|
|
|