Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: xfa/fde/fde_gedevice.cpp

Issue 1877383002: Only SolidBrush types are created, remove other brushes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/fde_gedevice.h ('k') | xfa/fde/fde_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fde/fde_gedevice.h" 7 #include "xfa/fde/fde_gedevice.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "xfa/fde/fde_brush.h" 11 #include "xfa/fde/fde_brush.h"
12 #include "xfa/fde/fde_devbasic.h"
13 #include "xfa/fde/fde_geobject.h" 12 #include "xfa/fde/fde_geobject.h"
14 #include "xfa/fde/fde_image.h" 13 #include "xfa/fde/fde_image.h"
14 #include "xfa/fde/fde_object.h"
15 #include "xfa/fde/fde_pen.h" 15 #include "xfa/fde/fde_pen.h"
16 16
17 FX_BOOL FDE_GetStockHatchMask(int32_t iHatchStyle, CFX_DIBitmap& hatchMask) {
18 FDE_LPCHATCHDATA pData = FDE_DEVGetHatchData(iHatchStyle);
19 if (!pData) {
20 return FALSE;
21 }
22 hatchMask.Create(pData->iWidth, pData->iHeight, FXDIB_1bppMask);
23 FXSYS_memcpy(hatchMask.GetBuffer(), pData->MaskBits,
24 hatchMask.GetPitch() * pData->iHeight);
25 return TRUE;
26 }
27
28 IFDE_RenderDevice* IFDE_RenderDevice::Create(CFX_DIBitmap* pBitmap, 17 IFDE_RenderDevice* IFDE_RenderDevice::Create(CFX_DIBitmap* pBitmap,
29 FX_BOOL bRgbByteOrder) { 18 FX_BOOL bRgbByteOrder) {
30 if (pBitmap == NULL) { 19 if (pBitmap == NULL) {
31 return NULL; 20 return NULL;
32 } 21 }
33 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; 22 CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
34 pDevice->Attach(pBitmap, 0, bRgbByteOrder); 23 pDevice->Attach(pBitmap, 0, bRgbByteOrder);
35 return new CFDE_FxgeDevice(pDevice, TRUE); 24 return new CFDE_FxgeDevice(pDevice, TRUE);
36 } 25 }
37 IFDE_RenderDevice* IFDE_RenderDevice::Create(CFX_RenderDevice* pDevice) { 26 IFDE_RenderDevice* IFDE_RenderDevice::Create(CFX_RenderDevice* pDevice) {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 360 }
372 int32_t iDashCount = dashArray.GetSize(); 361 int32_t iDashCount = dashArray.GetSize();
373 if (iDashCount > 0) { 362 if (iDashCount > 0) {
374 graphState.SetDashCount(iDashCount); 363 graphState.SetDashCount(iDashCount);
375 for (int32_t i = 0; i < iDashCount; ++i) { 364 for (int32_t i = 0; i < iDashCount; ++i) {
376 graphState.m_DashArray[i] = dashArray[i] * fPenWidth; 365 graphState.m_DashArray[i] = dashArray[i] * fPenWidth;
377 } 366 }
378 } 367 }
379 return TRUE; 368 return TRUE;
380 } 369 }
381 typedef FX_BOOL (CFDE_FxgeDevice::*pfFillPath)(IFDE_Brush* pBrush, 370
382 const CFX_PathData* pPath,
383 const CFX_Matrix* pMatrix);
384 static const pfFillPath gs_FillPath[] = {
385 &CFDE_FxgeDevice::FillSolidPath, &CFDE_FxgeDevice::FillHatchPath,
386 &CFDE_FxgeDevice::FillTexturePath, &CFDE_FxgeDevice::FillLinearGradientPath,
387 };
388 FX_BOOL CFDE_FxgeDevice::FillPath(IFDE_Brush* pBrush, 371 FX_BOOL CFDE_FxgeDevice::FillPath(IFDE_Brush* pBrush,
389 const IFDE_Path* pPath, 372 const IFDE_Path* pPath,
390 const CFX_Matrix* pMatrix) { 373 const CFX_Matrix* pMatrix) {
391 CFDE_Path* pGePath = (CFDE_Path*)pPath; 374 CFDE_Path* pGePath = (CFDE_Path*)pPath;
392 if (pGePath == NULL) { 375 if (!pGePath)
393 return FALSE; 376 return FALSE;
394 } 377
395 if (pBrush == NULL) { 378 if (!pBrush)
396 return FALSE; 379 return FALSE;
397 } 380
398 int32_t iType = pBrush->GetType(); 381 return FillSolidPath(pBrush, &pGePath->m_Path, pMatrix);
399 if (iType < 0 || iType > FDE_BRUSHTYPE_MAX) {
400 return FALSE;
401 }
402 return (this->*gs_FillPath[iType])(pBrush, &pGePath->m_Path, pMatrix);
403 } 382 }
383
404 FX_BOOL CFDE_FxgeDevice::FillSolidPath(IFDE_Brush* pBrush, 384 FX_BOOL CFDE_FxgeDevice::FillSolidPath(IFDE_Brush* pBrush,
405 const CFX_PathData* pPath, 385 const CFX_PathData* pPath,
406 const CFX_Matrix* pMatrix) { 386 const CFX_Matrix* pMatrix) {
407 FXSYS_assert(pPath && pBrush && pBrush->GetType() == FDE_BRUSHTYPE_Solid); 387 FXSYS_assert(pPath && pBrush && pBrush->GetType() == FDE_BRUSHTYPE_Solid);
408 IFDE_SolidBrush* pSolidBrush = (IFDE_SolidBrush*)pBrush; 388
389 IFDE_SolidBrush* pSolidBrush = static_cast<IFDE_SolidBrush*>(pBrush);
409 return m_pDevice->DrawPath(pPath, (const CFX_Matrix*)pMatrix, NULL, 390 return m_pDevice->DrawPath(pPath, (const CFX_Matrix*)pMatrix, NULL,
410 pSolidBrush->GetColor(), 0, FXFILL_WINDING); 391 pSolidBrush->GetColor(), 0, FXFILL_WINDING);
411 } 392 }
412 FX_BOOL CFDE_FxgeDevice::FillHatchPath(IFDE_Brush* pBrush,
413 const CFX_PathData* pPath,
414 const CFX_Matrix* pMatrix) {
415 FXSYS_assert(pPath && pBrush && pBrush->GetType() == FDE_BRUSHTYPE_Hatch);
416 IFDE_HatchBrush* pHatchBrush = (IFDE_HatchBrush*)pBrush;
417 int32_t iStyle = pHatchBrush->GetHatchStyle();
418 if (iStyle < FDE_HATCHSTYLE_Min || iStyle > FDE_HATCHSTYLE_Max) {
419 return FALSE;
420 }
421 CFX_DIBitmap mask;
422 if (!FDE_GetStockHatchMask(iStyle, mask)) {
423 return FALSE;
424 }
425 FX_ARGB dwForeColor = pHatchBrush->GetColor(TRUE);
426 FX_ARGB dwBackColor = pHatchBrush->GetColor(FALSE);
427 CFX_FloatRect rectf = pPath->GetBoundingBox();
428 if (pMatrix) {
429 rectf.Transform((const CFX_Matrix*)pMatrix);
430 }
431 FX_RECT rect(FXSYS_round(rectf.left), FXSYS_round(rectf.top),
432 FXSYS_round(rectf.right), FXSYS_round(rectf.bottom));
433 m_pDevice->SaveState();
434 m_pDevice->StartRendering();
435 m_pDevice->SetClip_PathFill(pPath, (const CFX_Matrix*)pMatrix,
436 FXFILL_WINDING);
437 m_pDevice->FillRect(&rect, dwBackColor);
438 for (int32_t j = rect.bottom; j < rect.top; j += mask.GetHeight())
439 for (int32_t i = rect.left; i < rect.right; i += mask.GetWidth()) {
440 m_pDevice->SetBitMask(&mask, i, j, dwForeColor);
441 }
442 m_pDevice->EndRendering();
443 m_pDevice->RestoreState();
444 return TRUE;
445 }
446 FX_BOOL CFDE_FxgeDevice::FillTexturePath(IFDE_Brush* pBrush,
447 const CFX_PathData* pPath,
448 const CFX_Matrix* pMatrix) {
449 FXSYS_assert(pPath && pBrush && pBrush->GetType() == FDE_BRUSHTYPE_Texture);
450 IFDE_TextureBrush* pTextureBrush = static_cast<IFDE_TextureBrush*>(pBrush);
451 IFDE_Image* pImage = pTextureBrush->GetImage();
452 if (!pImage)
453 return FALSE;
454
455 CFX_Size size(pImage->GetImageWidth(), pImage->GetImageHeight());
456 CFX_DIBitmap bmp;
457 bmp.Create(size.x, size.y, FXDIB_Argb);
458 if (!pImage->StartLoadImage(&bmp, 0, 0, size.x, size.y, 0, 0, size.x,
459 size.y)) {
460 return FALSE;
461 }
462 if (pImage->DoLoadImage() < 100) {
463 return FALSE;
464 }
465 pImage->StopLoadImage();
466 return WrapTexture(pTextureBrush->GetWrapMode(), &bmp, pPath, pMatrix);
467 }
468 FX_BOOL CFDE_FxgeDevice::WrapTexture(int32_t iWrapMode,
469 const CFX_DIBitmap* pBitmap,
470 const CFX_PathData* pPath,
471 const CFX_Matrix* pMatrix) {
472 CFX_FloatRect rectf = pPath->GetBoundingBox();
473 if (pMatrix) {
474 rectf.Transform((const CFX_Matrix*)pMatrix);
475 }
476 FX_RECT rect(FXSYS_round(rectf.left), FXSYS_round(rectf.top),
477 FXSYS_round(rectf.right), FXSYS_round(rectf.bottom));
478 rect.Normalize();
479 if (rect.IsEmpty()) {
480 return FALSE;
481 }
482 m_pDevice->SaveState();
483 m_pDevice->StartRendering();
484 m_pDevice->SetClip_PathFill(pPath, (const CFX_Matrix*)pMatrix,
485 FXFILL_WINDING);
486 switch (iWrapMode) {
487 case FDE_WRAPMODE_Tile:
488 case FDE_WRAPMODE_TileFlipX:
489 case FDE_WRAPMODE_TileFlipY:
490 case FDE_WRAPMODE_TileFlipXY: {
491 FX_BOOL bFlipX = iWrapMode == FDE_WRAPMODE_TileFlipXY ||
492 iWrapMode == FDE_WRAPMODE_TileFlipX;
493 FX_BOOL bFlipY = iWrapMode == FDE_WRAPMODE_TileFlipXY ||
494 iWrapMode == FDE_WRAPMODE_TileFlipY;
495 const CFX_DIBitmap* pFlip[2][2];
496 pFlip[0][0] = pBitmap;
497 pFlip[0][1] = bFlipX ? pBitmap->FlipImage(TRUE, FALSE) : pBitmap;
498 pFlip[1][0] = bFlipY ? pBitmap->FlipImage(FALSE, TRUE) : pBitmap;
499 pFlip[1][1] =
500 (bFlipX || bFlipY) ? pBitmap->FlipImage(bFlipX, bFlipY) : pBitmap;
501 int32_t iCounterY = 0;
502 for (int32_t j = rect.top; j < rect.bottom; j += pBitmap->GetHeight()) {
503 int32_t indexY = iCounterY++ % 2;
504 int32_t iCounterX = 0;
505 for (int32_t i = rect.left; i < rect.right; i += pBitmap->GetWidth()) {
506 int32_t indexX = iCounterX++ % 2;
507 m_pDevice->SetDIBits(pFlip[indexY][indexX], i, j);
508 }
509 }
510 if (pFlip[0][1] != pFlip[0][0]) {
511 delete pFlip[0][1];
512 }
513 if (pFlip[1][0] != pFlip[0][0]) {
514 delete pFlip[1][0];
515 }
516 if (pFlip[1][1] != pFlip[0][0]) {
517 delete pFlip[1][1];
518 }
519 } break;
520 case FDE_WRAPMODE_Clamp: {
521 m_pDevice->SetDIBits(pBitmap, rect.left, rect.bottom);
522 } break;
523 }
524 m_pDevice->EndRendering();
525 m_pDevice->RestoreState();
526 return TRUE;
527 }
528 FX_BOOL CFDE_FxgeDevice::FillLinearGradientPath(IFDE_Brush* pBrush,
529 const CFX_PathData* pPath,
530 const CFX_Matrix* pMatrix) {
531 FXSYS_assert(pPath && pBrush &&
532 pBrush->GetType() == FDE_BRUSHTYPE_LinearGradient);
533 IFDE_LinearGradientBrush* pLinearBrush = (IFDE_LinearGradientBrush*)pBrush;
534 CFX_PointF pt0, pt1;
535 pLinearBrush->GetLinearPoints(pt0, pt1);
536 CFX_VectorF fDiagonal(pt0, pt1);
537 FX_FLOAT fTheta = FXSYS_atan2(fDiagonal.y, fDiagonal.x);
538 FX_FLOAT fLength = fDiagonal.Length();
539 FX_FLOAT fTotalX = fLength / FXSYS_cos(fTheta);
540 FX_FLOAT fTotalY = fLength / FXSYS_cos(FX_PI / 2 - fTheta);
541 FX_FLOAT fSteps = std::max(fTotalX, fTotalY);
542 FX_FLOAT dx = fTotalX / fSteps;
543 FX_FLOAT dy = fTotalY / fSteps;
544 FX_ARGB cr0, cr1;
545 pLinearBrush->GetLinearColors(cr0, cr1);
546 FX_FLOAT a0 = FXARGB_A(cr0);
547 FX_FLOAT r0 = FXARGB_R(cr0);
548 FX_FLOAT g0 = FXARGB_G(cr0);
549 FX_FLOAT b0 = FXARGB_B(cr0);
550 FX_FLOAT da = (FXARGB_A(cr1) - a0) / fSteps;
551 FX_FLOAT dr = (FXARGB_R(cr1) - r0) / fSteps;
552 FX_FLOAT dg = (FXARGB_G(cr1) - g0) / fSteps;
553 FX_FLOAT db = (FXARGB_B(cr1) - b0) / fSteps;
554 CFX_DIBitmap bmp;
555 bmp.Create(FXSYS_round(FXSYS_fabs(fDiagonal.x)),
556 FXSYS_round(FXSYS_fabs(fDiagonal.y)), FXDIB_Argb);
557 CFX_FxgeDevice dev;
558 dev.Attach(&bmp);
559 pt1 = pt0;
560 int32_t iSteps = FXSYS_round(FXSYS_ceil(fSteps));
561 while (--iSteps >= 0) {
562 cr0 = ArgbEncode(FXSYS_round(a0), FXSYS_round(r0), FXSYS_round(g0),
563 FXSYS_round(b0));
564 dev.DrawCosmeticLine(pt0.x, pt0.y, pt1.x, pt1.y, cr0);
565 pt1.x += dx;
566 pt0.y += dy;
567 a0 += da;
568 r0 += dr;
569 g0 += dg;
570 b0 += db;
571 }
572 return WrapTexture(pLinearBrush->GetWrapMode(), &bmp, pPath, pMatrix);
573 }
OLDNEW
« no previous file with comments | « xfa/fde/fde_gedevice.h ('k') | xfa/fde/fde_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698