Compare commits

...

17 Commits

Author SHA1 Message Date
170686840c Fixed an inaccuracy in calculating the width of a row in the table 2022-05-26 21:50:37 +03:00
89a787fc32 fix spacing between tables 2022-05-26 21:50:37 +03:00
56bec09bfd empty <w:p> between tables 2022-05-26 21:50:37 +03:00
341d7a0b55 Improved table display quality 2022-05-26 21:50:37 +03:00
c549d52123 Fix bug 57363 (#939) 2022-05-26 18:57:05 +03:00
8c69e55bdd Merge pull request #937 from ONLYOFFICE/fix/v7.1.1-fix-bugs
fix bug #57274
2022-05-26 12:12:53 +03:00
77a07b09a5 fix bug #57274 2022-05-26 12:05:28 +03:00
282a6b50a5 Merge pull request #936 from ONLYOFFICE/fix/html-table-style
Fix html table style
2022-05-25 20:18:15 +03:00
02fe14ffe3 fix htmltoxhtml 2022-05-25 19:44:38 +03:00
0c1659cf48 fix html and css table style 2022-05-25 19:43:35 +03:00
1627332a20 Merge pull request #935 from ONLYOFFICE/fix/v7.1.1-fix-bugs
fix bug #57334
2022-05-25 16:52:27 +03:00
23d0b0e194 fix bug #57334 2022-05-25 16:51:11 +03:00
2f11ac944d Fix typo 2022-05-25 10:27:22 +03:00
0be13c04ce Fix bug 48473 2022-05-23 22:22:11 +03:00
0cdbdefeb2 Add support images from web 2022-05-23 21:28:15 +03:00
7f863a7b6a Merge pull request #930 from ONLYOFFICE/fix/v7.1.1-fix-bugs
fix save smart in group
2022-05-23 13:20:45 +03:00
d8cbbf4c2f fix save smart in group 2022-05-23 13:19:51 +03:00
25 changed files with 1049 additions and 530 deletions

View File

@ -1905,7 +1905,7 @@ namespace DocFileFormat
XMLTools::XMLElement bookmarkElem(L"w:bookmarkStart");
bookmarkElem.AppendAttribute(L"w:id", FormatUtils::IntToWideString(id));
bookmarkElem.AppendAttribute(L"w:name", *bookmarkName);
bookmarkElem.AppendAttribute(L"w:name", XmlUtils::EncodeXmlString(*bookmarkName));
m_pXmlWriter->WriteString(bookmarkElem.GetXMLString());

View File

@ -99,7 +99,7 @@ std::wstring presentation_class::get_type_ms()
//res = L"subTitle";
break;
case graphic:
res = L"dgm";
res = L"body";
break;
case object:
res = L"obj";

View File

@ -863,8 +863,8 @@ void common_draw_docx_convert(oox::docx_conversion_context & Context, union_comm
drawing->relativeHeight = L"2";
drawing->behindDoc = L"0";
if (((drawing->styleWrap && drawing->styleWrap->get_type() == style_wrap::RunThrough) ||
!drawing->styleWrap) && styleRunThrough && styleRunThrough->get_type() == run_through::Background)
if (((drawing->styleWrap && drawing->styleWrap->get_type() == style_wrap::RunThrough) || !drawing->styleWrap)
&& ((styleRunThrough && styleRunThrough->get_type() == run_through::Background) || !styleRunThrough))
{
drawing->behindDoc = L"1";
if (!drawing->styleWrap)

View File

@ -2215,6 +2215,9 @@ void odf_drawing_context::set_line_width(double pt)
{
if (!impl_->current_graphic_properties) return;
if (pt < 0.0001)
impl_->current_graphic_properties->draw_stroke_ = line_style::None;
impl_->current_graphic_properties->svg_stroke_width_ = length(length(pt,length::pt).get_value_unit(length::cm), length::cm);
}

View File

@ -457,7 +457,8 @@ namespace PPTX
void GraphicFrame::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const
{
if (smartArt.is_init() && ( pWriter->m_lDocType == XMLWRITER_DOC_TYPE_DOCX ||
pWriter->m_lDocType == XMLWRITER_DOC_TYPE_DOCX_GLOSSARY))
pWriter->m_lDocType == XMLWRITER_DOC_TYPE_DOCX_GLOSSARY) &&
pWriter->m_lGroupIndex == 0)
{
pWriter->WriteString(L"<a:graphic><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/diagram\">");
smartArt->toXmlWriter(pWriter);

View File

@ -23,7 +23,7 @@ namespace NSCSS
m_arParentsStyles(oStyle.m_arParentsStyles), m_sId(oStyle.m_sId),
m_nDpi(oStyle.m_nDpi), m_UnitMeasure(oStyle.m_UnitMeasure),
m_pFont(oStyle.m_pFont), m_pMargin(oStyle.m_pMargin), m_pBackground(oStyle.m_pBackground),
m_pText(oStyle.m_pText), m_pBorder(oStyle.m_pBorder){}
m_pText(oStyle.m_pText), m_pBorder(oStyle.m_pBorder), m_pDisplay(oStyle.m_pDisplay){}
CCompiledStyle::~CCompiledStyle()
{
@ -38,6 +38,7 @@ namespace NSCSS
m_pFont += oElement.m_pFont;
m_pMargin += oElement.m_pMargin;
m_pText += oElement.m_pText;
m_pDisplay += oElement.m_pDisplay;
return *this;
}
@ -55,6 +56,7 @@ namespace NSCSS
m_pFont = oElement.m_pFont;
m_pMargin = oElement.m_pMargin;
m_pText = oElement.m_pText;
m_pDisplay = oElement.m_pDisplay;
return *this;
}
@ -67,7 +69,8 @@ namespace NSCSS
m_pBorder == oStyle.m_pBorder &&
m_pFont == oStyle.m_pFont &&
m_pMargin == oStyle.m_pMargin &&
m_pText == oStyle.m_pText;
m_pText == oStyle.m_pText &&
m_pDisplay == oStyle.m_pDisplay;
}
void CCompiledStyle::StyleEquation(CCompiledStyle &oFirstStyle, CCompiledStyle &oSecondStyle)
@ -77,6 +80,7 @@ namespace NSCSS
NSConstValues::NSCssProperties::Background::BackgroundEquation(oFirstStyle.m_pBackground, oSecondStyle.m_pBackground);
NSConstValues::NSCssProperties::Text::TextEquation(oFirstStyle.m_pText, oSecondStyle.m_pText);
NSConstValues::NSCssProperties::Border::BorderEquation(oFirstStyle.m_pBorder, oSecondStyle.m_pBorder);
NSConstValues::NSCssProperties::Display::DisplayEquation(oFirstStyle.m_pDisplay, oSecondStyle.m_pDisplay);
oFirstStyle.ClearImportants();
oSecondStyle.ClearImportants();
@ -92,10 +96,20 @@ namespace NSCSS
m_UnitMeasure = enUnitMeasure;
}
void CCompiledStyle::SetSizeSourceWindow(const CSizeWindow &oSizeWindow)
{
m_oSourceWindow = oSizeWindow;
}
void CCompiledStyle::SetSizeDeviceWindow(const CSizeWindow &oSizeWindow)
{
m_oDeviceWindow = oSizeWindow;
}
bool CCompiledStyle::Empty() const
{
return m_pBackground.Empty() && m_pBorder.Empty() &&
m_pFont.Empty() && m_pMargin.Empty() && m_pText.Empty();
m_pFont.Empty() && m_pMargin.Empty() && m_pText.Empty() && m_pDisplay.Empty();
}
void CCompiledStyle::AddPropSel(const std::wstring& sProperty, const std::wstring& sValue, const unsigned int unLevel, const bool& bHardMode)
@ -225,12 +239,12 @@ namespace NSCSS
if (unPositionImp == std::wstring::npos)
{
const float fValue = wcstof(ConvertUnitMeasure(pPropertie.second, m_pFont.GetSize()).c_str(), NULL);
const float fValue = wcstof(ConvertUnitMeasure(pPropertie.second, m_pFont.GetSize() * 1.2).c_str(), NULL);
m_pFont.SetLineHeight(std::to_wstring(fValue * unCoefficient), unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const float fValue = wcstof(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), m_pFont.GetSize()).c_str(), NULL);
const float fValue = wcstof(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), m_pFont.GetSize() * 1.2).c_str(), NULL);
m_pFont.SetLineHeight(std::to_wstring(fValue * unCoefficient), unLevel, true);
m_pFont.SetImportantenLineHeight(true);
}
@ -245,13 +259,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddMargin(sValue, unLevel, true);
@ -268,13 +282,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddTopMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddTopMargin(sValue, unLevel, true);
@ -291,13 +305,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddRightMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddRightMargin(sValue, unLevel, true);
@ -313,13 +327,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddBottomMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddBottomMargin(sValue, unLevel, true);
@ -336,13 +350,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddLeftMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddLeftMargin(sValue, unLevel, true);
@ -352,6 +366,7 @@ namespace NSCSS
}
//PADDING
CASE(L"padding"):
CASE(L"mso-padding-alt"):
{
if (bIsThereBorder)
break;
@ -359,13 +374,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddMargin(sValue, unLevel, true);
@ -375,6 +390,7 @@ namespace NSCSS
break;
}
CASE(L"padding-top"):
CASE(L"mso-padding-top-alt"):
{
if (bIsThereBorder)
break;
@ -382,13 +398,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddTopMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddTopMargin(sValue, unLevel, true);
@ -398,6 +414,7 @@ namespace NSCSS
break;
}
CASE(L"padding-right"):
CASE(L"mso-padding-right-alt"):
{
if (bIsThereBorder)
break;
@ -406,13 +423,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddRightMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddRightMargin(sValue, unLevel, true);
@ -422,6 +439,7 @@ namespace NSCSS
break;
}
CASE(L"padding-bottom"):
CASE(L"mso-padding-bottom-alt"):
{
if (bIsThereBorder)
break;
@ -429,13 +447,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddBottomMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionY);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddBottomMargin(sValue, unLevel, true);
@ -445,6 +463,7 @@ namespace NSCSS
break;
}
CASE(L"padding-left"):
CASE(L"mso-padding-left-alt"):
{
if (bIsThereBorder)
break;
@ -452,13 +471,13 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddLeftMargin(sValue, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f);
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX);
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
m_pMargin.AddLeftMargin(sValue, unLevel, true);
@ -488,11 +507,11 @@ namespace NSCSS
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
m_pText.SetIndent(ConvertUnitMeasure(pPropertie.second, 540.0f), unLevel, bHardMode);
m_pText.SetIndent(ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX), unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
m_pText.SetIndent(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f), unLevel, true);
m_pText.SetIndent(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), 540.0f, ScalingDirectionX), unLevel, true);
m_pText.SetImportantIndent(true);
}
@ -915,6 +934,52 @@ namespace NSCSS
break;
}
//DISPLAY
CASE(L"display"):
{
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
m_pDisplay.SetDisplay(pPropertie.second, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
m_pDisplay.SetDisplay(pPropertie.second.substr(0, unPositionImp - 1), unLevel, true);
m_pDisplay.SetImportantDisplay(true);
}
break;
}
//OTHER
CASE(L"width"):
{
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
m_pDisplay.SetWidth(ConvertUnitMeasure(pPropertie.second, m_oDeviceWindow.m_ushWidth, ScalingDirectionX), unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
m_pDisplay.SetWidth(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), m_oDeviceWindow.m_ushWidth, ScalingDirectionX), unLevel, true);
m_pDisplay.SetImportantWidth(true);
}
break;
}
CASE(L"align"):
{
const size_t unPositionImp = pPropertie.second.find(L"!i");
if (unPositionImp == std::wstring::npos)
{
m_pDisplay.SetAlign(pPropertie.second, unLevel, bHardMode);
}
else if (unPositionImp != 0)
{
m_pDisplay.SetAlign(pPropertie.second.substr(0, unPositionImp - 1), unLevel, true);
m_pDisplay.SetImportantAlign(true);
}
break;
}
}
}
}
@ -990,7 +1055,7 @@ namespace NSCSS
m_pText .ClearImportants();
}
std::wstring CCompiledStyle::ConvertUnitMeasure(const std::wstring &sValue, const float& fPreviousValue) const
std::wstring CCompiledStyle::ConvertUnitMeasure(const std::wstring &sValue, const float& fPreviousValue, ScalingDirection enScalingDirection) const
{
if (sValue.empty())
return sValue;
@ -1031,7 +1096,11 @@ namespace NSCSS
}
else if (sValueTemp.find(L"px") != std::wstring::npos)
{
sValueString += ConvertPx(sValueTemp);
int nValue = ConvertPx(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
@ -1040,7 +1109,11 @@ namespace NSCSS
}
else if (sValueTemp.find(L"cm") != std::wstring::npos)
{
sValueString += ConvertCm(sValueTemp);
int nValue = ConvertCm(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
@ -1049,7 +1122,12 @@ namespace NSCSS
}
else if (sValueTemp.find(L"mm") != std::wstring::npos)
{
sValueString += ConvertMm(sValueTemp);
int nValue = ConvertMm(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
@ -1058,7 +1136,12 @@ namespace NSCSS
}
else if (sValueTemp.find(L"in") != std::wstring::npos)
{
sValueString += ConvertIn(sValueTemp);
int nValue = ConvertIn(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
@ -1067,7 +1150,12 @@ namespace NSCSS
}
else if (sValueTemp.find(L"pt") != std::wstring::npos)
{
sValueString += ConvertPt(sValueTemp);
int nValue = ConvertPt(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
@ -1076,7 +1164,12 @@ namespace NSCSS
}
else if (sValueTemp.find(L"pc") != std::wstring::npos)
{
sValueString += ConvertPc(sValueTemp);
int nValue = ConvertPc(sValueTemp);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
if (sValueTemp.find(L';') != std::wstring::npos)
sValueString += L';';
@ -1086,6 +1179,7 @@ namespace NSCSS
else if (sValueTemp.find(L"em") != std::wstring::npos)
{
const float fValue = wcstof(sValueTemp.c_str(), NULL) * m_pFont.GetSize();
sValueString += std::to_wstring(static_cast<short int>(fValue + 0.5f));
if (sValueTemp.find(L';') != std::wstring::npos)
@ -1095,7 +1189,16 @@ namespace NSCSS
}
else
{
sValueString += sValueTemp;
if (iswdigit(sValueTemp[0]))
{
int nValue = static_cast<int>(wcstof(sValueTemp.c_str(), NULL) + 0.5f);
Scale(nValue, enScalingDirection);
sValueString += std::to_wstring(nValue);
}
else
sValueString += sValueTemp;
if (sValueTemp.find(L";") != std::wstring::npos)
sValueString += L';';
@ -1110,10 +1213,26 @@ namespace NSCSS
return sValueString;
}
inline std::wstring CCompiledStyle::ConvertPx(const std::wstring& sValue) const
void CCompiledStyle::Scale(int &nValue, ScalingDirection enScalingDirection) const
{
if (ScalingDirectionNone == enScalingDirection)
return;
else if (ScalingDirectionX == enScalingDirection && 0 != m_oSourceWindow.m_ushWidth &&
0 != m_oDeviceWindow.m_ushWidth && m_oSourceWindow.m_ushWidth != m_oDeviceWindow.m_ushWidth)
{
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushWidth * m_oDeviceWindow.m_ushWidth + 0.5f);
}
else if (ScalingDirectionY == enScalingDirection && 0 != m_oSourceWindow.m_ushHeight &&
0 != m_oDeviceWindow.m_ushHeight && m_oSourceWindow.m_ushHeight != m_oDeviceWindow.m_ushHeight)
{
nValue = static_cast<int>((double)nValue / m_oSourceWindow.m_ushHeight * m_oDeviceWindow.m_ushHeight + 0.5f);
}
}
inline int CCompiledStyle::ConvertPx(const std::wstring& sValue) const
{
if (sValue.empty())
return std::wstring();
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"px") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
@ -1121,7 +1240,7 @@ namespace NSCSS
switch (m_UnitMeasure)
{
case Pixel:
return std::to_wstring(static_cast<short int>(dValue));;
return static_cast<int>(dValue);
case Default:
case Point:
return ConvertPxToPt(dValue);
@ -1135,53 +1254,38 @@ namespace NSCSS
return ConvertPxToPc(dValue);
}
return std::wstring();
return 0;
}
inline std::wstring CCompiledStyle::ConvertPxToCm(const float& dValue) const
inline int CCompiledStyle::ConvertPxToCm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / static_cast<float>(m_nDpi) * 2.54f + 0.5f));
return static_cast<int>(dValue / m_nDpi * 2.54f);
}
inline std::wstring CCompiledStyle::ConvertPxToIn(const float& dValue) const
inline int CCompiledStyle::ConvertPxToIn(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(1.0f / static_cast<float>(m_nDpi) * dValue + 0.5f));
return static_cast<int>(1.0f / static_cast<float>(m_nDpi) * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPxToMm(const float& dValue) const
inline int CCompiledStyle::ConvertPxToMm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / static_cast<float>(m_nDpi) * 25.4f + 0.5f));
return static_cast<int>(dValue / static_cast<float>(m_nDpi) * 25.4f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPxToPc(const float& dValue) const
inline int CCompiledStyle::ConvertPxToPc(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(0.16667f / static_cast<float>(m_nDpi) * dValue + 0.5f));
return static_cast<int>(0.16667f / static_cast<float>(m_nDpi) * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPxToPt(const float& dValue) const
inline int CCompiledStyle::ConvertPxToPt(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(72.0f / static_cast<float>(m_nDpi) * dValue + 0.5f));
return static_cast<int>(72.0f / static_cast<float>(m_nDpi) * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertCm(const std::wstring& sValue) const
inline int CCompiledStyle::ConvertCm(const std::wstring& sValue) const
{
if (sValue.empty())
return std::wstring();
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"cm") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
@ -1194,7 +1298,7 @@ namespace NSCSS
case Pixel:
return ConvertCmToPx(dValue);
case Cantimeter:
return std::to_wstring(static_cast<short int>(dValue));;
return static_cast<int>(dValue);
case Millimeter:
return ConvertCmToMm(dValue);
case Inch:
@ -1203,53 +1307,38 @@ namespace NSCSS
return ConvertCmToPc(dValue);
}
return std::wstring();
return 0;
}
inline std::wstring CCompiledStyle::ConvertCmToIn(const float& dValue) const
inline int CCompiledStyle::ConvertCmToIn(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 2.54f + 0.5f));
return static_cast<int>(dValue / 2.54f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertCmToMm(const float& dValue) const
inline int CCompiledStyle::ConvertCmToMm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 10.0f + 0.5f));
return static_cast<int>(dValue * 10.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertCmToPc(const float& dValue) const
inline int CCompiledStyle::ConvertCmToPc(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(2.36f * dValue + 0.5f));
return static_cast<int>(2.36f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertCmToPt(const float& dValue) const
inline int CCompiledStyle::ConvertCmToPt(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(28.35f * dValue + 0.5f));
return static_cast<int>(28.35f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertCmToPx(const float& dValue) const
inline int CCompiledStyle::ConvertCmToPx(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(static_cast<float>(m_nDpi) / 2.54f * dValue + 0.5f));
return static_cast<int>(static_cast<float>(m_nDpi) / 2.54f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertMm(const std::wstring& sValue) const
inline int CCompiledStyle::ConvertMm(const std::wstring& sValue) const
{
if (sValue.empty())
return std::wstring();
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"mm") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
@ -1264,59 +1353,44 @@ namespace NSCSS
case Cantimeter:
return ConvertMmToCm(dValue);
case Millimeter:
return std::to_wstring(static_cast<short int>(dValue));;
return static_cast< int>(dValue);
case Inch:
return ConvertMmToIn(dValue);
case Peak:
return ConvertMmToPc(dValue);
}
return std::wstring();
return 0;
}
inline std::wstring CCompiledStyle::ConvertMmToIn(const float& dValue) const
inline int CCompiledStyle::ConvertMmToIn(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 25.4f + 0.5f));
return static_cast<int>(dValue / 25.4f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertMmToCm(const float& dValue) const
inline int CCompiledStyle::ConvertMmToCm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 10.0f + 0.5f));
return static_cast<int>(dValue / 10.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertMmToPc(const float& dValue) const
inline int CCompiledStyle::ConvertMmToPc(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(2.8346f * dValue + 0.5f));
return static_cast<int>(2.8346f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertMmToPt(const float& dValue) const
inline int CCompiledStyle::ConvertMmToPt(const float& dValue) const
{
if (dValue == 0)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(0.23262f * dValue + 0.5f));
return static_cast<int>(0.23262f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertMmToPx(const float& dValue) const
inline int CCompiledStyle::ConvertMmToPx(const float& dValue) const
{
if (dValue == 0)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(static_cast<float>(m_nDpi) / 25.4f * dValue + 0.5f));
return static_cast<int>(static_cast<float>(m_nDpi) / 25.4f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertIn(const std::wstring& sValue) const
inline int CCompiledStyle::ConvertIn(const std::wstring& sValue) const
{
if (sValue.empty())
return std::wstring();
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"in") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
@ -1333,60 +1407,45 @@ namespace NSCSS
case Millimeter:
return ConvertInToMm(dValue);
case Inch:
return std::to_wstring(static_cast<short int>(dValue));;
return static_cast<int>(dValue);
case Peak:
return ConvertInToPc(dValue);
}
return std::wstring();
return 0;
}
inline std::wstring CCompiledStyle::ConvertInToMm(const float& dValue) const
inline int CCompiledStyle::ConvertInToMm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 25.4f + 0.5f));
return static_cast<int>(dValue * 25.4f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertInToCm(const float& dValue) const
inline int CCompiledStyle::ConvertInToCm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 2.54f + 0.5f));
return static_cast<int>(dValue * 2.54f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertInToPc(const float& dValue) const
inline int CCompiledStyle::ConvertInToPc(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 72.0f + 0.5f));
return static_cast<int>(dValue / 72.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertInToPt(const float& dValue) const
inline int CCompiledStyle::ConvertInToPt(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 6.0f + 0.5f));
return static_cast<int>(dValue / 6.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertInToPx(const float& dValue) const
inline int CCompiledStyle::ConvertInToPx(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * static_cast<float>(m_nDpi) + 0.5f));
return static_cast<short int>(dValue * static_cast<float>(m_nDpi) + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPt(const std::wstring& sValue) const
inline int CCompiledStyle::ConvertPt(const std::wstring& sValue) const
{
if (sValue.empty())
return std::wstring();
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"pt") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
switch (m_UnitMeasure)
{
@ -1394,7 +1453,7 @@ namespace NSCSS
return ConvertPtToPx(dValue);
case Default:
case Point:
return std::to_wstring(static_cast<short int>(dValue));
return static_cast<int>(dValue + 0.5f);
case Cantimeter:
return ConvertPtToCm(dValue);
case Millimeter:
@ -1405,53 +1464,38 @@ namespace NSCSS
return ConvertPtToPc(dValue);
}
return std::wstring();
return 0;
}
inline std::wstring CCompiledStyle::ConvertPtToIn(const float& dValue) const
inline int CCompiledStyle::ConvertPtToIn(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring((dValue / 72.0f + 0.5f));
return static_cast<int>(dValue / 72.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPtToCm(const float& dValue) const
inline int CCompiledStyle::ConvertPtToCm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 0.03528f + 0.5f));
return static_cast<int>(dValue * 0.03528f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPtToPc(const float& dValue) const
inline int CCompiledStyle::ConvertPtToPc(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 12.0f + 0.5f));
return static_cast<int>(dValue / 12.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPtToMm(const float& dValue) const
inline int CCompiledStyle::ConvertPtToMm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring((dValue * 0.3528f + 0.5f));
return static_cast<int>(dValue * 0.3528f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPtToPx(const float& dValue) const
inline int CCompiledStyle::ConvertPtToPx(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(static_cast<float>(m_nDpi) / 72.0f * dValue + 0.5f));
return static_cast<short int>(static_cast<float>(m_nDpi) / 72.0f * dValue + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPc(const std::wstring& sValue) const
inline int CCompiledStyle::ConvertPc(const std::wstring& sValue) const
{
if (sValue.empty())
return std::wstring();
return 0;
const std::wstring& sConvertValue = sValue.substr(0, sValue.find_last_of(L"pc") - 1);
const float dValue = wcstof(sConvertValue.c_str(), NULL) * 2.0f;
@ -1470,50 +1514,35 @@ namespace NSCSS
case Inch:
return ConvertPcToIn(dValue);
case Peak:
return std::to_wstring(static_cast<short int>(dValue));
return static_cast<int>(dValue);
}
return std::wstring();
return 0;
}
inline std::wstring CCompiledStyle::ConvertPcToIn(const float& dValue) const
inline int CCompiledStyle::ConvertPcToIn(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue / 6.0f + 0.5f));
return static_cast<int>(dValue / 6.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPcToCm(const float& dValue) const
inline int CCompiledStyle::ConvertPcToCm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 0.423f + 0.5f));
return static_cast<int>(dValue * 0.423f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPcToPt(const float& dValue) const
inline int CCompiledStyle::ConvertPcToPt(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 12.0f + 0.5f));
return static_cast<int>(dValue * 12.0f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPcToMm(const float& dValue) const
inline int CCompiledStyle::ConvertPcToMm(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(dValue * 4.23f + 0.5f));
return static_cast<int>(dValue * 4.23f + 0.5f);
}
inline std::wstring CCompiledStyle::ConvertPcToPx(const float& dValue) const
inline int CCompiledStyle::ConvertPcToPx(const float& dValue) const
{
if (dValue == 0.0f)
return std::wstring(L"0");
return std::to_wstring(static_cast<short int>(static_cast<float>(m_nDpi) / 6.0f * dValue + 0.5f));
return static_cast<int>(static_cast<float>(m_nDpi) / 6.0f * dValue + 0.5f);
}
}

View File

@ -19,49 +19,54 @@ namespace NSCSS
unsigned short int m_nDpi;
UnitMeasure m_UnitMeasure;
std::wstring ConvertUnitMeasure(const std::wstring& sValue, const float& fPreviousValue) const;
CSizeWindow m_oSourceWindow;
CSizeWindow m_oDeviceWindow;
std::wstring ConvertPx(const std::wstring& sValue) const;
std::wstring ConvertPxToCm(const float& dValue) const;
std::wstring ConvertPxToIn(const float& dValue) const;
std::wstring ConvertPxToMm(const float& dValue) const;
std::wstring ConvertPxToPt(const float& dValue) const;
std::wstring ConvertPxToPc(const float& dValue) const;
std::wstring ConvertUnitMeasure(const std::wstring& sValue, const float& fPreviousValue, ScalingDirection enScalingDirection = ScalingDirectionNone) const;
std::wstring ConvertCm(const std::wstring& sValue) const;
std::wstring ConvertCmToPx(const float& dValue) const;
std::wstring ConvertCmToIn(const float& dValue) const;
std::wstring ConvertCmToMm(const float& dValue) const;
std::wstring ConvertCmToPt(const float& dValue) const;
std::wstring ConvertCmToPc(const float& dValue) const;
void Scale(int &nValue, ScalingDirection enScalingDirection) const;
std::wstring ConvertMm(const std::wstring& sValue) const;
std::wstring ConvertMmToPx(const float& dValue) const;
std::wstring ConvertMmToIn(const float& dValue) const;
std::wstring ConvertMmToCm(const float& dValue) const;
std::wstring ConvertMmToPt(const float& dValue) const;
std::wstring ConvertMmToPc(const float& dValue) const;
int ConvertPx(const std::wstring& sValue) const;
int ConvertPxToCm(const float& dValue) const;
int ConvertPxToIn(const float& dValue) const;
int ConvertPxToMm(const float& dValue) const;
int ConvertPxToPt(const float& dValue) const;
int ConvertPxToPc(const float& dValue) const;
std::wstring ConvertIn(const std::wstring& sValue) const;
std::wstring ConvertInToPx(const float& dValue) const;
std::wstring ConvertInToMm(const float& dValue) const;
std::wstring ConvertInToCm(const float& dValue) const;
std::wstring ConvertInToPt(const float& dValue) const;
std::wstring ConvertInToPc(const float& dValue) const;
int ConvertCm(const std::wstring& sValue) const;
int ConvertCmToPx(const float& dValue) const;
int ConvertCmToIn(const float& dValue) const;
int ConvertCmToMm(const float& dValue) const;
int ConvertCmToPt(const float& dValue) const;
int ConvertCmToPc(const float& dValue) const;
std::wstring ConvertPt(const std::wstring& sValue) const;
std::wstring ConvertPtToPx(const float& dValue) const;
std::wstring ConvertPtToMm(const float& dValue) const;
std::wstring ConvertPtToCm(const float& dValue) const;
std::wstring ConvertPtToIn(const float& dValue) const;
std::wstring ConvertPtToPc(const float& dValue) const;
int ConvertMm(const std::wstring& sValue) const;
int ConvertMmToPx(const float& dValue) const;
int ConvertMmToIn(const float& dValue) const;
int ConvertMmToCm(const float& dValue) const;
int ConvertMmToPt(const float& dValue) const;
int ConvertMmToPc(const float& dValue) const;
std::wstring ConvertPc(const std::wstring& sValue) const;
std::wstring ConvertPcToPx(const float& dValue) const;
std::wstring ConvertPcToMm(const float& dValue) const;
std::wstring ConvertPcToCm(const float& dValue) const;
std::wstring ConvertPcToIn(const float& dValue) const;
std::wstring ConvertPcToPt(const float& dValue) const;
int ConvertIn(const std::wstring& sValue) const;
int ConvertInToPx(const float& dValue) const;
int ConvertInToMm(const float& dValue) const;
int ConvertInToCm(const float& dValue) const;
int ConvertInToPt(const float& dValue) const;
int ConvertInToPc(const float& dValue) const;
int ConvertPt(const std::wstring& sValue) const;
int ConvertPtToPx(const float& dValue) const;
int ConvertPtToMm(const float& dValue) const;
int ConvertPtToCm(const float& dValue) const;
int ConvertPtToIn(const float& dValue) const;
int ConvertPtToPc(const float& dValue) const;
int ConvertPc(const std::wstring& sValue) const;
int ConvertPcToPx(const float& dValue) const;
int ConvertPcToMm(const float& dValue) const;
int ConvertPcToCm(const float& dValue) const;
int ConvertPcToIn(const float& dValue) const;
int ConvertPcToPt(const float& dValue) const;
public:
@ -70,6 +75,7 @@ namespace NSCSS
NSConstValues::NSCssProperties::Background m_pBackground;
NSConstValues::NSCssProperties::Text m_pText;
NSConstValues::NSCssProperties::Border m_pBorder;
NSConstValues::NSCssProperties::Display m_pDisplay;
CCompiledStyle();
explicit CCompiledStyle(const std::map<std::wstring, std::wstring>& mStyle);
@ -79,6 +85,8 @@ namespace NSCSS
void SetDpi(const unsigned short& uiDpi);
void SetUnitMeasure(const UnitMeasure& enUnitMeasure);
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
bool Empty() const;

View File

@ -46,7 +46,27 @@ namespace NSCSS
void CCssCalculator::SetBodyTree(const CTree &oTree)
{
m_pInternal->SetBodyTree(oTree);
m_pInternal->SetBodyTree(oTree);
}
void CCssCalculator::SetSizeSourceWindow(const CSizeWindow &oSizeWindow)
{
m_pInternal->SetSizeSourceWindow(oSizeWindow);
}
void CCssCalculator::SetSizeDeviceWindow(const CSizeWindow &oSizeWindow)
{
m_pInternal->SetSizeDeviceWindow(oSizeWindow);
}
CSizeWindow CCssCalculator::GetSizeSourceWindow() const
{
return m_pInternal->GetSizeSourceWindow();
}
CSizeWindow CCssCalculator::GetSizeDeviceWindow() const
{
return m_pInternal->GetSizeDeviceWindow();
}
UnitMeasure CCssCalculator::GetUnitMeasure() const

View File

@ -30,6 +30,11 @@ namespace NSCSS
void SetDpi(const unsigned short int& nValue);
void SetBodyTree(const CTree &oTree);
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
CSizeWindow GetSizeSourceWindow() const;
CSizeWindow GetSizeDeviceWindow() const;
UnitMeasure GetUnitMeasure() const;
std::wstring GetEncoding() const;

View File

@ -326,13 +326,19 @@ namespace NSCSS
oStyle.SetUnitMeasure(m_UnitMeasure);
oStyle.SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
oStyle.SetSizeDeviceWindow(m_oDeviceWindow);
oStyle.SetSizeSourceWindow(m_oSourceWindow);
return oStyle;
}
CCompiledStyle *oStyle = new CCompiledStyle();
CCompiledStyle *pStyle = new CCompiledStyle();
oStyle->SetDpi(m_nDpi);
oStyle->SetUnitMeasure(m_UnitMeasure);
pStyle->SetDpi(m_nDpi);
pStyle->SetUnitMeasure(m_UnitMeasure);
pStyle->SetSizeDeviceWindow(m_oDeviceWindow);
pStyle->SetSizeSourceWindow(m_oSourceWindow);
std::vector<std::wstring> arWords;
arWords.reserve(arSelectors.size() * 2);
@ -345,10 +351,10 @@ namespace NSCSS
arWords.push_back(oNode->m_sName);
if (oNode->m_sName == L"td")
oStyle->m_pMargin.SetPermission(false);
pStyle->m_pMargin.SetPermission(false);
if (oNode->m_sName == L"table")
oStyle->m_pBorder.Block();
pStyle->m_pBorder.Block();
if (!oNode->m_sClass.empty())
{
@ -415,7 +421,7 @@ namespace NSCSS
sName = arWords.back();
arWords.pop_back();
arNextNodes.push_back(sName);
oStyle->AddParent(sName);
pStyle->AddParent(sName);
const std::map<std::wstring, CElement*>::const_iterator oFindName = m_mData.find(sName);
std::map<std::wstring, CElement*>::const_iterator oFindId;
@ -496,25 +502,30 @@ namespace NSCSS
});
}
pStyle->AddStyle(arSelectors[i].m_mAttrs, i + 1);
for (const CElement* oElement : arFindElements)
oStyle->AddStyle(oElement->GetStyle(), i + 1);
pStyle->AddStyle(oElement->GetStyle(), i + 1);
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_sStyle});
if(oFindCountStyle != m_mStatictics->end())
{
if ((bIsSettings && oFindCountStyle->second < MaxNumberRepetitions) ||
(!bIsSettings && oFindCountStyle->second >= MaxNumberRepetitions))
oStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
else if (!bIsSettings)
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
}
}
if (!bIsSettings)
{
oStyle->SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
m_mUsedStyles[arSelectors] = oStyle;
pStyle->SetID(arSelectors.back().m_sName + ((!arSelectors.back().m_sClass.empty()) ? L'.' + arSelectors.back().m_sClass : L"") + ((arSelectors.back().m_sId.empty()) ? L"" : L'#' + arSelectors.back().m_sId) + L'-' + std::to_wstring(++m_nCountNodes));
m_mUsedStyles[arSelectors] = pStyle;
}
return *oStyle;
return *pStyle;
}
void CCssCalculator_Private::AddStyles(const std::string &sStyle)
@ -558,6 +569,26 @@ namespace NSCSS
CTree::CountingNumberRepetitions(oTree, *m_mStatictics);
}
void CCssCalculator_Private::SetSizeSourceWindow(const CSizeWindow &oSizeWindow)
{
m_oSourceWindow = oSizeWindow;
}
void CCssCalculator_Private::SetSizeDeviceWindow(const CSizeWindow &oSizeWindow)
{
m_oDeviceWindow = oSizeWindow;
}
CSizeWindow CCssCalculator_Private::GetSizeSourceWindow() const
{
return m_oSourceWindow;
}
CSizeWindow CCssCalculator_Private::GetSizeDeviceWindow() const
{
return m_oDeviceWindow;
}
void CCssCalculator_Private::SetUnitMeasure(const UnitMeasure& nType)
{
m_UnitMeasure = nType;
@ -587,6 +618,9 @@ namespace NSCSS
m_mData.clear();
m_arFiles.clear();
m_oDeviceWindow.Clear();
m_oSourceWindow.Clear();
}
}
inline static std::wstring StringifyValueList(const KatanaArray* oValues)

View File

@ -27,6 +27,9 @@ namespace NSCSS
std::wstring m_sEncoding;
CSizeWindow m_oSourceWindow;
CSizeWindow m_oDeviceWindow;
void GetStylesheet(const KatanaStylesheet* oStylesheet);
void GetRule(const KatanaRule* oRule);
@ -56,6 +59,12 @@ namespace NSCSS
void SetDpi(unsigned short int nValue);
void SetBodyTree(const CTree &oTree);
void SetSizeSourceWindow(const CSizeWindow& oSizeWindow);
void SetSizeDeviceWindow(const CSizeWindow& oSizeWindow);
CSizeWindow GetSizeSourceWindow() const;
CSizeWindow GetSizeDeviceWindow() const;
UnitMeasure GetUnitMeasure() const;
std::wstring GetEncoding() const;
unsigned short int GetDpi() const;

View File

@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <map>
namespace NSCSS
{
@ -12,6 +13,7 @@ namespace NSCSS
std::wstring m_sClass; // Класс тэга
std::wstring m_sId; // Id тэга
std::wstring m_sStyle; // Стиль тэга
std::map<std::wstring, std::wstring> m_mAttrs; // Остальные аттрибуты тэга
CNode(){};
CNode(std::wstring sName, std::wstring sClass, std::wstring sId) : m_sName(sName), m_sClass(sClass), m_sId(sId){};

View File

@ -19,6 +19,43 @@ namespace NSCSS
Peak
} UnitMeasure;
typedef enum
{
ScalingDirectionNone = 0,
ScalingDirectionX = 1,
ScalingDirectionY = 2
} ScalingDirection;
struct CSizeWindow
{
unsigned short m_ushWidth;
unsigned short m_ushHeight;
CSizeWindow()
: m_ushWidth(0), m_ushHeight(0) {};
CSizeWindow(unsigned short unWidth, unsigned short unHeight)
: m_ushWidth(unWidth), m_ushHeight(unHeight) {};
bool Empty() const
{
return ((0 == m_ushWidth) && (0 == m_ushHeight));
}
void Clear()
{
m_ushWidth = m_ushHeight = 0;
}
bool operator==(const CSizeWindow& oSizeWindow) const
{
return ((m_ushWidth == oSizeWindow.m_ushWidth) && (m_ushHeight == oSizeWindow.m_ushHeight));
}
bool operator!=(const CSizeWindow& oSizeWindow) const
{
return ((m_ushWidth != oSizeWindow.m_ushWidth) || (m_ushHeight != oSizeWindow.m_ushHeight));
}
};
struct StatistickElement
{
enum TypeElement
@ -121,6 +158,31 @@ namespace NSCSS
};
}
static const std::vector<std::wstring> arDisplayValues =
{
/* <display-outside> values */
L"block", L"inline", L"run-in",
/* <display-inside> values */
L"flow", L"flow-root", L"table", L"flex", L"grid", L"ruby",
/* <display-outside> plus <display-inside> values */
L"block flow", L"inline table", L"flex run-in",
/* <display-listitem> values */
L"list-item", L"list-item block", L"list-item inline", L"list-item flow",
L"list-item flow-root", L"list-item block flow",
L"list-item block flow-root", L"flow list-item block",
/* <display-internal> values */
L"table-row-group", L"table-header-group", L"table-footer-group",
L"table-row", L"table-cell", L"table-column-group", L"table-column",
L"table-caption", L"ruby-base", L"ruby-text", L"ruby-base-container",
L"ruby-text-container",
/* <display-box> values */
L"contents", L"none",
/* <display-legacy> values */
L"inline-block", L"inline-table", L"inline-flex", L"inline-grid",
/* Global values */
L"inherit", L"initial", L"unset"
};
namespace NSProperties {
typedef enum
@ -828,7 +890,10 @@ namespace NSCSS
return;
if (sLineHeight == L"normal")
fLineHeight = 1.2;
{
arLevels[5] = unLevel;
fLineHeight = 24;
}
else
{
const float fValue = wcstof(sLineHeight.c_str(), NULL);
@ -1301,7 +1366,7 @@ namespace NSCSS
normal
};
enum class TextAlign
enum class Align
{
none = 0,
left,
@ -1313,7 +1378,7 @@ namespace NSCSS
class Text
{
float fIndent;
TextAlign enAlign;
Align enAlign;
TextDecoration enDecoration;
std::wstring sColor; //HEX color
@ -1323,7 +1388,7 @@ namespace NSCSS
public:
Text() : fIndent (fNoneValue),
enAlign (TextAlign::none),
enAlign (Align::none),
enDecoration (TextDecoration::none),
bImportants ({false, false, false, false}),
arLevels ({0, 0, 0, 0}){}
@ -1337,7 +1402,7 @@ namespace NSCSS
{
if (oText.fIndent != fNoneValue)
fIndent = oText.fIndent;
if (oText.enAlign != TextAlign::none)
if (oText.enAlign != Align::none)
enAlign = oText.enAlign;
if (oText.enDecoration != TextDecoration::none)
enDecoration = oText.enDecoration;
@ -1363,16 +1428,16 @@ namespace NSCSS
oSecondText.fIndent = fNoneValue;
}
if (oFirstText.bImportants[1] && !oSecondText.bImportants[1] && oFirstText.enAlign != TextAlign::none)
oSecondText.enAlign = TextAlign::none;
else if (oSecondText.bImportants[1] && !oFirstText.bImportants[1] && oSecondText.enAlign != TextAlign::none)
oFirstText.enAlign = TextAlign::none;
else if (oFirstText.enAlign != TextAlign::none && oSecondText.enAlign != TextAlign::none)
if (oFirstText.bImportants[1] && !oSecondText.bImportants[1] && oFirstText.enAlign != Align::none)
oSecondText.enAlign = Align::none;
else if (oSecondText.bImportants[1] && !oFirstText.bImportants[1] && oSecondText.enAlign != Align::none)
oFirstText.enAlign = Align::none;
else if (oFirstText.enAlign != Align::none && oSecondText.enAlign != Align::none)
{
if (oFirstText.arLevels[1] < oSecondText.arLevels[1])
oFirstText.enAlign = TextAlign::none;
oFirstText.enAlign = Align::none;
else
oSecondText.enAlign = TextAlign::none;
oSecondText.enAlign = Align::none;
}
if (oFirstText.bImportants[2] && !oSecondText.bImportants[2] && oFirstText.enDecoration != TextDecoration::none)
@ -1410,7 +1475,7 @@ namespace NSCSS
bool Empty() const
{
return fIndent == fNoneValue && enAlign == TextAlign::none &&
return fIndent == fNoneValue && enAlign == Align::none &&
enDecoration == TextDecoration::none && sColor.empty();
}
@ -1422,22 +1487,22 @@ namespace NSCSS
if (sAlign == L"center")
{
arLevels[1] = unLevel;
enAlign = NSConstValues::NSCssProperties::TextAlign::center;
enAlign = NSConstValues::NSCssProperties::Align::center;
}
else if(sAlign == L"justify")
{
arLevels[1] = unLevel;
enAlign = NSConstValues::NSCssProperties::TextAlign::justify;
enAlign = NSConstValues::NSCssProperties::Align::justify;
}
else if(sAlign == L"left" || sAlign == L"start")
{
arLevels[1] = unLevel;
enAlign = NSConstValues::NSCssProperties::TextAlign::left;
enAlign = NSConstValues::NSCssProperties::Align::left;
}
else if(sAlign == L"right" || sAlign == L"end")
{
arLevels[1] = unLevel;
enAlign = NSConstValues::NSCssProperties::TextAlign::right;
enAlign = NSConstValues::NSCssProperties::Align::right;
}
}
@ -1560,13 +1625,13 @@ namespace NSCSS
std::wstring GetAlign() const
{
if (enAlign == TextAlign::left)
if (enAlign == Align::left)
return L"left";
if (enAlign == TextAlign::center)
if (enAlign == Align::center)
return L"center";
if (enAlign == TextAlign::right)
if (enAlign == Align::right)
return L"right";
if (enAlign == TextAlign::justify)
if (enAlign == Align::justify)
return L"both";
return std::wstring();
@ -1701,7 +1766,7 @@ namespace NSCSS
bool Empty() const
{
return fWidth <= 0;
return fWidth < 0 && !bBlock;
}
void SetWidthWithoutChecking(const float& fWidth, const unsigned int& unLevel, const bool &bHardMode = false)
@ -1889,7 +1954,10 @@ namespace NSCSS
std::wstring GetStyle() const
{
return (bBlock) ? L"auto" : sStyle;
if (bBlock) return L"auto";
if (0 == fWidth) return L"none";
else if (L"auto" == sStyle) return L"single";
else return sStyle;
}
std::wstring GetColor() const
@ -1942,7 +2010,7 @@ namespace NSCSS
else if (iswdigit(sValue[0]))
{
const float fWidth = wcstof(sValue.c_str(), NULL);
if (fWidth > 0.0f)
if (fWidth >= 0.0f)
oBorderSide.fWidth = fWidth;
}
else if (sValue.substr(0, 3) == L"rgb")
@ -2425,7 +2493,7 @@ namespace NSCSS
std::vector<unsigned int> arLevels;
public:
Background() : bImportants({false}), arLevels({0}), bInBorder(false){}
Background() : bInBorder(false), bImportants({false}), arLevels({0}){}
void ClearImportants()
{
@ -2444,8 +2512,10 @@ namespace NSCSS
Background operator+=(const Background& oBackground)
{
if (oBackground.sColor.empty())
sColor = oBackground.sColor;
if (oBackground.sColor.empty() || (bImportants[0] && !oBackground.bImportants[0]))
return *this;
sColor = oBackground.sColor;
return *this;
}
@ -2587,6 +2657,165 @@ namespace NSCSS
return L"";
}
};
class Display
{
std::wstring wsDisplay;
int nWidth;
std::wstring wsAlign;
std::vector<bool> bImportants;
std::vector<unsigned int> arLevels;
public:
Display() : wsDisplay(L"inline"), nWidth(-1), wsAlign(), bImportants{false, false, false}, arLevels{0, 0, 0} {};
void ClearImportants()
{
bImportants = {false, false, false};
}
Display operator+=(const Display& oDisplay)
{
if (oDisplay.Empty())
return *this;
wsDisplay = oDisplay.wsDisplay;
nWidth = oDisplay.nWidth;
wsAlign = oDisplay.wsAlign;
return *this;
}
static void DisplayEquation(Display &oFirstDisplay, Display &oSecondDisplay)
{
if (oFirstDisplay.bImportants[0] && !oSecondDisplay.bImportants[0] && !oFirstDisplay.wsDisplay.empty())
oSecondDisplay.wsDisplay.clear();
else if (oSecondDisplay.bImportants[0] && !oFirstDisplay.bImportants[0] && !oSecondDisplay.wsDisplay.empty())
oFirstDisplay.wsDisplay.clear();
else if (!oSecondDisplay.wsDisplay.empty())
{
if (oFirstDisplay.arLevels[0] < oSecondDisplay.arLevels[0])
oFirstDisplay.wsDisplay.clear();
else
oSecondDisplay.wsDisplay.clear();
}
if (oFirstDisplay.bImportants[1] && !oSecondDisplay.bImportants[1] && oFirstDisplay.nWidth > 0)
oSecondDisplay.nWidth = -1;
else if (oSecondDisplay.bImportants[1] && !oFirstDisplay.bImportants[1] && oSecondDisplay.nWidth > 0)
oFirstDisplay.nWidth = -1;
else if (oSecondDisplay.nWidth > 0)
{
if (oFirstDisplay.arLevels[1] < oSecondDisplay.arLevels[1])
oFirstDisplay.nWidth = -1;
else
oSecondDisplay.nWidth = -1;
}
if (oFirstDisplay.bImportants[2] && !oSecondDisplay.bImportants[2] && !oFirstDisplay.wsAlign.empty())
oSecondDisplay.wsAlign.clear();
else if (oSecondDisplay.bImportants[2] && !oFirstDisplay.bImportants[2] && !oSecondDisplay.wsAlign.empty())
oFirstDisplay.wsAlign.clear();
else if (!oSecondDisplay.wsAlign.empty())
{
if (oFirstDisplay.arLevels[2] < oSecondDisplay.arLevels[2])
oFirstDisplay.wsAlign.clear();
else
oSecondDisplay.wsAlign.clear();
}
}
bool operator==(const Display& oDisplay) const
{
return wsDisplay == oDisplay.wsDisplay && nWidth == oDisplay.nWidth && wsAlign == oDisplay.wsAlign;
}
bool Empty() const
{
return (L"inline" == wsDisplay || wsDisplay.empty()) && (nWidth < 0) && (wsAlign.empty());
}
void SetImportantAll(const bool &bImportant)
{
bImportants = {bImportant, bImportant, bImportant};
}
void SetImportantDisplay(const bool &bImportant)
{
bImportants[0] = bImportant;
}
void SetImportantWidth(const bool &bImportant)
{
bImportants[1] = bImportant;
}
void SetImportantAlign(const bool& bImportant)
{
bImportants[2] = bImportant;
}
void SetDisplay(const std::wstring& wsNewDisplay, const unsigned int& unLevel, const bool &bHardMode = false)
{
if (wsNewDisplay.empty() || (bImportants[0] && !bHardMode))
return;
if (arDisplayValues.end() != std::find(arDisplayValues.begin(), arDisplayValues.end(), wsNewDisplay))
{
wsDisplay = wsNewDisplay;
arLevels[0] = unLevel;
}
}
void SetWidth(const std::wstring& wsNewValue, const unsigned int& unLevel, const bool &bHardMode = false)
{
if (wsNewValue.empty() || !iswdigit(wsNewValue[0]) || (bImportants[1] && !bHardMode))
return;
arLevels[1] = unLevel;
nWidth = std::stoi(wsNewValue);
}
void SetWidth(int nValue, const unsigned int& unLevel, const bool &bHardMode = false)
{
if (bImportants[1] && !bHardMode)
return;
arLevels[1] = unLevel;
nWidth = nValue;
}
void SetAlign(const std::wstring& sAlign, const unsigned int& unLevel, const bool& bHardMode = false)
{
if (sAlign.empty() || (bImportants[2] && !bHardMode))
return;
if (L"center" == sAlign || L"left" == sAlign || L"start" == sAlign ||
L"right" == sAlign || L"end" == sAlign)
{
arLevels[2] = unLevel;
wsAlign = sAlign;
}
}
std::wstring GetDisplay() const
{
return wsDisplay;
}
std::wstring GetWidthW() const
{
if (nWidth < 0)
return std::wstring();
return std::to_wstring(nWidth);
}
std::wstring GetAlign() const
{
return wsAlign;
}
};
}
const std::vector<std::wstring> arPseudoClasses {

View File

@ -279,6 +279,8 @@ namespace NSCSS
sSpacingValue += L"w:after=\"" + oStyle.m_pMargin.GetTopSide() + L"\" ";
sSpacingValue += L"w:before=\"" + oStyle.m_pMargin.GetTopSide() + L"\" ";
}
else if (!oStyle.m_pBorder.Empty())
sSpacingValue += L"w:after=\"0\" w:before=\"0\" ";
const std::wstring &sLineHeight = oStyle.m_pFont.GetLineHeight();
if (!sLineHeight.empty())
@ -286,6 +288,8 @@ namespace NSCSS
sSpacingValue += L"w:line=\"" + sLineHeight + L"\" ";
sSpacingValue += L"w:lineRule=\"auto\"";
}
// else if (!oStyle.m_pBorder.Empty())
// sSpacingValue += L"w:line=\"240\" w:lineRule=\"auto\" ";
if (!sSpacingValue.empty())
{
@ -308,7 +312,7 @@ namespace NSCSS
const std::wstring sBorderStyle = oStyle.m_pBorder.GetStyleBottomSide();
const std::wstring sBorderWidth = oStyle.m_pBorder.GetWidthBottomSideW();
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"4\" w:sz=\"" +
const std::wstring sBorder = L" w:color=\"" + sBorderColor + L"\" w:space=\"0\" w:sz=\"" +
sBorderWidth + L"\" w:val=\"" + sBorderStyle + L"\"";
oXmlElement.AddPropertiesInP(NSConstValues::NSProperties::ParagraphProperties::P_TopBorder, sBorder);

View File

@ -34,30 +34,33 @@ static void replace_all(std::string& s, const std::string& s1, const std::string
}
}
static std::wstring htmlToXhtml(std::string& sFileContent)
static std::wstring htmlToXhtml(std::string& sFileContent, bool bNeedConvert)
{
// Распознование кодировки
size_t posEncoding = sFileContent.find("charset=");
if (posEncoding == std::string::npos)
posEncoding = sFileContent.find("encoding=");
if (posEncoding != std::string::npos)
// Распознование кодировк
if (bNeedConvert)
{
posEncoding = sFileContent.find("=", posEncoding) + 1;
char quoteSymbol = '\"';
if(sFileContent[posEncoding] == '\"' || sFileContent[posEncoding] == '\'')
size_t posEncoding = sFileContent.find("charset=");
if (posEncoding == std::string::npos)
posEncoding = sFileContent.find("encoding=");
if (posEncoding != std::string::npos)
{
quoteSymbol = sFileContent[posEncoding];
posEncoding += 1;
}
size_t posEnd = sFileContent.find(quoteSymbol, posEncoding);
if (std::string::npos != posEnd)
{
std::string sEncoding = sFileContent.substr(posEncoding, posEnd - posEncoding);
if (sEncoding != "utf-8" && sEncoding != "UTF-8")
posEncoding = sFileContent.find("=", posEncoding) + 1;
char quoteSymbol = '\"';
if(sFileContent[posEncoding] == '\"' || sFileContent[posEncoding] == '\'')
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sFileContent = U_TO_UTF8(oConverter.toUnicode(sFileContent, sEncoding.c_str()));
quoteSymbol = sFileContent[posEncoding];
posEncoding += 1;
}
size_t posEnd = sFileContent.find(quoteSymbol, posEncoding);
if (std::string::npos != posEnd)
{
std::string sEncoding = sFileContent.substr(posEncoding, posEnd - posEncoding);
if (sEncoding != "utf-8" && sEncoding != "UTF-8")
{
NSUnicodeConverter::CUnicodeConverter oConverter;
sFileContent = U_TO_UTF8(oConverter.toUnicode(sFileContent, sEncoding.c_str()));
}
}
}
}
@ -423,11 +426,8 @@ static std::string mhtTohtml(std::string& sFileContent)
return sFile;
}
static std::wstring mhtToXhtml(const std::wstring& sFile)
static std::wstring mhtToXhtml(std::string& sFileContent)
{
std::string sFileContent;
if(!NSFile::CFileBinary::ReadAllTextUtf8A(sFile, sFileContent))
return L"";
sFileContent = mhtTohtml(sFileContent);
// Gumbo

View File

@ -1267,7 +1267,11 @@ namespace OOX
m_oType.Init();
m_oType->SetValueFromByte(pReader->GetUChar());
}
else if (10 == _at) m_oVal = pReader->GetDoubleReal();
else if (10 == _at)
{
m_oVal.Init();
m_oVal->SetValue(pReader->GetDoubleReal());
}
}
pReader->Seek(end);
}
@ -1284,8 +1288,8 @@ namespace OOX
if (m_oRefPtType.IsInit()) pWriter->WriteByte1(7, m_oRefPtType->GetValue());
if (m_oRefType.IsInit()) pWriter->WriteByte1(8, m_oRefType->GetValue());
if (m_oType.IsInit()) pWriter->WriteByte1(9, m_oType->GetValue());
pWriter->WriteDoubleReal2(10, m_oVal);
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
if (m_oVal.IsInit()) pWriter->WriteDoubleReal1(10, m_oVal->GetValue());
pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd);
}
void Diagram::CConstraint::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const
{
@ -1302,8 +1306,8 @@ namespace OOX
pWriter->WriteAttribute(L"refForName", m_oRefForName);
if (m_oOp.IsInit()) pWriter->WriteAttribute(L"op", m_oOp->ToString());
pWriter->WriteAttribute(L"fact", m_oFact);
pWriter->WriteAttribute(L"val", m_oVal);
pWriter->EndAttributes();
if (m_oVal.IsInit()) pWriter->WriteAttribute(L"val", m_oVal->ToString());
pWriter->EndAttributes();
pWriter->WriteNodeEnd(L"dgm:constr");
}
void Diagram::CConstraint::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)

View File

@ -241,7 +241,7 @@ namespace OOX
nullable<SimpleTypes::CElementTypes<>> m_oRefPtType;
nullable<SimpleTypes::CConstraintType<>> m_oRefType;
nullable<SimpleTypes::CConstraintType<>> m_oType;
nullable_double m_oVal;
nullable<SimpleTypes::CDouble> m_oVal;
nullable<OOX::Drawing::COfficeArtExtensionList> m_oExtLst;
};

View File

@ -37,6 +37,10 @@
#pragma comment(lib, "Wininet")
#pragma comment(lib, "Ole32.lib")
#ifdef GetTempPath
#undef GetTempPath
#endif
//------------------------------------------------------------------------------------------------------
// Константа для максимального числа символов в строке
@ -90,6 +94,13 @@ namespace NSNetwork
CoInitialize ( NULL );
if ( /*S_OK != _DownloadFile ( m_sFileUrl )*/TRUE )
{
if (m_sDownloadFilePath.empty())
{
m_sDownloadFilePath = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"DWD");
if (NSFile::CFileBinary::Exists(m_sDownloadFilePath))
NSFile::CFileBinary::Remove(m_sDownloadFilePath);
}
HRESULT hrResultAll = DownloadFileAll(m_sDownloadFileUrl, m_sDownloadFilePath);
if (S_OK != hrResultAll)

View File

@ -44,7 +44,7 @@ CBgraFrame* GetFrame(IOfficeDrawingFile* pFile, int nPageIndex, int nRasterW, in
if (!pApplicationFonts)
return NULL;
NSFonts::IFontManager *pFontManager = pApplicationFonts->GenerateFontManager();
pFontManager = pApplicationFonts->GenerateFontManager();
NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create();
pFontCache->SetStreams(pApplicationFonts->GetStreams());
pFontManager->SetOwnerCache(pFontCache);

View File

@ -1962,11 +1962,32 @@ HRESULT CFb2File::FromHtml(const std::wstring& sHtmlFile, const std::wstring& sC
oDocument.WriteString(L"</version></document-info>");
// body
oDocument.WriteString(L"</description><body><section>");
std::string sContent;
NSFile::CFileBinary::ReadAllTextUtf8A(sHtmlFile, sContent);;
BYTE* pData;
DWORD nLength;
if (!NSFile::CFileBinary::ReadAllBytes(sHtmlFile, &pData, nLength))
return S_FALSE;
std::string sContent = XmlUtils::GetUtf8FromFileContent(pData, nLength);
bool bNeedConvert = true;
if (nLength > 4)
{
if (pData[0] == 0xFF && pData[1] == 0xFE && !(pData[2] == 0x00 && pData[3] == 0x00))
bNeedConvert = false;
if (pData[0] == 0xFE && pData[1] == 0xFF)
bNeedConvert = false;
if (pData[0] == 0xFF && pData[1] == 0xFE && pData[2] == 0x00 && pData[3] == 0x00)
bNeedConvert = false;
if (pData[0] == 0 && pData[1] == 0 && pData[2] == 0xFE && pData[3] == 0xFF)
bNeedConvert = false;
}
RELEASEARRAYOBJECTS(pData);
XmlUtils::CXmlLiteReader oIndexHtml;
std::vector<std::wstring> arrBinary;
if (oIndexHtml.FromString(htmlToXhtml(sContent)))
std::wstring xhtml = htmlToXhtml(sContent, bNeedConvert);
if (oIndexHtml.FromString(xhtml))
{
oIndexHtml.ReadNextNode(); // html
int nDepth = oIndexHtml.GetDepth();

View File

@ -96,9 +96,18 @@ private:
NSStringUtils::CStringBuilder m_oDocXml; // document.xml
NSStringUtils::CStringBuilder m_oNoteXml; // footnotes.xml
NSStringUtils::CStringBuilder m_oNumberXml; // numbering.xml
bool m_bInP; // <w:p> открыт?
bool m_bWasPStyle; // <w:pStyle> записан?
public:
CHtmlFile2_Private() : m_nImageId(1), m_nFootnoteId(1), m_nHyperlinkId(1), m_nCrossId(1), m_nNumberingId(1) {}
CHtmlFile2_Private() : m_nImageId(1), m_nFootnoteId(1), m_nHyperlinkId(1), m_nCrossId(1), m_nNumberingId(1), m_bInP(false), m_bWasPStyle(false)
{
//Установим размер исходного и нового окна для Css калькулятора (должны быть одинаковые единицы измерения (желательно пункты))
//Это нужно для масштабирования некоторых значений
m_oStylesCalculator.SetSizeSourceWindow(NSCSS::CSizeWindow(5000 * (1366 / (8.26667 * m_oStylesCalculator.GetDpi())), 0));
m_oStylesCalculator.SetSizeDeviceWindow(NSCSS::CSizeWindow(5000, 0));
}
~CHtmlFile2_Private()
{
@ -276,7 +285,7 @@ public:
m_oDocXmlRels += L"<Relationship Id=\"rId5\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\" Target=\"theme/theme1.xml\"/>";
m_oDocXmlRels += L"<Relationship Id=\"rId6\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes\" Target=\"footnotes.xml\"/>";
m_oDocXmlRels += L"<Relationship Id=\"rId7\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering\" Target=\"numbering.xml\"/>";
m_oDocXml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\"><w:body><w:p>";
m_oDocXml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\"><w:body>";
m_oNoteXml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:footnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" mc:Ignorable=\"w14 w15 wp14\">";
m_oNoteXml += L"<w:footnote w:type=\"separator\" w:id=\"-1\"><w:p><w:pPr><w:spacing w:lineRule=\"auto\" w:line=\"240\" w:after=\"0\"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type=\"continuationSeparator\" w:id=\"0\"><w:p><w:pPr><w:spacing w:lineRule=\"auto\" w:line=\"240\" w:after=\"0\"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote>";
m_oStylesXml += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:styles xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" mc:Ignorable=\"w14 w15\">";
@ -331,7 +340,9 @@ public:
oRelsWriter.CloseFile();
}
m_oDocXml.WriteString(L"</w:p><w:sectPr/></w:body></w:document>");
if (m_bInP)
m_oDocXml.WriteString(L"</w:p>");
m_oDocXml.WriteString(L"<w:sectPr/></w:body></w:document>");
NSFile::CFileBinary oDocumentWriter;
if (oDocumentWriter.CreateFileW(m_sDst + L"/word/document.xml"))
{
@ -380,10 +391,27 @@ public:
// Конвертирует html в xhtml
bool htmlXhtml(const std::wstring& sSrc)
{
std::string sFileContent;
if(!NSFile::CFileBinary::ReadAllTextUtf8A(sSrc, sFileContent))
BYTE* pData;
DWORD nLength;
if (!NSFile::CFileBinary::ReadAllBytes(sSrc, &pData, nLength))
return false;
std::string sFileContent = XmlUtils::GetUtf8FromFileContent(pData, nLength);
bool bNeedConvert = true;
if (nLength > 4)
{
if (pData[0] == 0xFF && pData[1] == 0xFE && !(pData[2] == 0x00 && pData[3] == 0x00))
bNeedConvert = false;
if (pData[0] == 0xFE && pData[1] == 0xFF)
bNeedConvert = false;
if (pData[0] == 0xFF && pData[1] == 0xFE && pData[2] == 0x00 && pData[3] == 0x00)
bNeedConvert = false;
if (pData[0] == 0 && pData[1] == 0 && pData[2] == 0xFE && pData[3] == 0xFF)
bNeedConvert = false;
}
RELEASEARRAYOBJECTS(pData);
size_t nFind = sFileContent.find("version=\"");
if(nFind != std::string::npos)
{
@ -393,7 +421,7 @@ public:
sFileContent.replace(nFind, nFindEnd - nFind, "1.0");
}
/*
std::wstring sRes = htmlToXhtml(sFileContent);
std::wstring sRes = htmlToXhtml(sFileContent, bNeedConvert);
NSFile::CFileBinary oWriter;
if (oWriter.CreateFileW(m_sTmp + L"/res.html"))
{
@ -401,7 +429,7 @@ public:
oWriter.CloseFile();
}
*/
return m_oLightReader.FromString(htmlToXhtml(sFileContent));
return m_oLightReader.FromString(htmlToXhtml(sFileContent, bNeedConvert));
}
// Конвертирует mht в xhtml
@ -409,7 +437,17 @@ public:
{
std::wstring sExtention = NSFile::GetFileExtention(sSrc);
if(sExtention == L"mht" || sExtention == L"mhtml")
return m_oLightReader.FromString(mhtToXhtml(sSrc));
{
BYTE* pData;
DWORD nLength;
if (!NSFile::CFileBinary::ReadAllBytes(sSrc, &pData, nLength))
return false;
std::string sFileContent = XmlUtils::GetUtf8FromFileContent(pData, nLength);
RELEASEARRAYOBJECTS(pData);
return m_oLightReader.FromString(mhtToXhtml(sFileContent));
}
return htmlXhtml(sSrc);
}
@ -517,8 +555,8 @@ public:
oTree.m_oNode.m_sId = m_oLightReader.GetText();
else if(sNameA == L"style")
oTree.m_oNode.m_sStyle += m_oLightReader.GetText();
else if(sNameA == L"align")
oTree.m_oNode.m_sStyle += L"; text-align: " + m_oLightReader.GetText() + L";";
else
oTree.m_oNode.m_mAttrs[sNameA] = m_oLightReader.GetText();
}
m_oLightReader.MoveToElement();
@ -536,7 +574,7 @@ public:
void PageBreakBefore()
{
m_oDocXml.WriteString(L"<w:pPr><w:pageBreakBefore/></w:pPr>");
m_oDocXml.WriteString(L"<w:p><w:pPr><w:pageBreakBefore/></w:pPr></w:p>");
}
private:
@ -568,8 +606,8 @@ private:
oNode.m_sStyle += m_oLightReader.GetText();
else if(sName == L"title")
sNote = m_oLightReader.GetText();
else if(sName == L"align")
oNode.m_sStyle += L"; text-align: " + m_oLightReader.GetText() + L";";
else
oNode.m_mAttrs[sName] = m_oLightReader.GetText();
}
m_oLightReader.MoveToElement();
sSelectors.push_back(oNode);
@ -617,11 +655,10 @@ private:
m_oDocXml.WriteString(L"\"/>");
*/
bool bWasP = true;
readStream(&m_oDocXml, sSelectors, { false, false, -1, L"", L"" }, bWasP);
readStream(&m_oDocXml, sSelectors, { false, false, -1, L"", L"" });
}
void readInside (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP, const std::wstring& sName)
void readInside (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, const std::wstring& sName)
{
if(sName == L"#text")
{
@ -632,7 +669,7 @@ private:
else if(!(find == 1 && sText.front() == L' '))
sText.erase(0, find);
std::wstring sPStyle = wrP(oXml, sSelectors, oTS, bWasP);
std::wstring sPStyle = wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r>");
std::wstring sRStyle = wrR(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:t xml:space=\"preserve\">");
@ -671,7 +708,6 @@ private:
sText = std::wstring(sText.begin(), end);
oXml->WriteEncodeXmlString(sText);
oXml->WriteString(L"</w:t></w:r>");
bWasP = false;
return;
}
@ -680,14 +716,14 @@ private:
// Ссылка
// Область ссылки
if(sName == L"a" || sName == L"area")
readA(oXml, sSelectors, oTS, bWasP, sNote);
readA(oXml, sSelectors, oTS, sNote);
// Полужирный текст
// Акцентированный текст
else if(sName == L"b" || sName == L"strong")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:b/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Направление текста
else if(sName == L"bdo")
@ -700,26 +736,26 @@ private:
CTextSettings oTSBdo(oTS);
oTSBdo.bBdo = (sDir == L"rtl");
readStream(oXml, sSelectors, oTSBdo, bWasP);
readStream(oXml, sSelectors, oTSBdo);
}
// Отмена направления текста
else if(sName == L"bdi")
{
CTextSettings oTSBdo(oTS);
oTSBdo.bBdo = false;
readStream(oXml, sSelectors, oTSBdo, bWasP);
readStream(oXml, sSelectors, oTSBdo);
}
// Увеличивает размер шрифта
else if(sName == L"big")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:sz w:val=\"26\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Перенос строки
else if(sName == L"br")
{
wrP(oXml, sSelectors, oTS, bWasP);
wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r>");
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors);
if(oStyle.m_pText.GetAlign() == L"both")
@ -730,7 +766,7 @@ private:
{
CTextSettings oTSP(oTS);
oTSP.sPStyle += L"<w:jc w:val=\"center\"/>";
readStream(oXml, sSelectors, oTSP, bWasP);
readStream(oXml, sSelectors, oTSP);
}
// Цитата, обычно выделяется курсивом
// Новый термин, обычно выделяется курсивом
@ -741,7 +777,7 @@ private:
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:i/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Код
// Моноширинный шрифт, например, Consolas
@ -750,14 +786,14 @@ private:
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:rFonts w:ascii=\"Consolas\" w:hAnsi=\"Consolas\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Зачеркнутый текст
else if(sName == L"del" || sName == L"s")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:strike/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
else if(sName == L"font")
{
@ -786,72 +822,73 @@ private:
}
}
m_oLightReader.MoveToElement();
readStream(oXml, sSelectors, oTS, bWasP);
readStream(oXml, sSelectors, oTS);
}
// Картинки
else if(sName == L"img")
readImage(oXml, sSelectors, oTS, bWasP);
readImage(oXml, sSelectors, oTS);
// Подчеркнутый
else if(sName == L"ins" || sName == L"u")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:u w:val=\"single\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Выделенный текст, обычно выделяется желтым
else if(sName == L"mark")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:highlight w:val=\"yellow\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Цитата, выделенная кавычками, обычно выделяется курсивом
else if(sName == L"q")
{
wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r>");
std::wstring sRStyle = wrR(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:t xml:space=\"preserve\">&quot;</w:t></w:r>");
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:i/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r><w:rPr><w:rStyle w:val=\"");
oXml->WriteString(sRStyle);
oXml->WriteString(L"\"/>");
oXml->WriteString(oTS.sRStyle);
oXml->WriteString(L"</w:rPr><w:t xml:space=\"preserve\">&quot;</w:t></w:r>");
bWasP = false;
}
// Текст верхнего регистра
else if(sName == L"rt" || sName == L"sup")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:vertAlign w:val=\"superscript\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Уменьшает размер шрифта
else if(sName == L"small")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:sz w:val=\"18\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Текст нижнего регистра
else if(sName == L"sub")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:vertAlign w:val=\"subscript\"/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Векторная картинка
else if(sName == L"svg" || (sName.length() > 3 && sName.compare(sName.length() - 3, 3, L"svg") == 0))
{
wrP(oXml, sSelectors, oTS);
readSVG(oXml);
bWasP = false;
}
else if(sName == L"input")
readInput(oXml, sSelectors, oTS, bWasP);
readInput(oXml, sSelectors, oTS);
// Игнорируются тэги выполняющие скрипт
else if(sName == L"template" || sName == L"canvas" || sName == L"video" || sName == L"math" || sName == L"rp" ||
sName == L"command" || sName == L"iframe" || sName == L"embed" || sName == L"wbr" || sName == L"audio" ||
@ -866,24 +903,32 @@ private:
sName == L"noscript" || sName == L"output" || sName == L"abbr" || sName == L"time" || sName == L"ruby" ||
sName == L"progress" || sName == L"hgroup" || sName == L"meter" || sName == L"span" ||
sName == L"acronym")
readStream(oXml, sSelectors, oTS, bWasP);
readStream(oXml, sSelectors, oTS);
// С нового абзаца
else
{
wasP(oXml, sSelectors, bWasP);
if (m_bInP)
{
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
m_bInP = false;
}
// Адрес
if(sName == L"address")
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:i/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Определение термина, отступ от левого края
else if(sName == L"dd")
{
CTextSettings oTSP(oTS);
oTSP.sPStyle += L"<w:ind w:left=\"567\"/>";
readStream(oXml, sSelectors, oTSP, bWasP);
readStream(oXml, sSelectors, oTSP);
}
// С нового абзаца
else if(sName == L"article" || sName == L"header" || sName == L"div" || sName == L"blockquote" || sName == L"main" ||
@ -892,20 +937,17 @@ private:
sName == L"section" || sName == L"figure" || sName == L"dl" || sName == L"legend" || sName == L"map" ||
sName == L"dir" ||
sName == L"h1" || sName == L"h2" || sName == L"h3" || sName == L"h4" || sName == L"h5" || sName == L"h6")
readStream(oXml, sSelectors, oTS, bWasP);
readStream(oXml, sSelectors, oTS);
// Горизонтальная линия
else if(sName == L"hr")
{
oXml->WriteString(L"<w:pPr><w:pBdr><w:bottom w:val=\"single\" w:color=\"000000\" w:sz=\"8\" w:space=\"0\"/></w:pBdr></w:pPr>");
bWasP = false;
}
oXml->WriteString(L"<w:p><w:pPr><w:pBdr><w:bottom w:val=\"single\" w:color=\"000000\" w:sz=\"8\" w:space=\"0\"/></w:pBdr></w:pPr></w:p>");
// Меню
// Маркированный список
else if(sName == L"menu" || sName == L"ul" || sName == L"select" || sName == L"datalist")
readLi(oXml, sSelectors, oTS, bWasP, true);
readLi(oXml, sSelectors, oTS, true);
// Нумерованный список
else if(sName == L"ol")
readLi(oXml, sSelectors, oTS, bWasP, false);
readLi(oXml, sSelectors, oTS, false);
// Предварительно форматированный текст
else if(sName == L"pre" || sName == L"xmp")
{
@ -913,48 +955,38 @@ private:
oTSPre.bPre = true;
oTSPre.sRStyle += L"<w:rFonts w:ascii=\"Consolas\" w:hAnsi=\"Consolas\"/>";
oTSPre.sPStyle += L"<w:spacing w:after=\"0\"/>";
readStream(oXml, sSelectors, oTSPre, bWasP);
readStream(oXml, sSelectors, oTSPre);
}
// Таблицы
else if(sName == L"table")
{
size_t nHyp = 0;
for(const NSCSS::CNode& item : sSelectors)
{
if(item.m_sName == L"a")
{
oXml->WriteString(L"</w:hyperlink>");
nHyp++;
}
}
if(bWasP)
oXml->WriteString(L"<w:pPr><w:rPr><w:vanish/></w:rPr></w:pPr>");
oXml->WriteString(L"</w:p>");
readTable(oXml, sSelectors, oTS, bWasP);
oXml->WriteString(L"<w:p>");
for(size_t i = 0; i < nHyp; i++)
oXml->WriteString(L"<w:hyperlink>");
bWasP = true;
}
readTable(oXml, sSelectors, oTS);
// Текст с границами
else if(sName == L"textarea" || sName == L"fieldset")
{
CTextSettings oTSP(oTS);
oTSP.sPStyle += L"<w:pBdr><w:left w:val=\"single\" w:color=\"000000\" w:sz=\"8\" w:space=\"0\"/><w:top w:val=\"single\" w:color=\"000000\" w:sz=\"8\" w:space=\"0\"/><w:right w:val=\"single\" w:color=\"000000\" w:sz=\"8\" w:space=\"0\"/><w:bottom w:val=\"single\" w:color=\"000000\" w:sz=\"8\" w:space=\"0\"/></w:pBdr>";
readStream(oXml, sSelectors, oTSP, bWasP);
readStream(oXml, sSelectors, oTSP);
}
// Неизвестный тэг. Выделять ли его абзацем?
else
readStream(oXml, sSelectors, oTS, bWasP);
readNote(oXml, sNote);
readStream(oXml, sSelectors, oTS);
readNote(oXml, sSelectors, sNote);
sNote = L"";
wasP(oXml, sSelectors, bWasP);
if (m_bInP)
{
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
m_bInP = false;
}
}
readNote(oXml, sNote);
readNote(oXml, sSelectors, sNote);
sSelectors.pop_back();
}
bool readStream (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP)
bool readStream (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
{
int nDeath = m_oLightReader.GetDepth();
if(m_oLightReader.IsEmptyNode() || !m_oLightReader.ReadNextSiblingNode2(nDeath))
@ -962,22 +994,17 @@ private:
do
{
readInside(oXml, sSelectors, oTS, bWasP, m_oLightReader.GetName());
readInside(oXml, sSelectors, oTS, m_oLightReader.GetName());
} while(m_oLightReader.ReadNextSiblingNode2(nDeath));
return true;
}
void readTr (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP, const std::wstring& sBorders)
void readTr (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, const std::wstring& sBorders)
{
std::vector<CTc> mTable;
int nDeath = m_oLightReader.GetDepth();
int i = 1; // Строка
size_t nHyp = 0;
for(const NSCSS::CNode& item : sSelectors)
if(item.m_sName == L"a")
nHyp++;
while(m_oLightReader.ReadNextSiblingNode(nDeath))
{
// tr - строки в таблице
@ -1038,10 +1065,9 @@ private:
oXml->WriteString(L"\"/>");
j += nColspan - 1;
}
oXml->WriteString(L"</w:tcPr><w:p>");
for(size_t i = 0; i < nHyp; i++)
oXml->WriteString(L"<w:hyperlink>");
bWasP = true;
oXml->WriteString(L"</w:tcPr>");
size_t nEmpty = oXml->GetCurSize();
m_bWasPStyle = false;
GetSubClass(oXml, sSelectors);
// Читаем th. Ячейка заголовка таблицы. Выравнивание посередине. Выделяется полужирным
@ -1049,20 +1075,24 @@ private:
{
CTextSettings oTSR(oTS);
oTSR.sRStyle += L"<w:b/>";
readStream(oXml, sSelectors, oTSR, bWasP);
readStream(oXml, sSelectors, oTSR);
}
// Читаем td. Ячейка таблицы. Выравнивание вправо
else if(m_oLightReader.GetName() == L"td")
readStream(oXml, sSelectors, oTS, bWasP);
readStream(oXml, sSelectors, oTS);
sSelectors.pop_back();
for(size_t i = 0; i < nHyp; i++)
oXml->WriteString(L"</w:hyperlink>");
if (bWasP)
if (m_bInP)
{
wrP(oXml, sSelectors, oTS, bWasP);
oXml->WriteString(L"<w:r></w:r>");
wrP(oXml, sSelectors, oTS);
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"<w:r></w:r></w:p>");
m_bInP = false;
}
oXml->WriteString(L"</w:p></w:tc>");
else if (oXml->GetSubData(oXml->GetCurSize() - 6) != L"</w:p>")
oXml->WriteString(L"<w:p></w:p>");
oXml->WriteString(L"</w:tc>");
j++;
// Вставляем ячейки после
@ -1086,39 +1116,44 @@ private:
}
}
void readTable (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP)
void readTable (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
{
if(m_oLightReader.IsEmptyNode())
return;
std::wstring sBorders;
while (m_oLightReader.MoveToNextAttribute())
if (m_oLightReader.GetName() == L"border")
sBorders = L"<w:left w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/><w:top w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/>";
m_oLightReader.MoveToElement();
NSStringUtils::CStringBuilder oHead;
NSStringUtils::CStringBuilder oBody;
NSStringUtils::CStringBuilder oFoot;
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors, false);
if (oXml->GetSubData(oXml->GetCurSize() - 6) != L"</w:p>")
oXml->WriteString(L"<w:p><w:pPr><w:spacing w:line=\"0\"/></w:pPr></w:p>");
// Начало таблицы
oXml->WriteString(L"<w:tbl><w:tblPr><w:tblStyle w:val=\"table\"/><w:tblW w:w=\"0\" w:type=\"auto\"/>");
NSCSS::CNode oLast = sSelectors.back();
sSelectors.pop_back();
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors);
std::wstring sAlign = oStyle.m_pText.GetAlign();
if(sAlign == L"left" || sAlign == L"center" || sAlign == L"right" || sAlign == L"both")
oXml->WriteString(L"<w:jc w:val=\"" + sAlign + L"\"/>");
oXml->WriteString(L"</w:tblPr>");
sSelectors.push_back(oLast);
std::wstring wsTable = L"<w:tbl><w:tblPr>";
std::wstring wsWidth = oStyle.m_pDisplay.GetWidthW();
std::wstring wsAlign = oStyle.m_pDisplay.GetAlign();
if (!wsWidth.empty())
wsTable += L"<w:tblW w:w=\"" + wsWidth + L"\" w:type=\"pct\"/>";
else if (m_oStylesCalculator.GetSizeDeviceWindow().m_ushWidth != 0)
wsTable += L"<w:tblW w:w=\"" + std::to_wstring(m_oStylesCalculator.GetSizeDeviceWindow().m_ushWidth) + L"\" w:type=\"pct\"/>";
else
wsTable += L"<w:tblW w:w=\"0\" w:type=\"auto\"/>";
if (!wsAlign.empty())
wsTable += L"<w:jc w:val=\"" + wsAlign + L"\"/>";
wsTable += L"</w:tblPr>";
// borders
oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors, true);
std::wstring sBorders;
oStyle.m_pBorder.Unlock();
if (oStyle.m_pBorder.Empty())
{
sBorders = L"<w:left w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/><w:top w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\" w:color=\"000000\" w:sz=\"4\" w:space=\"0\"/>";
sBorders = L"<w:left w:val=\"none\" w:sz=\"4\" w:color=\"auto\" w:space=\"0\"/><w:top w:val=\"none\" w:sz=\"4\" w:color=\"auto\" w:space=\"0\"/><w:right w:val=\"none\" w:sz=\"4\" w:color=\"auto\" w:space=\"0\"/><w:bottom w:val=\"none\" w:color=\"auto\" w:sz=\"4\" w:space=\"0\"/>";
}
else
{
@ -1126,31 +1161,40 @@ private:
{
std::wstring sColor = oStyle.m_pBorder.GetColorBottomSide();
std::wstring sSz = oStyle.m_pBorder.GetWidthBottomSideW();
sBorders = L"<w:top w:val=\"single\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:left w:val=\"single\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:bottom w:val=\"single\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:right w:val=\"single\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:insideH w:val=\"single\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:insideV w:val=\"single\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>";
std::wstring sStyle = oStyle.m_pBorder.GetStyleBottomSide();
sBorders = L"<w:top w:val=\"" + sStyle + L"\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:left w:val=\"" + sStyle + L"\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:bottom w:val=\"" + sStyle + L"\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:right w:val=\"" + sStyle + L"\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:insideH w:val=\"" + sStyle + L"\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>" +
L"<w:insideV w:val=\"" + sStyle + L"\" w:color=\"" + sColor + L"\" w:sz=\"" + sSz + L"\" w:space=\"0\"/>";
}
else
{
std::wstring sColorLeftSide = oStyle.m_pBorder.GetColorLeftSide();
std::wstring sSzLeftSide = oStyle.m_pBorder.GetWidthLeftSideW();
std::wstring sStyleLeftSide = oStyle.m_pBorder.GetStyleLeftSide();
std::wstring sColorTopSide = oStyle.m_pBorder.GetColorTopSide();
std::wstring sSzTopSide = oStyle.m_pBorder.GetWidthTopSideW();
std::wstring sStyleTopSide = oStyle.m_pBorder.GetStyleLeftSide();
std::wstring sColorRightSide = oStyle.m_pBorder.GetColorRightSide();
std::wstring sSzRightSide = oStyle.m_pBorder.GetWidthRightSideW();
std::wstring sStyleRightSide = oStyle.m_pBorder.GetStyleLeftSide();
std::wstring sColorBottomSide = oStyle.m_pBorder.GetColorBottomSide();
std::wstring sSzBottomSide = oStyle.m_pBorder.GetWidthBottomSideW();
std::wstring sStyleBottomSide = oStyle.m_pBorder.GetStyleLeftSide();
sBorders = L"<w:left w:val=\"single\" w:color=\"" + sColorLeftSide + L"\" w:sz=\"" + sSzLeftSide + L"\" w:space=\"0\"/>" +
L"<w:top w:val=\"single\" w:color=\"" + sColorTopSide + L"\" w:sz=\"" + sSzTopSide + L"\" w:space=\"0\"/>" +
L"<w:right w:val=\"single\" w:color=\"" + sColorRightSide + L"\" w:sz=\"" + sSzRightSide + L"\" w:space=\"0\"/>" +
L"<w:bottom w:val=\"single\" w:color=\""+ sColorBottomSide + L"\" w:sz=\"" + sSzBottomSide + L"\" w:space=\"0\"/>";
sBorders = L"<w:left w:val=\"" + sStyleLeftSide + L"\" w:color=\"" + sColorLeftSide + L"\" w:sz=\"" + sSzLeftSide + L"\" w:space=\"0\"/>" +
L"<w:top w:val=\"" + sStyleTopSide + L"\" w:color=\"" + sColorTopSide + L"\" w:sz=\"" + sSzTopSide + L"\" w:space=\"0\"/>" +
L"<w:right w:val=\"" + sStyleRightSide + L"\" w:color=\"" + sColorRightSide + L"\" w:sz=\"" + sSzRightSide + L"\" w:space=\"0\"/>" +
L"<w:bottom w:val=\"" + sStyleBottomSide + L"\" w:color=\"" + sColorBottomSide + L"\" w:sz=\"" + sSzBottomSide + L"\" w:space=\"0\"/>";
}
}
oXml->WriteString(wsTable);
/*
NSCSS::CCompiledStyle oStyleSetting = m_oStylesCalculator.GetCompiledStyle(sSelectors, true);
oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors);
@ -1186,30 +1230,39 @@ private:
// Заголовок таблицы
if(sName == L"caption")
{
bWasP = true;
oXml->WriteString(L"<w:p>");
size_t nHyp = 0;
for(const NSCSS::CNode& item : sSelectors)
if (!m_bInP)
{
if(item.m_sName == L"a")
oXml->WriteString(L"<w:p>");
for (const NSCSS::CNode& item : sSelectors)
{
oXml->WriteString(L"<w:hyperlink>");
nHyp++;
if (item.m_sName == L"a")
{
oXml->WriteString(L"<w:hyperlink>");
nHyp++;
}
}
m_bInP = true;
m_bWasPStyle = false;
}
// Заголовок таблицы выравнивание посередине
CTextSettings oTSP { oTS.bBdo, oTS.bPre, oTS.nLi, oTS.sRStyle, oTS.sPStyle + L"<w:jc w:val=\"center\"/>" };
readStream(oXml, sSelectors, oTSP, bWasP);
for(size_t i = 0; i < nHyp; i++)
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
bWasP = false;
readStream(oXml, sSelectors, oTSP);
if (m_bInP)
{
for (size_t i = 0; i < nHyp; i++)
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
m_bInP = false;
m_bWasPStyle = false;
}
}
if(sName == L"thead")
readTr(&oHead, sSelectors, oTS, bWasP, sBorders);
readTr(&oHead, sSelectors, oTS, sBorders);
else if(sName == L"tbody")
readTr(&oBody, sSelectors, oTS, bWasP, sBorders);
readTr(&oBody, sSelectors, oTS, sBorders);
else if(sName == L"tfoot")
readTr(&oFoot, sSelectors, oTS, bWasP, sBorders);
readTr(&oFoot, sSelectors, oTS, sBorders);
sSelectors.pop_back();
}
@ -1218,12 +1271,9 @@ private:
oXml->WriteString(oBody.GetData());
oXml->WriteString(oFoot.GetData());
oXml->WriteString(L"</w:tbl>");
// Пустая строка после таблицы, чтобы следующий текст не приклеивался
// oXml->WriteString(L"<w:p></w:p>");
bWasP = false;
}
void readInput (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP)
void readInput (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
{
std::wstring sValue;
std::wstring sAlt;
@ -1245,17 +1295,17 @@ private:
sValue = sAlt;
if(!sValue.empty())
{
wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r>");
wrR(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:t xml:space=\"preserve\">");
oXml->WriteEncodeXmlString(sValue + L' ');
oXml->WriteString(L"</w:t></w:r>");
bWasP = false;
}
readStream(oXml, sSelectors, oTS, bWasP);
readStream(oXml, sSelectors, oTS);
}
void readLi (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP, bool bType)
void readLi (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool bType)
{
if(m_oLightReader.IsEmptyNode())
return;
@ -1277,23 +1327,28 @@ private:
{
if(m_oLightReader.GetName() != L"label")
continue;
wasP(oXml, sSelectors, bWasP);
wrP(oXml, sSelectors, oTS, bWasP);
if (m_bInP)
{
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
m_bInP = false;
}
wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r>");
wrR(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:t xml:space=\"preserve\">");
oXml->WriteEncodeXmlString(m_oLightReader.GetText());
oXml->WriteString(L"</w:t></w:r>");
bWasP = false;
wasP(oXml, sSelectors, bWasP);
}
m_oLightReader.MoveToElement();
readLi(oXml, sSelectors, oTS, bWasP, true);
readLi(oXml, sSelectors, oTS, true);
continue;
}
if(sName != L"li" && sName != L"option")
{
readInside(oXml, sSelectors, oTS, bWasP, sName);
readInside(oXml, sSelectors, oTS, sName);
sSelectors.pop_back();
continue;
}
@ -1303,13 +1358,27 @@ private:
sStart = m_oLightReader.GetText();
m_oLightReader.MoveToElement();
wasP(oXml, sSelectors, bWasP);
if (m_bInP)
{
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
m_bInP = false;
}
CTextSettings oTSLiP(oTS);
oTSLiP.nLi++;
oTSLiP.sPStyle += L"<w:numPr><w:ilvl w:val=\"" + std::to_wstring(oTSLiP.nLi) + L"\"/><w:numId w:val=\"" +
(bType ? L"1" : std::to_wstring(m_nNumberingId + 1)) + L"\"/></w:numPr>";
readStream(oXml, sSelectors, oTSLiP, bWasP);
wasP(oXml, sSelectors, bWasP);
readStream(oXml, sSelectors, oTSLiP);
if (m_bInP)
{
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"</w:hyperlink>");
oXml->WriteString(L"</w:p>");
m_bInP = false;
}
sSelectors.pop_back();
}
// Нумерованный список
@ -1339,7 +1408,7 @@ private:
}
}
void readA (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP, std::wstring& sNote)
void readA (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, std::wstring& sNote)
{
std::wstring sRef;
std::wstring sAlt;
@ -1371,7 +1440,16 @@ private:
if(sNote.empty())
sNote = sRef;
wrP(oXml, sSelectors, oTS, bWasP);
if (!m_bInP)
{
oXml->WriteString(L"<w:p>");
for (size_t i = 0; i < sSelectors.size() - 1; i++)
if (sSelectors[i].m_sName == L"a")
oXml->WriteString(L"<w:hyperlink>");
m_bInP = true;
m_bWasPStyle = false;
}
wrP(oXml, sSelectors, oTS);
// Перекрестная ссылка внутри файла
if(bCross)
{
@ -1400,7 +1478,7 @@ private:
}
oXml->WriteString(L"\">");
if(!readStream(oXml, sSelectors, oTS, bWasP))
if(!readStream(oXml, sSelectors, oTS))
{
oXml->WriteString(L"<w:r>");
wrR(oXml, sSelectors, oTS);
@ -1408,12 +1486,12 @@ private:
oXml->WriteEncodeXmlString(sAlt);
oXml->WriteString(L"</w:t></w:r>");
}
oXml->WriteString(L"</w:hyperlink>");
bWasP = false;
if (m_bInP)
oXml->WriteString(L"</w:hyperlink>");
sNote = L"";
}
void readImage (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP)
void readImage (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
{
std::wstring sAlt = L"";
bool bRes = false;
@ -1501,7 +1579,7 @@ private:
}
if(bRes)
{
wrP(oXml, sSelectors, oTS, bWasP);
wrP(oXml, sSelectors, oTS);
bRes = ImageRels(oXml, sImageId, L"i" + sImageName);
}
}
@ -1509,19 +1587,27 @@ private:
if(!bRes)
{
wrP(oXml, sSelectors, oTS, bWasP);
wrP(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:r>");
wrR(oXml, sSelectors, oTS);
oXml->WriteString(L"<w:t xml:space=\"preserve\">");
oXml->WriteEncodeXmlString(sAlt);
oXml->WriteString(L"</w:t></w:r>");
}
bWasP = false;
}
std::wstring wrP(NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS, bool& bWasP)
std::wstring wrP(NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
{
if(!bWasP)
if (!m_bInP)
{
oXml->WriteString(L"<w:p>");
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"<w:hyperlink>");
m_bInP = true;
m_bWasPStyle = false;
}
if (m_bWasPStyle)
return L"";
oXml->WriteString(L"<w:pPr><w:pStyle w:val=\"");
@ -1551,7 +1637,7 @@ private:
for(int i = temporary.size() - 1; i >= 0; i--)
sSelectors.insert(sSelectors.begin() + temporary[i].first, temporary[i].second);
// Если в таблице
// Если в таблице, то игнориуются Paragraph Borders
bool bInTable = false;
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"table")
@ -1571,12 +1657,15 @@ private:
oXml->WriteString(L"\"/>");
oXml->WriteString(oTS.sPStyle + L' ' + sPSettings);
oXml->WriteString(L"</w:pPr>");
bWasP = false;
m_bWasPStyle = true;
return sPStyle;
}
std::wstring wrR(NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const CTextSettings& oTS)
{
if (!m_bInP)
return L"";
NSCSS::CCompiledStyle oStyleSetting = m_oStylesCalculator.GetCompiledStyle(sSelectors, true);
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors);
@ -1597,25 +1686,6 @@ private:
return sRStyle;
}
void wasP (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, bool& bWasP)
{
if(bWasP)
return;
size_t nHyp = 0;
for(const NSCSS::CNode& item : sSelectors)
{
if(item.m_sName == L"a")
{
oXml->WriteString(L"</w:hyperlink>");
nHyp++;
}
}
oXml->WriteString(L"</w:p><w:p>");
for(size_t i = 0; i < nHyp; i++)
oXml->WriteString(L"<w:hyperlink>");
bWasP = true;
}
bool ImageRels (NSStringUtils::CStringBuilder* oXml, const std::wstring& sImageId, const std::wstring& sImageName)
{
CBgraFrame oBgraFrame;
@ -1674,10 +1744,19 @@ private:
return true;
}
void readNote (NSStringUtils::CStringBuilder* oXml, const std::wstring& sNote)
void readNote (NSStringUtils::CStringBuilder* oXml, std::vector<NSCSS::CNode>& sSelectors, const std::wstring& sNote)
{
if(sNote.empty())
return;
if (!m_bInP)
{
oXml->WriteString(L"<w:p>");
for (const NSCSS::CNode& item : sSelectors)
if (item.m_sName == L"a")
oXml->WriteString(L"<w:hyperlink>");
m_bInP = true;
m_bWasPStyle = false;
}
oXml->WriteString(L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr><w:footnoteReference w:id=\"");
oXml->WriteString(std::to_wstring(m_nFootnoteId));
oXml->WriteString(L"\"/></w:r>");

View File

@ -16,7 +16,7 @@ void getDirectories(const std::wstring& sDirectory, std::vector<std::wstring>& a
int main()
{
bool bBatchMode = false;
bool bMhtMode = true;
bool bMhtMode = false;
if(bBatchMode)
{
// Директория файлов
@ -97,7 +97,7 @@ int main()
oParams.SetDescription(L"Description");
// Файл, который открываем
std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/test.mht";
std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/test.html";
CHtmlFile2 oFile;
oFile.SetTmpDirectory(sOutputDirectory);
nResConvert = (bMhtMode ? oFile.OpenMht(sFile, sOutputDirectory, &oParams) : oFile.OpenHtml(sFile, sOutputDirectory, &oParams));

View File

@ -52,6 +52,7 @@
#include "../DesktopEditor/graphics/pro/Image.h"
#include "../UnicodeConverter/UnicodeConverter.h"
#include "../Common/Network/FileTransporter/include/FileTransporter.h"
#include "OnlineOfficeBinToPdf.h"
@ -1223,8 +1224,22 @@ HRESULT CPdfRenderer::DrawPath(const LONG& lType)
if (bStroke)
UpdatePen();
std::wstring sTextureOldPath = L"";
std::wstring sTextureTmpPath = L"";
if (bFill || bEoFill)
{
if (c_BrushTypeTexture == m_oBrush.GetType())
{
sTextureOldPath = m_oBrush.GetTexturePath();
sTextureTmpPath = GetDownloadFile(sTextureOldPath);
if (!sTextureTmpPath.empty())
m_oBrush.SetTexturePath(sTextureTmpPath);
}
UpdateBrush();
}
if (!m_pShading)
{
@ -1250,6 +1265,14 @@ HRESULT CPdfRenderer::DrawPath(const LONG& lType)
m_pPage->GrRestore();
if (!sTextureTmpPath.empty())
{
m_oBrush.SetTexturePath(sTextureOldPath);
if (NSFile::CFileBinary::Exists(sTextureTmpPath))
NSFile::CFileBinary::Remove(sTextureTmpPath);
}
return S_OK;
}
HRESULT CPdfRenderer::PathCommandMoveTo(const double& dX, const double& dY)
@ -1397,13 +1420,16 @@ HRESULT CPdfRenderer::DrawImage(IGrObject* pImage, const double& dX, const doubl
return S_OK;
}
HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePathSrc, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
{
m_oCommandManager.Flush();
if (!IsPageValid())
return S_OK;
std::wstring sTempImagePath = GetDownloadFile(wsImagePathSrc);
std::wstring wsImagePath = sTempImagePath.empty() ? wsImagePathSrc : sTempImagePath;
Aggplus::CImage* pAggImage = NULL;
CImageFileFormatChecker oImageFormat(wsImagePath);
@ -1429,18 +1455,17 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d
pAggImage = new Aggplus::CImage(wsImagePath);
}
if (!pAggImage)
return S_FALSE;
HRESULT hRes = S_OK;
if (!pAggImage || !DrawImage(pAggImage, dX, dY, dW, dH, nAlpha))
hRes = S_FALSE;
if (!DrawImage(pAggImage, dX, dY, dW, dH, nAlpha))
{
if (NSFile::CFileBinary::Exists(sTempImagePath))
NSFile::CFileBinary::Remove(sTempImagePath);
if (pAggImage)
delete pAggImage;
return S_FALSE;
}
delete pAggImage;
return S_OK;
return hRes;
}
//----------------------------------------------------------------------------------------
// Функции для выставления преобразования
@ -2747,3 +2772,37 @@ void CPdfRenderer::SetError()
{
m_bValid = false;
}
std::wstring CPdfRenderer::GetDownloadFile(const std::wstring& sUrl)
{
std::wstring::size_type n1 = sUrl.find(L"www.");
std::wstring::size_type n2 = sUrl.find(L"http://");
std::wstring::size_type n3 = sUrl.find(L"ftp://");
std::wstring::size_type n4 = sUrl.find(L"https://");
std::wstring::size_type nMax = 3;
bool bIsNeedDownload = false;
if (n1 != std::wstring::npos && n1 < nMax)
bIsNeedDownload = true;
else if (n2 != std::wstring::npos && n2 < nMax)
bIsNeedDownload = true;
else if (n3 != std::wstring::npos && n3 < nMax)
bIsNeedDownload = true;
else if (n4 != std::wstring::npos && n4 < nMax)
bIsNeedDownload = true;
if (!bIsNeedDownload)
return L"";
std::wstring sTempFile = GetTempFile();
NSNetwork::NSFileTransport::CFileDownloader oDownloader(sUrl, false);
oDownloader.SetFilePath(sTempFile);
if (oDownloader.DownloadSync())
return sTempFile;
if (NSFile::CFileBinary::Exists(sTempFile))
NSFile::CFileBinary::Remove(sTempFile);
return L"";
}

View File

@ -242,10 +242,11 @@ private:
void UpdateTransform();
void UpdatePen();
void UpdateBrush();
bool IsValid();
bool IsPageValid();
void SetError();
bool IsValid();
bool IsPageValid();
void SetError();
void AddLink(const unsigned int& unPage, const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const unsigned int& unDestPage);
std::wstring GetDownloadFile(const std::wstring& sUrl);
private:

View File

@ -15,7 +15,7 @@ include(../Common/base.pri)
DEFINES += PDFWRITER_USE_DYNAMIC_LIBRARY
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter)
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
DEFINES += CRYPTOPP_DISABLE_ASM
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib