Add ignoring meta-info in covertion and add bFontSubstitution

This commit is contained in:
Alexey Nagaev
2025-12-10 11:10:22 +03:00
parent e31e02d993
commit 39235f7fd6
6 changed files with 53 additions and 16 deletions

View File

@ -144,6 +144,7 @@ std::vector<std::wstring> CDocxRenderer::ScanPagePptx(IOfficeDrawingFile* pFile,
m_pInternal->m_oDocument.Init(false);
m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bCollectMetaInfo = true;
m_pInternal->m_bIsSupportShapeCommands = true;
m_pInternal->m_eShapeSerializeType = ShapeSerializeType::sstXml;
@ -160,6 +161,7 @@ NSWasm::CData CDocxRenderer::ScanPageBin(IOfficeDrawingFile* pFile, size_t nPage
m_pInternal->m_oDocument.Init(false);
m_pInternal->m_oDocument.m_oCurrentPage.m_bUseDefaultFont = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bWriteStyleRaw = true;
m_pInternal->m_oDocument.m_oCurrentPage.m_bCollectMetaInfo = true;
m_pInternal->m_bIsSupportShapeCommands = true;
DrawPage(pFile, nPage);
@ -732,6 +734,10 @@ HRESULT CDocxRenderer::CommandLong(const LONG& lType, const LONG& lCommand)
return S_OK;
}
if (c_nFontSubstitution == lType)
{
m_pInternal->m_oDocument.m_oCurrentPage.m_bFontSubstitution = true;
}
return S_OK;
}
HRESULT CDocxRenderer::CommandDouble(const LONG& lType, const double& dCommand)

View File

@ -322,6 +322,7 @@ namespace NSDocxRenderer
HRESULT CDocument::put_FontName(std::wstring sName)
{
m_oCurrentPage.m_oFont.Name = sName;
m_oCurrentPage.m_bFontSubstitution = false;
return S_OK;
}
HRESULT CDocument::get_FontPath(std::wstring* sPath)

View File

@ -342,7 +342,21 @@ namespace NSDocxRenderer
bForcedBold = true;
m_oManagers.pParagraphStyleManager->UpdateAvgFontSize(m_oFont.Size);
m_oContBuilder.AddUnicode(top, baseline, left, right, m_oFont, m_oBrush, m_oManagers.pFontManager, oText, pGids, bForcedBold, m_bUseDefaultFont, m_bWriteStyleRaw);
m_oContBuilder.AddUnicode(
top,
baseline,
left,
right,
m_oFont,
m_oBrush,
m_oManagers.pFontManager,
oText,
pGids,
bForcedBold,
m_bUseDefaultFont,
m_bWriteStyleRaw,
m_bCollectMetaInfo
);
}
void CPage::Analyze()

View File

@ -46,8 +46,10 @@ namespace NSDocxRenderer
bool m_bIsGradient {false};
bool m_bUseDefaultFont {false};
bool m_bWriteStyleRaw {false};
bool m_bCollectMetaInfo {false};
bool m_bIsBuildTables {false};
bool m_bIsLuminosityShapesFiled{false};
bool m_bFontSubstitution {false};
CPage(NSFonts::IApplicationFonts* pAppFonts, const CManagers& oManagers);
~CPage();

View File

@ -564,6 +564,7 @@ namespace NSDocxRenderer
origin_lefts += std::to_wstring(static_cast<int>(l * c_dMMToEMU)) + L";";
oWriter.WriteBYTE(5); oWriter.WriteStringUtf16(origin_lefts); // Origin lefts
oWriter.WriteBYTE(6); oWriter.WriteBool(m_bFontSubstitution); // Origin lefts
oWriter.WriteBYTE(kBin_g_nodeAttributeEnd);
oWriter.EndRecord();
@ -784,8 +785,8 @@ namespace NSDocxRenderer
}
void CContText::SetText(const NSStringUtils::CStringUTF32& oText,
const std::vector<double>& arSymWidths,
const std::vector<unsigned int>& arGids,
const std::vector<double>& arOriginLefts)
std::vector<unsigned int>&& arGids,
std::vector<double>&& arOriginLefts)
{
m_oText = oText;
m_arSymWidths.clear();
@ -797,8 +798,8 @@ namespace NSDocxRenderer
}
m_dRight = m_dLeft + m_dWidth;
m_arGids = arGids;
m_arOriginLefts = arOriginLefts;
m_arGids = std::move(arGids);
m_arOriginLefts = std::move(arOriginLefts);
}
void CContText::AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft)
@ -1114,24 +1115,32 @@ namespace NSDocxRenderer
const PUINT pGids,
bool bForcedBold,
bool bUseDefaultFont,
bool bWriteStyleRaw)
bool bWriteStyleRaw,
bool bCollectMetaInfo,
bool bFontSubstitution)
{
double dWidth = dRight - dLeft;
double dHeight = dBot - dTop;
std::vector<unsigned int> gids;
for (size_t i = 0; i < oText.length(); ++i)
if (bCollectMetaInfo)
{
for (size_t i = 0; i < oText.length(); ++i)
if (pGids)
gids.push_back(pGids[i]);
else
gids.push_back(0);
}
std::vector<double> origin_lefts;
double curr_origin_left = dLeft;
for (size_t i = 0; i < oText.length(); ++i)
if (bCollectMetaInfo)
{
origin_lefts.push_back(curr_origin_left);
curr_origin_left += dWidth / oText.length();
double curr_origin_left = dLeft;
for (size_t i = 0; i < oText.length(); ++i)
{
origin_lefts.push_back(curr_origin_left);
curr_origin_left += dWidth / oText.length();
}
}
// if new text is close to current cont
@ -1139,7 +1148,8 @@ namespace NSDocxRenderer
fabs(m_pCurrCont->m_dBot - dBot) < c_dTHE_SAME_STRING_Y_PRECISION_MM &&
m_oPrevFont.IsEqual2(&oFont) &&
m_oPrevBrush.IsEqual(&oBrush) && !(
oText.length() == 1 && CContText::IsUnicodeDiacriticalMark(oText.at(0))))
oText.length() == 1 && CContText::IsUnicodeDiacriticalMark(oText.at(0))) &&
bFontSubstitution == m_pCurrCont->m_bFontSubstitution)
{
double avg_width = dWidth / oText.length();
@ -1217,7 +1227,7 @@ namespace NSDocxRenderer
ar_widths.push_back(avg_width);
}
pCont->SetText(oText, ar_widths, gids, origin_lefts);
pCont->SetText(oText, ar_widths, std::move(gids), std::move(origin_lefts));
pCont->m_bIsRtl = CContText::IsUnicodeRtl(oText.at(0));
pCont->m_dWidth = dWidth;
@ -1249,6 +1259,7 @@ namespace NSDocxRenderer
pCont->m_oSelectedFont.Italic = m_pFontSelector->IsSelectedItalic();
}
pCont->m_bWriteStyleRaw = bWriteStyleRaw;
pCont->m_bFontSubstitution = bFontSubstitution;
if (pCont->IsDiacritical())
{

View File

@ -80,6 +80,7 @@ namespace NSDocxRenderer
std::vector<unsigned int> m_arGids{};
std::vector<double> m_arOriginLefts{};
bool m_bFontSubstitution = false;
CContText() = default;
CContText(CFontManager* pManager) : m_pManager(pManager) {}
@ -106,8 +107,8 @@ namespace NSDocxRenderer
const std::vector<double>& arOriginLefts);
void SetText(const NSStringUtils::CStringUTF32& oText,
const std::vector<double>& arSymWidths,
const std::vector<unsigned int>& arGids,
const std::vector<double>& arOriginLefts);
std::vector<unsigned int>&& arGids,
std::vector<double>&& arOriginLefts);
void AddSymBack(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft);
void AddSymFront(uint32_t cSym, double dWidth, unsigned int nGid, double dLeft);
@ -188,7 +189,9 @@ namespace NSDocxRenderer
const PUINT pGids = nullptr,
bool bForcedBold = false,
bool bUseDefaultFont = false,
bool bWriteStyleRaw = false);
bool bWriteStyleRaw = false,
bool bCollectMetaInfo = false,
bool bFontSubstitution = false);
void NullCurrCont();
void Clear();