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