Thanks a lot for the help so far. So I was successfully able to crate a highlight annotation from text selection. Here's my code, if anyone else get similar questions.
Only one more question. in my highlight annotation, I get two rounded half circles from the left and right sides. Not sure why?
HiliteEntry hilite; | ||
hilite.offset = 50; // highlight starting 50th word | ||
AVDoc currentAVDoc = AVAppGetActiveDoc(); | ||
PDDoc currentPDDoc = AVDocGetPDDoc(currentAVDoc); | ||
AVPageView currentPageView = AVDocGetPageView(currentAVDoc); | ||
ASInt32 pageNum = AVPageViewGetPageNum(currentPageView); | ||
PDEElement pdeElement; | ||
ASFixedRect boundingRect; | ||
PDPage pdPage = PDDocAcquirePage (currentPDDoc, pageNum); | ||
PDAnnot pdAnnot; | ||
PDColorValueRec red; | |
red.space = PDDeviceRGB; | |
red.value[0] = ASInt32ToFixed(1); | |
red.value[1] = 0; | |
red.value[2] = 0; |
// highlight | |
AVPageViewSetColor(currentPageView, &red); | |
PDTextSelect textSelection = PDTextSelectCreateWordHilite(pdPage,&hilite, 1); | |
AVDocSetSelection(currentAVDoc, ASAtomFromString("Text"),(void *)textSelection, true); | |
AVPageViewDrawNow(currentPageView); | |
AVDocShowSelection (currentAVDoc); | |
// make text selection and get the bbox of the selection. | |
PDTextSelect selectedText = static_cast<PDTextSelect>(AVDocGetSelection(currentAVDoc)); | |
PDTextSelectGetBoundingRect(selectedText,&boundingRect); | |
// use the bbox to create a highight annotation QuadPoints | |
CosObj ArrayObj, RecObj; | |
CosDoc cd = PDDocGetCosDoc(currentPDDoc); | |
CosObj cosPage = PDPageGetCosObj(pdPage); | |
ArrayObj = CosNewArray(cd,false,8); | |
CosArrayPut(ArrayObj,0,CosNewFixed(cd,false, boundingRect.right)); | |
CosArrayPut(ArrayObj,1,CosNewFixed(cd,false, boundingRect.bottom)); | |
CosArrayPut(ArrayObj,2,CosNewFixed(cd,false, boundingRect.left)); | |
CosArrayPut(ArrayObj,3,CosNewFixed(cd,false, boundingRect.bottom)); | |
CosArrayPut(ArrayObj,4,CosNewFixed(cd,false, boundingRect.right)); | |
CosArrayPut(ArrayObj,5,CosNewFixed(cd,false, boundingRect.top)); | |
CosArrayPut(ArrayObj,6,CosNewFixed(cd,false, boundingRect.left)); | |
CosArrayPut(ArrayObj,7,CosNewFixed(cd,false, boundingRect.top)); | |
// for the Rect. Highlight annotations don't require, but API call to create annotation requires this key | |
RecObj = CosNewArray(cd,false,4); | |
CosArrayPut(RecObj,0,CosNewFixed(cd,false, boundingRect.left)); | |
CosArrayPut(RecObj,1,CosNewFixed(cd,false, boundingRect.right)); | |
CosArrayPut(RecObj,2,CosNewFixed(cd,false, boundingRect.bottom)); | |
CosArrayPut(RecObj,3,CosNewFixed(cd,false, boundingRect.top)); |
CosObj cosDict = CosNewDict(cd, true, 4); | ||
CosDictPutKeyString(cosDict, "Subtype", CosNewNameFromString(cd, false, "Highlight")); | ||
CosDictPutKeyString(cosDict, "QuadPoints",ArrayObj); | ||
CosDictPutKeyString(cosDict, "Rect", RecObj); | ||
pdAnnot = PDAnnotFromCosObj(cosDict); | ||
PDPageAddAnnot(pdPage,-2,pdAnnot); | ||
PDPageNotifyContentsDidChange(pdPage); | ||
PDAnnotSetColor(pdAnnot, &red); | ||
AVPageViewDrawNow (currentPageView); | ||
PDPageRelease (pdPage); |