| 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 // 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 "core/fxcrt/include/fx_ext.h" | 7 #include "core/fxcrt/include/fx_ext.h" |
| 8 | 8 |
| 9 #ifndef _SKIA_SUPPORT_ | 9 #ifndef _SKIA_SUPPORT_ |
| 10 #include "core/fxge/agg/fx_agg_driver.h" | 10 #include "core/fxge/agg/fx_agg_driver.h" |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "core/fxge/dib/dib_int.h" | 13 #include "core/fxge/dib/dib_int.h" |
| 14 #include "core/fxge/ge/fx_text_int.h" | 14 #include "core/fxge/ge/fx_text_int.h" |
| 15 #include "core/fxge/include/fx_freetype.h" | 15 #include "core/fxge/include/fx_freetype.h" |
| 16 #include "core/fxge/include/fx_ge.h" | 16 #include "core/fxge/include/fx_ge.h" |
| 17 | 17 |
| 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 18 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 19 #include "core/fxge/apple/apple_int.h" | 19 #include "core/fxge/apple/apple_int.h" |
| 20 #include "core/fxge/include/fx_ge_apple.h" | 20 #include "core/fxge/include/fx_ge_apple.h" |
| 21 #ifndef CGFLOAT_IS_DOUBLE | 21 #ifndef CGFLOAT_IS_DOUBLE |
| 22 #error Expected CGFLOAT_IS_DOUBLE to be defined by CoreGraphics headers | 22 #error Expected CGFLOAT_IS_DOUBLE to be defined by CoreGraphics headers |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 void* CQuartz2D::createGraphics(CFX_DIBitmap* pBitmap) { | 25 void* CQuartz2D::createGraphics(CFX_DIBitmap* pBitmap) { |
| 26 if (!pBitmap) { | 26 if (!pBitmap) { |
| 27 return NULL; | 27 return nullptr; |
| 28 } | 28 } |
| 29 CGBitmapInfo bmpInfo = kCGBitmapByteOrder32Little; | 29 CGBitmapInfo bmpInfo = kCGBitmapByteOrder32Little; |
| 30 switch (pBitmap->GetFormat()) { | 30 switch (pBitmap->GetFormat()) { |
| 31 case FXDIB_Rgb32: | 31 case FXDIB_Rgb32: |
| 32 bmpInfo |= kCGImageAlphaNoneSkipFirst; | 32 bmpInfo |= kCGImageAlphaNoneSkipFirst; |
| 33 break; | 33 break; |
| 34 case FXDIB_Argb: | 34 case FXDIB_Argb: |
| 35 default: | 35 default: |
| 36 return NULL; | 36 return nullptr; |
| 37 } | 37 } |
| 38 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | 38 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 39 CGContextRef context = CGBitmapContextCreate( | 39 CGContextRef context = CGBitmapContextCreate( |
| 40 pBitmap->GetBuffer(), pBitmap->GetWidth(), pBitmap->GetHeight(), 8, | 40 pBitmap->GetBuffer(), pBitmap->GetWidth(), pBitmap->GetHeight(), 8, |
| 41 pBitmap->GetPitch(), colorSpace, bmpInfo); | 41 pBitmap->GetPitch(), colorSpace, bmpInfo); |
| 42 CGColorSpaceRelease(colorSpace); | 42 CGColorSpaceRelease(colorSpace); |
| 43 return context; | 43 return context; |
| 44 } | 44 } |
| 45 void CQuartz2D::destroyGraphics(void* graphics) { | 45 void CQuartz2D::destroyGraphics(void* graphics) { |
| 46 if (graphics) { | 46 if (graphics) { |
| 47 CGContextRelease((CGContextRef)graphics); | 47 CGContextRelease((CGContextRef)graphics); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 void* CQuartz2D::CreateFont(const uint8_t* pFontData, uint32_t dwFontSize) { | 50 void* CQuartz2D::CreateFont(const uint8_t* pFontData, uint32_t dwFontSize) { |
| 51 CGDataProviderRef pDataProvider = | 51 CGDataProviderRef pDataProvider = CGDataProviderCreateWithData( |
| 52 CGDataProviderCreateWithData(NULL, pFontData, (size_t)dwFontSize, NULL); | 52 nullptr, pFontData, (size_t)dwFontSize, nullptr); |
| 53 if (NULL == pDataProvider) { | 53 if (!pDataProvider) |
| 54 return NULL; | 54 return nullptr; |
| 55 } | 55 |
| 56 CGFontRef pCGFont = CGFontCreateWithDataProvider(pDataProvider); | 56 CGFontRef pCGFont = CGFontCreateWithDataProvider(pDataProvider); |
| 57 CGDataProviderRelease(pDataProvider); | 57 CGDataProviderRelease(pDataProvider); |
| 58 return pCGFont; | 58 return pCGFont; |
| 59 } | 59 } |
| 60 void CQuartz2D::DestroyFont(void* pFont) { | 60 void CQuartz2D::DestroyFont(void* pFont) { |
| 61 CGFontRelease((CGFontRef)pFont); | 61 CGFontRelease((CGFontRef)pFont); |
| 62 } | 62 } |
| 63 void CQuartz2D::setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix) { | 63 void CQuartz2D::setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix) { |
| 64 if (!graphics || !matrix) { | 64 if (!graphics || !matrix) { |
| 65 return; | 65 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 CGContextSaveGState((CGContextRef)graphics); | 117 CGContextSaveGState((CGContextRef)graphics); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 void CQuartz2D::restoreGraphicsState(void* graphics) { | 120 void CQuartz2D::restoreGraphicsState(void* graphics) { |
| 121 if (graphics) { | 121 if (graphics) { |
| 122 CGContextRestoreGState((CGContextRef)graphics); | 122 CGContextRestoreGState((CGContextRef)graphics); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 static CGContextRef createContextWithBitmap(CFX_DIBitmap* pBitmap) { | 125 static CGContextRef createContextWithBitmap(CFX_DIBitmap* pBitmap) { |
| 126 if (!pBitmap || pBitmap->IsCmykImage() || pBitmap->GetBPP() < 32) { | 126 if (!pBitmap || pBitmap->IsCmykImage() || pBitmap->GetBPP() < 32) { |
| 127 return NULL; | 127 return nullptr; |
| 128 } | 128 } |
| 129 CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Little; | 129 CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Little; |
| 130 if (pBitmap->HasAlpha()) { | 130 if (pBitmap->HasAlpha()) { |
| 131 bitmapInfo |= kCGImageAlphaPremultipliedFirst; | 131 bitmapInfo |= kCGImageAlphaPremultipliedFirst; |
| 132 } else { | 132 } else { |
| 133 bitmapInfo |= kCGImageAlphaNoneSkipFirst; | 133 bitmapInfo |= kCGImageAlphaNoneSkipFirst; |
| 134 } | 134 } |
| 135 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | 135 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 136 CGContextRef context = CGBitmapContextCreate( | 136 CGContextRef context = CGBitmapContextCreate( |
| 137 pBitmap->GetBuffer(), pBitmap->GetWidth(), pBitmap->GetHeight(), 8, | 137 pBitmap->GetBuffer(), pBitmap->GetWidth(), pBitmap->GetHeight(), 8, |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 469 } |
| 470 if (!(m_renderCaps | FXRC_GET_BITS)) { | 470 if (!(m_renderCaps | FXRC_GET_BITS)) { |
| 471 return FALSE; | 471 return FALSE; |
| 472 } | 472 } |
| 473 CGPoint pt = CGPointMake(left, top); | 473 CGPoint pt = CGPointMake(left, top); |
| 474 pt = CGPointApplyAffineTransform(pt, m_foxitDevice2User); | 474 pt = CGPointApplyAffineTransform(pt, m_foxitDevice2User); |
| 475 CGAffineTransform ctm = CGContextGetCTM(m_context); | 475 CGAffineTransform ctm = CGContextGetCTM(m_context); |
| 476 pt.x *= FXSYS_fabs(ctm.a); | 476 pt.x *= FXSYS_fabs(ctm.a); |
| 477 pt.y *= FXSYS_fabs(ctm.d); | 477 pt.y *= FXSYS_fabs(ctm.d); |
| 478 CGImageRef image = CGBitmapContextCreateImage(m_context); | 478 CGImageRef image = CGBitmapContextCreateImage(m_context); |
| 479 if (NULL == image) { | 479 if (!image) |
| 480 return FALSE; | 480 return FALSE; |
| 481 } | 481 |
| 482 CGFloat width = (CGFloat)bitmap->GetWidth(); | 482 CGFloat width = (CGFloat)bitmap->GetWidth(); |
| 483 CGFloat height = (CGFloat)bitmap->GetHeight(); | 483 CGFloat height = (CGFloat)bitmap->GetHeight(); |
| 484 if (width + pt.x > m_width) { | 484 if (width + pt.x > m_width) { |
| 485 width -= (width + pt.x - m_width); | 485 width -= (width + pt.x - m_width); |
| 486 } | 486 } |
| 487 if (height + pt.y > m_height) { | 487 if (height + pt.y > m_height) { |
| 488 height -= (height + pt.y - m_height); | 488 height -= (height + pt.y - m_height); |
| 489 } | 489 } |
| 490 CGImageRef subImage = CGImageCreateWithImageInRect( | 490 CGImageRef subImage = CGImageCreateWithImageInRect( |
| 491 image, CGRectMake(pt.x, pt.y, width, height)); | 491 image, CGRectMake(pt.x, pt.y, width, height)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 src_height /= scale_y; | 540 src_height /= scale_y; |
| 541 CGRect rect_fx = CGRectMake(dest_left, dest_top, src_width, src_height); | 541 CGRect rect_fx = CGRectMake(dest_left, dest_top, src_width, src_height); |
| 542 CGRect rect_usr = CGRectApplyAffineTransform(rect_fx, m_foxitDevice2User); | 542 CGRect rect_usr = CGRectApplyAffineTransform(rect_fx, m_foxitDevice2User); |
| 543 CGContextBeginPath(m_context); | 543 CGContextBeginPath(m_context); |
| 544 CGContextAddRect(m_context, rect_usr); | 544 CGContextAddRect(m_context, rect_usr); |
| 545 CGContextClip(m_context); | 545 CGContextClip(m_context); |
| 546 rect_usr.size = | 546 rect_usr.size = |
| 547 CGSizeMake(pBitmap->GetWidth() / scale_x, pBitmap->GetHeight() / scale_y); | 547 CGSizeMake(pBitmap->GetWidth() / scale_x, pBitmap->GetHeight() / scale_y); |
| 548 rect_usr = CGRectOffset(rect_usr, -src_left, -src_top); | 548 rect_usr = CGRectOffset(rect_usr, -src_left, -src_top); |
| 549 CG_SetImageTransform(dest_left, dest_top, src_width, src_height, &rect_usr); | 549 CG_SetImageTransform(dest_left, dest_top, src_width, src_height, &rect_usr); |
| 550 CFX_DIBitmap* pBitmap1 = NULL; | 550 CFX_DIBitmap* pBitmap1 = nullptr; |
| 551 if (pBitmap->IsAlphaMask()) { | 551 if (pBitmap->IsAlphaMask()) { |
| 552 if (pBitmap->GetBuffer()) { | 552 if (pBitmap->GetBuffer()) { |
| 553 pBitmap1 = (CFX_DIBitmap*)pBitmap; | 553 pBitmap1 = (CFX_DIBitmap*)pBitmap; |
| 554 } else { | 554 } else { |
| 555 pBitmap1 = pBitmap->Clone(); | 555 pBitmap1 = pBitmap->Clone(); |
| 556 } | 556 } |
| 557 if (NULL == pBitmap1) { | 557 if (!pBitmap1) { |
| 558 RestoreState(false); | 558 RestoreState(false); |
| 559 return FALSE; | 559 return FALSE; |
| 560 } | 560 } |
| 561 CGDataProviderRef pBitmapProvider = CGDataProviderCreateWithData( | 561 CGDataProviderRef pBitmapProvider = CGDataProviderCreateWithData( |
| 562 NULL, pBitmap1->GetBuffer(), | 562 nullptr, pBitmap1->GetBuffer(), |
| 563 pBitmap1->GetPitch() * pBitmap1->GetHeight(), NULL); | 563 pBitmap1->GetPitch() * pBitmap1->GetHeight(), nullptr); |
| 564 CGColorSpaceRef pColorSpace = CGColorSpaceCreateDeviceGray(); | 564 CGColorSpaceRef pColorSpace = CGColorSpaceCreateDeviceGray(); |
| 565 CGBitmapInfo bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrderDefault; | 565 CGBitmapInfo bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrderDefault; |
| 566 CGImageRef pImage = CGImageCreate( | 566 CGImageRef pImage = CGImageCreate( |
| 567 pBitmap1->GetWidth(), pBitmap1->GetHeight(), pBitmap1->GetBPP(), | 567 pBitmap1->GetWidth(), pBitmap1->GetHeight(), pBitmap1->GetBPP(), |
| 568 pBitmap1->GetBPP(), pBitmap1->GetPitch(), pColorSpace, bitmapInfo, | 568 pBitmap1->GetBPP(), pBitmap1->GetPitch(), pColorSpace, bitmapInfo, |
| 569 pBitmapProvider, NULL, true, kCGRenderingIntentDefault); | 569 pBitmapProvider, nullptr, true, kCGRenderingIntentDefault); |
| 570 CGContextClipToMask(m_context, rect_usr, pImage); | 570 CGContextClipToMask(m_context, rect_usr, pImage); |
| 571 CGContextSetRGBFillColor(m_context, FXARGB_R(argb) / 255.f, | 571 CGContextSetRGBFillColor(m_context, FXARGB_R(argb) / 255.f, |
| 572 FXARGB_G(argb) / 255.f, FXARGB_B(argb) / 255.f, | 572 FXARGB_G(argb) / 255.f, FXARGB_B(argb) / 255.f, |
| 573 FXARGB_A(argb) / 255.f); | 573 FXARGB_A(argb) / 255.f); |
| 574 CGContextFillRect(m_context, rect_usr); | 574 CGContextFillRect(m_context, rect_usr); |
| 575 CGImageRelease(pImage); | 575 CGImageRelease(pImage); |
| 576 CGColorSpaceRelease(pColorSpace); | 576 CGColorSpaceRelease(pColorSpace); |
| 577 CGDataProviderRelease(pBitmapProvider); | 577 CGDataProviderRelease(pBitmapProvider); |
| 578 if (pBitmap1 != pBitmap) { | 578 if (pBitmap1 != pBitmap) { |
| 579 delete pBitmap1; | 579 delete pBitmap1; |
| 580 } | 580 } |
| 581 RestoreState(false); | 581 RestoreState(false); |
| 582 return TRUE; | 582 return TRUE; |
| 583 } | 583 } |
| 584 if (pBitmap->GetBPP() < 32) { | 584 if (pBitmap->GetBPP() < 32) { |
| 585 pBitmap1 = pBitmap->CloneConvert(FXDIB_Rgb32); | 585 pBitmap1 = pBitmap->CloneConvert(FXDIB_Rgb32); |
| 586 } else { | 586 } else { |
| 587 if (pBitmap->GetBuffer()) { | 587 if (pBitmap->GetBuffer()) { |
| 588 pBitmap1 = (CFX_DIBitmap*)pBitmap; | 588 pBitmap1 = (CFX_DIBitmap*)pBitmap; |
| 589 } else { | 589 } else { |
| 590 pBitmap1 = pBitmap->Clone(); | 590 pBitmap1 = pBitmap->Clone(); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 if (NULL == pBitmap1) { | 593 if (!pBitmap1) { |
| 594 RestoreState(false); | 594 RestoreState(false); |
| 595 return FALSE; | 595 return FALSE; |
| 596 } | 596 } |
| 597 if (pBitmap1->HasAlpha()) { | 597 if (pBitmap1->HasAlpha()) { |
| 598 if (pBitmap1 == pBitmap) { | 598 if (pBitmap1 == pBitmap) { |
| 599 pBitmap1 = pBitmap->Clone(); | 599 pBitmap1 = pBitmap->Clone(); |
| 600 if (!pBitmap1) { | 600 if (!pBitmap1) { |
| 601 RestoreState(false); | 601 RestoreState(false); |
| 602 return FALSE; | 602 return FALSE; |
| 603 } | 603 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 CGRect rect = CGRectMake(dest_left, dest_top, dest_width, dest_height); | 658 CGRect rect = CGRectMake(dest_left, dest_top, dest_width, dest_height); |
| 659 rect = CGRectApplyAffineTransform(rect, m_foxitDevice2User); | 659 rect = CGRectApplyAffineTransform(rect, m_foxitDevice2User); |
| 660 if (FXDIB_BICUBIC_INTERPOL == flags) { | 660 if (FXDIB_BICUBIC_INTERPOL == flags) { |
| 661 CGContextSetInterpolationQuality(m_context, kCGInterpolationHigh); | 661 CGContextSetInterpolationQuality(m_context, kCGInterpolationHigh); |
| 662 } else if (FXDIB_DOWNSAMPLE == flags) { | 662 } else if (FXDIB_DOWNSAMPLE == flags) { |
| 663 CGContextSetInterpolationQuality(m_context, kCGInterpolationNone); | 663 CGContextSetInterpolationQuality(m_context, kCGInterpolationNone); |
| 664 } else { | 664 } else { |
| 665 CGContextSetInterpolationQuality(m_context, kCGInterpolationMedium); | 665 CGContextSetInterpolationQuality(m_context, kCGInterpolationMedium); |
| 666 } | 666 } |
| 667 CG_SetImageTransform(dest_left, dest_top, dest_width, dest_height); | 667 CG_SetImageTransform(dest_left, dest_top, dest_width, dest_height); |
| 668 CFX_DIBitmap* pBitmap1 = NULL; | 668 CFX_DIBitmap* pBitmap1 = nullptr; |
| 669 if (pBitmap->IsAlphaMask()) { | 669 if (pBitmap->IsAlphaMask()) { |
| 670 if (pBitmap->GetBuffer()) { | 670 if (pBitmap->GetBuffer()) { |
| 671 pBitmap1 = (CFX_DIBitmap*)pBitmap; | 671 pBitmap1 = (CFX_DIBitmap*)pBitmap; |
| 672 } else { | 672 } else { |
| 673 pBitmap1 = pBitmap->Clone(); | 673 pBitmap1 = pBitmap->Clone(); |
| 674 } | 674 } |
| 675 if (NULL == pBitmap1) { | 675 if (!pBitmap1) { |
| 676 RestoreState(false); | 676 RestoreState(false); |
| 677 return FALSE; | 677 return FALSE; |
| 678 } | 678 } |
| 679 CGDataProviderRef pBitmapProvider = CGDataProviderCreateWithData( | 679 CGDataProviderRef pBitmapProvider = CGDataProviderCreateWithData( |
| 680 NULL, pBitmap1->GetBuffer(), | 680 nullptr, pBitmap1->GetBuffer(), |
| 681 pBitmap1->GetPitch() * pBitmap1->GetHeight(), NULL); | 681 pBitmap1->GetPitch() * pBitmap1->GetHeight(), nullptr); |
| 682 CGColorSpaceRef pColorSpace = CGColorSpaceCreateDeviceGray(); | 682 CGColorSpaceRef pColorSpace = CGColorSpaceCreateDeviceGray(); |
| 683 CGBitmapInfo bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrderDefault; | 683 CGBitmapInfo bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrderDefault; |
| 684 CGImageRef pImage = CGImageCreate( | 684 CGImageRef pImage = CGImageCreate( |
| 685 pBitmap1->GetWidth(), pBitmap1->GetHeight(), pBitmap1->GetBPP(), | 685 pBitmap1->GetWidth(), pBitmap1->GetHeight(), pBitmap1->GetBPP(), |
| 686 pBitmap1->GetBPP(), pBitmap1->GetPitch(), pColorSpace, bitmapInfo, | 686 pBitmap1->GetBPP(), pBitmap1->GetPitch(), pColorSpace, bitmapInfo, |
| 687 pBitmapProvider, NULL, true, kCGRenderingIntentDefault); | 687 pBitmapProvider, nullptr, true, kCGRenderingIntentDefault); |
| 688 CGContextClipToMask(m_context, rect, pImage); | 688 CGContextClipToMask(m_context, rect, pImage); |
| 689 CGContextSetRGBFillColor(m_context, FXARGB_R(argb) / 255.f, | 689 CGContextSetRGBFillColor(m_context, FXARGB_R(argb) / 255.f, |
| 690 FXARGB_G(argb) / 255.f, FXARGB_B(argb) / 255.f, | 690 FXARGB_G(argb) / 255.f, FXARGB_B(argb) / 255.f, |
| 691 FXARGB_A(argb) / 255.f); | 691 FXARGB_A(argb) / 255.f); |
| 692 CGContextFillRect(m_context, rect); | 692 CGContextFillRect(m_context, rect); |
| 693 CGImageRelease(pImage); | 693 CGImageRelease(pImage); |
| 694 CGColorSpaceRelease(pColorSpace); | 694 CGColorSpaceRelease(pColorSpace); |
| 695 CGDataProviderRelease(pBitmapProvider); | 695 CGDataProviderRelease(pBitmapProvider); |
| 696 if (pBitmap1 != pBitmap) { | 696 if (pBitmap1 != pBitmap) { |
| 697 delete pBitmap1; | 697 delete pBitmap1; |
| 698 } | 698 } |
| 699 RestoreState(false); | 699 RestoreState(false); |
| 700 return TRUE; | 700 return TRUE; |
| 701 } | 701 } |
| 702 if (pBitmap->GetBPP() < 32) { | 702 if (pBitmap->GetBPP() < 32) { |
| 703 pBitmap1 = pBitmap->CloneConvert(FXDIB_Rgb32); | 703 pBitmap1 = pBitmap->CloneConvert(FXDIB_Rgb32); |
| 704 } else { | 704 } else { |
| 705 if (pBitmap->GetBuffer()) { | 705 if (pBitmap->GetBuffer()) { |
| 706 pBitmap1 = (CFX_DIBitmap*)pBitmap; | 706 pBitmap1 = (CFX_DIBitmap*)pBitmap; |
| 707 } else { | 707 } else { |
| 708 pBitmap1 = pBitmap->Clone(); | 708 pBitmap1 = pBitmap->Clone(); |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 if (NULL == pBitmap1) { | 711 if (!pBitmap1) { |
| 712 RestoreState(false); | 712 RestoreState(false); |
| 713 return FALSE; | 713 return FALSE; |
| 714 } | 714 } |
| 715 if (pBitmap1->HasAlpha()) { | 715 if (pBitmap1->HasAlpha()) { |
| 716 if (pBitmap1 == pBitmap) { | 716 if (pBitmap1 == pBitmap) { |
| 717 pBitmap1 = pBitmap->Clone(); | 717 pBitmap1 = pBitmap->Clone(); |
| 718 if (!pBitmap1) { | 718 if (!pBitmap1) { |
| 719 RestoreState(false); | 719 RestoreState(false); |
| 720 return FALSE; | 720 return FALSE; |
| 721 } | 721 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 } | 810 } |
| 811 FX_BOOL CFX_QuartzDeviceDriver::DrawDeviceText(int nChars, | 811 FX_BOOL CFX_QuartzDeviceDriver::DrawDeviceText(int nChars, |
| 812 const FXTEXT_CHARPOS* pCharPos, | 812 const FXTEXT_CHARPOS* pCharPos, |
| 813 CFX_Font* pFont, | 813 CFX_Font* pFont, |
| 814 CFX_FontCache* pCache, | 814 CFX_FontCache* pCache, |
| 815 const CFX_Matrix* pObject2Device, | 815 const CFX_Matrix* pObject2Device, |
| 816 FX_FLOAT font_size, | 816 FX_FLOAT font_size, |
| 817 uint32_t color, | 817 uint32_t color, |
| 818 int alpha_flag, | 818 int alpha_flag, |
| 819 void* pIccTransform) { | 819 void* pIccTransform) { |
| 820 if (NULL == pFont || NULL == m_context) | 820 if (!pFont || !m_context) |
| 821 return FALSE; | 821 return FALSE; |
| 822 FX_BOOL bBold = pFont->IsBold(); | 822 FX_BOOL bBold = pFont->IsBold(); |
| 823 if (!bBold && pFont->GetSubstFont() && | 823 if (!bBold && pFont->GetSubstFont() && |
| 824 pFont->GetSubstFont()->m_Weight >= 500 && | 824 pFont->GetSubstFont()->m_Weight >= 500 && |
| 825 pFont->GetSubstFont()->m_Weight <= 600) { | 825 pFont->GetSubstFont()->m_Weight <= 600) { |
| 826 return FALSE; | 826 return FALSE; |
| 827 } | 827 } |
| 828 SaveState(); | 828 SaveState(); |
| 829 CGContextSetTextDrawingMode(m_context, kCGTextFillClip); | 829 CGContextSetTextDrawingMode(m_context, kCGTextFillClip); |
| 830 FX_BOOL ret = FALSE; | 830 FX_BOOL ret = FALSE; |
| 831 int32_t i = 0; | 831 int32_t i = 0; |
| 832 while (i < nChars) { | 832 while (i < nChars) { |
| 833 if (pCharPos[i].m_bGlyphAdjust || font_size < 0) { | 833 if (pCharPos[i].m_bGlyphAdjust || font_size < 0) { |
| 834 if (i > 0) { | 834 if (i > 0) { |
| 835 ret = CG_DrawGlypRun(i, pCharPos, pFont, pCache, NULL, pObject2Device, | 835 ret = |
| 836 font_size, color, alpha_flag, pIccTransform); | 836 CG_DrawGlypRun(i, pCharPos, pFont, pCache, nullptr, pObject2Device, |
| 837 font_size, color, alpha_flag, pIccTransform); |
| 837 if (!ret) { | 838 if (!ret) { |
| 838 RestoreState(false); | 839 RestoreState(false); |
| 839 return ret; | 840 return ret; |
| 840 } | 841 } |
| 841 } | 842 } |
| 842 const FXTEXT_CHARPOS* char_pos = pCharPos + i; | 843 const FXTEXT_CHARPOS* char_pos = pCharPos + i; |
| 843 CFX_Matrix glphy_matrix; | 844 CFX_Matrix glphy_matrix; |
| 844 if (font_size < 0) { | 845 if (font_size < 0) { |
| 845 glphy_matrix.Concat(-1, 0, 0, -1, 0, 0); | 846 glphy_matrix.Concat(-1, 0, 0, -1, 0, 0); |
| 846 } | 847 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 858 } | 859 } |
| 859 i++; | 860 i++; |
| 860 pCharPos += i; | 861 pCharPos += i; |
| 861 nChars -= i; | 862 nChars -= i; |
| 862 i = 0; | 863 i = 0; |
| 863 } else { | 864 } else { |
| 864 i++; | 865 i++; |
| 865 } | 866 } |
| 866 } | 867 } |
| 867 if (i > 0) { | 868 if (i > 0) { |
| 868 ret = CG_DrawGlypRun(i, pCharPos, pFont, pCache, NULL, pObject2Device, | 869 ret = CG_DrawGlypRun(i, pCharPos, pFont, pCache, nullptr, pObject2Device, |
| 869 font_size, color, alpha_flag, pIccTransform); | 870 font_size, color, alpha_flag, pIccTransform); |
| 870 } | 871 } |
| 871 RestoreState(false); | 872 RestoreState(false); |
| 872 return ret; | 873 return ret; |
| 873 } | 874 } |
| 874 void CFX_QuartzDeviceDriver::setStrokeInfo(const CFX_GraphStateData* graphState, | 875 void CFX_QuartzDeviceDriver::setStrokeInfo(const CFX_GraphStateData* graphState, |
| 875 FX_ARGB argb, | 876 FX_ARGB argb, |
| 876 FX_FLOAT lineWidth) { | 877 FX_FLOAT lineWidth) { |
| 877 if (NULL == graphState) { | 878 if (!graphState) |
| 878 return; | 879 return; |
| 879 } | 880 |
| 880 CGContextSetLineWidth(m_context, lineWidth); | 881 CGContextSetLineWidth(m_context, lineWidth); |
| 881 CGLineCap cap; | 882 CGLineCap cap; |
| 882 switch (graphState->m_LineCap) { | 883 switch (graphState->m_LineCap) { |
| 883 case CFX_GraphStateData::LineCapRound: { | 884 case CFX_GraphStateData::LineCapRound: { |
| 884 cap = kCGLineCapRound; | 885 cap = kCGLineCapRound; |
| 885 break; | 886 break; |
| 886 } | 887 } |
| 887 case CFX_GraphStateData::LineCapSquare: { | 888 case CFX_GraphStateData::LineCapSquare: { |
| 888 cap = kCGLineCapSquare; | 889 cap = kCGLineCapSquare; |
| 889 break; | 890 break; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 transform, CGAffineTransformMake(flip_x, 0, 0, flip_y, 0, 0)); | 983 transform, CGAffineTransformMake(flip_x, 0, 0, flip_y, 0, 0)); |
| 983 transform = CGAffineTransformConcat( | 984 transform = CGAffineTransformConcat( |
| 984 transform, CGAffineTransformMake(1, 0, 0, 1, offset_x, offset_y)); | 985 transform, CGAffineTransformMake(1, 0, 0, 1, offset_x, offset_y)); |
| 985 CGContextConcatCTM(m_context, transform); | 986 CGContextConcatCTM(m_context, transform); |
| 986 if (rect) { | 987 if (rect) { |
| 987 *rect = CGRectApplyAffineTransform(*rect, transform); | 988 *rect = CGRectApplyAffineTransform(*rect, transform); |
| 988 } | 989 } |
| 989 } | 990 } |
| 990 } | 991 } |
| 991 void CFX_QuartzDeviceDriver::ClearDriver() { | 992 void CFX_QuartzDeviceDriver::ClearDriver() { |
| 992 if (NULL == m_context) { | 993 if (!m_context) |
| 993 return; | 994 return; |
| 994 } | 995 |
| 995 for (int i = 0; i < m_saveCount; ++i) { | 996 for (int i = 0; i < m_saveCount; ++i) { |
| 996 CGContextRestoreGState(m_context); | 997 CGContextRestoreGState(m_context); |
| 997 } | 998 } |
| 998 m_saveCount = 0; | 999 m_saveCount = 0; |
| 999 if (m_context) { | 1000 if (m_context) { |
| 1000 CGContextRelease(m_context); | 1001 CGContextRelease(m_context); |
| 1001 } | 1002 } |
| 1002 } | 1003 } |
| 1003 CFX_QuartzDevice::CFX_QuartzDevice() { | 1004 CFX_QuartzDevice::CFX_QuartzDevice() { |
| 1004 m_bOwnedBitmap = FALSE; | 1005 m_bOwnedBitmap = FALSE; |
| 1005 m_pContext = NULL; | 1006 m_pContext = nullptr; |
| 1006 } | 1007 } |
| 1007 CFX_QuartzDevice::~CFX_QuartzDevice() { | 1008 CFX_QuartzDevice::~CFX_QuartzDevice() { |
| 1008 if (m_pContext) { | 1009 if (m_pContext) { |
| 1009 CGContextRelease(m_pContext); | 1010 CGContextRelease(m_pContext); |
| 1010 } | 1011 } |
| 1011 if (m_bOwnedBitmap) { | 1012 if (m_bOwnedBitmap) { |
| 1012 delete GetBitmap(); | 1013 delete GetBitmap(); |
| 1013 } | 1014 } |
| 1014 } | 1015 } |
| 1015 CGContextRef CFX_QuartzDevice::GetContext() { | 1016 CGContextRef CFX_QuartzDevice::GetContext() { |
| 1016 return m_pContext; | 1017 return m_pContext; |
| 1017 } | 1018 } |
| 1018 FX_BOOL CFX_QuartzDevice::Attach(CGContextRef context, int32_t nDeviceClass) { | 1019 FX_BOOL CFX_QuartzDevice::Attach(CGContextRef context, int32_t nDeviceClass) { |
| 1019 if (m_pContext) { | 1020 if (m_pContext) { |
| 1020 CGContextRelease(m_pContext); | 1021 CGContextRelease(m_pContext); |
| 1021 } | 1022 } |
| 1022 m_pContext = context; | 1023 m_pContext = context; |
| 1023 CGContextRetain(m_pContext); | 1024 CGContextRetain(m_pContext); |
| 1024 IFX_RenderDeviceDriver* pDriver = | 1025 IFX_RenderDeviceDriver* pDriver = |
| 1025 new CFX_QuartzDeviceDriver(m_pContext, nDeviceClass); | 1026 new CFX_QuartzDeviceDriver(m_pContext, nDeviceClass); |
| 1026 SetDeviceDriver(pDriver); | 1027 SetDeviceDriver(pDriver); |
| 1027 return TRUE; | 1028 return TRUE; |
| 1028 } | 1029 } |
| 1029 FX_BOOL CFX_QuartzDevice::Attach(CFX_DIBitmap* pBitmap) { | 1030 FX_BOOL CFX_QuartzDevice::Attach(CFX_DIBitmap* pBitmap) { |
| 1030 SetBitmap(pBitmap); | 1031 SetBitmap(pBitmap); |
| 1031 m_pContext = createContextWithBitmap(pBitmap); | 1032 m_pContext = createContextWithBitmap(pBitmap); |
| 1032 if (NULL == m_pContext) { | 1033 if (!m_pContext) |
| 1033 return FALSE; | 1034 return FALSE; |
| 1034 } | 1035 |
| 1035 IFX_RenderDeviceDriver* pDriver = | 1036 IFX_RenderDeviceDriver* pDriver = |
| 1036 new CFX_QuartzDeviceDriver(m_pContext, FXDC_DISPLAY); | 1037 new CFX_QuartzDeviceDriver(m_pContext, FXDC_DISPLAY); |
| 1037 SetDeviceDriver(pDriver); | 1038 SetDeviceDriver(pDriver); |
| 1038 return TRUE; | 1039 return TRUE; |
| 1039 } | 1040 } |
| 1040 FX_BOOL CFX_QuartzDevice::Create(int32_t width, | 1041 FX_BOOL CFX_QuartzDevice::Create(int32_t width, |
| 1041 int32_t height, | 1042 int32_t height, |
| 1042 FXDIB_Format format) { | 1043 FXDIB_Format format) { |
| 1043 if ((uint8_t)format < 32) { | 1044 if ((uint8_t)format < 32) { |
| 1044 return FALSE; | 1045 return FALSE; |
| 1045 } | 1046 } |
| 1046 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 1047 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
| 1047 if (!pBitmap->Create(width, height, format)) { | 1048 if (!pBitmap->Create(width, height, format)) { |
| 1048 delete pBitmap; | 1049 delete pBitmap; |
| 1049 return FALSE; | 1050 return FALSE; |
| 1050 } | 1051 } |
| 1051 m_bOwnedBitmap = TRUE; | 1052 m_bOwnedBitmap = TRUE; |
| 1052 return Attach(pBitmap); | 1053 return Attach(pBitmap); |
| 1053 } | 1054 } |
| 1054 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 1055 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| OLD | NEW |