Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 2112943002: SkPDF: Glyph Useage Map improvements (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFDocument.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDevice.cpp
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 204678a687922e4bc32685c22a96518835ee105b..12698dc00b012117466c1b4eb1cd00866f4516b0 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -655,7 +655,6 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFDocument* do
, fContentSize(pageSize)
, fExistingClipRegion(SkIRect::MakeSize(pageSize))
, fClipStack(nullptr)
- , fFontGlyphUsage(new SkPDFGlyphSetMap)
, fRasterDpi(rasterDpi)
, fDocument(doc) {
SkASSERT(pageSize.width() > 0);
@@ -675,25 +674,18 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFDocument* do
}
SkPDFDevice::~SkPDFDevice() {
- this->cleanUp(true);
+ this->cleanUp();
}
void SkPDFDevice::init() {
fContentEntries.reset();
- if (fFontGlyphUsage.get() == nullptr) {
- fFontGlyphUsage.reset(new SkPDFGlyphSetMap);
- }
}
-void SkPDFDevice::cleanUp(bool clearFontUsage) {
+void SkPDFDevice::cleanUp() {
fGraphicStateResources.unrefAll();
fXObjectResources.unrefAll();
fFontResources.unrefAll();
fShaderResources.unrefAll();
-
- if (clearFontUsage) {
- fFontGlyphUsage->reset();
- }
}
void SkPDFDevice::drawAnnotation(const SkDraw& d, const SkRect& rect, const char key[],
@@ -1174,6 +1166,8 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
SkTDArray<uint16_t> glyphIDsCopy(glyphIDs, numGlyphs);
+ SkPDFGlyphSetMap* fontGlyphUsage = fDocument->getGlyphUsage();
+
while (numGlyphs > consumedGlyphCount) {
this->updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry());
SkPDFFont* font = content.entry()->fState.fFont;
@@ -1181,7 +1175,7 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
int availableGlyphs = font->glyphsToPDFFontEncoding(
glyphIDsCopy.begin() + consumedGlyphCount,
numGlyphs - consumedGlyphCount);
- fFontGlyphUsage->noteGlyphUsage(
+ fontGlyphUsage->noteGlyphUsage(
font, glyphIDsCopy.begin() + consumedGlyphCount,
availableGlyphs);
write_wide_string(&content.entry()->fContent,
@@ -1243,6 +1237,7 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
SkPaint::GlyphCacheProc glyphCacheProc = textPaint.getGlyphCacheProc(true);
content.entry()->fContent.writeText("BT\n");
this->updateFont(textPaint, glyphIDs[0], content.entry());
+ SkPDFGlyphSetMap* fontGlyphUsage = fDocument->getGlyphUsage();
for (size_t i = 0; i < numGlyphs; i++) {
SkPDFFont* font = content.entry()->fState.fFont;
uint16_t encodedValue = glyphIDs[i];
@@ -1257,7 +1252,7 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
}
}
- fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1);
+ fontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1);
SkScalar x = offset.x() + pos[i * scalarsPerPos];
SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos + 1] : 0);
@@ -1325,9 +1320,6 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device,
auto xObject = sk_make_sp<SkPDFFormXObject>(pdfDevice);
SkPDFUtils::DrawFormXObject(this->addXObjectResource(xObject.get()),
&content.entry()->fContent);
-
- // Merge glyph sets from the drawn device.
- fFontGlyphUsage->merge(pdfDevice->getFontGlyphUsage());
}
SkImageInfo SkPDFDevice::imageInfo() const {
@@ -1558,7 +1550,7 @@ SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() {
// We always draw the form xobjects that we create back into the device, so
// we simply preserve the font usage instead of pulling it out and merging
// it back in later.
- cleanUp(false); // Reset this device to have no content.
+ cleanUp(); // Reset this device to have no content.
init();
return xobject;
}
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFDocument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698