PDFArray

39 views
Skip to first unread message

Jarosław Bober

unread,
Feb 16, 2013, 9:46:19 AM2/16/13
to pdfhummus-in...@googlegroups.com
Hello Gal,
I have a question regarding

I have /Rect key
with these values:
/Rect[227.77 790 506.7 806]
The problem is when there is round value then this assignment does not give me a value.

left = rectContentIterator.GetItem();

if(objectContentIterator.GetKey()->GetValue() == "Rect")
{
{
PDFObjectCastPtr<PDFArray> Rect;
Rect =(objectContentIterator.GetValue());
PDFObjectCastPtr<PDFReal> left; 
PDFObjectCastPtr<PDFReal> bottom; 
PDFObjectCastPtr<PDFReal> width; 
PDFObjectCastPtr<PDFReal> height; 

SingleValueContainerIterator<PDFObjectVector>  rectContentIterator = Rect->GetIterator();
//while(rectContentIterator.MoveNext())
{
left = rectContentIterator.GetItem();
}
if(rectContentIterator.MoveNext())
{
bottom = rectContentIterator.GetItem();
}
if(rectContentIterator.MoveNext())
{
width = rectContentIterator.GetItem();
}
if(rectContentIterator.MoveNext())
{
height = rectContentIterator.GetItem();
}
xobjectContentContext->re(left->GetValue(),bottom->GetValue(), width->GetValue() , height->GetValue());

Regards,
Jaroslaw
}

Jarosław Bober

unread,
Feb 16, 2013, 10:11:10 AM2/16/13
to pdfhummus-in...@googlegroups.com
So the question is, how do I iterate over an array which has integer and real values in it, and get iterator value in a generic manner.
I tried 
left = rectContentIterator.GetItem()->getValue(); but the compilersays that 
 "PDFObject" has no member "getValue"

Gal Kahana

unread,
Feb 17, 2013, 2:55:53 AM2/17/13
to pdfhummus-in...@googlegroups.com
Yeah...it's because i'm determining the type while parsing. if you will look at the type of the parsed object for the round values you'll see that they are of PDFInteger and not PDFReal.
worry not, there's a way out of this. use the ParsedPrimitiveHelper object. it will give you what you actually want - the end result double.

(see https://github.com/galkahana/PDF-Writer/blob/master/PDFWriter/ParsedPrimitiveHelper.h, it's a rather useful class in general, check it out)

if i modify the code to use the helper, it looks something like this:

{
PDFObjectCastPtr<PDFArray> Rect;
Rect =(objectContentIterator.GetValue());
double left = ParsedPrimitiveHelper(RefCountPtr<PDFObject>(Rect->QueryObject(0)).GetPtr()).GetDoubleValue()
double bottom = ParsedPrimitiveHelper(RefCountPtr<PDFObject>(Rect->QueryObject(1)).GetPtr()).GetDoubleValue()
double width = ParsedPrimitiveHelper(RefCountPtr<PDFObject>(Rect->QueryObject(2)).GetPtr()).GetDoubleValue()
double height = ParsedPrimitiveHelper(RefCountPtr<PDFObject>(Rect->QueryObject(3)).GetPtr()).GetDoubleValue()



xobjectContentContext->re(left,bottom, width , height);
Reply all
Reply to author
Forward
0 new messages