| 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 <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "core/fxcodec/include/fx_codec.h" | 10 #include "core/fxcodec/include/fx_codec.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 return rect; | 420 return rect; |
| 421 } | 421 } |
| 422 | 422 |
| 423 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, | 423 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, |
| 424 const FXTEXT_CHARPOS* pCharPos, | 424 const FXTEXT_CHARPOS* pCharPos, |
| 425 CFX_Font* pFont, | 425 CFX_Font* pFont, |
| 426 CFX_FontCache* pCache, | 426 CFX_FontCache* pCache, |
| 427 FX_FLOAT font_size, | 427 FX_FLOAT font_size, |
| 428 const CFX_Matrix* pText2Device, | 428 const CFX_Matrix* pText2Device, |
| 429 uint32_t fill_color, | 429 uint32_t fill_color, |
| 430 uint32_t text_flags, | 430 uint32_t text_flags) { |
| 431 int alpha_flag, | |
| 432 void* pIccTransform) { | |
| 433 int nativetext_flags = text_flags; | 431 int nativetext_flags = text_flags; |
| 434 if (m_DeviceClass != FXDC_DISPLAY) { | 432 if (m_DeviceClass != FXDC_DISPLAY) { |
| 435 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { | 433 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { |
| 436 bool should_call_draw_device_text = true; | 434 bool should_call_draw_device_text = true; |
| 437 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 435 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 438 if ((text_flags & FXFONT_CIDFONT) || | 436 if ((text_flags & FXFONT_CIDFONT) || |
| 439 (pFont->GetPsName().Find( | 437 (pFont->GetPsName().Find( |
| 440 CFX_WideString::FromLocal("+ZJHL").AsStringC()) != -1) || | 438 CFX_WideString::FromLocal("+ZJHL").AsStringC()) != -1) || |
| 441 (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) { | 439 (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) { |
| 442 should_call_draw_device_text = false; | 440 should_call_draw_device_text = false; |
| 443 } | 441 } |
| 444 #endif | 442 #endif |
| 445 if (should_call_draw_device_text && | 443 if (should_call_draw_device_text && |
| 446 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | 444 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
| 447 pText2Device, font_size, fill_color, | 445 pText2Device, font_size, fill_color, |
| 448 alpha_flag, pIccTransform)) { | 446 0, nullptr)) { |
| 449 return TRUE; | 447 return TRUE; |
| 450 } | 448 } |
| 451 } | 449 } |
| 452 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 450 if (FXARGB_A(fill_color) < 255) |
| 453 ? FXGETFLAG_ALPHA_FILL(alpha_flag) | |
| 454 : FXARGB_A(fill_color); | |
| 455 if (alpha < 255) { | |
| 456 return FALSE; | 451 return FALSE; |
| 457 } | |
| 458 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { | 452 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { |
| 459 bool should_call_draw_device_text = true; | 453 bool should_call_draw_device_text = true; |
| 460 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 454 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 461 if ((text_flags & FXFONT_CIDFONT) || | 455 if ((text_flags & FXFONT_CIDFONT) || |
| 462 (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) { | 456 (pFont->GetPsName() == CFX_WideString::FromLocal("CNAAJI+cmex10"))) { |
| 463 should_call_draw_device_text = false; | 457 should_call_draw_device_text = false; |
| 464 } | 458 } |
| 465 #endif | 459 #endif |
| 466 if (should_call_draw_device_text && | 460 if (should_call_draw_device_text && |
| 467 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, | 461 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, |
| 468 pText2Device, font_size, fill_color, | 462 pText2Device, font_size, fill_color, 0, |
| 469 alpha_flag, pIccTransform)) { | 463 nullptr)) { |
| 470 return TRUE; | 464 return TRUE; |
| 471 } | 465 } |
| 472 } | 466 } |
| 473 CFX_Matrix char2device; | 467 CFX_Matrix char2device; |
| 474 CFX_Matrix text2Device; | 468 CFX_Matrix text2Device; |
| 475 if (pText2Device) { | 469 if (pText2Device) { |
| 476 char2device = *pText2Device; | 470 char2device = *pText2Device; |
| 477 text2Device = *pText2Device; | 471 text2Device = *pText2Device; |
| 478 } | 472 } |
| 479 char2device.Scale(font_size, -font_size); | 473 char2device.Scale(font_size, -font_size); |
| 480 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || | 474 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || |
| 481 ((m_DeviceClass == FXDC_PRINTER && !m_pDeviceDriver->IsPSPrintDriver()) && | 475 ((m_DeviceClass == FXDC_PRINTER && !m_pDeviceDriver->IsPSPrintDriver()) && |
| 482 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { | 476 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { |
| 483 if (pFont->GetFace() || | 477 if (pFont->GetFace() || |
| 484 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { | 478 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { |
| 485 int nPathFlags = | 479 int nPathFlags = |
| 486 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; | 480 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; |
| 487 return DrawTextPath(nChars, pCharPos, pFont, pCache, font_size, | 481 return DrawTextPathWithFlags(nChars, pCharPos, pFont, pCache, font_size, |
| 488 pText2Device, NULL, NULL, fill_color, 0, NULL, | 482 pText2Device, nullptr, nullptr, fill_color, |
| 489 nPathFlags, alpha_flag, pIccTransform); | 483 0, nullptr, nPathFlags); |
| 490 } | 484 } |
| 491 } | 485 } |
| 492 int anti_alias = FXFT_RENDER_MODE_MONO; | 486 int anti_alias = FXFT_RENDER_MODE_MONO; |
| 493 bool bNormal = false; | 487 bool bNormal = false; |
| 494 if ((text_flags & FXTEXT_NOSMOOTH) == 0) { | 488 if ((text_flags & FXTEXT_NOSMOOTH) == 0) { |
| 495 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { | 489 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { |
| 496 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { | 490 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { |
| 497 // Some Freetype implementations (like the one packaged with Fedora) do | 491 // Some Freetype implementations (like the one packaged with Fedora) do |
| 498 // not support hinting due to patents 6219025, 6239783, 6307566, | 492 // not support hinting due to patents 6219025, 6239783, 6307566, |
| 499 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest | 493 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 bitmap.m_pAlphaMask->Clear(0); | 608 bitmap.m_pAlphaMask->Clear(0); |
| 615 } | 609 } |
| 616 } | 610 } |
| 617 | 611 |
| 618 int dest_width = pixel_width; | 612 int dest_width = pixel_width; |
| 619 int a = 0; | 613 int a = 0; |
| 620 int r = 0; | 614 int r = 0; |
| 621 int g = 0; | 615 int g = 0; |
| 622 int b = 0; | 616 int b = 0; |
| 623 if (anti_alias == FXFT_RENDER_MODE_LCD) { | 617 if (anti_alias == FXFT_RENDER_MODE_LCD) { |
| 624 Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform); | 618 Color2Argb(fill_color, fill_color, (1 << 24), nullptr); |
| 625 ArgbDecode(fill_color, a, r, g, b); | 619 ArgbDecode(fill_color, a, r, g, b); |
| 626 } | 620 } |
| 627 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { | 621 for (const FXTEXT_GLYPHPOS& glyph : glyphs) { |
| 628 if (!glyph.m_pGlyph) | 622 if (!glyph.m_pGlyph) |
| 629 continue; | 623 continue; |
| 630 | 624 |
| 631 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; | 625 const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; |
| 632 int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left; | 626 int left = glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left; |
| 633 int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top; | 627 int top = glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top; |
| 634 int ncols = pGlyph->GetWidth(); | 628 int ncols = pGlyph->GetWidth(); |
| 635 int nrows = pGlyph->GetHeight(); | 629 int nrows = pGlyph->GetHeight(); |
| 636 if (anti_alias == FXFT_RENDER_MODE_NORMAL) { | 630 if (anti_alias == FXFT_RENDER_MODE_NORMAL) { |
| 637 if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color, 0, | 631 if (!bitmap.CompositeMask(left, top, ncols, nrows, pGlyph, fill_color, 0, |
| 638 0, FXDIB_BLEND_NORMAL, nullptr, FALSE, | 632 0, FXDIB_BLEND_NORMAL, nullptr, FALSE, 0, |
| 639 alpha_flag, pIccTransform)) { | 633 nullptr)) { |
| 640 return FALSE; | 634 return FALSE; |
| 641 } | 635 } |
| 642 continue; | 636 continue; |
| 643 } | 637 } |
| 644 | 638 |
| 645 bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); | 639 bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); |
| 646 ncols /= 3; | 640 ncols /= 3; |
| 647 int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; | 641 int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; |
| 648 int start_col = std::max(left, 0); | 642 int start_col = std::max(left, 0); |
| 649 int end_col = std::min(left + ncols, dest_width); | 643 int end_col = std::min(left + ncols, dest_width); |
| 650 if (start_col >= end_col) | 644 if (start_col >= end_col) |
| 651 continue; | 645 continue; |
| 652 | 646 |
| 653 DrawNormalTextHelper(&bitmap, pGlyph, nrows, left, top, start_col, end_col, | 647 DrawNormalTextHelper(&bitmap, pGlyph, nrows, left, top, start_col, end_col, |
| 654 bNormal, bBGRStripe, x_subpixel, a, r, g, b); | 648 bNormal, bBGRStripe, x_subpixel, a, r, g, b); |
| 655 } | 649 } |
| 656 if (bitmap.IsAlphaMask()) { | 650 if (bitmap.IsAlphaMask()) |
| 657 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color, alpha_flag, | 651 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); |
| 658 pIccTransform); | 652 else |
| 659 } else { | |
| 660 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); | 653 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); |
| 661 } | |
| 662 | |
| 663 return TRUE; | 654 return TRUE; |
| 664 } | 655 } |
| 665 | 656 |
| 666 FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars, | 657 FX_BOOL CFX_RenderDevice::DrawTextPathWithFlags( |
| 667 const FXTEXT_CHARPOS* pCharPos, | 658 int nChars, |
| 668 CFX_Font* pFont, | 659 const FXTEXT_CHARPOS* pCharPos, |
| 669 CFX_FontCache* pCache, | 660 CFX_Font* pFont, |
| 670 FX_FLOAT font_size, | 661 CFX_FontCache* pCache, |
| 671 const CFX_Matrix* pText2User, | 662 FX_FLOAT font_size, |
| 672 const CFX_Matrix* pUser2Device, | 663 const CFX_Matrix* pText2User, |
| 673 const CFX_GraphStateData* pGraphState, | 664 const CFX_Matrix* pUser2Device, |
| 674 uint32_t fill_color, | 665 const CFX_GraphStateData* pGraphState, |
| 675 FX_ARGB stroke_color, | 666 uint32_t fill_color, |
| 676 CFX_PathData* pClippingPath, | 667 FX_ARGB stroke_color, |
| 677 int nFlag, | 668 CFX_PathData* pClippingPath, |
| 678 int alpha_flag, | 669 int nFlag) { |
| 679 void* pIccTransform, | 670 if (!pCache) |
| 680 int blend_type) { | |
| 681 if (!pCache) { | |
| 682 pCache = CFX_GEModule::Get()->GetFontCache(); | 671 pCache = CFX_GEModule::Get()->GetFontCache(); |
| 683 } | 672 |
| 684 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); | 673 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont); |
| 685 FX_FONTCACHE_DEFINE(pCache, pFont); | 674 FX_FONTCACHE_DEFINE(pCache, pFont); |
| 686 for (int iChar = 0; iChar < nChars; iChar++) { | 675 for (int iChar = 0; iChar < nChars; iChar++) { |
| 687 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; | 676 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; |
| 688 CFX_Matrix matrix; | 677 CFX_Matrix matrix; |
| 689 if (charpos.m_bGlyphAdjust) | 678 if (charpos.m_bGlyphAdjust) |
| 690 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 679 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
| 691 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 680 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
| 692 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | 681 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
| 693 charpos.m_OriginY); | 682 charpos.m_OriginY); |
| 694 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | 683 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( |
| 695 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | 684 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); |
| 696 if (!pPath) { | 685 if (!pPath) |
| 697 continue; | 686 continue; |
| 698 } | 687 |
| 699 matrix.Concat(*pText2User); | 688 matrix.Concat(*pText2User); |
| 700 CFX_PathData TransformedPath(*pPath); | 689 CFX_PathData TransformedPath(*pPath); |
| 701 TransformedPath.Transform(&matrix); | 690 TransformedPath.Transform(&matrix); |
| 702 FX_BOOL bHasAlpha = FXGETFLAG_COLORTYPE(alpha_flag) | 691 if (fill_color || stroke_color) { |
| 703 ? (FXGETFLAG_ALPHA_FILL(alpha_flag) || | |
| 704 FXGETFLAG_ALPHA_STROKE(alpha_flag)) | |
| 705 : (fill_color || stroke_color); | |
| 706 if (bHasAlpha) { | |
| 707 int fill_mode = nFlag; | 692 int fill_mode = nFlag; |
| 708 if (FXGETFLAG_COLORTYPE(alpha_flag)) { | 693 if (fill_color) |
| 709 if (FXGETFLAG_ALPHA_FILL(alpha_flag)) { | 694 fill_mode |= FXFILL_WINDING; |
| 710 fill_mode |= FXFILL_WINDING; | |
| 711 } | |
| 712 } else { | |
| 713 if (fill_color) { | |
| 714 fill_mode |= FXFILL_WINDING; | |
| 715 } | |
| 716 } | |
| 717 fill_mode |= FX_FILL_TEXT_MODE; | 695 fill_mode |= FX_FILL_TEXT_MODE; |
| 718 if (!DrawPath(&TransformedPath, pUser2Device, pGraphState, fill_color, | 696 if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState, |
| 719 stroke_color, fill_mode, alpha_flag, pIccTransform, | 697 fill_color, stroke_color, fill_mode, |
| 720 blend_type)) { | 698 FXDIB_BLEND_NORMAL)) { |
| 721 return FALSE; | 699 return FALSE; |
| 722 } | 700 } |
| 723 } | 701 } |
| 724 if (pClippingPath) { | 702 if (pClippingPath) |
| 725 pClippingPath->Append(&TransformedPath, pUser2Device); | 703 pClippingPath->Append(&TransformedPath, pUser2Device); |
| 726 } | |
| 727 } | 704 } |
| 728 return TRUE; | 705 return TRUE; |
| 729 } | 706 } |
| 730 | 707 |
| 731 CFX_FontCache::CFX_FontCache() {} | 708 CFX_FontCache::CFX_FontCache() {} |
| 732 | 709 |
| 733 CFX_FontCache::~CFX_FontCache() { | 710 CFX_FontCache::~CFX_FontCache() { |
| 734 FreeCache(TRUE); | 711 FreeCache(TRUE); |
| 735 } | 712 } |
| 736 | 713 |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 1433 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
| 1457 va_list argList; | 1434 va_list argList; |
| 1458 va_start(argList, count); | 1435 va_start(argList, count); |
| 1459 for (int i = 0; i < count; i++) { | 1436 for (int i = 0; i < count; i++) { |
| 1460 int p = va_arg(argList, int); | 1437 int p = va_arg(argList, int); |
| 1461 ((uint32_t*)m_Key)[i] = p; | 1438 ((uint32_t*)m_Key)[i] = p; |
| 1462 } | 1439 } |
| 1463 va_end(argList); | 1440 va_end(argList); |
| 1464 m_KeyLen = count * sizeof(uint32_t); | 1441 m_KeyLen = count * sizeof(uint32_t); |
| 1465 } | 1442 } |
| OLD | NEW |