SkPDFCatalog();
~SkPDFCatalog();
- /** Add the passed object to the catalog.
+ /** Add the passed object to the catalog. Refs obj.
* @param obj The object to add.
* @param onFirstPage Is the object on the first page.
+ * @return The obj argument is returned.
*/
- void addObject(SkPDFObject* obj, bool onFirstPage);
+ SkPDFObject* addObject(SkPDFObject* obj, bool onFirstPage);
/** Inform the catalog of the object's position in the final stream.
* The object should already have been added to the catalog. Returns
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
- /** Add the value to the stream dictionary with the given key.
+ /** Add the value to the stream dictionary with the given key. Refs value.
* @param key The key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(SkPDFName* key, SkPDFObject* value);
+ SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
- /** Add the value to the stream dictionary with the given key.
+ /** Add the value to the stream dictionary with the given key. Refs value.
* @param key The text of the key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(const char key[], SkPDFObject* value);
+ SkPDFObject* insert(const char key[], SkPDFObject* value);
private:
SkString fContent;
virtual ~SkPDFImage();
- /** Add a Soft Mask (alpha or shape channel) to the image.
+ /** Add a Soft Mask (alpha or shape channel) to the image. Refs mask.
* @param mask A gray scale image representing the mask.
+ * @return The mask argument is returned.
*/
- void addSMask(SkPDFImage* mask);
+ SkPDFImage* addSMask(SkPDFImage* mask);
// The SkPDFObject interface.
virtual void emitObject(SkWStream* stream, SkPDFCatalog* catalog,
SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
const SkIRect& srcRect, bool alpha, const SkPaint& paint);
- /** Add the value to the stream dictionary with the given key.
+ /** Add the value to the stream dictionary with the given key. Refs value.
* @param key The key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(SkPDFName* key, SkPDFObject* value);
+ SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
- /** Add the value to the stream dictionary with the given key.
+ /** Add the value to the stream dictionary with the given key. Refs value.
* @param key The text of the key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(const char key[], SkPDFObject* value);
+ SkPDFObject* insert(const char key[], SkPDFObject* value);
};
#endif
bool indirect);
virtual size_t getOutputSize(SkPDFCatalog* catalog, bool indirect);
- /** Add the value to the stream dictionary with the given key.
+ /** Add the value to the stream dictionary with the given key. Refs value.
* @param key The key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(SkPDFName* key, SkPDFObject* value);
+ SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
- /** Add the value to the stream dictionary with the given key.
+ /** Add the value to the stream dictionary with the given key. Refs value.
* @param key The text of the key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(const char key[], SkPDFObject* value);
+ SkPDFObject* insert(const char key[], SkPDFObject* value);
private:
SkPDFDict fDict;
*/
SkPDFObject* getAt(int index) { return fValue[index]; }
- /** Set the object at the given offset in the array.
+ /** Set the object at the given offset in the array. Ref's value.
* @param index The index into the array to set.
* @param value The value to add to the array.
+ * @return The value argument is returned.
*/
- void setAt(int index, SkPDFObject* value);
+ SkPDFObject* setAt(int index, SkPDFObject* value);
- /** Append the object to the end of the array.
+ /** Append the object to the end of the array and increments its ref count.
* @param value The value to add to the array.
+ * @return The value argument is returned.
*/
- void append(SkPDFObject* value);
+ SkPDFObject* append(SkPDFObject* value);
private:
static const int kMaxLen = 8191;
*/
int size() { return fValue.count(); }
- /** Add the value to the dictionary with the given key.
+ /** Add the value to the dictionary with the given key. Refs value.
* @param key The key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(SkPDFName* key, SkPDFObject* value);
+ SkPDFObject* insert(SkPDFName* key, SkPDFObject* value);
- /** Add the value to the dictionary with the given key. The method will
- * create the SkPDFName object.
+ /** Add the value to the dictionary with the given key. Refs value. The
+ * method will create the SkPDFName object.
* @param key The text of the key for this dictionary entry.
* @param value The value for this dictionary entry.
+ * @return The value argument is returned.
*/
- void insert(const char key[], SkPDFObject* value);
+ SkPDFObject* insert(const char key[], SkPDFObject* value);
/** Remove all entries from the dictionary.
*/
SkPDFCatalog::~SkPDFCatalog() {}
-void SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
+SkPDFObject* SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
SkASSERT(findObjectIndex(obj) == -1);
SkASSERT(fNextFirstPageObjNum == 0);
if (onFirstPage)
struct Rec newEntry(obj, onFirstPage);
fCatalog.append(1, &newEntry);
+ return obj;
}
size_t SkPDFCatalog::setFileOffset(SkPDFObject* obj, size_t offset) {
for (int i = 0; i < fGraphicStateResources.count(); i++) {
SkString nameString("G");
nameString.appendS32(i);
- SkRefPtr<SkPDFName> name = new SkPDFName(nameString);
- name->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFObjRef> gsRef =
- new SkPDFObjRef(fGraphicStateResources[i]);
- gsRef->unref(); // SkRefPtr and new both took a reference.
- extGState->insert(name.get(), gsRef.get());
+ extGState->insert(
+ nameString.c_str(),
+ new SkPDFObjRef(fGraphicStateResources[i]))->unref();
}
fResourceDict->insert("ExtGState", extGState.get());
}
for (int i = 0; i < fXObjectResources.count(); i++) {
SkString nameString("X");
nameString.appendS32(i);
- SkRefPtr<SkPDFName> name = new SkPDFName(nameString);
- name->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFObjRef> xObjRef =
- new SkPDFObjRef(fXObjectResources[i]);
- xObjRef->unref(); // SkRefPtr and new both took a reference.
- xObjects->insert(name.get(), xObjRef.get());
+ xObjects->insert(
+ nameString.c_str(),
+ new SkPDFObjRef(fXObjectResources[i]))->unref();
}
fResourceDict->insert("XObject", xObjects.get());
}
for (int i = 0; i < fFontResources.count(); i++) {
SkString nameString("F");
nameString.appendS32(i);
- SkRefPtr<SkPDFName> name = new SkPDFName(nameString);
- name->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFObjRef> fontRef =
- new SkPDFObjRef(fFontResources[i]);
- fontRef->unref(); // SkRefPtr and new both took a reference.
- fonts->insert(name.get(), fontRef.get());
+ fonts->insert(nameString.c_str(),
+ new SkPDFObjRef(fFontResources[i]))->unref();
}
fResourceDict->insert("Font", fonts.get());
}
SkRefPtr<SkPDFArray> procSets = new SkPDFArray();
procSets->unref(); // SkRefPtr and new both took a reference.
procSets->reserve(SK_ARRAY_COUNT(procs));
- for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++) {
- SkRefPtr<SkPDFName> entry = new SkPDFName(procs[i]);
- entry->unref(); // SkRefPtr and new both took a reference.
- procSets->append(entry.get());
- }
+ for (size_t i = 0; i < SK_ARRAY_COUNT(procs); i++)
+ procSets->append(new SkPDFName(procs[i]))->unref();
fResourceDict->insert("ProcSet", procSets.get());
}
return fResourceDict;
SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
SkRefPtr<SkPDFInt> zero = new SkPDFInt(0);
zero->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> width = new SkPDFInt(fWidth);
- width->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> height = new SkPDFInt(fHeight);
- height->unref(); // SkRefPtr and new both took a reference.
+
SkRefPtr<SkPDFArray> mediaBox = new SkPDFArray();
mediaBox->unref(); // SkRefPtr and new both took a reference.
mediaBox->reserve(4);
mediaBox->append(zero.get());
mediaBox->append(zero.get());
- mediaBox->append(width.get());
- mediaBox->append(height.get());
+ mediaBox->append(new SkPDFInt(fWidth))->unref();
+ mediaBox->append(new SkPDFInt(fHeight))->unref();
return mediaBox;
}
SkPDFDict* pageTreeRoot;
SkPDFPage::generatePageTree(fPages, &fCatalog, &fPageTree,
&pageTreeRoot);
- SkRefPtr<SkPDFObjRef> pageTreeRootRef = new SkPDFObjRef(pageTreeRoot);
- pageTreeRootRef->unref(); // SkRefPtr and new both took a reference.
- fDocCatalog->insert("Pages", pageTreeRootRef.get());
+ fDocCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref();
/* TODO(vandebo) output intent
SkRefPtr<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
outputIntent->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFName> intentSubtype = new SkPDFName("GTS_PDFA1");
- intentSubtype->unref(); // SkRefPtr and new both took a reference.
- outputIntent->insert("S", intentSubtype.get());
- SkRefPtr<SkPDFString> intentIdentifier = new SkPDFString("sRGB");
- intentIdentifier->unref(); // SkRefPtr and new both took a reference.
+ outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref();
outputIntent->insert("OutputConditionIdentifier",
- intentIdentifier.get());
+ new SkPDFString("sRGB"))->unref();
SkRefPtr<SkPDFArray> intentArray = new SkPDFArray;
intentArray->unref(); // SkRefPtr and new both took a reference.
intentArray->append(outputIntent.get());
fTrailerDict = new SkPDFDict();
fTrailerDict->unref(); // SkRefPtr and new both took a reference.
- SkPDFInt* objCountInt = new SkPDFInt(objCount);
- fTrailerDict->insert("Size", objCountInt);
- objCountInt->unref(); // insert took a ref and we're done with it.
-
// TODO(vandebo) Linearized format will take a Prev entry too.
-
- SkPDFObjRef* docCatalogRef = new SkPDFObjRef(fDocCatalog.get());
- fTrailerDict->insert("Root", docCatalogRef);
- docCatalogRef->unref(); // insert took a ref and we're done with it.
-
// TODO(vandebo) PDF/A requires an ID entry.
+ fTrailerDict->insert("Size", new SkPDFInt(objCount))->unref();
+ fTrailerDict->insert("Root",
+ new SkPDFObjRef(fDocCatalog.get()))->unref();
}
stream->writeText("trailer\n");
return NULL;
}
-void appendWidth(const int& width, SkPDFArray* array) {
- SkRefPtr<SkPDFInt> widthInt = new SkPDFInt(width);
- widthInt->unref(); // SkRefPtr and new both took a reference.
- array->append(widthInt.get());
+SkPDFArray* appendWidth(const int& width, SkPDFArray* array) {
+ array->append(new SkPDFInt(width))->unref();
+ return array;
}
-void appendVerticalAdvance(const SkPDFTypefaceInfo::VerticalMetric& advance,
- SkPDFArray* array) {
+SkPDFArray* appendVerticalAdvance(
+ const SkPDFTypefaceInfo::VerticalMetric& advance, SkPDFArray* array) {
appendWidth(advance.fVerticalAdvance, array);
appendWidth(advance.fOriginXDisp, array);
appendWidth(advance.fOriginYDisp, array);
+ return array;
}
template <typename Data>
SkPDFArray* composeAdvanceData(
SkPDFTypefaceInfo::AdvanceMetric<Data>* advanceInfo,
- void (*appendAdvance)(const Data& advance, SkPDFArray* array),
+ SkPDFArray* (*appendAdvance)(const Data& advance, SkPDFArray* array),
Data* defaultAdvance) {
SkPDFArray* result = new SkPDFArray();
for (; advanceInfo != NULL; advanceInfo = advanceInfo->fNext.get()) {
advanceArray->unref(); // SkRefPtr and new both took a ref.
for (int j = 0; j < advanceInfo->fAdvance.count(); j++)
appendAdvance(advanceInfo->fAdvance[j], advanceArray.get());
- SkRefPtr<SkPDFInt> rangeStart =
- new SkPDFInt(advanceInfo->fStartId);
- rangeStart->unref(); // SkRefPtr and new both took a reference.
- result->append(rangeStart.get());
+ result->append(new SkPDFInt(advanceInfo->fStartId))->unref();
result->append(advanceArray.get());
break;
}
case SkPDFTypefaceInfo::WidthRange::kRun: {
SkASSERT(advanceInfo->fAdvance.count() == 1);
- SkRefPtr<SkPDFInt> rangeStart =
- new SkPDFInt(advanceInfo->fStartId);
- rangeStart->unref(); // SkRefPtr and new both took a reference.
- result->append(rangeStart.get());
-
- SkRefPtr<SkPDFInt> rangeEnd = new SkPDFInt(advanceInfo->fEndId);
- rangeEnd->unref(); // SkRefPtr and new both took a reference.
- result->append(rangeEnd.get());
-
+ result->append(new SkPDFInt(advanceInfo->fStartId))->unref();
+ result->append(new SkPDFInt(advanceInfo->fEndId))->unref();
appendAdvance(advanceInfo->fAdvance[0], result);
break;
}
}
void SkPDFFont::populateType0Font() {
- fMultiByteGlyphs = true;
-
- SkRefPtr<SkPDFName> subType = new SkPDFName("Type0");
- subType->unref(); // SkRefPtr and new both took a reference.
- insert("Subtype", subType.get());
-
- SkRefPtr<SkPDFName> baseFont = new SkPDFName(fFontInfo.get()->fFontName);
- baseFont->unref(); // SkRefPtr and new both took a reference.
- insert("BaseFont", baseFont.get());
-
- SkRefPtr<SkPDFName> encoding = new SkPDFName("Identity-H");
- encoding->unref(); // SkRefPtr and new both took a reference.
- insert("Encoding", encoding.get());
-
// TODO(vandebo) add a ToUnicode mapping.
+ fMultiByteGlyphs = true;
- SkRefPtr<SkPDFFont> cidFont = new SkPDFFont(fFontInfo.get(),
- fFontID, 1, true, NULL);
- fResources.push(cidFont.get()); // 2 refs: SkRefPtr, new. Pass one.
+ insert("Subtype", new SkPDFName("Type0"))->unref();
+ insert("BaseFont", new SkPDFName(fFontInfo.get()->fFontName))->unref();
+ insert("Encoding", new SkPDFName("Identity-H"))->unref();
SkRefPtr<SkPDFArray> descendantFonts = new SkPDFArray();
descendantFonts->unref(); // SkRefPtr and new took a reference.
- SkRefPtr<SkPDFObjRef> cidFontRef = new SkPDFObjRef(cidFont.get());
- cidFontRef->unref(); // SkRefPtr and new both took a reference.
- descendantFonts->append(cidFontRef.get());
+
+ // Pass ref new created to fResources.
+ fResources.push(new SkPDFFont(fFontInfo.get(), fFontID, 1, true, NULL));
+ descendantFonts->append(new SkPDFObjRef(fResources.top()))->unref();
insert("DescendantFonts", descendantFonts.get());
}
void SkPDFFont::populateCIDFont() {
fMultiByteGlyphs = true;
- SkRefPtr<SkPDFName> subType;
+ insert("BaseFont", new SkPDFName(fFontInfo.get()->fFontName))->unref();
+
if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kType1CID_Font)
- subType = new SkPDFName("CIDFontType0");
+ insert("Subtype", new SkPDFName("CIDFontType0"))->unref();
else if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kTrueType_Font)
- subType = new SkPDFName("CIDFontType2");
+ insert("Subtype", new SkPDFName("CIDFontType2"))->unref();
else
SkASSERT(false);
- subType->unref(); // SkRefPtr and new both took a reference.
- insert("Subtype", subType.get());
-
- SkRefPtr<SkPDFName> baseFont = new SkPDFName(fFontInfo.get()->fFontName);
- baseFont->unref(); // SkRefPtr and new both took a reference.
- insert("BaseFont", baseFont.get());
SkRefPtr<SkPDFDict> sysInfo = new SkPDFDict;
sysInfo->unref(); // SkRefPtr and new both took a reference.
-
- SkRefPtr<SkPDFString> adobeString = new SkPDFString("Adobe");
- adobeString->unref(); // SkRefPtr and new both took a reference.
- sysInfo->insert("Registry", adobeString.get());
-
- SkRefPtr<SkPDFString> identityString = new SkPDFString("Identity");
- identityString->unref(); // SkRefPtr and new both took a reference.
- sysInfo->insert("Ordering", identityString.get());
-
- SkRefPtr<SkPDFInt> supplement = new SkPDFInt(0);
- supplement->unref(); // SkRefPtr and new both took a reference.
- sysInfo->insert("Supplement", supplement.get());
-
+ sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref();
+ sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref();
+ sysInfo->insert("Supplement", new SkPDFInt(0))->unref();
insert("CIDSystemInfo", sysInfo.get());
addFontDescriptor(0);
if (widths->size())
insert("W", widths.get());
if (defaultWidth != 0) {
- SkRefPtr<SkPDFInt> defaultWidthInt =
- new SkPDFInt(defaultWidth);
- // SkRefPtr and compose both took a reference.
- defaultWidthInt->unref();
- insert("DW", defaultWidthInt.get());
+ insert("DW", new SkPDFInt(defaultWidth))->unref();
}
}
if (fFontInfo.get()->fVerticalMetrics.get()) {
if (defaultAdvance.fVerticalAdvance ||
defaultAdvance.fOriginXDisp ||
defaultAdvance.fOriginYDisp) {
- SkRefPtr<SkPDFArray> defaultAdvanceArray = new SkPDFArray;
- // SkRefPtr and compose both took a reference.
- defaultAdvanceArray->unref();
- appendVerticalAdvance(defaultAdvance,
- defaultAdvanceArray.get());
- insert("DW2", defaultAdvanceArray.get());
+ insert("DW2", appendVerticalAdvance(defaultAdvance,
+ new SkPDFArray))->unref();
}
}
}
fFirstGlyphID = firstGlyphID;
fLastGlyphID = lastGlyphID;
- SkRefPtr<SkPDFName> subType = new SkPDFName("Type1");
- subType->unref(); // SkRefPtr and new both took a reference.
- insert("Subtype", subType.get());
-
- SkRefPtr<SkPDFName> baseFont = new SkPDFName(fFontInfo.get()->fFontName);
- baseFont->unref(); // SkRefPtr and new both took a reference.
- insert("BaseFont", baseFont.get());
+ insert("Subtype", new SkPDFName("Type1"))->unref();
+ insert("BaseFont", new SkPDFName(fFontInfo.get()->fFontName))->unref();
SkRefPtr<SkPDFArray> widthArray = new SkPDFArray();
widthArray->unref(); // SkRefPtr and new both took a ref.
appendWidth(defaultWidth, widthArray.get());
}
insert("Widths", widthArray.get());
-
- SkRefPtr<SkPDFInt> firstCharInt = new SkPDFInt(firstChar);
- firstCharInt->unref(); // SkRefPtr and new both took a reference.
- insert("FirstChar", firstCharInt.get());
-
- SkRefPtr<SkPDFInt> lastChar =
- new SkPDFInt(firstChar + widthArray->size() - 1);
- lastChar->unref(); // SkRefPtr and new both took a reference.
- insert("LastChar", lastChar.get());
+ insert("FirstChar", new SkPDFInt(firstChar))->unref();
+ insert("LastChar",
+ new SkPDFInt(firstChar + widthArray->size() - 1))->unref();
SkRefPtr<SkPDFDict> encoding = new SkPDFDict("Encoding");
encoding->unref(); // SkRefPtr and new both took a reference.
encoding->insert("Differences", encDiffs.get());
encDiffs->reserve(fLastGlyphID - fFirstGlyphID + 2);
- SkRefPtr<SkPDFInt> startID = new SkPDFInt(1);
- startID->unref(); // SkRefPtr and new both took a reference.
- encDiffs->append(startID.get());
+ encDiffs->append(new SkPDFInt(1))->unref();
for (int gID = fFirstGlyphID; gID <= fLastGlyphID; gID++) {
- SkRefPtr<SkPDFName> glyphName =
- new SkPDFName(fFontInfo.get()->fGlyphNames->get()[gID]);
- glyphName->unref(); // SkRefPtr and new both took a reference.
- encDiffs->append(glyphName.get());
+ encDiffs->append(
+ new SkPDFName(fFontInfo.get()->fGlyphNames->get()[gID]))->unref();
}
if (fFontInfo.get()->fLastGlyphID <= 255)
if (fDescriptor.get() != NULL) {
fResources.push(fDescriptor.get());
fDescriptor->ref();
- SkRefPtr<SkPDFObjRef> descRef = new SkPDFObjRef(fDescriptor.get());
- descRef->unref(); // SkRefPtr and new both took a reference.
- insert("FontDescriptor", descRef.get());
+ insert("FontDescriptor", new SkPDFObjRef(fDescriptor.get()))->unref();
return true;
}
SkRefPtr<SkPDFStream> fontStream = new SkPDFStream(fontData);
// SkRefPtr and new both ref()'d fontStream, pass one.
fResources.push(fontStream.get());
-
- SkRefPtr<SkPDFInt> headerLen = new SkPDFInt(header);
- headerLen->unref(); // SkRefPtr and new both took a reference.
- fontStream->insert("Length1", headerLen.get());
- SkRefPtr<SkPDFInt> dataLen = new SkPDFInt(data);
- dataLen->unref(); // SkRefPtr and new both took a reference.
- fontStream->insert("Length2", dataLen.get());
- SkRefPtr<SkPDFInt> trailerLen = new SkPDFInt(trailer);
- trailerLen->unref(); // SkRefPtr and new both took a reference.
- fontStream->insert("Length3", trailerLen.get());
-
- SkRefPtr<SkPDFObjRef> streamRef = new SkPDFObjRef(fontStream.get());
- streamRef->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("FontFile", streamRef.get());
+ fontStream->insert("Length1", new SkPDFInt(header))->unref();
+ fontStream->insert("Length2", new SkPDFInt(data))->unref();
+ fontStream->insert("Length3", new SkPDFInt(trailer))->unref();
+ fDescriptor->insert("FontFile",
+ new SkPDFObjRef(fontStream.get()))->unref();
break;
}
case SkPDFTypefaceInfo::kTrueType_Font: {
// SkRefPtr and new both ref()'d fontStream, pass one.
fResources.push(fontStream.get());
- SkRefPtr<SkPDFInt> length = new SkPDFInt(fontData->getLength());
- length->unref(); // SkRefPtr and new both took a reference.
- fontStream->insert("Length1", length.get());
-
- SkRefPtr<SkPDFObjRef> streamRef = new SkPDFObjRef(fontStream.get());
- streamRef->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("FontFile2", streamRef.get());
+ fontStream->insert("Length1",
+ new SkPDFInt(fontData->getLength()))->unref();
+ fDescriptor->insert("FontFile2",
+ new SkPDFObjRef(fontStream.get()))->unref();
break;
}
case SkPDFTypefaceInfo::kCFF_Font:
// SkRefPtr and new both ref()'d fontStream, pass one.
fResources.push(fontStream.get());
- SkRefPtr<SkPDFName> subtype;
- if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kCFF_Font)
- subtype = new SkPDFName("Type1C");
- else
- subtype = new SkPDFName("CIDFontType0c");
- subtype->unref(); // SkRefPtr and new both took a reference.
- fontStream->insert("Subtype", subtype.get());
-
- SkRefPtr<SkPDFObjRef> streamRef = new SkPDFObjRef(fontStream.get());
- streamRef->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("FontFile3", streamRef.get());
+ if (fFontInfo.get()->fType == SkPDFTypefaceInfo::kCFF_Font) {
+ fontStream->insert("Subtype", new SkPDFName("Type1C"))->unref();
+ } else {
+ fontStream->insert("Subtype",
+ new SkPDFName("CIDFontType0c"))->unref();
+ }
+ fDescriptor->insert("FontFile3",
+ new SkPDFObjRef(fontStream.get()))->unref();
break;
}
default:
fResources.push(fDescriptor.get());
fDescriptor->ref();
- SkRefPtr<SkPDFObjRef> descRef = new SkPDFObjRef(fDescriptor.get());
- descRef->unref(); // SkRefPtr and new both took a reference.
- insert("FontDescriptor", descRef.get());
-
- SkRefPtr<SkPDFName> fontName =
- new SkPDFName(fFontInfo.get()->fFontName);
- fontName->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("FontName", fontName.get());
-
- SkRefPtr<SkPDFInt> flags = new SkPDFInt(fFontInfo.get()->fStyle);
- flags->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("Flags", flags.get());
+ insert("FontDescriptor", new SkPDFObjRef(fDescriptor.get()))->unref();
+
+ fDescriptor->insert("FontName",
+ new SkPDFName(fFontInfo.get()->fFontName))->unref();
+ fDescriptor->insert("Flags",
+ new SkPDFInt(fFontInfo.get()->fStyle))->unref();
+ fDescriptor->insert("Ascent",
+ new SkPDFScalar(fFontInfo.get()->fAscent))->unref();
+ fDescriptor->insert("Descent",
+ new SkPDFScalar(fFontInfo.get()->fDescent))->unref();
+ fDescriptor->insert("CapHeight",
+ new SkPDFScalar(fFontInfo.get()->fCapHeight))->unref();
+ fDescriptor->insert("StemV",
+ new SkPDFScalar(fFontInfo.get()->fStemV))->unref();
+ fDescriptor->insert("ItalicAngle",
+ new SkPDFInt(fFontInfo.get()->fItalicAngle))->unref();
SkIRect glyphBBox = fFontInfo.get()->fBBox;
SkRefPtr<SkPDFArray> bbox = new SkPDFArray;
bbox->unref(); // SkRefPtr and new both took a reference.
bbox->reserve(4);
- SkRefPtr<SkPDFInt> bboxXMin = new SkPDFInt(glyphBBox.fLeft);
- bboxXMin->unref(); // SkRefPtr and new both took a reference.
- bbox->append(bboxXMin.get());
- SkRefPtr<SkPDFInt> bboxYMin = new SkPDFInt(glyphBBox.fBottom);
- bboxYMin->unref(); // SkRefPtr and new both took a reference.
- bbox->append(bboxYMin.get());
- SkRefPtr<SkPDFInt> bboxXMax = new SkPDFInt(glyphBBox.fRight);
- bboxXMax->unref(); // SkRefPtr and new both took a reference.
- bbox->append(bboxXMax.get());
- SkRefPtr<SkPDFInt> bboxYMax = new SkPDFInt(glyphBBox.fTop);
- bboxYMax->unref(); // SkRefPtr and new both took a reference.
- bbox->append(bboxYMax.get());
+ bbox->append(new SkPDFInt(glyphBBox.fLeft))->unref();
+ bbox->append(new SkPDFInt(glyphBBox.fBottom))->unref();
+ bbox->append(new SkPDFInt(glyphBBox.fRight))->unref();
+ bbox->append(new SkPDFInt(glyphBBox.fTop))->unref();
fDescriptor->insert("FontBBox", bbox.get());
- SkRefPtr<SkPDFInt> italicAngle =
- new SkPDFInt(fFontInfo.get()->fItalicAngle);
- italicAngle->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("ItalicAngle", italicAngle.get());
-
- SkRefPtr<SkPDFScalar> ascent = new SkPDFScalar(fFontInfo.get()->fAscent);
- ascent->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("Ascent", ascent.get());
-
- SkRefPtr<SkPDFScalar> descent = new SkPDFScalar(fFontInfo.get()->fDescent);
- descent->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("Descent", descent.get());
-
- SkRefPtr<SkPDFScalar> capHeight =
- new SkPDFScalar(fFontInfo.get()->fCapHeight);
- capHeight->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("CapHeight", capHeight.get());
-
- SkRefPtr<SkPDFScalar> stemV = new SkPDFScalar(fFontInfo.get()->fStemV);
- stemV->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("StemV", stemV.get());
-
if (defaultWidth > 0) {
- SkRefPtr<SkPDFInt> defaultWidthInt = new SkPDFInt(defaultWidth);
- defaultWidthInt->unref(); // SkRefPtr and new both took a reference.
- fDescriptor->insert("MissingWidth", defaultWidthInt.get());
+ fDescriptor->insert("MissingWidth",
+ new SkPDFInt(defaultWidth))->unref();
}
return true;
}
fStream = new SkPDFStream(stream_data);
fStream->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFName> typeValue = new SkPDFName("XObject");
- typeValue->unref(); // SkRefPtr and new both took a reference.
- insert("Type", typeValue.get());
-
- SkRefPtr<SkPDFName> subTypeValue = new SkPDFName("Form");
- subTypeValue->unref(); // SkRefPtr and new both took a reference.
- insert("Subtype", subTypeValue.get());
-
+ insert("Type", new SkPDFName("XObject"))->unref();
+ insert("Subtype", new SkPDFName("Form"))->unref();
insert("BBox", device->getMediaBox().get());
insert("Resources", device->getResourceDict().get());
transformArray->reserve(6);
SkScalar transform[6];
SkAssertResult(matrix.pdfTransform(transform));
- for (size_t i = 0; i < SK_ARRAY_COUNT(transform); i++) {
- SkRefPtr<SkPDFScalar> val = new SkPDFScalar(transform[i]);
- val->unref(); // SkRefPtr and new both took a reference.
- transformArray->append(val.get());
- }
+ for (size_t i = 0; i < SK_ARRAY_COUNT(transform); i++)
+ transformArray->append(new SkPDFScalar(transform[i]))->unref();
insert("Matrix", transformArray.get());
}
}
fDevice->getResources(resourceList);
}
-void SkPDFFormXObject::insert(SkPDFName* key, SkPDFObject* value) {
- fStream->insert(key, value);
+SkPDFObject* SkPDFFormXObject::insert(SkPDFName* key, SkPDFObject* value) {
+ return fStream->insert(key, value);
}
-void SkPDFFormXObject::insert(const char key[], SkPDFObject* value) {
- fStream->insert(key, value);
+SkPDFObject* SkPDFFormXObject::insert(const char key[], SkPDFObject* value) {
+ return fStream->insert(key, value);
}
void SkPDFGraphicState::populateDict() {
if (!fPopulated) {
fPopulated = true;
- SkRefPtr<SkPDFName> typeName = new SkPDFName("ExtGState");
- typeName->unref(); // SkRefPtr and new both took a reference.
- insert("Type", typeName.get());
+ insert("Type", new SkPDFName("ExtGState"))->unref();
SkRefPtr<SkPDFScalar> alpha =
new SkPDFScalar(fPaint.getAlpha() * SkScalarInvert(0xFF));
insert("CA", alpha.get());
insert("ca", alpha.get());
- SkASSERT(SkPaint::kButt_Cap == 0);
- SkASSERT(SkPaint::kRound_Cap == 1);
- SkASSERT(SkPaint::kSquare_Cap == 2);
+ SK_COMPILE_ASSERT(SkPaint::kButt_Cap == 0, paint_cap_mismatch);
+ SK_COMPILE_ASSERT(SkPaint::kRound_Cap == 1, paint_cap_mismatch);
+ SK_COMPILE_ASSERT(SkPaint::kSquare_Cap == 2, paint_cap_mismatch);
+ SK_COMPILE_ASSERT(SkPaint::kCapCount == 3, paint_cap_mismatch);
SkASSERT(fPaint.getStrokeCap() >= 0 && fPaint.getStrokeCap() <= 2);
- SkRefPtr<SkPDFInt> strokeCap = new SkPDFInt(fPaint.getStrokeCap());
- strokeCap->unref(); // SkRefPtr and new both took a reference.
- insert("LC", strokeCap.get());
+ insert("LC", new SkPDFInt(fPaint.getStrokeCap()))->unref();
- SkASSERT(SkPaint::kMiter_Join == 0);
- SkASSERT(SkPaint::kRound_Join == 1);
- SkASSERT(SkPaint::kBevel_Join == 2);
+ SK_COMPILE_ASSERT(SkPaint::kMiter_Join == 0, paint_join_mismatch);
+ SK_COMPILE_ASSERT(SkPaint::kRound_Join == 1, paint_join_mismatch);
+ SK_COMPILE_ASSERT(SkPaint::kBevel_Join == 2, paint_join_mismatch);
+ SK_COMPILE_ASSERT(SkPaint::kJoinCount == 3, paint_join_mismatch);
SkASSERT(fPaint.getStrokeJoin() >= 0 && fPaint.getStrokeJoin() <= 2);
- SkRefPtr<SkPDFInt> strokeJoin = new SkPDFInt(fPaint.getStrokeJoin());
- strokeJoin->unref(); // SkRefPtr and new both took a reference.
- insert("LJ", strokeJoin.get());
+ insert("LJ", new SkPDFInt(fPaint.getStrokeJoin()))->unref();
- SkRefPtr<SkPDFScalar> strokeWidth =
- new SkPDFScalar(fPaint.getStrokeWidth());
- strokeWidth->unref(); // SkRefPtr and new both took a reference.
- insert("LW", strokeWidth.get());
-
- SkRefPtr<SkPDFScalar> strokeMiterLimit = new SkPDFScalar(
- fPaint.getStrokeMiter());
- strokeMiterLimit->unref(); // SkRefPtr and new both took a reference.
- insert("ML", strokeMiterLimit.get());
-
- // Turn on automatic stroke adjustment.
- SkRefPtr<SkPDFBool> trueVal = new SkPDFBool(true);
- trueVal->unref(); // SkRefPtr and new both took a reference.
- insert("SA", trueVal.get());
+ insert("LW", new SkPDFScalar(fPaint.getStrokeWidth()))->unref();
+ insert("ML", new SkPDFScalar(fPaint.getStrokeMiter()))->unref();
+ insert("SA", new SkPDFBool(true))->unref(); // Auto stroke adjustment.
}
}
SkPDFArray* makeIndexedColorSpace(SkColorTable* table) {
SkPDFArray* result = new SkPDFArray();
result->reserve(4);
- SkRefPtr<SkPDFName> indexedName = new SkPDFName("Indexed");
- indexedName->unref(); // SkRefPtr and new both took a reference.
- result->append(indexedName.get());
-
- SkRefPtr<SkPDFName> rgbName = new SkPDFName("DeviceRGB");
- rgbName->unref(); // SkRefPtr and new both took a reference.
- result->append(rgbName.get());
-
- SkRefPtr<SkPDFInt> countValue = new SkPDFInt(table->count() - 1);
- countValue->unref(); // SkRefPtr and new both took a reference.
- result->append(countValue.get());
+ result->append(new SkPDFName("Indexed"))->unref();
+ result->append(new SkPDFName("DeviceRGB"))->unref();;
+ result->append(new SkPDFInt(table->count() - 1))->unref();
// Potentially, this could be represented in fewer bytes with a stream.
// Max size as a string is 1.5k.
buf[2] = SkGetPackedB32(color);
index.append(buf, 3);
}
- SkRefPtr<SkPDFString> indexValue = new SkPDFString(index);
- indexValue->unref(); // SkRefPtr and new both took a reference.
- result->append(indexValue.get());
+ result->append(new SkPDFString(index))->unref();
return result;
}
new SkPDFImage(imageData, bitmap, srcRect, false, paint);
if (alphaData != NULL) {
- SkRefPtr<SkPDFImage> alphaImage =
- new SkPDFImage(alphaData, bitmap, srcRect, true, paint);
- alphaImage->unref(); // SkRefPtr and new both took a reference.
- image->addSMask(alphaImage.get());
+ image->addSMask(new SkPDFImage(alphaData, bitmap, srcRect, true,
+ paint))->unref();
}
return image;
}
fResources.unrefAll();
}
-void SkPDFImage::addSMask(SkPDFImage* mask) {
+SkPDFImage* SkPDFImage::addSMask(SkPDFImage* mask) {
fResources.push(mask);
mask->ref();
-
- SkRefPtr<SkPDFObjRef> maskRef = new SkPDFObjRef(mask);
- maskRef->unref(); // SkRefPtr and new both took a reference.
- insert("SMask", maskRef.get());
+ insert("SMask", new SkPDFObjRef(mask))->unref();
+ return mask;
}
void SkPDFImage::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
fStream = new SkPDFStream(imageData);
fStream->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFName> typeValue = new SkPDFName("XObject");
- typeValue->unref(); // SkRefPtr and new both took a reference.
- insert("Type", typeValue.get());
-
- SkRefPtr<SkPDFName> subTypeValue = new SkPDFName("Image");
- subTypeValue->unref(); // SkRefPtr and new both took a reference.
- insert("Subtype", subTypeValue.get());
-
SkBitmap::Config config = bitmap.getConfig();
bool alphaOnly = (config == SkBitmap::kA1_Config ||
config == SkBitmap::kA8_Config);
- SkRefPtr<SkPDFInt> widthValue;
- SkRefPtr<SkPDFInt> heightValue;
+ insert("Type", new SkPDFName("XObject"))->unref();
+ insert("Subtype", new SkPDFName("Image"))->unref();
+
if (!doingAlpha && alphaOnly) {
// For alpha only images, we stretch a single pixel of black for
// the color/shape part.
- widthValue = new SkPDFInt(1);
- heightValue = widthValue.get();
+ SkRefPtr<SkPDFInt> one = new SkPDFInt(1);
+ one->unref(); // SkRefPtr and new both took a reference.
+ insert("Width", one.get());
+ insert("Height", one.get());
} else {
- widthValue = new SkPDFInt(srcRect.width());
- heightValue = new SkPDFInt(srcRect.height());
- heightValue->unref(); // SkRefPtr and new both took a reference.
+ insert("Width", new SkPDFInt(srcRect.width()))->unref();
+ insert("Height", new SkPDFInt(srcRect.height()))->unref();
}
- widthValue->unref(); // SkRefPtr and new both took a reference.
- insert("Width", widthValue.get());
- insert("Height", heightValue.get());
// if (!image mask) {
- SkRefPtr<SkPDFObject> colorSpaceValue;
if (doingAlpha || alphaOnly) {
- colorSpaceValue = new SkPDFName("DeviceGray");
+ insert("ColorSpace", new SkPDFName("DeviceGray"))->unref();
} else if (config == SkBitmap::kIndex8_Config ||
config == SkBitmap::kRLE_Index8_Config) {
- colorSpaceValue = makeIndexedColorSpace(bitmap.getColorTable());
+ insert("ColorSpace",
+ makeIndexedColorSpace(bitmap.getColorTable()))->unref();
} else {
- colorSpaceValue = new SkPDFName("DeviceRGB");
+ insert("ColorSpace", new SkPDFName("DeviceRGB"))->unref();
}
- colorSpaceValue->unref(); // SkRefPtr and new both took a reference.
- insert("ColorSpace", colorSpaceValue.get());
// }
int bitsPerComp = 8;
bitsPerComp = 4;
else if (doingAlpha && config == SkBitmap::kA1_Config)
bitsPerComp = 1;
- SkRefPtr<SkPDFInt> bitsPerCompValue = new SkPDFInt(bitsPerComp);
- bitsPerCompValue->unref(); // SkRefPtr and new both took a reference.
- insert("BitsPerComponent", bitsPerCompValue.get());
+ insert("BitsPerComponent", new SkPDFInt(bitsPerComp))->unref();
if (config == SkBitmap::kRGB_565_Config) {
SkRefPtr<SkPDFInt> zeroVal = new SkPDFInt(0);
}
}
-void SkPDFImage::insert(SkPDFName* key, SkPDFObject* value) {
- fStream->insert(key, value);
+SkPDFObject* SkPDFImage::insert(SkPDFName* key, SkPDFObject* value) {
+ return fStream->insert(key, value);
}
-void SkPDFImage::insert(const char key[], SkPDFObject* value) {
- fStream->insert(key, value);
+SkPDFObject* SkPDFImage::insert(const char key[], SkPDFObject* value) {
+ return fStream->insert(key, value);
}
contentStream->unref(); // SkRefPtr and new both took a reference.
fContentStream = new SkPDFStream(contentStream.get());
fContentStream->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFObjRef> contentRef =
- new SkPDFObjRef(fContentStream.get());
- contentRef->unref(); // SkRefPtr and new both took a reference.
- insert("Contents", contentRef.get());
+ insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref();
}
catalog->addObject(fContentStream.get(), firstPage);
fDevice->getResources(resourceObjects);
int count = 0;
for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
curNodes[i]->insert(parentName.get(), newNodeRef.get());
- SkRefPtr<SkPDFObjRef> nodeRef = new SkPDFObjRef(curNodes[i]);
- nodeRef->unref(); // SkRefPtr and new both took a reference.
- kids->append(nodeRef.get());
+ kids->append(new SkPDFObjRef(curNodes[i]))->unref();
// TODO(vandebo) put the objects in strict access order.
// Probably doesn't matter because they are so small.
}
newNode->insert(kidsName.get(), kids.get());
- SkRefPtr<SkPDFInt> countVal = new SkPDFInt(count);
- countVal->unref(); // SkRefPtr and new both took a reference.
- newNode->insert(countName.get(), countVal.get());
+ newNode->insert(countName.get(), new SkPDFInt(count))->unref();
nextRoundNodes.push(newNode); // Transfer reference.
}
if (SkFlate::HaveFlate() &&
fCompressedData.getOffset() < stream->getLength()) {
fLength = fCompressedData.getOffset();
-
- SkRefPtr<SkPDFName> flateFilter = new SkPDFName("FlateDecode");
- flateFilter->unref(); // SkRefPtr and new both took a reference.
- fDict.insert("Filter", flateFilter.get());
+ fDict.insert("Filter", new SkPDFName("FlateDecode"))->unref();
} else {
fCompressedData.reset();
fPlainData = stream;
fLength = fPlainData->getLength();
}
-
- SkRefPtr<SkPDFInt> lenValue = new SkPDFInt(fLength);
- lenValue->unref(); // SkRefPtr and new both took a reference.
- fDict.insert("Length", lenValue.get());
+ fDict.insert("Length", new SkPDFInt(fLength))->unref();
}
SkPDFStream::~SkPDFStream() {
strlen(" stream\n\nendstream") + fLength;
}
-void SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
- fDict.insert(key, value);
+SkPDFObject* SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
+ return fDict.insert(key, value);
}
-void SkPDFStream::insert(const char key[], SkPDFObject* value) {
- fDict.insert(key, value);
+SkPDFObject* SkPDFStream::insert(const char key[], SkPDFObject* value) {
+ return fDict.insert(key, value);
}
fValue.setReserve(length);
}
-void SkPDFArray::setAt(int offset, SkPDFObject* value) {
+SkPDFObject* SkPDFArray::setAt(int offset, SkPDFObject* value) {
SkASSERT(offset < fValue.count());
SkSafeUnref(fValue[offset]);
fValue[offset] = value;
SkSafeRef(fValue[offset]);
+ return value;
}
-void SkPDFArray::append(SkPDFObject* value) {
+SkPDFObject* SkPDFArray::append(SkPDFObject* value) {
SkASSERT(fValue.count() < kMaxLen);
SkSafeRef(value);
fValue.push(value);
+ return value;
}
SkPDFDict::SkPDFDict() {}
SkPDFDict::SkPDFDict(const char type[]) {
- SkRefPtr<SkPDFName> typeName = new SkPDFName(type);
- typeName->unref(); // SkRefPtr and new both took a reference.
- insert("Type", typeName.get());
+ insert("Type", new SkPDFName(type))->unref();
}
SkPDFDict::~SkPDFDict() {
return result;
}
-void SkPDFDict::insert(SkPDFName* key, SkPDFObject* value) {
+SkPDFObject* SkPDFDict::insert(SkPDFName* key, SkPDFObject* value) {
struct Rec* newEntry = fValue.append();
newEntry->key = key;
SkSafeRef(newEntry->key);
newEntry->value = value;
SkSafeRef(newEntry->value);
+ return value;
}
-void SkPDFDict::insert(const char key[], SkPDFObject* value) {
+SkPDFObject* SkPDFDict::insert(const char key[], SkPDFObject* value) {
SkRefPtr<SkPDFName> keyName = new SkPDFName(key);
keyName->unref(); // SkRefPtr and new both took a reference.
- insert(keyName.get(), value);
+ return insert(keyName.get(), value);
}
void SkPDFDict::clear() {