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

Side by Side Diff: core/fxge/ge/cfx_renderdevice.cpp

Issue 2158023002: Pdfium: Fix fonts leaking on ClosePage. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix xfa tests. Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fxge/include/cfx_renderdevice.h" 7 #include "core/fxge/include/cfx_renderdevice.h"
8 8
9 #include "core/fxcrt/include/fx_safe_types.h" 9 #include "core/fxcrt/include/fx_safe_types.h"
10 #include "core/fxge/include/cfx_autofontcache.h" 10 #include "core/fxge/include/cfx_autofontcache.h"
11 #include "core/fxge/include/cfx_facecache.h" 11 #include "core/fxge/include/cfx_facecache.h"
12 #include "core/fxge/include/cfx_fontcache.h"
13 #include "core/fxge/include/cfx_fxgedevice.h" 12 #include "core/fxge/include/cfx_fxgedevice.h"
14 #include "core/fxge/include/cfx_graphstatedata.h" 13 #include "core/fxge/include/cfx_graphstatedata.h"
15 #include "core/fxge/include/cfx_pathdata.h" 14 #include "core/fxge/include/cfx_pathdata.h"
16 #include "core/fxge/include/ifx_renderdevicedriver.h" 15 #include "core/fxge/include/ifx_renderdevicedriver.h"
17 16
18 #if defined _SKIA_SUPPORT_ 17 #if defined _SKIA_SUPPORT_
19 #include "third_party/skia/include/core/SkTypes.h" 18 #include "third_party/skia/include/core/SkTypes.h"
20 #endif 19 #endif
21 20
22 namespace { 21 namespace {
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 int bitmap_alpha, 816 int bitmap_alpha,
818 int blend_type) { 817 int blend_type) {
819 return m_pDeviceDriver->SetBitsWithMask(pBitmap, pMask, left, top, 818 return m_pDeviceDriver->SetBitsWithMask(pBitmap, pMask, left, top,
820 bitmap_alpha, blend_type); 819 bitmap_alpha, blend_type);
821 } 820 }
822 #endif 821 #endif
823 822
824 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars, 823 FX_BOOL CFX_RenderDevice::DrawNormalText(int nChars,
825 const FXTEXT_CHARPOS* pCharPos, 824 const FXTEXT_CHARPOS* pCharPos,
826 CFX_Font* pFont, 825 CFX_Font* pFont,
827 CFX_FontCache* pCache,
828 FX_FLOAT font_size, 826 FX_FLOAT font_size,
829 const CFX_Matrix* pText2Device, 827 const CFX_Matrix* pText2Device,
830 uint32_t fill_color, 828 uint32_t fill_color,
831 uint32_t text_flags) { 829 uint32_t text_flags) {
832 int nativetext_flags = text_flags; 830 int nativetext_flags = text_flags;
833 if (m_DeviceClass != FXDC_DISPLAY) { 831 if (m_DeviceClass != FXDC_DISPLAY) {
834 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) { 832 if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) {
835 if (ShouldDrawDeviceText(pFont, text_flags) && 833 if (ShouldDrawDeviceText(pFont, text_flags) &&
836 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, 834 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pText2Device,
837 pText2Device, font_size, 835 font_size, fill_color)) {
838 fill_color)) {
839 return TRUE; 836 return TRUE;
840 } 837 }
841 } 838 }
842 if (FXARGB_A(fill_color) < 255) 839 if (FXARGB_A(fill_color) < 255)
843 return FALSE; 840 return FALSE;
844 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) { 841 } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) {
845 if (ShouldDrawDeviceText(pFont, text_flags) && 842 if (ShouldDrawDeviceText(pFont, text_flags) &&
846 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pCache, 843 m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pText2Device,
847 pText2Device, font_size, fill_color)) { 844 font_size, fill_color)) {
848 return TRUE; 845 return TRUE;
849 } 846 }
850 } 847 }
851 CFX_Matrix char2device; 848 CFX_Matrix char2device;
852 CFX_Matrix text2Device; 849 CFX_Matrix text2Device;
853 if (pText2Device) { 850 if (pText2Device) {
854 char2device = *pText2Device; 851 char2device = *pText2Device;
855 text2Device = *pText2Device; 852 text2Device = *pText2Device;
856 } 853 }
857 char2device.Scale(font_size, -font_size); 854 char2device.Scale(font_size, -font_size);
858 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f || 855 if (FXSYS_fabs(char2device.a) + FXSYS_fabs(char2device.b) > 50 * 1.0f ||
859 ((m_DeviceClass == FXDC_PRINTER) && 856 ((m_DeviceClass == FXDC_PRINTER) &&
860 !(text_flags & FXTEXT_PRINTIMAGETEXT))) { 857 !(text_flags & FXTEXT_PRINTIMAGETEXT))) {
861 if (pFont->GetFace() || 858 if (pFont->GetFace() ||
862 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) { 859 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_GLYPHPATH)) {
863 int nPathFlags = 860 int nPathFlags =
864 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH; 861 (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH;
865 return DrawTextPath(nChars, pCharPos, pFont, pCache, font_size, 862 return DrawTextPath(nChars, pCharPos, pFont, font_size, pText2Device,
866 pText2Device, nullptr, nullptr, fill_color, 0, 863 nullptr, nullptr, fill_color, 0, nullptr, nPathFlags);
867 nullptr, nPathFlags);
868 } 864 }
869 } 865 }
870 int anti_alias = FXFT_RENDER_MODE_MONO; 866 int anti_alias = FXFT_RENDER_MODE_MONO;
871 bool bNormal = false; 867 bool bNormal = false;
872 if ((text_flags & FXTEXT_NOSMOOTH) == 0) { 868 if ((text_flags & FXTEXT_NOSMOOTH) == 0) {
873 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) { 869 if (m_DeviceClass == FXDC_DISPLAY && m_bpp > 1) {
874 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) { 870 if (!CFX_GEModule::Get()->GetFontMgr()->FTLibrarySupportsHinting()) {
875 // Some Freetype implementations (like the one packaged with Fedora) do 871 // Some Freetype implementations (like the one packaged with Fedora) do
876 // not support hinting due to patents 6219025, 6239783, 6307566, 872 // not support hinting due to patents 6219025, 6239783, 6307566,
877 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest 873 // 6225973, 6243070, 6393145, 6421054, 6282327, and 6624828; the latest
(...skipping 10 matching lines...) Expand all
888 884
889 bool bClearType = false; 885 bool bClearType = false;
890 if (pFont->GetFace() || 886 if (pFont->GetFace() ||
891 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) { 887 (pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_CLEARTYPE)) {
892 bClearType = !!(text_flags & FXTEXT_CLEARTYPE); 888 bClearType = !!(text_flags & FXTEXT_CLEARTYPE);
893 } 889 }
894 bNormal = !bClearType; 890 bNormal = !bClearType;
895 } 891 }
896 } 892 }
897 } 893 }
898 if (!pCache)
899 pCache = CFX_GEModule::Get()->GetFontCache();
900 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);
901 CFX_AutoFontCache autoFontCache(pCache, pFont);
902 std::vector<FXTEXT_GLYPHPOS> glyphs(nChars); 894 std::vector<FXTEXT_GLYPHPOS> glyphs(nChars);
903 CFX_Matrix matrixCTM = GetCTM(); 895 CFX_Matrix matrixCTM = GetCTM();
904 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a); 896 FX_FLOAT scale_x = FXSYS_fabs(matrixCTM.a);
905 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d); 897 FX_FLOAT scale_y = FXSYS_fabs(matrixCTM.d);
906 CFX_Matrix deviceCtm = char2device; 898 CFX_Matrix deviceCtm = char2device;
907 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0); 899 deviceCtm.Concat(scale_x, 0, 0, scale_y, 0, 0);
908 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0); 900 text2Device.Concat(scale_x, 0, 0, scale_y, 0, 0);
909 for (size_t i = 0; i < glyphs.size(); ++i) { 901 for (size_t i = 0; i < glyphs.size(); ++i) {
910 FXTEXT_GLYPHPOS& glyph = glyphs[i]; 902 FXTEXT_GLYPHPOS& glyph = glyphs[i];
911 const FXTEXT_CHARPOS& charpos = pCharPos[i]; 903 const FXTEXT_CHARPOS& charpos = pCharPos[i];
912 glyph.m_fOriginX = charpos.m_OriginX; 904 glyph.m_fOriginX = charpos.m_OriginX;
913 glyph.m_fOriginY = charpos.m_OriginY; 905 glyph.m_fOriginY = charpos.m_OriginY;
914 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY); 906 text2Device.Transform(glyph.m_fOriginX, glyph.m_fOriginY);
915 if (anti_alias < FXFT_RENDER_MODE_LCD) 907 if (anti_alias < FXFT_RENDER_MODE_LCD)
916 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); 908 glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX);
917 else 909 else
918 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); 910 glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX);
919 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); 911 glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY);
920 if (charpos.m_bGlyphAdjust) { 912 if (charpos.m_bGlyphAdjust) {
921 CFX_Matrix new_matrix( 913 CFX_Matrix new_matrix(
922 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], 914 charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
923 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); 915 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);
924 new_matrix.Concat(deviceCtm); 916 new_matrix.Concat(deviceCtm);
925 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( 917 glyph.m_pGlyph = pFont->LoadGlyphBitmap(
926 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix, 918 charpos.m_GlyphIndex, charpos.m_bFontStyle, &new_matrix,
927 charpos.m_FontCharWidth, anti_alias, nativetext_flags); 919 charpos.m_FontCharWidth, anti_alias, nativetext_flags);
928 } else { 920 } else {
929 glyph.m_pGlyph = pFaceCache->LoadGlyphBitmap( 921 glyph.m_pGlyph = pFont->LoadGlyphBitmap(
930 pFont, charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm, 922 charpos.m_GlyphIndex, charpos.m_bFontStyle, &deviceCtm,
931 charpos.m_FontCharWidth, anti_alias, nativetext_flags); 923 charpos.m_FontCharWidth, anti_alias, nativetext_flags);
932 } 924 }
933 } 925 }
934 if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1) 926 if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1)
935 AdjustGlyphSpace(&glyphs); 927 AdjustGlyphSpace(&glyphs);
936 928
937 FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias); 929 FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias);
938 if (scale_x > 1 && scale_y > 1) { 930 if (scale_x > 1 && scale_y > 1) {
939 bmp_rect1.left--; 931 bmp_rect1.left--;
940 bmp_rect1.top--; 932 bmp_rect1.top--;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 if (bitmap.IsAlphaMask()) 1033 if (bitmap.IsAlphaMask())
1042 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); 1034 SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color);
1043 else 1035 else
1044 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); 1036 SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top);
1045 return TRUE; 1037 return TRUE;
1046 } 1038 }
1047 1039
1048 FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars, 1040 FX_BOOL CFX_RenderDevice::DrawTextPath(int nChars,
1049 const FXTEXT_CHARPOS* pCharPos, 1041 const FXTEXT_CHARPOS* pCharPos,
1050 CFX_Font* pFont, 1042 CFX_Font* pFont,
1051 CFX_FontCache* pCache,
1052 FX_FLOAT font_size, 1043 FX_FLOAT font_size,
1053 const CFX_Matrix* pText2User, 1044 const CFX_Matrix* pText2User,
1054 const CFX_Matrix* pUser2Device, 1045 const CFX_Matrix* pUser2Device,
1055 const CFX_GraphStateData* pGraphState, 1046 const CFX_GraphStateData* pGraphState,
1056 uint32_t fill_color, 1047 uint32_t fill_color,
1057 FX_ARGB stroke_color, 1048 FX_ARGB stroke_color,
1058 CFX_PathData* pClippingPath, 1049 CFX_PathData* pClippingPath,
1059 int nFlag) { 1050 int nFlag) {
1060 if (!pCache)
1061 pCache = CFX_GEModule::Get()->GetFontCache();
1062 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(pFont);
1063 CFX_AutoFontCache autoFontCache(pCache, pFont);
1064 for (int iChar = 0; iChar < nChars; iChar++) { 1051 for (int iChar = 0; iChar < nChars; iChar++) {
1065 const FXTEXT_CHARPOS& charpos = pCharPos[iChar]; 1052 const FXTEXT_CHARPOS& charpos = pCharPos[iChar];
1066 CFX_Matrix matrix; 1053 CFX_Matrix matrix;
1067 if (charpos.m_bGlyphAdjust) { 1054 if (charpos.m_bGlyphAdjust) {
1068 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], 1055 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
1069 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); 1056 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);
1070 } 1057 }
1071 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, 1058 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX,
1072 charpos.m_OriginY); 1059 charpos.m_OriginY);
1073 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( 1060 const CFX_PathData* pPath =
1074 pFont, charpos.m_GlyphIndex, charpos.m_FontCharWidth); 1061 pFont->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth);
1075 if (!pPath) 1062 if (!pPath)
1076 continue; 1063 continue;
1077 matrix.Concat(*pText2User); 1064 matrix.Concat(*pText2User);
1078 CFX_PathData TransformedPath(*pPath); 1065 CFX_PathData TransformedPath(*pPath);
1079 TransformedPath.Transform(&matrix); 1066 TransformedPath.Transform(&matrix);
1080 if (fill_color || stroke_color) { 1067 if (fill_color || stroke_color) {
1081 int fill_mode = nFlag; 1068 int fill_mode = nFlag;
1082 if (fill_color) 1069 if (fill_color)
1083 fill_mode |= FXFILL_WINDING; 1070 fill_mode |= FXFILL_WINDING;
1084 fill_mode |= FX_FILL_TEXT_MODE; 1071 fill_mode |= FX_FILL_TEXT_MODE;
1085 if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState, 1072 if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState,
1086 fill_color, stroke_color, fill_mode, 1073 fill_color, stroke_color, fill_mode,
1087 FXDIB_BLEND_NORMAL)) { 1074 FXDIB_BLEND_NORMAL)) {
1088 return FALSE; 1075 return FALSE;
1089 } 1076 }
1090 } 1077 }
1091 if (pClippingPath) 1078 if (pClippingPath)
1092 pClippingPath->Append(&TransformedPath, pUser2Device); 1079 pClippingPath->Append(&TransformedPath, pUser2Device);
1093 } 1080 }
1094 return TRUE; 1081 return TRUE;
1095 } 1082 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698