PDF: Remove SkPDFDeviceFlattener
There are no clients. TBR=mtklein@google.com Review URL: https://codereview.chromium.org/937333002
This commit is contained in:
parent
8c92dc1dc2
commit
56f4ace232
@ -18,8 +18,6 @@
|
||||
'<(skia_src_path)/pdf/SkPDFCatalog.h',
|
||||
'<(skia_src_path)/pdf/SkPDFDevice.cpp',
|
||||
'<(skia_src_path)/pdf/SkPDFDevice.h',
|
||||
'<(skia_src_path)/pdf/SkPDFDeviceFlattener.cpp',
|
||||
'<(skia_src_path)/pdf/SkPDFDeviceFlattener.h',
|
||||
'<(skia_src_path)/pdf/SkPDFDocument.cpp',
|
||||
'<(skia_src_path)/pdf/SkPDFDocument.h',
|
||||
'<(skia_src_path)/pdf/SkPDFFont.cpp',
|
||||
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkPDFDeviceFlattener.h"
|
||||
#include "SkDraw.h"
|
||||
|
||||
static SkISize SkSizeToISize(const SkSize& size) {
|
||||
return SkISize::Make(SkScalarRoundToInt(size.width()), SkScalarRoundToInt(size.height()));
|
||||
}
|
||||
|
||||
SkPDFDeviceFlattener::SkPDFDeviceFlattener(const SkSize& pageSize, const SkRect* trimBox)
|
||||
: SkPDFDevice(SkSizeToISize(pageSize),
|
||||
SkSizeToISize(pageSize),
|
||||
SkMatrix::I()) {
|
||||
// TODO(edisonn): store the trimbox on emit.
|
||||
}
|
||||
|
||||
SkPDFDeviceFlattener::~SkPDFDeviceFlattener() {
|
||||
}
|
||||
|
||||
static void flattenPaint(const SkDraw& d, SkPaint* paint) {
|
||||
if (paint->getShader()) {
|
||||
SkAutoTUnref<SkShader> lms(SkShader::CreateLocalMatrixShader(paint->getShader(),
|
||||
*d.fMatrix));
|
||||
paint->setShader(lms);
|
||||
}
|
||||
}
|
||||
|
||||
void SkPDFDeviceFlattener::drawPoints(const SkDraw& d, SkCanvas::PointMode mode,
|
||||
size_t count, const SkPoint points[],
|
||||
const SkPaint& paint) {
|
||||
if (!mustFlatten(d)) {
|
||||
INHERITED::drawPoints(d, mode, count, points, paint);
|
||||
return;
|
||||
}
|
||||
|
||||
SkPaint paintFlatten(paint);
|
||||
flattenPaint(d, &paintFlatten);
|
||||
|
||||
SkPoint* flattenedPoints = SkNEW_ARRAY(SkPoint, count);
|
||||
d.fMatrix->mapPoints(flattenedPoints, points, SkToS32(count));
|
||||
SkDraw draw(d);
|
||||
SkMatrix identity = SkMatrix::I();
|
||||
draw.fMatrix = &identity;
|
||||
INHERITED::drawPoints(draw, mode, count, flattenedPoints, paintFlatten);
|
||||
SkDELETE_ARRAY(flattenedPoints);
|
||||
}
|
||||
|
||||
void SkPDFDeviceFlattener::drawRect(const SkDraw& d, const SkRect& r, const SkPaint& paint) {
|
||||
if (!mustFlatten(d)) {
|
||||
INHERITED::drawRect(d, r, paint);
|
||||
return;
|
||||
}
|
||||
|
||||
SkPath path;
|
||||
path.addRect(r);
|
||||
path.transform(*d.fMatrix);
|
||||
SkDraw draw(d);
|
||||
SkMatrix matrix = SkMatrix::I();
|
||||
draw.fMatrix = &matrix;
|
||||
|
||||
SkPaint paintFlatten(paint);
|
||||
flattenPaint(d, &paintFlatten);
|
||||
|
||||
INHERITED::drawPath(draw, path, paintFlatten, NULL, true);
|
||||
}
|
||||
|
||||
void SkPDFDeviceFlattener::drawPath(const SkDraw& d, const SkPath& origPath,
|
||||
const SkPaint& paint, const SkMatrix* prePathMatrix,
|
||||
bool pathIsMutable) {
|
||||
if (!mustFlatten(d) && !(prePathMatrix && prePathMatrix->hasPerspective())) {
|
||||
INHERITED::drawPath(d, origPath, paint, prePathMatrix, pathIsMutable);
|
||||
return;
|
||||
}
|
||||
|
||||
SkPath* pathPtr = (SkPath*)&origPath;
|
||||
SkPath tmpPath;
|
||||
|
||||
if (!pathIsMutable) {
|
||||
tmpPath = origPath;
|
||||
pathPtr = &tmpPath;
|
||||
}
|
||||
|
||||
if (prePathMatrix) {
|
||||
pathPtr->transform(*prePathMatrix);
|
||||
}
|
||||
|
||||
SkPaint paintFlatten(paint);
|
||||
flattenPaint(d, &paintFlatten);
|
||||
|
||||
bool fill = paintFlatten.getFillPath(*pathPtr, &tmpPath);
|
||||
SkDEBUGCODE(pathPtr = (SkPath*)0x12345678); // Don't use pathPtr after this point.
|
||||
|
||||
paintFlatten.setPathEffect(NULL);
|
||||
if (fill) {
|
||||
paintFlatten.setStyle(SkPaint::kFill_Style);
|
||||
} else {
|
||||
paintFlatten.setStyle(SkPaint::kStroke_Style);
|
||||
paintFlatten.setStrokeWidth(0);
|
||||
}
|
||||
|
||||
tmpPath.transform(*d.fMatrix);
|
||||
|
||||
SkDraw draw(d);
|
||||
SkMatrix matrix = SkMatrix::I();
|
||||
draw.fMatrix = &matrix;
|
||||
|
||||
INHERITED::drawPath(draw, tmpPath, paintFlatten, NULL, true);
|
||||
}
|
||||
|
||||
void SkPDFDeviceFlattener::drawText(const SkDraw& d, const void* text, size_t len,
|
||||
SkScalar x, SkScalar y, const SkPaint& paint) {
|
||||
if (mustPathText(d, paint)) {
|
||||
d.drawText_asPaths((const char*)text, len, x, y, paint);
|
||||
return;
|
||||
}
|
||||
|
||||
INHERITED::drawText(d, text, len, x, y, paint);
|
||||
}
|
||||
|
||||
void SkPDFDeviceFlattener::drawPosText(const SkDraw& d, const void* text, size_t len,
|
||||
const SkScalar pos[], int scalarsPerPos,
|
||||
const SkPoint& offset, const SkPaint& paint) {
|
||||
if (mustPathText(d, paint)) {
|
||||
d.drawPosText_asPaths((const char*)text, len, pos, scalarsPerPos, offset, paint);
|
||||
return;
|
||||
}
|
||||
INHERITED::drawPosText(d, text, len, pos, scalarsPerPos, offset, paint);
|
||||
}
|
||||
|
||||
bool SkPDFDeviceFlattener::mustFlatten(const SkDraw& d) const {
|
||||
// TODO(edisonn): testability, add flag to force return true.
|
||||
return d.fMatrix->hasPerspective();
|
||||
}
|
||||
|
||||
bool SkPDFDeviceFlattener::mustPathText(const SkDraw& d, const SkPaint&) {
|
||||
// TODO(edisonn): testability, add flag to force return true.
|
||||
// TODO(edisonn): TBD: How to flatten MaskFilter.
|
||||
return d.fMatrix->hasPerspective();
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkPDFDeviceFlattener_DEFINED
|
||||
#define SkPDFDeviceFlattener_DEFINED
|
||||
|
||||
#include "SkPDFDevice.h"
|
||||
|
||||
|
||||
/** \class SkPDFDeviceFlattener
|
||||
|
||||
The PDF Device Flattener is used to flatten features without native support in PDF.
|
||||
For now, the only one implemented is Perspective.
|
||||
|
||||
TODO(edisonn): Rename the class once we know all the things it will do.
|
||||
*/
|
||||
class SkPDFDeviceFlattener : public SkPDFDevice {
|
||||
private:
|
||||
typedef SkPDFDevice INHERITED;
|
||||
|
||||
SK_API SkPDFDeviceFlattener(const SkSize& pageSize, const SkRect* trimBox = NULL);
|
||||
|
||||
public:
|
||||
SK_API virtual ~SkPDFDeviceFlattener();
|
||||
|
||||
virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode,
|
||||
size_t count, const SkPoint[],
|
||||
const SkPaint& paint) SK_OVERRIDE;
|
||||
void drawRect(const SkDraw&, const SkRect& r, const SkPaint& paint) SK_OVERRIDE;
|
||||
virtual void drawPath(const SkDraw&, const SkPath& origpath,
|
||||
const SkPaint& paint, const SkMatrix* prePathMatrix,
|
||||
bool pathIsMutable) SK_OVERRIDE;
|
||||
virtual void drawText(const SkDraw&, const void* text, size_t len,
|
||||
SkScalar x, SkScalar y, const SkPaint&) SK_OVERRIDE;
|
||||
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
|
||||
const SkScalar pos[], int scalarsPerPos,
|
||||
const SkPoint& offset, const SkPaint&) SK_OVERRIDE;
|
||||
private:
|
||||
|
||||
bool mustFlatten(const SkDraw& d) const;
|
||||
bool mustPathText(const SkDraw& d, const SkPaint& paint);
|
||||
|
||||
friend class SkDocument_PDF;
|
||||
};
|
||||
|
||||
#endif // SkPDFDeviceFlattener_DEFINED
|
Loading…
Reference in New Issue
Block a user