Compare commits

..

10 Commits

28 changed files with 122 additions and 410 deletions

View File

@ -72,6 +72,10 @@ extern NSString *const SRHTTPResponseErrorKey;
// Optional array of cookies (NSHTTPCookie objects) to apply to the connections
@property (nonatomic, readwrite) NSArray * requestCookies;
// Optional proxy configuration dictionary (kCFStreamPropertyHTTPProxy format).
// Set before calling -open. Example: Proxyman at 127.0.0.1:9090.
@property (nonatomic, strong) NSDictionary *proxyDictionary;
// This returns the negotiated protocol.
// It will be nil until after the handshake completes.
@property (nonatomic, readonly, copy) NSString *protocol;

View File

@ -619,7 +619,16 @@ static __strong NSData *CRLFCRLF;
_inputStream.delegate = self;
_outputStream.delegate = self;
if (self.proxyDictionary) {
CFReadStreamSetProperty((__bridge CFReadStreamRef)_inputStream,
kCFStreamPropertyHTTPProxy,
(__bridge CFDictionaryRef)self.proxyDictionary);
CFWriteStreamSetProperty((__bridge CFWriteStreamRef)_outputStream,
kCFStreamPropertyHTTPProxy,
(__bridge CFDictionaryRef)self.proxyDictionary);
}
[self setupNetworkServiceType:_urlRequest.networkServiceType];
}

View File

@ -38,6 +38,8 @@
#include <memory>
#include "../../../../../DesktopEditor/graphics/BaseThread.h"
#define _LOGGER_SOCKETS
namespace NSNetwork
{
namespace NSWebSocket
@ -124,6 +126,10 @@ namespace NSNetwork
}
//webSocket.connect(url, queryDst, sio::string_message::create(sAuth));
#ifdef _LOGGER_SOCKETS
m_socket->set_proxy_basic_auth("http://127.0.0.1:9090", "", "");
#endif
m_connecting_in_process = true;
m_socket->connect(m_base->url, queryDst, objAuth);

View File

@ -42,6 +42,8 @@
#include <memory>
#include "../../../../../DesktopEditor/graphics/BaseThread.h"
#define _LOGGER_SOCKETS
namespace NSNetwork
{
namespace NSWebSocket
@ -113,6 +115,10 @@ namespace NSNetwork
}
//webSocket.connect(url, queryDst, sio_no_tls::string_message::create(sAuth));
#ifdef _LOGGER_SOCKETS
m_socket->set_proxy_basic_auth("http://127.0.0.1:9090", "", "");
#endif
m_connecting_in_process = true;
m_socket->connect(m_base->url, queryDst, objAuth);

View File

@ -48,7 +48,7 @@
}
- (void)open
{
{
if (m_url && m_url.length)
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:m_url]];
@ -58,6 +58,19 @@
protocols:nil
allowsUntrustedSSLCertificates:YES];
self.socket.delegate = self;
#ifdef _LOGGER_SOCKETS
self.socket.proxyDictionary = @{
(NSString *)kCFNetworkProxiesHTTPEnable: @YES,
(NSString *)kCFNetworkProxiesHTTPProxy: @"127.0.0.1",
(NSString *)kCFNetworkProxiesHTTPPort: @9090,
(NSString *)kCFNetworkProxiesHTTPSEnable: @YES,
(NSString *)kCFNetworkProxiesHTTPSProxy: @"127.0.0.1",
(NSString *)kCFNetworkProxiesHTTPSPort: @9090
};
NSLog(@"[SocketRocket] Proxyman proxy enabled: 127.0.0.1:9090");
#endif
[self.socket open];
}
}
@ -65,7 +78,7 @@
- (void)send:(NSString*)message
{
#if _LOGGER_SOCKETS
#ifdef _LOGGER_SOCKETS
NSLog(@"------------------- SEND TO SOCKET -------------------");
NSLog(@"%@", message);
@ -101,7 +114,7 @@
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message
{
#if _LOGGER_SOCKETS
#ifdef _LOGGER_SOCKETS
NSLog(@"------------------- SOCKET RECEIVE MESSAGE -------------------");
NSLog(@"%@", message);
@ -119,7 +132,7 @@
{
m_listener->onOpen();
#if _LOGGER_SOCKETS
#ifdef _LOGGER_SOCKETS
NSLog(@"------------------- SOCKET OPEN -------------------");
NSLog(@"URL : %@", webSocket.url);
@ -134,7 +147,7 @@
{
m_listener->onError(error.localizedDescription.stdstring);
#if _LOGGER_SOCKETS
#ifdef _LOGGER_SOCKETS
NSLog(@"---------------------------------------------------------");
NSLog(@"------------------- SOCKET ERROR : %@ ------------", error);
@ -147,7 +160,7 @@
{
m_listener->onClose(code, reason.stdstring);
#if _LOGGER_SOCKETS
#ifdef _LOGGER_SOCKETS
NSLog(@"---------------------------------------------------------");
NSLog(@"------------------- SOCKET CLOSE : %@ -----------", reason);
@ -158,7 +171,7 @@
- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload
{
#if _LOGGER_SOCKETS
#ifdef _LOGGER_SOCKETS
NSString *str = [[NSString alloc] initWithData:pongPayload encoding:NSUTF8StringEncoding];

View File

@ -726,7 +726,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(int nPageIndex, int nRas
GP<DjVuImage> pPage = m_pDoc->get_page(nPageIndex);
//pPage->wait_for_complete_decode();
pPage->set_rotate(0);
return ConvertToPixels(pPage, nRasterW, nRasterH, bIsFlip, true);
return ConvertToPixels(pPage, nRasterW, nRasterH, bIsFlip);
}
catch (...)
{
@ -734,11 +734,11 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(int nPageIndex, int nRas
return NULL;
}
unsigned char* CDjVuFileImplementation::ConvertToPixels(GP<DjVuImage>& pPage, int nImageW, int nImageH, bool bFlip, bool bIsSwapRGB)
unsigned char* CDjVuFileImplementation::ConvertToPixels(GP<DjVuImage>& pPage, int nImageW, int nImageH, bool bFlip)
{
BYTE* pBufferDst = NULL;
auto processPixmap = [&](GP<GPixmap> pImage, bool bFlip = false, bool bIsSwapRGB = false)
auto processPixmap = [&](GP<GPixmap> pImage, bool bFlip = false)
{
pBufferDst = new BYTE[4 * nImageW * nImageH];
@ -749,10 +749,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(GP<DjVuImage>& pPage, in
GPixel* pLine = pImage->operator[](nRow);
for (int i = 0; i < nImageW; ++i)
{
if (bIsSwapRGB)
*pBuffer++ = 0xFF000000 | pLine->b << 16 | pLine->g << 8 | pLine->r;
else
*pBuffer++ = 0xFF000000 | pLine->r << 16 | pLine->g << 8 | pLine->b;
*pBuffer++ = 0xFF000000 | pLine->r << 16 | pLine->g << 8 | pLine->b;
++pLine;
}
}
@ -793,7 +790,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(GP<DjVuImage>& pPage, in
if (pPage->is_legal_photo() || pPage->is_legal_compound())
{
GP<GPixmap> pImage = pPage->get_pixmap(oRectAll, oRectAll);
processPixmap(pImage, bFlip, bIsSwapRGB);
processPixmap(pImage, bFlip);
}
else if (pPage->is_legal_bilevel())
{
@ -805,7 +802,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(GP<DjVuImage>& pPage, in
GP<GPixmap> pImage = pPage->get_pixmap(oRectAll, oRectAll);
if (pImage)
{
processPixmap(pImage, bFlip, bIsSwapRGB);
processPixmap(pImage, bFlip);
}
else
{

View File

@ -83,7 +83,7 @@ public:
private:
unsigned char* ConvertToPixels(GP<DjVuImage>& pPage, int nRasterW, int nRasterH, bool bIsFlip = false, bool bIsSwapRGB = false);
unsigned char* ConvertToPixels(GP<DjVuImage>& pPage, int nRasterW, int nRasterH, bool bIsFlip = false);
void CreateFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, int nPage, XmlUtils::CXmlNode& oText);
void CreatePdfFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, int nPage, XmlUtils::CXmlNode& oText);

View File

@ -267,7 +267,7 @@ namespace SimpleTypes
std::wstring CGuid::ToString (bool braces) const
{
std::wstringstream sstream;
sstream << boost::wformat( L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" ) % m_oGUID.a % m_oGUID.b % m_oGUID.c % m_oGUID.d % m_oGUID.e % m_oGUID.f % m_oGUID.g % m_oGUID.h % m_oGUID.i % m_oGUID.j % m_oGUID.k;
sstream << boost::wformat( L"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X" ) % m_oGUID.a % m_oGUID.b % m_oGUID.c % m_oGUID.d % m_oGUID.e % m_oGUID.f % m_oGUID.g % m_oGUID.h % m_oGUID.i % m_oGUID.j % m_oGUID.k;
std::wstring res = (braces ? L"{" : L"") + sstream.str() + (braces ? L"}" : L"");
return res;
}

View File

@ -227,7 +227,7 @@ namespace OOX
}
//------------------------------------------------------------------------------------------------------------------------
CDocument::CDocument(OOX::Document *pMain, OOX::FileType type)
: File(pMain), IFileContainer(pMain), WritingElementWithChilds<>(pMain)
: File(pMain), IFileContainer(pMain), WritingElement(pMain)
{
m_bMacroEnabled = false;
@ -254,7 +254,7 @@ namespace OOX
}
}
CDocument::CDocument(OOX::Document *pMain, const CPath& oRootPath, const CPath& oPath, OOX::FileType type)
: File(pMain), IFileContainer(pMain), WritingElementWithChilds<>(pMain)
: File(pMain), IFileContainer(pMain), WritingElement(pMain)
{
m_bMacroEnabled = false;
@ -302,13 +302,13 @@ namespace OOX
docx->m_bGlossaryRead = false;
}
}
CDocument::CDocument(XmlUtils::CXmlNode& oNode) : File(NULL), IFileContainer(NULL), WritingElementWithChilds<>(NULL)
CDocument::CDocument(XmlUtils::CXmlNode& oNode) : File(NULL), IFileContainer(NULL), WritingElement(NULL)
{
m_bMacroEnabled = false;
fromXML( oNode );
}
CDocument::CDocument(XmlUtils::CXmlLiteReader& oReader) : File(NULL), IFileContainer(NULL), WritingElementWithChilds<>(NULL)
CDocument::CDocument(XmlUtils::CXmlLiteReader& oReader) : File(NULL), IFileContainer(NULL), WritingElement(NULL)
{
m_bMacroEnabled = false;
@ -403,7 +403,8 @@ namespace OOX
{
if (document->m_arrSections.empty())
{
document->m_arrSections.emplace_back();
OOX::CDocument::_section section;
document->m_arrSections.push_back(section);
}
document->m_arrSections.back().sect = m_oSectPr.GetPointer();
document->m_arrSections.back().end_elm = document->m_arrItems.size(); //активный рутовый еще не добавлен
@ -491,7 +492,11 @@ namespace OOX
void CDocument::ClearItems()
{
WritingElementWithChilds<>::ClearItems();
for ( size_t i = 0; i < m_arrItems.size(); ++i)
{
if ( m_arrItems[i] )delete m_arrItems[i];
}
m_arrItems.clear();
//----------
m_arrSections.clear();
}

View File

@ -127,7 +127,7 @@ namespace OOX
//--------------------------------------------------------------------------------
// CDocument 17.2.3 (Part 1)
//--------------------------------------------------------------------------------
class CDocument : public OOX::File, public IFileContainer, public WritingElementWithChilds<>
class CDocument : public OOX::File, public IFileContainer, public WritingElement
{
public:
CDocument(OOX::Document *pMain = NULL, OOX::FileType type = OOX::FileTypes::Document);
@ -171,6 +171,8 @@ namespace OOX
nullable<OOX::Logic::CSectionProperty> m_oSectPr;
nullable<OOX::Logic::CBackground> m_oBackground;
std::vector<WritingElement*> m_arrItems;
//---------------------------------------------------------------------------------------------
struct _section
{

View File

@ -185,10 +185,10 @@ namespace OOX
{
if (m_oParagraphProperty)
{
pItem = new CParagraphProperty(*m_oParagraphProperty);
pItem->fromXML(oItem);
m_oParagraphProperty = dynamic_cast<CParagraphProperty*>(pItem);
CParagraphProperty prop2(oItem);
CParagraphProperty newProp = CParagraphProperty::Merge(*m_oParagraphProperty, prop2);
pItem = m_oParagraphProperty = new CParagraphProperty(newProp);
}
else
{
@ -331,10 +331,12 @@ namespace OOX
{// c копией .. для быстрого доступа/анализа
if (m_oParagraphProperty)
{
pItem = new CParagraphProperty(*m_oParagraphProperty);
pItem->m_pMainDocument = document;
CParagraphProperty prop2(document);
prop2.fromXML(oReader);
m_oParagraphProperty = dynamic_cast<CParagraphProperty*>(pItem);
pItem = m_oParagraphProperty = new CParagraphProperty(CParagraphProperty::Merge(*m_oParagraphProperty, prop2));
m_arrItems.push_back( pItem );
continue;
}
else
{
@ -381,21 +383,9 @@ namespace OOX
}
else if (L"p" == sName)
{
WritingElementWithChilds* parent = dynamic_cast<WritingElementWithChilds*>(m_oParent);
if (parent)
{
WritingElement* pItemUpper = new CParagraph(document, parent);
if (pItemUpper)
{
pItemUpper->fromXML(oReader);
parent->m_arrItems.push_back(pItemUpper);
}
}
else
{
int nDepthChild = oReader.GetDepth();
fromXML(nDepthChild, oReader);
}
int nDepthChild = oReader.GetDepth();
fromXML(nDepthChild, oReader);
}
if ( pItem )
{

View File

@ -582,7 +582,7 @@ namespace OOX
}
}
}
void CParagraphProperty::fromXML(XmlUtils::CXmlLiteReader& oReader/*, bool bEmbedded*/)
void CParagraphProperty::fromXML(XmlUtils::CXmlLiteReader& oReader)
{
if ( oReader.IsEmptyNode() )
return;
@ -659,13 +659,15 @@ namespace OOX
if (doc->m_arrSections.empty())
{
doc->m_arrSections.emplace_back();
OOX::CDocument::_section section;
doc->m_arrSections.push_back(section);
}
doc->m_arrSections.back().sect = m_oSectPr.GetPointer();
doc->m_arrSections.back().end_elm = doc->m_arrItems.size() + 1; // порядок выше - сначала читаем, потом добавляем
doc->m_arrSections.emplace_back();
doc->m_arrSections.back().start_elm = doc->m_arrItems.size() + 1;
OOX::CDocument::_section section;
section.start_elm = doc->m_arrItems.size() + 1;
doc->m_arrSections.push_back(section);
}
}
}

View File

@ -1225,7 +1225,6 @@ namespace OOX
}break;
case 1:
{
pReader->Skip(4); // size
content = pReader->GetString2();
}break;
default:

View File

@ -443,10 +443,9 @@ void embeddings::write(const std::wstring & RootPath)
items[i].type == typeControlProps ||
items[i].type == typeControl))
{
size_t pos_off = items[i].outputName.rfind(L"/");
size_t pos = items[i].outputName.rfind(L".");
std::wstring extension = (pos != std::wstring::npos && pos > pos_off) ? items[i].outputName.substr(pos + 1) : L"";
int pos = items[i].outputName.rfind(L".");
std::wstring extension = pos >= 0 ? items[i].outputName.substr(pos + 1) : L"";
content_types.add_or_find_default(extension);

View File

@ -160,7 +160,7 @@ void paragraph_format_properties::docx_convert(oox::docx_conversion_context & Co
}
if (Context.get_rtl()) //может быть он установился от стиля родителя !!
{
_pPr << L"<w:bidi w:val=\"1\"/>";
_pPr << L"<w:bidi/>";
}
odf_reader::list_style_container & list_styles = Context.root()->odf_context().listStyleContainer();
@ -233,15 +233,6 @@ void paragraph_format_properties::docx_convert(oox::docx_conversion_context & Co
case text_align::End: jc = Context.get_rtl() ? L"start": L"end"; break;
}
if( Context.get_rtl() )
{
switch(fo_text_align_->get_type())
{
case text_align::Left: jc = L"right"; break;
case text_align::Right: jc = L"left"; break;
}
}
if (!jc.empty()) CP_XML_NODE(L"w:jc"){CP_XML_ATTR(L"w:val", jc );}
}
else if (fo_keep_with_next_) //&& Context.get_drop_cap_context().state() != 2

View File

@ -155,11 +155,11 @@ namespace utils//////////////////////////////////////////// ОБЩАЯ хрен
{
nDate = boost::lexical_cast<__int64>(oox_date_time);
}
bool bPT = (nDate < 1);
std::wstring sDate, sTime;
if (dTime > 0)
{
sTime = convert_time(dTime, bPT);
sTime = convert_time(dTime, false);
}
if (nDate > 0)
{
@ -177,14 +177,7 @@ namespace utils//////////////////////////////////////////// ОБЩАЯ хрен
}
else
{
if (bPT)
{
odf_date_time = L"PT" + sTime;
}
else
{
odf_date_time = sDate + (sTime.empty() ? L"" : L"T" + sTime);
}
odf_date_time = sDate + (sTime.empty() ? L"" : L"T" + sTime);
}
return res;
}

View File

@ -153,7 +153,6 @@ namespace NSOnlineOfficeBinToPdf
MovePage = 4,
MergePages = 5,
SetType = 6,
RedactInfo = 7,
Undefined = 255
};
@ -251,11 +250,6 @@ namespace NSOnlineOfficeBinToPdf
pPdf->SetEditType(1);
break;
}
case AddCommandType::RedactInfo:
{
pPdf->RedactInfo(nPageNum);
break;
}
default:
return false;
}

View File

@ -416,49 +416,7 @@ PdfWriter::CObjectBase* DictToCDictObject2(Object* obj, PdfWriter::CDocument* pD
for (int nIndex = 0; nIndex < obj->dictGetLength(); ++nIndex)
{
char* chKey = obj->dictGetKey(nIndex);
if (strcmp("Resources", chKey) == 0)
{
Ref oResourcesRef = { -1, -1 };
if (obj->dictGetValNF(nIndex, &oTemp)->isRef())
oResourcesRef = oTemp.getRef();
oTemp.free();
PdfWriter::CObjectBase* pObj = oResourcesRef.num > 0 ? pManager->GetObj(oResourcesRef.num + nStartRefID) : NULL;
if (pObj)
{
pDict->Add(chKey, pObj);
pManager->IncRefCount(oResourcesRef.num + nStartRefID);
continue;
}
if (obj->dictGetVal(nIndex, &oTemp)->isDict())
{
PdfWriter::CResourcesDict* pResDict = pDoc->CreateResourcesDict(oResourcesRef.num < 0, false);
if (oResourcesRef.num > 0)
pManager->AddObj(oResourcesRef.num + nStartRefID, pResDict);
pDict->Add(chKey, pResDict);
for (int nIndex2 = 0; nIndex2 < oTemp.dictGetLength(); ++nIndex2)
{
Object oRes;
char* chKey2 = oTemp.dictGetKey(nIndex2);
oTemp.dictGetValNF(nIndex2, &oRes);
pBase = DictToCDictObject2(&oRes, pDoc, xref, pManager, nStartRefID, 0, bUndecodedStream);
pResDict->Add(chKey2, pBase);
oRes.free();
}
pResDict->Fix();
oTemp.free();
continue;
}
else
{
oTemp.free();
obj->dictGetValNF(nIndex, &oTemp);
}
}
else
obj->dictGetValNF(nIndex, &oTemp);
obj->dictGetValNF(nIndex, &oTemp);
pBase = DictToCDictObject2(&oTemp, pDoc, xref, pManager, nStartRefID, 0, bUndecodedStream);
pDict->Add(chKey, pBase);
oTemp.free();
@ -512,49 +470,7 @@ PdfWriter::CObjectBase* DictToCDictObject2(Object* obj, PdfWriter::CDocument* pD
oTemp.free();
continue;
}
else if (strcmp("Resources", chKey) == 0)
{
Ref oResourcesRef = { -1, -1 };
if (pODict->getValNF(nIndex, &oTemp)->isRef())
oResourcesRef = oTemp.getRef();
oTemp.free();
PdfWriter::CObjectBase* pObj = oResourcesRef.num > 0 ? pManager->GetObj(oResourcesRef.num + nStartRefID) : NULL;
if (pObj)
{
pDict->Add(chKey, pObj);
pManager->IncRefCount(oResourcesRef.num + nStartRefID);
continue;
}
if (pODict->getVal(nIndex, &oTemp)->isDict())
{
PdfWriter::CResourcesDict* pResDict = pDoc->CreateResourcesDict(oResourcesRef.num < 0, false);
if (oResourcesRef.num > 0)
pManager->AddObj(oResourcesRef.num + nStartRefID, pResDict);
pDict->Add(chKey, pResDict);
for (int nIndex2 = 0; nIndex2 < oTemp.dictGetLength(); ++nIndex2)
{
Object oRes;
char* chKey2 = oTemp.dictGetKey(nIndex2);
oTemp.dictGetValNF(nIndex2, &oRes);
pBase = DictToCDictObject2(&oRes, pDoc, xref, pManager, nStartRefID, 0, bUndecodedStream);
pResDict->Add(chKey2, pBase);
oRes.free();
}
pResDict->Fix();
oTemp.free();
continue;
}
else
{
oTemp.free();
pODict->getValNF(nIndex, &oTemp);
}
}
else
pODict->getValNF(nIndex, &oTemp);
pODict->getValNF(nIndex, &oTemp);
pBase = DictToCDictObject2(&oTemp, pDoc, xref, pManager, nStartRefID);
pDict->Add(chKey, pBase);
oTemp.free();
@ -1053,7 +969,6 @@ CPdfEditor::CPdfEditor(const std::wstring& _wsSrcFile, const wchar_t* _wsPasswor
m_nEditPage = -1;
m_nError = 0;
m_nMode = Mode::Unknown;
m_nRedactInfo = 0;
PDFDoc* pPDFDocument = m_pReader->GetPDFDocument(0);
if (!pPDFDocument)
@ -1083,7 +998,6 @@ void CPdfEditor::SetMode(Mode nMode)
else if (m_nMode == Mode::WriteNew)
{
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
pDoc->CreateNew();
PdfWriter::CPageTree* pPageTree = pDoc->GetPageTree();
m_mObjManager.SetDoc(pDoc);
int nPages = m_pReader->GetNumPages();
@ -1093,13 +1007,6 @@ void CPdfEditor::SetMode(Mode nMode)
NewFrom();
}
}
void CPdfEditor::RedactInfo(int nFlag)
{
if (m_nMode != Mode::Unknown)
return;
m_pWriter->GetDocument()->RedactInfo(nFlag);
m_nRedactInfo = nFlag;
}
bool CPdfEditor::IncrementalUpdates()
{
if (m_nMode != Mode::Unknown)
@ -1109,7 +1016,6 @@ bool CPdfEditor::IncrementalUpdates()
PDFDoc* pPDFDocument = m_pReader->GetPDFDocument(0);
XRef* xref = pPDFDocument->getXRef();
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
pDoc->CreateNew();
std::string sPathUtf8New = U_TO_UTF8(m_wsDstFile);
std::string sPathUtf8Old = U_TO_UTF8(m_wsSrcFile);
@ -2431,11 +2337,11 @@ bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength, PDFD
if (oResourcesRef.num > 0)
m_mObjManager.AddObj(oResourcesRef.num + nStartRefID, pDict);
pPage->Add(chKey, pDict);
for (int nIndex2 = 0; nIndex2 < oTemp.dictGetLength(); ++nIndex2)
for (int nIndex = 0; nIndex < oTemp.dictGetLength(); ++nIndex)
{
Object oRes;
char* chKey2 = oTemp.dictGetKey(nIndex2);
oTemp.dictGetValNF(nIndex2, &oRes);
char* chKey2 = oTemp.dictGetKey(nIndex);
oTemp.dictGetValNF(nIndex, &oRes);
PdfWriter::CObjectBase* pBase = DictToCDictObject2(&oRes, pDoc, xref, &m_mObjManager, nStartRefID);
pDict->Add(chKey2, pBase);
oRes.free();
@ -4145,35 +4051,7 @@ void CPdfEditor::ClearPage()
pageObj.free();
if (m_nMode == Mode::Split || m_nMode == Mode::WriteNew)
{
PdfWriter::CPage* pPage = pDoc->GetCurPage();
auto removeContentObj = [&](PdfWriter::CObjectBase* pObj)
{
if (pObj->GetType() == PdfWriter::object_type_DICT)
{
PdfWriter::CObjectBase* pLength = ((PdfWriter::CDictObject*)pObj)->Get("Length");
if (pLength)
{
int nLengthID = m_mObjManager.FindObj(pLength);
m_mObjManager.RemoveObj(nLengthID);
}
}
int nObjID = m_mObjManager.FindObj(pObj);
m_mObjManager.RemoveObj(nObjID);
};
PdfWriter::CObjectBase* pObjContents = pPage->Get("Contents");
if (pObjContents && pObjContents->GetType() == PdfWriter::object_type_ARRAY)
{
PdfWriter::CArrayObject* pContents = (PdfWriter::CArrayObject*)pObjContents;
for (int i = 0; i < pContents->GetCount(); ++i)
removeContentObj(pContents->Get(i));
}
else if (pObjContents)
removeContentObj(pObjContents);
pDoc->ClearPageFull();
}
else
pDoc->ClearPage();

View File

@ -82,7 +82,6 @@ public:
CPdfEditor(const std::wstring& _wsSrcFile, const wchar_t* _wsPassword, const std::wstring& _wsDstFile, CPdfReader* _pReader, CPdfWriter* _pWriter, Mode nMode = Mode::Unknown);
void SetMode(Mode nMode);
void RedactInfo(int nFlag);
int GetError();
void Close();
@ -141,7 +140,6 @@ private:
// 0 - Дозапись. pReader и pWriter работают с одним файлом
// 1 - Split. pReader и pWriter работают с разными файлами
Mode m_nMode;
int m_nRedactInfo;
int m_nEditPage;
int m_nOriginIndex;
};

View File

@ -140,7 +140,7 @@ bool CPdfFile::EditPdf(const std::wstring& wsDstFile)
m_pInternal->pReader->CleanUp();
RELEASEOBJECT(m_pInternal->pWriter);
m_pInternal->pWriter = new CPdfWriter(m_pInternal->pAppFonts, false, this, false, m_pInternal->wsTempFolder);
m_pInternal->pWriter = new CPdfWriter(m_pInternal->pAppFonts, false, this, true, m_pInternal->wsTempFolder);
RELEASEOBJECT(m_pInternal->pEditor);
m_pInternal->pEditor = new CPdfEditor(m_pInternal->wsSrcFile, m_pInternal->wsPassword, wsDstFile, m_pInternal->pReader, m_pInternal->pWriter);
@ -159,12 +159,6 @@ void CPdfFile::SetEditType(int nType)
if (nType == 1)
m_pInternal->pEditor->SetMode(CPdfEditor::Mode::WriteNew);
}
void CPdfFile::RedactInfo(int nFlag)
{
if (!m_pInternal->pEditor)
return;
m_pInternal->pEditor->RedactInfo(nFlag);
}
bool CPdfFile::EditPage(int nPageIndex)
{
if (!m_pInternal->pEditor)

View File

@ -102,7 +102,6 @@ public:
bool EditPdf(const std::wstring& wsDstFile = L"");
void EditClose();
void SetEditType(int nType);
void RedactInfo(int nFlag);
// Манипуляции со страницами возможны в режиме редактирования
bool EditPage (int nPageIndex);
bool DeletePage(int nPageIndex);

View File

@ -95,7 +95,6 @@ namespace PdfWriter
m_pTransparencyGroup = NULL;
m_pFreeTypeLibrary = NULL;
m_bPDFAConformance = false;
m_nRedactInfo = 0;
m_pAcroForm = NULL;
m_pFieldsResources = NULL;
}
@ -497,10 +496,6 @@ namespace PdfWriter
{
m_bPDFAConformance = isPDFA;
}
void CDocument::SetRedactInfo(int nFlag)
{
m_nRedactInfo = nFlag;
}
bool CDocument::IsPDFA() const
{
return m_bPDFAConformance;

View File

@ -123,7 +123,6 @@ namespace PdfWriter
void SetKeywords(const std::string& sKeywords);
void SetPDFAConformanceMode(bool isPDFA);
void SetRedactInfo(int nFlag);
bool IsPDFA() const;
CPage* AddPage();
@ -345,7 +344,6 @@ namespace PdfWriter
std::vector<CFontCidTrueType*> m_vFreeTypeFonts;
FT_Library m_pFreeTypeLibrary;
bool m_bPDFAConformance;
int m_nRedactInfo;
std::wstring m_wsDocumentID;
CDictObject* m_pAcroForm;
CResourcesDict* m_pFieldsResources;

View File

@ -521,7 +521,6 @@ void ApplyRedactToGray(const std::vector<double>& arrQuadPoints, BYTE* pImage, i
RedactOutputDev::RedactOutputDev(CPdfWriter* pRenderer, CObjectsManager* pObjMng, int nStartRefID)
{
m_pXref = NULL;
m_pResources = NULL;
m_pRenderer = pRenderer;
m_mObjManager = pObjMng;
@ -566,32 +565,6 @@ void RedactOutputDev::startPage(int nPageIndex, GfxState *pGState)
m_pPage = m_pDoc->GetEditPage(nPageIndex);
m_pRenderer->EditPage(m_pPage);
m_pDoc->SetCurPage(m_pPage);
auto removeContentObj = [&](PdfWriter::CObjectBase* pObj)
{
if (pObj->GetType() == PdfWriter::object_type_DICT)
{
PdfWriter::CObjectBase* pLength = ((PdfWriter::CDictObject*)pObj)->Get("Length");
if (pLength)
{
int nLengthID = m_mObjManager->FindObj(pLength);
m_mObjManager->RemoveObj(nLengthID);
}
}
int nObjID = m_mObjManager->FindObj(pObj);
m_mObjManager->RemoveObj(nObjID);
};
PdfWriter::CObjectBase* pObjContents = m_pPage->Get("Contents");
if (pObjContents && pObjContents->GetType() == PdfWriter::object_type_ARRAY)
{
PdfWriter::CArrayObject* pContents = (PdfWriter::CArrayObject*)pObjContents;
for (int i = 0; i < pContents->GetCount(); ++i)
removeContentObj(pContents->Get(i));
}
else if (pObjContents)
removeContentObj(pObjContents);
m_pDoc->ClearPageFull();
}
void RedactOutputDev::endPage()
@ -1401,16 +1374,11 @@ void RedactOutputDev::drawForm(GfxState *pGState, Gfx *gfx, Ref id, const char*
pObj = pOrigForm->Get("Matrix");
if (pObj)
pNewForm->Add("Matrix", pObj->Copy());
PdfWriter::CResourcesDict* pNewResources = NULL;
pObj = pOrigForm->Get("Resources");
if (pObj)
{
pNewForm->Add("Resources", pObj->Copy());
pNewResources = dynamic_cast<CResourcesDict*>(pNewForm->Get("Resources"));
}
PdfWriter::CResourcesDict* pResources = GetResources(gfx, pNewForm);
PdfWriter::CResourcesDict* pResources = GetResources(gfx);
if (pResources)
name = pResources->GetXObjectName(pNewForm);
@ -1423,7 +1391,6 @@ void RedactOutputDev::drawForm(GfxState *pGState, Gfx *gfx, Ref id, const char*
RedactOutputDev* pFormOutputDev = new RedactOutputDev(m_pRenderer, m_mObjManager, m_nStartRefID);
pFormOutputDev->NewPDF(m_pXref);
pFormOutputDev->m_pPage = pFakePage;
pFormOutputDev->m_pResources = pNewResources;
std::vector<double> arrFormQuadPoints;
double dInvMatrix[6] = { 1, 0, 0, 1, 0, 0 };
InvertMatrix(m_arrMatrix, dInvMatrix);
@ -1919,11 +1886,8 @@ CObjectBase* RedactOutputDev::CreateImage(Gfx *gfx, int nWidth, int nHeight, uns
return pObj;
}
CResourcesDict* RedactOutputDev::GetResources(Gfx *gfx, CDictObject* pNewForm)
CResourcesDict* RedactOutputDev::GetResources(Gfx *gfx)
{
if (m_pResources)
return m_pResources;
PdfWriter::CResourcesDict* pResources = NULL;
Object* pContent = gfx->getTopContentStreamStack();
if (pContent && pContent->isRef())
@ -1937,7 +1901,7 @@ CResourcesDict* RedactOutputDev::GetResources(Gfx *gfx, CDictObject* pNewForm)
if (!pResources)
{
pResources = new PdfWriter::CResourcesDict(NULL, true, false);
(pNewForm ? pNewForm : pDictForm)->Add("Resources", pResources);
pDictForm->Add("Resources", pResources);
}
}
}

View File

@ -201,12 +201,11 @@ namespace PdfWriter
void DoStateOp();
void DrawXObject(const char* name);
CObjectBase* CreateImage(Gfx *gfx, int nWidth, int nHeight, unsigned int nFilter, int nBPC, const char* sCS);
CResourcesDict* GetResources(Gfx *gfx, CDictObject* pNewForm = NULL);
CResourcesDict* GetResources(Gfx *gfx);
XRef* m_pXref;
std::vector<double> m_arrQuadPoints;
Aggplus::CGraphicsPath m_oPathRedact;
CResourcesDict* m_pResources;
CPdfWriter* m_pRenderer;
CObjectsManager* m_mObjManager;

View File

@ -67,19 +67,6 @@ namespace PdfWriter
pProcset->Add(new CNameObject("ImageI"));
}
}
CObjectBase* CResourcesDict::Copy(CObjectBase* pOut) const
{
CResourcesDict* pDict = pOut && pOut->GetType() == object_type_DICT ? dynamic_cast<CResourcesDict*>(pOut) : new CResourcesDict(NULL, true, false);
if (!pDict)
return NULL;
for (auto const &oIter : m_mList)
pDict->Add(oIter.first, oIter.second->Copy());
pDict->Fix();
return pDict;
}
const char* CResourcesDict::GetFontName(CFontDict* pFont)
{
if (!m_pFonts)

View File

@ -46,8 +46,6 @@ namespace PdfWriter
public:
CResourcesDict(CXref* pXref, bool bInline, bool bProcSet);
virtual CObjectBase* Copy(CObjectBase* pOut) const override;
const char* GetFontName(CFontDict* pFont);
const char* GetExtGrStateName(CExtGrState* pState);
const char* GetXObjectName(CObjectBase* pXObject);

View File

@ -46,60 +46,6 @@
namespace Txt2Docx
{
namespace
{
bool isEmoji(const std::string& utf8Char)
{
if (utf8Char.empty()) return false;
unsigned char c = utf8Char[0];
uint32_t codePoint = 0;
if ((c & 0xF8) == 0xF0 && utf8Char.length() >= 4)
{
codePoint = ((utf8Char[0] & 0x07) << 18) |
((utf8Char[1] & 0x3F) << 12) |
((utf8Char[2] & 0x3F) << 6) |
(utf8Char[3] & 0x3F);
}
else if ((c & 0xF0) == 0xE0 && utf8Char.length() >= 3)
{
codePoint = ((utf8Char[0] & 0x0F) << 12) |
((utf8Char[1] & 0x3F) << 6) |
(utf8Char[2] & 0x3F);
}
else
{
return false;
}
return (codePoint >= 0x1F300 && codePoint <= 0x1F9FF) ||
(codePoint >= 0x2600 && codePoint <= 0x27BF) ||
(codePoint >= 0x2B00 && codePoint <= 0x2BFF) ||
(codePoint >= 0xFE00 && codePoint <= 0xFE0F) ||
(codePoint >= 0x1F900 && codePoint <= 0x1F9FF) ||
codePoint == 0x00A9 || codePoint == 0x00AE;
}
std::string escapeXml(const std::string& text)
{
std::string result;
result.reserve(text.length() * 2);
for (char ch : text)
{
switch (ch)
{
case '&': result += "&amp;"; break;
case '<': result += "&lt;"; break;
case '>': result += "&gt;"; break;
case '"': result += "&quot;"; break;
case '\'': result += "&apos;"; break;
default: result += ch; break;
}
}
return result;
}
}
class Converter_Impl
{
public:
@ -212,8 +158,8 @@ namespace Txt2Docx
void Converter::write(NSStringUtils::CStringBuilderA &stringWriter)
{
const char* fontName = "Courier New";
const char* emojiFontName = "Segoe UI Emoji";
const char* defaultSpacing = "<w:spacing w:after=\"0\" w:line=\"240\" w:lineRule=\"auto\"/>";
for (const std::string &lineRaw : converter_->m_inputFile.m_listContentutf8)
{
std::string line = lineRaw;
@ -230,86 +176,32 @@ namespace Txt2Docx
stringWriter.WriteString(fontName);
stringWriter.WriteString("\"/></w:rPr></w:pPr>");
size_t i = 0;
while (i < line.length())
size_t start = 0;
while (true)
{
unsigned char c = line[i];
size_t pos = line.find('\x09', start);
std::string segment = (pos == std::string::npos) ? line.substr(start) : line.substr(start, pos - start);
if ((c & 0xF0) == 0xF0 || (c & 0xE0) == 0xE0)
if (!segment.empty())
{
int possibleLen = ((c & 0xF0) == 0xF0) ? 4 : 3;
if (i + possibleLen <= line.length())
{
std::string possible = line.substr(i, possibleLen);
if (isEmoji(possible))
{
stringWriter.WriteString("<w:r><w:rPr><w:rFonts w:ascii=\"");
stringWriter.WriteString(emojiFontName);
stringWriter.WriteString("\" w:hAnsi=\"");
stringWriter.WriteString(emojiFontName);
stringWriter.WriteString("\" w:cs=\"");
stringWriter.WriteString(emojiFontName);
stringWriter.WriteString("\"/></w:rPr><w:t xml:space=\"preserve\">");
stringWriter.WriteString(possible.c_str());
stringWriter.WriteString("</w:t></w:r>");
i += possibleLen;
continue;
}
}
stringWriter.WriteString("<w:r><w:rPr><w:rFonts w:ascii=\"");
stringWriter.WriteString(fontName);
stringWriter.WriteString("\" w:hAnsi=\"");
stringWriter.WriteString(fontName);
stringWriter.WriteString("\" w:cs=\"");
stringWriter.WriteString(fontName);
stringWriter.WriteString("\"/></w:rPr><w:t xml:space=\"preserve\">");
stringWriter.WriteString(segment.c_str());
stringWriter.WriteString("</w:t></w:r>");
}
size_t textStart = i;
while (i < line.length())
{
unsigned char next = line[i];
if ((next & 0xF0) == 0xF0 || (next & 0xE0) == 0xE0)
{
int checkLen = ((next & 0xF0) == 0xF0) ? 4 : 3;
if (i + checkLen <= line.length())
{
std::string check = line.substr(i, checkLen);
if (isEmoji(check))
break;
}
}
i++;
}
if (pos == std::string::npos)
break;
std::string textSegment = line.substr(textStart, i - textStart);
size_t tabStart = 0;
while (true)
{
size_t tabPos = textSegment.find('\x09', tabStart);
std::string seg = (tabPos == std::string::npos) ?
textSegment.substr(tabStart) :
textSegment.substr(tabStart, tabPos - tabStart);
if (!seg.empty())
{
std::string escaped = escapeXml(seg);
stringWriter.WriteString("<w:r><w:rPr><w:rFonts w:ascii=\"");
stringWriter.WriteString(fontName);
stringWriter.WriteString("\" w:hAnsi=\"");
stringWriter.WriteString(fontName);
stringWriter.WriteString("\" w:cs=\"");
stringWriter.WriteString(fontName);
stringWriter.WriteString("\"/></w:rPr><w:t xml:space=\"preserve\">");
stringWriter.WriteString(escaped.c_str());
stringWriter.WriteString("</w:t></w:r>");
}
if (tabPos == std::string::npos)
break;
stringWriter.WriteString("<w:r><w:tab/></w:r>");
tabStart = tabPos + 1;
}
stringWriter.WriteString("<w:tab/>");
start = pos + 1;
}
stringWriter.WriteString("</w:p>");
}
}