aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pdf-create.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-07-21 15:00:06 +0200
committerJay Berkenbilt <ejb@ql.org>2012-07-21 15:06:10 +0200
commit6bbea4baa0c06b39b1b71f1aa6fc276789296556 (patch)
tree62198136a609c86029d124323be9e2ea72f88d9a /examples/pdf-create.cc
parentf3e267fce28c58039789379ba3488ad12c20a7f6 (diff)
downloadqpdf-6bbea4baa0c06b39b1b71f1aa6fc276789296556.tar.zst
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.
Diffstat (limited to 'examples/pdf-create.cc')
-rw-r--r--examples/pdf-create.cc36
1 files changed, 19 insertions, 17 deletions
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<QPDFObjectHandle::StreamDataProvider> 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);