Refactoring

This commit is contained in:
Alexey Nagaev
2025-03-26 13:32:44 +03:00
parent 71201f4446
commit f0dbf92bde
12 changed files with 47 additions and 32 deletions

View File

@ -4,7 +4,6 @@
#include <map>
#include <set>
#include "../../../DesktopEditor/graphics/GraphicsPath.h"
#include "../../../DesktopEditor/graphics/pro/Graphics.h"
#include "../resources/Constants.h"
@ -1432,7 +1431,7 @@ namespace NSDocxRenderer
for (const auto& text_lines : bot_aligned_text_lines)
{
// lines [i] belongs group [j] (like a matrix)
// only 1 [i] to 1 [j].
// only 1 [i] to 1 [j] on the same bot position
std::vector<std::vector<bool>> lines_x_groups(text_lines.size());
for (auto& lxg : lines_x_groups)
lxg.resize(m_arTextLineGroups.size());
@ -1567,8 +1566,8 @@ namespace NSDocxRenderer
// lamda to setup and add paragpraph
auto add_paragraph = [this, &max_right, &min_left, &ar_paragraphs] (paragraph_ptr_t& paragraph) {
paragraph->m_dBot = paragraph->m_arLines.back()->m_dBot;
paragraph->m_dTop = paragraph->m_arLines.front()->m_dTop;
paragraph->m_dBot = paragraph->m_arTextLines.back()->m_dBot;
paragraph->m_dTop = paragraph->m_arTextLines.front()->m_dTop;
paragraph->m_dRight = max_right + c_dERROR_OF_PARAGRAPH_BORDERS_MM;
paragraph->m_dLeft = min_left;
@ -1578,7 +1577,7 @@ namespace NSDocxRenderer
paragraph->m_dRightBorder = m_dWidth - paragraph->m_dRight;
paragraph->m_dLeftBorder = min_left;
paragraph->m_dLineHeight = paragraph->m_dHeight / paragraph->m_arLines.size();
paragraph->m_dLineHeight = paragraph->m_dHeight / paragraph->m_arTextLines.size();
paragraph->m_bIsNeedFirstLineIndent = false;
paragraph->m_dFirstLine = 0;
paragraph->m_wsStyleId = m_oManagers.pParagraphStyleManager->GetDefaultParagraphStyleId(*paragraph);
@ -1586,7 +1585,7 @@ namespace NSDocxRenderer
paragraph->MergeLines();
// setting TextAlignmentType
if (paragraph->m_arLines.size() > 1)
if (paragraph->m_arTextLines.size() > 1)
{
Position position_curr;
position_curr.left = true;
@ -1595,10 +1594,10 @@ namespace NSDocxRenderer
bool first_left = false;
for (size_t index = 1; index < paragraph->m_arLines.size(); ++index)
for (size_t index = 1; index < paragraph->m_arTextLines.size(); ++index)
{
auto& curr_line = paragraph->m_arLines[index];
auto& prev_line = paragraph->m_arLines[index - 1];
auto& curr_line = paragraph->m_arTextLines[index];
auto& prev_line = paragraph->m_arTextLines[index - 1];
// indent check
if (index == 1)
@ -1625,7 +1624,7 @@ namespace NSDocxRenderer
// indent check
if (paragraph->m_eTextAlignmentType == CParagraph::tatByLeft && !first_left)
{
double left_diff = paragraph->m_arLines[0]->m_dLeft - paragraph->m_arLines[1]->m_dLeft;
double left_diff = paragraph->m_arTextLines[0]->m_dLeft - paragraph->m_arTextLines[1]->m_dLeft;
paragraph->m_bIsNeedFirstLineIndent = true;
paragraph->m_dFirstLine = left_diff;
@ -1645,7 +1644,7 @@ namespace NSDocxRenderer
auto add_line = [&min_left, &max_right] (paragraph_ptr_t& paragraph, const text_line_ptr_t& curr_line) {
min_left = std::min(min_left, curr_line->m_dLeft);
max_right = std::max(max_right, curr_line->m_dRight);
paragraph->m_arLines.push_back(curr_line);
paragraph->m_arTextLines.push_back(curr_line);
};
auto build_paragraphs = [this, add_line, add_paragraph] (const std::vector<text_line_ptr_t>& text_lines) {
@ -1907,6 +1906,9 @@ namespace NSDocxRenderer
std::vector<CPage::table_ptr_t> CPage::BuildTables()
{
auto graphical_cells = BuildGraphicalCells();
// auto text_cells = BuildTextCells();
// MergeGrapgicalTextCells();
// ..
std::vector<table_ptr_t> tables;
return tables;
}
@ -2244,7 +2246,7 @@ namespace NSDocxRenderer
{
auto pParagraph = std::make_shared<CParagraph>();
pParagraph->m_arLines.push_back(pLine);
pParagraph->m_arTextLines.push_back(pLine);
pParagraph->m_dLeft = pLine->m_dLeft;
pParagraph->m_dTop = pLine->m_dTop;
pParagraph->m_dBot = pLine->m_dBot;

View File

@ -11,7 +11,7 @@ namespace NSDocxRenderer
void CParagraph::Clear()
{
m_arLines.clear();
m_arTextLines.clear();
}
void CParagraph::ToXml(NSStringUtils::CStringBuilder& oWriter) const
@ -20,7 +20,7 @@ namespace NSDocxRenderer
oWriter.WriteString(L"<w:pPr>");
// styles
if(!m_wsStyleId.empty()) oWriter.WriteString(L"<w:pStyle w:val=\"" + m_wsStyleId + L"\"/>");
if (!m_wsStyleId.empty()) oWriter.WriteString(L"<w:pStyle w:val=\"" + m_wsStyleId + L"\"/>");
oWriter.WriteString(L"<w:spacing");
@ -105,7 +105,7 @@ namespace NSDocxRenderer
}
oWriter.WriteString(L"</w:pPr>");
for(const auto& line : m_arLines)
for(const auto& line : m_arTextLines)
if(line)
line->ToXml(oWriter);
oWriter.WriteString(L"</w:p>");
@ -165,7 +165,7 @@ namespace NSDocxRenderer
oWriter.WriteString(L"</a:lnSpc>");
oWriter.WriteString(L"</a:pPr>");
for(const auto& line : m_arLines)
for(const auto& line : m_arTextLines)
if(line)
line->ToXmlPptx(oWriter);
oWriter.WriteString(L"</a:p>");
@ -176,9 +176,9 @@ namespace NSDocxRenderer
if (!m_bIsShadingPresent)
return;
for(size_t i = 0; i < m_arLines.size(); ++i)
for(size_t i = 0; i < m_arTextLines.size(); ++i)
{
auto& pLine = m_arLines[i];
auto& pLine = m_arTextLines[i];
if (pLine || pLine->m_pDominantShape)
{
for (size_t j = 0; j < pLine->m_arConts.size(); ++j)
@ -194,9 +194,9 @@ namespace NSDocxRenderer
void CParagraph::MergeLines()
{
for(size_t i = 0; i < m_arLines.size() - 1; ++i)
for(size_t i = 0; i < m_arTextLines.size() - 1; ++i)
{
auto pLine = m_arLines[i];
auto pLine = m_arTextLines[i];
auto pLastCont = pLine->m_arConts.back();
size_t iNumConts = pLine->m_arConts.size() - 1;
@ -206,7 +206,7 @@ namespace NSDocxRenderer
auto text = pLastCont->GetText();
auto last_sym = text[text.length() - 1];
if (last_sym != c_SPACE_SYM && m_arLines.size() != 1)
if (last_sym != c_SPACE_SYM && m_arTextLines.size() != 1)
pLastCont->AddSymBack(c_SPACE_SYM, 0);
}
}

View File

@ -31,7 +31,7 @@ namespace NSDocxRenderer
double m_dSpaceAfter {0.0}; // в shape по умолчанию выставляется 8pt, если отсутсвует w:after
double m_dLineHeight {0.0};
std::vector<std::shared_ptr<CTextLine>> m_arLines;
std::vector<std::shared_ptr<CTextLine>> m_arTextLines;
std::wstring m_wsStyleId;
public:

View File

@ -110,7 +110,7 @@ namespace NSDocxRenderer
double dHorNearby = 30;
double dVerNearby = 30;
if(
if (
// только для фигур
(pShape->m_eGraphicsType == eGraphicsType::gtComplicatedFigure ||
pShape->m_eGraphicsType == eGraphicsType::gtRectangle) &&

View File

@ -31,7 +31,7 @@ namespace NSDocxRenderer
double dWidth{};
double dSpacing{};
long lColor{};
eLineType lineType{};
eLineType lineType{eLineType::ltNone};
};
enum class eVMerge
@ -97,6 +97,13 @@ namespace NSDocxRenderer
class CGraphicalCell : public CBaseItem
{
public:
// realization
};
class CTextCell : public CBaseItem
{
public:
std::vector<std::shared_ptr<CTextLine>> m_arTextLines;
};
} // namespace NSDocxRenderer

View File

@ -71,7 +71,7 @@ namespace NSDocxRenderer
std::shared_ptr<CContText> pFirst;
size_t j = 0;
for(; j < m_arConts.size() && !pFirst; ++j)
for (; j < m_arConts.size() && !pFirst; ++j)
pFirst = m_arConts[j];
for (size_t i = j; i < m_arConts.size(); ++i)

View File

@ -314,7 +314,7 @@ namespace NSDocxRenderer
void CFontSelector::ClearCache()
{
if(!m_arParamsCache.empty())
if (!m_arParamsCache.empty())
m_arParamsCache.clear();
}

View File

@ -29,11 +29,11 @@ namespace NSDocxRenderer
std::wstring CParagraphStyleManager::GetDefaultParagraphStyleId(const CParagraph& oParagraph) const noexcept
{
if(oParagraph.m_arLines.size() > 1) return L"Normal";
if (oParagraph.m_arTextLines.size() > 1) return L"Normal";
bool isHeading = true;
for(auto& val : oParagraph.m_arLines[0]->m_arConts)
if(val && val->m_pFontStyle->dFontSize <= m_dAvgFontSize + 1 && !val->m_pFontStyle->bBold)
for (auto& val : oParagraph.m_arTextLines[0]->m_arConts)
if (val && val->m_pFontStyle->dFontSize <= m_dAvgFontSize + 1 && !val->m_pFontStyle->bBold)
isHeading = false;
return isHeading ? L"Heading1" : L"Normal";

View File

@ -21,7 +21,7 @@ namespace NSDocxRenderer
oWriter.WriteString(L"w:styleId=\"" + wsStyleId + L"\">");
oWriter.WriteString(L"<w:name w:val=\"" + wsName + L"\"/>");
if(!wsBasedOn.empty()) oWriter.WriteString(L"<w:basedOn w:val=\"" + wsBasedOn + L"\"/>");
if (!wsBasedOn.empty()) oWriter.WriteString(L"<w:basedOn w:val=\"" + wsBasedOn + L"\"/>");
if(bIsUnhideWhenUsed) oWriter.WriteString(L"<w:unhideWhenUsed/>");
if(bIsSemiHidden) oWriter.WriteString(L"<w:semiHidden/>");
oWriter.WriteString(L"<w:uiPriority w:val=\"" + std::to_wstring(nUiPriority) + L"\"/>");

View File

@ -1,5 +1,6 @@
#pragma once
#include <type_traits>
#include <cstdlib>
#include <limits>
#include "../../../DesktopEditor/common/Types.h"

View File

@ -1,16 +1,15 @@
#pragma once
#include <type_traits>
#include <limits>
#include <algorithm>
#include "../../../DesktopEditor/common/Types.h"
#include "../../../DesktopEditor/common/StringUTF32.h"
inline LONG ConvertColorBGRToRGB(LONG lBGR)
{
return (0x00FFFFFF & (((lBGR & 0xFF) << 16) | (lBGR & 0x0000FF00) | ((lBGR >> 16) & 0xFF)));
}
// перемещает nullptr в конец и возвращает итератор, после которого начинаются nullptr
template<typename It>
It MoveNullptr(It start, It end)
{

View File

@ -40,6 +40,8 @@
#include "../DocxRenderer.h"
#include "../../Common/OfficeFileFormatChecker.h"
#include "TextCommandRenderer/TextCommandRenderer.h"
#include <fstream>
#ifdef TEST_FOR_HTML_RENDERER_TEXT
@ -178,6 +180,10 @@ int main(int argc, char *argv[])
// auto shapes = oDocxRenderer.ScanPagePptx(pReader, 0);
// for (auto& s : shapes)
// fin << U_TO_UTF8(s);
CTextCommandRenderer oTextCommandRenderer(pFonts);
oTextCommandRenderer.Do(pReader);
#endif
RELEASEOBJECT(pReader);
RELEASEOBJECT(pExternalImagheStorage);