/** \class SkPDFCatalog
- The PDF catalog object manages object numbers and when emitted to the
- PDF stream, indexes all the objects in the file by offset.
+ The PDF catalog manages object numbers and file offsets. It is used
+ to create the PDF cross reference table.
*/
class SkPDFCatalog {
public:
/** Create a PDF catalog.
*/
- SkPDFCatalog()
- : fNextObjNum(1),
- fStartedAssigningObjNums(false),
- fAssigningFirstPageObjNums(false) {
- }
- virtual ~SkPDFCatalog() {}
+ SkPDFCatalog();
+ ~SkPDFCatalog();
/** Add the passed object to the catalog.
* @param obj The object to add.
public:
/** Create a PDF object.
*/
- SkPDFObject() {}
- virtual ~SkPDFObject() {}
+ SkPDFObject();
+ virtual ~SkPDFObject();
/** Subclasses must implement this method to print the object to the
* PDF file.
/** Create a reference to an existing SkPDFObject.
* @param obj The object to reference.
*/
- explicit SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {}
- virtual ~SkPDFObjRef() {}
+ explicit SkPDFObjRef(SkPDFObject* obj);
+ virtual ~SkPDFObjRef();
// The SkPDFObject interface.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
/** Create a PDF integer (usually for indirect reference purposes).
* @param value An integer value between 2^31 - 1 and -2^31.
*/
- SkPDFInt(int32_t value) : fValue(value) {}
- virtual ~SkPDFInt() {}
+ explicit SkPDFInt(int32_t value);
+ virtual ~SkPDFInt();
// The SkPDFObject interface.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
/** Create a PDF real number.
* @param value A real value.
*/
- SkPDFScalar(SkScalar value) : fValue(value) {}
- virtual ~SkPDFScalar() {}
+ explicit SkPDFScalar(SkScalar value);
+ virtual ~SkPDFScalar();
// The SkPDFObject interface.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
/** Create a PDF string. Maximum length (in bytes) is 65,535.
* @param value A string value.
*/
- SkPDFString(const char value[]);
- SkPDFString(const SkString& value);
- virtual ~SkPDFString() {}
+ explicit SkPDFString(const char value[]);
+ explicit SkPDFString(const SkString& value);
+ virtual ~SkPDFString();
// The SkPDFObject interface.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
private:
- static const int kMaxLen = 65535;
+ static const uint32_t kMaxLen = 65535;
const SkString fValue;
/** Create a PDF name object. Maximum length is 127 bytes.
* @param value The name.
*/
- SkPDFName(const char name[]);
- SkPDFName(const SkString& name);
- virtual ~SkPDFName() {}
+ explicit SkPDFName(const char name[]);
+ explicit SkPDFName(const SkString& name);
+ virtual ~SkPDFName();
// The SkPDFObject interface.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
private:
- static const int kMaxLen = 127;
+ static const uint32_t kMaxLen = 127;
const SkString fValue;
- SkString formatName(const SkString& input);
+ static SkString formatName(const SkString& input);
};
/** \class SkPDFArray
public:
/** Create a PDF array. Maximum length is 8191.
*/
- SkPDFArray() {}
+ SkPDFArray();
virtual ~SkPDFArray();
// The SkPDFObject interface.
public:
/** Create a PDF dictionary. Maximum number of entries is 4095.
*/
- SkPDFDict() {}
+ SkPDFDict();
virtual ~SkPDFDict();
// The SkPDFObject interface.
#include "SkPDFTypes.h"
#include "SkStream.h"
+SkPDFCatalog::SkPDFCatalog()
+ : fNextObjNum(1),
+ fStartedAssigningObjNums(false),
+ fAssigningFirstPageObjNums(false) {
+}
+
+SkPDFCatalog::~SkPDFCatalog() {}
+
void SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
SkASSERT(findObjectIndex(obj) == -1);
SkASSERT(!fStartedAssigningObjNums);
#include "SkPDFTypes.h"
#include "SkStream.h"
+SkPDFObject::SkPDFObject() {}
+SkPDFObject::~SkPDFObject() {}
+
size_t SkPDFObject::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
SkDynamicMemoryWStream buffer;
emitObject(&buffer, catalog, indirect);
stream->writeText("\nendobj\n");
}
+SkPDFObjRef::SkPDFObjRef(SkPDFObject* obj) : fObj(obj) {}
+SkPDFObjRef::~SkPDFObjRef() {}
+
size_t SkPDFObject::getIndirectOutputSize(SkPDFCatalog* catalog) {
return catalog->getObjectNumberSize(this) + strlen(" obj\n") +
this->getOutputSize(catalog, false) + strlen("\nendobj\n");
return catalog->getObjectNumberSize(fObj.get()) + strlen(" R");
}
+SkPDFInt::SkPDFInt(int32_t value) : fValue(value) {}
+SkPDFInt::~SkPDFInt() {}
+
void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) {
if (indirect)
stream->writeDecAsText(fValue);
}
+SkPDFScalar::SkPDFScalar(SkScalar value) : fValue(value) {}
+SkPDFScalar::~SkPDFScalar() {}
+
void SkPDFScalar::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) {
if (indirect)
: fValue(formatString(value)) {
}
+SkPDFString::~SkPDFString() {}
+
void SkPDFString::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) {
if (indirect)
// a 7-bit clean string should require little escaping.
bool sevenBitClean = true;
for (size_t i = 0; i < input.size(); i++) {
- if (input[i] > 0x7F || input[i] < ' ') {
+ if (input[i] & 0x80 || input[i] < ' ') {
sevenBitClean = false;
break;
}
SkPDFName::SkPDFName(const char name[]) : fValue(formatName(SkString(name))) {}
SkPDFName::SkPDFName(const SkString& name) : fValue(formatName(name)) {}
+SkPDFName::~SkPDFName() {}
void SkPDFName::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
bool indirect) {
return fValue.size();
}
+// static
SkString SkPDFName::formatName(const SkString& input) {
SkASSERT(input.size() <= kMaxLen);
SkString result("/");
for (size_t i = 0; i < input.size(); i++) {
- if (input[i] > 0x7F || input[i] < '!' || input[i] == '#') {
+ if (input[i] & 0x80 || input[i] < '!' || input[i] == '#') {
result.append("#");
result.appendHex(input[i], 2);
} else {
return result;
}
+SkPDFArray::SkPDFArray() {}
SkPDFArray::~SkPDFArray() {
fValue.safeUnrefAll();
}
fValue.push(value);
}
+SkPDFDict::SkPDFDict() {}
SkPDFDict::~SkPDFDict() {
for (int i = 0; i < fValue.count(); i++) {
SkSafeUnref(fValue[i].key);
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <string>
#include "Test.h"