コード例 #1
0
METHOD_RETURN_TYPE PDFObjectDriver::ToNumber(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    PDFObject* anObject = ObjectWrap::Unwrap<PDFObjectDriver>(args.This())->GetObject();
    if(anObject->GetType() == PDFObject::ePDFObjectInteger)
    {
        SET_FUNCTION_RETURN_VALUE(NEW_NUMBER(((PDFInteger*)anObject)->GetValue()));
    }
    else if(anObject->GetType() == PDFObject::ePDFObjectReal)
    {
        SET_FUNCTION_RETURN_VALUE(NEW_NUMBER(((PDFReal*)anObject)->GetValue()));
        
    }
    else
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
}
コード例 #2
0
METHOD_RETURN_TYPE PDFObjectDriver::ToPDFArray(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    PDFObject* anObject = ObjectWrap::Unwrap<PDFObjectDriver>(args.This())->GetObject();
    if(anObject->GetType() != PDFObject::ePDFObjectArray)
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    
	Handle<Value> newInstance = PDFArrayDriver::GetNewInstance();
    ObjectWrap::Unwrap<PDFArrayDriver>(newInstance->ToObject())->TheObject = anObject;
    SET_FUNCTION_RETURN_VALUE(newInstance);
}
コード例 #3
0
METHOD_RETURN_TYPE PDFObjectDriver::ToString(const ARGS_TYPE& args)
{
    CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;
    
    PDFObject* anObject = ObjectWrap::Unwrap<PDFObjectDriver>(args.This())->GetObject();
    std::string result;
    
    switch(anObject->GetType())
    {
        case PDFObject::ePDFObjectName:
            result = ((PDFName*)anObject)->GetValue();
            break;
        case PDFObject::ePDFObjectLiteralString:
            result = ((PDFLiteralString*)anObject)->GetValue();
            break;
        case PDFObject::ePDFObjectHexString:
            result = ((PDFHexString*)anObject)->GetValue();
            break;
        case PDFObject::ePDFObjectReal:
            result = Double(((PDFReal*)anObject)->GetValue()).ToString();
            break;
        case PDFObject::ePDFObjectInteger:
            result = LongLong(((PDFInteger*)anObject)->GetValue()).ToString();
            break;
        case PDFObject::ePDFObjectSymbol:
            result = ((PDFSymbol*)anObject)->GetValue();
            break;
        case PDFObject::ePDFObjectBoolean:
            result = ((PDFBoolean*)anObject)->GetValue() ? "true":"false";
            break;
        default:
            result = PDFObject::scPDFObjectTypeLabel[anObject->GetType()];
    }
    SET_FUNCTION_RETURN_VALUE(NEW_STRING(result.c_str()));

}
コード例 #4
0
PDFObject* PDFObjectParser::ParseNewObject(IPDFParserExtender* inParserExtender)
{
	PDFObject* pdfObject = NULL;
	std::string token;

	do
	{
		if(!GetNextToken(token))
			break;

		// based on the parsed token, and parhaps some more, determine the type of object
		// and how to parse it.

		// Boolean
		if(IsBoolean(token))
		{
			pdfObject = ParseBoolean(token);
			break;
		} 
		// Literal String
		else if(IsLiteralString(token))
		{
			pdfObject = ParseLiteralString(token,inParserExtender);
			break;
		}
		// Hexadecimal String
		else if(IsHexadecimalString(token))
		{
			pdfObject = ParseHexadecimalString(token,inParserExtender);
			break;
		}
		// NULL
		else if (IsNull(token))
		{
			pdfObject = new PDFNull();
			break;
		}
		// Name
		else if(IsName(token))
		{
			pdfObject = ParseName(token);
			break;
		}
		// Number (and possibly an indirect reference)
		else if(IsNumber(token))
		{	
			pdfObject = ParseNumber(token);
			
			// this could be an indirect reference in case this is a positive integer
			// and the next one is also, and then there's an "R" keyword
			if(pdfObject && 
				(pdfObject->GetType() == PDFObject::ePDFObjectInteger) && 
				((PDFInteger*)pdfObject)->GetValue() > 0)
			{
				// try parse version
				std::string numberToken;
				if(!GetNextToken(numberToken)) // k. no next token...cant be reference
					break;

				if(!IsNumber(numberToken)) // k. no number, cant be reference
				{
					SaveTokenToBuffer(numberToken);
					break;
				}

				PDFObject* versionObject = ParseNumber(numberToken); 
				bool isReference = false;
				do
				{
					if(!versionObject || 
                       (versionObject->GetType() != PDFObject::ePDFObjectInteger) ||
						((PDFInteger*)versionObject)->GetValue() < 0) // k. failure to parse number, or no non-negative, cant be reference
					{
						SaveTokenToBuffer(numberToken);
						break;
					}

					// try parse R keyword
					std::string keywordToken;
					if(!GetNextToken(keywordToken)) // k. no next token...cant be reference
						break;

					if(keywordToken != scR) // k. not R...cant be reference
					{
						SaveTokenToBuffer(numberToken);
						SaveTokenToBuffer(keywordToken);
						break;
					}

					isReference = true;
				}while(false);

				// if passed all these, then this is a reference
				if(isReference)
				{
					PDFObject* referenceObject = new PDFIndirectObjectReference(
														(ObjectIDType)((PDFInteger*)pdfObject)->GetValue(),
														(unsigned long)((PDFInteger*)versionObject)->GetValue());
					delete pdfObject;
					pdfObject = referenceObject;
				}
				delete versionObject;
			}
			break;
		}
		// Array
		else if(IsArray(token))
		{
			pdfObject = ParseArray(inParserExtender);
			break;
		}
		// Dictionary
		else if (IsDictionary(token))
		{
			pdfObject = ParseDictionary(inParserExtender);

			if(pdfObject)
			{
				// could be a stream. will be if the next token is the "stream" keyword
				if(!GetNextToken(token))
					break;

				if(scStream == token) 
				{
					// yes, found a stream. record current position as the position where the stream starts. 
					// [tokenizer took care that the posiiton should be that way with a special case]
					pdfObject = new PDFStreamInput((PDFDictionary*)pdfObject,mCurrentPositionProvider->GetCurrentPosition());
				}
				else
				{
					SaveTokenToBuffer(token);
				}
			}

			break;
		}
		// Symbol (legitimate keyword or error. determine if error based on semantics)
		else
			pdfObject = new PDFSymbol(token);
	}while(false);


	return pdfObject;

}