mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef6af5a1ae | |||
| 6e5fe1202e | |||
| 0005b20095 | |||
| 82cdd75365 | |||
| 3410e157e0 | |||
| 92d0edeb48 | |||
| ce397b13f6 | |||
| d197c0da15 | |||
| 0e7a8c1af9 | |||
| a52bcb3205 | |||
| b57bf58068 | |||
| 7be6410a13 | |||
| 1ef73f12a4 | |||
| 9706ca50d5 | |||
| 7fba804f17 | |||
| d4f9eecbba | |||
| 245dfe198a | |||
| d49bed47b6 | |||
| b95065fd70 | |||
| 961bde6723 | |||
| 2261de2884 | |||
| 7bc4ab9655 | |||
| 5e6d2f12d5 | |||
| fb7d20c7e0 | |||
| ba518d7c85 | |||
| a045f57430 | |||
| b10274c65d | |||
| c1e4a2ce33 | |||
| ee091e7ca9 | |||
| 3d814e7b40 | |||
| bb65549dc1 | |||
| 5294089fd0 | |||
| 3ec24e5e39 | |||
| dc44dc5e84 | |||
| cf76de8811 | |||
| 86421d8235 | |||
| 5e77e96e5f |
@ -100,6 +100,7 @@ public:
|
||||
bSectionType = false;
|
||||
bPageNumStart = false;
|
||||
bRtlGutter = false;
|
||||
bGutter = false;
|
||||
}
|
||||
std::wstring Write()
|
||||
{
|
||||
@ -730,10 +731,12 @@ public:
|
||||
{
|
||||
pCStringWriter->WriteString(L"<w:sz w:val=\"" + std::to_wstring(FontSize) + L"\"/>");
|
||||
}
|
||||
if(bFontSizeCs)
|
||||
{
|
||||
if(bFontSizeCs)
|
||||
{
|
||||
if(false == bFontSize)
|
||||
pCStringWriter->WriteString(L"<w:sz w:val=\"" + std::to_wstring(FontSizeCs) + L"\"/>");
|
||||
pCStringWriter->WriteString(L"<w:szCs w:val=\"" + std::to_wstring(FontSizeCs) + L"\"/>");
|
||||
}
|
||||
}
|
||||
if(bHighLight)
|
||||
{
|
||||
docRGB& H = HighLight;
|
||||
|
||||
@ -350,9 +350,10 @@ namespace PPTX
|
||||
{
|
||||
nvGraphicFramePr.toXmlWriter(pWriter);
|
||||
|
||||
if (xfrm.IsInit() && pWriter->m_lDocType != XMLWRITER_DOC_TYPE_DOCX)
|
||||
if (xfrm.IsInit() && (pWriter->m_lDocType != XMLWRITER_DOC_TYPE_DOCX || pWriter->m_lGroupIndex >= 0))
|
||||
{
|
||||
if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_XLSX && pWriter->m_lGroupIndex >= 0) xfrm->m_ns = L"xdr";
|
||||
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_DOCX && pWriter->m_lGroupIndex >= 0) xfrm->m_ns = L"wpg";
|
||||
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_GRAPHICS) xfrm->m_ns = L"a";
|
||||
else if (pWriter->m_lDocType == XMLWRITER_DOC_TYPE_CHART_DRAWING) xfrm->m_ns = L"cdr";
|
||||
|
||||
|
||||
@ -1726,6 +1726,7 @@ bool RtfFieldReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,
|
||||
else if ( "fldinst" == sCommand )
|
||||
{
|
||||
RtfFieldInstPtr oNewFieldInst = RtfFieldInstPtr(new RtfFieldInst());
|
||||
oNewFieldInst->m_oCharProperty = oReader.m_oState->m_oCharProp;
|
||||
|
||||
RtfFieldInstReader oFieldInstReader( *oNewFieldInst );
|
||||
StartSubReader( oFieldInstReader, oDocument, oReader );
|
||||
@ -1740,6 +1741,7 @@ bool RtfFieldReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,
|
||||
else if ( "fldrslt" == sCommand )
|
||||
{
|
||||
RtfFieldInstPtr oNewFieldInst = RtfFieldInstPtr(new RtfFieldInst());
|
||||
oNewFieldInst->m_oCharProperty = oReader.m_oState->m_oCharProp;
|
||||
|
||||
RtfFieldInstReader oFieldInstReader( *oNewFieldInst );
|
||||
StartSubReader( oFieldInstReader, oDocument, oReader );
|
||||
@ -2528,6 +2530,11 @@ bool RtfParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfRead
|
||||
}
|
||||
else if ( "cell" == sCommand || "nestcell" == sCommand )
|
||||
{
|
||||
if (oReader.m_oState->m_oParagraphProp.m_bInTable == PROP_DEF && oReader.m_oState->m_oParagraphProp.m_nItap == PROP_DEF)
|
||||
{//пример п 9 п 12.rtf
|
||||
oReader.m_oState->m_oParagraphProp.m_bInTable = 1;
|
||||
oReader.m_oState->m_oParagraphProp.m_nItap = 1;
|
||||
}
|
||||
if (oReader.m_oState->m_oParagraphProp.m_bInTable == 1 && 0 == oReader.m_oState->m_oParagraphProp.m_nItap )//Платежное_поручение.rtf (ели по другому сбойная строка заменяется параграфами
|
||||
oReader.m_oState->m_oParagraphProp.m_nItap = 1;
|
||||
|
||||
@ -2918,7 +2925,15 @@ bool RtfParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfRead
|
||||
// pNewChar->m_eType = RtfCharSpecial::rsc_chatn;
|
||||
// m_oCurParagraph->AddItem( pNewChar );
|
||||
//}
|
||||
else if ( "chftn" == sCommand )
|
||||
else if ( "chpgn" == sCommand ) //todooo - other special
|
||||
{//header & footer
|
||||
RtfCharSpecialPtr pNewChar ( new RtfCharSpecial() );
|
||||
|
||||
pNewChar->m_oProperty = oReader.m_oState->m_oCharProp;
|
||||
pNewChar->m_eType = RtfCharSpecial::rsc_chpgn;
|
||||
m_oCurParagraph->AddItem( pNewChar );
|
||||
}
|
||||
else if ( "chftn" == sCommand )
|
||||
{
|
||||
if ( 1 == oReader.m_nFootnote )
|
||||
{
|
||||
|
||||
@ -86,7 +86,7 @@ public:
|
||||
if( NULL != oParam.poTableStyle )
|
||||
oNewParagraph->m_oProperty.m_nTableStyle = oParam.poTableStyle->m_nID;
|
||||
oNewParagraph->m_oProperty.m_nItap = oParam.oReader->m_nCurItap;
|
||||
oNewParagraph->m_oProperty.m_bInTable = true;
|
||||
oNewParagraph->m_oProperty.m_bInTable = 1;
|
||||
|
||||
oOutputCell.AddItem( oNewParagraph );
|
||||
}break;
|
||||
|
||||
@ -97,8 +97,8 @@ std::wstring RtfFieldInst::RenderToRtf(RenderParameter oRenderParameter)
|
||||
}
|
||||
std::wstring RtfFieldInst::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* pOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
|
||||
if (m_pTextItems)
|
||||
return m_pTextItems->RenderToOOX(oRenderParameter);
|
||||
@ -145,8 +145,8 @@ std::wstring RtfField::RenderToRtf(RenderParameter oRenderParameter)
|
||||
|
||||
std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* poOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* pOOXWriter = static_cast<OOXWriter*> (oRenderParameter.poWriter);
|
||||
|
||||
std::wstring sResult;
|
||||
|
||||
@ -168,20 +168,20 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
bInsert = true;
|
||||
|
||||
sAuthor = poRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauth);
|
||||
sAuthor = pRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauth);
|
||||
sDate = std::wstring(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttm).c_str());
|
||||
|
||||
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
sResult += L"<w:ins w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(pOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
m_pInsert->m_oCharProperty.m_nRevised = PROP_DEF;
|
||||
}
|
||||
if (m_pInsert->m_oCharProperty.m_nDeleted != PROP_DEF)
|
||||
{
|
||||
bDelete = true;
|
||||
|
||||
sAuthor = poRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauthDel);
|
||||
sAuthor = pRtfDocument->m_oRevisionTable.GetAuthor(m_pInsert->m_oCharProperty.m_nRevauthDel);
|
||||
sDate = std::wstring(RtfUtility::convertDateTime(m_pInsert->m_oCharProperty.m_nRevdttmDel).c_str());
|
||||
|
||||
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(poOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
sResult += L"<w:del w:date=\"" + sDate + L"\" w:author=\"" + sAuthor + L"\" w:id=\"" + std::to_wstring(pOOXWriter->m_nCurTrackChangesId++).c_str() + L"\">";
|
||||
m_pInsert->m_oCharProperty.m_nDeleted = PROP_DEF;
|
||||
}
|
||||
//поверяем на наличие гиперссылки
|
||||
@ -224,7 +224,7 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
RenderParameter oNewParametr = oRenderParameter;
|
||||
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
|
||||
|
||||
std::wstring props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
|
||||
std::wstring props = m_pResult->m_oCharProperty.RenderToOOX(oRenderParameter);
|
||||
if (!props.empty()) props = L"<w:rPr>" + props + L"</w:rPr>";
|
||||
|
||||
//начинаем Field
|
||||
@ -235,6 +235,8 @@ std::wstring RtfField::RenderToOOX(RenderParameter oRenderParameter)
|
||||
sResult += L"</w:r>";
|
||||
//-----------
|
||||
sResult += L"<w:r>";
|
||||
if (!props.empty())
|
||||
sResult += props;
|
||||
|
||||
sResult += L"<w:instrText xml:space=\"preserve\">";
|
||||
|
||||
|
||||
@ -87,8 +87,8 @@ std::wstring RtfParagraph::RenderToRtf(RenderParameter oRenderParameter)
|
||||
|
||||
std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
RtfDocument* poRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* poOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
|
||||
RtfDocument* pRtfDocument = static_cast<RtfDocument*> (oRenderParameter.poDocument);
|
||||
OOXWriter* pOOXWriter = static_cast<OOXWriter*>(oRenderParameter.poWriter);
|
||||
|
||||
std::wstring sResult ;
|
||||
|
||||
@ -134,7 +134,7 @@ std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
|
||||
sResult += L"<w:p";
|
||||
if (oRenderParameter.nType == RENDER_TO_OOX_PARAM_COMMENT)
|
||||
{
|
||||
std::wstring sParaId = XmlUtils::IntToString(++poOOXWriter->m_nextParaId, L"%08X");
|
||||
std::wstring sParaId = XmlUtils::IntToString(++pOOXWriter->m_nextParaId, L"%08X");
|
||||
sResult += L" w14:paraId=\"" + sParaId + L"\" w14:textId=\"" + sParaId + L"\"";
|
||||
}
|
||||
sResult += L"><w:pPr>";
|
||||
@ -145,7 +145,7 @@ std::wstring RtfParagraph::RenderToOOX(RenderParameter oRenderParameter)
|
||||
if ( PROP_DEF != m_oProperty.m_nTableStyle && m_oProperty.m_bInTable > 0)
|
||||
{
|
||||
RtfStylePtr oCurStyle;
|
||||
if( true == poRtfDocument->m_oStyleTable.GetStyle( m_oProperty.m_nTableStyle, oCurStyle ) )
|
||||
if( true == pRtfDocument->m_oStyleTable.GetStyle( m_oProperty.m_nTableStyle, oCurStyle ) )
|
||||
{
|
||||
RtfParagraphStyle* oCurParaStyle = dynamic_cast<RtfParagraphStyle*>(oCurStyle.get());
|
||||
|
||||
|
||||
@ -2948,8 +2948,14 @@ std::wstring RtfTableProperty::RenderToOOX(RenderParameter oRenderParameter)
|
||||
sDefCellMargins += L"<w:bottom w:w=\"" + std::to_wstring(m_nDefCellMarBottom) + L"\" w:type=\"dxa\"/>";
|
||||
if( PROP_DEF != m_nDefCellMarLeft && 3 == m_eDefCellMarLeftUnit )
|
||||
sDefCellMargins += L"<w:left w:w=\"" + std::to_wstring(m_nDefCellMarLeft) + L"\" w:type=\"dxa\"/>";
|
||||
else
|
||||
sDefCellMargins += L"<w:left w:w=\"0\" w:type=\"dxa\"/>";
|
||||
|
||||
if( PROP_DEF != m_nDefCellMarRight && 3 == m_eDefCellMarRightUnit )
|
||||
sDefCellMargins += L"<w:right w:w=\"" + std::to_wstring(m_nDefCellMarRight) + L"\" w:type=\"dxa\"/>";
|
||||
else
|
||||
sDefCellMargins += L"<w:right w:w=\"0\" w:type=\"dxa\"/>";
|
||||
|
||||
if( PROP_DEF != m_nDefCellMarTop && 3 == m_eDefCellMarTopUnit )
|
||||
sDefCellMargins += L"<w:top w:w=\"" + std::to_wstring(m_nDefCellMarTop) + L"\" w:type=\"dxa\"/>";
|
||||
|
||||
@ -3111,7 +3117,7 @@ std::wstring RtfRowProperty::RenderToOOX(RenderParameter oRenderParameter)
|
||||
{
|
||||
switch( m_eWidthEndInvCellUnit )
|
||||
{
|
||||
case mu_Percent: sResult += L"<w:wAfter w:type=\"pct\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"%\"/>"; break;
|
||||
case mu_Percent: sResult += L"<w:wAfter w:type=\"pct\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"\"/>"; break;
|
||||
case mu_Twips: sResult += L"<w:wAfter w:type=\"dxa\" w:w=\"" + std::to_wstring(m_nWidthEndInvCell) + L"\"/>"; break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -270,6 +270,7 @@ public:
|
||||
m_byteShade = oColor.m_byteShade;
|
||||
m_byteTint = oColor.m_byteTint;
|
||||
|
||||
m_bAuto = oColor.m_bAuto;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
|
||||
@ -2,13 +2,16 @@ INCLUDEPATH += $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/include
|
||||
CORE_BOOST_LIBS = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib
|
||||
|
||||
core_windows {
|
||||
BOOST_POSTFIX = vc140
|
||||
core_debug:BOOST_POSTFIX=$$BOOST_POSTFIX-mt-gd-1_58
|
||||
core_release:BOOST_POSTFIX=$$BOOST_POSTFIX-mt-1_58
|
||||
core_win_64:BOOST_POSTFIX = -vc140-mt-x64-1_72
|
||||
core_win_32:BOOST_POSTFIX = -vc140-mt-x32-1_72
|
||||
core_debug {
|
||||
core_win_64:BOOST_POSTFIX = -vc140-mt-gd-x64-1_72
|
||||
core_win_32:BOOST_POSTFIX = -vc140-mt-gd-x32-1_72
|
||||
}
|
||||
|
||||
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -llibboost_system-$$BOOST_POSTFIX -llibboost_filesystem-$$BOOST_POSTFIX
|
||||
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex-$$BOOST_POSTFIX
|
||||
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time-$$BOOST_POSTFIX
|
||||
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -llibboost_system$$BOOST_POSTFIX -llibboost_filesystem$$BOOST_POSTFIX
|
||||
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -llibboost_regex$$BOOST_POSTFIX
|
||||
core_boost_date_time:LIBS += -L$$CORE_BOOST_LIBS -llibboost_date_time$$BOOST_POSTFIX
|
||||
} else {
|
||||
core_boost_libs:LIBS += -L$$CORE_BOOST_LIBS -lboost_system -lboost_filesystem
|
||||
core_boost_regex:LIBS += -L$$CORE_BOOST_LIBS -lboost_regex
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
# iOS simulator.
|
||||
#
|
||||
# To configure the script, define:
|
||||
# BOOST_VERSION: Which version of Boost to build (e.g. 1.58.0)
|
||||
# BOOST_VERSION2: Same as BOOST_VERSION, but with _ instead of . (e.g. 1_58_0)
|
||||
# BOOST_VERSION: Which version of Boost to build (e.g. 1.72.0)
|
||||
# BOOST_VERSION2: Same as BOOST_VERSION, but with _ instead of . (e.g. 1_72_0)
|
||||
# BOOST_LIBS: Which Boost libraries to build
|
||||
# MIN_IOS_VERSION: Minimum iOS Target Version (e.g. 8.0)
|
||||
# IOS_SDK_VERSION: iOS SDK version (e.g. 9.0)
|
||||
@ -24,8 +24,8 @@ BOOST_LIBS="regex"
|
||||
BUILD_IOS=
|
||||
CLEAN=
|
||||
|
||||
BOOST_VERSION=1.58.0
|
||||
BOOST_VERSION2=1_58_0
|
||||
BOOST_VERSION=1.72.0
|
||||
BOOST_VERSION2=1_72_0
|
||||
MIN_IOS_VERSION=8.0
|
||||
IOS_SDK_VERSION=`xcodebuild BITCODE_GENERATION_MODE="bitcode" ENABLE_BITCODE="YES" OTHER_CFLAGS="-fembed-bitcode" -showsdks | grep iphoneos | \
|
||||
egrep "[[:digit:]]+\.[[:digit:]]+" -o | tail -1`
|
||||
|
||||
486
Common/3dParty/openssl/common/common_openssl.cpp
Normal file
486
Common/3dParty/openssl/common/common_openssl.cpp
Normal file
@ -0,0 +1,486 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#include "./common_openssl.h"
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
namespace NSOpenSSL
|
||||
{
|
||||
unsigned char* openssl_alloc(unsigned int len)
|
||||
{
|
||||
return (unsigned char*)malloc(len);
|
||||
}
|
||||
void openssl_free(unsigned char* data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
// hash
|
||||
unsigned int GetHashSize(const int& alg)
|
||||
{
|
||||
switch (alg)
|
||||
{
|
||||
case OPENSSL_HASH_ALG_SHA1:
|
||||
return 20;
|
||||
case OPENSSL_HASH_ALG_SHA224:
|
||||
return 28;
|
||||
case OPENSSL_HASH_ALG_SHA256:
|
||||
return 32;
|
||||
case OPENSSL_HASH_ALG_SHA384:
|
||||
return 48;
|
||||
case OPENSSL_HASH_ALG_SHA512:
|
||||
return 64;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len)
|
||||
{
|
||||
len = GetHashSize(alg);
|
||||
if (0 == len)
|
||||
return NULL;
|
||||
unsigned char* res = openssl_alloc(len);
|
||||
switch (alg)
|
||||
{
|
||||
case OPENSSL_HASH_ALG_SHA1:
|
||||
SHA1(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA224:
|
||||
SHA224(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA256:
|
||||
SHA256(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA384:
|
||||
SHA384(data, (size_t)size, res);
|
||||
break;
|
||||
case OPENSSL_HASH_ALG_SHA512:
|
||||
SHA512(data, (size_t)size, res);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// rsa
|
||||
bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey)
|
||||
{
|
||||
publicKey = NULL;
|
||||
privateKey = NULL;
|
||||
|
||||
RSA* rsa = RSA_new();
|
||||
BIGNUM *exponent = BN_new();
|
||||
|
||||
BN_set_word(exponent, RSA_F4);
|
||||
int result = RSA_generate_multi_prime_key(rsa, 2048, 2, exponent, NULL);
|
||||
if (0 == result)
|
||||
return false;
|
||||
|
||||
if (true)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL))
|
||||
{
|
||||
int key_length = BIO_pending(bio);
|
||||
privateKey = openssl_alloc(key_length + 1);
|
||||
if (key_length != BIO_read(bio, privateKey, key_length))
|
||||
{
|
||||
openssl_free(privateKey);
|
||||
privateKey = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
privateKey[key_length] = '\0';
|
||||
}
|
||||
}
|
||||
BIO_free_all(bio);
|
||||
}
|
||||
if (true)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (PEM_write_bio_RSA_PUBKEY(bio, rsa))
|
||||
{
|
||||
int key_length = BIO_pending(bio);
|
||||
publicKey = openssl_alloc(key_length + 1);
|
||||
if (key_length != BIO_read(bio, publicKey, key_length))
|
||||
{
|
||||
openssl_free(publicKey);
|
||||
publicKey = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
publicKey[key_length] = '\0';
|
||||
}
|
||||
}
|
||||
BIO_free_all(bio);
|
||||
}
|
||||
|
||||
BN_free(exponent);
|
||||
RSA_free(rsa);
|
||||
|
||||
return (NULL != publicKey && NULL != privateKey) ? true : false;
|
||||
}
|
||||
|
||||
//#define USE_DEPRECATED
|
||||
bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len)
|
||||
{
|
||||
BIO* bio = BIO_new_mem_buf(publicKey, (int)strlen((char*)publicKey));
|
||||
|
||||
#ifdef USE_DEPRECATED
|
||||
RSA* rsa = RSA_new();
|
||||
RSA* resrsa = PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, NULL);
|
||||
|
||||
unsigned int key_size = (unsigned int)RSA_size(rsa);
|
||||
data_crypt = openssl_alloc(key_size);
|
||||
|
||||
int res = RSA_public_encrypt((int)size, data, data_crypt, rsa, RSA_NO_PADDING);
|
||||
data_crypt_len = key_size;
|
||||
|
||||
BIO_free(bio);
|
||||
RSA_free(rsa);
|
||||
return (-1 != res) ? true : false;
|
||||
#else
|
||||
EVP_PKEY* publicKeyEngine = NULL;
|
||||
PEM_read_bio_PUBKEY(bio, &publicKeyEngine, 0, NULL);
|
||||
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(publicKeyEngine, NULL);
|
||||
EVP_PKEY_encrypt_init(ctx);
|
||||
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
size_t out_len = 0;
|
||||
EVP_PKEY_encrypt(ctx, NULL, &out_len, data, (size_t)size);
|
||||
|
||||
data_crypt = openssl_alloc((unsigned int)out_len);
|
||||
|
||||
EVP_PKEY_encrypt(ctx, data_crypt, &out_len, data, (size_t)size);
|
||||
data_crypt_len = (unsigned int)out_len;
|
||||
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
EVP_PKEY_free(publicKeyEngine);
|
||||
BIO_free(bio);
|
||||
|
||||
return (out_len > 0) ? true : false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len)
|
||||
{
|
||||
BIO* bio = BIO_new_mem_buf(privateKey, (int)strlen((char*)privateKey));
|
||||
|
||||
#ifdef USE_DEPRECATED
|
||||
RSA* rsa = RSA_new();
|
||||
PEM_read_bio_RSAPrivateKey(bio, &rsa, 0, NULL);
|
||||
|
||||
unsigned int key_size = (unsigned int)RSA_size(rsa);
|
||||
data_decrypt = openssl_alloc(key_size);
|
||||
|
||||
int res = RSA_private_decrypt((int)size, data, data_decrypt, rsa, RSA_NO_PADDING);
|
||||
data_decrypt_len = key_size;
|
||||
|
||||
BIO_free(bio);
|
||||
RSA_free(rsa);
|
||||
return (-1 != res) ? true : false;
|
||||
#else
|
||||
EVP_PKEY* privateKeyEngine = NULL;
|
||||
PEM_read_bio_PrivateKey(bio, &privateKeyEngine, 0, NULL);
|
||||
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(privateKeyEngine, NULL);
|
||||
EVP_PKEY_decrypt_init(ctx);
|
||||
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
size_t out_len = 0;
|
||||
EVP_PKEY_decrypt(ctx, NULL, &out_len, data, (size_t)size);
|
||||
|
||||
data_decrypt = openssl_alloc((unsigned int)out_len);
|
||||
|
||||
EVP_PKEY_decrypt(ctx, data_decrypt, &out_len, data, (size_t)size);
|
||||
data_decrypt_len = (unsigned int)out_len;
|
||||
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
EVP_PKEY_free(privateKeyEngine);
|
||||
BIO_free(bio);
|
||||
|
||||
return (out_len > 0) ? true : false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RSA_EncryptPublic_desktop(const unsigned char* publicKey, const std::string& input, std::string& out)
|
||||
{
|
||||
unsigned char* out_ptr = NULL;
|
||||
unsigned int out_ptr_len = 0;
|
||||
|
||||
if (!RSA_EncryptPublic(publicKey, (unsigned char*)input.c_str(), (unsigned int)input.length(), out_ptr, out_ptr_len))
|
||||
return false;
|
||||
|
||||
out = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_BASE64);
|
||||
openssl_free(out_ptr);
|
||||
return true;
|
||||
}
|
||||
bool RSA_DecryptPrivate_desktop(const unsigned char* privateKey, const std::string& input, std::string& out)
|
||||
{
|
||||
unsigned char* input_ptr = NULL;
|
||||
int input_ptr_len = 0;
|
||||
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str(), (int)input.length(), input_ptr, input_ptr_len);
|
||||
if (!bBase64)
|
||||
return false;
|
||||
|
||||
unsigned char* out_ptr = NULL;
|
||||
unsigned int out_ptr_len = 0;
|
||||
|
||||
if (!RSA_DecryptPrivate(privateKey, input_ptr, (unsigned int)input_ptr_len, out_ptr, out_ptr_len))
|
||||
{
|
||||
openssl_free(input_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
//out = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_ASCII);
|
||||
out = std::string((char*)out_ptr, out_ptr_len);
|
||||
openssl_free(input_ptr);
|
||||
openssl_free(out_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
// pbkdf2
|
||||
const EVP_MD* Get_EVP_MD(int nAlg)
|
||||
{
|
||||
switch (nAlg)
|
||||
{
|
||||
case OPENSSL_HASH_ALG_SHA1:
|
||||
{
|
||||
return EVP_sha1();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA224:
|
||||
{
|
||||
return EVP_sha224();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA256:
|
||||
{
|
||||
return EVP_sha256();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA384:
|
||||
{
|
||||
return EVP_sha384();
|
||||
}
|
||||
case OPENSSL_HASH_ALG_SHA512:
|
||||
{
|
||||
return EVP_sha512();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return EVP_sha1();
|
||||
}
|
||||
unsigned char* PBKDF2(const char* pass, int passlen, const unsigned char* salt, int saltlen, int hash_alg, int key_len)
|
||||
{
|
||||
unsigned char* out = openssl_alloc(key_len);
|
||||
if (0 == PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, 1000, Get_EVP_MD(hash_alg), key_len, out))
|
||||
{
|
||||
openssl_free(out);
|
||||
out = NULL;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
unsigned char* PBKDF2_desktop(const std::string& pass, const std::string& salt)
|
||||
{
|
||||
unsigned char* key_iv = NULL;
|
||||
if (salt.empty())
|
||||
{
|
||||
unsigned int pass_salt_len = 0;
|
||||
unsigned char* pass_salt = NSOpenSSL::GetHash((unsigned char*)pass.c_str(), (unsigned int)pass.length(), OPENSSL_HASH_ALG_SHA512, pass_salt_len);
|
||||
key_iv = PBKDF2(pass.c_str(), (int)pass.length(), pass_salt, pass_salt_len, OPENSSL_HASH_ALG_SHA256, 32 + 16);
|
||||
openssl_free(pass_salt);
|
||||
}
|
||||
else
|
||||
{
|
||||
key_iv = PBKDF2(pass.c_str(), (int)pass.length(), (const unsigned char*)salt.c_str(), (unsigned int)salt.length(), OPENSSL_HASH_ALG_SHA256, 32 + 16);
|
||||
}
|
||||
return key_iv;
|
||||
}
|
||||
|
||||
// aes
|
||||
int AES_GetKeySize(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OPENSSL_AES_256_CBC:
|
||||
return 32;
|
||||
}
|
||||
return 32;
|
||||
}
|
||||
int AES_GetIvSize(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OPENSSL_AES_256_CBC:
|
||||
return 16;
|
||||
}
|
||||
return 16;
|
||||
}
|
||||
|
||||
const EVP_CIPHER* _get_cipher_aes(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OPENSSL_AES_256_CBC:
|
||||
return EVP_aes_256_cbc();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
bool AES_Encrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len)
|
||||
{
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CIPHER_CTX_init(ctx);
|
||||
EVP_EncryptInit_ex(ctx, _get_cipher_aes(type), NULL, key, iv);
|
||||
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL);
|
||||
int out_len1 = (int)size + AES_BLOCK_SIZE;
|
||||
int out_len2 = 0;
|
||||
data_crypt = openssl_alloc(out_len1);
|
||||
EVP_EncryptUpdate(ctx, data_crypt, &out_len1, data, (int)size);
|
||||
EVP_EncryptFinal_ex(ctx, data_crypt + out_len1, &out_len2);
|
||||
data_crypt_len = out_len1 + out_len2;
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
EVP_cleanup();
|
||||
return true;
|
||||
}
|
||||
bool AES_Decrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len)
|
||||
{
|
||||
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CIPHER_CTX_init(ctx);
|
||||
EVP_DecryptInit_ex(ctx, _get_cipher_aes(type), NULL, key, iv);
|
||||
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 16, NULL);
|
||||
int out_len1 = (int)size;
|
||||
int out_len2 = 0;
|
||||
data_decrypt = openssl_alloc(out_len1);
|
||||
EVP_DecryptUpdate(ctx, data_decrypt, &out_len1, data, (int)size);
|
||||
EVP_DecryptFinal_ex(ctx, data_decrypt + out_len1, &out_len2);
|
||||
data_decrypt_len = out_len1 + out_len2;
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
EVP_cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AES_Encrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
|
||||
{
|
||||
unsigned char* key_iv = PBKDF2_desktop(pass, salt);
|
||||
bool bRes = AES_Encrypt_desktop(key_iv, input, output);
|
||||
openssl_free(key_iv);
|
||||
return bRes;
|
||||
}
|
||||
bool AES_Decrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt)
|
||||
{
|
||||
unsigned char* key_iv = PBKDF2_desktop(pass, salt);
|
||||
bool bRes = AES_Decrypt_desktop(key_iv, input, output);
|
||||
openssl_free(key_iv);
|
||||
return bRes;
|
||||
}
|
||||
bool AES_Encrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output)
|
||||
{
|
||||
unsigned char* data_crypt = NULL;
|
||||
unsigned int data_crypt_len = 0;
|
||||
bool bRes = AES_Encrypt(OPENSSL_AES_256_CBC, key_iv, key_iv + 32, (unsigned char*)input.c_str(), (unsigned int)input.length(), data_crypt, data_crypt_len);
|
||||
|
||||
if (!bRes)
|
||||
return false;
|
||||
|
||||
output = Serialize(data_crypt, data_crypt_len, OPENSSL_SERIALIZE_TYPE_BASE64);
|
||||
openssl_free(data_crypt);
|
||||
return true;
|
||||
}
|
||||
bool AES_Decrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output)
|
||||
{
|
||||
unsigned char* input_ptr = NULL;
|
||||
int input_ptr_len = 0;
|
||||
bool bBase64 = NSFile::CBase64Converter::Decode(input.c_str(), (int)input.length(), input_ptr, input_ptr_len);
|
||||
if (!bBase64)
|
||||
return false;
|
||||
|
||||
unsigned char* data_decrypt = NULL;
|
||||
unsigned int data_decrypt_len = 0;
|
||||
bool bRes = AES_Decrypt(OPENSSL_AES_256_CBC, key_iv, key_iv + 32, input_ptr, input_ptr_len, data_decrypt, data_decrypt_len);
|
||||
|
||||
if (!bRes)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(input_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
//output = Serialize(out_ptr, out_ptr_len, OPENSSL_SERIALIZE_TYPE_ASCII);
|
||||
output = std::string((char*)data_decrypt, data_decrypt_len);
|
||||
RELEASEARRAYOBJECTS(input_ptr);
|
||||
openssl_free(data_decrypt);
|
||||
return true;
|
||||
}
|
||||
|
||||
// serialize
|
||||
std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg)
|
||||
{
|
||||
switch (alg)
|
||||
{
|
||||
case OPENSSL_SERIALIZE_TYPE_ASCII:
|
||||
{
|
||||
return std::string((char*)data, size);
|
||||
}
|
||||
case OPENSSL_SERIALIZE_TYPE_HEX:
|
||||
{
|
||||
std::string res;
|
||||
res.reserve(2 * size + 1);
|
||||
char tmp[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
for (unsigned int i = 0; i < size; ++i)
|
||||
{
|
||||
res.append(1, tmp[data[i] >> 4]);
|
||||
res.append(1, tmp[data[i] & 0x0F]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
case OPENSSL_SERIALIZE_TYPE_BASE64:
|
||||
{
|
||||
char* pDataDst = NULL;
|
||||
int nDataDst = 0;
|
||||
NSFile::CBase64Converter::Encode((BYTE*)data, (int)size, pDataDst, nDataDst, NSBase64::B64_BASE64_FLAG_NOCRLF);
|
||||
std::string sBase64((char*)pDataDst, nDataDst);
|
||||
RELEASEARRAYOBJECTS(pDataDst);
|
||||
return sBase64;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
94
Common/3dParty/openssl/common/common_openssl.h
Normal file
94
Common/3dParty/openssl/common/common_openssl.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COMMON_OPENSSL_H
|
||||
#define COMMON_OPENSSL_H
|
||||
|
||||
#define OPENSSL_HASH_ALG_SHA1 0
|
||||
#define OPENSSL_HASH_ALG_INVALID 1
|
||||
#define OPENSSL_HASH_ALG_SHA256 2
|
||||
#define OPENSSL_HASH_ALG_SHA224 3
|
||||
#define OPENSSL_HASH_ALG_SHA384 4
|
||||
#define OPENSSL_HASH_ALG_SHA512 5
|
||||
|
||||
#define OPENSSL_SERIALIZE_TYPE_BASE64 0
|
||||
#define OPENSSL_SERIALIZE_TYPE_HEX 1
|
||||
#define OPENSSL_SERIALIZE_TYPE_ASCII 2
|
||||
|
||||
#define OPENSSL_AES_256_CBC 0
|
||||
|
||||
#include "../../../../DesktopEditor/common/File.h"
|
||||
|
||||
#ifdef COMMON_OPENSSL_BUILDING
|
||||
#define OPENSSL_DECL Q_DECL_EXPORT
|
||||
#else
|
||||
#define OPENSSL_DECL Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
namespace NSOpenSSL
|
||||
{
|
||||
// alloc
|
||||
OPENSSL_DECL unsigned char* openssl_alloc(unsigned int len);
|
||||
OPENSSL_DECL void openssl_free(unsigned char* data);
|
||||
|
||||
// hash
|
||||
OPENSSL_DECL unsigned int GetHashSize(const int& alg);
|
||||
OPENSSL_DECL unsigned char* GetHash(const unsigned char* data, const unsigned int& size, const int& alg, unsigned int& len);
|
||||
|
||||
// rsa
|
||||
OPENSSL_DECL bool RSA_GenerateKeys(unsigned char*& publicKey, unsigned char*& privateKey);
|
||||
OPENSSL_DECL bool RSA_EncryptPublic(const unsigned char* publicKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
OPENSSL_DECL bool RSA_DecryptPrivate(const unsigned char* privateKey, const unsigned char* data, const unsigned int& size, unsigned char*& data_decrypt, unsigned int& data_decrypt_len);
|
||||
|
||||
OPENSSL_DECL bool RSA_EncryptPublic_desktop(const unsigned char* publicKey, const std::string& input, std::string& out);
|
||||
OPENSSL_DECL bool RSA_DecryptPrivate_desktop(const unsigned char* privateKey, const std::string& input, std::string& out);
|
||||
|
||||
// pbkdf2
|
||||
OPENSSL_DECL unsigned char* PBKDF2(const char* pass, int passlen, const unsigned char* salt, int saltlen, int hash_alg, int key_len);
|
||||
OPENSSL_DECL unsigned char* PBKDF2_desktop(const std::string& pass, const std::string& salt = "");
|
||||
|
||||
// aes
|
||||
OPENSSL_DECL int AES_GetKeySize(int type);
|
||||
OPENSSL_DECL int AES_GetIvSize(int type);
|
||||
OPENSSL_DECL bool AES_Encrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
OPENSSL_DECL bool AES_Decrypt(int type, const unsigned char* key, const unsigned char* iv, const unsigned char* data, const unsigned int& size, unsigned char*& data_crypt, unsigned int& data_crypt_len);
|
||||
|
||||
OPENSSL_DECL bool AES_Encrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
|
||||
OPENSSL_DECL bool AES_Decrypt_desktop(const std::string& pass, const std::string& input, std::string& output, const std::string& salt = "");
|
||||
OPENSSL_DECL bool AES_Encrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output);
|
||||
OPENSSL_DECL bool AES_Decrypt_desktop(const unsigned char* key_iv, const std::string& input, std::string& output);
|
||||
|
||||
// serialize
|
||||
OPENSSL_DECL std::string Serialize(const unsigned char* data, const unsigned int& size, const int& alg);
|
||||
}
|
||||
|
||||
#endif // COMMON_OPENSSL_H
|
||||
@ -1,18 +1,14 @@
|
||||
core_linux {
|
||||
OPEN_SSL_PLATFORM=$$CORE_BUILDS_PLATFORM_PREFIX
|
||||
build_xp:OPEN_SSL_PLATFORM=$$join(OPEN_SSL_PLATFORM, OPEN_SSL_PLATFORM, "", "_xp")
|
||||
|
||||
INCLUDEPATH += $$PWD/openssl/include
|
||||
INCLUDEPATH += $$PWD/build/$$OPEN_SSL_PLATFORM/include
|
||||
|
||||
QMAKE_LFLAGS += -fvisibility=hidden
|
||||
LIBS += $$PWD/openssl/libssl.a
|
||||
LIBS += $$PWD/openssl/libcrypto.a
|
||||
|
||||
}
|
||||
|
||||
core_mac {
|
||||
|
||||
INCLUDEPATH += $$PWD/openssl/include
|
||||
|
||||
LIBS += $$PWD/openssl/libssl.a
|
||||
LIBS += $$PWD/openssl/libcrypto.a
|
||||
core_windows:LIBS += -L$$PWD/build/$$OPEN_SSL_PLATFORM/lib -llibcrypto -llibssl
|
||||
!core_windows:LIBS += -L$$PWD/build/$$OPEN_SSL_PLATFORM/lib -lcrypto -lssl
|
||||
|
||||
open_ssl_common {
|
||||
DEFINES += COMMON_OPENSSL_BUILDING
|
||||
|
||||
HEADERS += $$PWD/common/common_openssl.h
|
||||
SOURCES += $$PWD/common/common_openssl.cpp
|
||||
}
|
||||
|
||||
94
Common/3dParty/openssl/test/main.cpp
Normal file
94
Common/3dParty/openssl/test/main.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#include "./../common/common_openssl.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argc;
|
||||
argv;
|
||||
if (true)
|
||||
{
|
||||
std::string sTestHashString = "knoejnrgijwenrgiojwnergjiwnerigjnwerojgnweorigjn";
|
||||
unsigned int data_len = 0;
|
||||
unsigned char* data = NSOpenSSL::GetHash((unsigned char*)sTestHashString.c_str(), (unsigned int)sTestHashString.length(), OPENSSL_HASH_ALG_SHA256, data_len);
|
||||
std::string sResult = NSOpenSSL::Serialize(data, data_len, OPENSSL_SERIALIZE_TYPE_HEX);
|
||||
NSOpenSSL::openssl_free(data);
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
unsigned char* publicKey = NULL;
|
||||
unsigned char* privateKey = NULL;
|
||||
bool bRes = NSOpenSSL::RSA_GenerateKeys(publicKey, privateKey);
|
||||
bRes;
|
||||
|
||||
std::string sPublic((char*)publicKey);
|
||||
std::string sPrivate((char*)privateKey);
|
||||
|
||||
NSOpenSSL::openssl_free(publicKey);
|
||||
NSOpenSSL::openssl_free(privateKey);
|
||||
|
||||
std::string sMessage = "Hello world";
|
||||
|
||||
unsigned char* message_crypt = NULL;
|
||||
unsigned int message_crypt_len = 0;
|
||||
bool bEncrypt = NSOpenSSL::RSA_EncryptPublic((unsigned char*)sPublic.c_str(), (unsigned char*)sMessage.c_str(), (unsigned int)sMessage.length(), message_crypt, message_crypt_len);
|
||||
bEncrypt;
|
||||
|
||||
unsigned char* message_decrypt = NULL;
|
||||
unsigned int message_decrypt_len = 0;
|
||||
|
||||
bool bDecrypt = NSOpenSSL::RSA_DecryptPrivate((unsigned char*)sPrivate.c_str(), message_crypt, message_crypt_len, message_decrypt, message_decrypt_len);
|
||||
bDecrypt;
|
||||
|
||||
std::string sMessageOut((char*)message_decrypt, message_decrypt_len);
|
||||
|
||||
NSOpenSSL::openssl_free(message_crypt);
|
||||
NSOpenSSL::openssl_free(message_decrypt);
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
std::string password = "{PASSWORD}";
|
||||
std::string message = "{MESSAGE}";
|
||||
std::string message_crypted = "";
|
||||
std::string message_decrypted = "";
|
||||
|
||||
NSOpenSSL::AES_Encrypt_desktop(password, message, message_crypted);
|
||||
NSOpenSSL::AES_Decrypt_desktop(password, message_crypted, message_decrypted);
|
||||
|
||||
message;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
28
Common/3dParty/openssl/test/test.pro
Normal file
28
Common/3dParty/openssl/test/test.pro
Normal file
@ -0,0 +1,28 @@
|
||||
QT -= core
|
||||
QT -= gui
|
||||
|
||||
TARGET = test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../../../../../core
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
|
||||
############### destination path ###############
|
||||
DESTDIR = $$PWD_ROOT_DIR/build/$$CORE_BUILDS_PLATFORM_PREFIX
|
||||
################################################
|
||||
|
||||
INCLUDEPATH += $$PWD_ROOT_DIR/../build/$$CORE_BUILDS_PLATFORM_PREFIX/include
|
||||
LIBS += -L$$PWD_ROOT_DIR/../build/$$CORE_BUILDS_PLATFORM_PREFIX/lib -llibcrypto
|
||||
|
||||
core_windows:LIBS += -lws2_32 -lAdvapi32 -lCrypt32 -lUser32
|
||||
|
||||
ADD_DEPENDENCY(kernel)
|
||||
|
||||
HEADERS += $$PWD_ROOT_DIR/../common/common_openssl.h
|
||||
SOURCES += $$PWD_ROOT_DIR/../common/common_openssl.cpp
|
||||
|
||||
SOURCES += main.cpp
|
||||
@ -343,9 +343,7 @@ namespace OOX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CTbl::fromXML(XmlUtils::CXmlLiteReader& oReader)
|
||||
void CTbl::fromXML(XmlUtils::CXmlLiteReader& oReader)
|
||||
{
|
||||
if ( oReader.IsEmptyNode() )
|
||||
return;
|
||||
@ -411,7 +409,13 @@ namespace OOX
|
||||
else if ( _T("w:sdt") == sName )
|
||||
pItem = new CSdt( oReader );
|
||||
else if ( _T("w:tblGrid") == sName )
|
||||
m_oTblGrid = oReader;
|
||||
{
|
||||
if (false == m_oTblGrid.IsInit())
|
||||
{
|
||||
m_oTblGrid = new CTblGrid();
|
||||
}
|
||||
m_oTblGrid->fromXML(oReader);
|
||||
}
|
||||
else if ( _T("w:tblPr") == sName )
|
||||
{
|
||||
pItem = m_oTableProperties = new CTableProperty( oReader );
|
||||
@ -657,7 +661,11 @@ namespace OOX
|
||||
}
|
||||
else if ( _T("w:trPr") == sName )
|
||||
{
|
||||
pItem = m_pTableRowProperties = new CTableRowProperties( oReader );
|
||||
if (!m_pTableRowProperties)
|
||||
{
|
||||
pItem = m_pTableRowProperties = new CTableRowProperties();
|
||||
}
|
||||
m_pTableRowProperties->fromXML(oReader);
|
||||
}
|
||||
|
||||
if ( pItem )
|
||||
@ -872,7 +880,12 @@ namespace OOX
|
||||
pItem = new CTbl( oReader );
|
||||
else if ( _T("w:tcPr") == sName )
|
||||
{
|
||||
pItem = m_pTableCellProperties = new CTableCellProperties( oReader );
|
||||
if (!m_pTableCellProperties)
|
||||
{
|
||||
pItem = m_pTableCellProperties = new CTableCellProperties();
|
||||
}
|
||||
|
||||
m_pTableCellProperties->fromXML(oReader);
|
||||
}
|
||||
|
||||
if ( pItem )
|
||||
@ -905,9 +918,8 @@ namespace OOX
|
||||
|
||||
return sResult;
|
||||
}
|
||||
void CTc::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
|
||||
void CTc::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
|
||||
{
|
||||
// Читаем атрибуты
|
||||
WritingElement_ReadAttributes_Start( oReader )
|
||||
WritingElement_ReadAttributes_ReadSingle( oReader, _T("w:id"), m_sId )
|
||||
WritingElement_ReadAttributes_End( oReader )
|
||||
|
||||
@ -231,13 +231,11 @@ namespace XmlUtils
|
||||
|
||||
double d = 0;
|
||||
#if defined (_WIN32) || defined (_WIN64)
|
||||
swscanf_s(string.c_str(), L"%lf", &d);
|
||||
#elif defined(_IOS) || defined(__ANDROID__)
|
||||
swscanf(string.c_str(), L"%lf", &d);
|
||||
swscanf_s(string.c_str(), L"%lf", &d);
|
||||
#else
|
||||
_stscanf(string.c_str(), L"%lf", &d);
|
||||
swscanf(string.c_str(), L"%lf", &d);
|
||||
#endif
|
||||
return d;
|
||||
return d;
|
||||
}
|
||||
AVSINLINE static float GetFloat (const std::wstring& string)
|
||||
{
|
||||
@ -245,13 +243,11 @@ namespace XmlUtils
|
||||
|
||||
float f = 0;
|
||||
#if defined (_WIN32) || defined (_WIN64)
|
||||
swscanf_s(string.c_str(), L"%f", &f);
|
||||
#elif defined(_IOS) || defined(__ANDROID__)
|
||||
swscanf(string.c_str(), L"%f", &f);
|
||||
swscanf_s(string.c_str(), L"%f", &f);
|
||||
#else
|
||||
_stscanf(string.c_str(), L"%f", &f);
|
||||
swscanf(string.c_str(), L"%f", &f);
|
||||
#endif
|
||||
return f;
|
||||
return f;
|
||||
}
|
||||
AVSINLINE static std::wstring BoolToString (const bool & value)
|
||||
{
|
||||
|
||||
@ -80,14 +80,15 @@ int download_external(const std::wstring& sUrl, const std::wstring& sOutput)
|
||||
|
||||
case 0: // child process
|
||||
{
|
||||
const char* nargs[7];
|
||||
const char* nargs[8];
|
||||
nargs[0] = "/usr/bin/curl";
|
||||
nargs[1] = "--url";
|
||||
nargs[2] = sUrlA.c_str();
|
||||
nargs[3] = "--output";
|
||||
nargs[4] = sOutputA.c_str();
|
||||
nargs[5] = "--silent";
|
||||
nargs[6] = NULL;
|
||||
nargs[6] = "-L";
|
||||
nargs[7] = NULL;
|
||||
|
||||
const char* nenv[3];
|
||||
nenv[0] = "LD_PRELOAD=";
|
||||
|
||||
@ -6,7 +6,7 @@ BUILD_NUMBER = $$(BUILD_NUMBER)
|
||||
!isEmpty(PRODUCT_VERSION){
|
||||
!isEmpty(BUILD_NUMBER){
|
||||
VERSION = $${PRODUCT_VERSION}.$${BUILD_NUMBER}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEFINES += INTVER=$$VERSION
|
||||
@ -67,6 +67,8 @@ isEqual(QT_MAJOR_VERSION, 5) {
|
||||
}
|
||||
}
|
||||
|
||||
DEFINES += INTERNAL_USE_ARRAY_AS_VECTOR
|
||||
|
||||
ios {
|
||||
CONFIG += core_ios
|
||||
DEFINES += _IOS IOS LINUX _LINUX MAC _MAC _XCODE
|
||||
@ -158,7 +160,9 @@ core_windows {
|
||||
|
||||
core_linux {
|
||||
equals(TEMPLATE, app) {
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./:./system
|
||||
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
|
||||
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/system\'"
|
||||
QMAKE_LFLAGS += -Wl,--disable-new-dtags
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,6 +377,7 @@ defineTest(ADD_DEPENDENCY) {
|
||||
isEqual(lib, doctrenderer):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH/xp
|
||||
isEqual(lib, ascdocumentscore):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH/xp
|
||||
isEqual(lib, videoplayer):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH/xp
|
||||
isEqual(lib, ooxmlsignature):CORE_BUILDS_LIBRARIES_PATH_DST=$$CORE_BUILDS_LIBRARIES_PATH/xp
|
||||
}
|
||||
!bundle_dylibs:LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH_DST -l$$lib
|
||||
bundle_dylibs:LIBS += -F$$CORE_BUILDS_LIBRARIES_PATH_DST -framework $$lib
|
||||
|
||||
@ -35,7 +35,9 @@
|
||||
#include "Types.h"
|
||||
#include <string.h>
|
||||
|
||||
#if 0 //__APPLE__
|
||||
#ifdef INTERNAL_USE_ARRAY_AS_VECTOR
|
||||
|
||||
// Use std::vector instead this class
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -87,7 +89,7 @@ public:
|
||||
|
||||
for (int i = 0; i < nAllocSize; i++)
|
||||
Add();
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -137,6 +139,11 @@ public:
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
|
||||
T* GetData()
|
||||
{
|
||||
return m_aT.data();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@ -648,6 +648,8 @@ namespace NSDoctRenderer
|
||||
}
|
||||
void CDocBuilder::SetTmpFolder(const wchar_t* folder)
|
||||
{
|
||||
if (m_pInternal->m_bIsServerSafeVersion)
|
||||
return;
|
||||
m_pInternal->m_sTmpFolder = std::wstring(folder);
|
||||
}
|
||||
void CDocBuilder::CloseFile()
|
||||
@ -907,7 +909,10 @@ namespace NSDoctRenderer
|
||||
else if (sParam == "--cache-scripts")
|
||||
m_pInternal->m_bIsCacheScript = (std::wstring(value) == L"true");
|
||||
else if (sParam == "--save-use-only-names")
|
||||
{
|
||||
m_pInternal->m_bIsServerSafeVersion = true;
|
||||
m_pInternal->m_sFolderForSaveOnlyUseNames = std::wstring(value);
|
||||
}
|
||||
else if (sParam == "--all-fonts-path")
|
||||
{
|
||||
m_pInternal->m_strAllFonts = std::wstring(value);
|
||||
|
||||
@ -186,6 +186,7 @@ namespace NSDoctRenderer
|
||||
|
||||
bool m_bIsCacheScript;
|
||||
|
||||
bool m_bIsServerSafeVersion;
|
||||
std::wstring m_sFolderForSaveOnlyUseNames;
|
||||
|
||||
std::string m_sGlobalVariable;
|
||||
@ -214,6 +215,7 @@ namespace NSDoctRenderer
|
||||
m_bIsGlobalVariableUse = false;
|
||||
|
||||
m_bIsNotUseConfigAllFontsDir = false;
|
||||
m_bIsServerSafeVersion = false;
|
||||
}
|
||||
|
||||
void Init()
|
||||
@ -551,6 +553,10 @@ namespace NSDoctRenderer
|
||||
}
|
||||
#endif
|
||||
|
||||
// не открываем локальные файлы в серверной версии.
|
||||
if (m_bIsServerSafeVersion)
|
||||
return;
|
||||
|
||||
NSFile::CFileBinary::Copy(from, to);
|
||||
}
|
||||
|
||||
|
||||
@ -778,7 +778,7 @@ int CFontList::GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed)
|
||||
}
|
||||
|
||||
CFontListNamePicker CFontList::m_oPicker;
|
||||
int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName, bool bIsUseNamePicker)
|
||||
int CFontList::GetFaceNamePenalty(const std::wstring& sCandName, const std::wstring& sReqName, bool bIsUseNamePicker)
|
||||
{
|
||||
if ( 0 == sReqName.length() )
|
||||
return 0;
|
||||
@ -789,6 +789,9 @@ int CFontList::GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName,
|
||||
if ( sReqName == sCandName )
|
||||
return 0;
|
||||
|
||||
if (CFontListNamePicker::IsEqualsFontsAdvanced(sCandName, sReqName))
|
||||
return 100;
|
||||
|
||||
if ( std::wstring::npos != sReqName.find( sCandName ) || std::wstring::npos != sCandName.find( sReqName ) )
|
||||
{
|
||||
if (m_oPicker.IsLikeFonts(sCandName, sReqName))
|
||||
@ -1010,6 +1013,93 @@ void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory,
|
||||
*pLen = (LONG)(pDataMem - pData);
|
||||
}
|
||||
|
||||
class CFontSelectFormatCorrection
|
||||
{
|
||||
private:
|
||||
std::wstring* m_oldName;
|
||||
INT* m_oldBold;
|
||||
INT* m_oldItalic;
|
||||
|
||||
public:
|
||||
CFontSelectFormatCorrection()
|
||||
{
|
||||
m_oldName = NULL;
|
||||
m_oldBold = NULL;
|
||||
m_oldItalic = NULL;
|
||||
}
|
||||
|
||||
static CFontSelectFormatCorrection* CheckCorrection(NSFonts::CFontSelectFormat& oSelect)
|
||||
{
|
||||
// пробуем "подправить" настройки
|
||||
std::wstring sName = *oSelect.wsName;
|
||||
NSFonts::makeLower(sName);
|
||||
|
||||
INT* oldBold = NULL;
|
||||
INT* oldItalic = NULL;
|
||||
|
||||
bool isCorrect = false;
|
||||
if (std::wstring::npos != sName.find(L"bold"))
|
||||
{
|
||||
isCorrect = true;
|
||||
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = sName.find(L"bold", posn)))
|
||||
sName.erase(posn, 4);
|
||||
|
||||
oldBold = oSelect.bBold;
|
||||
if (!oSelect.bBold)
|
||||
oSelect.bBold = new INT(TRUE);
|
||||
}
|
||||
if (std::wstring::npos != sName.find(L"italic") ||
|
||||
std::wstring::npos != sName.find(L"oblique"))
|
||||
{
|
||||
isCorrect = true;
|
||||
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = sName.find(L"italic", posn)))
|
||||
sName.erase(posn, 6);
|
||||
while (std::wstring::npos != (posn = sName.find(L"oblique", posn)))
|
||||
sName.erase(posn, 7);
|
||||
|
||||
oldItalic = oSelect.bItalic;
|
||||
if (!oSelect.bItalic)
|
||||
oSelect.bItalic = new INT(TRUE);
|
||||
}
|
||||
|
||||
if (!isCorrect)
|
||||
return NULL;
|
||||
|
||||
CFontSelectFormatCorrection* pCorrection = new CFontSelectFormatCorrection();
|
||||
pCorrection->m_oldName = oSelect.wsName;
|
||||
oSelect.wsName = new std::wstring(sName);
|
||||
pCorrection->m_oldBold = oldBold;
|
||||
pCorrection->m_oldItalic = oldItalic;
|
||||
|
||||
return pCorrection;
|
||||
}
|
||||
|
||||
void Restore(NSFonts::CFontSelectFormat& oSelect)
|
||||
{
|
||||
RELEASEOBJECT((oSelect.wsName));
|
||||
oSelect.wsName = m_oldName;
|
||||
|
||||
if (m_oldBold != oSelect.bBold)
|
||||
{
|
||||
RELEASEOBJECT((oSelect.bBold));
|
||||
oSelect.bBold = m_oldBold;
|
||||
}
|
||||
if (m_oldItalic != oSelect.bItalic)
|
||||
{
|
||||
RELEASEOBJECT((oSelect.bItalic));
|
||||
oSelect.bItalic = m_oldItalic;
|
||||
}
|
||||
|
||||
m_oldName = NULL;
|
||||
m_oldBold = NULL;
|
||||
m_oldItalic = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect, bool bIsDictionaryUse)
|
||||
{
|
||||
int nFontsCount = m_pList.size();
|
||||
@ -1026,104 +1116,127 @@ NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect,
|
||||
int nMinPenalty = -1; // Минимальный вес
|
||||
|
||||
int nDefPenalty = 2147483647;
|
||||
|
||||
NSFonts::CFontInfo* pInfoMin = NULL;
|
||||
for (std::vector<NSFonts::CFontInfo*>::iterator iter = m_pList.begin(); iter != m_pList.end(); iter++)
|
||||
{
|
||||
int nCurPenalty = 0;
|
||||
NSFonts::CFontInfo* pInfo = *iter;
|
||||
CFontSelectFormatCorrection* pSelectCorrection = NULL;
|
||||
|
||||
if ( NULL != oSelect.pPanose )
|
||||
{
|
||||
nCurPenalty += GetPanosePenalty( pInfo->m_aPanose, oSelect.pPanose );
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
for (std::vector<NSFonts::CFontInfo*>::iterator iter = m_pList.begin(); iter != m_pList.end(); iter++)
|
||||
{
|
||||
int nCurPenalty = 0;
|
||||
NSFonts::CFontInfo* pInfo = *iter;
|
||||
|
||||
ULONG arrCandRanges[6] = { pInfo->m_ulUnicodeRange1, pInfo->m_ulUnicodeRange2, pInfo->m_ulUnicodeRange3, pInfo->m_ulUnicodeRange4, pInfo->m_ulCodePageRange1, pInfo->m_ulCodePageRange2 };
|
||||
|
||||
if (true)
|
||||
{
|
||||
if (NULL != oSelect.ulRange1 &&
|
||||
NULL != oSelect.ulRange2 &&
|
||||
NULL != oSelect.ulRange3 &&
|
||||
NULL != oSelect.ulRange4 &&
|
||||
NULL != oSelect.ulCodeRange1 &&
|
||||
NULL != oSelect.ulCodeRange2)
|
||||
{
|
||||
ULONG arrReqRanges[6] = { *oSelect.ulRange1, *oSelect.ulRange2, *oSelect.ulRange3, *oSelect.ulRange4, *oSelect.ulCodeRange1, *oSelect.ulCodeRange2 };
|
||||
nCurPenalty += GetSigPenalty( arrCandRanges, arrReqRanges, nCurPenalty >= 1000 ? 50 : 10, 10 );
|
||||
}
|
||||
}
|
||||
if ( NULL != oSelect.pPanose )
|
||||
{
|
||||
nCurPenalty += GetPanosePenalty( pInfo->m_aPanose, oSelect.pPanose );
|
||||
}
|
||||
|
||||
unsigned char unCharset = UNKNOWN_CHARSET;
|
||||
if (NULL != oSelect.unCharset)
|
||||
unCharset = *oSelect.unCharset;
|
||||
ULONG arrCandRanges[6] = { pInfo->m_ulUnicodeRange1, pInfo->m_ulUnicodeRange2, pInfo->m_ulUnicodeRange3, pInfo->m_ulUnicodeRange4, pInfo->m_ulCodePageRange1, pInfo->m_ulCodePageRange2 };
|
||||
|
||||
if ( NULL != oSelect.bFixedWidth )
|
||||
nCurPenalty += GetFixedPitchPenalty( pInfo->m_bIsFixed, *oSelect.bFixedWidth );
|
||||
if (true)
|
||||
{
|
||||
if (NULL != oSelect.ulRange1 &&
|
||||
NULL != oSelect.ulRange2 &&
|
||||
NULL != oSelect.ulRange3 &&
|
||||
NULL != oSelect.ulRange4 &&
|
||||
NULL != oSelect.ulCodeRange1 &&
|
||||
NULL != oSelect.ulCodeRange2)
|
||||
{
|
||||
ULONG arrReqRanges[6] = { *oSelect.ulRange1, *oSelect.ulRange2, *oSelect.ulRange3, *oSelect.ulRange4, *oSelect.ulCodeRange1, *oSelect.ulCodeRange2 };
|
||||
nCurPenalty += GetSigPenalty( arrCandRanges, arrReqRanges, nCurPenalty >= 1000 ? 50 : 10, 10 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( oSelect.wsName != NULL && oSelect.wsAltName != NULL )
|
||||
{
|
||||
nCurPenalty += min( GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true ),
|
||||
GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true ) );
|
||||
}
|
||||
else if ( oSelect.wsName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true );
|
||||
else if ( oSelect.wsAltName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true );
|
||||
unsigned char unCharset = UNKNOWN_CHARSET;
|
||||
if (NULL != oSelect.unCharset)
|
||||
unCharset = *oSelect.unCharset;
|
||||
|
||||
if ( NULL != oSelect.usWidth )
|
||||
nCurPenalty += GetWidthPenalty( pInfo->m_usWidth, *oSelect.usWidth );
|
||||
if ( NULL != oSelect.bFixedWidth )
|
||||
nCurPenalty += GetFixedPitchPenalty( pInfo->m_bIsFixed, *oSelect.bFixedWidth );
|
||||
|
||||
if ( NULL != oSelect.usWeight )
|
||||
nCurPenalty += GetWeightPenalty( pInfo->m_usWeigth, *oSelect.usWeight );
|
||||
if ( oSelect.wsName != NULL && oSelect.wsAltName != NULL )
|
||||
{
|
||||
nCurPenalty += min( GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true ),
|
||||
GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true ) );
|
||||
}
|
||||
else if ( oSelect.wsName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsName, true );
|
||||
else if ( oSelect.wsAltName != NULL )
|
||||
nCurPenalty += GetFaceNamePenalty( pInfo->m_wsFontName, *oSelect.wsAltName, true );
|
||||
|
||||
if ( NULL != oSelect.bBold )
|
||||
nCurPenalty += GetBoldPenalty( pInfo->m_bBold, *oSelect.bBold );
|
||||
if ( NULL != oSelect.usWidth )
|
||||
nCurPenalty += GetWidthPenalty( pInfo->m_usWidth, *oSelect.usWidth );
|
||||
|
||||
if ( NULL != oSelect.bItalic )
|
||||
nCurPenalty += GetItalicPenalty( pInfo->m_bItalic, *oSelect.bItalic );
|
||||
if ( NULL != oSelect.usWeight )
|
||||
nCurPenalty += GetWeightPenalty( pInfo->m_usWeigth, *oSelect.usWeight );
|
||||
|
||||
if ( NULL != oSelect.wsFamilyClass )
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.wsFamilyClass );
|
||||
else if (NULL != oSelect.sFamilyClass)
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.sFamilyClass );
|
||||
|
||||
//nCurPenalty += GetFontFormatPenalty( pInfo->m_eFontFormat, fontTrueType );
|
||||
nCurPenalty += GetCharsetPenalty( arrCandRanges, unCharset );
|
||||
//if ( NULL != oSelect.bBold )
|
||||
// nCurPenalty += GetBoldPenalty( pInfo->m_bBold, *oSelect.bBold );
|
||||
//if ( NULL != oSelect.bItalic )
|
||||
// nCurPenalty += GetItalicPenalty( pInfo->m_bItalic, *oSelect.bItalic );
|
||||
|
||||
if ( NULL != oSelect.shAvgCharWidth )
|
||||
nCurPenalty += GetAvgWidthPenalty( pInfo->m_shAvgCharWidth, *oSelect.shAvgCharWidth );
|
||||
// проверяем всегда!!! иначе только по имени может подобраться болд, и появляется зависимость от порядка шрифтов
|
||||
nCurPenalty += GetBoldPenalty( pInfo->m_bBold, (NULL != oSelect.bBold) ? *oSelect.bBold : FALSE );
|
||||
nCurPenalty += GetItalicPenalty( pInfo->m_bItalic, (NULL != oSelect.bItalic) ? *oSelect.bItalic : FALSE );
|
||||
|
||||
if ( NULL != oSelect.shAscent )
|
||||
nCurPenalty += GetAscentPenalty( pInfo->m_shAscent, *oSelect.shAscent );
|
||||
if ( NULL != oSelect.wsFamilyClass )
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.wsFamilyClass );
|
||||
else if (NULL != oSelect.sFamilyClass)
|
||||
nCurPenalty += GetFamilyUnlikelyPenalty( pInfo->m_sFamilyClass, *oSelect.sFamilyClass );
|
||||
|
||||
if ( NULL != oSelect.shDescent )
|
||||
nCurPenalty += GetDescentPenalty( pInfo->m_shDescent, *oSelect.shDescent );
|
||||
//nCurPenalty += GetFontFormatPenalty( pInfo->m_eFontFormat, fontTrueType );
|
||||
nCurPenalty += GetCharsetPenalty( arrCandRanges, unCharset );
|
||||
|
||||
if ( NULL != oSelect.shLineGap )
|
||||
nCurPenalty += GetLineGapPenalty( pInfo->m_shLineGap, *oSelect.shLineGap );
|
||||
if ( NULL != oSelect.shAvgCharWidth )
|
||||
nCurPenalty += GetAvgWidthPenalty( pInfo->m_shAvgCharWidth, *oSelect.shAvgCharWidth );
|
||||
|
||||
if ( NULL != oSelect.shXHeight )
|
||||
nCurPenalty += GetXHeightPenalty( pInfo->m_shXHeight, *oSelect.shXHeight );
|
||||
if ( NULL != oSelect.shAscent )
|
||||
nCurPenalty += GetAscentPenalty( pInfo->m_shAscent, *oSelect.shAscent );
|
||||
|
||||
if ( NULL != oSelect.shCapHeight )
|
||||
nCurPenalty += GetCapHeightPenalty( pInfo->m_shCapHeight, *oSelect.shCapHeight );
|
||||
if ( NULL != oSelect.shDescent )
|
||||
nCurPenalty += GetDescentPenalty( pInfo->m_shDescent, *oSelect.shDescent );
|
||||
|
||||
if ( nMinPenalty < 0 )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
else if ( nCurPenalty < nMinPenalty )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
if ( NULL != oSelect.shLineGap )
|
||||
nCurPenalty += GetLineGapPenalty( pInfo->m_shLineGap, *oSelect.shLineGap );
|
||||
|
||||
// Нашелся шрифт, удовлетворяющий всем параметрам, дальше искать нет смысла
|
||||
if ( 0 == nCurPenalty )
|
||||
break;
|
||||
}
|
||||
if ( NULL != oSelect.shXHeight )
|
||||
nCurPenalty += GetXHeightPenalty( pInfo->m_shXHeight, *oSelect.shXHeight );
|
||||
|
||||
if ( NULL != oSelect.shCapHeight )
|
||||
nCurPenalty += GetCapHeightPenalty( pInfo->m_shCapHeight, *oSelect.shCapHeight );
|
||||
|
||||
if ( nMinPenalty < 0 )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
else if ( nCurPenalty < nMinPenalty )
|
||||
{
|
||||
pInfoMin = pInfo;
|
||||
nMinPenalty = nCurPenalty;
|
||||
}
|
||||
|
||||
// Нашелся шрифт, удовлетворяющий всем параметрам, дальше искать нет смысла
|
||||
if ( 0 == nCurPenalty )
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == nMinPenalty)
|
||||
break;
|
||||
|
||||
if (NULL == oSelect.wsName || pSelectCorrection)
|
||||
break;
|
||||
|
||||
pSelectCorrection = CFontSelectFormatCorrection::CheckCorrection(oSelect);
|
||||
if (NULL == pSelectCorrection)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pSelectCorrection)
|
||||
{
|
||||
pSelectCorrection->Restore(oSelect);
|
||||
RELEASEOBJECT(pSelectCorrection);
|
||||
}
|
||||
|
||||
return pInfoMin;
|
||||
}
|
||||
|
||||
@ -186,6 +186,17 @@ public:
|
||||
return 1500;
|
||||
}
|
||||
|
||||
return IsEqualsFontsAdvanced(name, req) ? 3000 : 10000;
|
||||
}
|
||||
|
||||
static bool IsEqualsFontsAdvanced(const std::wstring& name, const std::wstring& req)
|
||||
{
|
||||
int lenName = (int)name.length();
|
||||
int lenReq = (int)req.length();
|
||||
|
||||
const wchar_t* pName = name.c_str();
|
||||
const wchar_t* pReq = req.c_str();
|
||||
|
||||
pName = name.c_str();
|
||||
pReq = req.c_str();
|
||||
|
||||
@ -232,7 +243,7 @@ public:
|
||||
delete [] pNameD;
|
||||
delete [] pReqD;
|
||||
|
||||
return bIsEq ? 3000 : 10000;
|
||||
return bIsEq;
|
||||
}
|
||||
};
|
||||
|
||||
@ -273,7 +284,7 @@ private:
|
||||
int GetCharsetPenalty(ULONG ulCandRanges[6], unsigned char unReqCharset);
|
||||
int GetSigPenalty(ULONG ulCandRanges[6], ULONG ulReqRanges[6], double dRangeWeight = 1, double dRangeWeightSuferflouous = 0);
|
||||
int GetFixedPitchPenalty(INT bCandFixed, INT bReqFixed);
|
||||
int GetFaceNamePenalty(std::wstring sCandName, std::wstring sReqName, bool bIsUseNamePicker = false);
|
||||
int GetFaceNamePenalty(const std::wstring& sCandName, const std::wstring& sReqName, bool bIsUseNamePicker = false);
|
||||
int GetFamilyUnlikelyPenalty(SHORT nCandFamilyClass, SHORT nReqFamilyClass);
|
||||
int GetFamilyUnlikelyPenalty(int nCandFamilyClass, std::wstring sReqFamilyClass);
|
||||
int GetWidthPenalty(USHORT usCandWidth, USHORT usReqWidth);
|
||||
|
||||
@ -679,7 +679,7 @@ HRESULT CGraphicsRenderer::CommandDrawTextExCHAR(const LONG& c, const LONG& gid,
|
||||
|
||||
HRESULT CGraphicsRenderer::CommandDrawTextEx(const std::wstring& bsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& x, const double& y, const double& w, const double& h)
|
||||
{
|
||||
if (NULL != pGids)
|
||||
if (NULL != pGids && 0 != nGidsCount && !(1 == nGidsCount && 0 == *pGids))
|
||||
{
|
||||
m_oFont.StringGID = TRUE;
|
||||
if (c_nHyperlinkType == m_lCurrentCommandType)
|
||||
|
||||
@ -19,14 +19,6 @@ include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
ADD_DEPENDENCY(kernel)
|
||||
|
||||
DEFINES -= UNICODE
|
||||
|
||||
core_linux {
|
||||
CONFIG += signature_openssl
|
||||
}
|
||||
core_mac {
|
||||
CONFIG += signature_openssl
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
include/XmlCertificate.h \
|
||||
include/OOXMLSigner.h \
|
||||
@ -51,10 +43,12 @@ HEADERS += \
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lws2_32
|
||||
LIBS += -lUser32
|
||||
|
||||
}
|
||||
|
||||
signature_openssl {
|
||||
!core_windows {
|
||||
|
||||
HEADERS += \
|
||||
src/XmlSigner_openssl.h
|
||||
@ -64,8 +58,6 @@ SOURCES += \
|
||||
|
||||
}
|
||||
|
||||
signature_openssl {
|
||||
|
||||
CONFIG += open_ssl_common
|
||||
include(../../../Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
}
|
||||
build_xp:DESTDIR=$$DESTDIR/xp
|
||||
|
||||
@ -616,7 +616,7 @@ public:
|
||||
|
||||
void RemoveSignature(const std::string& sGuid)
|
||||
{
|
||||
int nCountSignatures = m_arSignatures.size();
|
||||
int nCountSignatures = (int)m_arSignatures.size();
|
||||
if (0 == nCountSignatures)
|
||||
return;
|
||||
|
||||
|
||||
@ -49,6 +49,73 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern char** environ;
|
||||
|
||||
char** linux_environ_get(const std::string& str_library_path = "")
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; environ[i] != NULL; i++)
|
||||
++count;
|
||||
count += 2;
|
||||
|
||||
char** env = new char*[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
env[i] = NULL;
|
||||
|
||||
bool is_ld_library_path = false;
|
||||
for (int i = 0; environ[i] != NULL; i++)
|
||||
{
|
||||
std::string s = environ[i];
|
||||
if (0 == s.find("LD_LIBRARY_PATH"))
|
||||
{
|
||||
s += (":" + str_library_path);
|
||||
is_ld_library_path = true;
|
||||
}
|
||||
env[i] = new char[s.length() + 1];
|
||||
memcpy(env[i], s.c_str(), s.length() * sizeof(char));
|
||||
env[i][s.length()] = '\0';
|
||||
}
|
||||
if (!is_ld_library_path)
|
||||
{
|
||||
int index = count - 2;
|
||||
std::string s = "LD_LIBRARY_PATH=";
|
||||
s += str_library_path;
|
||||
env[index] = new char[s.length() + 1];
|
||||
memcpy(env[index], s.c_str(), s.length() * sizeof(char));
|
||||
env[index][s.length()] = '\0';
|
||||
}
|
||||
return env;
|
||||
}
|
||||
void linux_environ_clear(char** data)
|
||||
{
|
||||
for (int i = 0; data[i] != NULL; i++)
|
||||
delete [] data[i];
|
||||
delete [] data;
|
||||
}
|
||||
void linux_environ_print(char** env)
|
||||
{
|
||||
std::wstring file = NSFile::GetProcessDirectory() + L"/env.log";
|
||||
std::string fileA = U_TO_UTF8(file);
|
||||
for (int i = 0; env[i] != NULL; i++)
|
||||
{
|
||||
FILE* f = fopen(fileA.c_str(), "a+");
|
||||
std::string s = env[i];
|
||||
|
||||
// replace %%
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = s.find("%", posn)))
|
||||
{
|
||||
s.replace(posn, 1, "%%");
|
||||
posn += 2;
|
||||
}
|
||||
|
||||
fprintf(f, s.c_str());
|
||||
fprintf(f, "\n");
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class CHtmlFile_Private
|
||||
@ -432,10 +499,11 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
|
||||
std::string::size_type posLast = sProgramm.find_last_of('/');
|
||||
std::string sProgrammDir = sProgramm.substr(0, posLast);
|
||||
if (std::string::npos != posLast)
|
||||
sLibraryDir = "LD_LIBRARY_PATH=" + sProgrammDir + ":" + sProgrammDir + "/../";
|
||||
sLibraryDir = sProgrammDir + ":" + sProgrammDir + "/../";
|
||||
|
||||
if (!IsLinuxXVFB())
|
||||
{
|
||||
sLibraryDir = "LD_LIBRARY_PATH=" + sLibraryDir;
|
||||
const char* nargs[2];
|
||||
nargs[0] = sXmlA.c_str();
|
||||
nargs[1] = NULL;
|
||||
@ -461,12 +529,17 @@ int CHtmlFile::Convert(const std::vector<std::wstring>& arFiles, const std::wstr
|
||||
nargs[4] = sXmlA.c_str();
|
||||
nargs[5] = NULL;
|
||||
|
||||
/*
|
||||
const char* nenv[4];
|
||||
nenv[0] = sLibraryDir.c_str();
|
||||
nenv[1] = NULL;//"DISPLAY=:99";
|
||||
nenv[2] = NULL;
|
||||
*/
|
||||
|
||||
execve("/usr/bin/xvfb-run", (char * const *)nargs, (char * const *)nenv);
|
||||
char** env = linux_environ_get(sLibraryDir);
|
||||
//linux_environ_print(env);
|
||||
execve("/usr/bin/xvfb-run", (char * const *)nargs, (char * const *)env);
|
||||
linux_environ_clear(env);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +39,8 @@
|
||||
#define SVG_INLINE_MAX_SIZE 500000 // 500Kb
|
||||
#define SVG_TO_RASTER_MIN_SIZE 50000000 // 1Mb
|
||||
|
||||
const long c_nClipType2 = 0x0021; // c_nClipType + 1
|
||||
|
||||
namespace NSHtmlRenderer
|
||||
{
|
||||
#define USE_SIMPLE_GRAPHICS_NOSVG
|
||||
@ -1672,7 +1674,8 @@ namespace NSHtmlRenderer
|
||||
}
|
||||
}
|
||||
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType);
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType2);
|
||||
m_oClipMetafile.WriteLONG(m_lClipMode);
|
||||
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandEnd);
|
||||
}
|
||||
|
||||
@ -1726,7 +1729,8 @@ namespace NSHtmlRenderer
|
||||
}
|
||||
}
|
||||
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType);
|
||||
m_oClipMetafile.WriteLONG(CMetafile::ctEndCommand, c_nClipType2);
|
||||
m_oClipMetafile.WriteLONG(m_lClipMode);
|
||||
m_oClipMetafile.WriteCommandType(CMetafile::ctPathCommandEnd);
|
||||
|
||||
return nRet;
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
|
||||
#include "../../DesktopEditor/graphics/pro/Fonts.h"
|
||||
#include "../../DesktopEditor/graphics/pro/Graphics.h"
|
||||
#include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
|
||||
|
||||
#include "../../PdfReader/PdfReader.h"
|
||||
#include "../../DjVuFile/DjVu.h"
|
||||
@ -77,17 +78,15 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
NSFonts::IApplicationFonts* pFonts = NSFonts::NSApplication::Create();
|
||||
if (true)
|
||||
{
|
||||
pFonts->Initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::wstring> arFiles = pFonts->GetSetupFontFiles();
|
||||
NSDirectory::GetFiles2(L"D:\\GIT\\core-fonts", arFiles, true);
|
||||
pFonts->InitializeFromArrayFiles(arFiles);
|
||||
}
|
||||
CApplicationFontsWorker oWorker;
|
||||
oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
|
||||
//oWorker.m_arAdditionalFolders.push_back(L"D:\\GIT\\core-fonts");
|
||||
oWorker.m_bIsNeedThumbnails = false;
|
||||
|
||||
if (!NSDirectory::Exists(oWorker.m_sDirectory))
|
||||
NSDirectory::CreateDirectory(oWorker.m_sDirectory);
|
||||
|
||||
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
|
||||
|
||||
#ifdef METAFILE_TEST
|
||||
|
||||
|
||||
@ -53,5 +53,8 @@ linux-g++ | linux-g++-64 | linux-g++-32 {
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
SOURCES += ../src/ASCSVGWriter.cpp
|
||||
SOURCES += \
|
||||
../src/ASCSVGWriter.cpp \
|
||||
../../DesktopEditor/fontengine/ApplicationFontsWorker.cpp
|
||||
|
||||
HEADERS += ../include/ASCSVGWriter.h
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "tchar.h"
|
||||
#include "../source/ECMACryptFile.h"
|
||||
#include "../../Common/OfficeFileFormatChecker.h"
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
|
||||
#if defined(_WIN64)
|
||||
#pragma comment(lib, "../../build/bin/icu/win_64/icuuc.lib")
|
||||
@ -25,7 +26,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
ECMACryptFile crypt_file;
|
||||
bool result = false, bDataIntegrity = false;
|
||||
|
||||
std::wstring srcFileName = L"D:\\test\\_crypted\\test-111.docx";
|
||||
std::wstring srcFileName = L"D:\\test\\_bad_86\\crypt_file_test.docx";
|
||||
std::wstring dstFileName = srcFileName + L"-mycrypt.docx";
|
||||
std::wstring dstFileName2 = dstFileName + L".oox";
|
||||
|
||||
@ -39,8 +40,17 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//std::wstring dstFileName1 = srcFileName1 + L".oox";
|
||||
//result = crypt_file.DecryptOfficeFile(srcFileName1, dstFileName1, password, bDataIntegrity);
|
||||
|
||||
result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
||||
result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
||||
//result = crypt_file.EncryptOfficeFile(srcFileName, dstFileName, password, L"123456789");
|
||||
//result = crypt_file.DecryptOfficeFile(dstFileName, dstFileName2, password, bDataIntegrity);
|
||||
|
||||
std::wstring addit_name = L"11111111111111111111111111111";
|
||||
|
||||
std::string addit_info = crypt_file.ReadAdditional(srcFileName, addit_name);
|
||||
|
||||
std::wstring temp = NSFile::CFileBinary::CreateTempFileWithUniqueName(L"", L"asd");
|
||||
|
||||
addit_info += std::string(temp.begin(), temp.end());
|
||||
|
||||
crypt_file.WriteAdditional(srcFileName, addit_name, addit_info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
314
OfficeCryptReader/ooxml_crypt/main.cpp
Normal file
314
OfficeCryptReader/ooxml_crypt/main.cpp
Normal file
@ -0,0 +1,314 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
|
||||
#include "./../source/ECMACryptFile.h"
|
||||
#include "./../../DesktopEditor/common/File.h"
|
||||
#include "./../../Common/3dParty/openssl/common/common_openssl.h"
|
||||
#include <iostream>
|
||||
|
||||
// examples:
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --password=111
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --add={user-id-1}\ndata1
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --remove={user-id-1}
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --remove={user-id-1}\ndata1
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --add={user-id-1}\ndata11
|
||||
// ooxml_crypt --file=D:/cryptor/1.docx --info=
|
||||
|
||||
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int wmain(int argc, wchar_t** argv)
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
#endif
|
||||
{
|
||||
if (argc <= 0)
|
||||
return 0;
|
||||
|
||||
std::wstring file_path;
|
||||
std::wstring password;
|
||||
bool is_print_info = false;
|
||||
bool is_decrypt = false;
|
||||
std::string user;
|
||||
std::wstring user_key_file;
|
||||
|
||||
std::vector<std::string> add_records;
|
||||
std::vector<std::string> remove_records;
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring param(argv[i]);
|
||||
#else
|
||||
std::string paramA(argv[i]);
|
||||
std::wstring param = UTF8_TO_U(paramA);
|
||||
#endif
|
||||
|
||||
std::wstring::size_type len = param.length();
|
||||
if (2 > len)
|
||||
continue;
|
||||
|
||||
const wchar_t* param_str = param.c_str();
|
||||
if (param_str[0] != '-' || param_str[1] != '-')
|
||||
continue;
|
||||
|
||||
std::wstring::size_type pos = param.find('=');
|
||||
if (std::wstring::npos == pos)
|
||||
continue;
|
||||
|
||||
std::wstring key = param.substr(2, pos - 2);
|
||||
std::wstring value = param.substr(pos + 1);
|
||||
|
||||
if (key == L"file")
|
||||
{
|
||||
file_path = value;
|
||||
}
|
||||
else if (key == L"add")
|
||||
{
|
||||
if (!value.empty())
|
||||
{
|
||||
if (value.c_str()[value.length() - 1] == '\n')
|
||||
value = value.substr(0, value.length() - 1);
|
||||
|
||||
string_replace(value, L";;;", L"\n");
|
||||
add_records.push_back(U_TO_UTF8(value));
|
||||
}
|
||||
}
|
||||
else if (key == L"remove")
|
||||
{
|
||||
if (!value.empty())
|
||||
{
|
||||
if (value.c_str()[value.length() - 1] == '\n')
|
||||
value = value.substr(0, value.length() - 1);
|
||||
string_replace(value, L";;;", L"\n");
|
||||
remove_records.push_back(U_TO_UTF8(value));
|
||||
}
|
||||
}
|
||||
else if (key == L"password")
|
||||
{
|
||||
password = value;
|
||||
}
|
||||
else if (key == L"info")
|
||||
{
|
||||
is_print_info = true;
|
||||
}
|
||||
else if (key == L"decrypt")
|
||||
{
|
||||
is_decrypt = true;
|
||||
}
|
||||
else if (key == L"user")
|
||||
{
|
||||
user = U_TO_UTF8(value);
|
||||
}
|
||||
else if (key == L"key")
|
||||
{
|
||||
user_key_file = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_path.empty() || !NSFile::CFileBinary::Exists(file_path))
|
||||
{
|
||||
std::cout << "error: file not exist" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!password.empty())
|
||||
{
|
||||
// encrypt file
|
||||
ECMACryptFile file;
|
||||
bool result = file.EncryptOfficeFile(file_path, file_path, password);
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "error: file is not encrypted" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
ECMACryptFile file;
|
||||
std::string docinfo = file.ReadAdditional(file_path, L"DocumentID");
|
||||
|
||||
if (is_print_info)
|
||||
{
|
||||
std::cout << docinfo << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* doc_info_str = docinfo.c_str();
|
||||
const char* doc_info_str_end = doc_info_str + docinfo.length();
|
||||
|
||||
if (is_decrypt)
|
||||
{
|
||||
std::string encrypted_password = "";
|
||||
|
||||
// находим нужную запись
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
const char* rec_start = doc_info_str;
|
||||
|
||||
// 1) ищем старт записи
|
||||
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
|
||||
++doc_info_str;
|
||||
|
||||
if (user == std::string(rec_start, doc_info_str - rec_start))
|
||||
{
|
||||
rec_start = doc_info_str;
|
||||
|
||||
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
|
||||
++doc_info_str;
|
||||
|
||||
encrypted_password = std::string(rec_start, doc_info_str - rec_start);
|
||||
}
|
||||
|
||||
// идем в конец записи
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
if (*doc_info_str++ == '\n')
|
||||
{
|
||||
if (*doc_info_str == '\n')
|
||||
{
|
||||
++doc_info_str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string private_key_content;
|
||||
NSFile::CFileBinary::ReadAllTextUtf8A(user_key_file, private_key_content);
|
||||
|
||||
std::string passwordA;
|
||||
NSOpenSSL::RSA_DecryptPrivate_desktop((unsigned char*)private_key_content.c_str(), encrypted_password, passwordA);
|
||||
std::wstring password = UTF8_TO_U(passwordA);
|
||||
|
||||
// encrypt file
|
||||
ECMACryptFile file;
|
||||
bool bDataIntegrity;
|
||||
bool result = file.DecryptOfficeFile(file_path, file_path, password, bDataIntegrity);
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "error: file is not decrypted" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::string sResult = "";
|
||||
sResult.reserve(1000);
|
||||
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
const char* rec_start = doc_info_str;
|
||||
|
||||
// 1) ищем старт записи
|
||||
while (doc_info_str < doc_info_str_end && *doc_info_str != '\n')
|
||||
++doc_info_str;
|
||||
|
||||
std::string::size_type len_first = doc_info_str - rec_start;
|
||||
|
||||
// 2) ищем конец записи
|
||||
while (doc_info_str < doc_info_str_end)
|
||||
{
|
||||
if (*doc_info_str++ == '\n')
|
||||
{
|
||||
if (*doc_info_str == '\n')
|
||||
{
|
||||
++doc_info_str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isAdd = true;
|
||||
std::string sRec = std::string(rec_start, (doc_info_str - rec_start - 2));
|
||||
|
||||
// 3) проверяем запись на удаление
|
||||
for (std::vector<std::string>::iterator iter = remove_records.begin(); iter != remove_records.end(); iter++)
|
||||
{
|
||||
if (*iter == std::string(rec_start, len_first))
|
||||
{
|
||||
isAdd = false;
|
||||
}
|
||||
else if (*iter == sRec)
|
||||
{
|
||||
isAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 4) проверяем запись на удаление
|
||||
for (std::vector<std::string>::iterator iter = add_records.begin(); iter != add_records.end(); iter++)
|
||||
{
|
||||
if (*iter == sRec)
|
||||
{
|
||||
isAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isAdd)
|
||||
{
|
||||
sResult += sRec;
|
||||
sResult += "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::iterator iter = add_records.begin(); iter != add_records.end(); iter++)
|
||||
{
|
||||
sResult += *iter;
|
||||
sResult += "\n\n";
|
||||
}
|
||||
|
||||
bool result = file.WriteAdditional(file_path, L"DocumentID", sResult);
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "error: docinfo not writed" << std::endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
OfficeCryptReader/ooxml_crypt/ooxml_crypt.pro
Normal file
56
OfficeCryptReader/ooxml_crypt/ooxml_crypt.pro
Normal file
@ -0,0 +1,56 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
TARGET = ooxml_crypt
|
||||
CORE_ROOT_DIR = $$PWD/../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
|
||||
CONFIG += core_static_link_libstd
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
|
||||
|
||||
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib
|
||||
ADD_DEPENDENCY(kernel)
|
||||
|
||||
CONFIG += open_ssl_common
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
DEFINES += CRYPTOPP_DISABLE_ASM
|
||||
DESTDIR = $$CORE_BUILDS_BINARY_PATH
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/../source/ECMACryptFile.h \
|
||||
$$PWD/../source/CryptTransform.h \
|
||||
$$PWD/../source/simple_xml_writer.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/../source/ECMACryptFile.cpp \
|
||||
$$PWD/../source/CryptTransform.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$CORE_ROOT_DIR/Common/OfficeFileFormatChecker2.cpp \
|
||||
$$CORE_ROOT_DIR/Common/3dParty/pole/pole.cpp \
|
||||
$$CORE_ROOT_DIR/Common/DocxFormat/Source/Base/unicode_util.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/main.cpp
|
||||
|
||||
core_windows {
|
||||
DEFINES -= UNICODE
|
||||
DEFINES -= _DEBUG
|
||||
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lShell32
|
||||
LIBS += -lGdi32
|
||||
LIBS += -lUser32
|
||||
LIBS += -lcrypt32
|
||||
LIBS += -lcryptui
|
||||
LIBS += -lws2_32
|
||||
}
|
||||
|
||||
core_linux {
|
||||
LIBS += -lz -pthread
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./
|
||||
}
|
||||
@ -976,3 +976,56 @@ bool ECMACryptFile::DecryptOfficeFile(const std::wstring &file_name_inp, const s
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ECMACryptFile::ReadAdditional(const std::wstring &file_name, const std::wstring &addit_name)
|
||||
{
|
||||
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||
|
||||
if (!pStorage->open(false, false))
|
||||
{
|
||||
delete pStorage;
|
||||
return "";
|
||||
}
|
||||
std::string result;
|
||||
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name);
|
||||
if ((pStream) && (pStream->size() > 0))
|
||||
{
|
||||
_UINT64 lengthData, size = pStream->size();
|
||||
|
||||
char* data = new char[size];
|
||||
|
||||
lengthData = pStream->read((unsigned char*)data, size);
|
||||
|
||||
result = std::string(data, lengthData);
|
||||
delete []data;
|
||||
delete pStream;
|
||||
}
|
||||
delete pStorage;
|
||||
|
||||
return result;
|
||||
}
|
||||
bool ECMACryptFile::WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info)
|
||||
{
|
||||
POLE::Storage *pStorage = new POLE::Storage(file_name.c_str());
|
||||
|
||||
if (!pStorage)return false;
|
||||
|
||||
if (!pStorage->open(true, false))
|
||||
{
|
||||
delete pStorage;
|
||||
return false;
|
||||
}
|
||||
|
||||
POLE::Stream *pStream = new POLE::Stream(pStorage, addit_name, true, addit_info.size());
|
||||
|
||||
pStream->write((unsigned char*)addit_info.c_str(), addit_info.size());
|
||||
pStream->setSize(addit_info.size());
|
||||
|
||||
pStream->flush();
|
||||
delete pStream;
|
||||
|
||||
pStorage->close();
|
||||
delete pStorage;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,6 +40,9 @@ public:
|
||||
bool DecryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, bool & bDataIntegrity);
|
||||
bool EncryptOfficeFile(const std::wstring &file_name_inp, const std::wstring &file_name_out, const std::wstring &password, const std::wstring &documentID = L"");
|
||||
|
||||
std::string ReadAdditional(const std::wstring &file_name, const std::wstring &addit_name);
|
||||
bool WriteAdditional(const std::wstring &file_name, const std::wstring &addit_name, const std::string &addit_info);
|
||||
|
||||
struct _refComponent
|
||||
{
|
||||
int type;
|
||||
@ -50,5 +53,5 @@ public:
|
||||
std::vector<_refComponent> refComponents;
|
||||
std::wstring dataSpaceName;
|
||||
};
|
||||
std::vector<_mapEntry> mapEntries;
|
||||
std::vector<_mapEntry> mapEntries;
|
||||
};
|
||||
|
||||
@ -613,6 +613,7 @@ namespace PdfReader
|
||||
|
||||
std::wstring wsTempFileName = L"";
|
||||
Ref oEmbRef;
|
||||
bool bFontSubstitution = false;
|
||||
// 1. Если шрифт внедренный, тогда скидываем его в темповый файл.
|
||||
// 2. Если шрифт лежит вне пдф, а в самом пдф есть ссылка на него, тогда используем эту ссылку.
|
||||
// 3. В противном случае подбираем шрифт.
|
||||
@ -1018,6 +1019,8 @@ namespace PdfReader
|
||||
{
|
||||
wsFileName = pFontInfo->m_wsFontPath;
|
||||
eFontType = pFont->IsCIDFont() ? fontCIDType2 : fontTrueType;
|
||||
|
||||
bFontSubstitution = true;
|
||||
}
|
||||
else // В крайнем случае, в данном шрифте просто не пишем ничего
|
||||
{
|
||||
@ -1274,12 +1277,11 @@ namespace PdfReader
|
||||
case fontCIDType2OT:
|
||||
{
|
||||
// Создаем карту CID-to-GID
|
||||
// Если у нас есть мап ToUnicode, тогда на основе его читаем из файла гиды по юникодным значениям,
|
||||
// если не нашли, но у нас есть мап CIDtoGID, тогда строим по последнему.
|
||||
|
||||
// Если у нас шрифт был не встроен и подбирался и есть мап ToUnicode, тогда на основе его читаем из файла гиды по юникодным значениям.
|
||||
// Для встроенных шрифтов используем мап CIDtoGID
|
||||
pCodeToGID = NULL;
|
||||
nLen = 0;
|
||||
if (L"" != wsFileName)
|
||||
if (L"" != wsFileName && bFontSubstitution)
|
||||
{
|
||||
CharCodeToUnicode *pCodeToUnicode = NULL;
|
||||
if ((pCodeToUnicode = ((GrCIDFont *)pFont)->GetToUnicode()))
|
||||
@ -1316,7 +1318,7 @@ namespace PdfReader
|
||||
}
|
||||
else
|
||||
{
|
||||
pCodeToGID[nCode] = nCode;
|
||||
pCodeToGID[nCode] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1326,8 +1328,7 @@ namespace PdfReader
|
||||
pCodeToUnicode->Release();
|
||||
}
|
||||
}
|
||||
|
||||
if (!pCodeToGID && ((GrCIDFont *)pFont)->GetCIDToGID())
|
||||
else if (((GrCIDFont *)pFont)->GetCIDToGID())
|
||||
{
|
||||
nLen = ((GrCIDFont *)pFont)->GetCIDToGIDLen();
|
||||
pCodeToGID = (unsigned short *)MemUtilsMallocArray(nLen, sizeof(unsigned short));
|
||||
@ -3262,10 +3263,12 @@ namespace PdfReader
|
||||
Aggplus::CImage oImage;
|
||||
oImage.Create(pBufferPtr, nWidth, nHeight, -4 * nWidth);
|
||||
|
||||
// Пишем данные в pBufferPtr
|
||||
ImageStream *pImageStream = new ImageStream(pStream, nWidth, pColorMap->GetComponentsCount(), pColorMap->GetBitsPerComponent());
|
||||
int nComponentsCount = pColorMap->GetComponentsCount();
|
||||
|
||||
pImageStream->Reset();
|
||||
// Пишем данные в pBufferPtr
|
||||
ImageStream *pImageStream = new ImageStream(pStream, nWidth, nComponentsCount, pColorMap->GetBitsPerComponent());
|
||||
|
||||
pImageStream->Reset();
|
||||
|
||||
unsigned char unAlpha = m_bTransparentGroup ? 255.0 * pGState->GetFillOpacity() : 255;
|
||||
|
||||
@ -3276,12 +3279,29 @@ namespace PdfReader
|
||||
{
|
||||
int nIndex = 4 * (nX + nY * nWidth);
|
||||
pImageStream->GetPixel(unPixel);
|
||||
|
||||
GrRGB oRGB;
|
||||
pColorMap->GetRGB(unPixel, &oRGB);
|
||||
pBufferPtr[nIndex + 0] = ColorToByte(oRGB.b);
|
||||
pBufferPtr[nIndex + 1] = ColorToByte(oRGB.g);
|
||||
pBufferPtr[nIndex + 2] = ColorToByte(oRGB.r);
|
||||
pBufferPtr[nIndex + 3] = unAlpha;
|
||||
|
||||
if (pMaskColors)
|
||||
{
|
||||
bool isMask = true;
|
||||
for (int nCompIndex = 0; nCompIndex < nComponentsCount; ++nCompIndex)
|
||||
{
|
||||
if (pMaskColors[nCompIndex * 2] > unPixel[nCompIndex] || unPixel[nCompIndex] > pMaskColors[nCompIndex * 2 + 1])
|
||||
{
|
||||
isMask = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMask)
|
||||
pBufferPtr[nIndex + 3] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -503,7 +503,7 @@ CPdfRenderer::CPdfRenderer(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) :
|
||||
return;
|
||||
}
|
||||
|
||||
m_pDocument->SetCompressionMode(COMP_ALL);
|
||||
m_pDocument->SetCompressionMode(COMP_ALL);
|
||||
|
||||
m_bValid = true;
|
||||
m_dPageHeight = 297;
|
||||
@ -1864,32 +1864,32 @@ void CPdfRenderer::UpdateBrush()
|
||||
double dL, dR, dT, dB;
|
||||
m_oPath.GetBounds(dL, dT, dR, dB);
|
||||
|
||||
double dXStepSpacing = 0, dYStepSpacing = 0;
|
||||
if (c_BrushTextureModeStretch == lTextureMode)
|
||||
{
|
||||
// Чтобы избавиться от погрешностей из-за которых могут возникать полоски, немного увеличим границы пата.
|
||||
dL -= 1;
|
||||
dT -= 1;
|
||||
dB += 1;
|
||||
dR += 1;
|
||||
|
||||
// Растягиваем картинку по размерам пата
|
||||
dW = std::max(10.0, dR - dL);
|
||||
dH = std::max(10.0, dB - dT);
|
||||
dW = std::max(10.0, dR - dL);
|
||||
dH = std::max(10.0, dB - dT);
|
||||
|
||||
// Чтобы избавиться от погрешностей из-за которых могут возникать полоски или обрезание картинки,
|
||||
// удвоим расстрояние между соседними тайлами. Плохого тут нет, т.к. нам нужен всего 1 тайл
|
||||
dXStepSpacing = dW;
|
||||
dYStepSpacing = dH;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Размеры картинки заданы в пикселях. Размеры тайла - это размеры картинки в пунктах.
|
||||
dW = nImageW * 72 / 96;
|
||||
dH = nImageH * 72 / 96;
|
||||
}
|
||||
}
|
||||
|
||||
// Нам нужно, чтобы левый нижний угол границ нашего пата являлся точкой переноса для матрицы преобразования.
|
||||
CMatrix* pMatrix = m_pPage->GetTransform();
|
||||
pMatrix->Apply(dL, dB);
|
||||
pMatrix->Apply(dL, dT);
|
||||
CMatrix oPatternMatrix = *pMatrix;
|
||||
oPatternMatrix.x = dL;
|
||||
oPatternMatrix.y = dB;
|
||||
m_pPage->SetPatternColorSpace(m_pDocument->CreateImageTilePattern(dW, dH, pImage, &oPatternMatrix));
|
||||
oPatternMatrix.y = dT;
|
||||
m_pPage->SetPatternColorSpace(m_pDocument->CreateImageTilePattern(dW, dH, pImage, &oPatternMatrix, imagetilepatterntype_Default, dXStepSpacing, dYStepSpacing));
|
||||
}
|
||||
}
|
||||
else if (c_BrushTypeHatch1 == lBrushType)
|
||||
|
||||
@ -744,9 +744,9 @@ namespace PdfWriter
|
||||
|
||||
return pShading;
|
||||
}
|
||||
CImageTilePattern*CDocument::CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType)
|
||||
CImageTilePattern*CDocument::CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType, double dXStepSpacing, double dYStepSpacing)
|
||||
{
|
||||
return new CImageTilePattern(m_pXref, dW, dH, pImageDict, pMatrix, eType);
|
||||
return new CImageTilePattern(m_pXref, dW, dH, pImageDict, pMatrix, eType, dXStepSpacing, dYStepSpacing);
|
||||
}
|
||||
CImageTilePattern*CDocument::CreateHatchPattern(double dW, double dH, const BYTE& nR1, const BYTE& nG1, const BYTE& nB1, const BYTE& nAlpha1, const BYTE& nR2, const BYTE& nG2, const BYTE& nB2, const BYTE& nAlpha2, const std::wstring& wsHatch)
|
||||
{
|
||||
|
||||
@ -117,7 +117,7 @@ namespace PdfWriter
|
||||
CFont14* CreateFont14(EStandard14Fonts eType);
|
||||
CFontCidTrueType* CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex);
|
||||
|
||||
CImageTilePattern*CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default);
|
||||
CImageTilePattern*CreateImageTilePattern(double dW, double dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default, double dXStepSpacing = 0, double dYStepSpacing = 0);
|
||||
CImageTilePattern*CreateHatchPattern(double dW, double dH, const BYTE& nR1, const BYTE& nG1, const BYTE& nB1, const BYTE& nAlpha1, const BYTE& nR2, const BYTE& nG2, const BYTE& nB2, const BYTE& nAlpha2, const std::wstring& wsHatch);
|
||||
CShading* CreateAxialShading(CPage* pPage, double dX0, double dY0, double dX1, double dY1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
|
||||
CShading* CreateRadialShading(CPage* pPage, double dX0, double dY0, double dR0, double dX1, double dY1, double dR1, unsigned char* pColors, unsigned char* pAlphas, double* pPoints, int nCount, CExtGrState*& pExtGrState);
|
||||
|
||||
@ -44,7 +44,7 @@ namespace PdfWriter
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CImageTilePattern
|
||||
//----------------------------------------------------------------------------------------
|
||||
CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType) : CPattern(pXref)
|
||||
CImageTilePattern::CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix, EImageTilePatternType eType, double dXStepSpacing, double dYStepSpacing) : CPattern(pXref)
|
||||
{
|
||||
Add("Type", "Pattern");
|
||||
Add("PatternType", 1);
|
||||
@ -84,9 +84,13 @@ namespace PdfWriter
|
||||
|
||||
if (imagetilepatterntype_Default == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, dW, dH));
|
||||
Add("XStep", dW);
|
||||
Add("YStep", dH);
|
||||
if (dXStepSpacing > 0.01 && dYStepSpacing > 0.01)
|
||||
Add("BBox", CArrayObject::CreateBox(-dXStepSpacing / 2, -dYStepSpacing / 2, dW + dXStepSpacing / 2, dH + dYStepSpacing / 2));
|
||||
else
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, dW, dH));
|
||||
|
||||
Add("XStep", dW + dXStepSpacing);
|
||||
Add("YStep", dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteReal(dW);
|
||||
pStream->WriteStr(" 0 0 ");
|
||||
@ -97,8 +101,8 @@ namespace PdfWriter
|
||||
else if (imagetilepatterntype_InverseX == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, 2 * dW, dH));
|
||||
Add("XStep", 2 * dW);
|
||||
Add("YStep", dH);
|
||||
Add("XStep", 2 * dW + dXStepSpacing);
|
||||
Add("YStep", dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteStr("q\12");
|
||||
pStream->WriteReal(dW);
|
||||
@ -119,8 +123,8 @@ namespace PdfWriter
|
||||
else if (imagetilepatterntype_InverseY == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, dW, 2 * dH));
|
||||
Add("XStep", dW);
|
||||
Add("YStep", 2 * dH);
|
||||
Add("XStep", dW + dXStepSpacing);
|
||||
Add("YStep", 2 * dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteStr("q\12");
|
||||
pStream->WriteReal(dW);
|
||||
@ -141,8 +145,8 @@ namespace PdfWriter
|
||||
else if (imagetilepatterntype_InverseXY == eType)
|
||||
{
|
||||
Add("BBox", CArrayObject::CreateBox(0, 0, 2 * dW, 2 * dH));
|
||||
Add("XStep", 2 * dW);
|
||||
Add("YStep", 2 * dH);
|
||||
Add("XStep", 2 * dW + dXStepSpacing);
|
||||
Add("YStep", 2 * dH + dYStepSpacing);
|
||||
|
||||
pStream->WriteStr("q\12");
|
||||
pStream->WriteReal(dW);
|
||||
@ -183,4 +187,4 @@ namespace PdfWriter
|
||||
pStream->WriteStr("/X1 Do\12");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ namespace PdfWriter
|
||||
class CImageTilePattern : public CPattern
|
||||
{
|
||||
public:
|
||||
CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default);
|
||||
CImageTilePattern(CXref* pXref, const double& dW, const double& dH, CImageDict* pImageDict, CMatrix* pMatrix = NULL, EImageTilePatternType eType = imagetilepatterntype_Default, double dXStepSpacing = 0, double dYStepSpacing = 0);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _PDF_WRITER_SRC_PATTERN_H
|
||||
#endif // _PDF_WRITER_SRC_PATTERN_H
|
||||
|
||||
@ -15,8 +15,9 @@ include(../Common/base.pri)
|
||||
|
||||
DEFINES += UNICODECONVERTER_USE_DYNAMIC_LIBRARY
|
||||
|
||||
core_linux {
|
||||
QMAKE_LFLAGS += -Wl,--rpath=./
|
||||
core_linux {
|
||||
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
|
||||
QMAKE_LFLAGS += -Wl,--disable-new-dtags
|
||||
}
|
||||
|
||||
core_ios {
|
||||
|
||||
@ -329,10 +329,13 @@ namespace CSVReader
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto oEncodindId = std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
|
||||
|
||||
#ifdef __ANDROID__
|
||||
const auto oEncodindId = *std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
|
||||
#else
|
||||
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
|
||||
#endif
|
||||
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId->Name);
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -340,10 +343,13 @@ namespace CSVReader
|
||||
|
||||
if (nSize < 1 && nInputBufferSize > 0)
|
||||
{//для синхронности вывода превью и нормального результата
|
||||
const auto oEncodindId = std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
|
||||
|
||||
#ifdef __ANDROID__
|
||||
const auto oEncodindId = *std::find_if (NSUnicodeConverter::Encodings, NSUnicodeConverter::Encodings + UNICODE_CONVERTER_ENCODINGS_COUNT - 1, [nCodePage] (const NSUnicodeConverter::EncodindId& ei) { return ei.WindowsCodePage == nCodePage; });
|
||||
#else
|
||||
const NSUnicodeConverter::EncodindId& oEncodindId = NSUnicodeConverter::Encodings[nCodePage];
|
||||
#endif
|
||||
NSUnicodeConverter::CUnicodeConverter oUnicodeConverter;
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId->Name);
|
||||
sFileDataW = oUnicodeConverter.toUnicode((const char*)pInputBuffer, nInputBufferSize, oEncodindId.Name);
|
||||
|
||||
nSize = sFileDataW.length();
|
||||
//return AVS_FILEUTILS_ERROR_CONVERT_ICU;
|
||||
|
||||
Reference in New Issue
Block a user