diff options
author | 2013-08-07 18:04:15 +0000 | |
---|---|---|
committer | 2013-08-07 18:04:15 +0000 | |
commit | e57c62d039cbd67a4e52776b3e95c5d002b818d2 (patch) | |
tree | 3755ce95565d1ca30fef65825c4a6be273323c95 /experimental | |
parent | c6233285be7b5151d5a87eba5547b0d953b4f50c (diff) |
pdfviewer: fix font rotation issues
Review URL: https://codereview.chromium.org/22407005
git-svn-id: http://skia.googlecode.com/svn/trunk@10617 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/PdfViewer/SkPdfFont.h | 7 | ||||
-rw-r--r-- | experimental/PdfViewer/SkPdfRenderer.cpp | 38 | ||||
-rw-r--r-- | experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp | 27 |
3 files changed, 32 insertions, 40 deletions
diff --git a/experimental/PdfViewer/SkPdfFont.h b/experimental/PdfViewer/SkPdfFont.h index d5641b2847..bbbaa7a73e 100644 --- a/experimental/PdfViewer/SkPdfFont.h +++ b/experimental/PdfViewer/SkPdfFont.h @@ -172,9 +172,14 @@ public: 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)); } } diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/SkPdfRenderer.cpp index 4f36c0bc91..e2197b0296 100644 --- a/experimental/PdfViewer/SkPdfRenderer.cpp +++ b/experimental/PdfViewer/SkPdfRenderer.cpp @@ -390,26 +390,6 @@ static PdfResult DrawText(PdfContext* pdfContext, 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(); @@ -756,8 +736,10 @@ static PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfT 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? } @@ -870,9 +852,10 @@ PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObjec 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"); @@ -1074,7 +1057,7 @@ static PdfResult PdfOp_Td(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop 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); @@ -1125,6 +1108,7 @@ static PdfResult PdfOp_Tm(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop SkMatrix matrix = SkMatrixFromPdfMatrix(array); matrix.postConcat(pdfContext->fGraphicsState.fCTM); + matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); // TODO(edisonn): Text positioning. pdfContext->fGraphicsState.fMatrixTm = matrix; @@ -1459,8 +1443,10 @@ static PdfResult PdfOp_n(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope 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; } diff --git a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp index 333b0a25db..2e7e670ce9 100644 --- a/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp +++ b/experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp @@ -90,21 +90,22 @@ SkNativeParsedPDF::SkNativeParsedPDF(const char* path) , 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) { |