|
@@ -62,7 +62,7 @@ class TextColorAutoTest : AutoTest {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-#if flase // 新文档框排形式
|
|
|
+#if true // 新文档框排形式
|
|
|
|
|
|
/// 转换结果信息
|
|
|
// let resultData = NSData.init(contentsOfFile: resultPath) as! Data
|
|
@@ -170,17 +170,55 @@ class TextColorAutoTest : AutoTest {
|
|
|
|
|
|
#else // 原富文本形式
|
|
|
/// 检测信息
|
|
|
- let resultData = NSData.init(contentsOfFile: resultPath) as! Data
|
|
|
+ let resultData = NSData.init(contentsOfFile: resultPath)! as Data
|
|
|
var rDocumentAttributes:NSDictionary!
|
|
|
- let resultAttString = NSAttributedString.init(rtf: resultData, documentAttributes: &cDocumentAttributes)
|
|
|
-
|
|
|
+ let resultAttString = NSAttributedString.init(rtf: resultData, documentAttributes: &rDocumentAttributes)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ let string = resultAttString?.string
|
|
|
+
|
|
|
+
|
|
|
+ var maxCount = 0
|
|
|
+ var succCount = 0
|
|
|
+ let semaphore = DispatchSemaphore.init(value: 1)
|
|
|
+
|
|
|
+ resultAttString?.enumerateAttribute(NSAttributedString.Key.strokeColor, in: NSMakeRange(0, Int(NSString(string: string!).length)), options: longestEffectiveRangeNotRequired, using: { (color, range, stop) in
|
|
|
+ let currentString = NSString(string: string!).substring(with: range) as! NSString
|
|
|
+
|
|
|
+ let cColor = color as! NSColor
|
|
|
+ let cColorString = self.colorStringWithColor(cColor, withAlpha: false) as! NSString
|
|
|
+
|
|
|
+ let items = currentString.components(separatedBy: "[")
|
|
|
+ for it in items {
|
|
|
+ let item = it as NSString
|
|
|
+
|
|
|
+ if item.contains("Color Check(") {
|
|
|
+ maxCount = maxCount+1
|
|
|
+
|
|
|
+ let dRange = item.range(of: "Color Check(")
|
|
|
+ let mark = item.intValue
|
|
|
+ let dColorString = self.colorStringWithString(item.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)")
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CLongLong(range.location + range.length) >= CLongLong(NSString(string: string!).length)) {
|
|
|
+ semaphore.signal()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ semaphore.wait()
|
|
|
#endif
|
|
|
|
|
|
- reportString?.append(NSAttributedString.init(string: "【\(self.name())】识别字体颜色识别完成,准确率\(Float(succCount)/Float(maxCount) * 100)%%(\(succCount)/\(maxCount))\n",
|
|
|
+ reportString?.append(NSAttributedString.init(string: "【\(self.name())】识别字体颜色识别完成,准确率\(Float(succCount)/Float(maxCount) * 100)%(\(succCount)/\(maxCount))\n",
|
|
|
attributes:[.foregroundColor : NSColor.blue]))
|
|
|
}
|
|
|
|
|
@@ -230,6 +268,23 @@ class TextColorAutoTest : AutoTest {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+ func colorStringWithColor(_ color:NSColor, withAlpha:Bool) -> String? {
|
|
|
+ if color != nil {
|
|
|
+ let red = Int(color.redComponent * 255)
|
|
|
+ let green = Int(color.greenComponent * 255)
|
|
|
+ let blue = Int(color.blueComponent * 255)
|
|
|
+ let alpha = Int(color.alphaComponent * 255)
|
|
|
+
|
|
|
+ if withAlpha {
|
|
|
+ return String("(\(red),\(green),\(blue),\(alpha)")
|
|
|
+ }else {
|
|
|
+ return String("(\(red),\(green),\(blue)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
// Auto Test refrence Latest Status
|
|
|
override func autoCheck() {
|
|
|
|