Пример #1
0
wxPdfParser::wxPdfParser(const wxString& filename, const wxString& password)
{
  m_objectQueue     = new wxPdfObjectQueue();
  m_objectQueueLast = m_objectQueue;
  m_objectMap       = new wxPdfObjectMap();
  m_objStmCache     = new wxPdfObjStmMap();
  m_tokens  = NULL;
  m_trailer = NULL;
  m_root    = NULL;
  m_useRawStream = false;
  m_cacheObjects = true;

  m_encrypted = false;
  m_decryptor = NULL;

  m_filename = filename;
  m_password = password;

  wxString fileURL = filename;
  wxURI uri(filename);
  if (!uri.HasScheme())
  {
    fileURL = wxFileSystem::FileNameToURL(filename);
  }
  m_pdfFile = wxPdfParser::GetFileSystem()->OpenFile(fileURL);
  if (m_pdfFile != NULL)
  {
    m_tokens = new wxPdfTokenizer(m_pdfFile->GetStream());
    m_initialized = ParseDocument();
  }
}
Пример #2
0
	Bool CXmlFile::ParseData(const void* pData, Size_t iSize, PVoid pDoc)
	{
		if (!pData || iSize <=0 || !pDoc)
			return false;

		//解析文档
		return ParseDocument(pDoc, pData);
	}
Пример #3
0
void LibraryParser::Parse() {
	TiXmlDocument doc(mFname.c_str() );
	bool loadSuccess = doc.LoadFile() ;
	if ( !loadSuccess ) {
		cout << "The Xml file "<< mFname<< "  could not be loaded correctly "
				<< endl ;
		exit( 1) ;
		return;
	} else {
		ParseDocument( &doc ) ;
	}
}
Пример #4
0
 //--------------------------------------------------
 //--------------------------------------------------
 XMLUPtr ReadDocument(StorageLocation in_storageLocation, const std::string& in_filePath)
 {
     Core::FileStreamSPtr stream = Application::Get()->GetFileSystem()->CreateFileStream(in_storageLocation, in_filePath, Core::FileMode::k_read);
     if (stream != nullptr && stream->IsOpen() == true && stream->IsBad() == false)
     {
         std::string contents;
         stream->GetAll(contents);
         
         XMLUPtr document = ParseDocument(contents);
         return document;
     }
     
     return XMLUPtr();
 }
Пример #5
0
int XMLDocument::ParseFromBuffer(const char * buf)
{
    if (buffer!=NULL) 
    {
        hasError=true;
        Error="Already parsed";
        return hasError;
    }
    buffer=(char*) buf;
    bufferPos=buffer;
    currentChar=*bufferPos;
    currentLine=1;
    currentColumn=1;
    return ParseDocument();
}
Пример #6
0
	Bool CXmlFile::ParseFile(const AString& sFile, PVoid pDoc)
	{
		CDiskFile xFile;
		if (!pDoc || !xFile.Open(sFile))
			return false;

		Size_t iSize = (Size_t)(xFile.GetFileSize() + 8);
		Char* pData	 = (Char*)UtilMalloc(iSize);
		CScope::CMallocPtr scope(pData);
		memset(pData, 0, iSize);
		iSize = (Size_t)xFile.Read(pData, xFile.GetFileSize());
		xFile.Close();

		//解析文档
		return ParseDocument(pDoc, pData);
	}
gfxSVGGlyphsDocument::gfxSVGGlyphsDocument(const uint8_t *aBuffer, uint32_t aBufLen,
                                           hb_blob_t *aCmapTable)
{
    mGlyphIdMap.Init();
    ParseDocument(aBuffer, aBufLen);
    if (!mDocument) {
        NS_WARNING("Could not parse SVG glyphs document");
        return;
    }

    Element *root = mDocument->GetRootElement();
    if (!root) {
        NS_WARNING("Could not parse SVG glyphs document");
        return;
    }

    nsresult rv = SetupPresentation();
    if (NS_FAILED(rv)) {
        NS_WARNING("Couldn't setup presentation for SVG glyphs document");
        return;
    }

    FindGlyphElements(root, aCmapTable);
}
Пример #8
0
bool BaseMediaDocument::Process() {
	double startTime = 0;
	double endTime = 0;
	GETCLOCKS(startTime);

	//1. Compute the names
	_mediaFilePath = (string) _metadata[META_SERVER_FULL_PATH];
	_metaFilePath = _mediaFilePath + "."MEDIA_TYPE_META;
	_seekFilePath = _mediaFilePath + "."MEDIA_TYPE_SEEK;
	_keyframeSeek = (bool)_metadata[CONF_APPLICATION_KEYFRAMESEEK];
	_seekGranularity = (uint32_t) _metadata[CONF_APPLICATION_SEEKGRANULARITY];

	//1. Open the media file
#ifdef HAS_MMAP
	if (!_mediaFile.Initialize(_mediaFilePath, 4 * 1024 * 1024, true)) {
		FATAL("Unable to open media file: %s", STR(_mediaFilePath));
		return false;
	}
#else
	if (!_mediaFile.Initialize(_mediaFilePath)) {
		FATAL("Unable to open media file: %s", STR(_mediaFilePath));
		return false;
	}
#endif

	//4. Read the document
	if (!ParseDocument()) {
		FATAL("Unable to parse document");
		return false;
	}

	//5. Build the frames
	if (!BuildFrames()) {
		FATAL("Unable to build frames");
		return false;
	}

	//6. Save the seek file
	if (!SaveSeekFile()) {
		FATAL("Unable to save seeking file");
		return false;
	}

	//7. Build the meta
	if (!SaveMetaFile()) {
		FATAL("Unable to save meta file");
		return false;
	}

	GETCLOCKS(endTime);

	INFO("%"PRIz"u frames computed in %.2f seconds at a speed of %.2f FPS",
			_frames.size(),
			(endTime - startTime) / (double) CLOCKS_PER_SECOND,
			(double) _frames.size() / ((endTime - startTime) / (double) CLOCKS_PER_SECOND));
	if (_frames.size() != 0) {
		uint32_t totalSeconds = (uint32_t) (((uint32_t) _frames[_frames.size() - 1].absoluteTime) / 1000);
		uint32_t hours = totalSeconds / 3600;
		uint32_t minutes = (totalSeconds - hours * 3600) / 60;
		uint32_t seconds = (totalSeconds - hours * 3600 - minutes * 60);
		INFO("File size: %"PRIu64" bytes; Duration: %u:%u:%u (%u sec); Optimal bandwidth: %.2f kb/s",
				_mediaFile.Size(),
				hours, minutes, seconds,
				totalSeconds,
				(double) _streamCapabilities.bandwidthHint);
	}

	moveFile(_seekFilePath + ".tmp", _seekFilePath);
	moveFile(_metaFilePath + ".tmp", _metaFilePath);

	chmod(STR(_seekFilePath), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
	chmod(STR(_metaFilePath), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);

	return true;
}
Пример #9
0
prim::XML::Parser::Error Representation::fromString(prim::String& source)
{
  return ParseDocument(source);
}
Пример #10
0
int main(int argc,char **argv)
{
 URL *Url;
 URL **list,*refresh;
 int j;

 if(argc==1)
   {fprintf(stderr,"usage: test-doc URL < contents-of-url\n");return(1);}

 StderrLevel=ExtraDebug;

 InitErrorHandler("test-doc",0,1);

 InitConfigurationFile("./wwwoffle.conf");

 init_io(STDERR_FILENO);

 if(ReadConfigurationFile(STDERR_FILENO))
    PrintMessage(Fatal,"Error in configuration file 'wwwoffle.conf'.");

 finish_io(STDERR_FILENO);

 Url=SplitURL(argv[1]);

 init_io(0);

 ParseDocument(0,Url,1);

 if((refresh=GetReference(RefMetaRefresh)))
    printf("Refresh = %s\n",refresh->file);

 if((list=GetReferences(RefStyleSheet)))
    for(j=0;list[j];j++)
       printf("StyleSheet = %s\n",list[j]->file);

 if((list=GetReferences(RefImage)))
    for(j=0;list[j];j++)
       printf("Image = %s\n",list[j]->file);

 if((list=GetReferences(RefFrame)))
    for(j=0;list[j];j++)
       printf("Frame = %s\n",list[j]->file);

 if((list=GetReferences(RefScript)))
    for(j=0;list[j];j++)
       printf("Script = %s\n",list[j]->file);

 if((list=GetReferences(RefObject)))
    for(j=0;list[j];j++)
       printf("Object = %s\n",list[j]->file);

 if((list=GetReferences(RefInlineObject)))
    for(j=0;list[j];j++)
       printf("InlineObject = %s\n",list[j]->file);

 if((list=GetReferences(RefLink)))
    for(j=0;list[j];j++)
       printf("Link = %s\n",list[j]->file);

 FreeURL(Url);

 finish_io(0);

 return(0);
}
Пример #11
0
RTFStatus RTFReader::Parse(void)
{
	RTFStatus t_status;
	t_status = kRTFStatusSuccess;
			
	while(t_status == kRTFStatusSuccess)
	{
		RTFToken t_token;
		int4 t_value;
		
		if (m_input_skip_count > 0)
		{
			while(m_input_skip_count > 0)
			{
				t_status = ParseToken(t_token, t_value);
				if (t_status != kRTFStatusSuccess)
					break;

				if (t_token == kRTFTokenEnd || t_token == kRTFTokenBeginGroup || t_token == kRTFTokenEndGroup)
				{
					m_input_skip_count = 0;
					break;
				}

				if ((t_token & kRTFTokenMask) == kRTFTokenBin)
					m_input += t_value;

				m_input_skip_count -= 1;
			}
		}

		if (t_status == kRTFStatusSuccess)
			t_status = ParseToken(t_token, t_value);

		if (t_status != kRTFStatusSuccess)
			break;

		if (t_token == kRTFTokenEnd)
			break;
			
		if (t_token == kRTFTokenBeginGroup)
			t_status = m_state . Save();
		else if (t_token == kRTFTokenEndGroup)
		{
			// Take into account implementation of 'destinations'.
			bool t_was_list;
			t_was_list = m_state . GetDestination() == kRTFDestinationLegacyList;

			bool t_was_list_text;
			t_was_list_text = m_state . GetDestination() == kRTFDestinationListText;

			bool t_was_field;
			t_was_field = m_state . GetDestination() == kRTFDestinationFldInst;

			// MW-2014-01-08: [[ Bug 11627 ]] If the paragraph attributes have changed then
			//   force a flush so that a new paragraph with said attributes is created. [ This
			//   isn't 100% correct from my reading of the RTF Spec - really paragraph attrs
			//   should be set on the current paragraph as the paragraph is parsed, rather than
			//   before the first text is emitted - however due to the way LiveCode and Word Processors
			//   generate RTF, this at least makes things roundtrip ].
			if (m_state . HasParagraphChanged())
				Flush(true);

			t_status = m_state . Restore();

			if (t_was_list)
			{
				m_state . SetListStyle(m_list_style);
				m_state . SetListLevel(m_list_level);
			}
			else if (t_was_list_text)
			{
				if (m_list_skip)
					m_state . SetListStyle(kMCTextListStyleSkip);
			}
			else if (t_was_field && m_state . GetDestination() != kRTFDestinationFldInst)
			{
				ProcessField();
			}

			m_attributes_changed = true;
		}
		else if ((t_token & kRTFTokenMask) == kRTFTokenBin)
		{
			m_input_binary_count = t_value;
			m_input_state = kRTFInputStateBinary;
		}
		else switch(m_state . GetDestination())
		{
		case kRTFDestinationSkip:
			// If the skipped destination is in fact the 'list' destination then
			// handle it. We ignore 'pn' destinations if we have a listtable though.
			if (t_token == kRTFTokenLegacyList && m_lists . Count() == 0)
			{
				m_list_style = kMCTextListStyleNone;
				m_list_level = 0;
				m_state . SetDestination(kRTFDestinationLegacyList);
			}
			else if (t_token == kRTFTokenListTable)
				m_state . SetDestination(kRTFDestinationListTable);
			else if (t_token == kRTFTokenListOverrideTable)
				m_state . SetDestination(kRTFDestinationListOverrideTable);
			else if (t_token == kRTFTokenFldInst)
				m_state . SetDestination(kRTFDestinationFldInst);
		break;
		
		case kRTFDestinationNormal:
			t_status = ParseDocument(t_token, t_value);
		break;
		
		case kRTFDestinationFontTable:
			t_status = ParseFontTable(t_token, t_value);
		break;
		
		case kRTFDestinationColorTable:
			t_status = ParseColorTable(t_token, t_value);
		break;

		case kRTFDestinationLegacyList:
			t_status = ParseLegacyList(t_token, t_value);
		break;

		case kRTFDestinationLegacyListPrefix:
			t_status = ParseLegacyListPrefix(t_token, t_value);
		break;
				
		case kRTFDestinationListTable:
			t_status = ParseListTable(t_token, t_value);
		break;
				
		case kRTFDestinationListTableLevelText:
			t_status = ParseListTableLevelText(t_token, t_value);
		break;
				
		case kRTFDestinationListOverrideTable:
			t_status = ParseListOverrideTable(t_token, t_value);
		break;

		case kRTFDestinationListText:
			t_status = ParseListText(t_token, t_value);
		break;

		case kRTFDestinationField:
		break;

		case kRTFDestinationFldInst:
			t_status = ParseFldInst(t_token, t_value);
		break;
		}
	}
	
	return t_status;
}
Пример #12
0
bool BaseMediaDocument::Process() {
	double startTime = 0;
	double endTime = 0;
	GETCLOCKS(startTime, double);

	//1. Compute the names
	_mediaFilePath = _metadata.mediaFullPath();
	_metaFilePath = _metadata.metaFileFullPath();
	_seekFilePath = _metadata.seekFileFullPath();
	_keyframeSeek = _metadata.storage().keyframeSeek();
	_seekGranularity = _metadata.storage().seekGranularity();

	//1. Open the media file
	if (!GetFile(_mediaFilePath, 4 * 1024 * 1024, _mediaFile)) {
		FATAL("Unable to open media file: %s", STR(_mediaFilePath));
		return false;
	}

	//4. Read the document
	if (!ParseDocument()) {
		FATAL("Unable to parse document");
		return false;
	}

	//5. Build the frames
	if (!BuildFrames()) {
		FATAL("Unable to build frames");
		return false;
	}

	//6. Save the seek file
	if (!SaveSeekFile()) {
		FATAL("Unable to save seeking file");
		return false;
	}

	//7. Build the meta
	if (!SaveMetaFile()) {
		FATAL("Unable to save meta file");
		return false;
	}

	GETCLOCKS(endTime, double);

	uint64_t framesCount = _audioSamplesCount + _videoSamplesCount;
	if (framesCount == 0)
		framesCount = (uint64_t) _frames.size();

	INFO("%"PRIu64" frames computed in %.2f seconds at a speed of %.2f FPS",
			framesCount,
			(endTime - startTime) / (double) CLOCKS_PER_SECOND,
			(double) framesCount / ((endTime - startTime) / (double) CLOCKS_PER_SECOND));
	if (_frames.size() != 0) {
		uint32_t totalSeconds = (uint32_t) (((uint32_t) _frames[_frames.size() - 1].dts) / 1000);
		uint32_t hours = totalSeconds / 3600;
		uint32_t minutes = (totalSeconds - hours * 3600) / 60;
		uint32_t seconds = (totalSeconds - hours * 3600 - minutes * 60);
		INFO("File size: %"PRIu64" bytes; Duration: %u:%u:%u (%u sec); Optimal bandwidth: %.2f kB/s",
				_mediaFile.Size(),
				hours, minutes, seconds,
				totalSeconds,
				(double) _streamCapabilities.GetTransferRate() / 8192);
	}

	moveFile(_seekFilePath + ".tmp", _seekFilePath);
	moveFile(_metaFilePath + ".tmp", _metaFilePath);

	chmod(STR(_seekFilePath), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
	chmod(STR(_metaFilePath), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);

	return true;
}