| Index: src/pdf/SkPDFDevice.cpp
|
| diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
|
| index 83408a55be1de09713d660f51ba2d913d972acd3..17092bd2a060e2b82f9e508d41f74b2c2302ee7f 100644
|
| --- a/src/pdf/SkPDFDevice.cpp
|
| +++ b/src/pdf/SkPDFDevice.cpp
|
| @@ -41,20 +41,6 @@
|
|
|
| // Utility functions
|
|
|
| -static bool excessive_translation(const SkMatrix& m) {
|
| - const SkScalar kExcessiveTranslation = 8192.0f;
|
| - return SkScalarAbs(m.getTranslateX()) > kExcessiveTranslation
|
| - || SkScalarAbs(m.getTranslateY()) > kExcessiveTranslation;
|
| -}
|
| -
|
| -static SkMatrix untranslate(const SkMatrix& matrix, SkScalar x, SkScalar y) {
|
| - // https://bug.skia.org/257 If the translation is too large,
|
| - // PDF can't exactly represent the float values as numbers.
|
| - SkMatrix result(matrix);
|
| - result.preTranslate(x, y);
|
| - return result;
|
| -}
|
| -
|
| // If the paint will definitely draw opaquely, replace kSrc_Mode with
|
| // kSrcOver_Mode. http://crbug.com/473572
|
| static void replace_srcmode_on_opaque_paint(SkPaint* paint) {
|
| @@ -798,7 +784,7 @@ void SkPDFDevice::internalDrawPaint(const SkPaint& paint,
|
| &contentEntry->fContent);
|
| }
|
|
|
| -void SkPDFDevice::drawPoints(const SkDraw& srcDraw,
|
| +void SkPDFDevice::drawPoints(const SkDraw& d,
|
| SkCanvas::PointMode mode,
|
| size_t count,
|
| const SkPoint* points,
|
| @@ -811,21 +797,10 @@ void SkPDFDevice::drawPoints(const SkDraw& srcDraw,
|
| }
|
|
|
| if (SkAnnotation* annotation = passedPaint.getAnnotation()) {
|
| - if (handlePointAnnotation(points, count, *srcDraw.fMatrix, annotation)) {
|
| + if (handlePointAnnotation(points, count, *d.fMatrix, annotation)) {
|
| return;
|
| }
|
| }
|
| - SkMatrix newMatrix;
|
| - SkDraw d(srcDraw);
|
| - SkTArray<SkPoint> pointsCopy;
|
| - if (excessive_translation(*d.fMatrix)) {
|
| - newMatrix = untranslate(*d.fMatrix, points[0].x(), points[0].y());
|
| - d.fMatrix = &newMatrix;
|
| - pointsCopy.reset(points, SkToInt(count));
|
| - SkPoint::Offset(&pointsCopy[0], SkToInt(count),
|
| - -points[0].x(), -points[0].y());
|
| - points = &pointsCopy[0];
|
| - }
|
|
|
| // SkDraw::drawPoints converts to multiple calls to fDevice->drawPath.
|
| // We only use this when there's a path effect because of the overhead
|
| @@ -946,7 +921,7 @@ static SkPDFDict* create_link_named_dest(const SkData* nameData,
|
| return annotation.detach();
|
| }
|
|
|
| -void SkPDFDevice::drawRect(const SkDraw& srcDraw,
|
| +void SkPDFDevice::drawRect(const SkDraw& d,
|
| const SkRect& rect,
|
| const SkPaint& srcPaint) {
|
| SkPaint paint = srcPaint;
|
| @@ -954,14 +929,6 @@ void SkPDFDevice::drawRect(const SkDraw& srcDraw,
|
| SkRect r = rect;
|
| r.sort();
|
|
|
| - SkMatrix newMatrix;
|
| - SkDraw d(srcDraw);
|
| - if (excessive_translation(*d.fMatrix)) {
|
| - newMatrix = untranslate(*d.fMatrix, r.x(), r.y());
|
| - d.fMatrix = &newMatrix;
|
| - r.offsetTo(0, 0);
|
| - }
|
| -
|
| if (paint.getPathEffect()) {
|
| if (d.fClip->isEmpty()) {
|
| return;
|
| @@ -1009,40 +976,24 @@ void SkPDFDevice::drawOval(const SkDraw& draw,
|
| this->drawPath(draw, path, paint, nullptr, true);
|
| }
|
|
|
| -void SkPDFDevice::drawPath(const SkDraw& srcDraw,
|
| +void SkPDFDevice::drawPath(const SkDraw& d,
|
| const SkPath& origPath,
|
| const SkPaint& srcPaint,
|
| const SkMatrix* prePathMatrix,
|
| bool pathIsMutable) {
|
| - SkMatrix newMatrix;
|
| - SkDraw d(srcDraw);
|
| - SkPath modifiedPath;
|
| - SkPath* pathPtr = const_cast<SkPath*>(&origPath);
|
| - if (excessive_translation(*d.fMatrix)) {
|
| - SkPoint firstPt;
|
| - if (origPath.getPoints(&firstPt, 1) > 0) {
|
| - newMatrix = untranslate(*d.fMatrix, firstPt.x(), firstPt.y());
|
| - d.fMatrix = &newMatrix;
|
| - modifiedPath = origPath;
|
| - modifiedPath.offset(-firstPt.x(), -firstPt.y());
|
| - pathPtr = &modifiedPath; // NOTE: shader behavior will be off.
|
| - pathIsMutable = true;
|
| - }
|
| - }
|
| -
|
| SkPaint paint = srcPaint;
|
| replace_srcmode_on_opaque_paint(&paint);
|
| + SkPath modifiedPath;
|
| + SkPath* pathPtr = const_cast<SkPath*>(&origPath);
|
|
|
| SkMatrix matrix = *d.fMatrix;
|
| if (prePathMatrix) {
|
| if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) {
|
| - if (pathIsMutable) {
|
| - pathPtr->transform(*prePathMatrix);
|
| - } else {
|
| - pathPtr->transform(*prePathMatrix, &modifiedPath);
|
| + if (!pathIsMutable) {
|
| pathPtr = &modifiedPath;
|
| pathIsMutable = true;
|
| }
|
| + origPath.transform(*prePathMatrix, pathPtr);
|
| } else {
|
| matrix.preConcat(*prePathMatrix);
|
| }
|
| @@ -1052,14 +1003,11 @@ void SkPDFDevice::drawPath(const SkDraw& srcDraw,
|
| if (d.fClip->isEmpty()) {
|
| return;
|
| }
|
| - bool fill;
|
| - if (pathIsMutable) {
|
| - fill = paint.getFillPath(*pathPtr, pathPtr);
|
| - } else {
|
| - fill = paint.getFillPath(*pathPtr, &modifiedPath);
|
| + if (!pathIsMutable) {
|
| pathPtr = &modifiedPath;
|
| pathIsMutable = true;
|
| }
|
| + bool fill = paint.getFillPath(origPath, pathPtr);
|
|
|
| SkPaint noEffectPaint(paint);
|
| noEffectPaint.setPathEffect(nullptr);
|
| @@ -1323,17 +1271,8 @@ static void draw_transparent_text(SkPDFDevice* device,
|
| }
|
|
|
|
|
| -void SkPDFDevice::drawText(const SkDraw& srcDraw, const void* text, size_t len,
|
| +void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
|
| SkScalar x, SkScalar y, const SkPaint& srcPaint) {
|
| - SkMatrix newMatrix;
|
| - SkDraw d(srcDraw);
|
| - if (excessive_translation(*d.fMatrix)) {
|
| - newMatrix = untranslate(*d.fMatrix, x, y);
|
| - d.fMatrix = &newMatrix;
|
| - x = 0;
|
| - y = 0;
|
| - }
|
| -
|
| if (!SkPDFFont::CanEmbedTypeface(srcPaint.getTypeface(), fCanon)) {
|
| // https://bug.skia.org/3866
|
| SkPath path;
|
| @@ -1392,46 +1331,9 @@ void SkPDFDevice::drawText(const SkDraw& srcDraw, const void* text, size_t len,
|
| content.entry()->fContent.writeText("ET\n");
|
| }
|
|
|
| -void SkPDFDevice::drawPosText(const SkDraw& srcDraw, const void* text, size_t len,
|
| +void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
|
| const SkScalar pos[], int scalarsPerPos,
|
| - const SkPoint& srcOffset, const SkPaint& srcPaint) {
|
| - if (len == 0) {
|
| - return;
|
| - }
|
| - SkMatrix newMatrix;
|
| - SkDraw d(srcDraw);
|
| - SkPoint offset(srcOffset);
|
| - SkAutoTMalloc<SkScalar> scalarsBuffer;
|
| - if (excessive_translation(*d.fMatrix)) {
|
| - SkPoint first;
|
| - if (scalarsPerPos != 2) {
|
| - first.set(pos[0], 0);
|
| - } else {
|
| - first.set(pos[0], pos[1]);
|
| - }
|
| - newMatrix = untranslate(*d.fMatrix,
|
| - first.x() + offset.x(),
|
| - first.y() + offset.y());
|
| - d.fMatrix = &newMatrix;
|
| - offset.set(0, 0); // offset -= offset;
|
| - if (first.x() != 0 || first.y() != 0) {
|
| - int glyphCount = srcPaint.textToGlyphs(text, len, NULL);
|
| - if (scalarsPerPos != 2) {
|
| - scalarsBuffer.reset(glyphCount);
|
| - for (int i = 0; i < glyphCount; ++i) {
|
| - scalarsBuffer[i] = pos[i] - first.x();
|
| - }
|
| - } else {
|
| - scalarsBuffer.reset(2 * glyphCount);
|
| - for (int i = 0; i < glyphCount; ++i) {
|
| - scalarsBuffer[2 * i] = pos[2 * i] - first.x();
|
| - scalarsBuffer[2 * i + 1] = pos[2 * i + 1] - first.y();
|
| - }
|
| - }
|
| - pos = &scalarsBuffer[0];
|
| - }
|
| - }
|
| -
|
| + const SkPoint& offset, const SkPaint& srcPaint) {
|
| if (!SkPDFFont::CanEmbedTypeface(srcPaint.getTypeface(), fCanon)) {
|
| const SkPoint* positions = reinterpret_cast<const SkPoint*>(pos);
|
| SkAutoTMalloc<SkPoint> positionsBuffer;
|
|
|