void drawText(const SkDecodedText& text, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
for (int i = 0 ; i < text.size(); i++) {
+ canvas->setMatrix(pdfContext->fGraphicsState.fMatrixTm);
+#ifdef PDF_TRACE
+ SkPoint point = SkPoint::Make(SkDoubleToScalar(0), SkDoubleToScalar(0));
+ pdfContext->fGraphicsState.fMatrixTm.mapPoints(&point, 1);
+ printf("DrawText at (%f, %f)\n", SkScalarToDouble(point.x()), SkScalarToDouble(point.y()));
+#endif // PDF_TRACE
double width = drawOneChar(text[i], paint, pdfContext, canvas);
pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
- canvas->translate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
}
}
canvas->save();
-#if 1
- SkMatrix matrix = pdfContext->fGraphicsState.fMatrixTm;
-
- SkPoint point1;
- pdfContext->fGraphicsState.fMatrixTm.mapXY(SkIntToScalar(0), SkIntToScalar(0), &point1);
-
- SkMatrix mirror;
- mirror.setTranslate(0, -point1.y());
- // TODO(edisonn): fix rotated text, and skewed too
- mirror.postScale(SK_Scalar1, -SK_Scalar1);
- // TODO(edisonn): post rotate, skew
- mirror.postTranslate(0, point1.y());
-
- matrix.postConcat(mirror);
-
- canvas->setMatrix(matrix);
-
- SkTraceMatrix(matrix, "mirrored");
-#endif
-
skfont->drawText(decoded, &paint, pdfContext, canvas);
canvas->restore();
if (skobj->has_Matrix()) {
pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdfDoc));
- pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM;
- pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
+ SkMatrix matrix = pdfContext->fGraphicsState.fCTM;
+ matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1));
+ pdfContext->fGraphicsState.fMatrixTm = matrix;
+ pdfContext->fGraphicsState.fMatrixTlm = matrix;
// TODO(edisonn) reset matrixTm and matricTlm also?
}
pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), SkDoubleToScalar(textSize));
+ pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm;
pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm;
- pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
+ pdfContext->fGraphicsState.fCTM.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1));
SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix");
obj = obj;
double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObjectStack.pop();
- double array[6] = {1, 0, 0, 1, tx, ty};
+ double array[6] = {1, 0, 0, 1, tx, -ty};
SkMatrix matrix = SkMatrixFromPdfMatrix(array);
pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix);
SkMatrix matrix = SkMatrixFromPdfMatrix(array);
matrix.postConcat(pdfContext->fGraphicsState.fCTM);
+ matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1));
// TODO(edisonn): Text positioning.
pdfContext->fGraphicsState.fMatrixTm = matrix;
static PdfResult PdfOp_BT(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** looper) {
pdfContext->fGraphicsState.fTextBlock = true;
- pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM;
- pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
+ SkMatrix matrix = pdfContext->fGraphicsState.fCTM;
+ matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1));
+ pdfContext->fGraphicsState.fMatrixTm = matrix;
+ pdfContext->fGraphicsState.fMatrixTlm = matrix;
return kPartial_PdfResult;
}
, fRootCatalog(NULL) {
gDoc = this;
FILE* file = fopen(path, "r");
- size_t size = getFileSize(path);
- void* content = sk_malloc_throw(size);
- bool ok = (0 != fread(content, size, 1, file));
- fclose(file);
- file = NULL;
+ // TODO(edisonn): put this in a function that can return NULL
+ if (file) {
+ size_t size = getFileSize(path);
+ void* content = sk_malloc_throw(size);
+ bool ok = (0 != fread(content, size, 1, file));
+ fclose(file);
+ if (!ok) {
+ sk_free(content);
+ // TODO(edisonn): report read error
+ // TODO(edisonn): not nice to return like this from constructor, create a static
+ // function that can report NULL for failures.
+ return; // Doc will have 0 pages
+ }
- if (!ok) {
- sk_free(content);
- // TODO(edisonn): report read error
- // TODO(edisonn): not nice to return like this from constructor, create a static
- // function that can report NULL for failures.
- return; // Doc will have 0 pages
+ init(content, size);
}
-
- init(content, size);
}
void SkNativeParsedPDF::init(const void* bytes, size_t length) {