Пример #1
0
Файл: pdf.c Проект: db00/reader
PdfObj * PdfObj_read(PdfFile * file,char *line)
{
	ByteArray * bytearray = file->bytearray;
	PdfObj * obj = malloc(sizeof(*obj));
	memset(obj,0,sizeof(*obj));

	obj->id = atoi(line);
	printf("id:%d,",obj->id);

	if(file->numObjs < obj->id)
	{
		if(file->objs==NULL)
		{
			file->objs = malloc(obj->id*sizeof(PdfObj*));
			memset(file->objs,0,obj->id*sizeof(PdfObj*));
		}else{
			int len = obj->id*sizeof(PdfObj*);
			file->objs = realloc(file->objs,len);
			int dealed = file->numObjs*sizeof(PdfObj*);
			memset((char*)file->objs+dealed,0,len-dealed);
		}
		file->numObjs = obj->id;
	}
	file->objs[obj->id-1] = obj;



	int position = bytearray->position - strlen(line);
	int numL = getNumChars(line,'<');
	int numR = getNumChars(line,'>');

	while(numL-numR || numL==0)
	{
		if(line)free(line);line = NULL;
		line = ByteArray_readLine(bytearray);
		numL += getNumChars(line,'<');
		numR += getNumChars(line,'>');
	}

	int propertiesLen = bytearray->position - position;
	obj->properties = malloc(propertiesLen);
	bytearray->position = position;
	ByteArray_readBytes(bytearray,propertiesLen,obj->properties);

	if(obj->length==0){
		char * length = strstr(obj->properties,"/Length ");
		if(length){
			obj->length = atoi(length+strlen("/Length "));
			printf("(%d)",obj->length);
		}
	}

	if(obj->length>0)
	{
		if((line+strlen(line)-strrchr(line,'>'))<3)
		{
			if(line)free(line);line=NULL;
			line = ByteArray_readLine(bytearray);
		}

		obj->data = malloc(obj->length);
		ByteArray_readBytes(bytearray,obj->length,obj->data);
		//printf("data:%s,",obj->data);
		if(line)free(line);line=NULL;
		line = ByteArray_readLine(bytearray);
		while(strlen(line)<3){
			//printf("line:%s,",line);
			if(line)free(line);line = NULL;
			line = ByteArray_readLine(bytearray);
		}
		if(line && strncmp(line,"endstream",9)){
			printf("\nXXXXXXXXXXXXxx type_end:%s",line);
		}
	}
	if(line)free(line);line = NULL;
	line = (ByteArray_readLine(bytearray));
	if(strncmp(line,"endobj",6)){
		printf("\nXXXXXXXXXXXXxx endobj:%s",line);
	}
	//printf("endobj:%s",line);
	free(line);
	//printf("\n----------------------------------------,\n");

	if(obj->data)
	{
		size_t outsize = obj->length*10;
		char out[outsize];
		memset(out, 0,outsize);
		Text_printf(obj->data,obj->length,out,outsize);
	}

	return obj;
}
Пример #2
0
void cleanTicketNumbers(LPFIELDSRESULTS lpFieldsResults) {
	 char *resultsStr = lpFieldsResults->result;
	 int numGr, i, k;
	 int iStart, iStop;
	 char strT[10];
	 int ret;
	 int numLines = 0;

	 int thGroups = 5;
	 int numChars;
	 int beginCut = 0;
	 resultTmp[0] = 0;
	 cand2Tmp[0] = 0;
// test every line
//printf("\n\n");
//printf(resultsStr);
//printf("\n\n");
// get number of lines
	 i = 0;
	 while(1){
		if(getLine(resultsStr, i, &iStart, &iStop) < 0) break;
		numLines++;
		i++;
	 }
// test last lines
// printf("--- numLines= %d\n",numLines);

	 k = numLines-1;
	 while(k>0){
		 if(getLine(resultsStr, k, &iStart, &iStop) < 0) break;
		 if(testLineConf(lpFieldsResults, iStart, iStop) < 0)
			 numLines--;
		 else
			 break;
		 k--;
	 }

	 i = 0;
	 k = 0;
	 while(i < numLines){
		if(getLine(resultsStr, i, &iStart, &iStop) < 0) break;
           testLeftSideForLine(resultsStr, &iStart, iStop);
//printLine(resultsStr, iStart, iStop);

	    numGr = getNumberOfGroups(resultsStr, iStart, iStop);
	    beginCut = 0;
// printf("--- line i= %d; numGr= %d, iStart= %d, iStop= %d\n",i, numGr, iStart, iStop);
        numChars = getNumChars(resultsStr, iStart, iStop);
//printf("--- line i= %d; numGr= %d, numChars= %d\n",i, numGr, numChars);
        if(numGr == thGroups){
        	beginCut = testBeginCut(lpFieldsResults, iStart, iStop);
            if(beginCut > 0)
            	numGr++;
        }

//   printLine(resultsStr, iStart, iStop);

//   printf("--- line i= %d; numGr= %d, numChars= %d\n",i, numGr, numChars);
	    if(numGr > thGroups && strlen(resultsStr) > 15 && numChars < 20){
	       copyLine(lpFieldsResults, iStart, iStop);
//  printLine(resultsStr, iStart, iStop);

//    printfQuad();
//  printf("--- line i= %d; %s\n",i, result);
	       if(beginCut > 0){


//  printf("--- line i= %d; beginCut= %d\n",i, beginCut);

               strT[0] = 'A'+k;
               strT[1] = 32;
               strT[2] = 0;
               replaceChars(0, -1, strT);
	       }else{
              getFirstCharFromNumLine(&iStart, &iStop);

//  printfQuad();
//   printf("--- getFirstCharFromNumLine i= %d; iStart= %d, iStop= %d\n",i, iStart, iStop);

              if(numGr < 8 && iStart == 0 && iStop == 0 && result[1] != 32) {
                 strT[0] = 'A'+k;
                 strT[1] = 32;
                 strT[2] = 0;
                 replaceChars(0, -1, strT);
             }else{
//  	   printf("--- numGr= %d; iStart= %d, iStop= %d, result[1]= %d\n",numGr, iStart, iStop, result[1]);
                 strT[0] = 'A'+k;
                 strT[1] = 0;
                replaceChars(iStart, iStop, strT);
             }
	       }
           iStop = -1;
           ret = getFirstQPFromNumLine(&iStart, &iStop);
           if(ret >= 0) {
               replaceChars(iStart, iStop, "QP");
           }
           if( ret > 0 || numGr >6) {
              if(getSecondQPFromNumLine(&iStart, &iStop) >=0){
                 replaceChars(iStart, iStop, "QP");
              }
           }
	       addLineToTmp();
	       k++;
//printTmp();
	    }
	    i++;
	 }
	 copyResultsBack(lpFieldsResults);
}
Пример #3
0
Файл: pdf.c Проект: db00/reader
PdfTrailer * PdfTrailer_read(PdfFile * file,ByteArray * bytearray)
{
	PdfTrailer * trailer = malloc(sizeof(*trailer));
	memset(trailer,0,sizeof(*trailer));
	char * line = NULL;
	int numL = 0;
	int numR = 0;
	while(numL-numR || numL==0)
	{
		if(line)free(line);
		line = ByteArray_readLine(bytearray);
		numL += getNumChars(line,'<');
		numR += getNumChars(line,'>');
		//printf("%s",line);
		char * per = NULL;

		if(trailer->size == 0)
		{
			per = strstr(line,"/Size ");
			if(per) {
				trailer->size = atoi(per+6);
				printf("size:%d,",trailer->size);
			}
		}

		if(trailer->root == NULL)
		{
			per = strstr(line,"/Root ");
			if(per) {
				int rootId = atoi(per+6);
				printf("rootId:%d,",rootId);
				trailer->root = PdfFile_getObjById(file,rootId);
				if(trailer->root)
				{
					char * s = trailer->root->properties;
					printf("\nroot obj:\n%s\n",s);
					char *p = strstr(s,"/Pages ");
					if(p)
					{
						PdfObj * pageObj = PdfFile_getObjById(file,atoi(p+7));
						if(pageObj)
						{
							char* properties = pageObj->properties;
							printf("pages found! %s\n",properties);
						}
					}
				}
			}
		}

		if(trailer->info==NULL)
		{
			per = strstr(line,"/Info ");
			if(per) {
				int infoId = atoi(per+6);
				printf("infoId:%d,",infoId);
				trailer->info = PdfFile_getObjById(file,infoId);
				if(trailer->info)
				{
					printf("info obj found!\n");
				}
			}
		}
		if(trailer->ID==NULL)
		{
			per = strstr(line,"/ID[< ");
			if(per) {
				trailer->ID = per+6;
				if(trailer->ID)
				{
					printf("ID:%s,",trailer->ID);
				}
			}
		}
	}
	printf("\n");
	//printf("%s",line);
	free(line);
	return trailer;
}