diff --git a/ASCOfficeDocFile/DocDocxConverter/Converter.cpp b/ASCOfficeDocFile/DocDocxConverter/Converter.cpp index 3715d76c64..33bf6f1ff1 100644 --- a/ASCOfficeDocFile/DocDocxConverter/Converter.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/Converter.cpp @@ -61,7 +61,7 @@ namespace DocFileFormat namespace DocFileFormat { - _UINT32 Converter::Convert(WordDocument* doc, WordprocessingDocument* docx, const ProgressCallback* progress) + _UINT32 Converter::Convert(WordDocument* doc, WordprocessingDocument* docx) { if (!doc || !docx) return S_FALSE; @@ -81,21 +81,9 @@ namespace DocFileFormat } //write document.xml and the header and footers - MainDocumentMapping mainDocMapping( &context, progress ); + MainDocumentMapping mainDocMapping( &context); doc->Convert( &mainDocMapping ); - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 810000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 810000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } //Write numbering.xml if (doc->listTable) { @@ -103,129 +91,43 @@ namespace DocFileFormat doc->listTable->Convert( &numberingMapping ); } - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 850000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 850000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 875000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 875000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } //write the footnotes FootnotesMapping footnotesMapping( &context ); doc->Convert( &footnotesMapping ); - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 900000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 900000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } - //write the endnotes EndnotesMapping endnotesMapping( &context ); doc->Convert( &endnotesMapping ); - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 925000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 925000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } - //write the comments CommentsMapping commentsMapping( &context ); doc->Convert( &commentsMapping ); - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 950000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 950000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } - //write settings.xml at last because of the rsid list if (doc->DocProperties) { SettingsMapping settingsMapping( &context ); doc->DocProperties->Convert( &settingsMapping ); } - - if ( progress != NULL ) - { - progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 975000 ); - - short cancel = 0; - progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 975000, &cancel ); - - if ( cancel != 0 ) - { - return S_FALSE; - } - } return S_OK; } - _UINT32 Converter::LoadAndConvert(const std::wstring& strSrcFile, const std::wstring& strDstDirectory, const std::wstring& password, const ProgressCallback* progress, bool &bMacros) + _UINT32 Converter::LoadAndConvert(const std::wstring& strSrcFile, const std::wstring& strDstDirectory, const std::wstring& password, bool &bMacros) { - WordDocument doc(progress, m_sTempFolder, m_nUserLCID); + WordDocument doc(m_sTempFolder, m_nUserLCID); WordprocessingDocument docx(strDstDirectory, &doc); _UINT32 result = doc.LoadDocument(strSrcFile, password); if (result == 0) { - result = Convert(&doc, &docx, progress); + result = Convert(&doc, &docx); if (result == 0) { - docx.SaveDocument(bMacros); - - if (progress)progress->OnProgress(progress->caller, DOC_ONPROGRESSEVENT_ID, 1000000); - - short cancel = 0; - if (progress)progress->OnProgressEx(progress->caller, DOC_ONPROGRESSEVENT_ID, 1000000, &cancel); - - if (0 != cancel) - { - return S_FALSE; - } + result = docx.SaveDocument(bMacros); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/Converter.h b/ASCOfficeDocFile/DocDocxConverter/Converter.h index d42bb1efbf..d0400b18a0 100644 --- a/ASCOfficeDocFile/DocDocxConverter/Converter.h +++ b/ASCOfficeDocFile/DocDocxConverter/Converter.h @@ -34,8 +34,6 @@ #include #include "../../Common/DocxFormat/Source/Base/Types_32.h" -struct ProgressCallback; - namespace DocFileFormat { class WordDocument; @@ -50,9 +48,9 @@ namespace DocFileFormat std::wstring m_sTempFolder; int m_nUserLCID; - _UINT32 LoadAndConvert(const std::wstring & strSrcFile, const std::wstring & strDstDirectory, const std::wstring & password, const ProgressCallback* progress, bool &bMacros); + _UINT32 LoadAndConvert(const std::wstring & strSrcFile, const std::wstring & strDstDirectory, const std::wstring & password, bool &bMacros); private: - _UINT32 Convert(WordDocument* doc, WordprocessingDocument* docx, const ProgressCallback* progress); + _UINT32 Convert(WordDocument* doc, WordprocessingDocument* docx); }; } diff --git a/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp index 7234ced61b..0f158f6d64 100644 --- a/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp @@ -34,9 +34,8 @@ namespace DocFileFormat { - MainDocumentMapping::MainDocumentMapping (ConversionContext* ctx, const ProgressCallback* ffCallBack) : DocumentMapping( ctx, this ), m_ffCallBack(NULL) + MainDocumentMapping::MainDocumentMapping (ConversionContext* ctx) : DocumentMapping( ctx, this ) { - m_ffCallBack = ffCallBack; } MainDocumentMapping::~MainDocumentMapping() @@ -168,24 +167,6 @@ namespace DocFileFormat cp = m_document->FIB->m_RgLw97.ccpText; } - - if (m_ffCallBack) - { - if (( (unsigned int) cp > (progressStep * index) ) && (m_ffCallBack)) - { - double progress = ( double( 800000 - 500000 ) / m_document->FIB->m_RgLw97.ccpText * cp ); - - m_ffCallBack->OnProgress (m_ffCallBack->caller, DOC_ONPROGRESSEVENT_ID, long( 500000 + progress )); - - short bCancel = 0; - m_ffCallBack->OnProgressEx (m_ffCallBack->caller, DOC_ONPROGRESSEVENT_ID, long( 500000 + progress ), &bCancel); - - if (0 != bCancel) - return; - - ++index; - } - } } //write the section properties of the body with the last SEPX diff --git a/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.h b/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.h index 1b91bf8660..a6be80ef82 100644 --- a/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.h @@ -41,12 +41,9 @@ namespace DocFileFormat class MainDocumentMapping : public DocumentMapping { public: - MainDocumentMapping (ConversionContext* ctx, const ProgressCallback* ffCallBack); + MainDocumentMapping (ConversionContext* ctx); virtual ~MainDocumentMapping(); + virtual void Apply (IVisitable* visited); - - private: - - const ProgressCallback* m_ffCallBack; }; } \ No newline at end of file diff --git a/ASCOfficeDocFile/DocDocxConverter/SprmTDefTable.h b/ASCOfficeDocFile/DocDocxConverter/SprmTDefTable.h index 0944f96cd4..1ce2e44d8d 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SprmTDefTable.h +++ b/ASCOfficeDocFile/DocDocxConverter/SprmTDefTable.h @@ -114,7 +114,7 @@ namespace DocFileFormat TC80 oTC80; oTC80.ftsWidth = Global::dxa; - oTC80.wWidth = 3190; + oTC80.wWidth = 0; oTC80.brcTop = new BorderCode(); oTC80.brcLeft = new BorderCode(); diff --git a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp index 781698ab72..4c1a7b03b0 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp @@ -111,6 +111,18 @@ namespace DocFileFormat bPresentDefTable = true; SprmTDefTable tdef(iter->Arguments, iter->argumentsSize); + + bool bUseWidth = true; + + for (size_t j = 0; j < tdef.rgTc80.size(); ++j) + { // 1bc0f6c0-b226-4bcb-912c-e7f97b009d8a.doc + // Технические_Требования_1_287_ДИТ.DOC + if (tdef.rgTc80[j].horzMerge == 0 && tdef.rgTc80[j].wWidth < 1) + { + bUseWidth = false; + break; + } + } int cc = tdef.numberOfColumns; _tGrid = tdef.rgdxaCenter; @@ -172,9 +184,8 @@ namespace DocFileFormat _gridSpan = 1; nComputedCellWidths += (tdef.rgdxaCenter[ _cellIndex + 1] - tdef.rgdxaCenter[ 0 ]); - nComputedCellWidth += /*tdef.rgTc80[ _cellIndex].wWidth > 1 ? tdef.rgTc80[ _cellIndex].wWidth :*/ // 1bc0f6c0-b226-4bcb-912c-e7f97b009d8a.doc + nComputedCellWidth += bUseWidth ? tdef.rgTc80[ _cellIndex].wWidth : (tdef.rgdxaCenter[ _cellIndex + 1] - tdef.rgdxaCenter[ _cellIndex ]); - //Технические_Требования_1_287_ДИТ.DOC } if (!IsTableBordersDefined(tapx->grpprl)) diff --git a/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp index b8a9c45501..1e17518a45 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp @@ -84,9 +84,7 @@ namespace DocFileFormat case sprmTDxaGapHalf: { gabHalf = FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ); - } - break; - + }break; case sprmOldTDefTable: case sprmTDefTable: { @@ -101,9 +99,7 @@ namespace DocFileFormat //If there follows a real sprmTWidthIndent, this value will be overwritten //tblIndent = (std::max)((int)tblIndent,0); //cerere.doc - } - break; - + }break; case sprmTTableWidth: { //preferred table width @@ -121,8 +117,7 @@ namespace DocFileFormat _tblPr->AppendChild( tblW ); bTableW = true; - } - break; + }break; case sprmTMerge: { itcFirst = iter->Arguments[0]; @@ -135,23 +130,19 @@ namespace DocFileFormat case sprmOldTJc: case sprmTJc: case sprmTJcRow: - { //justification + { appendValueElement( _tblPr, L"jc" , FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::JustificationCode[0][0], 10, 15 ), true ); - } - break; - + }break; case sprmTWidthIndent: - { //indent + { tblIndent = FtsWWidth_Indent(iter->Arguments).wWidth; // tblIndent = FormatUtils::BytesToInt16( iter->Arguments, 1, iter->argumentsSize ); - } - break; - + }break; case sprmTIstd: case sprmTIstdPermute: - { //style + { if ( _isTableStyleNeeded ) { @@ -164,28 +155,21 @@ namespace DocFileFormat appendValueElement( _tblPr, L"tblStyle", id, true ); } } - } - break; - + }break; case sprmTFBiDi: case sprmTFBiDi90: - { //bidi + { appendValueElement( _tblPr, L"bidiVisual", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ), true ); - } - break; - + }break; case sprmOldTTlp: case sprmTTlp: - { //table look + { appendValueElement( _tblPr, L"tblLook", FormatUtils::IntToFormattedWideString( FormatUtils::BytesToInt16( iter->Arguments, 2, iter->argumentsSize ), L"%04x" ), true ); - } - break; + }break; case sprmTFAutofit: - {//autofit - - layoutType.SetValue(L"fixed"); + { if ( iter->Arguments[0] == 1 ) { layoutType.SetValue( L"auto" ); @@ -219,48 +203,36 @@ namespace DocFileFormat { marginRight = wMar; } - } - break; - - case sprmTCHorzBands: - { //row count + }break; + case sprmTCHorzBands: + { appendValueElement( _tblPr, L"tblStyleRowBandSize", iter->Arguments[0], true ); - } - break; - + }break; case sprmTCVertBands: - { //col count + { appendValueElement( _tblPr, L"tblStyleColBandSize", iter->Arguments[0], true ); - } - break; - + }break; case sprmTFNoAllowOverlap: - { //overlap - - std::wstring tblOverlapVal = std::wstring( L"overlap"); + { + std::wstring tblOverlapVal(L"overlap"); if ( iter->Arguments[0] ) { - tblOverlapVal = std::wstring( L"never"); + tblOverlapVal = L"never"; } appendValueElement( _tblPr, L"tblOverlap", tblOverlapVal, true ); - } - break; - + }break; case sprmOldTSetShd : case sprmTSetShdTable : - { //shading + { appendShading( _tblPr, ShadingDescriptor( iter->Arguments, iter->argumentsSize ) ); - } - break; - + }break; case sprmTTableBorders80: - { //borders 80 exceptions - + { const int size = 4; unsigned char brc80[size]; @@ -293,10 +265,7 @@ namespace DocFileFormat memcpy( brc80, ( iter->Arguments + 20 ), size ); RELEASEOBJECT( brcVert ); brcVert = new BorderCode( brc80, size ); - } - break; - - //border exceptions + }break; case sprmOldTTableBorders: case sprmTTableBorders: { @@ -332,10 +301,7 @@ namespace DocFileFormat memcpy( brc, ( iter->Arguments + 40 ), size ); RELEASEOBJECT( brcVert ); brcVert = new BorderCode( brc, size ); - } - break; - - //floating table properties + }break; case sprmTPc: { unsigned char flag = ( iter->Arguments[0] & 0x30 ) >> 4; @@ -345,44 +311,31 @@ namespace DocFileFormat flag = ( iter->Arguments[0] & 0xC0 ) >> 6; appendValueAttribute( &tblpPr, L"w:horzAnchor", FormatUtils::MapValueToWideString( flag, &Global::HorizontalPositionCode[0][0], 4, 7 ) ); - } - break; - + }break; case sprmTDxaFromText: { appendValueAttribute( &tblpPr, L"w:leftFromText", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - } - break; - + }break; case sprmTDxaFromTextRight: { appendValueAttribute( &tblpPr, L"w:rightFromText", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - } - break; - + }break; case sprmTDyaFromText: { appendValueAttribute( &tblpPr, L"w:topFromText", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - } - break; - + }break; case sprmTDyaFromTextBottom: { appendValueAttribute( &tblpPr, L"w:bottomFromText", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - } - break; - + }break; case sprmTDxaAbs: { appendValueAttribute( &tblpPr, L"w:tblpX", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - } - break; - + }break; case sprmTDyaAbs: { appendValueAttribute( &tblpPr, L"w:tblpY", FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - } - break; + }break; } } if (false == bTableW) diff --git a/ASCOfficeDocFile/DocDocxConverter/VMLShapeMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/VMLShapeMapping.cpp index 04a6f6faeb..fb2aecc025 100644 --- a/ASCOfficeDocFile/DocDocxConverter/VMLShapeMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/VMLShapeMapping.cpp @@ -565,6 +565,7 @@ namespace DocFileFormat case ODRAW::fillFocus: { appendValueAttribute(&m_fill, L"focus", (FormatUtils::IntToWideString(iter->op) + L"%")); + appendValueAttribute(&m_fill, L"focusposition", L".5, .5"); appendValueAttribute(&m_fill, L"focussize", L""); }break; case ODRAW::fillType: @@ -602,12 +603,14 @@ namespace DocFileFormat }break; case ODRAW::fillOpacity: { - appendValueAttribute(&m_fill, L"opacity", (FormatUtils::IntToWideString(iter->op) + L"f")); + double opa = (iter->op / pow((double)2, (double)16)); + appendValueAttribute(&m_fill, L"opacity", FormatUtils::DoubleToFormattedWideString(opa, L"%.2f")); } break; case ODRAW::fillBackOpacity: { - appendValueAttribute(&m_fill, L"o:opacity2", (FormatUtils::IntToWideString(iter->op) + L"f")); + double opa = (iter->op / pow((double)2, (double)16)); + appendValueAttribute(&m_fill, L"o:opacity2", FormatUtils::DoubleToFormattedWideString(opa, L"%.2f")); }break; // SHADOW case ODRAW::shadowType: @@ -652,8 +655,14 @@ namespace DocFileFormat }break; case ODRAW::shadowStyleBooleanProperties: { - //ODRAW::ShadowStyleBooleanProperties - + ODRAW::ShadowStyleBooleanProperties* booleans = dynamic_cast(iter.get()); + if (booleans) + { + if (booleans->fUsefShadow && booleans->fShadow) + { + bShadow = true; + } + } }break; // OLE case ODRAW::pictureId: @@ -1020,13 +1029,6 @@ namespace DocFileFormat appendValueAttribute(&m_shadow, L"origin", FormatUtils::DoubleToWideString(*ShadowOriginX) + std::wstring(L"," ) + FormatUtils::DoubleToWideString(*ShadowOriginY)); } -// write shadow - if (m_shadow.GetAttributeCount() > 0) - { - appendValueAttribute(&m_shadow, L"on", bShadow ? L"t" : L"f" ); - m_pXmlWriter->WriteString(m_shadow.GetXMLString()); - } - //write the viewpoint if ( ViewPointX || ViewPointY || ViewPointZ ) { @@ -1095,6 +1097,13 @@ namespace DocFileFormat { m_pXmlWriter->WriteString(m_fill.GetXMLString()); } + +// write shadow + if (m_shadow.GetAttributeCount() > 0) + { + appendValueAttribute(&m_shadow, L"on", bShadow ? L"t" : L"f"); + m_pXmlWriter->WriteString(m_shadow.GetXMLString()); + } // write imagedata if (m_imagedata.GetAttributeCount()) { @@ -2029,8 +2038,12 @@ namespace DocFileFormat std::wstring result; for (size_t i = 0; i < pColors->complex.data.size(); ++i) { - result += FormatUtils::IntToWideString((int)pColors->complex.data[i].dPosition); - result += L"f #"; + if (pColors->complex.data[i].position.Fractional == 0) + result += FormatUtils::IntToWideString(pColors->complex.data[i].position.Integral); + else + result += FormatUtils::IntToWideString(pColors->complex.data[i].position.Fractional) +L"f"; + + result += L" #"; result += pColors->complex.data[i].color.sColorRGB; result += L";"; } diff --git a/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp b/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp index 3d37195bc6..1eb9120177 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp @@ -80,7 +80,7 @@ namespace DocFileFormat 254, 437,//PC 437 255, 850//OEM }; - WordDocument::WordDocument (const ProgressCallback* pCallFunc, const std::wstring & sTempFolder, const int userLCID) : + WordDocument::WordDocument (const std::wstring & sTempFolder, const int userLCID) : m_PieceTable(NULL), WordDocumentStream(NULL), TableStream(NULL), DataStream(NULL), FIB(NULL), Text(NULL), RevisionAuthorTable(NULL), FontTable(NULL), BookmarkNames(NULL), AutoTextNames(NULL), IndividualFootnotesPlex(NULL), FootnoteReferenceCharactersPlex(NULL), IndividualEndnotesPlex(NULL), @@ -93,7 +93,6 @@ namespace DocFileFormat AnnotationOwners(NULL), DocProperties(NULL), listFormatOverrideTable(NULL), headerAndFooterTable(NULL), AnnotStartPlex(NULL), AnnotEndPlex(NULL), encryptionHeader(NULL) { - m_pCallFunc = pCallFunc; m_sTempFolder = sTempFolder; m_nUserLCID = userLCID; @@ -315,21 +314,7 @@ namespace DocFileFormat BookmarkAnnotNames = new StringTable (TableStream, FIB->m_FibWord97.fcSttbfAtnBkmk, FIB->m_FibWord97.lcbSttbfAtnBkmk, nWordVersion, true); - if (m_pCallFunc) - { - m_pCallFunc->OnProgress (m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 100000); - - SHORT bCancel = 0; - m_pCallFunc->OnProgressEx(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 100000, &bCancel); - - if (bCancel) - { - Clear(); - return AVS_ERROR_FILEFORMAT; - } - } - - // Read all needed PLCFs + // Read all needed PLCFs if (FIB->m_RgLw97.ccpFtn > 0) { FootnoteReferenceCharactersPlex = new Plex(FootnoteDescriptor::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcffndRef, FIB->m_FibWord97.lcbPlcffndRef, nWordVersion); @@ -422,20 +407,6 @@ namespace DocFileFormat ListPlex = new Plex (ListNumCache::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcfBteLvc, FIB->m_FibWord97.lcbPlcfBteLvc, nWordVersion); - if (m_pCallFunc) - { - m_pCallFunc->OnProgress(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 200000 ); - - SHORT bCancel = 0; - m_pCallFunc->OnProgressEx(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 200000, &bCancel); - - if (bCancel) - { - Clear(); - return AVS_ERROR_FILEFORMAT; - } - } - // Read the FKPs AllPapxFkps = FormattedDiskPagePAPX::GetAllPAPXFKPs (FIB, WordDocumentStream, TableStream, DataStream); AllChpxFkps = FormattedDiskPageCHPX::GetAllCHPXFKPs (FIB, WordDocumentStream, TableStream); @@ -452,19 +423,6 @@ namespace DocFileFormat AnnotationOwners = new AnnotationOwnerList (FIB, TableStream); } - if (m_pCallFunc) - { - m_pCallFunc->OnProgress(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 300000 ); - - SHORT bCancel = 0; - m_pCallFunc->OnProgressEx(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 300000, &bCancel); - - if (bCancel) - { - Clear(); - return AVS_ERROR_FILEFORMAT; - } - } if (FontTable) { std::unordered_map fonts_charsets; @@ -556,20 +514,6 @@ namespace DocFileFormat std::sort (AllPapxVector->begin(), AllPapxVector->end()); - if (m_pCallFunc) - { - m_pCallFunc->OnProgress(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 400000 ); - - SHORT bCancel = 0; - m_pCallFunc->OnProgressEx(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 400000, &bCancel); - - if (bCancel) - { - Clear(); - return AVS_ERROR_FILEFORMAT; - } - } - //build a dictionary of all SEPX if ( !SectionPlex->Elements.empty() ) { @@ -594,20 +538,6 @@ namespace DocFileFormat } } - if (m_pCallFunc) - { - m_pCallFunc->OnProgress(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 500000 ); - - SHORT bCancel = 0; - m_pCallFunc->OnProgressEx(m_pCallFunc->caller, DOC_ONPROGRESSEVENT_ID, 500000, &bCancel); - - if (bCancel) - { - Clear(); - return AVS_ERROR_FILEFORMAT; - } - } - return 0; } bool WordDocument::LoadDocumentFlat() diff --git a/ASCOfficeDocFile/DocDocxConverter/WordDocument.h b/ASCOfficeDocFile/DocDocxConverter/WordDocument.h index be5cd5556d..fd1b3515f5 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordDocument.h +++ b/ASCOfficeDocFile/DocDocxConverter/WordDocument.h @@ -58,7 +58,6 @@ #include "EndnoteDescriptor.h" #include "FieldCharacter.h" #include "IVisitable.h" -#include "../Common/Callback.h" namespace CRYPT { @@ -92,7 +91,7 @@ namespace DocFileFormat public: - WordDocument (const ProgressCallback* pCallFunc, const std::wstring & tempFolder, const int userLCID); + WordDocument (const std::wstring & tempFolder, const int userLCID); virtual ~WordDocument(); _UINT32 LoadDocument(const std::wstring & fileName, const std::wstring & password); @@ -155,8 +154,6 @@ namespace DocFileFormat std::wstring m_sTempDecryptFileName; int m_nUserLCID; - const ProgressCallback* m_pCallFunc; - POLE::Stream * WordDocumentStream; // The stream "WordDocument" POLE::Stream * TableStream; // The stream "0Table" or "1Table" POLE::Stream * DataStream; // The stream called "Data" diff --git a/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp b/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp index 67fcf618f8..32a28d50df 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp @@ -51,7 +51,7 @@ namespace DocFileFormat { } - void WordprocessingDocument::SaveDocument(bool &bMacros) + _UINT32 WordprocessingDocument::SaveDocument(bool &bMacros) { std::wstring pathWord = m_strOutputPath + FILE_SEPARATOR_STR + L"word" ; NSDirectory::CreateDirectory( pathWord ); @@ -179,5 +179,6 @@ namespace DocFileFormat { SaveToFile(pathWord, ( std::wstring( L"footer" ) + FormatUtils::IntToWideString(++footersCount) + std::wstring( L".xml" ) ), *iter); } + return 0; } } diff --git a/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.h b/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.h index e8ca077310..3d912e1cc6 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.h +++ b/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.h @@ -79,6 +79,6 @@ namespace DocFileFormat WordprocessingDocument(const std::wstring & _docxDirectory, const WordDocument* _docFile); virtual ~WordprocessingDocument(); - void SaveDocument(bool &bMacros); + _UINT32 SaveDocument(bool &bMacros); }; } \ No newline at end of file diff --git a/ASCOfficeDocFile/DocFormatLib/DocFormatLib.cpp b/ASCOfficeDocFile/DocFormatLib/DocFormatLib.cpp index 5a593b3e38..cff1633292 100644 --- a/ASCOfficeDocFile/DocFormatLib/DocFormatLib.cpp +++ b/ASCOfficeDocFile/DocFormatLib/DocFormatLib.cpp @@ -34,7 +34,7 @@ #include "../DocDocxConverter/Converter.h" #include "../../OfficeUtils/src/OfficeUtils.h" -_UINT32 COfficeDocFile::LoadFromFile(const std::wstring & docFile, const std::wstring & docxDirectory, const std::wstring & password, bool &bMacros, ProgressCallback *ffCallBack) +_UINT32 COfficeDocFile::LoadFromFile(const std::wstring & docFile, const std::wstring & docxDirectory, const std::wstring & password, bool &bMacros) { _UINT32 hr = 0; @@ -43,12 +43,12 @@ _UINT32 COfficeDocFile::LoadFromFile(const std::wstring & docFile, const std::w docToDocx.m_sTempFolder = m_sTempFolder; docToDocx.m_nUserLCID = m_nUserLCID; - hr= docToDocx.LoadAndConvert(docFile, docxDirectory, password, ffCallBack, bMacros); + hr= docToDocx.LoadAndConvert(docFile, docxDirectory, password, bMacros); return hr; } -_UINT32 COfficeDocFile::SaveToFile (const std::wstring & sDstFileName, const std::wstring & sSrcFileName, ProgressCallback *ffCallBack ) +_UINT32 COfficeDocFile::SaveToFile (const std::wstring & sDstFileName, const std::wstring & sSrcFileName) { return 0; } diff --git a/ASCOfficeDocFile/DocFormatLib/DocFormatLib.h b/ASCOfficeDocFile/DocFormatLib/DocFormatLib.h index a6b1e3d9d7..d3e36ede2f 100644 --- a/ASCOfficeDocFile/DocFormatLib/DocFormatLib.h +++ b/ASCOfficeDocFile/DocFormatLib/DocFormatLib.h @@ -29,8 +29,7 @@ * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ -#ifndef DOC_FORMAT_LIB -#define DOC_FORMAT_LIB +#pragma once #if defined(_WIN32) || defined(_WIN64) #include @@ -38,8 +37,6 @@ #include "../../DesktopEditor/common/ASCVariant.h" -struct ProgressCallback; - class COfficeDocFile { public: @@ -49,9 +46,8 @@ public: std::wstring m_sTempFolder; int m_nUserLCID; - _UINT32 LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstFileName, const std::wstring & password, bool &bMacros, ProgressCallback *ffCallBack = NULL); - _UINT32 SaveToFile(const std::wstring & sDstFileName, const std::wstring & sSrcFileName, ProgressCallback *ffCallBack = NULL); + _UINT32 LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstFileName, const std::wstring & password, bool &bMacros); + _UINT32 SaveToFile(const std::wstring & sDstFileName, const std::wstring & sSrcFileName); }; -#endif //DOC_FORMAT_LIB diff --git a/ASCOfficeDocxFile2/BinReader/ReaderClasses.h b/ASCOfficeDocxFile2/BinReader/ReaderClasses.h index 7bd06f78d0..11ef2e36f4 100644 --- a/ASCOfficeDocxFile2/BinReader/ReaderClasses.h +++ b/ASCOfficeDocxFile2/BinReader/ReaderClasses.h @@ -579,6 +579,7 @@ public: bool bThemeColor; bool bVanish; + long CompressText; bool bDoNotWriteNullProp; public: rPr(boost::unordered_map& mapFonts) : m_mapFonts(mapFonts) @@ -636,6 +637,8 @@ public: MoveFrom.clear(); MoveTo.clear(); rPrChange.clear(); + + CompressText = -1; //not set } bool IsNoEmpty() { @@ -701,6 +704,10 @@ public: sFont += _T("/>"); pCStringWriter->WriteString(sFont); } + if (CompressText >= 0 && CompressText <= 600) + { + pCStringWriter->WriteString(L""); + } if(bBold) { if(Bold) @@ -798,8 +805,8 @@ public: } if(bFontSizeCs) { - if(false == bFontSize) - pCStringWriter->WriteString(L""); + //if(false == bFontSize) - Sample Doc.docx + // pCStringWriter->WriteString(L""); pCStringWriter->WriteString(L""); } if(nHighLight > 0) diff --git a/ASCOfficeDocxFile2/BinReader/Readers.cpp b/ASCOfficeDocxFile2/BinReader/Readers.cpp index d68204c6b3..0d52b6f9a9 100644 --- a/ASCOfficeDocxFile2/BinReader/Readers.cpp +++ b/ASCOfficeDocxFile2/BinReader/Readers.cpp @@ -758,6 +758,11 @@ int Binary_rPrReader::ReadContent(BYTE type, long length, void* poResult) orPr->rPrChange = oRPrChange.ToString(L"w:rPrChange"); } break; + case c_oSerProp_rPrType::CompressText: + { + orPr->CompressText = m_oBufferedStream.GetLong(); + } + break; default: res = c_oSerConstants::ReadUnknown; break; @@ -4619,6 +4624,32 @@ int Binary_DocumentTableReader::ReadDocumentContent(BYTE type, long length, void READ1_DEF(length, res, this->ReadParagraph, NULL); m_oDocumentWriter.m_oContent.WriteString(std::wstring(L"")); } + else if (c_oSerParType::CommentStart == type) + { + long nId = 0; + READ1_DEF(length, res, this->ReadComment, &nId); + if (NULL != m_oFileWriter.m_pComments) + { + CComment* pComment = m_oFileWriter.m_pComments->get(nId); + if (NULL != pComment) + { + int nNewId = m_oFileWriter.m_pComments->getNextId(pComment->getCount()); + pComment->setFormatStart(nNewId); + GetRunStringWriter().WriteString(pComment->writeRef(std::wstring(_T("")), std::wstring(_T("w:commentRangeStart")), std::wstring(_T("")))); + } + } + } + else if (c_oSerParType::CommentEnd == type) + { + long nId = 0; + READ1_DEF(length, res, this->ReadComment, &nId); + if (NULL != m_oFileWriter.m_pComments) + { + CComment* pComment = m_oFileWriter.m_pComments->get(nId); + if (NULL != pComment && pComment->bIdFormat) + GetRunStringWriter().WriteString(pComment->writeRef(std::wstring(_T("")), std::wstring(_T("w:commentRangeEnd")), std::wstring(_T("")))); + } + } else if(c_oSerParType::Table == type) { m_byteLastElemType = c_oSerParType::Table; diff --git a/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h b/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h index 379fa51f3a..0cb375963d 100644 --- a/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h +++ b/ASCOfficeDocxFile2/BinWriter/BinReaderWriterDefines.h @@ -416,7 +416,8 @@ extern int g_nCurFormatVersion; FontAsciiTheme = 40, FontHAnsiTheme = 41, FontAETheme = 42, - FontCSTheme = 43 + FontCSTheme = 43, + CompressText = 44 };} namespace c_oSerProp_rowPrType{enum c_oSerProp_rowPrType { diff --git a/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp b/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp index 4b76a1be77..5cec90cd87 100644 --- a/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp +++ b/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp @@ -700,28 +700,28 @@ void Binary_rPrWriter::Write_rPr(OOX::Logic::CRunProperty* rPr) m_oBcw.m_oStream.WriteBOOL(italicCs); } //FontSizeCs - if(rPr->m_oSzCs.IsInit() && rPr->m_oSzCs->m_oVal.IsInit()) + if (rPr->m_oSzCs.IsInit() && rPr->m_oSzCs->m_oVal.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::FontSizeCs); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Long); m_oBcw.m_oStream.WriteLONG(rPr->m_oSzCs.get().m_oVal.get().ToHps()); } //Cs - if(false != rPr->m_oCs.IsInit()) + if (false != rPr->m_oCs.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::Cs); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); m_oBcw.m_oStream.WriteBOOL(rPr->m_oCs->m_oVal.ToBool()); } //Rtl - if(false != rPr->m_oRtL.IsInit()) + if (false != rPr->m_oRtL.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::Rtl); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); m_oBcw.m_oStream.WriteBOOL(rPr->m_oRtL->m_oVal.ToBool()); } //Lang - if(false != rPr->m_oLang.IsInit()) + if (false != rPr->m_oLang.IsInit()) { if(rPr->m_oLang->m_oVal.IsInit()) { @@ -743,7 +743,7 @@ void Binary_rPrWriter::Write_rPr(OOX::Logic::CRunProperty* rPr) } } //Vanish - if(false != rPr->m_oVanish.IsInit()) + if (false != rPr->m_oVanish.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::Vanish); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); @@ -767,7 +767,7 @@ void Binary_rPrWriter::Write_rPr(OOX::Logic::CRunProperty* rPr) m_oBcw.m_oStream.WriteRecord1(0, rPr->m_oTextFill); m_oBcw.WriteItemWithLengthEnd(nCurPos); } - if(rPr->m_oDel.IsInit()) + if (rPr->m_oDel.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::Del); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); @@ -775,7 +775,7 @@ void Binary_rPrWriter::Write_rPr(OOX::Logic::CRunProperty* rPr) m_oBcw.WriteTrackRevision(rPr->m_oDel.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } - if(rPr->m_oIns.IsInit()) + if (rPr->m_oIns.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::Ins); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); @@ -799,7 +799,7 @@ void Binary_rPrWriter::Write_rPr(OOX::Logic::CRunProperty* rPr) m_oBcw.WriteTrackRevision(rPr->m_oMoveFrom.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } - if(rPr->m_oMoveTo.IsInit()) + if (rPr->m_oMoveTo.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::MoveTo); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); @@ -807,6 +807,12 @@ void Binary_rPrWriter::Write_rPr(OOX::Logic::CRunProperty* rPr) m_oBcw.WriteTrackRevision(rPr->m_oMoveTo.get()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } + if (rPr->m_oW.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSerProp_rPrType::CompressText); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Long); + m_oBcw.m_oStream.WriteLONG(rPr->m_oW->m_oVal->GetValue()); + } } void Binary_rPrWriter::Write_rPrChange(const OOX::Logic::CRPrChange& rPrChange) { @@ -3216,6 +3222,16 @@ void BinaryDocumentTableWriter::WriteDocumentContent(const std::vectorgetType()) { + case OOX::et_w_commentRangeStart: + { + OOX::Logic::CCommentRangeStart* pCommentRangeStart = static_cast(item); + WriteComment(OOX::et_w_commentRangeStart, pCommentRangeStart->m_oId); + }break; + case OOX::et_w_commentRangeEnd: + { + OOX::Logic::CCommentRangeEnd* pCommentRangeEnd = static_cast(item); + WriteComment(OOX::et_w_commentRangeEnd, pCommentRangeEnd->m_oId); + }break; case OOX::et_w_altChunk: { OOX::Logic::CAltChunk* pAltChunk = static_cast(item); @@ -3433,7 +3449,7 @@ void BinaryDocumentTableWriter::WriteAltChunk(OOX::Media& oAltChunkFile, OOX::CS bool bMacros = false; - result = (S_OK == docFile.LoadFromFile(file_name_inp, sResultDocxDir, NULL, bMacros, NULL)); + result = (S_OK == docFile.LoadFromFile(file_name_inp, sResultDocxDir, NULL, bMacros)); #else result = S_FALSE; #endif diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp index 43b1ebf310..29b7d890a7 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp +++ b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.cpp @@ -1315,7 +1315,7 @@ void odt_conversion_context::end_run() //} } //-------------------------------------------------------------------------------------------------------- -bool odt_conversion_context::start_comment(int oox_comm_id) +int odt_conversion_context::start_comment(int oox_comm_id) { int comm_state = comment_context_.find_by_id(oox_comm_id); @@ -1326,15 +1326,21 @@ bool odt_conversion_context::start_comment(int oox_comm_id) comment_context_.start_comment(comm_elm, oox_comm_id); - if (text_context()->current_level_.size() > 0) - text_context()->current_level_.back().elm->add_child_element(comm_elm); + if (text_context()->current_level_.empty()) + { + comm_state = 2; + + start_paragraph(); + text_context()->set_KeepNextParagraph(true); + + //аннотацию нельзя добавить на верхний уровень - нет поддержки в open_format + } + text_context()->current_level_.back().elm->add_child_element(comm_elm); odf_element_state state(comm_elm, L"", office_element_ptr(), text_context()->current_level_.size()); text_context()->current_level_.push_back(state); - - return false; //типо новый } - return true; + return comm_state; } void odt_conversion_context::start_comment_content() { diff --git a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h index fe145392d4..a13f4d16fb 100644 --- a/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h +++ b/ASCOfficeOdfFileW/source/OdfFormat/odt_conversion_context.h @@ -154,7 +154,7 @@ public: style_text_properties* get_drop_cap_properties(); int get_drop_cap_lines() {return drop_cap_state_.lines;} - bool start_comment (int oox_comment_id); + int start_comment (int oox_comment_id); void end_comment (int oox_comment_id); void start_comment_content (); void end_comment_content (); diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp index 4ae8f77ef9..931317b652 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp @@ -4283,11 +4283,16 @@ void DocxConverter::convert(OOX::Logic::CCommentRangeStart* oox_comm_start) int oox_comm_id = oox_comm_start->m_oId->GetValue(); - bool added = odt_context->start_comment(oox_comm_id); + int state = odt_context->start_comment(oox_comm_id); - if (added == false) + if (state > 0) { convert_comment(oox_comm_id); + + //if (state == 2) + //{ + // odt_context->text_context()->end_element(); + //} } } @@ -4328,12 +4333,17 @@ void DocxConverter::convert(OOX::Logic::CCommentReference* oox_comm_ref) int oox_comm_id = oox_comm_ref->m_oId->GetValue(); - bool added = odt_context->start_comment(oox_comm_id); + int state = odt_context->start_comment(oox_comm_id); - if (added == false) // типо тока стартанул + if (state > 0) // типо тока стартанул { //значит старт тута а не по RangeStart convert_comment(oox_comm_id); + + if (state == 2) + { + odt_context->text_context()->end_element(); + } } } void DocxConverter::convert(OOX::Logic::CFootnoteReference* oox_ref) diff --git a/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp b/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp index 60c731d7b2..238a38aa74 100644 --- a/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp +++ b/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp @@ -3398,6 +3398,10 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P bool bIsInline = false; bool bIsMargin = false; + bool bZIndex = false; + + if (oCssStyles.m_mapSettings.end() != oCssStyles.m_mapSettings.find(L"z-index")) + bZIndex = true; if (oProps.IsTop == true) { @@ -3421,8 +3425,9 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P { pFind = oCssStyles.m_mapSettings.find(L"mso-position-vertical-relative"); if (oCssStyles.m_mapSettings.end() != pFind && ((pFind->second == L"text" && !bIsMargin) || pFind->second == L"line")) - { - bIsInline = true; + { + if (!bZIndex || !bIsMargin) //Liturgie Homberg 2017 mit Abendmahlsteil.docx + bIsInline = true; } } diff --git a/ASCOfficePPTXFile/Editor/Drawing/Shapes/BaseShape/PPTShape/PptShape.cpp b/ASCOfficePPTXFile/Editor/Drawing/Shapes/BaseShape/PPTShape/PptShape.cpp index 9280dc2b4b..8f292753ca 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Shapes/BaseShape/PPTShape/PptShape.cpp +++ b/ASCOfficePPTXFile/Editor/Drawing/Shapes/BaseShape/PPTShape/PptShape.cpp @@ -66,16 +66,13 @@ CBaseShapePtr CPPTShape::CreateByType(PPTShapes::ShapeType type) // msosptNotchedCircularArrow 0x00000064 A value that SHOULD NOT be used. // msosptHostControl 0x000000C9 A value that SHOULD NOT be used. - //case sptNotchedCircularArrow: - case sptHostControl: { pShape = new CPPTShape(); pShape->m_eType = type; break; } case 0: { pShape = new CRectangleType(); break; } + case sptNotchedCircularArrow: case sptPictureFrame: { pShape = new CRectangleType(); pShape->m_eType = type; break; } - CREATE_BY_SPT(0x00000064, CArcType) - CREATE_BY_SPT(sptAccentBorderCallout90, CAccentBorderCallout90Type) CREATE_BY_SPT(sptAccentBorderCallout1, CAccentBorderCallout1Type) CREATE_BY_SPT(sptAccentBorderCallout2, CAccentBorderCallout2Type) diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp index 5cbdcbfd0a..f99079b224 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp @@ -1647,6 +1647,7 @@ bool RtfPictureReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader else if ( "pngblip" == sCommand ) m_oShape.m_oPicture->eDataType = RtfPicture::dt_png; else if ( "jpegblip" == sCommand ) m_oShape.m_oPicture->eDataType = RtfPicture::dt_jpg; else if ( "macpict" == sCommand ) m_oShape.m_oPicture->eDataType = RtfPicture::dt_macpict; + else if ( "svgpict" == sCommand) m_oShape.m_oPicture->eDataType = RtfPicture::dt_svg; else if ( "wmetafile" == sCommand ) { diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp index b3289bb0a5..ff65f09bc0 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp @@ -2180,7 +2180,7 @@ bool OOXShapeReader::WriteDataToPicture( std::wstring sPath, RtfPicture& pOutput } else { - if (pOutput.eDataType == RtfPicture::dt_emf || pOutput.eDataType == RtfPicture::dt_wmf) + if (pOutput.eDataType == RtfPicture::dt_emf || pOutput.eDataType == RtfPicture::dt_wmf || pOutput.eDataType == RtfPicture::dt_svg) { if (!oParam.oRtf->m_pAppFonts) { diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXTextItemReader.h b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXTextItemReader.h index 8ea7bc623a..2446f61108 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXTextItemReader.h +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXTextItemReader.h @@ -57,14 +57,14 @@ public: { PPTX::Logic::Paragraph * pParagraph = dynamic_cast(ooxElement); - OOXParagraphReader m_oParagraphReader(pParagraph); + OOXParagraphReader oParagraphReader(pParagraph); RtfParagraphPtr oNewParagraph ( new RtfParagraph() ); //применяем к новому параграфу default property oNewParagraph->m_oProperty = oParam.oRtf->m_oDefaultParagraphProp; oNewParagraph->m_oProperty.m_oCharProperty = oParam.oRtf->m_oDefaultCharProp; oNewParagraph->m_oProperty.m_nItap = 0; - if( true == m_oParagraphReader.Parse( oParam, (*oNewParagraph), CcnfStyle() )) + if( true == oParagraphReader.Parse( oParam, (*oNewParagraph), CcnfStyle() )) { m_oTextItems->AddItem( oNewParagraph ); } @@ -73,14 +73,14 @@ public: { OOX::Logic::CParagraph * pParagraph = dynamic_cast(ooxElement); - OOXParagraphReader m_oParagraphReader(pParagraph); + OOXParagraphReader oParagraphReader(pParagraph); RtfParagraphPtr oNewParagraph ( new RtfParagraph() ); //применяем к новому параграфу default property oNewParagraph->m_oProperty = oParam.oRtf->m_oDefaultParagraphProp; oNewParagraph->m_oProperty.m_oCharProperty = oParam.oRtf->m_oDefaultCharProp; oNewParagraph->m_oProperty.m_nItap = 0; - if( true == m_oParagraphReader.Parse( oParam, (*oNewParagraph), CcnfStyle() )) + if( true == oParagraphReader.Parse( oParam, (*oNewParagraph), CcnfStyle() )) { m_oTextItems->AddItem( oNewParagraph ); } @@ -120,8 +120,40 @@ public: } }break; - default: - break; + case OOX::et_w_commentRangeStart: + case OOX::et_w_commentReference: + case OOX::et_w_commentRangeEnd: + { + OOX::Logic::CParagraph oParagraph; + oParagraph.m_oParagraphProperty = new OOX::Logic::CParagraphProperty(); + oParagraph.m_arrItems.push_back(ooxElement); + + OOXParagraphReader oParagraphReader(&oParagraph); + RtfParagraphPtr oNewParagraph(new RtfParagraph()); + + oParagraph.m_oParagraphProperty->m_oKeepNext.Init(); + oParagraph.m_oParagraphProperty->m_oKeepNext->m_oVal.SetValue(SimpleTypes::EOnOff::onoffTrue); + + oParagraph.m_oParagraphProperty->m_oKeepLines.Init(); + oParagraph.m_oParagraphProperty->m_oKeepLines->m_oVal.SetValue(SimpleTypes::EOnOff::onoffTrue); + + //применяем к новому параграфу default property + oNewParagraph->m_oProperty = oParam.oRtf->m_oDefaultParagraphProp; + oNewParagraph->m_oProperty.m_oCharProperty = oParam.oRtf->m_oDefaultCharProp; + oNewParagraph->m_oProperty.m_nItap = 0; + + if (true == oParagraphReader.Parse(oParam, (*oNewParagraph), CcnfStyle())) + { + m_oTextItems->AddItem(oNewParagraph); + } + + oParagraph.m_arrItems.clear(); + delete oParagraph.m_oParagraphProperty; oParagraph.m_oParagraphProperty = NULL; + }break; + default: + { + + }break; } return true; } diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.cpp index 03f1cbf597..d33d1faf20 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.cpp @@ -102,6 +102,7 @@ std::wstring RtfPicture::RenderToRtf(RenderParameter oRenderParameter) case dt_wmf: sResult += L"\\wmetafile8"; break; case dt_png: sResult += L"\\pngblip"; break; case dt_jpg: sResult += L"\\jpegblip"; break; + case dt_svg: sResult += L"\\svgblip"; break; //case dt_bmp: sResult += L"wbitmap8"; break; } sResult += L" "; @@ -128,6 +129,7 @@ std::wstring RtfPicture::RenderToOOX(RenderParameter oRenderParameter) case dt_wmf: sExtension = L"wmf"; sMime = L"image/x-wmf"; break; case dt_emf: sExtension = L"emf"; sMime = L"image/x-emf"; break; case dt_macpict:sExtension = L"pct"; sMime = L"image/x-pict"; break; + case dt_svg: sExtension = L"svg"; sMime = L"image/svg+xml"; break; } if (poOOXWriter->m_sTargetFolder.empty()) return L"rIdtemp"; //test from fields diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.h b/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.h index 30c1df4e9b..be40dd9ce2 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.h +++ b/ASCOfficeRtfFile/RtfFormatLib/source/RtfPicture.h @@ -36,7 +36,7 @@ class RtfPicture : public IDocumentElement { public: - typedef enum {dt_none, dt_png, dt_jpg, dt_emf, dt_wmf, dt_apm, dt_macpict}DataType; + typedef enum {dt_none, dt_png, dt_jpg, dt_emf, dt_wmf, dt_apm, dt_macpict, dt_svg}DataType; DataType eDataType; @@ -117,13 +117,13 @@ public: static DataType GetPictureType( std::wstring sFilename ) { - BYTE pBuffer[ 16 ]; + BYTE pBuffer[ 100 ]; DWORD dwBytesRead = 0; CFile file; if (file.OpenFile(sFilename) != S_OK) return dt_none; - file.ReadFile(pBuffer, 16); + file.ReadFile(pBuffer, 100); dwBytesRead = (DWORD)file.GetPosition(); file.CloseFile(); @@ -161,6 +161,26 @@ public: if ( (4 <= dwBytesRead) && (0x01 == pBuffer[0]) && (0x00 == pBuffer[1]) && (0x00 == pBuffer[2]) && (0x00 == pBuffer[3]) ) return dt_emf; + if ('<' == pBuffer[0] && + 's' == pBuffer[1] && + 'v' == pBuffer[2] && + 'g' == pBuffer[3]) + { + return dt_svg;; + } + + if ('<' == pBuffer[0] && + '?' == pBuffer[1] && + 'x' == pBuffer[2] && + 'm' == pBuffer[3] && + 'l' == pBuffer[4]) + { + std::string test((char*)pBuffer, dwBytesRead); + if (std::string::npos != test.find("Version = 0x601; - record.getGlobalWorkbookInfo()->CodePage = 0; + record.getGlobalWorkbookInfo()->Version = 0x0501; - if (record.getGlobalWorkbookInfo()->lcid_user > 0) + if (record.getGlobalWorkbookInfo()->CodePage == 0 && record.getGlobalWorkbookInfo()->lcid_user > 0) { record.getGlobalWorkbookInfo()->CodePage = msLCID2DefCodePage(record.getGlobalWorkbookInfo()->lcid_user); } diff --git a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Formula.cpp b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Formula.cpp index 475ea45d14..8731af0d0c 100644 --- a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Formula.cpp +++ b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Formula.cpp @@ -61,18 +61,10 @@ void Formula::readFields(CFRecord& record) fShrFmla = GETBIT(flags, 3); fClearErrors = GETBIT(flags, 5); - //if (record.getGlobalWorkbookInfo()->Version < 0x0600) - //{ - // _UINT16 chn = 0; - // record >> chn; - //} - //else - { - _UINT32 chn = 0; - record >> chn; - } + _UINT32 chn = 0; + record >> chn; + formula.load(record); - } diff --git a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Label.cpp b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Label.cpp index e48e689db9..9b07ca2586 100644 --- a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Label.cpp +++ b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Label.cpp @@ -57,7 +57,7 @@ void Label::readFields(CFRecord& record) record >> cell; - if (global_info_->Version < 0x0600 || global_info_->Version == 0x601) + if (global_info_->Version < 0x0600) { LPAnsiString name; record >> name; diff --git a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Obj.cpp b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Obj.cpp index f95f91c1bf..7104ff274f 100644 --- a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Obj.cpp +++ b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/Obj.cpp @@ -243,8 +243,19 @@ void Obj::readFields(CFRecord& record) //pictFmla.load(record, nLinkSize); record.skipNunBytes(nLinkSize); + int size = record.getDataSize() - record.getRdPtr(); + const char* data = record.getData() + record.getRdPtr(); + + ShortXLAnsiString name1; + if (size > 0) + { + record >> name1; + + if (old_version.name.value().empty()) + old_version.name = name1; + } if (continue_records.size() > 0) - {//embedded + {//embedded data std::list& recs = continue_records[rt_Continue]; if (recs.size()) diff --git a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/OperatorPtgs.h b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/OperatorPtgs.h index bcd95967d3..e4d83b5c1d 100644 --- a/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/OperatorPtgs.h +++ b/ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/OperatorPtgs.h @@ -62,6 +62,9 @@ public: std::wstring operand2(ptg_stack.top()); ptg_stack.pop(); + + if (ptg_stack.empty()) + return; ptg_stack.top() += getOperatorSymbols() + operand2; }; virtual const unsigned short getPtgId() const {return fixedPtgId;}; diff --git a/ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp b/ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp index 5aac620a57..857c19c714 100644 --- a/ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp +++ b/ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp @@ -157,6 +157,7 @@ XlsConverter::XlsConverter(const std::wstring & xlsFileName, const std::wstring xls_global_info->fontsDirectory = fontsPath; xls_global_info->password = password; xls_global_info->tempDirectory = tempPath; + xls_global_info->CodePage = 0; XLS::GlobalWorkbookInfo::_sheet_info sheet_info; xls_global_info->sheets_info.push_back(sheet_info); @@ -1082,7 +1083,8 @@ void XlsConverter::convert(XLS::IMDATA * imdata) std::wstring type_image; if (imdata->cf == 0x09 && imdata->env == 0x01) type_image = L".wmf"; - if (imdata->cf == 0x09 && imdata->env == 0x02) type_image = L".pict"; + if ((imdata->cf == 0x09 || imdata->cf == 0x02) + && imdata->env == 0x02) type_image = L".pict"; if (imdata->cf == 0x09) type_image = L"dib_data"; if (imdata->cf == 0x0e) type_image = L""; //native aka unknown diff --git a/ASCOfficeXlsFile2/source/XlsXlsxConverter/oox_package.cpp b/ASCOfficeXlsFile2/source/XlsXlsxConverter/oox_package.cpp index 710f6c3b64..da11b1393f 100644 --- a/ASCOfficeXlsFile2/source/XlsXlsxConverter/oox_package.cpp +++ b/ASCOfficeXlsFile2/source/XlsXlsxConverter/oox_package.cpp @@ -67,6 +67,7 @@ static std::wstring get_mime_type(const std::wstring & extension) else if (L"doc" == extension) return L"application/vnd.ms-word"; else if (L"vsd" == extension) return L"application/vnd.visio"; else if (L"vsdx" == extension) return L"application/vnd.ms-visio.drawing"; + else if (L"pict" == extension) return L"image/pict"; return L""; } diff --git a/Common/3dParty/curl/.gitignore b/Common/3dParty/curl/.gitignore new file mode 100644 index 0000000000..53efc092d8 --- /dev/null +++ b/Common/3dParty/curl/.gitignore @@ -0,0 +1 @@ +curl-* \ No newline at end of file diff --git a/Common/3dParty/curl/curl.pri b/Common/3dParty/curl/curl.pri index 31ec261bdd..d1178d404e 100644 --- a/Common/3dParty/curl/curl.pri +++ b/Common/3dParty/curl/curl.pri @@ -8,11 +8,11 @@ core_android { ABI_PATH = $$replace(ABI_PATH, "arm64_v8a", "arm64-v8a") } INCLUDEPATH += \ - $$PWD/android/build/$$ABI_PATH/include \ - $$PWD/../openssl/android/build/$$ABI_PATH/include \ + $$PWD/build/android/$$ABI_PATH/include \ + $$PWD/../openssl/build/android/$$ABI_PATH/include \ LIBS += \ - $$PWD/android/build/$$ABI_PATH/lib/libcurl.a \ - $$PWD/../openssl/android/build/$$ABI_PATH/lib/libssl.a \ - $$PWD/../openssl/android/build/$$ABI_PATH/lib/libcrypto.a \ + $$PWD/build/android/$$ABI_PATH/lib/libcurl.a \ + $$PWD/../openssl/build/android/$$ABI_PATH/lib/libssl.a \ + $$PWD/../openssl/build/android/$$ABI_PATH/lib/libcrypto.a \ } diff --git a/Common/3dParty/ixwebsocket/ixwebsocket.pri b/Common/3dParty/ixwebsocket/ixwebsocket.pri index 2c445be845..d6bcd40e46 100644 --- a/Common/3dParty/ixwebsocket/ixwebsocket.pri +++ b/Common/3dParty/ixwebsocket/ixwebsocket.pri @@ -1,3 +1,5 @@ +OPENSSL_LIBS_DIRECTORY = $$PWD/../openssl/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib + core_android { ABI_PATH = $$replace(CORE_BUILDS_PLATFORM_PREFIX, "android_", "") @@ -8,8 +10,10 @@ core_android { ABI_PATH = $$replace(ABI_PATH, "arm64_v8a", "arm64-v8a") } - INCLUDEPATH += $$PWD/../ixwebsocket/IXWebSocket/build/android/$$ABI_PATH/include - LIBS += $$PWD/../ixwebsocket/IXWebSocket/build/android/$$ABI_PATH/lib/libixwebsocket.a + INCLUDEPATH += $$PWD/../ixwebsocket/IXWebSocket/build/android/$$ABI_PATH/usr/include + LIBS += $$PWD/../ixwebsocket/IXWebSocket/build/android/$$ABI_PATH/usr/lib/libixwebsocket.a + + OPENSSL_LIBS_DIRECTORY = $$PWD/../openssl/build/android/$$ABI_PATH/lib } core_ios { @@ -50,9 +54,9 @@ core_windows { } core_windows { - LIBS += $$PWD/../openssl/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib/libssl.lib - LIBS += $$PWD/../openssl/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib/libcrypto.lib + LIBS += $$OPENSSL_LIBS_DIRECTORY/libssl.lib + LIBS += $$OPENSSL_LIBS_DIRECTORY/libcrypto.lib } else { - LIBS += $$PWD/../openssl/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib/libssl.a - LIBS += $$PWD/../openssl/build/$$CORE_BUILDS_PLATFORM_PREFIX/lib/libcrypto.a + LIBS += $$OPENSSL_LIBS_DIRECTORY/libssl.a + LIBS += $$OPENSSL_LIBS_DIRECTORY/libcrypto.a } diff --git a/Common/3dParty/openssl/.gitignore b/Common/3dParty/openssl/.gitignore new file mode 100644 index 0000000000..0a870cd626 --- /dev/null +++ b/Common/3dParty/openssl/.gitignore @@ -0,0 +1 @@ +openssl-* \ No newline at end of file diff --git a/Common/MS-LCID.h b/Common/MS-LCID.h index 28507c61f4..11650eca37 100644 --- a/Common/MS-LCID.h +++ b/Common/MS-LCID.h @@ -202,6 +202,7 @@ public: m_mapLCID.insert(std::make_pair( 0x0493, L"quc-CO")); m_mapLCID.insert(std::make_pair( 0x0501, L"qps-ploc")); m_mapLCID.insert(std::make_pair( 0x05fe, L"qps-ploca")); + m_mapLCID.insert(std::make_pair( 0x0801, L"ar-IQ")); m_mapLCID.insert(std::make_pair( 0x0803, L"ca-ES-valencia")); m_mapLCID.insert(std::make_pair( 0x0804, L"zh-CN")); @@ -372,121 +373,306 @@ public: m_mapLCID.insert(std::make_pair( 0x7c67, L"ff-Latn")); m_mapLCID.insert(std::make_pair( 0x7c68, L"ha-Latn")); m_mapLCID.insert(std::make_pair( 0x7c92, L"ku-Arab")); + m_mapLCID.insert(std::make_pair( 0x01, L"ar")); + m_mapLCID.insert(std::make_pair( 0x02, L"bg")); + m_mapLCID.insert(std::make_pair( 0x03, L"ca")); + m_mapLCID.insert(std::make_pair( 0x05, L"cs")); + m_mapLCID.insert(std::make_pair( 0x06, L"da")); + m_mapLCID.insert(std::make_pair( 0x07, L"de")); + m_mapLCID.insert(std::make_pair( 0x08, L"el")); + m_mapLCID.insert(std::make_pair( 0x09, L"en")); + m_mapLCID.insert(std::make_pair( 0x0A, L"es")); + m_mapLCID.insert(std::make_pair( 0x0B, L"fi")); + m_mapLCID.insert(std::make_pair( 0x0C, L"fr")); + m_mapLCID.insert(std::make_pair( 0x0D, L"he")); + m_mapLCID.insert(std::make_pair( 0x0E, L"hu")); + m_mapLCID.insert(std::make_pair( 0x0F, L"is")); + m_mapLCID.insert(std::make_pair( 0x10, L"it")); + m_mapLCID.insert(std::make_pair( 0x11, L"ja")); + m_mapLCID.insert(std::make_pair( 0x12, L"ko")); + m_mapLCID.insert(std::make_pair( 0x13, L"nl")); + m_mapLCID.insert(std::make_pair( 0x14, L"no")); + m_mapLCID.insert(std::make_pair( 0x15, L"pl")); + m_mapLCID.insert(std::make_pair( 0x16, L"pt")); + m_mapLCID.insert(std::make_pair( 0x17, L"rm")); + m_mapLCID.insert(std::make_pair( 0x18, L"ro")); + m_mapLCID.insert(std::make_pair( 0x19, L"ru")); + m_mapLCID.insert(std::make_pair( 0x1A, L"hr")); + m_mapLCID.insert(std::make_pair( 0x1B, L"sk")); + m_mapLCID.insert(std::make_pair( 0x1C, L"sq")); + m_mapLCID.insert(std::make_pair( 0x1D, L"sv")); + m_mapLCID.insert(std::make_pair( 0x1E, L"th")); + m_mapLCID.insert(std::make_pair( 0x1F, L"tr")); + m_mapLCID.insert(std::make_pair( 0x20, L"ur")); + m_mapLCID.insert(std::make_pair( 0x21, L"id")); + m_mapLCID.insert(std::make_pair( 0x22, L"uk")); + m_mapLCID.insert(std::make_pair( 0x23, L"be")); + m_mapLCID.insert(std::make_pair( 0x24, L"sl")); + m_mapLCID.insert(std::make_pair( 0x25, L"et")); + m_mapLCID.insert(std::make_pair( 0x26, L"lv")); + m_mapLCID.insert(std::make_pair( 0x27, L"lt")); + m_mapLCID.insert(std::make_pair( 0x28, L"tg")); + m_mapLCID.insert(std::make_pair( 0x29, L"fa")); + m_mapLCID.insert(std::make_pair( 0x2A, L"vi")); + m_mapLCID.insert(std::make_pair( 0x2B, L"hy")); + m_mapLCID.insert(std::make_pair( 0x2C, L"az")); + m_mapLCID.insert(std::make_pair( 0x2D, L"eu")); + m_mapLCID.insert(std::make_pair( 0x2E, L"hsb")); + m_mapLCID.insert(std::make_pair( 0x2F, L"mk")); + m_mapLCID.insert(std::make_pair( 0x30, L"st")); + m_mapLCID.insert(std::make_pair( 0x31, L"ts")); + m_mapLCID.insert(std::make_pair( 0x32, L"tn")); + m_mapLCID.insert(std::make_pair( 0x33, L"ve")); + m_mapLCID.insert(std::make_pair( 0x34, L"xh")); + m_mapLCID.insert(std::make_pair( 0x35, L"zu")); + m_mapLCID.insert(std::make_pair( 0x36, L"af")); + m_mapLCID.insert(std::make_pair( 0x37, L"ka")); + m_mapLCID.insert(std::make_pair( 0x38, L"fo")); + m_mapLCID.insert(std::make_pair( 0x39, L"hi")); + m_mapLCID.insert(std::make_pair( 0x3A, L"mt")); + m_mapLCID.insert(std::make_pair( 0x3B, L"se")); + m_mapLCID.insert(std::make_pair( 0x3C, L"ga")); + m_mapLCID.insert(std::make_pair( 0x3D, L"yi")); + m_mapLCID.insert(std::make_pair( 0x3E, L"ms")); + m_mapLCID.insert(std::make_pair( 0x3F, L"kk")); + m_mapLCID.insert(std::make_pair( 0x40, L"ky")); + m_mapLCID.insert(std::make_pair( 0x41, L"sw")); + m_mapLCID.insert(std::make_pair( 0x42, L"tk")); + m_mapLCID.insert(std::make_pair( 0x43, L"uz")); + m_mapLCID.insert(std::make_pair( 0x44, L"tt")); + m_mapLCID.insert(std::make_pair( 0x45, L"bn")); + m_mapLCID.insert(std::make_pair( 0x46, L"pa")); + m_mapLCID.insert(std::make_pair( 0x47, L"gu")); + m_mapLCID.insert(std::make_pair( 0x48, L"or")); + m_mapLCID.insert(std::make_pair( 0x49, L"ta")); + m_mapLCID.insert(std::make_pair( 0x4A, L"te")); + m_mapLCID.insert(std::make_pair( 0x4B, L"kn")); + m_mapLCID.insert(std::make_pair( 0x4C, L"ml")); + m_mapLCID.insert(std::make_pair( 0x4D, L"as")); + m_mapLCID.insert(std::make_pair( 0x4E, L"mr")); + m_mapLCID.insert(std::make_pair( 0x4F, L"sa")); + m_mapLCID.insert(std::make_pair( 0x50, L"mn")); + m_mapLCID.insert(std::make_pair( 0x51, L"bo")); + m_mapLCID.insert(std::make_pair( 0x52, L"cy")); + m_mapLCID.insert(std::make_pair( 0x53, L"km")); + m_mapLCID.insert(std::make_pair( 0x54, L"lo")); + m_mapLCID.insert(std::make_pair( 0x55, L"my")); + m_mapLCID.insert(std::make_pair( 0x56, L"gl")); + m_mapLCID.insert(std::make_pair( 0x57, L"kok")); + m_mapLCID.insert(std::make_pair( 0x58, L"mni")); + m_mapLCID.insert(std::make_pair( 0x59, L"sd")); + m_mapLCID.insert(std::make_pair( 0x5A, L"syr")); + m_mapLCID.insert(std::make_pair( 0x5B, L"si")); + m_mapLCID.insert(std::make_pair( 0x5C, L"chr")); + m_mapLCID.insert(std::make_pair( 0x5D, L"iu")); + m_mapLCID.insert(std::make_pair( 0x5E, L"am")); + m_mapLCID.insert(std::make_pair( 0x5F, L"tzm")); + m_mapLCID.insert(std::make_pair( 0x60, L"ks")); + m_mapLCID.insert(std::make_pair( 0x61, L"ne")); + m_mapLCID.insert(std::make_pair( 0x62, L"fy")); + m_mapLCID.insert(std::make_pair( 0x63, L"ps")); + m_mapLCID.insert(std::make_pair( 0x64, L"fil")); + m_mapLCID.insert(std::make_pair( 0x65, L"dv")); + m_mapLCID.insert(std::make_pair( 0x66, L"bin")); + m_mapLCID.insert(std::make_pair( 0x67, L"ff")); + m_mapLCID.insert(std::make_pair( 0x68, L"ha")); + m_mapLCID.insert(std::make_pair( 0x69, L"ibb")); + m_mapLCID.insert(std::make_pair( 0x6A, L"yo")); + m_mapLCID.insert(std::make_pair( 0x6B, L"quz")); + m_mapLCID.insert(std::make_pair( 0x6C, L"nso")); + m_mapLCID.insert(std::make_pair( 0x6D, L"ba")); + m_mapLCID.insert(std::make_pair( 0x6E, L"lb")); + m_mapLCID.insert(std::make_pair( 0x6F, L"kl")); + m_mapLCID.insert(std::make_pair( 0x70, L"ig")); + m_mapLCID.insert(std::make_pair( 0x71, L"kr")); + m_mapLCID.insert(std::make_pair( 0x72, L"om")); + m_mapLCID.insert(std::make_pair( 0x73, L"ti")); + m_mapLCID.insert(std::make_pair( 0x74, L"gn")); + m_mapLCID.insert(std::make_pair( 0x75, L"haw")); + m_mapLCID.insert(std::make_pair( 0x76, L"la")); + m_mapLCID.insert(std::make_pair( 0x77, L"so")); + m_mapLCID.insert(std::make_pair( 0x78, L"ii")); + m_mapLCID.insert(std::make_pair( 0x79, L"pap")); + m_mapLCID.insert(std::make_pair( 0x7A, L"arn")); + m_mapLCID.insert(std::make_pair( 0x7C, L"moh")); + m_mapLCID.insert(std::make_pair( 0x7E, L"br")); + m_mapLCID.insert(std::make_pair( 0x80, L"ug")); + m_mapLCID.insert(std::make_pair( 0x81, L"mi")); + m_mapLCID.insert(std::make_pair( 0x82, L"oc")); + m_mapLCID.insert(std::make_pair( 0x83, L"co")); + m_mapLCID.insert(std::make_pair( 0x84, L"gsw")); + m_mapLCID.insert(std::make_pair( 0x85, L"sah")); + m_mapLCID.insert(std::make_pair( 0x86, L"quc")); + m_mapLCID.insert(std::make_pair( 0x87, L"rw")); + m_mapLCID.insert(std::make_pair( 0x88, L"wo")); + m_mapLCID.insert(std::make_pair( 0x8C, L"prs")); + m_mapLCID.insert(std::make_pair( 0x91, L"gd")); + m_mapLCID.insert(std::make_pair( 0x92, L"ku")); - m_mapLCID2DefCodePage.insert(std::make_pair( 1078, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1052, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 5121, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 15361, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 3073, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2049, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 11265, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 13313, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 12289, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 4097, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 6145, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 8193, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 16385, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1025, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 10241, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 7169, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 14337, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 9217, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2092, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1068, 1254)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1069, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1059, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1026, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1027, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1050, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1029, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1030, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2067, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1043, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 3081, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 10249, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 4105, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 9225, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2057, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 6153, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 8201, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 5129, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 13321, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 7177, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 11273, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1033, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 12297, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1061, 1257)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1071, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1080, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1065, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1035, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2060, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 3084, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1036, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 5132, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 6156, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 4108, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1110, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 3079, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1031, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 5127, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 4103, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2055, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1032, 1253)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1037, 1255)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1038, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1039, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1057, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1040, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2064, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1087, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1088, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1062, 1257)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1063, 1257)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2110, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1086, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1104, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1044, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2068, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1045, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1046, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2070, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1048, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1049, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 3098, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2074, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1051, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1060, 1250)); - m_mapLCID2DefCodePage.insert(std::make_pair( 11274, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 16394, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 13322, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 9226, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 5130, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 7178, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 12298, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 17418, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 4106, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 18442, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2058, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 19466, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 6154, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 15370, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 10250, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 20490, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1034, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 14346, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 8202, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1089, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2077, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1053, 1252)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1092, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1055, 1254)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1058, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1056, 1256)); - m_mapLCID2DefCodePage.insert(std::make_pair( 2115, 1251)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1091, 1254)); - m_mapLCID2DefCodePage.insert(std::make_pair( 1066, 1258)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x401, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x402, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x403, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x405, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x406, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x407, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x408, 1253)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x409, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40B, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40D, 1255)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40E, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40F, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x410, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x413, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x414, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x415, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x416, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x418, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x419, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x41A, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x41B, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x41C, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x41D, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x41F, 1254)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x420, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x421, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x422, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x423, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x424, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x425, 1257)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x426, 1257)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x427, 1257)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x429, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x42A, 1258)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x42C, 1254)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x42D, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x42F, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x436, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x438, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x43E, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x43F, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x440, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x441, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x443, 1254)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x444, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x450, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x456, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1401, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3C01, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0xC01, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x801, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2C01, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3401, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3001, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1001, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1801, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2001, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x4001, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2801, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1C01, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3801, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2401, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x82C, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x813, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0xC09, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2809, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1009, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2409, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x809, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1809, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2009, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1409, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3409, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1C09, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2C09, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3009, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x80C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0xC0C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x140C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x180C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x100C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0xC07, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1407, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1007, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x807, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x810, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x83E, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x814, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x816, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0xC1A, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x81A, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2C0A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x400A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x340A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x240A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x140A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1C0A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x300A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x440A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x100A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x480A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x80A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x4C0A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x180A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3C0A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x280A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x500A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x380A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x200A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x81D, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x843, 1251)); + + m_mapLCID2DefCodePage.insert(std::make_pair(0x01, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x02, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x03, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x05, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x06, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x07, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x08, 1253)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x09, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x0A, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x0B, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x0C, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x0D, 1255)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x0E, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x0F, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x10, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x13, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x14, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x15, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x16, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x18, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x19, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1A, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1B, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1C, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1D, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x1F, 1254)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x20, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x21, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x22, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x23, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x24, 1250)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x25, 1257)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x26, 1257)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x27, 1257)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x29, 1256)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2A, 1258)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2C, 1254)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2D, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x2F, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x36, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x38, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3E, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x3F, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x40, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x41, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x43, 1254)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x44, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x50, 1251)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x56, 1252)); } }; diff --git a/Common/Network/FileTransporter/filetransporter.pri b/Common/Network/FileTransporter/filetransporter.pri index ce081df5a3..f38753dce2 100644 --- a/Common/Network/FileTransporter/filetransporter.pri +++ b/Common/Network/FileTransporter/filetransporter.pri @@ -41,6 +41,4 @@ core_android { SOURCES += $$PWD/src/FileTransporter_curl.cpp !use_external_transport:include($$PWD/../../3dParty/curl/curl.pri) - - DEFINES += NOT_USE_PTHREAD_CANCEL } diff --git a/Common/Network/FileTransporter/src/FileTransporter_curl.cpp b/Common/Network/FileTransporter/src/FileTransporter_curl.cpp index c926a2f1fb..bf17480474 100644 --- a/Common/Network/FileTransporter/src/FileTransporter_curl.cpp +++ b/Common/Network/FileTransporter/src/FileTransporter_curl.cpp @@ -95,7 +95,7 @@ namespace NSNetwork CURL *curl; int fp; CURLcode res; - std::string sUrl = U_TO_UTF8(m_sFileUrl); + std::string sUrl = U_TO_UTF8(m_sDownloadFileUrl); std::string sOut; const char *url = sUrl.c_str(); curl = curl_easy_init(); diff --git a/Common/OfficeFileFormatChecker2.cpp b/Common/OfficeFileFormatChecker2.cpp index aceed22fd0..ffc0290201 100644 --- a/Common/OfficeFileFormatChecker2.cpp +++ b/Common/OfficeFileFormatChecker2.cpp @@ -70,6 +70,12 @@ bool COfficeFileFormatChecker::isHtmlFormatFile(unsigned char* pBuffer, int dwBy { return true; } + else if ((0x3C == pBuffer[i]) && (0x2F == pBuffer[i + 1]) && (0x62 == pBuffer[i + 2]) + && (0x6f == pBuffer[i + 3]) && (0x64 == pBuffer[i + 4]) && (0x79 == pBuffer[i + 5]) + && (0x3e == pBuffer[i + 6])) + {// + return true; + } } } else if (dwBytes > 3) @@ -886,6 +892,7 @@ std::wstring COfficeFileFormatChecker::GetExtensionByType(int type) switch (type) { case AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM: return L".oform"; + case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF: return L".docxf"; case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX: return L".docx"; case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM: return L".docm"; case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX: return L".dotx"; @@ -948,7 +955,7 @@ std::wstring COfficeFileFormatChecker::GetExtensionByType(int type) case AVS_OFFICESTUDIO_FILE_IMAGE_PSD: return L".psd"; case AVS_OFFICESTUDIO_FILE_IMAGE_ICO: return L".ico"; - case AVS_OFFICESTUDIO_FILE_CANVAS_WORD: + case AVS_OFFICESTUDIO_FILE_CANVAS_WORD: case AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET: case AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION: return L".bin"; case AVS_OFFICESTUDIO_FILE_OTHER_OLD_DOCUMENT: @@ -967,6 +974,8 @@ int COfficeFileFormatChecker::GetFormatByExtension(const std::wstring& ext) return AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; if (L".oform" == ext) return AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; //AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM + if (L".docxf" == ext) + return AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; //AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF if (L".docm" == ext) return AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM; if (L".dotx" == ext) diff --git a/Common/OfficeFileFormats.h b/Common/OfficeFileFormats.h index 5855661387..1d402787ec 100644 --- a/Common/OfficeFileFormats.h +++ b/Common/OfficeFileFormats.h @@ -54,6 +54,7 @@ #define AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML_IN_CONTAINER AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0012 #define AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX_PACKAGE AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0014 #define AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0015 +#define AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0016 #define AVS_OFFICESTUDIO_FILE_PRESENTATION 0x0080 #define AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0001 diff --git a/Common/kernel.pro b/Common/kernel.pro index 4ed6917c0e..ee6ad7c6e6 100644 --- a/Common/kernel.pro +++ b/Common/kernel.pro @@ -37,6 +37,7 @@ SOURCES += \ ./../DesktopEditor/graphics/TemporaryCS.cpp # THREAD +core_android:DEFINES += NOT_USE_PTHREAD_CANCEL HEADERS += \ ./../DesktopEditor/graphics/BaseThread.h diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 40c391e862..95adde0c12 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -324,6 +324,10 @@ public: public: CTextFormPr() { + m_unMaxCharacters = 0; + m_bComb = false; + m_bAutoFit = false; + m_bMultiLine = false; } void SetTextValue(const std::wstring& wsValue) { @@ -378,7 +382,9 @@ public: { public: CDropDownFormPr() - {} + { + m_bEditComboBox = false; + } void SetTextValue(const std::wstring& wsValue) { @@ -419,7 +425,12 @@ public: { public: CCheckBoxFormPr() - {} + { + m_bChecked = false; + m_unType = 0; + m_unCheckedSymbol = 0x2612; + m_unUncheckedSymbol = 0x2610; + } bool IsChecked() const { return m_bChecked; @@ -427,6 +438,14 @@ public: void SetChecked(const bool& bChecked) { m_bChecked = bChecked; + } + unsigned int GetType() const + { + return m_unType; + } + void SetType(const unsigned int& unType) + { + m_unType = unType; } unsigned int GetCheckedSymbol() const { @@ -476,6 +495,7 @@ public: private: bool m_bChecked; + unsigned int m_unType; unsigned int m_unCheckedSymbol; unsigned int m_unUncheckedSymbol; std::wstring m_wsCheckedFont; @@ -486,7 +506,13 @@ public: { public: CPictureFormPr() - {} + { + m_eScaleType = EScaleType::Always; + m_bRespectBorders = false; + m_bConstantProportions = true; + m_lShiftX = 500; + m_lShiftY = 500; + } bool IsConstantProportions() const { return m_bConstantProportions; @@ -524,13 +550,22 @@ public: { return m_lShiftY; } + void SetPicturePath(const std::wstring& wsPath) + { + m_wsPicturePath = wsPath; + } + const std::wstring& GetPicturePath() const + { + return m_wsPicturePath; + } private: - EScaleType m_eScaleType; - bool m_bRespectBorders; - bool m_bConstantProportions; - LONG m_lShiftX; - LONG m_lShiftY; + EScaleType m_eScaleType; + bool m_bRespectBorders; + bool m_bConstantProportions; + LONG m_lShiftX; + LONG m_lShiftY; + std::wstring m_wsPicturePath; }; public: @@ -550,6 +585,13 @@ public: m_nBorderType = 0; + // 0 - Right + // 1 - Left + // 2 - Center + // 3 - Justify + // 4 - Distributed + m_nJc = 1; + m_bHaveShd = false; } @@ -654,7 +696,14 @@ public: unG = ((m_lShdColor >> 8) & 0xFF); unB = ((m_lShdColor) & 0xFF); } - + void SetJc(const unsigned char& unJc) + { + m_nJc = unJc; + } + BYTE GetJc() const + { + return m_nJc; + } bool IsTextField() const { @@ -723,6 +772,7 @@ private: LONG m_lBorderColor; bool m_bHaveShd; LONG m_lShdColor; + BYTE m_nJc; CTextFormPr m_oTextPr; CDropDownFormPr m_oDropDownPr; diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index ad4f4f3691..00e884fc5a 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -922,6 +922,11 @@ namespace NSOnlineOfficeBinToPdf oInfo.SetShd(unR, unG, unB, unA); } + if (nFlags & (1 << 10)) + { + oInfo.SetJc(ReadByte(current, curindex)); + } + oInfo.SetType(ReadInt(current, curindex)); if (oInfo.IsTextField()) @@ -935,8 +940,8 @@ namespace NSOnlineOfficeBinToPdf if (nFlags & (1 << 22)) pPr->SetTextValue(ReadString(current, curindex)); - pPr->SetAutoFit(nFlags & (1 << 23)); - pPr->SetMultiLine(nFlags & (1 << 24)); + pPr->SetMultiLine(nFlags & (1 << 23)); + pPr->SetAutoFit(nFlags & (1 << 24)); } else if (oInfo.IsDropDownList()) { @@ -958,6 +963,7 @@ namespace NSOnlineOfficeBinToPdf { CFormFieldInfo::CCheckBoxFormPr* pPr = oInfo.GetCheckBoxFormPr(); pPr->SetChecked(nFlags & (1 << 20)); + pPr->SetType(ReadInt(current, curindex)); pPr->SetCheckedSymbol(ReadInt(current, curindex)); pPr->SetCheckedFont(ReadString(current, curindex)); pPr->SetUncheckedSymbol(ReadInt(current, curindex)); @@ -975,6 +981,9 @@ namespace NSOnlineOfficeBinToPdf LONG lShiftX = ReadInt(current, curindex); LONG lShiftY = ReadInt(current, curindex); pPr->SetShift(lShiftX, lShiftY); + + if (nFlags & (1 << 22)) + pPr->SetPicturePath(pCorrector->GetImagePath(ReadString(current, curindex))); } if (oInfo.IsValid()) diff --git a/OfficeCryptReader/Test/Test.sln b/OfficeCryptReader/Test/Test.sln index e46a2f5707..3792276fd5 100644 --- a/OfficeCryptReader/Test/Test.sln +++ b/OfficeCryptReader/Test/Test.sln @@ -1,17 +1,13 @@  -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}" - ProjectSection(ProjectDependencies) = postProject - {C27E9A9F-3A17-4482-9C5F-BF15C01E747C} = {C27E9A9F-3A17-4482-9C5F-BF15C01E747C} - EndProjectSection +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{BE4AA52B-8AF0-48DD-8240-CCBA6F84D7A2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OfficeFileCrypt", "..\win32\ECMACryptReader.vcproj", "{C27E9A9F-3A17-4482-9C5F-BF15C01E747C}" - ProjectSection(ProjectDependencies) = postProject - {3423EC9A-52E4-4A4D-9753-EDEBC38785EF} = {3423EC9A-52E4-4A4D-9753-EDEBC38785EF} - EndProjectSection +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OfficeFileCrypt", "..\win32\ECMACryptReader.vcxproj", "{C27E9A9F-3A17-4482-9C5F-BF15C01E747C}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cryptlib", "..\..\Common\3dParty\cryptopp\cryptlib.vcproj", "{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cryptlib", "..\..\Common\3dParty\cryptopp\cryptlib.vcxproj", "{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/OfficeCryptReader/win32/ECMACryptReader.vcxproj b/OfficeCryptReader/win32/ECMACryptReader.vcxproj index 80a00823b3..eb058a6764 100644 --- a/OfficeCryptReader/win32/ECMACryptReader.vcxproj +++ b/OfficeCryptReader/win32/ECMACryptReader.vcxproj @@ -64,7 +64,7 @@ - <_ProjectFileVersion>14.0.23107.0 + <_ProjectFileVersion>14.0.25431.1 $(SolutionDir)$(Configuration)\ @@ -75,8 +75,6 @@ $(SolutionDir)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ - $(VC_IncludePath);$(WindowsSDK_IncludePath);D:\_Work\core\Common\3dParty\boost\build\win_64\include; - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;D:\_Work\core\Common\3dParty\boost\build\win_64\lib; $(SolutionDir)$(Configuration)\ @@ -107,7 +105,7 @@ Disabled - WIN32;_DEBUG;_LIB;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED;DONT_WRITE_EMBEDDED_FONTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;USE_LITE_READER;_USE_XMLLITE_READER_;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED;%(PreprocessorDefinitions) true EnableFastChecks MultiThreadedDebugDLL @@ -148,6 +146,7 @@ {3423ec9a-52e4-4a4d-9753-edebc38785ef} + false diff --git a/PdfWriter/PdfRenderer.cpp b/PdfWriter/PdfRenderer.cpp index 96df25bf21..2c740eea19 100644 --- a/PdfWriter/PdfRenderer.cpp +++ b/PdfWriter/PdfRenderer.cpp @@ -39,6 +39,7 @@ #include "Src/Image.h" #include "Src/Font.h" #include "Src/FontCidTT.h" +#include "Src/FontTT.h" #include "Src/Annotation.h" #include "Src/Destination.h" #include "Src/Field.h" @@ -1528,6 +1529,10 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) if (!m_pFont) return S_OK; + PdfWriter::CFontTrueType* pFontTT = m_pDocument->CreateTrueTypeFont(m_pFont); + if (!pFontTT) + return S_OK; + double dX, dY, dW, dH; oInfo.GetBounds(dX, dY, dW, dH); @@ -1549,7 +1554,14 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) CTextField* pField = m_pDocument->CreateTextField(); pFieldBase = static_cast(pField); - pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); + double _dY = m_pPage->GetHeight() - MM_2_PT(dY); + double _dB = m_pPage->GetHeight() - MM_2_PT(dY + dH); + + double dMargin = 2; // такой отступ используется в AdobeReader + double dBaseLine = MM_2_PT(dH - oInfo.GetBaseLineOffset()); + double dShiftX = dMargin; + + pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX) - dMargin, _dY, MM_2_PT(dX + dW) + dMargin, _dB)); pField->SetMaxLen(pPr->GetMaxCharacters()); pField->SetCombFlag(pPr->IsComb()); @@ -1583,21 +1595,96 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) } } - TColor oColor = m_oBrush.GetTColor1(); - if (oInfo.IsPlaceHolder()) + unsigned int unAlign = oInfo.GetJc(); + + TColor oColor = m_oBrush.GetTColor1(); + bool isPlaceHolder = oInfo.IsPlaceHolder(); + double dAlpha = isPlaceHolder ? 0.5 : 1; + + if (!isPlaceHolder) + pField->SetTextValue(wsValue); + + if (pPr->IsMultiLine()) { - pField->SetTextAppearance(wsValue, pCodes, unLen * 2, m_pFont, TRgb(oColor.r, oColor.g, oColor.b), 0.5, m_oFont.GetSize(), 0, MM_2_PT(dH - oInfo.GetBaseLineOffset()), pShifts, unShiftsCount); + double dFontSize = m_oFont.GetSize(); + unsigned short* pCodes2 = new unsigned short[unLen]; + unsigned int* pWidths = new unsigned int[unLen]; + + unsigned short ushSpaceCode = 0xFFFF; + for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex) + { + pCodes2[unIndex] = (static_cast((pCodes[unIndex * 2] << 8) & 0xFFFF) | static_cast((pCodes[unIndex * 2 + 1]))); + pWidths[unIndex] = m_pFont->GetWidth(pCodes2[unIndex]); + if (0x0020 == pUnicodes[unIndex]) + ushSpaceCode = pCodes2[unIndex]; + } + + m_oLinesManager.Init(pCodes2, pWidths, unLen, ushSpaceCode, pFontTT->GetLineHeight(), pFontTT->GetAscent()); + + // TODO: Разобраться более детально по какой именно высоте идет в Adobe расчет + // пока временно оставим (H - 3 * margin) + if (pPr->IsAutoFit()) + dFontSize = m_oLinesManager.ProcessAutoFit(MM_2_PT(dW), (MM_2_PT(dH) - 3 * dMargin)); + + double dLineHeight = pFontTT->GetLineHeight() * dFontSize / 1000.0; + + m_oLinesManager.CalculateLines(dFontSize, MM_2_PT(dW)); + + pField->StartTextAppearance(m_pFont, dFontSize, TRgb(oColor.r, oColor.g, oColor.b), dAlpha); + + unsigned int unLinesCount = m_oLinesManager.GetLinesCount(); + double dLineShiftY = MM_2_PT(dH) - pFontTT->GetLineHeight() * dFontSize / 1000.0 - dMargin; + for (unsigned int unIndex = 0; unIndex < unLinesCount; ++unIndex) + { + unsigned int unLineStart = m_oLinesManager.GetLineStartPos(unIndex); + double dLineShiftX = dShiftX; + double dLineWidth = m_oLinesManager.GetLineWidth(unIndex, dFontSize); + if (0 == unAlign) + dLineShiftX += MM_2_PT(dW) - dLineWidth; + else if (2 == unAlign) + dLineShiftX += (MM_2_PT(dW) - dLineWidth) / 2; + + int nInLineCount = m_oLinesManager.GetLineEndPos(unIndex) - m_oLinesManager.GetLineStartPos(unIndex); + if (nInLineCount > 0) + pField->AddLineToTextAppearance(dLineShiftX, dLineShiftY, pCodes + (2 * unLineStart), nInLineCount * 2, pShifts ? (pShifts + unLineStart) : NULL, unShiftsCount ? nInLineCount : 0); + + dLineShiftY -= dLineHeight; + } + + pField->EndTextAppearance(); + + m_oLinesManager.Clear(); + + delete[] pCodes2; + delete[] pWidths; } else { - pField->SetTextValue(wsValue); - pField->SetTextAppearance(wsValue, pCodes, unLen * 2, m_pFont, TRgb(oColor.r, oColor.g, oColor.b), 1, m_oFont.GetSize(), 0, MM_2_PT(dH - oInfo.GetBaseLineOffset()), pShifts, unShiftsCount); + if (0 == unAlign || 2 == unAlign) + { + double dSumWidth = 0; + for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex) + { + unsigned short ushCode = (static_cast((pCodes[unIndex * 2] << 8) & 0xFFFF) | static_cast((pCodes[unIndex * 2 + 1]))); + double dLetterWidth = m_pFont->GetWidth(ushCode) / 1000.0 * m_oFont.GetSize(); + dSumWidth += dLetterWidth; + } + + if (0 == unAlign && MM_2_PT(dW) - dSumWidth > 0) + dShiftX += MM_2_PT(dW) - dSumWidth; + else if (2 == unAlign && (MM_2_PT(dW) - dSumWidth) / 2 > 0) + dShiftX += (MM_2_PT(dW) - dSumWidth) / 2; + } + + pField->SetTextAppearance(wsValue, pCodes, unLen * 2, m_pFont, TRgb(oColor.r, oColor.g, oColor.b), dAlpha, m_oFont.GetSize(), dShiftX, dBaseLine, pShifts, unShiftsCount); } if (pShifts) delete[] pShifts; - delete[] pCodes; + delete[] pCodes; + + pField->SetDefaultAppearance(pFontTT, m_oFont.GetSize(), TRgb(oColor.r, oColor.g, oColor.b)); } else if (oInfo.IsDropDownList()) { @@ -1638,6 +1725,8 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pField->SetComboFlag(true); pField->SetEditFlag(!pPr->IsEditComboBox()); + + pField->SetDefaultAppearance(pFontTT, m_oFont.GetSize(), TRgb(oColor.r, oColor.g, oColor.b)); } else if (oInfo.IsCheckBox()) { @@ -1680,8 +1769,7 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) TColor oColor = m_oBrush.GetTColor1(); pField->SetAppearance(L"", pCheckedCodes, 2, pCheckedFont, L"", pUncheckedCodes, 2, pUncheckedFont, TRgb(oColor.r, oColor.g, oColor.b), 1, m_oFont.GetSize(), 0, MM_2_PT(dH - oInfo.GetBaseLineOffset())); - - } + } } else if (oInfo.IsPicture()) { @@ -1689,16 +1777,26 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) CPictureField* pField = m_pDocument->CreatePictureField(); pFieldBase = static_cast(pField); - pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); - pField->SetAppearance(); + pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); pField->SetConstantProportions(pPr->IsConstantProportions()); pField->SetRespectBorders(pPr->IsRespectBorders()); pField->SetScaleType(static_cast(pPr->GetScaleType())); - pField->SetShift(pPr->GetShiftX() / 1000.0, (1000 - pPr->GetShiftY()) / 1000.0); + pField->SetShift(pPr->GetShiftX() / 1000.0, (1000 - pPr->GetShiftY()) / 1000.0); } if (pFieldBase) { + // 0 - Right + // 1 - Left + // 2 - Center + // 3 - Justify + // 4 - Distributed + unsigned int unAlign = oInfo.GetJc(); + if (0 == unAlign) + pFieldBase->SetAlign(CFieldBase::EFieldAlignType::Right); + else if (2 == unAlign) + pFieldBase->SetAlign(CFieldBase::EFieldAlignType::Center); + if (oInfo.HaveBorder()) { unsigned char unR, unG, unB, unA; @@ -1714,6 +1812,8 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pFieldBase->SetShd(TRgb(unR, unG, unB)); } + pFieldBase->SetRequiredFlag(oInfo.IsRequired()); + pFieldBase->SetFieldHint(oInfo.GetHelpText()); if (!bRadioButton) { @@ -1724,8 +1824,23 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pFieldBase->SetFieldName(m_oFieldsManager.GetNewFieldName()); } - pFieldBase->SetRequiredFlag(oInfo.IsRequired()); - pFieldBase->SetFieldHint(oInfo.GetHelpText()); + if (oInfo.IsPicture()) + { + CPictureField* pField = dynamic_cast(pFieldBase); + if (pField) + { + const CFormFieldInfo::CPictureFormPr* pPr = oInfo.GetPicturePr(); + std::wstring wsPath = pPr->GetPicturePath(); + CImageDict* pImage = NULL; + if (wsPath.length()) + { + Aggplus::CImage oImage(wsPath); + pImage = LoadImage(&oImage, 255); + } + + pField->SetAppearance(pImage); + } + } } return S_OK; @@ -2011,7 +2126,7 @@ PdfWriter::CFontCidTrueType* CPdfRenderer::GetFont(const std::wstring& wsFontPat std::wstring wsFontType = m_pFontManager->GetFontType(); if (L"TrueType" == wsFontType || L"OpenType" == wsFontType || L"CFF" == wsFontType) - pFont = m_pDocument->CreateTrueTypeFont(wsFontPath, lFaceIndex); + pFont = m_pDocument->CreateCidTrueTypeFont(wsFontPath, lFaceIndex); } return pFont; diff --git a/PdfWriter/PdfRenderer.h b/PdfWriter/PdfRenderer.h index f6d951676b..f6b01d79ae 100644 --- a/PdfWriter/PdfRenderer.h +++ b/PdfWriter/PdfRenderer.h @@ -52,6 +52,7 @@ namespace PdfWriter class CDocument; class CPage; class CFontCidTrueType; + class CFontTrueType; class CImageDict; class CShading; class CExtGrState; @@ -1586,6 +1587,244 @@ private: private: unsigned int m_unCounter; + }; + //---------------------------------------------------------------------------------------- + // + // CMultiLineTextManager + // + //---------------------------------------------------------------------------------------- + class CMultiLineTextManager + { + public: + CMultiLineTextManager() + { + m_pCodes = NULL; + m_pWidths = NULL; + m_unLen = 0; + m_ushSpaceCode = 0; + m_unLineHeight = 0; + m_nAscent = 0; + m_nDescent = 0; + } + void Init(unsigned short* pCodes, unsigned int* pWidths, const unsigned int& unLen, const unsigned short& ushSpaceCode, const unsigned int& unLineHeight, const int& nAscent) + { + m_pCodes = pCodes; + m_pWidths = pWidths; + m_unLen = unLen; + m_ushSpaceCode = ushSpaceCode; + m_unLineHeight = unLineHeight; + m_nAscent = nAscent; + m_nDescent = unLineHeight - nAscent; + } + void Clear() + { + m_pCodes = NULL; + m_pWidths = NULL; + m_unLen = 0; + m_ushSpaceCode = 0; + m_unLineHeight = 0; + m_nAscent = 0; + m_nDescent = 0; + } + void CalculateLines(const double& dFontSize, const double& dW) + { + m_vBreaks.clear(); + + bool bLineStart = true, bWord = false, bFirstItemOnLine = true; + + unsigned int unPos = 0, unWordStartPos = 0; + double dWordWidth = 0; + double dX = 0, dKoef = dFontSize / 1000.0; + + while (unPos < m_unLen) + { + if (IsSpace(unPos)) + { + dX += dWordWidth + m_pWidths[unPos] * dKoef; + bWord = false; + dWordWidth = 0; + bLineStart = false; + bFirstItemOnLine = false; + } + else + { + double dLetterWidth = m_pWidths[unPos] * dKoef; + if (dX + dWordWidth + dLetterWidth > dW) + { + if (bLineStart) + { + if (bFirstItemOnLine) + { + if (unPos != m_unLen - 1) + m_vBreaks.push_back(unPos + 1); + + unPos++; + } + else + { + m_vBreaks.push_back(unPos); + } + } + else + { + if (bWord) + { + m_vBreaks.push_back(unWordStartPos); + unPos = unWordStartPos; + } + else + { + m_vBreaks.push_back(unPos); + } + } + + dX = 0; + bWord = false; + dWordWidth = 0; + bLineStart = true; + bFirstItemOnLine = true; + continue; + } + + if (bWord) + { + dWordWidth += m_pWidths[unPos] * dKoef; + } + else + { + unWordStartPos = unPos; + bWord = true; + dWordWidth = m_pWidths[unPos] * dKoef; + } + + bFirstItemOnLine = false; + } + + unPos++; + } + } + double ProcessAutoFit(const double& dW, const double& dH) + { + double dGoodFontSize = 0; + + // Параметры подобраны для совместимости с AdobeReader + double dFontSize = 4; + double dFontSizeStep = 0.797 / 3.0; + + while (true) + { + CalculateLines(dFontSize, dW); + if (CheckHeight(dH, dFontSize)) + { + dGoodFontSize = dFontSize; + dFontSize += dFontSizeStep; + + if (dFontSize > 12) + { + dFontSize = 12; + break; + } + } + else + { + if (dGoodFontSize > 0.001) + { + dFontSize = dGoodFontSize; + break; + } + + dFontSize -= dFontSizeStep; + if (dFontSize < 4) + { + dFontSize = 4; + break; + } + } + } + + return (floor(dFontSize * 1000.0 + 0.5) / 1000.0); + } + unsigned int GetLinesCount() const + { + return m_vBreaks.size() + 1; + } + unsigned int GetLineStartPos(const int& nLineIndex) const + { + if (!nLineIndex || nLineIndex > m_vBreaks.size()) + return 0; + + return m_vBreaks[nLineIndex - 1]; + } + unsigned int GetLineEndPos(const int& nLineIndex) const + { + if (nLineIndex >= m_vBreaks.size()) + return m_unLen; + + return m_vBreaks[nLineIndex]; + } + double GetLineWidth(const int& nLineIndex, const double& dFontSize = 10.0) + { + if (nLineIndex < 0 || nLineIndex > m_vBreaks.size()) + return 0; + + unsigned int unStart = GetLineStartPos(nLineIndex); + unsigned int unEnd = GetLineEndPos(nLineIndex); + + double dWidth = 0; + double dKoef = dFontSize / 1000.0; + + while (unStart < unEnd) + { + if (IsSpace(unStart)) + unStart++; + else + break; + } + + while (unEnd > unStart && unEnd > 0) + { + if (IsSpace(unEnd - 1)) + unEnd--; + else + break; + } + + for (unsigned int unPos = unStart; unPos < unEnd; ++unPos) + { + dWidth += m_pWidths[unPos] * dKoef; + } + + return dWidth; + } + + + private: + + inline bool IsSpace(const unsigned int& unPos) const + { + return (m_pCodes[unPos] == m_ushSpaceCode); + } + inline bool CheckHeight(const double& dH, const double& dFontSize) const + { + double dKoef = dFontSize / 1000.0; + double dTest1 = dH - (m_nDescent * dKoef); + double dTest2 = GetLinesCount() * (m_unLineHeight * dKoef); + + return (GetLinesCount() * (m_unLineHeight * dKoef) < (dH - (m_nDescent * dKoef))); + } + + + private: + + unsigned short* m_pCodes; + unsigned int* m_pWidths; + unsigned int m_unLen; + unsigned short m_ushSpaceCode; + unsigned int m_unLineHeight; + int m_nAscent; + int m_nDescent; + + std::vector m_vBreaks; }; private: @@ -1621,6 +1860,7 @@ private: std::vector m_vFonts; std::vectorm_vDestinations; CFieldsManager m_oFieldsManager; + CMultiLineTextManager m_oLinesManager; bool m_bValid; diff --git a/PdfWriter/PdfWriter.pro b/PdfWriter/PdfWriter.pro index c73a562387..5a37d54814 100644 --- a/PdfWriter/PdfWriter.pro +++ b/PdfWriter/PdfWriter.pro @@ -59,12 +59,14 @@ HEADERS += \ Src/Consts.h \ Src/Destination.h \ Src/Document.h \ + Src/Encodings.h \ Src/Encrypt.h \ Src/EncryptDictionary.h \ Src/Field.h \ Src/Font.h \ Src/Font14.h \ Src/FontCidTT.h \ + Src/FontTT.h \ Src/FontTTWriter.h \ Src/GState.h \ Src/Image.h \ @@ -95,6 +97,7 @@ SOURCES += \ Src/Font.cpp \ Src/Font14.cpp \ Src/FontCidTT.cpp \ + Src/FontTT.cpp \ Src/FontTTWriter.cpp \ Src/GState.cpp \ Src/Image.cpp \ diff --git a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp index 5f302ea9c5..be494e4d53 100644 --- a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp +++ b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp @@ -39,7 +39,7 @@ using namespace PdfWriter; -std::wstring g_wsOutFolder = L"D:\\Work\\Test\\"; +std::wstring g_wsOutFolder = L"D:\\Work\\Test\\TextOnline\\"; void TestDocument1() { @@ -61,107 +61,124 @@ void TestField() { CDocument oPdf; oPdf.CreateNew(); + oPdf.SetPDFAConformanceMode(true); CPage* pPage = oPdf.AddPage(); - CFontDict* pFont = oPdf.CreateFont14(standard14fonts_Courier); + CFontDict* pFont2 = oPdf.CreateFont14(standard14fonts_Courier); - CTextField* pField1 = oPdf.CreateTextField(); - pField1->SetRequiredFlag(true); - pField1->AddPageRect(pPage, TRect(0, 100, 100, 0)); - pField1->SetFieldName(L"Test"); - pField1->SetFieldHint(L"Илья"); + CFontTrueType* pFont = oPdf.CreateTrueTypeFont(L"C:/Windows/Fonts/centaur.ttf", 0); - CTextField* pField2 = oPdf.CreateTextField(); - pField2->SetRequiredFlag(false); - pField2->SetCombFlag(true); - pField2->AddPageRect(pPage, TRect(200, 300, 300, 250)); - pField2->SetFieldName(L"Test"); - pField2->SetFieldHint(L"Hint"); + //CTextField* pField1 = oPdf.CreateTextField(); + //pField1->SetRequiredFlag(false); + //pField1->AddPageRect(pPage, TRect(0, 100, 100, 0)); + //pField1->SetFieldName(L"Test"); + //pField1->SetFieldHint(L"Илья"); + //pField1->SetAlign(CFieldBase::EFieldAlignType::Center); - CTextField* pField3 = oPdf.CreateTextField(); - pField3->SetRequiredFlag(false); - pField3->SetCombFlag(true); - pField3->AddPageRect(pPage, TRect(000, 500, 300, 450)); - pField3->SetFieldName(L"Test123"); - pField3->SetFieldHint(L"Hint123"); - //pField3->SetMaxLen(100); - pField3->SetTextValue(L"Enter text"); - pField3->SetTextAppearance(L"Enter text", NULL, 0, pFont, TRgb(0, 255, 0), 0.5, 40, 1, 14.3); + //CTextField* pField2 = oPdf.CreateTextField(); + //pField2->SetRequiredFlag(false); + //pField2->SetCombFlag(true); + //pField2->AddPageRect(pPage, TRect(200, 300, 300, 250)); + //pField2->SetFieldName(L"Test"); + //pField2->SetFieldHint(L"Hint"); + //pField2->SetDefaultAppearance((CFontDict*)pFont, 40, TRgb(0, 255, 0)); + //pField2->SetTextAppearance(L"Enter text", NULL, 0, (CFontDict*)pFont2, TRgb(255, 0, 0), 0.5, 40, 1, 14.3); + + //CTextField* pField3 = oPdf.CreateTextField(); + //pField3->SetRequiredFlag(false); + //pField3->SetCombFlag(true); + //pField3->AddPageRect(pPage, TRect(000, 500, 300, 450)); + //pField3->SetFieldName(L"Test123"); + //pField3->SetFieldHint(L"Hint123"); + ////pField3->SetMaxLen(100); + //pField3->SetTextValue(L"Enter text"); + //pField3->SetTextAppearance(L"Enter text", NULL, 0, pFont, TRgb(0, 255, 0), 0.5, 40, 1, 14.3); - CTextField* pField33 = oPdf.CreateTextField(); - pField33->SetRequiredFlag(false); - pField33->SetCombFlag(true); - pField33->AddPageRect(pPage, TRect(000, 400, 300, 350)); - pField33->SetFieldName(L"Test123"); - pField33->SetFieldHint(L"Hint123"); - //pField33->SetMaxLen(100); - pField33->SetAutoFit(true); - pField33->SetTextValue(L"Enter text"); - pField33->SetTextAppearance(L"Enter text", NULL, 0, pFont, TRgb(0, 255, 0), 0.5, 40, 1, 14.3); + //CTextField* pField33 = oPdf.CreateTextField(); + //pField33->SetRequiredFlag(false); + //pField33->SetCombFlag(true); + //pField33->AddPageRect(pPage, TRect(000, 400, 300, 350)); + //pField33->SetFieldName(L"Test123"); + //pField33->SetFieldHint(L"Hint123"); + ////pField33->SetMaxLen(100); + //pField33->SetAutoFit(true); + //pField33->SetTextValue(L"Enter text"); + //pField33->SetTextAppearance(L"Enter text", NULL, 0, pFont, TRgb(0, 255, 0), 0.5, 40, 1, 14.3); - CTextField* pField4 = oPdf.CreateTextField(); - pField4->SetRequiredFlag(false); - pField4->AddPageRect(pPage, TRect(400, 500, 500, 450)); - pField4->SetFieldName(L"Test1234"); - pField4->SetFieldHint(L"Hint1234"); - pField4->SetMaxLen(10); - pField4->SetCombFlag(true); - pField4->SetTextValue(L"Ilya"); - pField4->SetFieldBorder(border_subtype_Solid, TRgb(255, 0, 0), 1, 0, 0, 0); - pField4->SetTextAppearance(L"Ilya", NULL, 0, pFont, TRgb(255, 0, 0), 1, 40, 1, 14.3); + //CTextField* pField4 = oPdf.CreateTextField(); + //pField4->SetRequiredFlag(false); + //pField4->AddPageRect(pPage, TRect(400, 500, 500, 450)); + //pField4->SetFieldName(L"Test1234"); + //pField4->SetFieldHint(L"Hint1234"); + //pField4->SetMaxLen(10); + //pField4->SetCombFlag(true); + //pField4->SetTextValue(L"Ilya"); + //pField4->SetFieldBorder(border_subtype_Solid, TRgb(255, 0, 0), 1, 0, 0, 0); + //pField4->SetTextAppearance(L"Ilya", NULL, 0, pFont, TRgb(255, 0, 0), 1, 40, 1, 14.3); - CChoiceField* pComboBox = oPdf.CreateChoiceField(); - pComboBox->SetRequiredFlag(false); - pComboBox->AddPageRect(pPage, TRect(200, 600, 500, 550)); - pComboBox->SetFieldName(L"ComboBox1"); - pComboBox->SetFieldHint(L"Какой-то текст"); - pComboBox->SetTextValue(L"Ilya"); - pComboBox->AddOption(L"Зеленый"); - pComboBox->AddOption(L"Green"); - pComboBox->AddOption(L"Зеленый"); - pComboBox->SetComboFlag(true); - pComboBox->SetEditFlag(false); - pComboBox->SetFieldBorder(border_subtype_Solid, TRgb(0, 255, 0), 1, 0, 0, 0); - pComboBox->SetMultiSelectFlag(false); - pComboBox->SetTextAppearance(L"Ilya", NULL, 0, pFont, TRgb(255, 0, 0), 0.5, 40, 1, 14.3); + //CChoiceField* pComboBox = oPdf.CreateChoiceField(); + //pComboBox->SetRequiredFlag(false); + //pComboBox->AddPageRect(pPage, TRect(200, 600, 500, 550)); + //pComboBox->SetFieldName(L"ComboBox1"); + //pComboBox->SetFieldHint(L"Какой-то текст"); + //pComboBox->SetTextValue(L"Ilya"); + //pComboBox->AddOption(L"Зеленый"); + //pComboBox->AddOption(L"Green"); + //pComboBox->AddOption(L"Зеленый"); + //pComboBox->SetComboFlag(true); + //pComboBox->SetEditFlag(false); + //pComboBox->SetFieldBorder(border_subtype_Solid, TRgb(0, 255, 0), 1, 0, 0, 0); + //pComboBox->SetMultiSelectFlag(false); + //pComboBox->SetTextAppearance(L"Ilya", NULL, 0, pFont, TRgb(255, 0, 0), 0.5, 40, 1, 14.3); - CCheckBoxField* pCheckBox = oPdf.CreateCheckBoxField(); - pCheckBox->SetFieldName(L"CheckBox"); - pCheckBox->SetRequiredFlag(false); - pCheckBox->AddPageRect(pPage, TRect(50, 600, 100, 550)); - pCheckBox->SetValue(true); - pCheckBox->SetAppearance(L"1", NULL, 0, pFont, L"2", NULL, 0, pFont, TRgb(0, 0, 0), 1, 40, 0, 0); + //CCheckBoxField* pCheckBox = oPdf.CreateCheckBoxField(); + //pCheckBox->SetFieldName(L"CheckBox"); + //pCheckBox->SetRequiredFlag(false); + //pCheckBox->AddPageRect(pPage, TRect(50, 600, 100, 550)); + //pCheckBox->SetValue(true); + ////pCheckBox->SetAppearance(L"1", NULL, 0, pFont2, L"2", NULL, 0, pFont2, TRgb(0, 0, 0), 1, 40, 0, 0); + //pCheckBox->SetAppearance(1, TRgb(0, 0, 0), 1, 40, 0, 0); - CRadioGroupField* pRadioGroup = oPdf.GetRadioGroupField(L"RadioGroup"); - CCheckBoxField* pRadio1 = pRadioGroup->CreateKid(); - pRadio1->AddPageRect(pPage, TRect(50, 700, 100, 650)); - pRadio1->SetValue(true); - pRadio1->SetAppearance(L"3", NULL, 0, pFont, L"4", NULL, 0, pFont, TRgb(0, 0, 0), 1, 40, 0, 0); + //CRadioGroupField* pRadioGroup = oPdf.GetRadioGroupField(L"RadioGroup"); + //CCheckBoxField* pRadio1 = pRadioGroup->CreateKid(); + //pRadio1->AddPageRect(pPage, TRect(50, 700, 100, 650)); + //pRadio1->SetValue(true); + ////pRadio1->SetAppearance(L"3", NULL, 0, pFont2, L"4", NULL, 0, pFont2, TRgb(0, 0, 0), 1, 40, 0, 0); + //pRadio1->SetAppearance(2, TRgb(0, 0, 0), 1, 40, 0, 0); - CCheckBoxField* pRadio2 = pRadioGroup->CreateKid(); - pRadio2->AddPageRect(pPage, TRect(150, 700, 200, 650)); - pRadio2->SetValue(false); - pRadio2->SetAppearance(L"3", NULL, 0, pFont, L"4", NULL, 0, pFont, TRgb(0, 0, 0), 1, 40, 0, 0); + //CCheckBoxField* pRadio2 = pRadioGroup->CreateKid(L"TestName"); + //pRadio2->AddPageRect(pPage, TRect(150, 700, 200, 650)); + //pRadio2->SetValue(true); + ////pRadio2->SetAppearance(L"3", NULL, 0, pFont2, L"4", NULL, 0, pFont2, TRgb(0, 0, 0), 1, 40, 0, 0); + //pRadio2->SetAppearance(2, TRgb(0, 0, 0), 1, 40, 0, 0); - CCheckBoxField* pRadio3 = pRadioGroup->CreateKid(); - pRadio3->AddPageRect(pPage, TRect(250, 700, 300, 650)); - pRadio3->SetValue(false); - pRadio3->SetAppearance(L"3", NULL, 0, pFont, L"4", NULL, 0, pFont, TRgb(0, 0, 0), 1, 40, 0, 0); + //CCheckBoxField* pRadio3 = pRadioGroup->CreateKid(); + //pRadio3->AddPageRect(pPage, TRect(250, 700, 300, 650)); + //pRadio3->SetValue(false); + ////pRadio3->SetAppearance(L"3", NULL, 0, pFont2, L"4", NULL, 0, pFont2, TRgb(0, 0, 0), 1, 40, 0, 0); + //pRadio3->SetAppearance(2, TRgb(0, 0, 0), 1, 40, 0, 0); + + CImageDict* pImage = oPdf.CreateImage(); + pImage->LoadJpeg(L"D:/1429799187_5060172-vinni-puh-idet-v-gosti.jpg", 3872, 2592); + //pImage->LoadJpeg(L"D:/Fry.jpg", 240, 240); + + pPage->DrawImage(pImage, 0, 0, 10, 10); CPictureField* pPictureField = oPdf.CreatePictureField(); pPictureField->SetRequiredFlag(false); pPictureField->AddPageRect(pPage, TRect(100, 100, 500, 650)); pPictureField->SetFieldName(L"Pic"); pPictureField->SetFieldHint(L"Картинка"); - pPictureField->SetAppearance(); pPictureField->SetShift(0.25, 0.75); - pPictureField->SetScaleType(CPictureField::EScaleType::Smaller); - pPictureField->SetFieldBorder(border_subtype_Solid, TRgb(255, 0, 0), 1, 0, 0, 0); + pPictureField->SetScaleType(CPictureField::EScaleType::Bigger); + pPictureField->SetFieldBorder(border_subtype_Solid, TRgb(255, 0, 0), 3, 0, 0, 0); pPictureField->SetShd(TRgb(0, 0, 255)); pPictureField->SetRespectBorders(true); + pPictureField->SetAppearance(pImage); + oPdf.SaveToFile(g_wsOutFolder + L"TestField1.pdf"); oPdf.Close(); } @@ -634,8 +651,8 @@ void TestDocument7() pPage->SetHeight(600); pPage->SetWidth(1000); - //CFontCidTrueType* pFont = oPdf.CreateTrueTypeFont(L"D:/test/_pdf/Test.ttf", 0); - CFontCidTrueType* pFont = oPdf.CreateTrueTypeFont(L"D:/test/_pdf/cambria.ttc", 1); + //CFontCidTrueType* pFont = oPdf.CreateCidTrueTypeFont(L"D:/test/_pdf/Test.ttf", 0); + CFontCidTrueType* pFont = oPdf.CreateCidTrueTypeFont(L"D:/test/_pdf/cambria.ttc", 1); pPage->BeginText(); diff --git a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj index 9b21c830fe..576a7f762f 100644 --- a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj +++ b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj @@ -160,12 +160,14 @@ + + @@ -248,6 +250,7 @@ + diff --git a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj.filters b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj.filters index 18c172ceb4..78eb59279b 100644 --- a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj.filters +++ b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.vcxproj.filters @@ -120,6 +120,12 @@ PdfWriterLib + + PdfWriterLib + + + PdfWriterLib + @@ -353,5 +359,8 @@ PdfWriterLib + + PdfWriterLib + \ No newline at end of file diff --git a/PdfWriter/Src/Document.cpp b/PdfWriter/Src/Document.cpp index 2e2155b6af..2503226b80 100644 --- a/PdfWriter/Src/Document.cpp +++ b/PdfWriter/Src/Document.cpp @@ -43,6 +43,7 @@ #include "Image.h" #include "Font14.h" #include "FontCidTT.h" +#include "FontTT.h" #include "Shading.h" #include "Pattern.h" #include "AcroForm.h" @@ -83,6 +84,7 @@ namespace PdfWriter m_pFreeTypeLibrary = NULL; m_pAcroForm = NULL; m_pFieldsResources = NULL; + m_pDefaultCheckBoxFont = NULL; m_bPDFAConformance = false; } @@ -174,12 +176,14 @@ namespace PdfWriter m_pAcroForm = NULL; m_pFieldsResources = NULL; memset((void*)m_sTTFontTag, 0x00, 8); + m_pDefaultCheckBoxFont = NULL; m_vPages.clear(); m_vExtGrStates.clear(); m_vStrokeAlpha.clear(); m_vFillAlpha.clear(); m_vShadings.clear(); + m_vCidTTFonts.clear(); m_vTTFonts.clear(); m_vFreeTypeFonts.clear(); if (m_pFreeTypeLibrary) @@ -312,6 +316,10 @@ namespace PdfWriter { m_unCompressMode = unMode; } + unsigned int CDocument::GetCompressionMode() const + { + return m_unCompressMode; + } void CDocument::SetPDFAConformanceMode(bool isPDFA) { m_bPDFAConformance = isPDFA; @@ -547,13 +555,13 @@ namespace PdfWriter { return new CFont14(m_pXref, this, eType); } - CFontCidTrueType* CDocument::CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex) + CFontCidTrueType* CDocument::CreateCidTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex) { - for (int nIndex = 0, nCount = m_vTTFonts.size(); nIndex < nCount; nIndex++) + for (int nIndex = 0, nCount = m_vCidTTFonts.size(); nIndex < nCount; nIndex++) { - TFontInfo& oInfo = m_vTTFonts.at(nIndex); + TFontInfo& oInfo = m_vCidTTFonts.at(nIndex); if (wsFontPath == oInfo.wsPath && unIndex == oInfo.unIndex) - return oInfo.pFont; + return (CFontCidTrueType*)oInfo.pFont; } CFontCidTrueType* pFont = new CFontCidTrueType(m_pXref, this, wsFontPath, unIndex); @@ -566,10 +574,46 @@ namespace PdfWriter if (pString) delete pString; + m_vCidTTFonts.push_back(TFontInfo(wsFontPath, unIndex, pFont)); + return pFont; + } + CFontTrueType* CDocument::CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex) + { + for (int nIndex = 0, nCount = m_vTTFonts.size(); nIndex < nCount; nIndex++) + { + TFontInfo& oInfo = m_vTTFonts.at(nIndex); + if (wsFontPath == oInfo.wsPath && unIndex == oInfo.unIndex) + return (CFontTrueType*)oInfo.pFont; + } + + CFontTrueType* pFont = new CFontTrueType(m_pXref, this, wsFontPath, unIndex); + if (!pFont) + return NULL; + m_vTTFonts.push_back(TFontInfo(wsFontPath, unIndex, pFont)); return pFont; } - char* CDocument::GetTTFontTag() + CFontTrueType* CDocument::CreateTrueTypeFont(CFontCidTrueType* pCidFont) + { + for (int nIndex = 0, nCount = m_vCidTTFonts.size(); nIndex < nCount; nIndex++) + { + TFontInfo& oInfo = m_vCidTTFonts.at(nIndex); + if (pCidFont == (CFontCidTrueType*)oInfo.pFont) + { + return CreateTrueTypeFont(oInfo.wsPath, oInfo.unIndex); + } + } + + return NULL; + } + CFont14* CDocument::GetDefaultCheckboxFont() + { + if (!m_pDefaultCheckBoxFont) + m_pDefaultCheckBoxFont = new CFont14(m_pXref, this, EStandard14Fonts::standard14fonts_ZapfDingbats); + + return m_pDefaultCheckBoxFont; + } + char* CDocument::GetTTFontTag() { if (0 == m_sTTFontTag[0]) { @@ -826,7 +870,13 @@ namespace PdfWriter CResourcesDict* CDocument::GetFieldsResources() { if (!m_pFieldsResources) + { + if (!CheckAcroForm()) + return NULL; + m_pFieldsResources = new CResourcesDict(m_pXref, false, true); + m_pAcroForm->Add("DR", m_pFieldsResources); + } return m_pFieldsResources; } @@ -920,9 +970,41 @@ namespace PdfWriter return pField; } - void CDocument::CheckFieldName(CFieldBase* pField) + bool CDocument::CheckFieldName(CFieldBase* pField, const std::string& sName) { + CFieldBase* pBase = m_mFields[sName]; + if (pBase) + { + if (!pBase->GetKidsCount()) + { + CFieldBase* pParent = new CFieldBase(m_pXref, this); + pParent->SetFieldName(sName, true); + pParent->Add("Ff", pBase->GetFieldFlag()); + pParent->Add("FT", pBase->GetFieldType()); + pBase->SetParent(pParent); + pBase->ClearKidRecords(); + pParent->AddKid(pBase); + + m_mFields[sName] = pParent; + pField->ClearKidRecords(); + pField->SetParent(pParent); + pParent->AddKid(pField); + } + else + { + pField->ClearKidRecords(); + pField->SetParent(pBase); + pBase->AddKid(pField); + } + + return true; + } + else + { + m_mFields[sName] = pField; + return false; + } } bool CDocument::CheckAcroForm() { diff --git a/PdfWriter/Src/Document.h b/PdfWriter/Src/Document.h index e26bde0b14..f055a314d1 100644 --- a/PdfWriter/Src/Document.h +++ b/PdfWriter/Src/Document.h @@ -72,6 +72,7 @@ namespace PdfWriter class CFontDict; class CFont14; class CFontCidTrueType; + class CFontTrueType; class CJbig2Global; class CShading; class CImageTilePattern; @@ -101,6 +102,7 @@ namespace PdfWriter void SetPasswords(const std::wstring & wsOwnerPassword, const std::wstring & wsUserPassword); void SetPermission(unsigned int unPermission); void SetCompressionMode(unsigned int unMode); + unsigned int GetCompressionMode() const; void SetDocumentID(const std::wstring & wsDocumentID); void SetPDFAConformanceMode(bool isPDFA); @@ -127,7 +129,10 @@ namespace PdfWriter CImageDict* CreateImage(); CFont14* CreateFont14(EStandard14Fonts eType); - CFontCidTrueType* CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex); + CFontCidTrueType* CreateCidTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex); + CFontTrueType* CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex); + CFontTrueType* CreateTrueTypeFont(CFontCidTrueType* pCidFont); + CFont14* GetDefaultCheckboxFont(); 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); @@ -140,7 +145,7 @@ namespace PdfWriter CCheckBoxField* CreateCheckBoxField(); CRadioGroupField* GetRadioGroupField(const std::wstring& wsGroupName); CPictureField* CreatePictureField(); - void CheckFieldName(CFieldBase* pField); + bool CheckFieldName(CFieldBase* pField, const std::string& sName); private: @@ -161,48 +166,52 @@ namespace PdfWriter struct TFontInfo { - TFontInfo(const std::wstring& path, const unsigned int& index, CFontCidTrueType* font) + TFontInfo(const std::wstring& path, const unsigned int& index, CFontDict* font) { wsPath = path; unIndex = index; pFont = font; } - std::wstring wsPath; - unsigned int unIndex; - CFontCidTrueType* pFont; + std::wstring wsPath; + unsigned int unIndex; + CFontDict* pFont; }; - CCatalog* m_pCatalog; - COutline* m_pOutlines; - CXref* m_pXref; - CPageTree* m_pPageTree; - CPage* m_pCurPage; - int m_nCurPageNum; - CInfoDict* m_pInfo; - CDictObject* m_pTrailer; - CDictObject* m_pResources; - bool m_bEncrypt; - CEncryptDict* m_pEncryptDict; - unsigned int m_unCompressMode; - std::vector m_vPages; - std::vector m_vExtGrStates; - std::vector m_vStrokeAlpha; - std::vector m_vFillAlpha; - char m_sTTFontTag[8]; // 6 символов + '+' + 0x00 ("BAAAAA+/0") - CJbig2Global* m_pJbig2; - std::vector m_vShadings; - std::vector m_vTTFonts; - CDictObject* m_pTransparencyGroup; - std::vector m_vFreeTypeFonts; - FT_Library m_pFreeTypeLibrary; - bool m_bPDFAConformance; - std::wstring m_wsDocumentID; - CAcroForm* m_pAcroForm; - CResourcesDict* m_pFieldsResources; - std::vector m_vRadioGroups; + CCatalog* m_pCatalog; + COutline* m_pOutlines; + CXref* m_pXref; + CPageTree* m_pPageTree; + CPage* m_pCurPage; + int m_nCurPageNum; + CInfoDict* m_pInfo; + CDictObject* m_pTrailer; + CDictObject* m_pResources; + bool m_bEncrypt; + CEncryptDict* m_pEncryptDict; + unsigned int m_unCompressMode; + std::vector m_vPages; + std::vector m_vExtGrStates; + std::vector m_vStrokeAlpha; + std::vector m_vFillAlpha; + char m_sTTFontTag[8]; // 6 символов + '+' + 0x00 ("BAAAAA+/0") + CJbig2Global* m_pJbig2; + std::vector m_vShadings; + std::vector m_vCidTTFonts; + std::vector m_vTTFonts; + CFont14* m_pDefaultCheckBoxFont; + CDictObject* m_pTransparencyGroup; + std::vector m_vFreeTypeFonts; + FT_Library m_pFreeTypeLibrary; + bool m_bPDFAConformance; + std::wstring m_wsDocumentID; + CAcroForm* m_pAcroForm; + CResourcesDict* m_pFieldsResources; + std::vector m_vRadioGroups; + std::map m_mFields; friend class CFontCidTrueType; + friend class CFontTrueType; }; } diff --git a/PdfWriter/Src/Encodings.h b/PdfWriter/Src/Encodings.h new file mode 100644 index 0000000000..f9eecba1df --- /dev/null +++ b/PdfWriter/Src/Encodings.h @@ -0,0 +1,292 @@ +/* + * (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 _PDF_WRITER_SRC_ENCODINGS_H +#define _PDF_WRITER_SRC_ENCODINGS_H + +namespace PdfWriter +{ + static unsigned int c_arrWinAnsiEncoding[256] ={ + 0x0000, + 0x0001, + 0x0002, + 0x0003, + 0x0004, + 0x0005, + 0x0006, + 0x0007, + 0x0008, + 0x0009, + 0x000A, + 0x000B, + 0x000C, + 0x000D, + 0x000E, + 0x000F, + 0x0010, + 0x0011, + 0x0012, + 0x0013, + 0x0014, + 0x0015, + 0x0016, + 0x0017, + 0x0018, + 0x0019, + 0x001A, + 0x001B, + 0x001C, + 0x001D, + 0x001E, + 0x001F, + 0x0020, + 0x0021, + 0x0022, + 0x0023, + 0x0024, + 0x0025, + 0x0026, + 0x0027, + 0x0028, + 0x0029, + 0x002A, + 0x002B, + 0x002C, + 0x002D, + 0x002E, + 0x002F, + 0x0030, + 0x0031, + 0x0032, + 0x0033, + 0x0034, + 0x0035, + 0x0036, + 0x0037, + 0x0038, + 0x0039, + 0x003A, + 0x003B, + 0x003C, + 0x003D, + 0x003E, + 0x003F, + 0x0040, + 0x0041, + 0x0042, + 0x0043, + 0x0044, + 0x0045, + 0x0046, + 0x0047, + 0x0048, + 0x0049, + 0x004A, + 0x004B, + 0x004C, + 0x004D, + 0x004E, + 0x004F, + 0x0050, + 0x0051, + 0x0052, + 0x0053, + 0x0054, + 0x0055, + 0x0056, + 0x0057, + 0x0058, + 0x0059, + 0x005A, + 0x005B, + 0x005C, + 0x005D, + 0x005E, + 0x005F, + 0x0060, + 0x0061, + 0x0062, + 0x0063, + 0x0064, + 0x0065, + 0x0066, + 0x0067, + 0x0068, + 0x0069, + 0x006A, + 0x006B, + 0x006C, + 0x006D, + 0x006E, + 0x006F, + 0x0070, + 0x0071, + 0x0072, + 0x0073, + 0x0074, + 0x0075, + 0x0076, + 0x0077, + 0x0078, + 0x0079, + 0x007A, + 0x007B, + 0x007C, + 0x007D, + 0x007E, + 0x007F, + 0x20AC, + 0x201A, + 0x0192, + 0x201E, + 0x2026, + 0x2020, + 0x2021, + 0x02C6, + 0x2030, + 0x0160, + 0x2039, + 0x0152, + 0x017D, + 0x2018, + 0x2019, + 0x201C, + 0x201D, + 0x2022, + 0x2013, + 0x2014, + 0x02DC, + 0x2122, + 0x0161, + 0x203A, + 0x0153, + 0x017E, + 0x0178, + 0x00A0, + 0x00A1, + 0x00A2, + 0x00A3, + 0x00A4, + 0x00A5, + 0x00A6, + 0x00A7, + 0x00A8, + 0x00A9, + 0x00AA, + 0x00AB, + 0x00AC, + 0x00AD, + 0x00AE, + 0x00AF, + 0x00B0, + 0x00B1, + 0x00B2, + 0x00B3, + 0x00B4, + 0x00B5, + 0x00B6, + 0x00B7, + 0x00B8, + 0x00B9, + 0x00BA, + 0x00BB, + 0x00BC, + 0x00BD, + 0x00BE, + 0x00BF, + 0x00C0, + 0x00C1, + 0x00C2, + 0x00C3, + 0x00C4, + 0x00C5, + 0x00C6, + 0x00C7, + 0x00C8, + 0x00C9, + 0x00CA, + 0x00CB, + 0x00CC, + 0x00CD, + 0x00CE, + 0x00CF, + 0x00D0, + 0x00D1, + 0x00D2, + 0x00D3, + 0x00D4, + 0x00D5, + 0x00D6, + 0x00D7, + 0x00D8, + 0x00D9, + 0x00DA, + 0x00DB, + 0x00DC, + 0x00DD, + 0x00DE, + 0x00DF, + 0x00E0, + 0x00E1, + 0x00E2, + 0x00E3, + 0x00E4, + 0x00E5, + 0x00E6, + 0x00E7, + 0x00E8, + 0x00E9, + 0x00EA, + 0x00EB, + 0x00EC, + 0x00ED, + 0x00EE, + 0x00EF, + 0x00F0, + 0x00F1, + 0x00F2, + 0x00F3, + 0x00F4, + 0x00F5, + 0x00F6, + 0x00F7, + 0x00F8, + 0x00F9, + 0x00FA, + 0x00FB, + 0x00FC, + 0x00FD, + 0x00FE, + 0x00FF + }; +} + +#endif // _PDF_WRITER_SRC_ENCODINGS_H diff --git a/PdfWriter/Src/Field.cpp b/PdfWriter/Src/Field.cpp index 4baba82050..8a1621bda3 100644 --- a/PdfWriter/Src/Field.cpp +++ b/PdfWriter/Src/Field.cpp @@ -35,6 +35,7 @@ #include "Document.h" #include "ResourcesDictionary.h" #include "Types.h" +#include "Image.h" #include #include @@ -66,7 +67,10 @@ namespace PdfWriter m_bShd = false; - m_pMK = NULL; + m_pMK = NULL; + m_pParent = NULL; + m_pKids = NULL; + m_pAppearance = NULL; } void CFieldBase::SetReadOnlyFlag(bool isReadOnly) { @@ -140,14 +144,22 @@ namespace PdfWriter Add("F", 4); } - void CFieldBase::SetFieldName(const std::string& sName) + void CFieldBase::SetFieldName(const std::string& sName, bool isSkipCheck) { - Add("T", new CStringObject(sName.c_str())); + if (isSkipCheck || !m_pDocument->CheckFieldName(this, sName)) + Add("T", new CStringObject(sName.c_str())); } - void CFieldBase::SetFieldName(const std::wstring& wsName) + void CFieldBase::SetFieldName(const std::wstring& wsName, bool isSkipCheck) { std::string sName = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(wsName); - Add("T", new CStringObject(sName.c_str(), true)); + if (isSkipCheck || !m_pDocument->CheckFieldName(this, sName)) + Add("T", new CStringObject(sName.c_str(), true)); + } + void CFieldBase::ClearKidRecords() + { + Remove("T"); + Remove("FT"); + Remove("Ff"); } void CFieldBase::SetFieldHint(const std::wstring& wsHint) { @@ -169,23 +181,14 @@ namespace PdfWriter { return m_pDocument->GetFieldsResources(); } - void CFieldBase::SetTextAppearance(const std::wstring& wsValue, unsigned char* pCodes, unsigned int unCount, CFontDict* pFont, const TRgb& oColor, const double& dAlpha, double dFontSize, double dX, double dY, double* pShifts, unsigned int unShiftsCount) + void CFieldBase::SetDefaultAppearance(CFontDict* pFont, const double& dFontSize, const TRgb& oColor) { - CAnnotAppearance* pAppearance = new CAnnotAppearance(m_pXref, this); - Add("AP", pAppearance); - - - CAnnotAppearanceObject* pNormal = pAppearance->GetNormal(); - CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources(); - CResourcesDict* pResources = new CResourcesDict(m_pXref, true, false); - const char* sFontName = pResources->GetFontName(pFont); + const char* sFontName = pFieldsResources->GetFontName(pFont); if (!sFontName) return; - Add("DR", pResources); - std::string sDA; sDA.append(std::to_string(oColor.r)); sDA.append(" "); @@ -206,6 +209,17 @@ namespace PdfWriter sDA.append(" Tf"); } + Add("DA", new CStringObject(sDA.c_str())); + } + void CFieldBase::SetTextAppearance(const std::wstring& wsValue, unsigned char* pCodes, unsigned int unCount, CFontDict* pFont, const TRgb& oColor, const double& dAlpha, double dFontSize, double dX, double dY, double* pShifts, unsigned int unShiftsCount) + { + CAnnotAppearance* pAppearance = new CAnnotAppearance(m_pXref, this); + Add("AP", pAppearance); + + CAnnotAppearanceObject* pNormal = pAppearance->GetNormal(); + + CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources(); + const char* sExtGrStateName = NULL; if (fabs(dAlpha - 1.0) > 0.001) { @@ -213,10 +227,45 @@ namespace PdfWriter sExtGrStateName = pFieldsResources->GetExtGrStateName(pExtGrState); } - Add("DA", new CStringObject(sDA.c_str())); - pNormal->DrawSimpleText(wsValue, pCodes, unCount, pFieldsResources->GetFontName(pFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop), pShifts, unShiftsCount); } + void CFieldBase::StartTextAppearance(CFontDict* pFont, const double& dFontSize, const TRgb& oColor, const double& dAlpha) + { + m_pAppearance = new CAnnotAppearance(m_pXref, this); + if (!m_pAppearance) + return; + + Add("AP", m_pAppearance); + + CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal(); + + CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources(); + + const char* sExtGrStateName = NULL; + if (fabs(dAlpha - 1.0) > 0.001) + { + CExtGrState* pExtGrState = m_pDocument->GetFillAlpha(dAlpha); + sExtGrStateName = pFieldsResources->GetExtGrStateName(pExtGrState); + } + + pNormal->StartDrawText(pFieldsResources->GetFontName(pFont), dFontSize, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + } + void CFieldBase::AddLineToTextAppearance(const double& dX, const double& dY, unsigned char* pCodes, const unsigned int& unCodesCount, const double* pShifts, const unsigned int& unShiftsCount) + { + if (!m_pAppearance) + return; + + CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal(); + pNormal->DrawTextLine(dX, dY, pCodes, unCodesCount, pShifts, unShiftsCount); + } + void CFieldBase::EndTextAppearance() + { + if (!m_pAppearance) + return; + + CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal(); + pNormal->EndDrawText(); + } void CFieldBase::SetTextValue(const std::wstring &wsValue) { std::string sValue = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(wsValue); @@ -328,6 +377,7 @@ namespace PdfWriter pBG->Add(oRgb.b); m_pMK->Add("BG", pBG); } + m_bShd = true; } const TRgb& CFieldBase::GetShdColor() const { @@ -335,11 +385,37 @@ namespace PdfWriter } void CFieldBase::SetParent(CFieldBase* pParent) { - + m_pParent = pParent; + Add("Parent", pParent); } - void CFieldBase::AddChild(CFieldBase* pChild) + void CFieldBase::AddKid(CFieldBase* pChild) { + if (!m_pKids) + { + m_pKids = new CArrayObject(); + Add("Kids", m_pKids); + } + m_pKids->Add(pChild); + } + int CFieldBase::GetKidsCount() const + { + if (!m_pKids) + return 0; + + return m_pKids->GetCount(); + } + int CFieldBase::GetFieldFlag() const + { + return ((CNumberObject*)Get("Ff"))->Get(); + } + const char* CFieldBase::GetFieldType() const + { + return ((CNameObject*)Get("FT"))->Get(); + } + void CFieldBase::SetAlign(const EFieldAlignType& eType) + { + Add("Q", (int)eType); } //---------------------------------------------------------------------------------------- // CTextField @@ -396,7 +472,6 @@ namespace PdfWriter int nFlags = ((CNumberObject*)this->Get("Ff"))->Get(); return (nFlags & (1 << 24)); } - //---------------------------------------------------------------------------------------- // CChoiceField //---------------------------------------------------------------------------------------- @@ -441,9 +516,9 @@ namespace PdfWriter m_pOpt->Add(new CStringObject(sOption.c_str(), true)); } //---------------------------------------------------------------------------------------- - // CChoiceField + // CCheckBoxField //---------------------------------------------------------------------------------------- - CCheckBoxField::CCheckBoxField(CXref* pXref, CDocument* pDocument, CRadioGroupField* pGroup) : CFieldBase(pXref, pDocument) + CCheckBoxField::CCheckBoxField(CXref* pXref, CDocument* pDocument, CRadioGroupField* pGroup, const char* sYesName) : CFieldBase(pXref, pDocument) { Add("FT", "Btn"); @@ -451,36 +526,38 @@ namespace PdfWriter if (pGroup) Add("Parent", pGroup); + + m_sYesName = sYesName ? sYesName : "Yes"; + Add("AS", "Off"); } void CCheckBoxField::SetAppearance(const std::wstring& wsYesValue, unsigned char* pYesCodes, unsigned int unYesCount, CFontDict* pYesFont, const std::wstring& wsOffValue, unsigned char* pOffCodes, unsigned int unOffCount, CFontDict* pOffFont, const TRgb& oColor, const double& dAlpha, double dFontSize, double dX, double dY) { - if (!Get("AS")) - { - if (m_pGroup) - Add("AS", m_pGroup->GetGroupName().c_str()); - else - Add("AS", "Yes"); - } - - - CCheckBoxAnnotAppearance* pAppearance = new CCheckBoxAnnotAppearance(m_pXref, this); + CCheckBoxAnnotAppearance* pAppearance = new CCheckBoxAnnotAppearance(m_pXref, this, m_sYesName.c_str()); Add("AP", pAppearance); + if (!m_pMK) + { + m_pMK = new CDictObject(); + m_pXref->Add(m_pMK); + Add("MK", m_pMK); + } - CAnnotAppearanceObject* pYes = pAppearance->GetYes(); - CAnnotAppearanceObject* pOff = pAppearance->GetOff(); + CArrayObject* pArray = new CArrayObject(); + pArray->Add(0); + m_pMK->Add("BC", pArray); + pArray = new CArrayObject(); + pArray->Add(1); + m_pMK->Add("BG", pArray); + CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources(); - CResourcesDict* pResources = new CResourcesDict(m_pXref, true, false); - const char* sFontName = pResources->GetFontName(pYesFont); + const char* sFontName = pFieldsResources->GetFontName(pYesFont); if (!sFontName) return; - Add("DR", pResources); - std::string sDA; sDA.append(std::to_string(oColor.r)); sDA.append(" "); @@ -490,8 +567,9 @@ namespace PdfWriter sDA.append(" rg /"); sDA.append(sFontName); sDA.append(" "); - sDA.append(std::to_string(dFontSize)); + sDA.append(std::to_string(0)); sDA.append(" Tf"); + Add("DA", new CStringObject(sDA.c_str())); const char* sExtGrStateName = NULL; if (fabs(dAlpha - 1.0) > 0.001) @@ -500,19 +578,96 @@ namespace PdfWriter sExtGrStateName = pFieldsResources->GetExtGrStateName(pExtGrState); } + + pAppearance->GetYesN()->DrawSimpleText(wsYesValue, pYesCodes, unYesCount, pFieldsResources->GetFontName(pYesFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + pAppearance->GetOffN()->DrawSimpleText(wsOffValue, pOffCodes, unOffCount, pFieldsResources->GetFontName(pOffFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + + pAppearance->GetYesD()->DrawSimpleText(wsYesValue, pYesCodes, unYesCount, pFieldsResources->GetFontName(pYesFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + pAppearance->GetOffD()->DrawSimpleText(wsOffValue, pOffCodes, unOffCount, pFieldsResources->GetFontName(pOffFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + } + void CCheckBoxField::SetAppearance(const int& nType, const TRgb& oColor, const double& dAlpha, double dFontSize, double dX, double dY) + { + if (!m_pMK) + { + m_pMK = new CDictObject(); + m_pXref->Add(m_pMK); + Add("MK", m_pMK); + } + + CArrayObject* pArray = new CArrayObject(); + pArray->Add(3); + m_pMK->Add("BC", pArray); + + pArray = new CArrayObject(); + pArray->Add(1); + pArray->Add(1); + pArray->Add(1); + m_pMK->Add("BG", pArray); + + CCheckBoxAnnotAppearance* pAppearance = new CCheckBoxAnnotAppearance(m_pXref, this, m_sYesName.c_str()); + Add("AP", pAppearance); + + CFontDict* pFont = (CFontDict*)m_pDocument->GetDefaultCheckboxFont(); + CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources(); + + const char* sFontName = pFieldsResources->GetFontName(pFont); + if (!sFontName) + return; + + std::string sDA; + sDA.append(std::to_string(oColor.r)); + sDA.append(" "); + sDA.append(std::to_string(oColor.g)); + sDA.append(" "); + sDA.append(std::to_string(oColor.b)); + sDA.append(" rg /"); + sDA.append(sFontName); + sDA.append(" "); + sDA.append(std::to_string(0)); + sDA.append(" Tf"); Add("DA", new CStringObject(sDA.c_str())); - pYes->DrawSimpleText(wsYesValue, pYesCodes, unYesCount, pFieldsResources->GetFontName(pYesFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); - pOff->DrawSimpleText(wsOffValue, pOffCodes, unOffCount, pFieldsResources->GetFontName(pOffFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + const char* sExtGrStateName = NULL; + if (fabs(dAlpha - 1.0) > 0.001) + { + CExtGrState* pExtGrState = m_pDocument->GetFillAlpha(dAlpha); + sExtGrStateName = pFieldsResources->GetExtGrStateName(pExtGrState); + } + + double dW = fabs(m_oRect.fRight - m_oRect.fLeft); + double dH = fabs(m_oRect.fBottom - m_oRect.fTop); + + dFontSize = dH * 31.014 / 33.8712; + dX = 5.4407 * dW / 37.119000; + dY = 6.4375 * dH / 33.8712; + + SetFieldBorder(border_subtype_Solid, TRgb(0, 0, 0), 1, 0, 0, 0); + Remove("BS"); + + if (1 == nType) + { + m_pMK->Add("CA", new CStringObject("4")); + + pAppearance->GetYesN()->DrawSimpleText(L"4", NULL, 0, pFieldsResources->GetFontName(pFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, dW, dH); + pAppearance->GetOffN()->DrawSimpleText(L"", NULL, 0, pFieldsResources->GetFontName(pFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, dW, dH); + } + else if (2 == nType) + { + m_pMK->Add("CA", new CStringObject("1")); + + pAppearance->GetYesN()->DrawSimpleText(L"1", NULL, 0, pFieldsResources->GetFontName(pFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, dW, dH); + pAppearance->GetOffN()->DrawSimpleText(L"", NULL, 0, pFieldsResources->GetFontName(pFont), dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, dW, dH); + } + } void CCheckBoxField::SetValue(const bool& isYes) { - const char* sValue = (isYes ? (m_pGroup ? m_pGroup->GetGroupName().c_str() : "Yes") : "Off"); + const char* sValue = (isYes ? m_sYesName.c_str() : "Off"); Add("AS", sValue); Add("V", sValue); } //---------------------------------------------------------------------------------------- - // CAnnotAppearance + // CRadioGroupField //---------------------------------------------------------------------------------------- CRadioGroupField::CRadioGroupField(CXref* pXref, CDocument* pDocument) : CFieldBase(pXref, pDocument) { @@ -524,30 +679,21 @@ namespace PdfWriter if (m_pKids) Add("Kids", m_pKids); - - m_sGroupName = "Yes"; } - const std::string& CRadioGroupField::GetGroupName() const - { - return m_sGroupName; - } - void CRadioGroupField::SetGroupName(const std::string& sGroupName) - { - m_sGroupName = sGroupName; - } - CCheckBoxField* CRadioGroupField::CreateKid() + CCheckBoxField* CRadioGroupField::CreateKid(const wchar_t* wsChoiceName) { if (!m_pKids) return NULL; - CCheckBoxField* pKid = new CCheckBoxField(m_pXref, m_pDocument, this); + std::string sName = wsChoiceName ? NSFile::CUtf8Converter::GetUtf8StringFromUnicode(wsChoiceName) : "Choice" + std::to_string(m_pKids->GetCount() + 1); + CCheckBoxField* pKid = new CCheckBoxField(m_pXref, m_pDocument, this, sName.c_str()); m_pKids->Add(pKid); return pKid; } - void CRadioGroupField::SetFieldName(const std::wstring& wsFieldName) + void CRadioGroupField::SetFieldName(const std::wstring& wsFieldName, bool isSkipCheck) { m_wsFieldName = wsFieldName; - CFieldBase::SetFieldName(wsFieldName); + CFieldBase::SetFieldName(wsFieldName, true); } const std::wstring& CRadioGroupField::GetFieldName() const { @@ -585,16 +731,6 @@ namespace PdfWriter Add("MK", m_pMK); m_pMK->Add("R", 0); - - CArrayObject* pBG = new CArrayObject(); - if (pBG) - { - pBG->Add(0.909); - pBG->Add(0.941); - pBG->Add(0.992); - m_pMK->Add("BG", pBG); - } - m_pMK->Add("TP", 1); m_pIF = new CDictObject(); @@ -608,22 +744,124 @@ namespace PdfWriter SetConstantProportions(true); SetShift(0.5, 0.5); } - void CPictureField::SetAppearance() + void CPictureField::SetFieldName(const std::string& sName, bool isSkipCheck) + { + std::string _sName = sName + "_af_image"; + CFieldBase::SetFieldName(_sName, isSkipCheck); + } + void CPictureField::SetFieldName(const std::wstring& wsName, bool isSkipCheck) + { + std::string sName = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(wsName) + "_af_image"; + CFieldBase::SetFieldName(sName, isSkipCheck); + } + void CPictureField::SetAppearance(CImageDict* pImage) { CAnnotAppearance* pAppearance = new CAnnotAppearance(m_pXref, this); Add("AP", pAppearance); - CAnnotAppearanceObject* pNormal = pAppearance->GetNormal(); - CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources(); - CResourcesDict* pResources = new CResourcesDict(m_pXref, true, false); - std::string sDA = "0.909 0.941 0.992 rg"; Add("DA", new CStringObject(sDA.c_str())); - pNormal->DrawPicturePlaceholder(); + if (pImage) + { + TRect oRect = GetRect(); + + double dH = fabs(oRect.fTop - oRect.fBottom); + double dW = fabs(oRect.fRight - oRect.fLeft); + + double dOriginW = pImage->GetWidth() * 72 / 96.0; + double dOriginH = pImage->GetHeight() * 72 / 96.0; + + bool bNeedScale = (EScaleType::Always == m_eScaleType + || (EScaleType::Bigger == m_eScaleType && (dOriginH > dH || dOriginW > dW)) + || (EScaleType::Smaller == m_eScaleType && dOriginH < dH && dOriginW < dW)); + + double dDstW = dOriginW; + double dDstH = dOriginH; + double dDstX = 0; + double dDstY = 0; + + if (m_bRespectBorders && HaveBorder()) + { + double dBorderSize = GetBorderSize(); + dDstX += 2 * dBorderSize; + dDstY += 2 * dBorderSize; + dH -= 4 * dBorderSize; + dW -= 4 * dBorderSize; + } + + if (bNeedScale) + { + if (!m_bConstantProportions) + { + dDstH = dH; + dDstW = dW; + } + else + { + double dScaleKoef = fmin(dW / dOriginW, dH / dOriginH); + dDstW = dScaleKoef * dOriginW; + dDstH = dScaleKoef * dOriginH; + } + } + + dDstX += (dW - dDstW) * m_dShiftX; + dDstY += (dH - dDstH) * m_dShiftY; + + CXObject* pForm = new CXObject(); + CStream* pStream = new CMemoryStream(); + pForm->SetStream(m_pXref, pStream); + +#ifndef FILTER_FLATE_DECODE_DISABLED + if (m_pDocument->GetCompressionMode() & COMP_TEXT) + pForm->SetFilter(STREAM_FILTER_FLATE_DECODE); +#endif + CArrayObject* pBBox = new CArrayObject(); + pForm->Add("BBox", pBBox); + pBBox->Add(0); + pBBox->Add(0); + pBBox->Add(dOriginW); + pBBox->Add(dOriginH); + pForm->Add("FormType", 1); + CArrayObject* pFormMatrix = new CArrayObject(); + pForm->Add("Matrix", pFormMatrix); + pFormMatrix->Add(1); + pFormMatrix->Add(0); + pFormMatrix->Add(0); + pFormMatrix->Add(1); + pFormMatrix->Add(0); + pFormMatrix->Add(0); + pForm->Add("Name", "FRM"); + + CDictObject* pFormRes = new CDictObject(); + CArrayObject* pFormResProcset = new CArrayObject(); + pFormRes->Add("ProcSet", pFormResProcset); + pFormResProcset->Add(new CNameObject("PDF")); + pFormResProcset->Add(new CNameObject("ImageC")); + CDictObject* pFormResXObject = new CDictObject(); + pFormRes->Add("XObject", pFormResXObject); + pFormResXObject->Add("Img", pImage); + pForm->Add("Resources", pFormRes); + + pForm->Add("Subtype", "Form"); + pForm->Add("Type", "XObject"); + + pStream->WriteStr("q\012"); + pStream->WriteReal(dOriginW); + pStream->WriteStr(" 0 0 "); + pStream->WriteReal(dOriginH); + pStream->WriteStr(" 0 0 cm\012/Img Do\012Q"); + + pFieldsResources->AddXObjectWithName("FRM", pForm); + pNormal->DrawPicture("FRM", dDstX, dDstY, dDstW / dOriginW, dDstH / dOriginH, m_bRespectBorders); + } + else + { + pNormal->DrawPicture(); + } } void CPictureField::SetScaleType(const EScaleType& eType) { @@ -636,7 +874,9 @@ namespace PdfWriter case EScaleType::Bigger: m_pIF->Add("SW", "B"); break; case EScaleType::Smaller: m_pIF->Add("SW", "S"); break; case EScaleType::Never: m_pIF->Add("SW", "N"); break; - } + } + + m_eScaleType = eType; } void CPictureField::SetConstantProportions(const bool& bConstant) { @@ -647,6 +887,8 @@ namespace PdfWriter m_pIF->Add("S", "P"); else m_pIF->Add("S", "A"); + + m_bConstantProportions = bConstant; } void CPictureField::SetRespectBorders(const bool& bRespectBorders) { @@ -654,6 +896,8 @@ namespace PdfWriter return; m_pIF->Add("FB", !bRespectBorders); + + m_bRespectBorders = bRespectBorders; } void CPictureField::SetShift(const double& dX, const double& dY) { @@ -667,6 +911,9 @@ namespace PdfWriter pA->Add(dX); pA->Add(dY); } + + m_dShiftX = dX; + m_dShiftY = dY; } //---------------------------------------------------------------------------------------- // CAnnotAppearance @@ -709,26 +956,41 @@ namespace PdfWriter //---------------------------------------------------------------------------------------- // CAnnotAppearance //---------------------------------------------------------------------------------------- - CCheckBoxAnnotAppearance::CCheckBoxAnnotAppearance(CXref* pXref, CFieldBase* pField) + CCheckBoxAnnotAppearance::CCheckBoxAnnotAppearance(CXref* pXref, CFieldBase* pField, const char* sYesName) { m_pXref = pXref; m_pField = pField; - m_pYes = new CAnnotAppearanceObject(pXref, pField); - m_pOff = new CAnnotAppearanceObject(pXref, pField); + m_pYesN = new CAnnotAppearanceObject(pXref, pField); + m_pOffN = new CAnnotAppearanceObject(pXref, pField); + m_pYesD = new CAnnotAppearanceObject(pXref, pField); + m_pOffD = new CAnnotAppearanceObject(pXref, pField); - CDictObject* pDict = new CDictObject(); - Add("N", pDict); - pDict->Add("Yes", m_pYes); - pDict->Add("Off", m_pOff); + CDictObject* pDictN = new CDictObject(); + Add("N", pDictN); + pDictN->Add(sYesName ? sYesName : "Yes", m_pYesN); + pDictN->Add("Off", m_pOffN); + + CDictObject* pDictD = new CDictObject(); + Add("D", pDictD); + pDictD->Add(sYesName ? sYesName : "Yes", m_pYesD); + pDictD->Add("Off", m_pOffD); } - CAnnotAppearanceObject* CCheckBoxAnnotAppearance::GetYes() + CAnnotAppearanceObject* CCheckBoxAnnotAppearance::GetYesN() { - return m_pYes; + return m_pYesN; } - CAnnotAppearanceObject* CCheckBoxAnnotAppearance::GetOff() + CAnnotAppearanceObject* CCheckBoxAnnotAppearance::GetOffN() { - return m_pOff; + return m_pOffN; + } + CAnnotAppearanceObject* CCheckBoxAnnotAppearance::GetYesD() + { + return m_pYesD; + } + CAnnotAppearanceObject* CCheckBoxAnnotAppearance::GetOffD() + { + return m_pOffD; } //---------------------------------------------------------------------------------------- // CAnnotAppearanceObject @@ -759,7 +1021,7 @@ namespace PdfWriter Add("Resources", pField->GetResourcesDict()); #ifndef FILTER_FLATE_DECODE_DISABLED - SetFilter(STREAM_FILTER_FLATE_DECODE); + //SetFilter(STREAM_FILTER_FLATE_DECODE); #endif } void CAnnotAppearanceObject::DrawSimpleText(const std::wstring& wsText, unsigned char* pCodes, unsigned int unCount, const char* sFontName, double dFontSize, double dX, double dY, double dR, double dG, double dB, const char* sExtGStateName, double dWidth, double dHeight, double* pShifts, unsigned int unShiftsCount) @@ -767,16 +1029,22 @@ namespace PdfWriter if (!m_pStream || !sFontName) return; + StartDrawText(sFontName, dFontSize, dR, dG, dB, sExtGStateName, dWidth, dHeight); + + if (pCodes) + DrawTextLine(dX, dY, pCodes, unCount, pShifts, unShiftsCount); + else + DrawTextLine(dX, dY, wsText); + + EndDrawText(); + return; + m_pStream->WriteEscapeName("Tx"); - m_pStream->WriteStr(" BMC\012q\012"); - - m_pStream->WriteStr("0 0 "); - m_pStream->WriteReal(std::max(dWidth, 0.0)); - m_pStream->WriteChar(' '); - m_pStream->WriteReal(std::max(dHeight, 0.0)); - m_pStream->WriteStr(" re\012W\012n\012"); - + m_pStream->WriteStr(" BMC\012"); + double dBorderSize = 0; + double dBorderSize_2 = 0; + double dBorderSize2 = 0; if (m_pField && m_pField->HaveBorder()) { TRgb oColor = m_pField->GetBorderColor(); @@ -789,10 +1057,11 @@ namespace PdfWriter m_pStream->WriteReal(oColor.b); m_pStream->WriteStr(" RG\012"); - double dBorderSize = m_pField->GetBorderSize(); - double dBorderSize_2 = dBorderSize / 2; + dBorderSize = m_pField->GetBorderSize(); + dBorderSize_2 = dBorderSize / 2; + dBorderSize_2 = dBorderSize * 2; m_pStream->WriteReal(dBorderSize); - m_pStream->WriteStr(" W\0120 j\0120 J\012"); + m_pStream->WriteStr(" w\0120 j\0120 J\012"); m_pStream->WriteReal(dBorderSize_2); m_pStream->WriteChar(' '); @@ -832,6 +1101,17 @@ namespace PdfWriter m_pStream->WriteStr("Q\012"); } + m_pStream->WriteStr("q\012"); + + m_pStream->WriteReal(dBorderSize); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dBorderSize); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::max(dWidth - dBorderSize2, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::max(dHeight - dBorderSize2, 0.0)); + m_pStream->WriteStr(" re\012W\012n\012"); + m_pStream->WriteStr("BT\012"); m_pStream->WriteReal(dR); @@ -904,7 +1184,7 @@ namespace PdfWriter m_pStream->WriteStr("Q\012EMC\012"); } - void CAnnotAppearanceObject::DrawPicturePlaceholder() + void CAnnotAppearanceObject::DrawPicture(const char* sImageName, const double& dX, const double& dY, const double& dImageW, const double& dImageH, const bool& bRespectBorder) { if (!m_pStream) return; @@ -917,11 +1197,290 @@ namespace PdfWriter dH = fabs(oRect.fBottom - oRect.fTop); } - m_pStream->WriteStr("Q\0120.909 0.941 0.992 rg\0121 0 0 1 0 0 cm\012"); - m_pStream->WriteStr("0 0 "); - m_pStream->WriteReal(std::max(dW, 0.0)); + m_pStream->WriteStr("q\012"); + + if (m_pField->HaveShd()) + { + TRgb oColor = m_pField->GetShdColor(); + m_pStream->WriteReal(oColor.r); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(oColor.g); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(oColor.b); + m_pStream->WriteStr(" rg\012"); + + m_pStream->WriteStr("1 0 0 1 0 0 cm\012"); + m_pStream->WriteStr("0 0 "); + m_pStream->WriteReal(fmax(dW, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dH, 0.0)); + m_pStream->WriteStr(" re\012f\012"); + } + else if (!sImageName) + { + m_pStream->WriteStr("0.909 0.941 0.992 rg\0121 0 0 1 0 0 cm\012"); + m_pStream->WriteStr("0 0 "); + m_pStream->WriteReal(fmax(dW, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dH, 0.0)); + m_pStream->WriteStr(" re\012f\012"); + } + + if (m_pField->HaveBorder()) + { + TRgb oColor = m_pField->GetBorderColor(); + + m_pStream->WriteReal(oColor.r); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(oColor.g); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(oColor.b); + m_pStream->WriteStr(" RG\012"); + + double dBorderSize = m_pField->GetBorderSize(); + double dBorderSize_2 = dBorderSize / 2; + m_pStream->WriteReal(dBorderSize); + m_pStream->WriteStr(" w\0120 j\0120 J\012"); + + m_pStream->WriteReal(dBorderSize_2); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dBorderSize_2); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dW - dBorderSize, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dH - dBorderSize, 0.0)); + m_pStream->WriteStr(" re\012S\012"); + + if (bRespectBorder && sImageName) + { + m_pStream->WriteReal(2 * dBorderSize); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(2 * dBorderSize); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dW - 4 * dBorderSize, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dH - 4 * dBorderSize, 0.0)); + m_pStream->WriteStr(" re\012W\012n\012"); + } + + } + else if (!sImageName) + { + m_pStream->WriteStr("0.909 0.941 0.992 RG\012"); + m_pStream->WriteStr("0.5 0.5 "); + m_pStream->WriteReal(fmax(dW - 1, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(fmax(dH - 1, 0.0)); + m_pStream->WriteStr(" re\012s\012"); + } + + if (sImageName) + { + + m_pStream->WriteReal(dImageW); + m_pStream->WriteStr(" 0 0 "); + m_pStream->WriteReal(dImageH); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dX); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dY); + m_pStream->WriteStr(" cm\012"); + + m_pStream->WriteEscapeName(sImageName); + m_pStream->WriteStr(" Do\012"); + } + + m_pStream->WriteStr("Q"); + } + void CAnnotAppearanceObject::StartDrawText(const char* sFontName, const double& dFontSize, const double& dR, const double& dG, const double& dB, const char* sExtGStateName, const double& dWidth, const double& dHeight) + { + if (!m_pStream || !sFontName) + return; + + m_pStream->WriteEscapeName("Tx"); + m_pStream->WriteStr(" BMC\012"); + + double dBorderSize = 0; + double dBorderSize_2 = 0; + double dBorderSize2 = 0; + if (m_pField && m_pField->HaveBorder()) + { + TRgb oColor = m_pField->GetBorderColor(); + m_pStream->WriteStr("q\012"); + + m_pStream->WriteReal(oColor.r); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(oColor.g); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(oColor.b); + m_pStream->WriteStr(" RG\012"); + + dBorderSize = m_pField->GetBorderSize(); + dBorderSize_2 = dBorderSize / 2; + dBorderSize_2 = dBorderSize * 2; + m_pStream->WriteReal(dBorderSize); + m_pStream->WriteStr(" w\0120 j\0120 J\012"); + + m_pStream->WriteReal(dBorderSize_2); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dBorderSize_2); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::max(dWidth - dBorderSize, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::max(dHeight - dBorderSize, 0.0)); + m_pStream->WriteStr(" re\012S\012"); + + CTextField* pTextField = dynamic_cast(m_pField); + if (pTextField && pTextField->IsCombFlag()) + { + int nMaxLen = pTextField->GetMaxLen(); + if (nMaxLen > 1) + { + double dStep = dWidth / nMaxLen; + double dX = dStep; + for (int nIndex = 0; nIndex < nMaxLen - 1; ++nIndex) + { + m_pStream->WriteReal(dX); + m_pStream->WriteChar(' '); + m_pStream->WriteInt(0); + m_pStream->WriteChar(' '); + m_pStream->WriteStr(" m\012"); + m_pStream->WriteReal(dX); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dHeight); + m_pStream->WriteChar(' '); + m_pStream->WriteStr(" l\012S\012"); + + dX += dStep; + } + } + } + + m_pStream->WriteStr("Q\012"); + } + + m_pStream->WriteStr("q\012"); + + m_pStream->WriteReal(dBorderSize); m_pStream->WriteChar(' '); - m_pStream->WriteReal(std::max(dH, 0.0)); - m_pStream->WriteStr(" re\012f\012q"); + m_pStream->WriteReal(dBorderSize); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::max(dWidth - dBorderSize2, 0.0)); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::max(dHeight - dBorderSize2, 0.0)); + m_pStream->WriteStr(" re\012W\012n\012"); + + m_pStream->WriteStr("BT\012"); + + m_pStream->WriteReal(dR); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dG); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dB); + m_pStream->WriteStr(" rg\012"); + + if (sExtGStateName) + { + m_pStream->WriteEscapeName(sExtGStateName); + m_pStream->WriteStr(" gs\012"); + } + + m_pStream->WriteEscapeName(sFontName); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(std::min(1000.0, std::max(0.0, dFontSize))); + m_pStream->WriteStr(" Tf\012"); + + m_bStart = true; + } + void CAnnotAppearanceObject::DrawTextLine(const double& dX, const double& dY, const unsigned char* pCodes, const unsigned int& unCount, const double* pShifts, const unsigned int& unShiftsCount) + { + if (pCodes && pShifts && unShiftsCount > 0 && unShiftsCount == unCount / 2) + { + double _dX = dX + pShifts[0], _dY = dY; + + if (!m_bStart) + { + _dX -= m_dCurX; + _dY -= m_dCurY; + + m_dCurX += _dX; + m_dCurY += _dY; + } + else + { + m_dCurX = _dX; + m_dCurY = _dY; + } + + m_pStream->WriteReal(_dX); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(_dY); + m_pStream->WriteStr(" Td\012"); + + for (unsigned int unIndex = 0; unIndex < unShiftsCount; ++unIndex) + { + m_pStream->WriteChar('['); + m_pStream->WriteChar('<'); + m_pStream->WriteBinary(pCodes + 2 * unIndex, 2, NULL); + m_pStream->WriteChar('>'); + m_pStream->WriteStr("]TJ\012"); + + if (unIndex != unShiftsCount - 1) + { + m_pStream->WriteReal(pShifts[unIndex + 1]); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(0.0); + m_pStream->WriteStr(" Td\012"); + } + } + } + else + { + double _dX = dX, _dY = dY; + + if (!m_bStart) + { + _dX -= m_dCurX; + _dY -= m_dCurY; + + m_dCurX += _dX; + m_dCurY += _dY; + } + else + { + m_dCurX = _dX; + m_dCurY = _dY; + } + + m_pStream->WriteReal(_dX); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(_dY); + m_pStream->WriteStr(" Td\012"); + + m_pStream->WriteChar('<'); + m_pStream->WriteBinary(pCodes, unCount, NULL); + m_pStream->WriteChar('>'); + + m_pStream->WriteStr(" Tj\012"); + } + + m_bStart = false; + } + void CAnnotAppearanceObject::DrawTextLine(const double &dX, const double &dY, const std::wstring& wsText) + { + m_pStream->WriteReal(dX); + m_pStream->WriteChar(' '); + m_pStream->WriteReal(dY); + m_pStream->WriteStr(" Td\012"); + + std::string sText = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(wsText); + m_pStream->WriteEscapeText((BYTE*)(sText.c_str()), sText.length()); + + m_pStream->WriteStr(" Tj\012"); + } + void CAnnotAppearanceObject::EndDrawText() + { + m_pStream->WriteStr("ET\012"); + m_pStream->WriteStr("Q\012EMC\012"); } } diff --git a/PdfWriter/Src/Field.h b/PdfWriter/Src/Field.h index 83f10815b7..ca219404d6 100644 --- a/PdfWriter/Src/Field.h +++ b/PdfWriter/Src/Field.h @@ -46,9 +46,19 @@ namespace PdfWriter class CResourcesDict; class CFontDict; class CRadioGroupField; + class CImageDict; class CFieldBase : public CDictObject { + public: + + enum EFieldAlignType + { + Left = 0, + Center = 1, + Right = 2 + }; + public: CFieldBase(CXref* pXref, CDocument* pDocument); @@ -56,12 +66,17 @@ namespace PdfWriter void SetRequiredFlag(bool isRequired); void SetNoExportFlag(bool isNoExport); void AddPageRect(CPage* pPage, const TRect& oRect); - virtual void SetFieldName(const std::string& sName); - virtual void SetFieldName(const std::wstring& wsName); + virtual void SetFieldName(const std::string& sName, bool isSkipCheck = false); + virtual void SetFieldName(const std::wstring& wsName, bool isSkipCheck = false); + void ClearKidRecords(); void SetFieldHint(const std::wstring& wsHint); TRect& GetRect(); CResourcesDict* GetResourcesDict(); + void SetDefaultAppearance(CFontDict* pFont, const double& dFontSize, const TRgb& oColor); void SetTextAppearance(const std::wstring& wsValue, unsigned char* pCodes, unsigned int unCount, CFontDict* pFont, const TRgb& oColor, const double& dAlpha, double dFontSize = 10.0, double dX = 0.0, double dY = 0.0, double* pShifts = NULL, unsigned int unShiftsCount = 0); + void StartTextAppearance(CFontDict* pFont, const double& dFontSize, const TRgb& oColor, const double& dAlpha); + void AddLineToTextAppearance(const double& dX, const double& dY, unsigned char* pCodes, const unsigned int& unCodesCount, const double* pShifts = NULL, const unsigned int& unShiftsCount = 0); + void EndTextAppearance(); void SetTextValue(const std::wstring& wsValue); void SetFieldBorder(const EBorderSubtype& eSubtype, const TRgb& oColor, const double& fWidth, const unsigned short& nDashOn, const unsigned short& nDashOff, const unsigned short& nDashPhase); bool HaveBorder() const; @@ -70,10 +85,14 @@ namespace PdfWriter const bool& IsAutoFit() const; void SetAutoFit(const bool& isAutoFit); void SetParent(CFieldBase* pParent); - void AddChild(CFieldBase* pChild); + void AddKid(CFieldBase* pChild); + int GetKidsCount() const; bool HaveShd() const; void SetShd(const TRgb& oColor); const TRgb& GetShdColor() const; + int GetFieldFlag() const; + const char* GetFieldType() const; + void SetAlign(const EFieldAlignType& eType); protected: @@ -81,17 +100,19 @@ namespace PdfWriter protected: - CXref* m_pXref; - TRect m_oRect; - CDocument* m_pDocument; - int m_nBorderType; - double m_dBorderSize; - TRgb m_oBorderColor; - bool m_bAutoFit; - CFieldBase* m_pParent; - bool m_bShd; - TRgb m_oShdColor; - CDictObject* m_pMK; + CXref* m_pXref; + TRect m_oRect; + CDocument* m_pDocument; + int m_nBorderType; + double m_dBorderSize; + TRgb m_oBorderColor; + bool m_bAutoFit; + bool m_bShd; + TRgb m_oShdColor; + CDictObject* m_pMK; + CFieldBase* m_pParent; + CArrayObject* m_pKids; + CAnnotAppearance* m_pAppearance; }; class CTextField : public CFieldBase @@ -139,16 +160,22 @@ namespace PdfWriter class CCheckBoxField : public CFieldBase { public: - CCheckBoxField(CXref* pXref, CDocument* pDocument, CRadioGroupField* pGroup = NULL); + CCheckBoxField(CXref* pXref, CDocument* pDocument, CRadioGroupField* pGroup = NULL, const char* sYesName = NULL); void SetAppearance(const std::wstring& wsYesValue, unsigned char* pYesCodes, unsigned int unYesCount, CFontDict* pYesFont, const std::wstring& wsOffValue, unsigned char* pOffCodes, unsigned int unOffCount, CFontDict* pOffFont, const TRgb& oColor, const double& dAlpha, double dFontSize = 10.0, double dX = 0.0, double dY = 0.0); + void SetAppearance(const int& nType, const TRgb& oColor, const double& dAlpha, double dFontSize = 10.0, double dX = 0.0, double dY = 0.0); void SetValue(const bool& isYes); + private: + + void SetDefaultCheckBoxAppearance(const std::string& sText); + private: CRadioGroupField* m_pGroup; + std::string m_sYesName; }; class CRadioGroupField : public CFieldBase @@ -156,15 +183,12 @@ namespace PdfWriter public: CRadioGroupField(CXref* pXref, CDocument* pDocument); - const std::string& GetGroupName() const; - void SetGroupName(const std::string& sGroupName); - CCheckBoxField* CreateKid(); - virtual void SetFieldName(const std::wstring& wsName) override; + CCheckBoxField* CreateKid(const wchar_t* wsChoiceName = NULL); + virtual void SetFieldName(const std::wstring& wsName, bool isSkipCheck = false) override; const std::wstring& GetFieldName() const; private: - std::string m_sGroupName; CArrayObject* m_pKids; std::wstring m_wsFieldName; }; @@ -183,7 +207,9 @@ namespace PdfWriter public: CPictureField(CXref* pXref, CDocument* pDocument); - void SetAppearance(); + virtual void SetFieldName(const std::string& sName, bool isSkipCheck = false); + virtual void SetFieldName(const std::wstring& wsName, bool isSkipCheck = false); + void SetAppearance(CImageDict* pImage = NULL); void SetScaleType(const EScaleType& eType); void SetConstantProportions(const bool& bConstant); void SetRespectBorders(const bool& bRespectBorders); @@ -191,6 +217,11 @@ namespace PdfWriter private: CDictObject* m_pIF; + EScaleType m_eScaleType; + bool m_bConstantProportions; + bool m_bRespectBorders; + double m_dShiftX; + double m_dShiftY; }; class CAnnotAppearance : public CDictObject @@ -214,18 +245,21 @@ namespace PdfWriter class CCheckBoxAnnotAppearance : public CDictObject { public: - CCheckBoxAnnotAppearance(CXref* pXref, CFieldBase* pField); + CCheckBoxAnnotAppearance(CXref* pXref, CFieldBase* pField, const char* sYesName = NULL); - CAnnotAppearanceObject* GetYes(); - CAnnotAppearanceObject* GetOff(); + CAnnotAppearanceObject* GetYesN(); + CAnnotAppearanceObject* GetOffN(); + CAnnotAppearanceObject* GetYesD(); + CAnnotAppearanceObject* GetOffD(); private: CXref* m_pXref; CFieldBase* m_pField; - CAnnotAppearanceObject* m_pYes; - CAnnotAppearanceObject* m_pOff; - + CAnnotAppearanceObject* m_pYesN; + CAnnotAppearanceObject* m_pOffN; + CAnnotAppearanceObject* m_pYesD; + CAnnotAppearanceObject* m_pOffD; }; class CAnnotAppearanceObject : public CDictObject @@ -233,13 +267,20 @@ namespace PdfWriter public: CAnnotAppearanceObject(CXref* pXRef, CFieldBase* pField); void DrawSimpleText(const std::wstring& wsText, unsigned char* pCodes, unsigned int unCount, const char* sFont, double dFontSize = 10.0, double dX = 0.0, double dY = 0.0, double dR = 0.0, double dG = 0.0, double dB = 0.0, const char* sExtGrStateName = NULL, double dW = 1.0, double dH = 1.0, double* pShifts = NULL, unsigned int unShiftsCount = 0); - void DrawPicturePlaceholder(); + void DrawPicture(const char* sImageName = NULL, const double& dX = 0.0, const double& dY = 0.0, const double& dW = 0.0, const double& dH = 0.0, const bool& bRespectBorder = false); + void StartDrawText(const char* sFontName, const double& dFontSize, const double& dR, const double& dG, const double& dB, const char* sExtGStateName, const double& dWidth, const double& dHeight); + void DrawTextLine(const double& dX, const double& dY, const unsigned char* pCodes, const unsigned int& unCount, const double* pShifts, const unsigned int& unShiftsCount); + void DrawTextLine(const double &dX, const double &dY, const std::wstring& wsText); + void EndDrawText(); private: CXref* m_pXref; CStream* m_pStream; CFieldBase* m_pField; + double m_dCurX; + double m_dCurY; + bool m_bStart; }; } diff --git a/PdfWriter/Src/FontCidTT.cpp b/PdfWriter/Src/FontCidTT.cpp index 034fe2b680..b05be0e8bc 100644 --- a/PdfWriter/Src/FontCidTT.cpp +++ b/PdfWriter/Src/FontCidTT.cpp @@ -48,47 +48,6 @@ namespace PdfWriter static const char* c_sToUnicodeInfo = "/CIDSystemInfo\n<< /Registry (Adobe)\n /Ordering (UCS)\n /Supplement 0\n >> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> \nendcodespacerange\n"; static const char* c_sToUnicodeFooter = "endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend\n"; - static unsigned int GetGID(FT_Face pFace, unsigned int unUnicode) - { - int nCharIndex = 0; - - if (!pFace) - return nCharIndex; - - for (int nIndex = 0; nIndex < pFace->num_charmaps; nIndex++) - { - FT_CharMap pCharMap = pFace->charmaps[nIndex]; - - if (FT_Set_Charmap(pFace, pCharMap)) - continue; - FT_Encoding pEncoding = pCharMap->encoding; - - if (FT_ENCODING_UNICODE == pEncoding) - { - if (nCharIndex = FT_Get_Char_Index(pFace, unUnicode)) - return nCharIndex; - } - - if (FT_ENCODING_NONE == pEncoding || FT_ENCODING_MS_SYMBOL == pEncoding || FT_ENCODING_APPLE_ROMAN == pEncoding) - { - nCharIndex = FT_Get_Char_Index(pFace, unUnicode); - } - /*else if ( FT_ENCODING_ADOBE_STANDARD == pEncoding ) - { - nCharIndex = FT_Get_Char_Index( pFace, unUnicode ); - } - else if ( FT_ENCODING_ADOBE_CUSTOM == pEncoding ) - { - nCharIndex = FT_Get_Char_Index( pFace, unUnicode ); - } - else if ( FT_ENCODING_ADOBE_EXPERT == pEncoding ) - { - nCharIndex = FT_Get_Char_Index( pFace, unUnicode ); - }*/ - } - - return nCharIndex; - } static int GetSymbolicCmapIndex(FT_Face pFace) { TT_OS2 *pOs2 = (TT_OS2 *)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); diff --git a/PdfWriter/Src/FontCidTT.h b/PdfWriter/Src/FontCidTT.h index 3380bd48d4..ef67505953 100644 --- a/PdfWriter/Src/FontCidTT.h +++ b/PdfWriter/Src/FontCidTT.h @@ -45,6 +45,49 @@ namespace PdfWriter { + static unsigned int GetGID(FT_Face pFace, unsigned int unUnicode) + { + int nCharIndex = 0; + + if (!pFace) + return nCharIndex; + + for (int nIndex = 0; nIndex < pFace->num_charmaps; nIndex++) + { + FT_CharMap pCharMap = pFace->charmaps[nIndex]; + + if (FT_Set_Charmap(pFace, pCharMap)) + continue; + FT_Encoding pEncoding = pCharMap->encoding; + + if (FT_ENCODING_UNICODE == pEncoding) + { + if (nCharIndex = FT_Get_Char_Index(pFace, unUnicode)) + return nCharIndex; + } + + if (FT_ENCODING_NONE == pEncoding || FT_ENCODING_MS_SYMBOL == pEncoding || FT_ENCODING_APPLE_ROMAN == pEncoding) + { + nCharIndex = FT_Get_Char_Index(pFace, unUnicode); + } + /*else if ( FT_ENCODING_ADOBE_STANDARD == pEncoding ) + { + nCharIndex = FT_Get_Char_Index( pFace, unUnicode ); + } + else if ( FT_ENCODING_ADOBE_CUSTOM == pEncoding ) + { + nCharIndex = FT_Get_Char_Index( pFace, unUnicode ); + } + else if ( FT_ENCODING_ADOBE_EXPERT == pEncoding ) + { + nCharIndex = FT_Get_Char_Index( pFace, unUnicode ); + }*/ + } + + return nCharIndex; + } + + class CXref; class CStream; class CFontFileTrueType; diff --git a/PdfWriter/Src/FontTT.cpp b/PdfWriter/Src/FontTT.cpp new file mode 100644 index 0000000000..9febfc8c84 --- /dev/null +++ b/PdfWriter/Src/FontTT.cpp @@ -0,0 +1,183 @@ +/* + * (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 "FontTT.h" +#include "FontCidTT.h" +#include "Document.h" +#include "Streams.h" +#include "Utils.h" +#include "FontTTWriter.h" +#include "Encodings.h" + +#include "../../DesktopEditor/graphics/pro/Fonts.h" +#include "../../DesktopEditor/common/File.h" + +#include + +#include FT_TRUETYPE_TABLES_H + +namespace PdfWriter +{ + //---------------------------------------------------------------------------------------- + // CFontTrueType + //---------------------------------------------------------------------------------------- + CFontTrueType::CFontTrueType(CXref* pXref, CDocument* pDocument, const std::wstring& wsFontPath, unsigned int unIndex) : CFontDict(pXref, pDocument) + { + CFontFileTrueType* pFontTT = CFontFileTrueType::LoadFromFile(wsFontPath, unIndex); + m_pFontFile = pFontTT; + + m_wsFontPath = wsFontPath; + m_unFontIndex = unIndex; + + Add("Type", "Font"); + Add("Subtype", "TrueType"); + Add("Encoding", "WinAnsiEncoding"); + Add("FirstChar", 0); + Add("LastChar", 255); + + CDictObject* pFontDescriptor = new CDictObject(); + // FontDescriptor обязательно должен идти ссылкой + m_pXref->Add(pFontDescriptor); + pFontDescriptor->Add("Type", "FontDescriptor"); + m_pFontDescriptor = pFontDescriptor; + + // Выставляем бит Symbolic, а бит NonSymbolic убираем + unsigned int nFlags = 0; + if (!(nFlags & 4)) + UIntChangeBit(nFlags, 2); + if (nFlags & 32) + UIntChangeBit(nFlags, 5); + + pFontDescriptor->Add("Flags", nFlags); + + m_pFontFileDict = new CDictObject(m_pXref); + pFontDescriptor->Add("FontFile2", m_pFontFileDict); + + Add("FontDescriptor", pFontDescriptor); + + ReadName(); + } + CFontTrueType::~CFontTrueType() + { + if (m_pFontFile) + delete m_pFontFile; + } + void CFontTrueType::BeforeWrite() + { + if (m_pFontFile) + { + CStream* pStream = m_pFontFileDict->GetStream(); + m_pFontFile->WriteTTF(pStream); + m_pFontFileDict->Add("Length1", pStream->Size()); + m_pFontFileDict->SetFilter(STREAM_FILTER_FLATE_DECODE); + } + } + void CFontTrueType::ReadName() + { + FT_Library pLibrary = m_pDocument->GetFreeTypeLibrary(); + if (!pLibrary) + return; + + DWORD dwFileSize; + FT_Byte* pFaceMemory = NULL; + NSFile::CFileBinary::ReadAllBytes(m_wsFontPath, &pFaceMemory, dwFileSize); + if (!pFaceMemory) + return; + + FT_Face pFace = NULL; + FT_New_Memory_Face(pLibrary, pFaceMemory, dwFileSize, m_unFontIndex, &pFace); + + if (!pFace) + { + RELEASEARRAYOBJECTS(pFaceMemory); + return; + } + + // Дописываем имя шрифта во все необходимые словари, а также заполняем дескриптор + std::string sFontName = std::string(pFace->family_name); + if (pFace->style_flags & FT_STYLE_FLAG_ITALIC) + sFontName += "-Italic"; + if (pFace->style_flags & FT_STYLE_FLAG_BOLD) + sFontName += "-Bold"; + + const char* sName = sFontName.c_str(); + + Add("BaseFont", sName); + Add("Name", sName); + m_pFontDescriptor->Add("FontName", sName); + + CArrayObject* pWidths = new CArrayObject(); + Add("Widths", pWidths); + + unsigned int unUnitsPerEm = pFace->units_per_EM; + double dKoef = 1000.0 / unUnitsPerEm; + + for (unsigned int unIndex = 0; unIndex < 255; ++unIndex) + { + unsigned int unGID = GetGID(pFace, c_arrWinAnsiEncoding[unIndex]); + + if (0 == FT_Load_Glyph(pFace, unGID, FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE)) + { + unsigned int unWidth = 0; + if (unUnitsPerEm) + unWidth = ((unsigned int)pFace->glyph->metrics.horiAdvance * 1000 / unUnitsPerEm); + else + unWidth = ((unsigned int)pFace->glyph->metrics.horiAdvance); + + pWidths->Add(unWidth); + } + } + + int xMin = (int)(unUnitsPerEm ? pFace->bbox.xMin * dKoef : pFace->bbox.xMin); + int yMin = (int)(unUnitsPerEm ? pFace->bbox.yMin * dKoef : pFace->bbox.yMin); + int xMax = (int)(unUnitsPerEm ? pFace->bbox.xMax * dKoef : pFace->bbox.xMax); + int yMax = (int)(unUnitsPerEm ? pFace->bbox.yMax * dKoef : pFace->bbox.yMax); + + m_nLineHeight = yMax - yMin; + m_nAscent = yMax; + + CArrayObject* pBBox = new CArrayObject(); + pBBox->Add(xMin); + pBBox->Add(yMin); + pBBox->Add(xMax); + pBBox->Add(yMax); + m_pFontDescriptor->Add("FontBBox", pBBox); + m_pFontDescriptor->Add("Ascent", yMax); + m_pFontDescriptor->Add("Descent", yMin); + m_pFontDescriptor->Add("CapHeight", (int)(unUnitsPerEm ? m_pFontFile->GetCapHeight() * dKoef : m_pFontFile->GetCapHeight())); + m_pFontDescriptor->Add("ItalicAngle", 0); + m_pFontDescriptor->Add("StemV", 80); + m_pFontDescriptor->Add("FontWeight", m_pFontFile->GetWeight()); + + FT_Done_Face(pFace); + RELEASEARRAYOBJECTS(pFaceMemory); + } +} diff --git a/PdfWriter/Src/FontTT.h b/PdfWriter/Src/FontTT.h new file mode 100644 index 0000000000..a2a6f1f055 --- /dev/null +++ b/PdfWriter/Src/FontTT.h @@ -0,0 +1,97 @@ +/* + * (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 _PDF_WRITER_SRC_FONTTT_H +#define _PDF_WRITER_SRC_FONTTT_H + +#include "Font.h" +#include "Objects.h" +#include +#include +#include + +#include "../../DesktopEditor/common/File.h" + +#include +#include FT_TRUETYPE_TABLES_H + +namespace PdfWriter +{ + class CXref; + class CStream; + class CFontFileTrueType; + class CDocument; + //---------------------------------------------------------------------------------------- + // CFontTrueType + //---------------------------------------------------------------------------------------- + class CFontTrueType : public CFontDict + { + public: + + CFontTrueType(CXref* pXref, CDocument* pDocument, const std::wstring& wsFontPath, unsigned int unIndex); + ~CFontTrueType(); + unsigned int GetWidth(unsigned short ushCode); + int GetLineHeight() const + { + return m_nLineHeight; + } + int GetAscent() const + { + return m_nAscent; + } + EFontType GetFontType() + { + return fontTrueType; + } + + private: + + void BeforeWrite(); + void ReadName(); + + private: + + std::wstring m_wsFontPath; + unsigned int m_unFontIndex; + + CFontFileTrueType* m_pFontFile; + CDictObject* m_pFontFileDict; + CDictObject* m_pFont; + CDictObject* m_pFontDescriptor; + int m_nLineHeight; + int m_nAscent; + + + friend class CDocument; + }; +} + +#endif // _PDF_WRITER_SRC_FONTTT_H diff --git a/PdfWriter/Src/Image.cpp b/PdfWriter/Src/Image.cpp index b9c8b62af9..f671690678 100644 --- a/PdfWriter/Src/Image.cpp +++ b/PdfWriter/Src/Image.cpp @@ -422,6 +422,14 @@ namespace PdfWriter Add("Mask", pMask); } + unsigned int CImageDict::GetWidth() const + { + return ((unsigned int)((CNumberObject*)this->Get("Width"))->Get()); + } + unsigned int CImageDict::GetHeight() const + { + return ((unsigned int)((CNumberObject*)this->Get("Height"))->Get()); + } //---------------------------------------------------------------------------------------- // CJbig2Global //---------------------------------------------------------------------------------------- diff --git a/PdfWriter/Src/Image.h b/PdfWriter/Src/Image.h index 4947e432ce..1f2db7b7b0 100644 --- a/PdfWriter/Src/Image.h +++ b/PdfWriter/Src/Image.h @@ -68,6 +68,8 @@ namespace PdfWriter void LoadBW(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride); void LoadBW(NSImages::CPixJbig2* pPix, unsigned int unWidth, unsigned int unHeight); void LoadMask(NSImages::CPixJbig2* pPix, unsigned int unWidth, unsigned int unHeight); + unsigned int GetWidth() const; + unsigned int GetHeight() const; private: diff --git a/PdfWriter/Src/ResourcesDictionary.cpp b/PdfWriter/Src/ResourcesDictionary.cpp index f95b942504..510eea3f15 100644 --- a/PdfWriter/Src/ResourcesDictionary.cpp +++ b/PdfWriter/Src/ResourcesDictionary.cpp @@ -33,6 +33,7 @@ #include "Font.h" #include "Utils.h" #include "GState.h" +#include "Image.h" namespace PdfWriter { @@ -45,6 +46,8 @@ namespace PdfWriter m_pFonts = NULL; m_unExtGStatesCount = 0; m_pExtGStates = NULL; + m_unXObjectsCount = 0; + m_pXObjects = NULL; if (!bInline) pXref->Add(this); @@ -77,7 +80,7 @@ namespace PdfWriter const char *sKey = m_pFonts->GetKey(pFont); if (!sKey) { - // , + // ���� ���� �� ��������������� � ��������, ����� ������������ ��� char sFontName[LIMIT_MAX_NAME_LEN + 1]; char *pPointer = NULL; char *pEndPointer = sFontName + LIMIT_MAX_NAME_LEN; @@ -105,7 +108,7 @@ namespace PdfWriter const char* sKey = m_pExtGStates->GetKey(pState); if (!sKey) { - // ExtGState Resource, + // ���� ExtGState �� ��������������� � Resource, ������������ char sExtGrStateName[LIMIT_MAX_NAME_LEN + 1]; char *pPointer; char *pEndPointer = sExtGrStateName + LIMIT_MAX_NAME_LEN; @@ -119,4 +122,44 @@ namespace PdfWriter return sKey; } + const char* CResourcesDict::GetXObjectName(CXObject* pObject) + { + if (!m_pXObjects) + { + m_pXObjects = new CDictObject(); + if (!m_pXObjects) + return NULL; + + Add("XObject", m_pXObjects); + } + + const char* sKey = m_pXObjects->GetKey(pObject); + if (!sKey) + { + char sXObjName[LIMIT_MAX_NAME_LEN + 1]; + char *pPointer; + char *pEndPointer = sXObjName + LIMIT_MAX_NAME_LEN; + + pPointer = (char*)StrCpy(sXObjName, "X", pEndPointer); + ItoA(pPointer, m_unXObjectsCount + 1, pEndPointer); + m_unXObjectsCount++; + m_pXObjects->Add(sXObjName, pObject); + sKey = m_pXObjects->GetKey(pObject); + } + + return sKey; + } + void CResourcesDict::AddXObjectWithName(const char* sXObjName, CXObject* pObject) + { + if (!m_pXObjects) + { + m_pXObjects = new CDictObject(); + if (!m_pXObjects) + return; + + Add("XObject", m_pXObjects); + } + + m_pXObjects->Add(sXObjName, pObject); + } } diff --git a/PdfWriter/Src/ResourcesDictionary.h b/PdfWriter/Src/ResourcesDictionary.h index 2321ff67fe..312fcae598 100644 --- a/PdfWriter/Src/ResourcesDictionary.h +++ b/PdfWriter/Src/ResourcesDictionary.h @@ -40,6 +40,7 @@ namespace PdfWriter { class CFontDict; class CExtGrState; + class CXObject; class CResourcesDict : public CDictObject { @@ -48,6 +49,8 @@ namespace PdfWriter const char* GetFontName(CFontDict* pFont); const char* GetExtGrStateName(CExtGrState* pState); + const char* GetXObjectName(CXObject* pXObject); + void AddXObjectWithName(const char* sXObjectName, CXObject* pXObject); private: @@ -55,6 +58,8 @@ namespace PdfWriter unsigned int m_unFontsCount; CDictObject* m_pExtGStates; unsigned int m_unExtGStatesCount; + CDictObject* m_pXObjects; + unsigned int m_unXObjectsCount; }; } diff --git a/X2tConverter/build/Android/libx2t/build.gradle.kts b/X2tConverter/build/Android/libx2t/build.gradle.kts index 8ecbc90d82..4a85199169 100644 --- a/X2tConverter/build/Android/libx2t/build.gradle.kts +++ b/X2tConverter/build/Android/libx2t/build.gradle.kts @@ -7,16 +7,13 @@ plugins { android { - buildToolsVersion("30.0.3") - compileSdkVersion(30) + buildToolsVersion = AppDependency.BUILD_TOOLS_VERSION + compileSdk = AppDependency.COMPILE_SDK_VERSION ndkVersion = rootProject.extra.get("NDK_VERSION").toString() defaultConfig { - - minSdkVersion(23) - targetSdkVersion(30) - versionCode = 1 - versionName = "1.0" + minSdk = AppDependency.MIN_SDK_VERSION + targetSdk = AppDependency.TARGET_SDK_VERSION buildConfigField("String", "LIB_X2T", "\"${extra.get("NAME_LIB")}\"") @@ -41,14 +38,12 @@ android { } buildTypes { - getByName(AppDependency.BuildType.RELEASE) { - minifyEnabled(false) + release { + isMinifyEnabled = false proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") } - - getByName(AppDependency.BuildType.DEBUG) { - debuggable(true) - jniDebuggable(true) + debug { + isJniDebuggable = true } } @@ -81,9 +76,9 @@ android { val dh = file("${extra.get("PATH_LIB_BUILD_TOOLS")}/$abi") dh.listFiles().forEach { if (it.name.contains(".so")) - pickFirst("lib/$abi/${it.name}") + jniLibs.pickFirsts.add("lib/$abi/${it.name}") } - pickFirst("lib/$abi/lib${extra.get("NAME_LIB")}.so") + jniLibs.pickFirsts.add("lib/$abi/lib${extra.get("NAME_LIB")}.so") } } } diff --git a/X2tConverter/src/ASCConverters.cpp b/X2tConverter/src/ASCConverters.cpp index 815b8c170f..ae5718f209 100644 --- a/X2tConverter/src/ASCConverters.cpp +++ b/X2tConverter/src/ASCConverters.cpp @@ -2362,6 +2362,7 @@ namespace NExtractTools RtfConvertationManager rtfConvert; rtfConvert.m_sTempFolder = sTemp; + rtfConvert.m_nUserLCID = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; if ( rtfConvert.ConvertRtfToOOX(sFrom, sResultDocxDir) == 0) { @@ -2397,6 +2398,7 @@ namespace NExtractTools RtfConvertationManager rtfConvert; rtfConvert.m_sTempFolder = sTemp; + rtfConvert.m_nUserLCID = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; if (rtfConvert.ConvertOOXToRtf(sTo, sDocxDir) == 0) return 0; @@ -2440,7 +2442,7 @@ namespace NExtractTools params.m_bMacro = false; - _UINT32 hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), params.m_bMacro, NULL); + _UINT32 hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), params.m_bMacro); if (AVS_ERROR_DRM == hRes) { if(!params.getDontSaveAdditional()) @@ -2488,10 +2490,11 @@ namespace NExtractTools { COfficeDocFile docFile; docFile.m_sTempFolder = sTemp; - + docFile.m_nUserLCID = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; + params.m_bMacro = true; - _UINT32 hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), params.m_bMacro, NULL); + _UINT32 hRes = docFile.LoadFromFile( sFrom, sTo, params.getPassword(), params.m_bMacro); if (AVS_ERROR_DRM == hRes) { if(!params.getDontSaveAdditional()) @@ -2536,10 +2539,11 @@ namespace NExtractTools COfficeDocFile docFile; docFile.m_sTempFolder = sTemp; + docFile.m_nUserLCID = (NULL != params.m_nLcid) ? *params.m_nLcid : -1;; params.m_bMacro = true; - _UINT32 nRes = docFile.LoadFromFile( sFrom, sResultDocxDir, params.getPassword(), params.m_bMacro, NULL); + _UINT32 nRes = docFile.LoadFromFile( sFrom, sResultDocxDir, params.getPassword(), params.m_bMacro); nRes = processEncryptionError(nRes, sFrom, params); if (SUCCEEDED_X2T(nRes)) @@ -2559,8 +2563,6 @@ namespace NExtractTools _UINT32 docx_dir2doc (const std::wstring &sDocxDir, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) { return AVS_FILEUTILS_ERROR_CONVERT; - COfficeDocFile docFile; - return /*S_OK == docFile.SaveToFile(sTo, sDocxDir, NULL) ? 0 : */AVS_FILEUTILS_ERROR_CONVERT; } // doct -> rtf @@ -2613,7 +2615,8 @@ namespace NExtractTools //docx folder to rtf RtfConvertationManager rtfConvert; - rtfConvert.m_sTempFolder = sTemp; + rtfConvert.m_sTempFolder = sTemp; + rtfConvert.m_nUserLCID = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; nRes = rtfConvert.ConvertOOXToRtf(sTo, sResultDocxDir); } @@ -4438,8 +4441,10 @@ namespace NExtractTools _UINT32 xls2xlsm_dir (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params) { params.m_bMacro = true; + + int lcid = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; - _UINT32 nRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), sTemp, NULL, params.m_bMacro); + _UINT32 nRes = ConvertXls2Xlsx( sFrom, sTo, params.getPassword(), params.getFontPath(), sTemp, lcid, params.m_bMacro); nRes = processEncryptionError(nRes, sFrom, params); return nRes; @@ -4472,7 +4477,10 @@ namespace NExtractTools NSDirectory::CreateDirectory(sResultXlsxDir); params.m_bMacro = true; - _UINT32 nRes = ConvertXls2Xlsx( sFrom, sResultXlsxDir, params.getPassword(), params.getFontPath(), sTemp, NULL, params.m_bMacro); + + int lcid = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; + + _UINT32 nRes = ConvertXls2Xlsx( sFrom, sResultXlsxDir, params.getPassword(), params.getFontPath(), sTemp, lcid, params.m_bMacro); nRes = processEncryptionError(nRes, sFrom, params); if (SUCCEEDED_X2T(nRes)) diff --git a/X2tConverter/src/cextracttools.h b/X2tConverter/src/cextracttools.h index e9cba8ac7d..ff85b27447 100644 --- a/X2tConverter/src/cextracttools.h +++ b/X2tConverter/src/cextracttools.h @@ -1096,6 +1096,10 @@ namespace NExtractTools else m_sFileTo->append(FileFormatChecker.GetExtensionByType(toFormat)); } + else if ( AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM == toFormat || AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF == toFormat) + { + toFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; + } *m_nFormatTo = toFormat; } bool getDontSaveAdditional() const