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 "xfa/fxfa/xfa_ffwidget.h" | 7 #include "xfa/fxfa/xfa_ffwidget.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 CFX_WideString wsImage; | 1047 CFX_WideString wsImage; |
1048 pImage->GetContent(wsImage); | 1048 pImage->GetContent(wsImage); |
1049 if (wsHref.IsEmpty() && wsImage.IsEmpty()) { | 1049 if (wsHref.IsEmpty() && wsImage.IsEmpty()) { |
1050 return nullptr; | 1050 return nullptr; |
1051 } | 1051 } |
1052 CFX_WideString wsContentType; | 1052 CFX_WideString wsContentType; |
1053 pImage->GetContentType(wsContentType); | 1053 pImage->GetContentType(wsContentType); |
1054 FXCODEC_IMAGE_TYPE type = XFA_GetImageType(wsContentType); | 1054 FXCODEC_IMAGE_TYPE type = XFA_GetImageType(wsContentType); |
1055 CFX_ByteString bsContent; | 1055 CFX_ByteString bsContent; |
1056 uint8_t* pImageBuffer = nullptr; | 1056 uint8_t* pImageBuffer = nullptr; |
1057 IFX_SeekableReadStream* pImageFileRead = nullptr; | 1057 CFX_RetainPtr<IFX_SeekableReadStream> pImageFileRead; |
1058 if (wsImage.GetLength() > 0) { | 1058 if (wsImage.GetLength() > 0) { |
1059 XFA_ATTRIBUTEENUM iEncoding = | 1059 XFA_ATTRIBUTEENUM iEncoding = |
1060 (XFA_ATTRIBUTEENUM)pImage->GetTransferEncoding(); | 1060 (XFA_ATTRIBUTEENUM)pImage->GetTransferEncoding(); |
1061 if (iEncoding == XFA_ATTRIBUTEENUM_Base64) { | 1061 if (iEncoding == XFA_ATTRIBUTEENUM_Base64) { |
1062 CFX_ByteString bsData = wsImage.UTF8Encode(); | 1062 CFX_ByteString bsData = wsImage.UTF8Encode(); |
1063 int32_t iLength = bsData.GetLength(); | 1063 int32_t iLength = bsData.GetLength(); |
1064 pImageBuffer = FX_Alloc(uint8_t, iLength); | 1064 pImageBuffer = FX_Alloc(uint8_t, iLength); |
1065 int32_t iRead = XFA_Base64Decode(bsData.c_str(), pImageBuffer); | 1065 int32_t iRead = XFA_Base64Decode(bsData.c_str(), pImageBuffer); |
1066 if (iRead > 0) { | 1066 if (iRead > 0) { |
1067 pImageFileRead = IFX_MemoryStream::Create(pImageBuffer, iRead); | 1067 pImageFileRead = IFX_MemoryStream::Create(pImageBuffer, iRead); |
(...skipping 17 matching lines...) Expand all Loading... |
1085 pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL); | 1085 pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL); |
1086 } | 1086 } |
1087 if (!pImageFileRead) { | 1087 if (!pImageFileRead) { |
1088 FX_Free(pImageBuffer); | 1088 FX_Free(pImageBuffer); |
1089 return nullptr; | 1089 return nullptr; |
1090 } | 1090 } |
1091 bNameImage = false; | 1091 bNameImage = false; |
1092 CFX_DIBitmap* pBitmap = | 1092 CFX_DIBitmap* pBitmap = |
1093 XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi); | 1093 XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi); |
1094 FX_Free(pImageBuffer); | 1094 FX_Free(pImageBuffer); |
1095 pImageFileRead->Release(); | |
1096 return pBitmap; | 1095 return pBitmap; |
1097 } | 1096 } |
1098 static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, | 1097 static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, |
1099 int32_t iComponents, | 1098 int32_t iComponents, |
1100 int32_t iBitsPerComponent) { | 1099 int32_t iBitsPerComponent) { |
1101 FXDIB_Format dibFormat = FXDIB_Argb; | 1100 FXDIB_Format dibFormat = FXDIB_Argb; |
1102 switch (type) { | 1101 switch (type) { |
1103 case FXCODEC_IMAGE_BMP: | 1102 case FXCODEC_IMAGE_BMP: |
1104 case FXCODEC_IMAGE_JPG: | 1103 case FXCODEC_IMAGE_JPG: |
1105 case FXCODEC_IMAGE_TIF: { | 1104 case FXCODEC_IMAGE_TIF: { |
1106 dibFormat = FXDIB_Rgb32; | 1105 dibFormat = FXDIB_Rgb32; |
1107 int32_t bpp = iComponents * iBitsPerComponent; | 1106 int32_t bpp = iComponents * iBitsPerComponent; |
1108 if (bpp <= 24) { | 1107 if (bpp <= 24) { |
1109 dibFormat = FXDIB_Rgb; | 1108 dibFormat = FXDIB_Rgb; |
1110 } | 1109 } |
1111 } break; | 1110 } break; |
1112 case FXCODEC_IMAGE_PNG: | 1111 case FXCODEC_IMAGE_PNG: |
1113 default: | 1112 default: |
1114 break; | 1113 break; |
1115 } | 1114 } |
1116 return dibFormat; | 1115 return dibFormat; |
1117 } | 1116 } |
1118 CFX_DIBitmap* XFA_LoadImageFromBuffer(IFX_SeekableReadStream* pImageFileRead, | 1117 |
1119 FXCODEC_IMAGE_TYPE type, | 1118 CFX_DIBitmap* XFA_LoadImageFromBuffer( |
1120 int32_t& iImageXDpi, | 1119 const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, |
1121 int32_t& iImageYDpi) { | 1120 FXCODEC_IMAGE_TYPE type, |
| 1121 int32_t& iImageXDpi, |
| 1122 int32_t& iImageYDpi) { |
1122 CFX_GEModule* pGeModule = CFX_GEModule::Get(); | 1123 CFX_GEModule* pGeModule = CFX_GEModule::Get(); |
1123 if (!pGeModule) { | 1124 if (!pGeModule) |
1124 return nullptr; | 1125 return nullptr; |
1125 } | 1126 |
1126 CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); | 1127 CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); |
1127 if (!pCodecMgr) { | 1128 if (!pCodecMgr) |
1128 return nullptr; | 1129 return nullptr; |
1129 } | 1130 |
1130 CFX_DIBAttribute dibAttr; | 1131 CFX_DIBAttribute dibAttr; |
1131 CFX_DIBitmap* pBitmap = nullptr; | 1132 CFX_DIBitmap* pBitmap = nullptr; |
1132 CCodec_ProgressiveDecoder* pProgressiveDecoder = | 1133 CCodec_ProgressiveDecoder* pProgressiveDecoder = |
1133 pCodecMgr->CreateProgressiveDecoder(); | 1134 pCodecMgr->CreateProgressiveDecoder(); |
1134 pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false); | 1135 pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false); |
1135 switch (dibAttr.m_wDPIUnit) { | 1136 switch (dibAttr.m_wDPIUnit) { |
1136 case FXCODEC_RESUNIT_CENTIMETER: | 1137 case FXCODEC_RESUNIT_CENTIMETER: |
1137 dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI * 2.54f); | 1138 dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI * 2.54f); |
1138 dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI * 2.54f); | 1139 dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI * 2.54f); |
1139 break; | 1140 break; |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 } | 2044 } |
2044 XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); | 2045 XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); |
2045 XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); | 2046 XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); |
2046 } | 2047 } |
2047 | 2048 |
2048 CXFA_CalcData::CXFA_CalcData() : m_iRefCount(0) {} | 2049 CXFA_CalcData::CXFA_CalcData() : m_iRefCount(0) {} |
2049 | 2050 |
2050 CXFA_CalcData::~CXFA_CalcData() { | 2051 CXFA_CalcData::~CXFA_CalcData() { |
2051 m_Globals.RemoveAll(); | 2052 m_Globals.RemoveAll(); |
2052 } | 2053 } |
OLD | NEW |