From 6bbea4baa0c06b39b1b71f1aa6fc276789296556 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 21 Jul 2012 09:00:06 -0400 Subject: Implement QPDFObjectHandle::parse Move object parsing code from QPDF to QPDFObjectHandle and parameterize the parts of it that are specific to a QPDF object. Provide a version that can't handle indirect objects and that can be called on an arbitrary string. A side effect of this change is that the offset used when reporting invalid stream length has changed, but since the new value seems like a better value than the old one, the test suite has been updated rather than making the code backward compatible. This only effects the offset reported for invalid streams that lack /Length or have an invalid /Length key. Updated some test code and exmaples to use QPDFObjectHandle::parse. Supporting changes include adding a BufferInputSource constructor that takes a string. --- examples/pdf-create.cc | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'examples/pdf-create.cc') diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc index a9ad2389..902c6805 100644 --- a/examples/pdf-create.cc +++ b/examples/pdf-create.cc @@ -81,24 +81,28 @@ static void create_pdf(char const* filename) // Add an indirect object to contain a font descriptor for the // built-in Helvetica font. QPDFObjectHandle font = pdf.makeIndirectObject( - QPDFObjectHandle::newDictionary()); - font.replaceKey("/Type", newName("/Font")); - font.replaceKey("/Subtype", newName("/Type1")); - font.replaceKey("/Name", newName("/F1")); - font.replaceKey("/BaseFont", newName("/Helvetica")); - font.replaceKey("/Encoding", newName("/WinAnsiEncoding")); + QPDFObjectHandle::parse( + "<<" + " /Type /Font" + " /Subtype /Type1" + " /Name /F1" + " /BaseFont /Helvetica" + " /Encoding /WinAnsiEncoding" + ">>")); // Create a stream to encode our image. We don't have to set the // length or filters. QPDFWriter will fill in the length and // compress the stream data using FlateDecode by default. QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf); - QPDFObjectHandle image_dict = image.getDict(); - image_dict.replaceKey("/Type", newName("/XObject")); - image_dict.replaceKey("/Subtype", newName("/Image")); - image_dict.replaceKey("/ColorSpace", newName("/DeviceRGB")); - image_dict.replaceKey("/BitsPerComponent", newInteger(8)); - image_dict.replaceKey("/Width", newInteger(100)); - image_dict.replaceKey("/Height", newInteger(100)); + image.replaceDict(QPDFObjectHandle::parse( + "<<" + " /Type /XObject" + " /Subtype /Image" + " /ColorSpace /DeviceRGB" + " /BitsPerComponent 8" + " /Width 100" + " /Height 100" + ">>")); // Provide the stream data. ImageProvider* p = new ImageProvider(100, 100); PointerHolder provider(p); @@ -107,10 +111,8 @@ static void create_pdf(char const* filename) QPDFObjectHandle::newNull()); // Create direct objects as needed by the page dictionary. - QPDFObjectHandle procset = QPDFObjectHandle::newArray(); - procset.appendItem(newName("/PDF")); - procset.appendItem(newName("/Text")); - procset.appendItem(newName("/ImageC")); + QPDFObjectHandle procset = QPDFObjectHandle::parse( + "[/PDF /Text /ImageC]"); QPDFObjectHandle rfont = QPDFObjectHandle::newDictionary(); rfont.replaceKey("/F1", font); -- cgit v1.2.3-54-g00ecf