From 5f96f5dbb73481e5cf37629c1415874f17d9d9d3 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Fri, 9 Jul 2021 14:47:21 +0300 Subject: [PATCH] refactoring --- DesktopEditor/fontengine/FontManager.cpp | 14 +- DesktopEditor/fontengine/FontManager.h | 6 +- DesktopEditor/graphics/GraphicsRenderer.cpp | 156 ++++----- DjVuFile/wasm/all_files_test/code.js | 17 +- DjVuFile/wasm/all_files_test/selection.js | 348 ++++++++++++++++++++ XpsFile/XpsLib/Document.cpp | 44 +-- XpsFile/XpsLib/Document.h | 4 +- XpsFile/XpsLib/FontList.h | 8 +- XpsFile/XpsLib/Page.cpp | 30 +- XpsFile/XpsLib/StaticResources.cpp | 46 +-- XpsFile/XpsLib/StaticResources.h | 6 +- 11 files changed, 521 insertions(+), 158 deletions(-) create mode 100644 DjVuFile/wasm/all_files_test/selection.js diff --git a/DesktopEditor/fontengine/FontManager.cpp b/DesktopEditor/fontengine/FontManager.cpp index 2090e14059..b1a82c72e0 100644 --- a/DesktopEditor/fontengine/FontManager.cpp +++ b/DesktopEditor/fontengine/FontManager.cpp @@ -112,13 +112,13 @@ NSFonts::IFontStream* CApplicationFontStreams::GetStream(const std::wstring &str if (NULL != pStream) return pStream; - if (m_pMemoryStorage) - pStream = m_pMemoryStorage->Get(strFile); - else - { - pStream = new CFontStream(); - pStream->CreateFromFile(strFile); - } + if (m_pMemoryStorage) + pStream = m_pMemoryStorage->Get(strFile); + else + { + pStream = new CFontStream(); + pStream->CreateFromFile(strFile); + } m_mapStreams[strFile] = pStream; return pStream; diff --git a/DesktopEditor/fontengine/FontManager.h b/DesktopEditor/fontengine/FontManager.h index 3c86596dd5..4ad0c6f36e 100644 --- a/DesktopEditor/fontengine/FontManager.h +++ b/DesktopEditor/fontengine/FontManager.h @@ -111,10 +111,10 @@ public: class CApplicationFontStreams : public NSFonts::IApplicationFontStreams { private: - // этот мап нужно периодически опрашивать и удалять неиспользуемые стримы - std::map m_mapStreams; + // этот мап нужно периодически опрашивать и удалять неиспользуемые стримы + std::map m_mapStreams; public: - static CGlobalFontsMemoryStorage* m_pMemoryStorage; + static CGlobalFontsMemoryStorage* m_pMemoryStorage; CApplicationFontStreams(); virtual ~CApplicationFontStreams(); diff --git a/DesktopEditor/graphics/GraphicsRenderer.cpp b/DesktopEditor/graphics/GraphicsRenderer.cpp index 0811016ccf..8b3563b1af 100644 --- a/DesktopEditor/graphics/GraphicsRenderer.cpp +++ b/DesktopEditor/graphics/GraphicsRenderer.cpp @@ -855,45 +855,45 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType) } else { - #ifdef BUILDING_WASM_MODULE - if (m_oBrush.TexturePath.find(L"data:") == 0) - { - bool bIsOnlyOfficeHatch = false; - if (m_oBrush.TexturePath.find(L"onlyoffice_hatch") != std::wstring::npos) - bIsOnlyOfficeHatch = true; - m_oBrush.TexturePath.erase(0, m_oBrush.TexturePath.find(L',') + 1); - std::string sBase64MultyByte(m_oBrush.TexturePath.begin(), m_oBrush.TexturePath.end()); - int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(sBase64MultyByte.length()); - BYTE* pImageData = new BYTE[nDecodeLen + 64]; - if (TRUE == NSBase64::Base64Decode(sBase64MultyByte.c_str(), sBase64MultyByte.length(), pImageData, &nDecodeLen)) - { - CBgraFrame oFrame; - if (bIsOnlyOfficeHatch) - { - int nSize = (int)sqrt(nDecodeLen >> 2); - oFrame.put_IsRGBA(true); - oFrame.put_Data(pImageData); - oFrame.put_Width(nSize); - oFrame.put_Height(nSize); - oFrame.put_Stride(4 * nSize); - } - else - { - oFrame.put_IsRGBA(false); - oFrame.Decode(pImageData, nDecodeLen); - RELEASEARRAYOBJECTS(pImageData); - } - // pImage отдается pTextureBrush и освобождается вместе с pBrush - Aggplus::CImage* pImage = new Aggplus::CImage(); - pImage->Create(oFrame.get_Data(), oFrame.get_Width(), oFrame.get_Height(), oFrame.get_Stride()); - oFrame.ClearNoAttack(); - pTextureBrush = new Aggplus::CBrushTexture(pImage, oMode); - pTextureBrush->m_bReleaseImage = TRUE; - } - } - #else - pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode); - #endif + #ifdef BUILDING_WASM_MODULE + if (m_oBrush.TexturePath.find(L"data:") == 0) + { + bool bIsOnlyOfficeHatch = false; + if (m_oBrush.TexturePath.find(L"onlyoffice_hatch") != std::wstring::npos) + bIsOnlyOfficeHatch = true; + m_oBrush.TexturePath.erase(0, m_oBrush.TexturePath.find(L',') + 1); + std::string sBase64MultyByte(m_oBrush.TexturePath.begin(), m_oBrush.TexturePath.end()); + int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(sBase64MultyByte.length()); + BYTE* pImageData = new BYTE[nDecodeLen + 64]; + if (TRUE == NSBase64::Base64Decode(sBase64MultyByte.c_str(), sBase64MultyByte.length(), pImageData, &nDecodeLen)) + { + CBgraFrame oFrame; + if (bIsOnlyOfficeHatch) + { + int nSize = (int)sqrt(nDecodeLen >> 2); + oFrame.put_IsRGBA(true); + oFrame.put_Data(pImageData); + oFrame.put_Width(nSize); + oFrame.put_Height(nSize); + oFrame.put_Stride(4 * nSize); + } + else + { + oFrame.put_IsRGBA(false); + oFrame.Decode(pImageData, nDecodeLen); + RELEASEARRAYOBJECTS(pImageData); + } + // pImage отдается pTextureBrush и освобождается вместе с pBrush + Aggplus::CImage* pImage = new Aggplus::CImage(); + pImage->Create(oFrame.get_Data(), oFrame.get_Width(), oFrame.get_Height(), oFrame.get_Stride()); + oFrame.ClearNoAttack(); + pTextureBrush = new Aggplus::CBrushTexture(pImage, oMode); + pTextureBrush->m_bReleaseImage = TRUE; + } + } + #else + pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode); + #endif } if( pTextureBrush ) @@ -951,45 +951,45 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType) } else { - #ifdef BUILDING_WASM_MODULE - if (m_oBrush.TexturePath.find(L"data:") == 0) - { - bool bIsOnlyOfficeHatch = false; - if (m_oBrush.TexturePath.find(L"onlyoffice_hatch") != std::wstring::npos) - bIsOnlyOfficeHatch = true; - m_oBrush.TexturePath.erase(0, m_oBrush.TexturePath.find(L',') + 1); - std::string sBase64MultyByte(m_oBrush.TexturePath.begin(), m_oBrush.TexturePath.end()); - int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(sBase64MultyByte.length()); - BYTE* pImageData = new BYTE[nDecodeLen + 64]; - if (TRUE == NSBase64::Base64Decode(sBase64MultyByte.c_str(), sBase64MultyByte.length(), pImageData, &nDecodeLen)) - { - CBgraFrame oFrame; - if (bIsOnlyOfficeHatch) - { - int nSize = (int)sqrt(nDecodeLen >> 2); - oFrame.put_IsRGBA(true); - oFrame.put_Data(pImageData); - oFrame.put_Width(nSize); - oFrame.put_Height(nSize); - oFrame.put_Stride(4 * nSize); - } - else - { - oFrame.put_IsRGBA(false); - oFrame.Decode(pImageData, nDecodeLen); - RELEASEARRAYOBJECTS(pImageData); - } - // pImage отдается pTextureBrush и освобождается вместе с pBrush - Aggplus::CImage* pImage = new Aggplus::CImage(); - pImage->Create(oFrame.get_Data(), oFrame.get_Width(), oFrame.get_Height(), oFrame.get_Stride()); - oFrame.ClearNoAttack(); - pTextureBrush = new Aggplus::CBrushTexture(pImage, oMode); - pTextureBrush->m_bReleaseImage = TRUE; - } - } - #else - pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode); - #endif + #ifdef BUILDING_WASM_MODULE + if (m_oBrush.TexturePath.find(L"data:") == 0) + { + bool bIsOnlyOfficeHatch = false; + if (m_oBrush.TexturePath.find(L"onlyoffice_hatch") != std::wstring::npos) + bIsOnlyOfficeHatch = true; + m_oBrush.TexturePath.erase(0, m_oBrush.TexturePath.find(L',') + 1); + std::string sBase64MultyByte(m_oBrush.TexturePath.begin(), m_oBrush.TexturePath.end()); + int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(sBase64MultyByte.length()); + BYTE* pImageData = new BYTE[nDecodeLen + 64]; + if (TRUE == NSBase64::Base64Decode(sBase64MultyByte.c_str(), sBase64MultyByte.length(), pImageData, &nDecodeLen)) + { + CBgraFrame oFrame; + if (bIsOnlyOfficeHatch) + { + int nSize = (int)sqrt(nDecodeLen >> 2); + oFrame.put_IsRGBA(true); + oFrame.put_Data(pImageData); + oFrame.put_Width(nSize); + oFrame.put_Height(nSize); + oFrame.put_Stride(4 * nSize); + } + else + { + oFrame.put_IsRGBA(false); + oFrame.Decode(pImageData, nDecodeLen); + RELEASEARRAYOBJECTS(pImageData); + } + // pImage отдается pTextureBrush и освобождается вместе с pBrush + Aggplus::CImage* pImage = new Aggplus::CImage(); + pImage->Create(oFrame.get_Data(), oFrame.get_Width(), oFrame.get_Height(), oFrame.get_Stride()); + oFrame.ClearNoAttack(); + pTextureBrush = new Aggplus::CBrushTexture(pImage, oMode); + pTextureBrush->m_bReleaseImage = TRUE; + } + } + #else + pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode); + #endif } if( pTextureBrush ) diff --git a/DjVuFile/wasm/all_files_test/code.js b/DjVuFile/wasm/all_files_test/code.js index f815b93172..75cc35aa3e 100644 --- a/DjVuFile/wasm/all_files_test/code.js +++ b/DjVuFile/wasm/all_files_test/code.js @@ -160,7 +160,10 @@ window.onload = function() //console.log(message); }; - window.onscroll = function(e) { if (window.Viewer) window.Viewer.scroll(e); }; + window.onscroll = function(e) { if (window.Viewer) window.Viewer.scroll(e); }; + window.onmousedown = function(e) { if (window.Viewer) window.Viewer.OnMouseDown(e); }; + window.onmousemove = function(e) { if (window.Viewer) window.Viewer.OnMouseMove(e); }; + window.onmouseup = function(e) { if (window.Viewer) window.Viewer.OnMouseUp(e); }; this.timerAnimation = function() { @@ -318,6 +321,18 @@ window.onload = function() this.log("scroll: [" + document.scrollingElement.scrollLeft + ", " + document.scrollingElement.scrollTop + "]"); this.paint(); }; + + this.OnMouseDown = function(e) + { + }; + + this.OnMouseMove = function(e) + { + }; + + this.OnMouseUp = function(e) + { + }; this.paint = function() { diff --git a/DjVuFile/wasm/all_files_test/selection.js b/DjVuFile/wasm/all_files_test/selection.js new file mode 100644 index 0000000000..18a1fe60fd --- /dev/null +++ b/DjVuFile/wasm/all_files_test/selection.js @@ -0,0 +1,348 @@ +(function(window, undefined) { + +function CDocMetaSelection() +{ + this.Page1 = 0; + this.Line1 = 0; + this.Glyph1 = 0; + + this.Page2 = 0; + this.Line2 = 0; + this.Glyph2 = 0; + + this.IsSelection = false; +} + +function CSpan() +{ + this.fontName = 0; + this.fontSize = 0; + + this.colorR = 0; + this.colorG = 0; + this.colorB = 0; + + this.inner = ""; + + this.CreateDublicate = function() + { + var ret = new CSpan(); + + ret.fontName = this.fontName; + ret.fontSize = this.fontSize; + + ret.colorR = this.colorR; + ret.colorG = this.colorG; + ret.colorB = this.colorB; + + ret.inner = this.inner; + + return ret; + } +} + +function CDocMeta() +{ + this.Pages = null; + this.stream = null; + this.Selection = new CDocMetaSelection(); +} + +CDocMeta.prototype = +{ + getStreamPage : function(pageNum) + { + return this.stream; + }, + + GetNearestPos : function(pageNum, x, y) + { + var page = this.Pages[pageNum]; + var s = this.getStreamPage(pageNum); + s.Seek(page.start); + + // textline parameters + var _line = -1; + var _glyph = -1; + var _minDist = 0xFFFFFF; + + // textline parameters + var _lineX = 0; + var _lineY = 0; + var _lineEx = 0; + var _lineEy = 0; + var _lineAscent = 0; + var _lineDescent = 0; + var _lineWidth = 0; + var _lineGidExist = false; + var _linePrevCharX = 0; + var _lineCharCount = 0; + var _lineLastGlyphWidth = 0; + var _arrayGlyphOffsets = []; + + var _numLine = -1; + + var _lenGls = 0; + var tmp = 0; + + while (s.pos < page.end) + { + var command = s.GetUChar(); + + switch (command) + { + + case 80: + { + if (0 != _lineCharCount) + _linePrevCharX += s.GetDouble2(); + + _arrayGlyphOffsets[_lineCharCount] = _linePrevCharX; + + _lineCharCount++; + + if (_lineGidExist) + s.Skip(4); + else + s.Skip(2); + + if (0 == _lineWidth) + _lineLastGlyphWidth = s.GetDouble2(); + else + s.Skip(2); + + break; + } + + case 160: + { + // textline + _linePrevCharX = 0; + _lineCharCount = 0; + _lineWidth = 0; + + _arrayGlyphOffsets.splice(0, _arrayGlyphOffsets.length); + + ++_numLine; + + var mask = s.GetUChar(); + _lineX = s.GetDouble(); + _lineY = s.GetDouble(); + + if ((mask & 0x01) != 0) + { + _lineEx = 1; + _lineEy = 0; + } + else + { + _lineEx = s.GetDouble(); + _lineEy = s.GetDouble(); + } + + _lineAscent = s.GetDouble(); + _lineDescent = s.GetDouble(); + + if ((mask & 0x04) != 0) + _lineWidth = s.GetDouble(); + + if ((mask & 0x02) != 0) + _lineGidExist = true; + else + _lineGidExist = false; + + break; + } + case 162: + { + // textline end + + // все подсчитано + if (0 == _lineWidth) + _lineWidth = _linePrevCharX + _lineLastGlyphWidth; + + // в принципе код один и тот же. Но почти всегда линии горизонтальные. + // а для горизонтальной линии все можно пооптимизировать + if (_lineEx == 1 && _lineEy == 0) + { + var _distX = x - _lineX; + if (y >= (_lineY - _lineAscent) && y <= (_lineY + _lineDescent) && _distX >= 0 && _distX <= _lineWidth) + { + // попали внутрь линии. Теперь нужно найти глиф + _line = _numLine; + + _lenGls = _arrayGlyphOffsets.length; + for (_glyph = 0; _glyph < _lenGls; _glyph++) + { + if (_arrayGlyphOffsets[_glyph] > _distX) + break; + } + if (_glyph > 0) + --_glyph; + + return { Line : _line, Glyph : _glyph }; + } + + if (_distX >= 0 && _distX <= _lineWidth) + tmp = Math.abs(y - _lineY); + else if (_distX < 0) + { + tmp = Math.sqrt((x - _lineX) * (x - _lineX) + (y - _lineY) * (y - _lineY)); + } + else + { + var _xx1 = _lineX + _lineWidth; + tmp = Math.sqrt((x - _xx1) * (x - _xx1) + (y - _lineY) * (y - _lineY)); + } + + if (tmp < _minDist) + { + _minDist = tmp; + _line = _numLine; + + if (_distX < 0) + _glyph = -2; + else if (_distX > _lineWidth) + { + _glyph = -1; + } + else + { + _lenGls = _arrayGlyphOffsets.length; + for (_glyph = 0; _glyph < _lenGls; _glyph++) + { + if (_arrayGlyphOffsets[_glyph] > _distX) + break; + } + + if (_glyph > 0) + _glyph--; + } + } + + // Ничего не надо делать, уже найдена более "ближняя" линия + } + else + { + // определяем точки descent линии + var ortX = -_lineEy; + var ortY = _lineEx; + + var _dx = _lineX + ortX * _lineDescent; + var _dy = _lineY + ortY * _lineDescent; + + // теперь проекции (со знаком) на линию descent + var h = -((x - _dx) * ortX + (y - _dy) * ortY); + var w = (x - _dx) * _lineEx + (y - _dy) * _lineEy; + + if (w >= 0 && w <= _lineWidth && h >= 0 && h <= (_lineDescent + _lineAscent)) + { + // попали внутрь линии. Теперь нужно найти глиф + _line = _numLine; + + _lenGls = _arrayGlyphOffsets.length; + for (_glyph = 0; _glyph < _lenGls; _glyph++) + { + if (_arrayGlyphOffsets[_glyph] > w) + break; + } + + if (_glyph > 0) + _glyph--; + + return { Line : _line, Glyph : _glyph }; + } + + if (w >= 0 && w <= _lineWidth) + tmp = Math.abs(h - _lineDescent); + else if (w < 0) + { + tmp = Math.sqrt((x - _lineX) * (x - _lineX) + (y - _lineY) * (y - _lineY)); + } + else + { + var _tmpX = _lineX + _lineWidth * _lineEx; + var _tmpY = _lineY + _lineWidth * _lineEy; + tmp = Math.sqrt((x - _tmpX) * (x - _tmpX) + (y - _tmpY) * (y - _tmpY)); + } + + //tmp = Math.abs(h - _lineDescent); + if (tmp < _minDist) + { + _minDist = tmp; + _line = _numLine; + + if (w < 0) + _glyph = -2; + else if (w > _lineWidth) + _glyph = -1; + else + { + _lenGls = _arrayGlyphOffsets.length; + for (_glyph = 0; _glyph < _lenGls; _glyph++) + { + if (_arrayGlyphOffsets[_glyph] > w) + break; + } + + if (_glyph > 0) + _glyph--; + } + } + + // Ничего не надо делать, уже найдена более "ближняя" линия + } + + break; + } + + } + } + + return { Line : _line, Glyph : _glyph }; + }, + + OnMouseDown : function(page, x, y) + { + var ret = this.GetNearestPos(page, x, y); + + var sel = this.Selection; + sel.Page1 = page; + sel.Line1 = ret.Line; + sel.Glyph1 = ret.Glyph; + + sel.Page2 = page; + sel.Line2 = ret.Line; + sel.Glyph2 = ret.Glyph; + + sel.IsSelection = true; + this.OnUpdateSelection(); + }, + + OnMouseMove : function(page, x, y) + { + if (false === this.Selection.IsSelection) + return; + + var ret = this.GetNearestPos(page, x, y); + + var sel = this.Selection; + sel.Page2 = page; + sel.Line2 = ret.Line; + sel.Glyph2 = ret.Glyph; + + this.OnUpdateSelection(); + }, + + OnMouseUp : function() + { + this.Selection.IsSelection = false; + }, + + OnUpdateSelection : function() + { + editor.WordControl.m_oOverlayApi.Show(); + editor.WordControl.OnUpdateOverlay(); + }, +} +})(window, undefined); \ No newline at end of file diff --git a/XpsFile/XpsLib/Document.cpp b/XpsFile/XpsLib/Document.cpp index 67b0d8ac4b..e6aab68583 100644 --- a/XpsFile/XpsLib/Document.cpp +++ b/XpsFile/XpsLib/Document.cpp @@ -41,24 +41,24 @@ namespace XPS { m_pFontManager = pFontManager; m_mPages.clear(); - m_wsPath = NULL; + m_wsPath = NULL; } CDocument::~CDocument() { Close(); } - bool CDocument::Read(IFolder* pFolder) + bool CDocument::Read(IFolder* pFolder) { Close(); - m_wsPath = pFolder; + m_wsPath = pFolder; - XmlUtils::CXmlLiteReader oReader; + XmlUtils::CXmlLiteReader oReader; - if (!oReader.FromStringA(m_wsPath->readXml(L"_rels/.rels"))) + if (!oReader.FromStringA(m_wsPath->readXml(L"_rels/.rels"))) return false; - if (!oReader.ReadNextNode()) + if (!oReader.ReadNextNode()) return false; std::wstring wsName = oReader.GetName(); @@ -87,15 +87,15 @@ namespace XPS oReader.Clear(); - std::wstring wsTargerFullPath = wsTargetFile; - if (!m_wsPath->exists(wsTargerFullPath)) + std::wstring wsTargerFullPath = wsTargetFile; + if (!m_wsPath->exists(wsTargerFullPath)) { - wsTargerFullPath = GetPath(L"_rels/.rels") + wsTargetFile; - if (!m_wsPath->exists(wsTargerFullPath)) + wsTargerFullPath = GetPath(L"_rels/.rels") + wsTargetFile; + if (!m_wsPath->exists(wsTargerFullPath)) return false; } - - if (!oReader.FromStringA(m_wsPath->readXml(wsTargerFullPath))) + + if (!oReader.FromStringA(m_wsPath->readXml(wsTargerFullPath))) return false; if (!oReader.ReadNextNode()) @@ -122,15 +122,15 @@ namespace XPS oReader.Clear(); - std::wstring wsSourceFullPath = wsSourceFile; - if (!m_wsPath->exists(wsSourceFullPath)) + std::wstring wsSourceFullPath = wsSourceFile; + if (!m_wsPath->exists(wsSourceFullPath)) { wsSourceFullPath = GetPath(wsTargerFullPath) + wsSourceFile; - if (!m_wsPath->exists(wsSourceFullPath)) + if (!m_wsPath->exists(wsSourceFullPath)) return false; } - if (!oReader.FromStringA(m_wsPath->readXml(wsSourceFullPath))) + if (!oReader.FromStringA(m_wsPath->readXml(wsSourceFullPath))) return false; if (!oReader.ReadNextNode()) @@ -153,15 +153,15 @@ namespace XPS { ReadAttribute(oReader, L"Source", wsSource); - std::wstring wsPagePath = wsSource; - if (!m_wsPath->exists(wsPagePath)) + std::wstring wsPagePath = wsSource; + if (!m_wsPath->exists(wsPagePath)) { wsPagePath = wsFilePath + wsSource; - if (!m_wsPath->exists(wsPagePath)) + if (!m_wsPath->exists(wsPagePath)) continue; } - m_mPages.insert(std::pair(nIndex++, new XPS::Page(wsPagePath, m_wsPath, &m_oFontList, m_pFontManager, this))); + m_mPages.insert(std::pair(nIndex++, new XPS::Page(wsPagePath, m_wsPath, &m_oFontList, m_pFontManager, this))); } } @@ -200,7 +200,7 @@ namespace XPS delete oIter->second; } m_mStaticResources.clear(); - RELEASEOBJECT(m_wsPath); + RELEASEOBJECT(m_wsPath); } CStaticResource* CDocument::GetStaticResource(const wchar_t* wsPath) { @@ -210,7 +210,7 @@ namespace XPS return oIt.second; } - CStaticResource* pStaticResource = new CStaticResource(m_wsPath->readXml(wsPath)); + CStaticResource* pStaticResource = new CStaticResource(m_wsPath->readXml(wsPath)); m_mStaticResources.insert(std::pair(wsPath, pStaticResource)); return pStaticResource; } diff --git a/XpsFile/XpsLib/Document.h b/XpsFile/XpsLib/Document.h index 440904c132..32b3c9006c 100644 --- a/XpsFile/XpsLib/Document.h +++ b/XpsFile/XpsLib/Document.h @@ -51,7 +51,7 @@ namespace XPS CDocument(NSFonts::IFontManager* pFontManager); ~CDocument(); - bool Read(IFolder* pFolder); + bool Read(IFolder* pFolder); int GetPageCount() const; void GetPageSize(int nPageIndex, int& nW, int& nH); void DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak); @@ -60,7 +60,7 @@ namespace XPS private: - IFolder* m_wsPath; + IFolder* m_wsPath; std::map m_mPages; CFontList m_oFontList; NSFonts::IFontManager* m_pFontManager; diff --git a/XpsFile/XpsLib/FontList.h b/XpsFile/XpsLib/FontList.h index e00242cd93..ce17b829d0 100644 --- a/XpsFile/XpsLib/FontList.h +++ b/XpsFile/XpsLib/FontList.h @@ -58,7 +58,7 @@ namespace XPS { m_mList.clear(); } - void Check(const std::wstring& wsName, BYTE* data, DWORD length) + void Check(const std::wstring& wsName, BYTE* data, DWORD length) { m_oCS.Enter(); if (!Find(wsName)) @@ -68,9 +68,9 @@ namespace XPS unsigned char sKey[16]; GetFontKey(wsName, sKey); - if (length >= 32) - for (int nIndex = 0; nIndex < 32; nIndex++) - data[nIndex] ^= sKey[nIndex % 16]; + if (length >= 32) + for (int nIndex = 0; nIndex < 32; nIndex++) + data[nIndex] ^= sKey[nIndex % 16]; } m_oCS.Leave(); } diff --git a/XpsFile/XpsLib/Page.cpp b/XpsFile/XpsLib/Page.cpp index 99458256e3..1e3f88d2e3 100644 --- a/XpsFile/XpsLib/Page.cpp +++ b/XpsFile/XpsLib/Page.cpp @@ -95,7 +95,7 @@ namespace XPS { XmlUtils::CXmlLiteReader oReader; - if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath))) + if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath))) return; if (!oReader.ReadNextNode()) @@ -173,7 +173,7 @@ namespace XPS { XmlUtils::CXmlLiteReader oReader; - if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath))) + if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath))) return; if (!oReader.ReadNextNode()) @@ -451,23 +451,23 @@ namespace XPS std::wstring wsRelativePath = (std::wstring::npos == nSlashPos) ? m_wsPagePath : m_wsPagePath.substr(0, nSlashPos + 1); wsFontPath = wsRelativePath + wsFontPath; } - else - { - wsFontPath = m_wsRootPath->getFullFilePath(wsFontPath); - } + else + { + wsFontPath = m_wsRootPath->getFullFilePath(wsFontPath); + } std::wstring wsExt = GetFileExtension(wsFontPath); NSStringExt::ToLower(wsExt); if (L"odttf" == wsExt) { NSStringExt::ToLower(wsFontName); - IFolder::CBuffer* buffer = NULL; - m_wsRootPath->read(wsFontPath, buffer); - m_pFontList->Check(wsFontName, buffer->Buffer, buffer->Size); - if (CApplicationFontStreams::m_pMemoryStorage) - CApplicationFontStreams::m_pMemoryStorage->Add(wsFontPath, buffer->Buffer, buffer->Size); - m_wsRootPath->write(wsFontPath, buffer->Buffer, buffer->Size); - RELEASEOBJECT(buffer); + IFolder::CBuffer* buffer = NULL; + m_wsRootPath->read(wsFontPath, buffer); + m_pFontList->Check(wsFontName, buffer->Buffer, buffer->Size); + if (CApplicationFontStreams::m_pMemoryStorage) + CApplicationFontStreams::m_pMemoryStorage->Add(wsFontPath, buffer->Buffer, buffer->Size); + m_wsRootPath->write(wsFontPath, buffer->Buffer, buffer->Size); + RELEASEOBJECT(buffer); } wsFontPath = NormalizePath(wsFontPath); pRenderer->put_FontPath(wsFontPath); @@ -638,7 +638,7 @@ namespace XPS int nIndicesPos = 0, nIndicesLen = wsIndices.size(); int nUtf16Pos = 0; bool bRtoL = (nBidiLevel % 2 ? true : false); - m_pFontManager->LoadFontFromFile(m_wsRootPath->getFullFilePath(wsFontPath), 0, (float)(dFontSize * 0.75), 96, 96); + m_pFontManager->LoadFontFromFile(m_wsRootPath->getFullFilePath(wsFontPath), 0, (float)(dFontSize * 0.75), 96, 96); double dFontKoef = dFontSize / 100.0; bool bNeedItalic = false, bNeedBold = false; @@ -973,7 +973,7 @@ namespace XPS if (pBrush) { if (pBrush->IsImageBrush()) - ((CImageBrush*)pBrush)->SetPaths(m_wsRootPath, GetPath(m_wsPagePath).c_str()); + ((CImageBrush*)pBrush)->SetPaths(m_wsRootPath, GetPath(m_wsPagePath).c_str()); bFill = pBrush->SetToRenderer(pRenderer); if (bDeleteBrush) diff --git a/XpsFile/XpsLib/StaticResources.cpp b/XpsFile/XpsLib/StaticResources.cpp index aaf449df4b..5ca9f93eae 100644 --- a/XpsFile/XpsLib/StaticResources.cpp +++ b/XpsFile/XpsLib/StaticResources.cpp @@ -47,11 +47,11 @@ namespace XPS { - CStaticResource::CStaticResource(const std::string& wsPath) + CStaticResource::CStaticResource(const std::string& wsPath) { XmlUtils::CXmlLiteReader oReader; - if (!oReader.FromStringA(wsPath)) + if (!oReader.FromStringA(wsPath)) return; Parse(oReader); @@ -152,33 +152,33 @@ namespace XPS } bool CImageBrush::SetToRenderer(IRenderer* pRenderer) { - std::wstring wsPath = m_wsPath.c_stdstr(); - if (!m_wsRoot->exists(wsPath)) + std::wstring wsPath = m_wsPath.c_stdstr(); + if (!m_wsRoot->exists(wsPath)) { - wsPath = m_wsPage.c_stdstr() + m_wsPath.c_stdstr(); - if (!m_wsRoot->exists(wsPath)) + wsPath = m_wsPage.c_stdstr() + m_wsPath.c_stdstr(); + if (!m_wsRoot->exists(wsPath)) return false; } - IFolder::CBuffer* buffer = NULL; - m_wsRoot->read(wsPath, buffer); - int nBase64BufferLen = NSBase64::Base64EncodeGetRequiredLength(buffer->Size); - BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen + 64]; - if (true == NSBase64::Base64Encode(buffer->Buffer, buffer->Size, pbBase64Buffer, &nBase64BufferLen)) - { - pRenderer->put_BrushType(c_BrushTypeTexture); - pRenderer->put_BrushTexturePath(L"data:," + NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(pbBase64Buffer, nBase64BufferLen)); - RELEASEARRAYOBJECTS(pbBase64Buffer); - RELEASEOBJECT(buffer); - return true; - } - RELEASEARRAYOBJECTS(pbBase64Buffer); - RELEASEOBJECT(buffer); - return false; + IFolder::CBuffer* buffer = NULL; + m_wsRoot->read(wsPath, buffer); + int nBase64BufferLen = NSBase64::Base64EncodeGetRequiredLength(buffer->Size); + BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen + 64]; + if (true == NSBase64::Base64Encode(buffer->Buffer, buffer->Size, pbBase64Buffer, &nBase64BufferLen)) + { + pRenderer->put_BrushType(c_BrushTypeTexture); + pRenderer->put_BrushTexturePath(L"data:," + NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(pbBase64Buffer, nBase64BufferLen)); + RELEASEARRAYOBJECTS(pbBase64Buffer); + RELEASEOBJECT(buffer); + return true; + } + RELEASEARRAYOBJECTS(pbBase64Buffer); + RELEASEOBJECT(buffer); + return false; } - void CImageBrush::SetPaths(IFolder* wsRoot, const wchar_t* wsPage) + void CImageBrush::SetPaths(IFolder* wsRoot, const wchar_t* wsPage) { - m_wsRoot = wsRoot; + m_wsRoot = wsRoot; m_wsPage.create(wsPage, true); } bool CLinearGradientBrush::SetToRenderer(IRenderer* pRenderer) diff --git a/XpsFile/XpsLib/StaticResources.h b/XpsFile/XpsLib/StaticResources.h index f80628581c..1569936974 100644 --- a/XpsFile/XpsLib/StaticResources.h +++ b/XpsFile/XpsLib/StaticResources.h @@ -52,7 +52,7 @@ namespace XPS class CStaticResource { public: - CStaticResource(const std::string& wsPath); + CStaticResource(const std::string& wsPath); CStaticResource(XmlUtils::CXmlLiteReader& oReader); ~CStaticResource(); bool GetFigure(CWString& wsKey, CWString& wsFigure); @@ -101,11 +101,11 @@ namespace XPS } bool SetToRenderer(IRenderer* pRenderer); bool IsImageBrush() { return true; } - void SetPaths(IFolder* wsRoot, const wchar_t* wsPage); + void SetPaths(IFolder* wsRoot, const wchar_t* wsPage); private: CWString m_wsPath; - IFolder* m_wsRoot; + IFolder* m_wsRoot; CWString m_wsPage; }; class CGradientBrush : public CBrush