| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/include/fxge/fx_ge.h" | 5 #include "core/include/fxge/fx_ge.h" |
| 6 | 6 |
| 7 #if defined(_SKIA_SUPPORT_) | 7 #if defined(_SKIA_SUPPORT_) |
| 8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
| 9 | 9 |
| 10 #include "SkDashPathEffect.h" | 10 #include "SkDashPathEffect.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 default: | 205 default: |
| 206 join = SkPaint::kMiter_Join; | 206 join = SkPaint::kMiter_Join; |
| 207 break; | 207 break; |
| 208 } | 208 } |
| 209 FX_FIXFLOAT width = pGraphState->m_LineWidth * scale; | 209 FX_FIXFLOAT width = pGraphState->m_LineWidth * scale; |
| 210 FX_FIXFLOAT unit = fix32_to_8(fixdiv_8_8_to_32( | 210 FX_FIXFLOAT unit = fix32_to_8(fixdiv_8_8_to_32( |
| 211 FIX8_ONE, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2)); | 211 FIX8_ONE, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2)); |
| 212 if (width <= unit) | 212 if (width <= unit) |
| 213 width = unit; | 213 width = unit; |
| 214 | 214 |
| 215 if (pGraphState->m_DashArray == NULL) { | 215 if (pGraphState->m_DashArray) { |
| 216 SkStroke stroker; | |
| 217 stroker.setCap(cap); | |
| 218 stroker.setJoin(join); | |
| 219 stroker.setMiterLimit(pGraphState->m_MiterLimit); | |
| 220 stroker.setWidth(width); | |
| 221 stroker.setDoFill(FALSE); | |
| 222 stroker.strokePath(path_data, dstPathData); | |
| 223 SkMatrix smatrix; | |
| 224 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, | |
| 225 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, | |
| 226 0, 1); | |
| 227 dstPathData->transform(smatrix); | |
| 228 } else { | |
| 229 int count = (pGraphState->m_DashCount + 1) / 2; | 216 int count = (pGraphState->m_DashCount + 1) / 2; |
| 230 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); | 217 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar)); |
| 231 // Set dash pattern | 218 // Set dash pattern |
| 232 for (int i = 0; i < count; i++) { | 219 for (int i = 0; i < count; i++) { |
| 233 FX_FIXFLOAT on = pGraphState->m_DashArray[i * 2]; | 220 FX_FIXFLOAT on = pGraphState->m_DashArray[i * 2]; |
| 234 if (on <= 0.000001f) | 221 if (on <= 0.000001f) |
| 235 on = FIX8_ONE / 10; | 222 on = FIX8_ONE / 10; |
| 236 FX_FIXFLOAT off = i * 2 + 1 == pGraphState->m_DashCount | 223 FX_FIXFLOAT off = i * 2 + 1 == pGraphState->m_DashCount |
| 237 ? on | 224 ? on |
| 238 : pGraphState->m_DashArray[i * 2 + 1]; | 225 : pGraphState->m_DashArray[i * 2 + 1]; |
| 239 if (off < 0) | 226 if (off < 0) |
| 240 off = 0; | 227 off = 0; |
| 241 intervals[i * 2] = on * scale; | 228 intervals[i * 2] = on * scale; |
| 242 intervals[i * 2 + 1] = off * scale; | 229 intervals[i * 2 + 1] = off * scale; |
| 243 } | 230 } |
| 244 SkDashPathEffect* pEffect = new SkDashPathEffect( | 231 SkDashPathEffect* pEffect = new SkDashPathEffect( |
| 245 intervals, count * 2, pGraphState->m_DashPhase * scale); | 232 intervals, count * 2, pGraphState->m_DashPhase * scale); |
| 246 spaint.setPathEffect(pEffect)->unref(); | 233 spaint.setPathEffect(pEffect)->unref(); |
| 247 spaint.setStrokeWidth(width); | 234 spaint.setStrokeWidth(width); |
| 248 spaint.setStrokeMiter(pGraphState->m_MiterLimit); | 235 spaint.setStrokeMiter(pGraphState->m_MiterLimit); |
| 249 spaint.setStrokeCap(cap); | 236 spaint.setStrokeCap(cap); |
| 250 spaint.setStrokeJoin(join); | 237 spaint.setStrokeJoin(join); |
| 251 spaint.getFillPath(path_data, dstPathData); | 238 spaint.getFillPath(path_data, dstPathData); |
| 252 SkMatrix smatrix; | 239 SkMatrix smatrix; |
| 253 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, | 240 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, |
| 254 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, | 241 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, |
| 255 0, 1); | 242 0, 1); |
| 256 dstPathData->transform(smatrix); | 243 dstPathData->transform(smatrix); |
| 257 FX_Free(intervals); | 244 FX_Free(intervals); |
| 245 } else { |
| 246 SkStroke stroker; |
| 247 stroker.setCap(cap); |
| 248 stroker.setJoin(join); |
| 249 stroker.setMiterLimit(pGraphState->m_MiterLimit); |
| 250 stroker.setWidth(width); |
| 251 stroker.setDoFill(FALSE); |
| 252 stroker.strokePath(path_data, dstPathData); |
| 253 SkMatrix smatrix; |
| 254 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, |
| 255 pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, |
| 256 0, 1); |
| 257 dstPathData->transform(smatrix); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 261 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
| 262 int dither_bits, | 262 int dither_bits, |
| 263 FX_BOOL bRgbByteOrder, | 263 FX_BOOL bRgbByteOrder, |
| 264 CFX_DIBitmap* pOriDevice, | 264 CFX_DIBitmap* pOriDevice, |
| 265 FX_BOOL bGroupKnockout) { | 265 FX_BOOL bGroupKnockout) { |
| 266 m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, | 266 m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, |
| 267 pOriDevice, bGroupKnockout); | 267 pOriDevice, bGroupKnockout); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 // Finally, we have got the mask that we need, intersect with current clip | 326 // Finally, we have got the mask that we need, intersect with current clip |
| 327 // region | 327 // region |
| 328 m_pAggDriver->m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask); | 328 m_pAggDriver->m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask); |
| 329 } | 329 } |
| 330 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( | 330 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill( |
| 331 const CFX_PathData* pPathData, // path info | 331 const CFX_PathData* pPathData, // path info |
| 332 const CFX_AffineMatrix* pObject2Device, // optional transformation | 332 const CFX_AffineMatrix* pObject2Device, // optional transformation |
| 333 int fill_mode // fill mode, WINDING or ALTERNATE | 333 int fill_mode // fill mode, WINDING or ALTERNATE |
| 334 ) { | 334 ) { |
| 335 if (m_pAggDriver->m_pClipRgn == NULL) | 335 if (!m_pAggDriver->m_pClipRgn) { |
| 336 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( | 336 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( |
| 337 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 337 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 338 } |
| 338 | 339 |
| 339 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 340 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
| 340 CFX_FloatRect rectf; | 341 CFX_FloatRect rectf; |
| 341 if (pPathData->IsRect(pObject2Device, &rectf)) { | 342 if (pPathData->IsRect(pObject2Device, &rectf)) { |
| 342 rectf.Intersect( | 343 rectf.Intersect( |
| 343 CFX_FloatRect(0, 0, (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 344 CFX_FloatRect(0, 0, (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 344 (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 345 (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 345 FX_RECT rect = rectf.GetOutterRect(); | 346 FX_RECT rect = rectf.GetOutterRect(); |
| 346 m_pAggDriver->m_pClipRgn->IntersectRect(rect); | 347 m_pAggDriver->m_pClipRgn->IntersectRect(rect); |
| 347 return TRUE; | 348 return TRUE; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 362 SetClipMask(path_data.m_PathData, &spaint); | 363 SetClipMask(path_data.m_PathData, &spaint); |
| 363 | 364 |
| 364 return TRUE; | 365 return TRUE; |
| 365 } | 366 } |
| 366 | 367 |
| 367 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( | 368 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke( |
| 368 const CFX_PathData* pPathData, // path info | 369 const CFX_PathData* pPathData, // path info |
| 369 const CFX_AffineMatrix* pObject2Device, // optional transformation | 370 const CFX_AffineMatrix* pObject2Device, // optional transformation |
| 370 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 371 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
| 371 ) { | 372 ) { |
| 372 if (m_pAggDriver->m_pClipRgn == NULL) | 373 if (!m_pAggDriver->m_pClipRgn) { |
| 373 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( | 374 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn( |
| 374 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 375 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 376 } |
| 375 | 377 |
| 376 // build path data | 378 // build path data |
| 377 CSkia_PathData path_data; | 379 CSkia_PathData path_data; |
| 378 path_data.BuildPath(pPathData, NULL); | 380 path_data.BuildPath(pPathData, NULL); |
| 379 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); | 381 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); |
| 380 | 382 |
| 381 SkPaint spaint; | 383 SkPaint spaint; |
| 382 spaint.setColor(0xffffffff); | 384 spaint.setColor(0xffffffff); |
| 383 spaint.setStyle(SkPaint::kStroke_Style); | 385 spaint.setStyle(SkPaint::kStroke_Style); |
| 384 spaint.setAntiAlias(TRUE); | 386 spaint.setAntiAlias(TRUE); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 428 |
| 427 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( | 429 FX_BOOL CFX_SkiaDeviceDriver::DrawPath( |
| 428 const CFX_PathData* pPathData, // path info | 430 const CFX_PathData* pPathData, // path info |
| 429 const CFX_AffineMatrix* pObject2Device, // optional transformation | 431 const CFX_AffineMatrix* pObject2Device, // optional transformation |
| 430 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 432 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
| 431 FX_DWORD fill_color, // fill color | 433 FX_DWORD fill_color, // fill color |
| 432 FX_DWORD stroke_color, // stroke color | 434 FX_DWORD stroke_color, // stroke color |
| 433 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 435 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
| 434 int alpha_flag, | 436 int alpha_flag, |
| 435 void* pIccTransform) { | 437 void* pIccTransform) { |
| 436 if (GetBuffer() == NULL) | 438 if (!GetBuffer()) |
| 437 return TRUE; | 439 return TRUE; |
| 438 FOXIT_DEBUG1("CFX_SkiaDeviceDriver::DrawPath: entering"); | 440 FOXIT_DEBUG1("CFX_SkiaDeviceDriver::DrawPath: entering"); |
| 439 SkIRect rect; | 441 SkIRect rect; |
| 440 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 442 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
| 441 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 443 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
| 442 if ((fill_mode & 3) && fill_color) { | 444 if ((fill_mode & 3) && fill_color) { |
| 443 // We have to transform before building path data, otherwise we'll have | 445 // We have to transform before building path data, otherwise we'll have |
| 444 // flatting problem | 446 // flatting problem |
| 445 // when we enlarge a small path (flatten before transformed) | 447 // when we enlarge a small path (flatten before transformed) |
| 446 // TESTDOC: Bug #5115 - DS_S1Dimpact_lr.pdf | 448 // TESTDOC: Bug #5115 - DS_S1Dimpact_lr.pdf |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 588 |
| 587 CFX_SkiaDevice::CFX_SkiaDevice() { | 589 CFX_SkiaDevice::CFX_SkiaDevice() { |
| 588 m_bOwnedBitmap = FALSE; | 590 m_bOwnedBitmap = FALSE; |
| 589 } | 591 } |
| 590 | 592 |
| 591 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap, | 593 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap, |
| 592 int dither_bits, | 594 int dither_bits, |
| 593 FX_BOOL bRgbByteOrder, | 595 FX_BOOL bRgbByteOrder, |
| 594 CFX_DIBitmap* pOriDevice, | 596 CFX_DIBitmap* pOriDevice, |
| 595 FX_BOOL bGroupKnockout) { | 597 FX_BOOL bGroupKnockout) { |
| 596 if (pBitmap == NULL) | 598 if (!pBitmap) |
| 597 return FALSE; | 599 return FALSE; |
| 598 SetBitmap(pBitmap); | 600 SetBitmap(pBitmap); |
| 599 CFX_SkiaDeviceDriver* pDriver = new CFX_SkiaDeviceDriver( | 601 CFX_SkiaDeviceDriver* pDriver = new CFX_SkiaDeviceDriver( |
| 600 pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout); | 602 pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout); |
| 601 SetDeviceDriver(pDriver); | 603 SetDeviceDriver(pDriver); |
| 602 return TRUE; | 604 return TRUE; |
| 603 } | 605 } |
| 604 | 606 |
| 605 FX_BOOL CFX_SkiaDevice::Create(int width, | 607 FX_BOOL CFX_SkiaDevice::Create(int width, |
| 606 int height, | 608 int height, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 618 new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE); | 620 new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE); |
| 619 SetDeviceDriver(pDriver); | 621 SetDeviceDriver(pDriver); |
| 620 return TRUE; | 622 return TRUE; |
| 621 } | 623 } |
| 622 CFX_SkiaDevice::~CFX_SkiaDevice() { | 624 CFX_SkiaDevice::~CFX_SkiaDevice() { |
| 623 if (m_bOwnedBitmap && GetBitmap()) | 625 if (m_bOwnedBitmap && GetBitmap()) |
| 624 delete GetBitmap(); | 626 delete GetBitmap(); |
| 625 } | 627 } |
| 626 | 628 |
| 627 #endif | 629 #endif |
| OLD | NEW |