static ACCB1 void ACCB2 wordPickAVDocDidSetSelection( AVDoc doc, ASAtom selType, void * selData, void * clientData) { if(!boolPickWords) return; if(selType != ASAtomFromString("Text")) return; wbuffer[0] = 0; PDTextSelect Text = static_cast<PDTextSelect>(selData); /* NOTE Acrobat enumerates text in the order it appears in the PDF file, which is often not the same as the order in which a person would read the text. */ PDTextSelectEnumTextProc enumProc = ASCallbackCreateProto(PDTextSelectEnumTextProc, &PDTextSelectEnumTextProcCB); DURING PDTextSelectEnumTextUCS(Text, enumProc, NULL); HANDLER ASCallbackDestroy(enumProc); return; END_HANDLER ASCallbackDestroy(enumProc); if(!ConvertBufferToUTF8()) return; GlobalData->CurMod.BeginPos = -1; strcpy_s(GlobalData->CurMod.MatchedWord, MAX_SCAN_TEXT_SIZE, buffer); GlobalData->CurMod.IgnoreScanModifierKey = true; NotifyStarDictNewScanWord(1000); }
void SetUpUI(void) { setSelectionProc = ASCallbackCreateNotification(AVDocDidSetSelection, &wordPickAVDocDidSetSelection); AVAppRegisterNotification(AVDocDidSetSelectionNSEL, gExtensionID, setSelectionProc, NULL); cbIsEnabled = ASCallbackCreateProto (AVComputeEnabledProc, &IsEnabled); cbIsMarked = ASCallbackCreateProto (AVComputeMarkedProc, &IsMarked); if (ASGetConfiguration(ASAtomFromString("CanEdit"))) SetUpToolButton(); }
static void SetUpToolButton(void) { void *WordPickIcon = GetToolButtonIcon(); AVToolBar toolBar = AVAppGetToolBar(); AVToolButton separator = AVToolBarGetButtonByName (toolBar, ASAtomFromString("Hand")); wordPickToolButton = AVToolButtonNew (ASAtomFromString("ADBE:WordPick"), WordPickIcon, true, false); cbActivateTool = ASCallbackCreateProto(AVExecuteProc, &ActivateWordPickTool); AVToolButtonSetExecuteProc (wordPickToolButton, cbActivateTool, NULL); /* pdPermCopy - permissions required to extract text from a document. In Document Properties this property is named "Content Copy or Extration". To see Document Restrictions go to Main menu -> File -> Document properties -> Security tab. If we ignore permissions here (use 0), PDTextSelectEnumTextUCS throws an exception. We will not get text anyway. */ AVToolButtonSetComputeEnabledProc (wordPickToolButton, cbIsEnabled, (void *)pdPermCopy); AVToolButtonSetComputeMarkedProc (wordPickToolButton, cbIsMarked, NULL); AVToolButtonSetHelpText (wordPickToolButton, "Toggle StarDict"); AVToolBarAddButton(toolBar, wordPickToolButton, true, separator); }
ASPathName CDocument::MakeFullPath(const char* path) { ASPathName fullPath = NULL; //Assume these are all markers of full paths if(path[0] != '/' && path[0] != '\\' && path[1] != ':') { if(baseDirectory) { #ifdef MAC_PLATFORM ASPlatformPath platformPath; ASFileSysAcquirePlatformPath(NULL, baseDirectory, ASAtomFromString("POSIXPath"), &platformPath); char* basePath = ASPlatformPathGetPOSIXPathPtr(platformPath); char fullPathString[MAXPATH]; strlcpy(fullPathString, basePath, sizeof(fullPathString)); strlcat(fullPathString, path, sizeof(fullPathString)); fullPath = ASFileSysCreatePathFromPOSIXPath(NULL, fullPathString); #else ASPlatformPath platformPath; ASFileSysAcquirePlatformPath(NULL, baseDirectory, ASAtomFromString("Cstring"), &platformPath); char* basePath = ASPlatformPathGetCstringPtr(platformPath); char fullPathString[MAXPATH]; strncpy_s(fullPathString, sizeof(fullPathString), basePath, _TRUNCATE); strcat_s(fullPathString, sizeof(fullPathString), "/"); strcat_s(fullPathString, sizeof(fullPathString), path); fullPath = ASFileSysCreatePathName(NULL, ASAtomFromString("Cstring"), fullPathString, 0); #endif } else Console::displayString("Need to set the directory using the setdir command"); } else { #ifdef MAC_PLATFORM fullPath = ASFileSysCreatePathFromPOSIXPath(NULL, path); #else fullPath = ASFileSysCreatePathName(NULL, ASAtomFromString("Cstring"), path, 0); #endif } return fullPath; }
ASPathName CDocument::MakeFullPath(const ASUTF16Val* path) { ASPathName fullPath = NULL; //Assume these are all markers of full paths if(path[0] != '/' && path[0] != '\\' && path[1] != ':') { if(baseDirectory) { ASPlatformPath platformPath; ASFileSysAcquirePlatformPath( CDocument::fileSys, baseDirectory, ASAtomFromString("WinUnicodePath"), &platformPath); const ASUTF16Val* basePath = (const ASUTF16Val*)ASPlatformPathGetCstringPtr(platformPath); ASText filePath = ASTextFromUnicode(basePath, kUTF16HostEndian); ASTextCatMany( filePath, ASTextFromUnicode(path, kUTF16HostEndian), NULL ); ASFileSys fileSys = ASGetDefaultFileSysForPath(ASAtomFromString("ASTextPath"), filePath); fullPath = ASFileSysCreatePathName(fileSys, ASAtomFromString("ASTextPath"), filePath, 0); } else Console::displayString("Need to set the directory using the setdir command"); } else { ASText asPath = ASTextFromUnicode(path, kUTF16HostEndian); fullPath = ASFileSysCreatePathName( ASGetDefaultFileSysForPath(ASAtomFromString("ASTextPath"), asPath), ASAtomFromString("ASTextPath"), asPath, 0); } return fullPath; }
ACCB1 void ACCB2 MyPluginCommand(void *clientData) { // try to get front PDF document AVDoc avDoc = AVAppGetActiveDoc(); PDDoc pdDoc = NULL; int numPages = 0; if(avDoc==NULL) { // if no doc is loaded, make a message. //strcat(str,"There is no PDF document loaded in Acrobat."); return; } else { // if a PDF is open, get its number of pages pdDoc = AVDocGetPDDoc (avDoc); numPages = PDDocGetNumPages (pdDoc); } if(pdDoc == NULL) return; // get a PDF open in front. /*CDocument document; PDDoc pdDoc = (PDDoc)document; if(pdDoc == NULL){ return; }*/ // enumerate from PDF conversion handlers to find the "rtf" handler. AVConversionEnumFromPDFConverters(myAVConversionFromPDFEnumProc, NULL); SnippetRunnerUtils::ShowDebugWindow(); string szPath = "C:\\"; CDocument::SetBaseDirectory(szPath); // save the rtf file to the snippetRunner's output files folder. ASPathName OutPath = SnippetRunnerUtils::getOutputPath(RTF_FILE); if(OutPath==NULL) OutPath = ASFileSysCreatePathName (NULL, ASAtomFromString("Cstring"), RTF_FILE, 0); if(OutPath==NULL) { AVAlertNote("Cannot open an output file."); return; } // do conversion AVConversionStatus status=AVConversionConvertFromPDFWithHandler(RightHandler, NULL,kAVConversionNoFlags, pdDoc, OutPath, ASGetDefaultFileSys(),NULL); ////////////////////////////////////////////////////////////////////// // save the rtf file to the snippetRunner's output files folder. // enumerate from PDF conversion handlers to find the "rtf" handler. AVConversionEnumFromPDFConverters(myAVConversionFromPDFEnumProc2, NULL); SnippetRunnerUtils::ShowDebugWindow(); OutPath = SnippetRunnerUtils::getOutputPath(TXT_FILE); if(OutPath==NULL) OutPath = ASFileSysCreatePathName (NULL, ASAtomFromString("Cstring"), TXT_FILE, 0); if(OutPath==NULL) { AVAlertNote("Cannot open an output file."); return; } // do conversion status=AVConversionConvertFromPDFWithHandler(RightHandler, NULL,kAVConversionNoFlags, pdDoc, OutPath, ASGetDefaultFileSys(),NULL); ///////////////////////////////////////////////////////////////////////// // check the returned status and show message /* if(status == kAVConversionSuccess) AVAlertNote("The Rtf file was saved in SnippetRunner output folder."); else if(status == kAVConversionFailed) AVAlertNote("The Rtf file conversion failed."); else if(status == kAVConversionSuccessAsync) AVAlertNote("The conversion will continue asynchronously."); else if(status == kAVConversionCancelled) AVAlertNote("The conversion was cancelled."); /* ASInt32 nStartPage, nEndPage, nToUnicode; ASBool bToUnicode; nStartPage = 1; nEndPage = numPages; nToUnicode = 0; bToUnicode = false; //bToUnicode = (nToUnicode==0)?(false):(true); // Set up WordFinder creation options record PDWordFinderConfigRec wfConfig; memset(&wfConfig, 0, sizeof(PDWordFinderConfigRec)); wfConfig.recSize = sizeof(PDWordFinderConfigRec); wfConfig.ignoreCharGaps = true; wfConfig.ignoreLineGaps = false; wfConfig.noAnnots = true; wfConfig.noEncodingGuess = true; // leave non-Roman single-byte font alone // Std Roman treatment for custom encoding; overrides the noEncodingGuess option wfConfig.unknownToStdEnc = false; wfConfig.disableTaggedPDF = false; // legacy mode WordFinder creation wfConfig.noXYSort = false; wfConfig.preserveSpaces = false; wfConfig.noLigatureExp = false; wfConfig.noHyphenDetection = false; wfConfig.trustNBSpace = false; wfConfig.noExtCharOffset = false; // text extraction efficiency wfConfig.noStyleInfo = false; // text extraction efficiency wfConfig.decomposeTbl = NULL; // Unicode character replacement wfConfig.decomposeTblSize = 0; wfConfig.charTypeTbl = NULL; // Custom char type table wfConfig.charTypeTblSize = 0; ASPathName pathName; pathName = SnippetRunnerUtils::getOutputPath("output.txt"); #ifndef MAC_PLATFORM //on the Mac ASFileSysDisplayStringFromPath returns an Mac OS 9 style path. pOutput = fopen(ASFileSysDisplayStringFromPath (NULL, pathName), "w+b"); #else ASPlatformPath platformPath; ASFileSysAcquirePlatformPath (NULL, pathName, ASAtomFromString("POSIXPath"), &platformPath); POSIXPath_Ptr path = ASPlatformPathGetPOSIXPathPtr (platformPath); pOutput = fopen(path, "w+b"); ASFileSysReleasePlatformPath(NULL, platformPath); #endif if (pOutput) { if(ExtractText(pdDoc, nStartPage - 1, nEndPage - 1, bToUnicode, &wfConfig, pOutput)) Console::displayString("Text extraction completed."); return; } else AVAlertNote("Text extraction aborted."); if (pathName) ASFileSysReleasePath(NULL, pathName); if (pOutput) fclose(pOutput); return; */ }
/** ** Return the unique ASAtom associated with your plug-in. ** @return the plug-in 's name as an ASAtom. ** ** @see ASAtomFromString */ ASAtom GetExtensionName() { return ASAtomFromString("ADBE:WordPick"); }