OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
(...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 // int formsCount(); | 1916 // int formsCount(); |
1917 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) | 1917 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) |
1918 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, parsin
g all content, ... | 1918 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, parsin
g all content, ... |
1919 // if we load the first page, and we zoom to fit to screen horizontally, then lo
ad only those | 1919 // if we load the first page, and we zoom to fit to screen horizontally, then lo
ad only those |
1920 // resources needed, so the preview is fast. | 1920 // resources needed, so the preview is fast. |
1921 // TODO (edisonn): hide parser/tokenizer behind and interface and a query langua
ge, and resolve | 1921 // TODO (edisonn): hide parser/tokenizer behind and interface and a query langua
ge, and resolve |
1922 // references automatically. | 1922 // references automatically. |
1923 | 1923 |
1924 PdfContext* gPdfContext = NULL; | 1924 PdfContext* gPdfContext = NULL; |
1925 | 1925 |
1926 bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas) const { | 1926 bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co
nst { |
1927 if (!fPdfDoc) { | 1927 if (!fPdfDoc) { |
1928 return false; | 1928 return false; |
1929 } | 1929 } |
1930 | 1930 |
1931 if (page < 0 || page >= pages()) { | 1931 if (page < 0 || page >= pages()) { |
1932 return false; | 1932 return false; |
1933 } | 1933 } |
1934 | 1934 |
1935 SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfPage(page); | 1935 SkPdfNativeTokenizer* tokenizer = fPdfDoc->tokenizerOfPage(page); |
1936 | 1936 |
1937 PdfContext pdfContext(fPdfDoc); | 1937 PdfContext pdfContext(fPdfDoc); |
1938 pdfContext.fOriginalMatrix = SkMatrix::I(); | 1938 pdfContext.fOriginalMatrix = SkMatrix::I(); |
1939 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); | 1939 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); |
1940 | 1940 |
1941 gPdfContext = &pdfContext; | 1941 gPdfContext = &pdfContext; |
1942 | 1942 |
1943 // TODO(edisonn): get matrix stuff right. | 1943 // TODO(edisonn): get matrix stuff right. |
1944 // TODO(edisonn): add DPI/scale/zoom. | |
1945 SkScalar z = SkIntToScalar(0); | 1944 SkScalar z = SkIntToScalar(0); |
1946 SkRect rect = fPdfDoc->MediaBox(page); | 1945 SkScalar w = dst.width(); |
1947 SkScalar w = rect.width(); | 1946 SkScalar h = dst.height(); |
1948 SkScalar h = rect.height(); | |
1949 | 1947 |
1950 SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(w, z), SkPoint::Ma
ke(w, h), SkPoint::Make(z, h)}; | 1948 SkScalar wp = fPdfDoc->MediaBox(page).width(); |
| 1949 SkScalar hp = fPdfDoc->MediaBox(page).height(); |
| 1950 |
| 1951 SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(wp, z), SkPoint::M
ake(wp, hp), SkPoint::Make(z, hp)}; |
1951 // SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w,
h), SkPoint::Make(w, z), SkPoint::Make(z, z)}; | 1952 // SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w,
h), SkPoint::Make(w, z), SkPoint::Make(z, z)}; |
1952 | 1953 |
1953 // TODO(edisonn): add flag for this app to create sourunding buffer zone | 1954 // TODO(edisonn): add flag for this app to create sourunding buffer zone |
1954 // TODO(edisonn): add flagg for no clipping. | 1955 // TODO(edisonn): add flagg for no clipping. |
1955 // Use larger image to make sure we do not draw anything outside of page | 1956 // Use larger image to make sure we do not draw anything outside of page |
1956 // could be used in tests. | 1957 // could be used in tests. |
1957 | 1958 |
1958 #ifdef PDF_DEBUG_3X | 1959 #ifdef PDF_DEBUG_3X |
1959 SkPoint skiaSpace[4] = {SkPoint::Make(w+z, h+h), SkPoint::Make(w+w, h+h), Sk
Point::Make(w+w, h+z), SkPoint::Make(w+z, h+z)}; | 1960 SkPoint skiaSpace[4] = {SkPoint::Make(w+z, h+h), SkPoint::Make(w+w, h+h), Sk
Point::Make(w+w, h+z), SkPoint::Make(w+z, h+z)}; |
1960 #else | 1961 #else |
1961 SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w, h), SkPoint::M
ake(w, z), SkPoint::Make(z, z)}; | 1962 SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w, h), SkPoint::M
ake(w, z), SkPoint::Make(z, z)}; |
1962 #endif | 1963 #endif |
1963 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(w, h)}; | 1964 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(w, h)}; |
1964 //SkPoint skiaSpace[2] = {SkPoint::Make(w, z), SkPoint::Make(z, h)}; | 1965 //SkPoint skiaSpace[2] = {SkPoint::Make(w, z), SkPoint::Make(z, h)}; |
1965 | 1966 |
1966 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)}; | 1967 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)}; |
1967 //SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)}; | 1968 //SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)}; |
1968 | 1969 |
1969 //SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint::
Make(w, h)}; | 1970 //SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint::
Make(w, h)}; |
1970 //SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint:
:Make(w, 0)}; | 1971 //SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint:
:Make(w, 0)}; |
1971 | 1972 |
1972 SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace,
4)); | 1973 SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace,
4)); |
1973 SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix"); | 1974 SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix"); |
1974 | 1975 |
1975 | 1976 |
1976 pdfContext.fGraphicsState.fMatrix = pdfContext.fOriginalMatrix; | 1977 pdfContext.fGraphicsState.fMatrix = pdfContext.fOriginalMatrix; |
1977 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fMatrix; | 1978 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fMatrix; |
1978 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fMatrix; | 1979 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fMatrix; |
1979 | 1980 |
| 1981 #ifndef PDF_DEBUG_NO_PAGE_CLIPING |
| 1982 canvas->clipRect(dst, SkRegion::kIntersect_Op, true); |
| 1983 #endif |
| 1984 |
1980 canvas->setMatrix(pdfContext.fOriginalMatrix); | 1985 canvas->setMatrix(pdfContext.fOriginalMatrix); |
1981 | 1986 |
1982 #ifndef PDF_DEBUG_NO_PAGE_CLIPING | |
1983 canvas->clipRect(SkRect::MakeXYWH(z, z, w, h), SkRegion::kIntersect_Op, true
); | |
1984 #endif | |
1985 | |
1986 // erase with red before? | 1987 // erase with red before? |
1987 // SkPaint paint; | 1988 // SkPaint paint; |
1988 // paint.setColor(SK_ColorRED); | 1989 // paint.setColor(SK_ColorRED); |
1989 // canvas->drawRect(rect, paint); | 1990 // canvas->drawRect(rect, paint); |
1990 | 1991 |
1991 PdfMainLooper looper(NULL, tokenizer, &pdfContext, canvas); | 1992 PdfMainLooper looper(NULL, tokenizer, &pdfContext, canvas); |
1992 looper.loop(); | 1993 looper.loop(); |
1993 | 1994 |
1994 delete tokenizer; | 1995 delete tokenizer; |
1995 | 1996 |
(...skipping 21 matching lines...) Expand all Loading... |
2017 | 2018 |
2018 SkRect SkPdfRenderer::MediaBox(int page) const { | 2019 SkRect SkPdfRenderer::MediaBox(int page) const { |
2019 SkASSERT(fPdfDoc); | 2020 SkASSERT(fPdfDoc); |
2020 return fPdfDoc->MediaBox(page); | 2021 return fPdfDoc->MediaBox(page); |
2021 } | 2022 } |
2022 | 2023 |
2023 size_t SkPdfRenderer::bytesUsed() const { | 2024 size_t SkPdfRenderer::bytesUsed() const { |
2024 return fPdfDoc ? fPdfDoc->bytesUsed() : 0; | 2025 return fPdfDoc ? fPdfDoc->bytesUsed() : 0; |
2025 } | 2026 } |
2026 | 2027 |
OLD | NEW |