No effect cleanup in pdf code.
Review URL: http://codereview.appspot.com/4927042 git-svn-id: http://skia.googlecode.com/svn/trunk@2146 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
971d0c8049
commit
769fa6a013
@ -110,10 +110,10 @@ private:
|
||||
SkPDFObject* fSubstitute;
|
||||
};
|
||||
|
||||
// TODO(vandebo) Make this a hash if it's a performance problem.
|
||||
// TODO(vandebo): Make this a hash if it's a performance problem.
|
||||
SkTDArray<struct Rec> fCatalog;
|
||||
|
||||
// TODO(arthurhsu) Make this a hash if it's a performance problem.
|
||||
// TODO(arthurhsu): Make this a hash if it's a performance problem.
|
||||
SkTDArray<SubstituteMapping> fSubstituteMap;
|
||||
SkTDArray<SkPDFObject*> fSubstituteResourcesFirstPage;
|
||||
SkTDArray<SkPDFObject*> fSubstituteResourcesRemaining;
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
* inverse scale+translate to accommodate the one that SkPDFDevice
|
||||
* always does.
|
||||
*/
|
||||
// TODO(vandebo) The sizes should be SkSize and not SkISize.
|
||||
// TODO(vandebo): The sizes should be SkSize and not SkISize.
|
||||
SK_API SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
|
||||
const SkMatrix& initialTransform);
|
||||
SK_API virtual ~SkPDFDevice();
|
||||
@ -110,7 +110,7 @@ public:
|
||||
};
|
||||
|
||||
/** Sets the drawing area for the device. Subsequent draw calls are directed
|
||||
* to the specific drawing area (margin or content). The default drawing
|
||||
* to the specific drawing area (margin or content). The default drawing
|
||||
* area is the content drawing area.
|
||||
*
|
||||
* Currently if margin content is drawn and then a complex (for PDF) xfer
|
||||
@ -161,7 +161,7 @@ public:
|
||||
return *(fFontGlyphUsage.get());
|
||||
}
|
||||
|
||||
// TODO(vandebo) Remove this as soon as Chrome's Platform device goes away.
|
||||
// TODO(vandebo): Remove this as soon as Chrome's Platform device goes away.
|
||||
void setOrigin(int x, int y);
|
||||
virtual void setMatrixClip(const SkMatrix& m, const SkRegion& r,
|
||||
const SkClipStack& c);
|
||||
@ -169,7 +169,7 @@ public:
|
||||
private:
|
||||
typedef SkDevice INHERITED;
|
||||
|
||||
// TODO(vandebo) push most of SkPDFDevice's state into a core object in
|
||||
// TODO(vandebo): push most of SkPDFDevice's state into a core object in
|
||||
// order to get the right access levels without using friend.
|
||||
friend class ScopedContentEntry;
|
||||
|
||||
|
@ -61,7 +61,7 @@ private:
|
||||
// Indicates what form (or if) the stream has been requested.
|
||||
State fState;
|
||||
|
||||
// TODO(vandebo) Use SkData (after removing deprecated constructor).
|
||||
// TODO(vandebo): Use SkData (after removing deprecated constructor).
|
||||
SkRefPtr<SkStream> fData;
|
||||
SkRefPtr<SkPDFStream> fSubstitute;
|
||||
|
||||
|
@ -29,8 +29,9 @@ SkPDFObject* SkPDFCatalog::addObject(SkPDFObject* obj, bool onFirstPage) {
|
||||
return obj;
|
||||
}
|
||||
SkASSERT(fNextFirstPageObjNum == 0);
|
||||
if (onFirstPage)
|
||||
if (onFirstPage) {
|
||||
fFirstPageCount++;
|
||||
}
|
||||
|
||||
struct Rec newEntry(obj, onFirstPage);
|
||||
fCatalog.append(1, &newEntry);
|
||||
@ -59,8 +60,9 @@ size_t SkPDFCatalog::getObjectNumberSize(SkPDFObject* obj) {
|
||||
|
||||
int SkPDFCatalog::findObjectIndex(SkPDFObject* obj) const {
|
||||
for (int i = 0; i < fCatalog.count(); i++) {
|
||||
if (fCatalog[i].fObject == obj)
|
||||
if (fCatalog[i].fObject == obj) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// If it's not in the main array, check if it's a substitute object.
|
||||
for (int i = 0; i < fSubstituteMap.count(); ++i) {
|
||||
@ -77,12 +79,14 @@ int SkPDFCatalog::assignObjNum(SkPDFObject* obj) {
|
||||
// to the resource list.
|
||||
SkASSERT(pos >= 0);
|
||||
uint32_t currentIndex = pos;
|
||||
if (fCatalog[currentIndex].fObjNumAssigned)
|
||||
if (fCatalog[currentIndex].fObjNumAssigned) {
|
||||
return currentIndex + 1;
|
||||
}
|
||||
|
||||
// First assignment.
|
||||
if (fNextFirstPageObjNum == 0)
|
||||
if (fNextFirstPageObjNum == 0) {
|
||||
fNextFirstPageObjNum = fCatalog.count() - fFirstPageCount + 1;
|
||||
}
|
||||
|
||||
uint32_t objNum;
|
||||
if (fCatalog[currentIndex].fOnFirstPage) {
|
||||
@ -96,8 +100,9 @@ int SkPDFCatalog::assignObjNum(SkPDFObject* obj) {
|
||||
// When we assign an object an object number, we put it in that array
|
||||
// offset (minus 1 because object number 0 is reserved).
|
||||
SkASSERT(!fCatalog[objNum - 1].fObjNumAssigned);
|
||||
if (objNum - 1 != currentIndex)
|
||||
if (objNum - 1 != currentIndex) {
|
||||
SkTSwap(fCatalog[objNum - 1], fCatalog[currentIndex]);
|
||||
}
|
||||
fCatalog[objNum - 1].fObjNumAssigned = true;
|
||||
return objNum;
|
||||
}
|
||||
@ -105,7 +110,7 @@ int SkPDFCatalog::assignObjNum(SkPDFObject* obj) {
|
||||
int32_t SkPDFCatalog::emitXrefTable(SkWStream* stream, bool firstPage) {
|
||||
int first = -1;
|
||||
int last = fCatalog.count() - 1;
|
||||
// TODO(vandebo) support linearized format.
|
||||
// TODO(vandebo): Support linearized format.
|
||||
// int last = fCatalog.count() - fFirstPageCount - 1;
|
||||
// if (firstPage) {
|
||||
// first = fCatalog.count() - fFirstPageCount;
|
||||
|
@ -54,10 +54,11 @@ static SkPaint calculate_text_paint(const SkPaint& paint) {
|
||||
kStdFakeBoldInterpValues,
|
||||
kStdFakeBoldInterpLength);
|
||||
SkScalar width = SkScalarMul(result.getTextSize(), fakeBoldScale);
|
||||
if (result.getStyle() == SkPaint::kFill_Style)
|
||||
if (result.getStyle() == SkPaint::kFill_Style) {
|
||||
result.setStyle(SkPaint::kStrokeAndFill_Style);
|
||||
else
|
||||
} else {
|
||||
width += result.getStrokeWidth();
|
||||
}
|
||||
result.setStrokeWidth(width);
|
||||
}
|
||||
return result;
|
||||
@ -67,8 +68,9 @@ static SkPaint calculate_text_paint(const SkPaint& paint) {
|
||||
static void align_text(SkDrawCacheProc glyphCacheProc, const SkPaint& paint,
|
||||
const uint16_t* glyphs, size_t len, SkScalar* x,
|
||||
SkScalar* y, SkScalar* width) {
|
||||
if (paint.getTextAlign() == SkPaint::kLeft_Align && width == NULL)
|
||||
if (paint.getTextAlign() == SkPaint::kLeft_Align && width == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkMatrix ident;
|
||||
ident.reset();
|
||||
@ -79,16 +81,18 @@ static void align_text(SkDrawCacheProc glyphCacheProc, const SkPaint& paint,
|
||||
const char* stop = reinterpret_cast<const char*>(glyphs + len);
|
||||
SkFixed xAdv = 0, yAdv = 0;
|
||||
|
||||
// TODO(vandebo) This probably needs to take kerning into account.
|
||||
// TODO(vandebo): This probably needs to take kerning into account.
|
||||
while (start < stop) {
|
||||
const SkGlyph& glyph = glyphCacheProc(cache, &start, 0, 0);
|
||||
xAdv += glyph.fAdvanceX;
|
||||
yAdv += glyph.fAdvanceY;
|
||||
};
|
||||
if (width)
|
||||
if (width) {
|
||||
*width = SkFixedToScalar(xAdv);
|
||||
if (paint.getTextAlign() == SkPaint::kLeft_Align)
|
||||
}
|
||||
if (paint.getTextAlign() == SkPaint::kLeft_Align) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkScalar xAdj = SkFixedToScalar(xAdv);
|
||||
SkScalar yAdj = SkFixedToScalar(yAdv);
|
||||
@ -277,7 +281,7 @@ static void emit_clip(SkPath* clipPath, SkRect* clipRect,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(vandebo) Take advantage of SkClipStack::getSaveCount(), the PDF
|
||||
// TODO(vandebo): Take advantage of SkClipStack::getSaveCount(), the PDF
|
||||
// graphic state stack, and the fact that we can know all the clips used
|
||||
// on the page to optimize this.
|
||||
void GraphicStackState::updateClip(const SkClipStack& clipStack,
|
||||
@ -1280,7 +1284,7 @@ ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack,
|
||||
createFormXObjectFromDevice(dst);
|
||||
}
|
||||
}
|
||||
// TODO(vandebo) Figure out how/if we can handle the following modes:
|
||||
// TODO(vandebo): Figure out how/if we can handle the following modes:
|
||||
// SrcAtop, DestAtop, Xor, Plus.
|
||||
|
||||
// These xfer modes don't draw source at all.
|
||||
|
@ -68,8 +68,9 @@ SkPDFDocument::~SkPDFDocument() {
|
||||
|
||||
// The page tree has both child and parent pointers, so it creates a
|
||||
// reference cycle. We must clear that cycle to properly reclaim memory.
|
||||
for (int i = 0; i < fPageTree.count(); i++)
|
||||
for (int i = 0; i < fPageTree.count(); i++) {
|
||||
fPageTree[i]->clear();
|
||||
}
|
||||
fPageTree.safeUnrefAll();
|
||||
fPageResources.safeUnrefAll();
|
||||
fSubstitutes.safeUnrefAll();
|
||||
@ -86,13 +87,13 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
|
||||
}
|
||||
|
||||
// We haven't emitted the document before if fPageTree is empty.
|
||||
if (fPageTree.count() == 0) {
|
||||
if (fPageTree.isEmpty()) {
|
||||
SkPDFDict* pageTreeRoot;
|
||||
SkPDFPage::GeneratePageTree(fPages, fCatalog.get(), &fPageTree,
|
||||
&pageTreeRoot);
|
||||
fDocCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref();
|
||||
|
||||
/* TODO(vandebo) output intent
|
||||
/* TODO(vandebo): output intent
|
||||
SkRefPtr<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
|
||||
outputIntent->unref(); // SkRefPtr and new both took a reference.
|
||||
outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref();
|
||||
@ -131,21 +132,24 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
|
||||
// Add the size of resources of substitute objects used on page 1.
|
||||
fileOffset += fCatalog->setSubstituteResourcesOffsets(fileOffset, true);
|
||||
if (fPages.count() > 1) {
|
||||
// TODO(vandebo) For linearized format, save the start of the
|
||||
// TODO(vandebo): For linearized format, save the start of the
|
||||
// first page xref table and calculate the size.
|
||||
}
|
||||
|
||||
for (int i = 0; i < fPageTree.count(); i++)
|
||||
for (int i = 0; i < fPageTree.count(); i++) {
|
||||
fileOffset += fCatalog->setFileOffset(fPageTree[i], fileOffset);
|
||||
}
|
||||
|
||||
for (int i = 1; i < fPages.count(); i++)
|
||||
for (int i = 1; i < fPages.count(); i++) {
|
||||
fileOffset += fPages[i]->getPageSize(fCatalog.get(), fileOffset);
|
||||
}
|
||||
|
||||
for (int i = fSecondPageFirstResourceIndex;
|
||||
i < fPageResources.count();
|
||||
i++)
|
||||
i++) {
|
||||
fileOffset += fCatalog->setFileOffset(fPageResources[i],
|
||||
fileOffset);
|
||||
}
|
||||
|
||||
fileOffset += fCatalog->setSubstituteResourcesOffsets(fileOffset,
|
||||
false);
|
||||
@ -160,9 +164,9 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
|
||||
fPageResources[i]->emit(stream, fCatalog.get(), true);
|
||||
}
|
||||
fCatalog->emitSubstituteResources(stream, true);
|
||||
// TODO(vandebo) support linearized format
|
||||
// TODO(vandebo): Support linearized format
|
||||
// if (fPages.size() > 1) {
|
||||
// // TODO(vandebo) save the file offset for the first page xref table.
|
||||
// // TODO(vandebo): Save the file offset for the first page xref table.
|
||||
// fCatalog->emitXrefTable(stream, true);
|
||||
// }
|
||||
|
||||
@ -187,7 +191,7 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
|
||||
}
|
||||
|
||||
bool SkPDFDocument::setPage(int pageNumber, SkPDFDevice* pdfDevice) {
|
||||
if (fPageTree.count() != 0) {
|
||||
if (!fPageTree.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -209,7 +213,7 @@ bool SkPDFDocument::setPage(int pageNumber, SkPDFDevice* pdfDevice) {
|
||||
}
|
||||
|
||||
bool SkPDFDocument::appendPage(SkPDFDevice* pdfDevice) {
|
||||
if (fPageTree.count() != 0) {
|
||||
if (!fPageTree.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -241,8 +245,8 @@ void SkPDFDocument::emitFooter(SkWStream* stream, int64_t objCount) {
|
||||
fTrailerDict = new SkPDFDict();
|
||||
fTrailerDict->unref(); // SkRefPtr and new both took a reference.
|
||||
|
||||
// TODO(vandebo) Linearized format will take a Prev entry too.
|
||||
// TODO(vandebo) PDF/A requires an ID entry.
|
||||
// TODO(vandebo): Linearized format will take a Prev entry too.
|
||||
// TODO(vandebo): PDF/A requires an ID entry.
|
||||
fTrailerDict->insertInt("Size", objCount);
|
||||
fTrailerDict->insert("Root",
|
||||
new SkPDFObjRef(fDocCatalog.get()))->unref();
|
||||
|
@ -44,18 +44,20 @@ bool parsePFBSection(const uint8_t** src, size_t* len, int sectionType,
|
||||
// an ASCII section (includes a length), type two is a binary section
|
||||
// (includes a length) and type three is an EOF marker with no length.
|
||||
const uint8_t* buf = *src;
|
||||
if (*len < 2 || buf[0] != 0x80 || buf[1] != sectionType)
|
||||
if (*len < 2 || buf[0] != 0x80 || buf[1] != sectionType) {
|
||||
return false;
|
||||
if (buf[1] == 3)
|
||||
} else if (buf[1] == 3) {
|
||||
return true;
|
||||
if (*len < 6)
|
||||
} else if (*len < 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = (size_t)buf[2] | ((size_t)buf[3] << 8) | ((size_t)buf[4] << 16) |
|
||||
((size_t)buf[5] << 24);
|
||||
size_t consumed = *size + 6;
|
||||
if (consumed > *len)
|
||||
if (consumed > *len) {
|
||||
return false;
|
||||
}
|
||||
*src = *src + consumed;
|
||||
*len = *len - consumed;
|
||||
return true;
|
||||
@ -85,17 +87,20 @@ bool parsePFA(const char* src, size_t size, size_t* headerLen,
|
||||
const char* end = src + size;
|
||||
|
||||
const char* dataPos = strstr(src, "eexec");
|
||||
if (!dataPos)
|
||||
if (!dataPos) {
|
||||
return false;
|
||||
}
|
||||
dataPos += strlen("eexec");
|
||||
while ((*dataPos == '\n' || *dataPos == '\r' || *dataPos == ' ') &&
|
||||
dataPos < end)
|
||||
dataPos < end) {
|
||||
dataPos++;
|
||||
}
|
||||
*headerLen = dataPos - src;
|
||||
|
||||
const char* trailerPos = strstr(dataPos, "cleartomark");
|
||||
if (!trailerPos)
|
||||
if (!trailerPos) {
|
||||
return false;
|
||||
}
|
||||
int zeroCount = 0;
|
||||
for (trailerPos--; trailerPos > dataPos && zeroCount < 512; trailerPos--) {
|
||||
if (*trailerPos == '\n' || *trailerPos == '\r' || *trailerPos == ' ') {
|
||||
@ -106,8 +111,9 @@ bool parsePFA(const char* src, size_t size, size_t* headerLen,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (zeroCount != 512)
|
||||
if (zeroCount != 512) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*hexDataLen = trailerPos - src - *headerLen;
|
||||
*trailerLen = size - *headerLen - *hexDataLen;
|
||||
@ -115,10 +121,12 @@ bool parsePFA(const char* src, size_t size, size_t* headerLen,
|
||||
// Verify that the data section is hex encoded and count the bytes.
|
||||
int nibbles = 0;
|
||||
for (; dataPos < trailerPos; dataPos++) {
|
||||
if (isspace(*dataPos))
|
||||
if (isspace(*dataPos)) {
|
||||
continue;
|
||||
if (!isxdigit(*dataPos))
|
||||
}
|
||||
if (!isxdigit(*dataPos)) {
|
||||
return false;
|
||||
}
|
||||
nibbles++;
|
||||
}
|
||||
*dataLen = (nibbles + 1) / 2;
|
||||
@ -127,11 +135,15 @@ bool parsePFA(const char* src, size_t size, size_t* headerLen,
|
||||
}
|
||||
|
||||
int8_t hexToBin(uint8_t c) {
|
||||
if (!isxdigit(c))
|
||||
if (!isxdigit(c)) {
|
||||
return -1;
|
||||
if (c <= '9') return c - '0';
|
||||
if (c <= 'F') return c - 'A' + 10;
|
||||
if (c <= 'f') return c - 'a' + 10;
|
||||
} else if (c <= '9') {
|
||||
return c - '0';
|
||||
} else if (c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
} else if (c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -158,8 +170,9 @@ SkStream* handleType1Stream(SkStream* srcStream, size_t* headerLen,
|
||||
while (read < srcLen) {
|
||||
size_t got = srcStream->read((void *)staticStream->getAtPos(),
|
||||
srcLen - read);
|
||||
if (got == 0)
|
||||
if (got == 0) {
|
||||
return NULL;
|
||||
}
|
||||
read += got;
|
||||
staticStream->seek(read);
|
||||
}
|
||||
@ -169,8 +182,9 @@ SkStream* handleType1Stream(SkStream* srcStream, size_t* headerLen,
|
||||
static const size_t kBufSize = 4096;
|
||||
uint8_t buf[kBufSize];
|
||||
size_t amount;
|
||||
while ((amount = srcStream->read(buf, kBufSize)) > 0)
|
||||
while ((amount = srcStream->read(buf, kBufSize)) > 0) {
|
||||
dynamicStream.write(buf, amount);
|
||||
}
|
||||
amount = 0;
|
||||
dynamicStream.write(&amount, 1); // NULL terminator.
|
||||
data = dynamicStream.copyToData();
|
||||
@ -211,8 +225,9 @@ SkStream* handleType1Stream(SkStream* srcStream, size_t* headerLen,
|
||||
bool highNibble = true;
|
||||
for (; hexData < trailer; hexData++) {
|
||||
char curNibble = hexToBin(*hexData);
|
||||
if (curNibble < 0)
|
||||
if (curNibble < 0) {
|
||||
continue;
|
||||
}
|
||||
if (highNibble) {
|
||||
dataByte = curNibble << 4;
|
||||
highNibble = false;
|
||||
@ -222,8 +237,9 @@ SkStream* handleType1Stream(SkStream* srcStream, size_t* headerLen,
|
||||
((char *)result->getAtPos())[outputOffset++] = dataByte;
|
||||
}
|
||||
}
|
||||
if (!highNibble)
|
||||
if (!highNibble) {
|
||||
((char *)result->getAtPos())[outputOffset++] = dataByte;
|
||||
}
|
||||
SkASSERT(outputOffset == *dataLen);
|
||||
result->seek(*headerLen + outputOffset);
|
||||
|
||||
@ -450,7 +466,9 @@ static void append_bfrange_section(const SkTDArray<BFRange>& bfrange,
|
||||
void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
|
||||
const SkPDFGlyphSet* subset,
|
||||
SkDynamicMemoryWStream* cmap) {
|
||||
if (glyphToUnicode.count() == 0) return;
|
||||
if (glyphToUnicode.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkTDArray<BFChar> bfcharEntries;
|
||||
SkTDArray<BFRange> bfrangeEntries;
|
||||
@ -795,11 +813,12 @@ SkMutex& SkPDFFont::CanonicalFontsMutex() {
|
||||
|
||||
// static
|
||||
bool SkPDFFont::Find(uint32_t fontID, uint16_t glyphID, int* index) {
|
||||
// TODO(vandebo) optimize this, do only one search?
|
||||
// TODO(vandebo): Optimize this, do only one search?
|
||||
FontRec search(NULL, fontID, glyphID);
|
||||
*index = CanonicalFonts().find(search);
|
||||
if (*index >= 0)
|
||||
if (*index >= 0) {
|
||||
return true;
|
||||
}
|
||||
search.fGlyphID = 0;
|
||||
*index = CanonicalFonts().find(search);
|
||||
return false;
|
||||
@ -927,14 +946,16 @@ void SkPDFFont::adjustGlyphRangeForSingleByteEncoding(int16_t glyphID) {
|
||||
}
|
||||
|
||||
bool SkPDFFont::FontRec::operator==(const SkPDFFont::FontRec& b) const {
|
||||
if (fFontID != b.fFontID)
|
||||
if (fFontID != b.fFontID) {
|
||||
return false;
|
||||
}
|
||||
if (fFont != NULL && b.fFont != NULL) {
|
||||
return fFont->fFirstGlyphID == b.fFont->fFirstGlyphID &&
|
||||
fFont->fLastGlyphID == b.fFont->fLastGlyphID;
|
||||
}
|
||||
if (fGlyphID == 0 || b.fGlyphID == 0)
|
||||
if (fGlyphID == 0 || b.fGlyphID == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fFont != NULL) {
|
||||
return fFont->fFirstGlyphID <= b.fGlyphID &&
|
||||
@ -1242,8 +1263,9 @@ bool SkPDFType1Font::populate(int16_t glyphID) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!addFontDescriptor(defaultWidth))
|
||||
if (!addFontDescriptor(defaultWidth)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
insertName("Subtype", "Type1");
|
||||
insertName("BaseFont", fontInfo()->fFontName);
|
||||
@ -1286,8 +1308,9 @@ void SkPDFType1Font::addWidthInfoFromRange(
|
||||
} else {
|
||||
firstChar = startIndex + widthRangeEntry->fStartId;
|
||||
}
|
||||
for (int i = startIndex; i < endIndex; i++)
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
appendWidth(widthRangeEntry->fAdvance[i], emSize, widthArray.get());
|
||||
}
|
||||
} else {
|
||||
appendWidth(defaultWidth, 1000, widthArray.get());
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ static const char* blend_mode_from_xfermode(SkXfermode::Mode mode) {
|
||||
case SkXfermode::kDstOut_Mode:
|
||||
return "Normal";
|
||||
|
||||
// TODO(vandebo) Figure out if we can support more of these modes.
|
||||
// TODO(vandebo): Figure out if we can support more of these modes.
|
||||
case SkXfermode::kSrcATop_Mode:
|
||||
case SkXfermode::kDstATop_Mode:
|
||||
case SkXfermode::kXor_Mode:
|
||||
|
@ -75,10 +75,12 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
|
||||
dst += 3;
|
||||
alphaDst[0] = (SkGetPackedA4444(src[x]) << 4) |
|
||||
SkGetPackedA4444(src[x + 1]);
|
||||
if (alphaDst[0] != 0xFF)
|
||||
if (alphaDst[0] != 0xFF) {
|
||||
hasAlpha = true;
|
||||
if (alphaDst[0])
|
||||
}
|
||||
if (alphaDst[0]) {
|
||||
isTransparent = false;
|
||||
}
|
||||
alphaDst++;
|
||||
}
|
||||
if (srcRect.width() & 1) {
|
||||
@ -87,10 +89,12 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
|
||||
dst[1] = (SkGetPackedB4444(src[x]) << 4);
|
||||
dst += 2;
|
||||
alphaDst[0] = (SkGetPackedA4444(src[x]) << 4);
|
||||
if (alphaDst[0] != 0xF0)
|
||||
if (alphaDst[0] != 0xF0) {
|
||||
hasAlpha = true;
|
||||
if (alphaDst[0] & 0xF0)
|
||||
}
|
||||
if (alphaDst[0] & 0xF0) {
|
||||
isTransparent = false;
|
||||
}
|
||||
alphaDst++;
|
||||
}
|
||||
}
|
||||
@ -126,10 +130,12 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
|
||||
dst[2] = SkGetPackedB32(src[x]);
|
||||
dst += 3;
|
||||
alphaDst[0] = SkGetPackedA32(src[x]);
|
||||
if (alphaDst[0] != 0xFF)
|
||||
if (alphaDst[0] != 0xFF) {
|
||||
hasAlpha = true;
|
||||
if (alphaDst[0])
|
||||
}
|
||||
if (alphaDst[0]) {
|
||||
isTransparent = false;
|
||||
}
|
||||
alphaDst++;
|
||||
}
|
||||
}
|
||||
@ -156,20 +162,24 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
|
||||
} else {
|
||||
alphaDst[0] = src[x / 8];
|
||||
}
|
||||
if (x + 7 < srcRect.fRight && alphaDst[0] != 0xFF)
|
||||
if (x + 7 < srcRect.fRight && alphaDst[0] != 0xFF) {
|
||||
hasAlpha = true;
|
||||
if (x + 7 < srcRect.fRight && alphaDst[0])
|
||||
}
|
||||
if (x + 7 < srcRect.fRight && alphaDst[0]) {
|
||||
isTransparent = false;
|
||||
}
|
||||
alphaDst++;
|
||||
}
|
||||
// Calculate the mask of bits we're interested in within the
|
||||
// last byte of alphaDst.
|
||||
// width mod 8 == 1 -> 0x80 ... width mod 8 == 7 -> 0xFE
|
||||
uint8_t mask = ~((1 << (8 - (srcRect.width() % 8))) - 1);
|
||||
if (srcRect.width() % 8 && (alphaDst[-1] & mask) != mask)
|
||||
if (srcRect.width() % 8 && (alphaDst[-1] & mask) != mask) {
|
||||
hasAlpha = true;
|
||||
if (srcRect.width() % 8 && (alphaDst[-1] & mask))
|
||||
}
|
||||
if (srcRect.width() % 8 && (alphaDst[-1] & mask)) {
|
||||
isTransparent = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -185,10 +195,12 @@ void extractImageData(const SkBitmap& bitmap, const SkIRect& srcRect,
|
||||
uint8_t* src = bitmap.getAddr8(0, y);
|
||||
for (int x = srcRect.fLeft; x < srcRect.fRight; x++) {
|
||||
alphaDst[0] = src[x];
|
||||
if (alphaDst[0] != 0xFF)
|
||||
if (alphaDst[0] != 0xFF) {
|
||||
hasAlpha = true;
|
||||
if (alphaDst[0])
|
||||
}
|
||||
if (alphaDst[0]) {
|
||||
isTransparent = false;
|
||||
}
|
||||
alphaDst++;
|
||||
}
|
||||
}
|
||||
@ -240,8 +252,9 @@ SkPDFArray* makeIndexedColorSpace(SkColorTable* table) {
|
||||
SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
|
||||
const SkIRect& srcRect,
|
||||
const SkPaint& paint) {
|
||||
if (bitmap.getConfig() == SkBitmap::kNo_Config)
|
||||
if (bitmap.getConfig() == SkBitmap::kNo_Config) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkStream* imageData = NULL;
|
||||
SkStream* alphaData = NULL;
|
||||
@ -314,10 +327,11 @@ SkPDFImage::SkPDFImage(SkStream* imageData, const SkBitmap& bitmap,
|
||||
// }
|
||||
|
||||
int bitsPerComp = 8;
|
||||
if (config == SkBitmap::kARGB_4444_Config)
|
||||
if (config == SkBitmap::kARGB_4444_Config) {
|
||||
bitsPerComp = 4;
|
||||
else if (doingAlpha && config == SkBitmap::kA1_Config)
|
||||
} else if (doingAlpha && config == SkBitmap::kA1_Config) {
|
||||
bitsPerComp = 1;
|
||||
}
|
||||
insertInt("BitsPerComponent", bitsPerComp);
|
||||
|
||||
if (config == SkBitmap::kRGB_565_Config) {
|
||||
|
@ -100,7 +100,7 @@ void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
|
||||
curNodes[i]->insert(parentName.get(), newNodeRef.get());
|
||||
kids->append(new SkPDFObjRef(curNodes[i]))->unref();
|
||||
|
||||
// TODO(vandebo) put the objects in strict access order.
|
||||
// TODO(vandebo): put the objects in strict access order.
|
||||
// Probably doesn't matter because they are so small.
|
||||
if (curNodes[i] != pages[0]) {
|
||||
pageTree->push(curNodes[i]); // Transfer reference.
|
||||
@ -127,8 +127,9 @@ void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
|
||||
|
||||
pageTree->push(curNodes[0]); // Transfer reference.
|
||||
catalog->addObject(curNodes[0], false);
|
||||
if (rootNode)
|
||||
if (rootNode) {
|
||||
*rootNode = curNodes[0];
|
||||
}
|
||||
}
|
||||
|
||||
const SkTDArray<SkPDFFont*>& SkPDFPage::getFontResources() const {
|
||||
|
@ -84,8 +84,9 @@ SkPDFInt::~SkPDFInt() {}
|
||||
|
||||
void SkPDFInt::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
bool indirect) {
|
||||
if (indirect)
|
||||
if (indirect) {
|
||||
return emitIndirectObject(stream, catalog);
|
||||
}
|
||||
stream->writeDecAsText(fValue);
|
||||
}
|
||||
|
||||
@ -104,8 +105,9 @@ void SkPDFBool::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
|
||||
size_t SkPDFBool::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
|
||||
SkASSERT(!indirect);
|
||||
if (fValue)
|
||||
if (fValue) {
|
||||
return strlen("true");
|
||||
}
|
||||
return strlen("false");
|
||||
}
|
||||
|
||||
@ -114,8 +116,9 @@ SkPDFScalar::~SkPDFScalar() {}
|
||||
|
||||
void SkPDFScalar::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
bool indirect) {
|
||||
if (indirect)
|
||||
if (indirect) {
|
||||
return emitIndirectObject(stream, catalog);
|
||||
}
|
||||
|
||||
Append(fValue, stream);
|
||||
}
|
||||
@ -223,8 +226,9 @@ SkString SkPDFString::DoFormatString(const void* input, size_t len,
|
||||
SkASSERT(wideInput);
|
||||
SkString result;
|
||||
result.append("<");
|
||||
for (size_t i = 0; i < len; i++)
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
result.appendHex(win[i], 4);
|
||||
}
|
||||
result.append(">");
|
||||
return result;
|
||||
}
|
||||
@ -247,8 +251,9 @@ SkString SkPDFString::DoFormatString(const void* input, size_t len,
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
SkASSERT(!wideInput || !(win[i] & ~0xFF));
|
||||
char val = wideInput ? win[i] : cin[i];
|
||||
if (val == '\\' || val == '(' || val == ')')
|
||||
if (val == '\\' || val == '(' || val == ')') {
|
||||
result.append("\\");
|
||||
}
|
||||
result.append(&val, 1);
|
||||
}
|
||||
result.append(")");
|
||||
@ -308,27 +313,32 @@ SkPDFArray::~SkPDFArray() {
|
||||
|
||||
void SkPDFArray::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
bool indirect) {
|
||||
if (indirect)
|
||||
if (indirect) {
|
||||
return emitIndirectObject(stream, catalog);
|
||||
}
|
||||
|
||||
stream->writeText("[");
|
||||
for (int i = 0; i < fValue.count(); i++) {
|
||||
fValue[i]->emit(stream, catalog, false);
|
||||
if (i + 1 < fValue.count())
|
||||
if (i + 1 < fValue.count()) {
|
||||
stream->writeText(" ");
|
||||
}
|
||||
}
|
||||
stream->writeText("]");
|
||||
}
|
||||
|
||||
size_t SkPDFArray::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
|
||||
if (indirect)
|
||||
if (indirect) {
|
||||
return getIndirectOutputSize(catalog);
|
||||
}
|
||||
|
||||
size_t result = strlen("[]");
|
||||
if (fValue.count())
|
||||
if (fValue.count()) {
|
||||
result += fValue.count() - 1;
|
||||
for (int i = 0; i < fValue.count(); i++)
|
||||
}
|
||||
for (int i = 0; i < fValue.count(); i++) {
|
||||
result += fValue[i]->getOutputSize(catalog, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -381,8 +391,9 @@ SkPDFDict::~SkPDFDict() {
|
||||
|
||||
void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
bool indirect) {
|
||||
if (indirect)
|
||||
if (indirect) {
|
||||
return emitIndirectObject(stream, catalog);
|
||||
}
|
||||
|
||||
stream->writeText("<<");
|
||||
for (int i = 0; i < fValue.count(); i++) {
|
||||
@ -395,8 +406,9 @@ void SkPDFDict::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
|
||||
}
|
||||
|
||||
size_t SkPDFDict::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
|
||||
if (indirect)
|
||||
if (indirect) {
|
||||
return getIndirectOutputSize(catalog);
|
||||
}
|
||||
|
||||
size_t result = strlen("<<>>") + (fValue.count() * 2);
|
||||
for (int i = 0; i < fValue.count(); i++) {
|
||||
|
@ -141,18 +141,20 @@ void SkPDFUtils::ClosePath(SkWStream* content) {
|
||||
// static
|
||||
void SkPDFUtils::PaintPath(SkPaint::Style style, SkPath::FillType fill,
|
||||
SkWStream* content) {
|
||||
if (style == SkPaint::kFill_Style)
|
||||
if (style == SkPaint::kFill_Style) {
|
||||
content->writeText("f");
|
||||
else if (style == SkPaint::kStrokeAndFill_Style)
|
||||
} else if (style == SkPaint::kStrokeAndFill_Style) {
|
||||
content->writeText("B");
|
||||
else if (style == SkPaint::kStroke_Style)
|
||||
} else if (style == SkPaint::kStroke_Style) {
|
||||
content->writeText("S");
|
||||
}
|
||||
|
||||
if (style != SkPaint::kStroke_Style) {
|
||||
NOT_IMPLEMENTED(fill == SkPath::kInverseEvenOdd_FillType, false);
|
||||
NOT_IMPLEMENTED(fill == SkPath::kInverseWinding_FillType, false);
|
||||
if (fill == SkPath::kEvenOdd_FillType)
|
||||
if (fill == SkPath::kEvenOdd_FillType) {
|
||||
content->writeText("*");
|
||||
}
|
||||
}
|
||||
content->writeText("\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user