OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 321 |
322 NOT_IMPLEMENTED(clipFill == SkPath::kInverseEvenOdd_FillType, false); | 322 NOT_IMPLEMENTED(clipFill == SkPath::kInverseEvenOdd_FillType, false); |
323 NOT_IMPLEMENTED(clipFill == SkPath::kInverseWinding_FillType, false); | 323 NOT_IMPLEMENTED(clipFill == SkPath::kInverseWinding_FillType, false); |
324 if (clipFill == SkPath::kEvenOdd_FillType) { | 324 if (clipFill == SkPath::kEvenOdd_FillType) { |
325 contentStream->writeText("W* n\n"); | 325 contentStream->writeText("W* n\n"); |
326 } else { | 326 } else { |
327 contentStream->writeText("W n\n"); | 327 contentStream->writeText("W n\n"); |
328 } | 328 } |
329 } | 329 } |
330 | 330 |
331 #ifdef SK_PDF_USE_PATHOPS | |
332 /* Calculate an inverted path's equivalent non-inverted path, given the | 331 /* Calculate an inverted path's equivalent non-inverted path, given the |
333 * canvas bounds. | 332 * canvas bounds. |
334 * outPath may alias with invPath (since this is supported by PathOps). | 333 * outPath may alias with invPath (since this is supported by PathOps). |
335 */ | 334 */ |
336 static bool calculate_inverse_path(const SkRect& bounds, const SkPath& invPath, | 335 static bool calculate_inverse_path(const SkRect& bounds, const SkPath& invPath, |
337 SkPath* outPath) { | 336 SkPath* outPath) { |
338 SkASSERT(invPath.isInverseFillType()); | 337 SkASSERT(invPath.isInverseFillType()); |
339 | 338 |
340 SkPath clipPath; | 339 SkPath clipPath; |
341 clipPath.addRect(bounds); | 340 clipPath.addRect(bounds); |
342 | 341 |
343 return Op(clipPath, invPath, kIntersect_PathOp, outPath); | 342 return Op(clipPath, invPath, kIntersect_PathOp, outPath); |
344 } | 343 } |
345 | 344 |
| 345 #ifdef SK_PDF_USE_PATHOPS_CLIPPING |
346 // Sanity check the numerical values of the SkRegion ops and PathOps ops | 346 // Sanity check the numerical values of the SkRegion ops and PathOps ops |
347 // enums so region_op_to_pathops_op can do a straight passthrough cast. | 347 // enums so region_op_to_pathops_op can do a straight passthrough cast. |
348 // If these are failing, it may be necessary to make region_op_to_pathops_op | 348 // If these are failing, it may be necessary to make region_op_to_pathops_op |
349 // do more. | 349 // do more. |
350 SK_COMPILE_ASSERT(SkRegion::kDifference_Op == (int)kDifference_PathOp, | 350 SK_COMPILE_ASSERT(SkRegion::kDifference_Op == (int)kDifference_PathOp, |
351 region_pathop_mismatch); | 351 region_pathop_mismatch); |
352 SK_COMPILE_ASSERT(SkRegion::kIntersect_Op == (int)kIntersect_PathOp, | 352 SK_COMPILE_ASSERT(SkRegion::kIntersect_Op == (int)kIntersect_PathOp, |
353 region_pathop_mismatch); | 353 region_pathop_mismatch); |
354 SK_COMPILE_ASSERT(SkRegion::kUnion_Op == (int)kUnion_PathOp, | 354 SK_COMPILE_ASSERT(SkRegion::kUnion_Op == (int)kUnion_PathOp, |
355 region_pathop_mismatch); | 355 region_pathop_mismatch); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 } | 433 } |
434 } | 434 } |
435 push(); | 435 push(); |
436 | 436 |
437 currentEntry()->fClipStack = clipStack; | 437 currentEntry()->fClipStack = clipStack; |
438 currentEntry()->fClipRegion = clipRegion; | 438 currentEntry()->fClipRegion = clipRegion; |
439 | 439 |
440 SkMatrix transform; | 440 SkMatrix transform; |
441 transform.setTranslate(translation.fX, translation.fY); | 441 transform.setTranslate(translation.fX, translation.fY); |
442 | 442 |
443 #ifdef SK_PDF_USE_PATHOPS | 443 #ifdef SK_PDF_USE_PATHOPS_CLIPPING |
444 SkPath clipPath; | 444 SkPath clipPath; |
445 if (get_clip_stack_path(transform, clipStack, clipRegion, &clipPath)) { | 445 if (get_clip_stack_path(transform, clipStack, clipRegion, &clipPath)) { |
446 emit_clip(&clipPath, NULL, fContentStream); | 446 emit_clip(&clipPath, NULL, fContentStream); |
447 return; | 447 return; |
448 } | 448 } |
449 #endif | 449 #endif |
450 // gsState->initialEntry()->fClipStack/Region specifies the clip that has | 450 // gsState->initialEntry()->fClipStack/Region specifies the clip that has |
451 // already been applied. (If this is a top level device, then it specifies | 451 // already been applied. (If this is a top level device, then it specifies |
452 // a clip to the content area. If this is a layer, then it specifies | 452 // a clip to the content area. If this is a layer, then it specifies |
453 // the clip in effect when the layer was created.) There's no need to | 453 // the clip in effect when the layer was created.) There's no need to |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 if (fill) { | 944 if (fill) { |
945 noEffectPaint.setStyle(SkPaint::kFill_Style); | 945 noEffectPaint.setStyle(SkPaint::kFill_Style); |
946 } else { | 946 } else { |
947 noEffectPaint.setStyle(SkPaint::kStroke_Style); | 947 noEffectPaint.setStyle(SkPaint::kStroke_Style); |
948 noEffectPaint.setStrokeWidth(0); | 948 noEffectPaint.setStrokeWidth(0); |
949 } | 949 } |
950 drawPath(d, *pathPtr, noEffectPaint, NULL, true); | 950 drawPath(d, *pathPtr, noEffectPaint, NULL, true); |
951 return; | 951 return; |
952 } | 952 } |
953 | 953 |
954 #ifdef SK_PDF_USE_PATHOPS | |
955 if (handleInversePath(d, origPath, paint, pathIsMutable, prePathMatrix)) { | 954 if (handleInversePath(d, origPath, paint, pathIsMutable, prePathMatrix)) { |
956 return; | 955 return; |
957 } | 956 } |
958 #endif | |
959 | 957 |
960 if (handleRectAnnotation(pathPtr->getBounds(), matrix, paint)) { | 958 if (handleRectAnnotation(pathPtr->getBounds(), matrix, paint)) { |
961 return; | 959 return; |
962 } | 960 } |
963 | 961 |
964 ScopedContentEntry content(this, d.fClipStack, *d.fClip, matrix, paint); | 962 ScopedContentEntry content(this, d.fClipStack, *d.fClip, matrix, paint); |
965 if (!content.entry()) { | 963 if (!content.entry()) { |
966 return; | 964 return; |
967 } | 965 } |
968 SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(), | 966 SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(), |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 // initial transform, so just clip to the device size. | 1354 // initial transform, so just clip to the device size. |
1357 if (fPageSize != fContentSize) { | 1355 if (fPageSize != fContentSize) { |
1358 SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()), | 1356 SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()), |
1359 SkIntToScalar(this->height())); | 1357 SkIntToScalar(this->height())); |
1360 emit_clip(NULL, &r, out); | 1358 emit_clip(NULL, &r, out); |
1361 } | 1359 } |
1362 | 1360 |
1363 SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), out); | 1361 SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), out); |
1364 } | 1362 } |
1365 | 1363 |
1366 #ifdef SK_PDF_USE_PATHOPS | |
1367 /* Draws an inverse filled path by using Path Ops to compute the positive | 1364 /* Draws an inverse filled path by using Path Ops to compute the positive |
1368 * inverse using the current clip as the inverse bounds. | 1365 * inverse using the current clip as the inverse bounds. |
1369 * Return true if this was an inverse path and was properly handled, | 1366 * Return true if this was an inverse path and was properly handled, |
1370 * otherwise returns false and the normal drawing routine should continue, | 1367 * otherwise returns false and the normal drawing routine should continue, |
1371 * either as a (incorrect) fallback or because the path was not inverse | 1368 * either as a (incorrect) fallback or because the path was not inverse |
1372 * in the first place. | 1369 * in the first place. |
1373 */ | 1370 */ |
1374 bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, | 1371 bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, |
1375 const SkPaint& paint, bool pathIsMutable, | 1372 const SkPaint& paint, bool pathIsMutable, |
1376 const SkMatrix* prePathMatrix) { | 1373 const SkMatrix* prePathMatrix) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 bounds.outset(paint.getStrokeWidth() + SK_Scalar1, | 1419 bounds.outset(paint.getStrokeWidth() + SK_Scalar1, |
1423 paint.getStrokeWidth() + SK_Scalar1); | 1420 paint.getStrokeWidth() + SK_Scalar1); |
1424 | 1421 |
1425 if (!calculate_inverse_path(bounds, *pathPtr, &modifiedPath)) { | 1422 if (!calculate_inverse_path(bounds, *pathPtr, &modifiedPath)) { |
1426 return false; | 1423 return false; |
1427 } | 1424 } |
1428 | 1425 |
1429 drawPath(d, modifiedPath, noInversePaint, prePathMatrix, true); | 1426 drawPath(d, modifiedPath, noInversePaint, prePathMatrix, true); |
1430 return true; | 1427 return true; |
1431 } | 1428 } |
1432 #endif | |
1433 | 1429 |
1434 bool SkPDFDevice::handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, | 1430 bool SkPDFDevice::handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, |
1435 const SkPaint& p) { | 1431 const SkPaint& p) { |
1436 SkAnnotation* annotationInfo = p.getAnnotation(); | 1432 SkAnnotation* annotationInfo = p.getAnnotation(); |
1437 if (!annotationInfo) { | 1433 if (!annotationInfo) { |
1438 return false; | 1434 return false; |
1439 } | 1435 } |
1440 SkData* urlData = annotationInfo->find(SkAnnotationKeys::URL_Key()); | 1436 SkData* urlData = annotationInfo->find(SkAnnotationKeys::URL_Key()); |
1441 if (urlData) { | 1437 if (urlData) { |
1442 handleLinkToURL(urlData, r, matrix); | 1438 handleLinkToURL(urlData, r, matrix); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 return; | 2140 return; |
2145 } | 2141 } |
2146 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); | 2142 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); |
2147 if (!image) { | 2143 if (!image) { |
2148 return; | 2144 return; |
2149 } | 2145 } |
2150 | 2146 |
2151 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), | 2147 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), |
2152 &content.entry()->fContent); | 2148 &content.entry()->fContent); |
2153 } | 2149 } |
OLD | NEW |