helpers for append and insert when the value is a POD.

reduces code-size and perf: fewer refs/unrefs



git-svn-id: http://skia.googlecode.com/svn/trunk@1909 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-07-20 12:14:33 +00:00
parent f5181a496d
commit c789cf1c6f
9 changed files with 172 additions and 107 deletions

View File

@ -274,7 +274,22 @@ public:
* @return The value argument is returned.
*/
SkPDFObject* append(SkPDFObject* value);
/** Creates a SkPDFInt object and appends it to the array.
* @param value The value to add to the array.
*/
void appendInt(int32_t value);
/** Creates a SkPDFScalar object and appends it to the array.
* @param value The value to add to the array.
*/
void appendScalar(SkScalar value);
/** Creates a SkPDFName object and appends it to the array.
* @param value The value to add to the array.
*/
void appendName(const char name[]);
private:
static const int kMaxLen = 8191;
SkTDArray<SkPDFObject*> fValue;
@ -320,7 +335,33 @@ public:
* @return The value argument is returned.
*/
SkPDFObject* insert(const char key[], SkPDFObject* value);
/** Add the int to the dictionary with the given key.
* @param key The text of the key for this dictionary entry.
* @param value The int value for this dictionary entry.
*/
void insertInt(const char key[], int32_t value);
/** Add the scalar to the dictionary with the given key.
* @param key The text of the key for this dictionary entry.
* @param value The scalar value for this dictionary entry.
*/
void insertScalar(const char key[], SkScalar value);
/** Add the name to the dictionary with the given key.
* @param key The text of the key for this dictionary entry.
* @param name The name for this dictionary entry.
*/
void insertName(const char key[], const char name[]);
/** Add the name to the dictionary with the given key.
* @param key The text of the key for this dictionary entry.
* @param name The name for this dictionary entry.
*/
void insertName(const char key[], const SkString& name) {
this->insertName(key, name.c_str());
}
/** Remove all entries from the dictionary.
*/
void clear();

View File

@ -1045,7 +1045,7 @@ const SkRefPtr<SkPDFDict>& SkPDFDevice::getResourceDict() {
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++)
procSets->append(new SkPDFName(procs[i]))->unref();
procSets->appendName(procs[i]);
fResourceDict->insert("ProcSet", procSets.get());
}
return fResourceDict;
@ -1092,8 +1092,8 @@ SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
mediaBox->reserve(4);
mediaBox->append(zero.get());
mediaBox->append(zero.get());
mediaBox->append(new SkPDFInt(fPageSize.fWidth))->unref();
mediaBox->append(new SkPDFInt(fPageSize.fHeight))->unref();
mediaBox->appendInt(fPageSize.fWidth);
mediaBox->appendInt(fPageSize.fHeight);
return mediaBox;
}

View File

@ -211,7 +211,7 @@ void SkPDFDocument::emitFooter(SkWStream* stream, int64_t objCount) {
// TODO(vandebo) Linearized format will take a Prev entry too.
// TODO(vandebo) PDF/A requires an ID entry.
fTrailerDict->insert("Size", new SkPDFInt(objCount))->unref();
fTrailerDict->insertInt("Size", objCount);
fTrailerDict->insert("Root",
new SkPDFObjRef(fDocCatalog.get()))->unref();
}

View File

@ -261,20 +261,16 @@ void setGlyphWidthAndBoundingBox(SkScalar width, SkIRect box,
SkPDFArray* makeFontBBox(SkIRect glyphBBox, uint16_t emSize) {
SkPDFArray* bbox = new SkPDFArray;
bbox->reserve(4);
bbox->append(new SkPDFScalar(scaleFromFontUnits(glyphBBox.fLeft,
emSize)))->unref();
bbox->append(new SkPDFScalar(scaleFromFontUnits(glyphBBox.fBottom,
emSize)))->unref();
bbox->append(new SkPDFScalar(scaleFromFontUnits(glyphBBox.fRight,
emSize)))->unref();
bbox->append(new SkPDFScalar(scaleFromFontUnits(glyphBBox.fTop,
emSize)))->unref();
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize));
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize));
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize));
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize));
return bbox;
}
SkPDFArray* appendWidth(const int16_t& width, uint16_t emSize,
SkPDFArray* array) {
array->append(new SkPDFScalar(scaleFromFontUnits(width, emSize)))->unref();
array->appendScalar(scaleFromFontUnits(width, emSize));
return array;
}
@ -308,14 +304,14 @@ SkPDFArray* composeAdvanceData(
for (int j = 0; j < advanceInfo->fAdvance.count(); j++)
appendAdvance(advanceInfo->fAdvance[j], emSize,
advanceArray.get());
result->append(new SkPDFInt(advanceInfo->fStartId))->unref();
result->appendInt(advanceInfo->fStartId);
result->append(advanceArray.get());
break;
}
case SkAdvancedTypefaceMetrics::WidthRange::kRun: {
SkASSERT(advanceInfo->fAdvance.count() == 1);
result->append(new SkPDFInt(advanceInfo->fStartId))->unref();
result->append(new SkPDFInt(advanceInfo->fEndId))->unref();
result->appendInt(advanceInfo->fStartId);
result->appendInt(advanceInfo->fEndId);
appendAdvance(advanceInfo->fAdvance[0], emSize, result);
break;
}
@ -594,9 +590,9 @@ SkPDFFont::SkPDFFont(class SkAdvancedTypefaceMetrics* fontInfo,
void SkPDFFont::populateType0Font() {
fMultiByteGlyphs = true;
insert("Subtype", new SkPDFName("Type0"))->unref();
insert("BaseFont", new SkPDFName(fFontInfo->fFontName))->unref();
insert("Encoding", new SkPDFName("Identity-H"))->unref();
insertName("Subtype", "Type0");
insertName("BaseFont", fFontInfo->fFontName);
insertName("Encoding", "Identity-H");
SkRefPtr<SkPDFArray> descendantFonts = new SkPDFArray();
descendantFonts->unref(); // SkRefPtr and new took a reference.
@ -630,13 +626,13 @@ void SkPDFFont::populateToUnicodeTable() {
void SkPDFFont::populateCIDFont() {
fMultiByteGlyphs = true;
insert("BaseFont", new SkPDFName(fFontInfo->fFontName))->unref();
insertName("BaseFont", fFontInfo->fFontName);
if (fFontInfo->fType == SkAdvancedTypefaceMetrics::kType1CID_Font) {
insert("Subtype", new SkPDFName("CIDFontType0"))->unref();
insertName("Subtype", "CIDFontType0");
} else if (fFontInfo->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) {
insert("Subtype", new SkPDFName("CIDFontType2"))->unref();
insert("CIDToGIDMap", new SkPDFName("Identity"))->unref();
insertName("Subtype", "CIDFontType2");
insertName("CIDToGIDMap", "Identity");
} else {
SkASSERT(false);
}
@ -645,7 +641,7 @@ void SkPDFFont::populateCIDFont() {
sysInfo->unref(); // SkRefPtr and new both took a reference.
sysInfo->insert("Registry", new SkPDFString("Adobe"))->unref();
sysInfo->insert("Ordering", new SkPDFString("Identity"))->unref();
sysInfo->insert("Supplement", new SkPDFInt(0))->unref();
sysInfo->insertInt("Supplement", 0);
insert("CIDSystemInfo", sysInfo.get());
addFontDescriptor(0);
@ -659,8 +655,8 @@ void SkPDFFont::populateCIDFont() {
if (widths->size())
insert("W", widths.get());
if (defaultWidth != 0) {
insert("DW", new SkPDFScalar(scaleFromFontUnits(
defaultWidth, fFontInfo->fEmSize)))->unref();
insertScalar("DW", scaleFromFontUnits(defaultWidth,
fFontInfo->fEmSize));
}
}
if (fFontInfo->fVerticalMetrics.get()) {
@ -714,8 +710,8 @@ bool SkPDFFont::populateType1Font(int16_t glyphID) {
if (!addFontDescriptor(defaultWidth))
return false;
insert("Subtype", new SkPDFName("Type1"))->unref();
insert("BaseFont", new SkPDFName(fFontInfo->fFontName))->unref();
insertName("Subtype", "Type1");
insertName("BaseFont", fFontInfo->fFontName);
addWidthInfoFromRange(defaultWidth, widthRangeEntry);
@ -728,10 +724,9 @@ bool SkPDFFont::populateType1Font(int16_t glyphID) {
encoding->insert("Differences", encDiffs.get());
encDiffs->reserve(fLastGlyphID - fFirstGlyphID + 2);
encDiffs->append(new SkPDFInt(1))->unref();
encDiffs->appendInt(1);
for (int gID = fFirstGlyphID; gID <= fLastGlyphID; gID++) {
encDiffs->append(
new SkPDFName(fFontInfo->fGlyphNames->get()[gID]))->unref();
encDiffs->appendName(fFontInfo->fGlyphNames->get()[gID].c_str());
}
if (fFontInfo->fLastGlyphID <= 255)
@ -752,7 +747,7 @@ void SkPDFFont::populateType3Font(int16_t glyphID) {
adjustGlyphRangeForSingleByteEncoding(glyphID);
insert("Subtype", new SkPDFName("Type3"))->unref();
insertName("Subtype", "Type3");
// Flip about the x-axis and scale by 1/1000.
SkMatrix fontMatrix;
fontMatrix.setScale(SkScalarInvert(1000), -SkScalarInvert(1000));
@ -770,7 +765,7 @@ void SkPDFFont::populateType3Font(int16_t glyphID) {
encDiffs->unref(); // SkRefPtr and new both took a reference.
encoding->insert("Differences", encDiffs.get());
encDiffs->reserve(fLastGlyphID - fFirstGlyphID + 2);
encDiffs->append(new SkPDFInt(1))->unref();
encDiffs->appendInt(1);
SkRefPtr<SkPDFArray> widthArray = new SkPDFArray();
widthArray->unref(); // SkRefPtr and new both took a ref.
@ -779,10 +774,10 @@ void SkPDFFont::populateType3Font(int16_t glyphID) {
for (int gID = fFirstGlyphID; gID <= fLastGlyphID; gID++) {
SkString characterName;
characterName.printf("gid%d", gID);
encDiffs->append(new SkPDFName(characterName))->unref();
encDiffs->appendName(characterName.c_str());
const SkGlyph& glyph = cache->getGlyphIDMetrics(gID);
widthArray->append(new SkPDFScalar(SkFixedToScalar(glyph.fAdvanceX)))->unref();
widthArray->appendScalar(SkFixedToScalar(glyph.fAdvanceX));
SkIRect glyphBBox = SkIRect::MakeXYWH(glyph.fLeft, glyph.fTop,
glyph.fWidth, glyph.fHeight);
bbox.join(glyphBBox);
@ -809,14 +804,14 @@ void SkPDFFont::populateType3Font(int16_t glyphID) {
}
insert("FontBBox", makeFontBBox(bbox, 1000))->unref();
insert("FirstChar", new SkPDFInt(fFirstGlyphID))->unref();
insert("LastChar", new SkPDFInt(fLastGlyphID))->unref();
insertInt("FirstChar", fFirstGlyphID);
insertInt("LastChar", fLastGlyphID);
insert("Widths", widthArray.get());
insert("CIDToGIDMap", new SkPDFName("Identity"))->unref();
insertName("CIDToGIDMap", "Identity");
if (fFontInfo && fFontInfo->fLastGlyphID <= 255)
if (fFontInfo && fFontInfo->fLastGlyphID <= 255) {
fFontInfo = NULL;
}
populateToUnicodeTable();
}
@ -846,9 +841,9 @@ bool SkPDFFont::addFontDescriptor(int16_t defaultWidth) {
SkRefPtr<SkPDFStream> fontStream = new SkPDFStream(fontData);
// SkRefPtr and new both ref()'d fontStream, pass one.
fResources.push(fontStream.get());
fontStream->insert("Length1", new SkPDFInt(header))->unref();
fontStream->insert("Length2", new SkPDFInt(data))->unref();
fontStream->insert("Length3", new SkPDFInt(trailer))->unref();
fontStream->insertInt("Length1", header);
fontStream->insertInt("Length2", data);
fontStream->insertInt("Length3", trailer);
fDescriptor->insert("FontFile",
new SkPDFObjRef(fontStream.get()))->unref();
break;
@ -861,8 +856,7 @@ bool SkPDFFont::addFontDescriptor(int16_t defaultWidth) {
// SkRefPtr and new both ref()'d fontStream, pass one.
fResources.push(fontStream.get());
fontStream->insert("Length1",
new SkPDFInt(fontData->getLength()))->unref();
fontStream->insertInt("Length1", fontData->getLength());
fDescriptor->insert("FontFile2",
new SkPDFObjRef(fontStream.get()))->unref();
break;
@ -877,10 +871,9 @@ bool SkPDFFont::addFontDescriptor(int16_t defaultWidth) {
fResources.push(fontStream.get());
if (fFontInfo->fType == SkAdvancedTypefaceMetrics::kCFF_Font) {
fontStream->insert("Subtype", new SkPDFName("Type1C"))->unref();
fontStream->insertName("Subtype", "Type1C");
} else {
fontStream->insert("Subtype",
new SkPDFName("CIDFontType0c"))->unref();
fontStream->insertName("Subtype", "CIDFontType0c");
}
fDescriptor->insert("FontFile3",
new SkPDFObjRef(fontStream.get()))->unref();
@ -895,25 +888,23 @@ bool SkPDFFont::addFontDescriptor(int16_t defaultWidth) {
fDescriptor->ref();
insert("FontDescriptor", new SkPDFObjRef(fDescriptor.get()))->unref();
fDescriptor->insert("FontName", new SkPDFName(
fFontInfo->fFontName))->unref();
fDescriptor->insert("Flags", new SkPDFInt(fFontInfo->fStyle))->unref();
fDescriptor->insert("Ascent", new SkPDFScalar(
scaleFromFontUnits(fFontInfo->fAscent, emSize)))->unref();
fDescriptor->insert("Descent", new SkPDFScalar(
scaleFromFontUnits(fFontInfo->fDescent, emSize)))->unref();
fDescriptor->insert("StemV", new SkPDFScalar(
scaleFromFontUnits(fFontInfo->fStemV, emSize)))->unref();
fDescriptor->insert("CapHeight", new SkPDFScalar(
scaleFromFontUnits(fFontInfo->fCapHeight, emSize)))->unref();
fDescriptor->insert("ItalicAngle", new SkPDFInt(
fFontInfo->fItalicAngle))->unref();
fDescriptor->insertName("FontName", fFontInfo->fFontName);
fDescriptor->insertInt("Flags", fFontInfo->fStyle);
fDescriptor->insertScalar("Ascent",
scaleFromFontUnits(fFontInfo->fAscent, emSize));
fDescriptor->insertScalar("Descent",
scaleFromFontUnits(fFontInfo->fDescent, emSize));
fDescriptor->insertScalar("StemV",
scaleFromFontUnits(fFontInfo->fStemV, emSize));
fDescriptor->insertScalar("CapHeight",
scaleFromFontUnits(fFontInfo->fCapHeight, emSize));
fDescriptor->insertInt("ItalicAngle", fFontInfo->fItalicAngle);
fDescriptor->insert("FontBBox", makeFontBBox(fFontInfo->fBBox,
fFontInfo->fEmSize))->unref();
if (defaultWidth > 0) {
fDescriptor->insert("MissingWidth", new SkPDFScalar(
scaleFromFontUnits(defaultWidth, emSize)))->unref();
fDescriptor->insertScalar("MissingWidth",
scaleFromFontUnits(defaultWidth, emSize));
}
return true;
}
@ -941,9 +932,8 @@ void SkPDFFont::addWidthInfoFromRange(
} else {
appendWidth(defaultWidth, 1000, widthArray.get());
}
insert("FirstChar", new SkPDFInt(firstChar))->unref();
insert("LastChar",
new SkPDFInt(firstChar + widthArray->size() - 1))->unref();
insertInt("FirstChar", firstChar);
insertInt("LastChar", firstChar + widthArray->size() - 1);
insert("Widths", widthArray.get());
}

View File

@ -126,8 +126,8 @@ SkPDFObject* SkPDFGraphicState::GetInvertFunction() {
SkRefPtr<SkPDFArray> domainAndRange = new SkPDFArray;
domainAndRange->unref(); // SkRefPtr and new both took a reference.
domainAndRange->reserve(2);
domainAndRange->append(new SkPDFInt(0))->unref();
domainAndRange->append(new SkPDFInt(1))->unref();
domainAndRange->appendInt(0);
domainAndRange->appendInt(1);
static const char psInvert[] = "{1 exch sub}";
SkRefPtr<SkMemoryStream> psInvertStream =
@ -135,7 +135,7 @@ SkPDFObject* SkPDFGraphicState::GetInvertFunction() {
psInvertStream->unref(); // SkRefPtr and new both took a reference.
invertFunction = new SkPDFStream(psInvertStream.get());
invertFunction->insert("FunctionType", new SkPDFInt(4))->unref();
invertFunction->insertInt("FunctionType", 4);
invertFunction->insert("Domain", domainAndRange.get());
invertFunction->insert("Range", domainAndRange.get());
}
@ -151,13 +151,13 @@ SkPDFGraphicState* SkPDFGraphicState::getSMaskGraphicState(
SkRefPtr<SkPDFDict> sMaskDict = new SkPDFDict("Mask");
sMaskDict->unref(); // SkRefPtr and new both took a reference.
sMaskDict->insert("S", new SkPDFName("Alpha"))->unref();
sMaskDict->insertName("S", "Alpha");
sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref();
SkPDFGraphicState* result = new SkPDFGraphicState;
result->fPopulated = true;
result->fSMask = true;
result->insert("Type", new SkPDFName("ExtGState"))->unref();
result->insertName("Type", "ExtGState");
result->insert("SMask", sMaskDict.get());
result->fResources.push(sMask);
sMask->ref();
@ -180,8 +180,8 @@ SkPDFGraphicState* SkPDFGraphicState::getNoSMaskGraphicState() {
noSMaskGS = new SkPDFGraphicState;
noSMaskGS->fPopulated = true;
noSMaskGS->fSMask = true;
noSMaskGS->insert("Type", new SkPDFName("ExtGState"))->unref();
noSMaskGS->insert("SMask", new SkPDFName("None"))->unref();
noSMaskGS->insertName("Type", "ExtGState");
noSMaskGS->insertName("SMask", "None");
}
noSMaskGS->ref();
return noSMaskGS;
@ -208,7 +208,7 @@ SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint)
void SkPDFGraphicState::populateDict() {
if (!fPopulated) {
fPopulated = true;
insert("Type", new SkPDFName("ExtGState"))->unref();
insertName("Type", "ExtGState");
SkRefPtr<SkPDFScalar> alpha =
new SkPDFScalar(fPaint.getAlpha() * SkScalarInvert(0xFF));
@ -221,17 +221,17 @@ void SkPDFGraphicState::populateDict() {
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);
insert("LC", new SkPDFInt(fPaint.getStrokeCap()))->unref();
insertInt("LC", fPaint.getStrokeCap());
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);
insert("LJ", new SkPDFInt(fPaint.getStrokeJoin()))->unref();
insertInt("LJ", fPaint.getStrokeJoin());
insert("LW", new SkPDFScalar(fPaint.getStrokeWidth()))->unref();
insert("ML", new SkPDFScalar(fPaint.getStrokeMiter()))->unref();
insertScalar("LW", fPaint.getStrokeWidth());
insertScalar("ML", fPaint.getStrokeMiter());
insert("SA", new SkPDFBool(true))->unref(); // Auto stroke adjustment.
SkXfermode::Mode xfermode = SkXfermode::kSrcOver_Mode;
@ -244,8 +244,7 @@ void SkPDFGraphicState::populateDict() {
xfermode = SkXfermode::kSrcOver_Mode;
NOT_IMPLEMENTED("unsupported xfermode", false);
}
insert("BM",
new SkPDFName(blend_mode_from_xfermode(xfermode)))->unref();
insertName("BM", blend_mode_from_xfermode(xfermode));
}
}

View File

@ -370,12 +370,12 @@ SkPDFObject* SkPDFShader::rangeObject() {
if (range == NULL) {
range = new SkPDFArray;
range->reserve(6);
range->append(new SkPDFInt(0))->unref();
range->append(new SkPDFInt(1))->unref();
range->append(new SkPDFInt(0))->unref();
range->append(new SkPDFInt(1))->unref();
range->append(new SkPDFInt(0))->unref();
range->append(new SkPDFInt(1))->unref();
range->appendInt(0);
range->appendInt(1);
range->appendInt(0);
range->appendInt(1);
range->appendInt(0);
range->appendInt(1);
}
return range;
}
@ -445,10 +445,10 @@ void SkPDFShader::doFunctionShader() {
SkRefPtr<SkPDFArray> domain = new SkPDFArray;
domain->unref(); // SkRefPtr and new both took a reference.
domain->reserve(4);
domain->append(new SkPDFScalar(bbox.fLeft))->unref();
domain->append(new SkPDFScalar(bbox.fRight))->unref();
domain->append(new SkPDFScalar(bbox.fTop))->unref();
domain->append(new SkPDFScalar(bbox.fBottom))->unref();
domain->appendScalar(bbox.fLeft);
domain->appendScalar(bbox.fRight);
domain->appendScalar(bbox.fTop);
domain->appendScalar(bbox.fBottom);
SkString functionCode;
// The two point radial gradient further references fState.get()->fInfo
@ -474,14 +474,14 @@ void SkPDFShader::doFunctionShader() {
SkRefPtr<SkPDFDict> pdfShader = new SkPDFDict;
pdfShader->unref(); // SkRefPtr and new both took a reference.
pdfShader->insert("ShadingType", new SkPDFInt(1))->unref();
pdfShader->insert("ColorSpace", new SkPDFName("DeviceRGB"))->unref();
pdfShader->insertInt("ShadingType", 1);
pdfShader->insertName("ColorSpace", "DeviceRGB");
pdfShader->insert("Domain", domain.get());
pdfShader->insert("Function", new SkPDFObjRef(function.get()))->unref();
fContent = new SkPDFDict("Pattern");
fContent->unref(); // SkRefPtr and new both took a reference.
fContent->insert("PatternType", new SkPDFInt(2))->unref();
fContent->insertInt("PatternType", 2);
fContent->insert("Matrix", SkPDFUtils::MatrixToArray(finalMatrix))->unref();
fContent->insert("Shading", pdfShader.get());
}
@ -656,10 +656,10 @@ void SkPDFShader::doImageShader() {
SkRefPtr<SkPDFArray> patternBBoxArray = new SkPDFArray;
patternBBoxArray->unref(); // SkRefPtr and new both took a reference.
patternBBoxArray->reserve(4);
patternBBoxArray->append(new SkPDFScalar(patternBBox.fLeft))->unref();
patternBBoxArray->append(new SkPDFScalar(patternBBox.fTop))->unref();
patternBBoxArray->append(new SkPDFScalar(patternBBox.fRight))->unref();
patternBBoxArray->append(new SkPDFScalar(patternBBox.fBottom))->unref();
patternBBoxArray->appendScalar(patternBBox.fLeft);
patternBBoxArray->appendScalar(patternBBox.fTop);
patternBBoxArray->appendScalar(patternBBox.fRight);
patternBBoxArray->appendScalar(patternBBox.fBottom);
// Put the canvas into the pattern stream (fContent).
SkRefPtr<SkStream> content = pattern.content();
@ -668,13 +668,13 @@ void SkPDFShader::doImageShader() {
fContent = new SkPDFStream(content.get());
fContent->unref(); // SkRefPtr and new both took a reference.
fContent->insert("Type", new SkPDFName("Pattern"))->unref();
fContent->insert("PatternType", new SkPDFInt(1))->unref();
fContent->insert("PaintType", new SkPDFInt(1))->unref();
fContent->insert("TilingType", new SkPDFInt(1))->unref();
fContent->insertName("Type", "Pattern");
fContent->insertInt("PatternType", 1);
fContent->insertInt("PaintType", 1);
fContent->insertInt("TilingType", 1);
fContent->insert("BBox", patternBBoxArray.get());
fContent->insert("XStep", new SkPDFScalar(patternBBox.width()))->unref();
fContent->insert("YStep", new SkPDFScalar(patternBBox.height()))->unref();
fContent->insertScalar("XStep", patternBBox.width());
fContent->insertScalar("YStep", patternBBox.height());
fContent->insert("Resources", pattern.getResourceDict().get());
fContent->insert("Matrix", SkPDFUtils::MatrixToArray(finalMatrix))->unref();
@ -688,7 +688,7 @@ SkPDFStream* SkPDFShader::makePSFunction(const SkString& psCode,
funcStream->unref(); // SkRefPtr and new both took a reference.
SkPDFStream* result = new SkPDFStream(funcStream.get());
result->insert("FunctionType", new SkPDFInt(4))->unref();
result->insertInt("FunctionType", 4);
result->insert("Domain", domain);
result->insert("Range", rangeObject());
return result;

View File

@ -33,7 +33,7 @@ SkPDFStream::SkPDFStream(SkStream* stream) {
fPlainData = stream;
fLength = fPlainData->getLength();
}
insert("Length", new SkPDFInt(fLength))->unref();
insertInt("Length", fLength);
}
SkPDFStream::~SkPDFStream() {

View File

@ -337,6 +337,23 @@ SkPDFObject* SkPDFArray::append(SkPDFObject* value) {
return value;
}
void SkPDFArray::appendInt(int32_t value) {
SkASSERT(fValue.count() < kMaxLen);
fValue.push(new SkPDFInt(value));
}
void SkPDFArray::appendScalar(SkScalar value) {
SkASSERT(fValue.count() < kMaxLen);
fValue.push(new SkPDFScalar(value));
}
void SkPDFArray::appendName(const char name[]) {
SkASSERT(fValue.count() < kMaxLen);
fValue.push(new SkPDFName(name));
}
///////////////////////////////////////////////////////////////////////////////
SkPDFDict::SkPDFDict() {}
SkPDFDict::SkPDFDict(const char type[]) {
@ -391,6 +408,24 @@ SkPDFObject* SkPDFDict::insert(const char key[], SkPDFObject* value) {
return value;
}
void SkPDFDict::insertInt(const char key[], int32_t value) {
struct Rec* newEntry = fValue.append();
newEntry->key = new SkPDFName(key);
newEntry->value = new SkPDFInt(value);
}
void SkPDFDict::insertScalar(const char key[], SkScalar value) {
struct Rec* newEntry = fValue.append();
newEntry->key = new SkPDFName(key);
newEntry->value = new SkPDFScalar(value);
}
void SkPDFDict::insertName(const char key[], const char name[]) {
struct Rec* newEntry = fValue.append();
newEntry->key = new SkPDFName(key);
newEntry->value = new SkPDFName(name);
}
void SkPDFDict::clear() {
for (int i = 0; i < fValue.count(); i++) {
fValue[i].key->unref();

View File

@ -31,7 +31,7 @@ SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
SkPDFArray* result = new SkPDFArray;
result->reserve(6);
for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) {
result->append(new SkPDFScalar(values[i]))->unref();
result->appendScalar(values[i]);
}
return result;
}