+ private void addImageHilight(String resGuid, QFile f) {\r
+ if (enSearch == null || enSearch.hilightWords == null || enSearch.hilightWords.size() == 0)\r
+ return;\r
+ \r
+ // Get the recognition XML that tells where to hilight on the image\r
+ Resource recoResource = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(resGuid);\r
+ QByteArray recoData = new QByteArray(recoResource.getRecognition().getBody());\r
+ String xml = recoData.toString();\r
+ \r
+ // Get a painter for the image. This is the background (the initial image).\r
+ QPixmap pix = new QPixmap(f.fileName());\r
+ QPixmap hilightedPix = new QPixmap(pix.size());\r
+ QPainter p = new QPainter(hilightedPix);\r
+ p.drawPixmap(0,0, pix);\r
+\r
+ // Create a transparent pixmap. The only non-transparent\r
+ // piece is the hilight that will be overlayed to hilight text no the background\r
+ QPixmap overlayPix = new QPixmap(pix.size());\r
+ QPainter p2 = new QPainter(overlayPix);\r
+ p2.setBackgroundMode(BGMode.TransparentMode);\r
+ p2.setBrush(QColor.yellow);\r
+ \r
+ // Get the recognition data from the note\r
+ QDomDocument doc = new QDomDocument();\r
+ doc.setContent(xml);\r
+ \r
+ // Go through all "item" nodes\r
+ QDomNodeList anchors = doc.elementsByTagName("item");\r
+ for (int i=0; i<anchors.length(); i++) {\r
+ QDomElement element = anchors.at(i).toElement();\r
+ int x = new Integer(element.attribute("x")); // x coordinate\r
+ int y = new Integer(element.attribute("y")); // y coordinate\r
+ int w = new Integer(element.attribute("w")); // width\r
+ int h = new Integer(element.attribute("h")); // height\r
+ QDomNodeList children = element.childNodes(); // all children ("t" nodes).\r
+ \r
+ // Go through the children ("t" nodes)\r
+ for (int j=0; j<children.length(); j++) {\r
+ QDomElement child = children.at(j).toElement();\r
+ if (child.nodeName().equalsIgnoreCase("t")) {\r
+ String text = child.text(); // recognition text\r
+ int weight = new Integer(child.attribute("w")); // recognition weight\r
+ if (weight >= Global.getRecognitionWeight()) { // Are we above the maximum?\r
+ \r
+ // Check to see if this word matches something we were searching for.\r
+ for (int k=0; k<enSearch.hilightWords.size(); k++) {\r
+ if (enSearch.hilightWords.get(k).equalsIgnoreCase(text))\r
+ p2.drawRect(x,y,w,h); \r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ p2.end();\r
+ \r
+ // Paint the hilight onto the background.\r
+ p.setOpacity(0.40);\r
+ p.drawPixmap(0,0, overlayPix);\r
+ p.end();\r
+ \r
+ // Save over the initial pixmap.\r
+ hilightedPix.save(f.fileName());\r
+ }\r