mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba0359e3d1 | |||
| fbf77242de | |||
| 54b3fc1866 | |||
| e49f1a481c | |||
| 76bcd744e0 | |||
| 1f9078d5fb | |||
| 68e5ceb928 | |||
| b6ec92a557 | |||
| eae4921ccd | |||
| 3ab0a4ee5e | |||
| 6438c9a88a | |||
| 302b575f29 | |||
| e1c87770bd | |||
| b5d9d81704 | |||
| dc92a8c07f | |||
| c3bddd9e5d | |||
| 7e5421862b | |||
| 599e2d0d8b | |||
| 964c75126e | |||
| 170686840c | |||
| 89a787fc32 | |||
| 56bec09bfd | |||
| 341d7a0b55 | |||
| c549d52123 | |||
| 8c69e55bdd | |||
| 77a07b09a5 | |||
| 282a6b50a5 | |||
| 02fe14ffe3 | |||
| 0c1659cf48 | |||
| 1627332a20 | |||
| 23d0b0e194 | |||
| 2f11ac944d | |||
| 0be13c04ce | |||
| 0cdbdefeb2 | |||
| 7f863a7b6a | |||
| d8cbbf4c2f | |||
| 9bee310052 | |||
| f76ede5078 |
@ -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());
|
||||
|
||||
|
||||
@ -172,13 +172,13 @@ void pptx_text_context::Impl::start_paragraph(const std::wstring & styleName)
|
||||
{
|
||||
if (paragraphs_cout_++ > 0)
|
||||
{
|
||||
if (in_list_ == false || in_comment == true)
|
||||
{
|
||||
// конец предыдущего абзаца и начало следующего
|
||||
//text_ << L" ";
|
||||
text_ << L"\n";
|
||||
}
|
||||
else/* (paragraph_style_name_ != styleName)*/
|
||||
//if (in_list_ == false || in_comment == true)
|
||||
//{
|
||||
//// конец предыдущего абзаца и начало следующего
|
||||
////text_ << L" ";
|
||||
// text_ << L"\n";
|
||||
//}
|
||||
//else/* (paragraph_style_name_ != styleName)*/
|
||||
{
|
||||
dump_paragraph();
|
||||
}
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -230,22 +230,30 @@ namespace NSCSS
|
||||
}
|
||||
CASE(L"line-height"):
|
||||
{
|
||||
size_t unCoefficient = 1;
|
||||
double dCoefficient = 1;
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
const size_t unPositionSymbol = pPropertie.second.find_first_of(L"abcdefghijklmnopqrstuvwxyz%");
|
||||
|
||||
if (unPositionSymbol == std::wstring::npos)
|
||||
unCoefficient = m_pFont.GetSize();
|
||||
dCoefficient = m_pFont.GetSize();
|
||||
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
{
|
||||
const float fValue = wcstof(ConvertUnitMeasure(pPropertie.second, m_pFont.GetSize()).c_str(), NULL);
|
||||
m_pFont.SetLineHeight(std::to_wstring(fValue * unCoefficient), unLevel, bHardMode);
|
||||
float fValue = wcstof(ConvertUnitMeasure(pPropertie.second, m_pFont.GetSize()).c_str(), NULL);
|
||||
|
||||
if (m_pFont.GetSize() == fValue || bIsThereBorder)
|
||||
fValue *= 1.2;
|
||||
|
||||
m_pFont.SetLineHeight(std::to_wstring(fValue * dCoefficient), unLevel, bHardMode);
|
||||
}
|
||||
else if (unPositionImp != 0)
|
||||
{
|
||||
const float fValue = wcstof(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), m_pFont.GetSize()).c_str(), NULL);
|
||||
m_pFont.SetLineHeight(std::to_wstring(fValue * unCoefficient), unLevel, true);
|
||||
float fValue = wcstof(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), m_pFont.GetSize()).c_str(), NULL);
|
||||
|
||||
if (m_pFont.GetSize() == fValue || bIsThereBorder)
|
||||
fValue *= 1.2;
|
||||
|
||||
m_pFont.SetLineHeight(std::to_wstring(fValue * dCoefficient), unLevel, true);
|
||||
m_pFont.SetImportantenLineHeight(true);
|
||||
}
|
||||
break;
|
||||
@ -368,32 +376,52 @@ namespace NSCSS
|
||||
CASE(L"padding"):
|
||||
CASE(L"mso-padding-alt"):
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
break;
|
||||
// if (bIsThereBorder)
|
||||
// break;
|
||||
|
||||
bool bMarginPermission = m_pMargin.GetPermission();
|
||||
|
||||
m_pMargin.SetPermission(true);
|
||||
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
{
|
||||
const std::wstring sValue = ConvertUnitMeasure(pPropertie.second, 540.0f, ScalingDirectionX);
|
||||
if (sValue.find_first_not_of(L" 0") != std::wstring::npos)
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
m_pMargin.AddMargin(L"0", 0, true);
|
||||
|
||||
m_pMargin.AddMargin(sValue, unLevel, bHardMode);
|
||||
}
|
||||
}
|
||||
else if (unPositionImp != 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
m_pMargin.AddMargin(L"0", 0, true);
|
||||
|
||||
m_pMargin.AddMargin(sValue, unLevel, true);
|
||||
}
|
||||
|
||||
m_pMargin.SetImportantAll(true);
|
||||
}
|
||||
|
||||
m_pMargin.SetPermission(bMarginPermission);
|
||||
|
||||
break;
|
||||
}
|
||||
CASE(L"padding-top"):
|
||||
CASE(L"mso-padding-top-alt"):
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
break;
|
||||
// if (bIsThereBorder)
|
||||
// break;
|
||||
|
||||
bool bMarginPermission = m_pMargin.GetPermission();
|
||||
|
||||
m_pMargin.SetPermission(true);
|
||||
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
@ -411,14 +439,18 @@ namespace NSCSS
|
||||
m_pMargin.SetImportantTopSide(true);
|
||||
}
|
||||
|
||||
m_pMargin.SetPermission(bMarginPermission);
|
||||
|
||||
break;
|
||||
}
|
||||
CASE(L"padding-right"):
|
||||
CASE(L"mso-padding-right-alt"):
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
break;
|
||||
// if (bIsThereBorder)
|
||||
// break;
|
||||
bool bMarginPermission = m_pMargin.GetPermission();
|
||||
|
||||
m_pMargin.SetPermission(true);
|
||||
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
@ -436,13 +468,19 @@ namespace NSCSS
|
||||
m_pMargin.SetImportantRightSide(true);
|
||||
}
|
||||
|
||||
m_pMargin.SetPermission(bMarginPermission);
|
||||
|
||||
break;
|
||||
}
|
||||
CASE(L"padding-bottom"):
|
||||
CASE(L"mso-padding-bottom-alt"):
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
break;
|
||||
// if (bIsThereBorder)
|
||||
// break;
|
||||
|
||||
bool bMarginPermission = m_pMargin.GetPermission();
|
||||
|
||||
m_pMargin.SetPermission(true);
|
||||
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
@ -460,13 +498,20 @@ namespace NSCSS
|
||||
m_pMargin.SetImportantBottomSide(true);
|
||||
}
|
||||
|
||||
m_pMargin.SetPermission(bMarginPermission);
|
||||
|
||||
break;
|
||||
}
|
||||
CASE(L"padding-left"):
|
||||
CASE(L"mso-padding-left-alt"):
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
break;
|
||||
// if (bIsThereBorder)
|
||||
// break;
|
||||
|
||||
bool bMarginPermission = m_pMargin.GetPermission();
|
||||
|
||||
m_pMargin.SetPermission(true);
|
||||
|
||||
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
@ -484,6 +529,8 @@ namespace NSCSS
|
||||
m_pMargin.SetImportantLeftSide(true);
|
||||
}
|
||||
|
||||
m_pMargin.SetPermission(bMarginPermission);
|
||||
|
||||
break;
|
||||
}
|
||||
// TEXT
|
||||
@ -953,34 +1000,37 @@ namespace NSCSS
|
||||
//OTHER
|
||||
CASE(L"width"):
|
||||
{
|
||||
if (bIsThereBorder)
|
||||
break;
|
||||
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
|
||||
int nParentValue = m_pDisplay.GetWidth();
|
||||
|
||||
if (0 >= nParentValue)
|
||||
nParentValue = m_oDeviceWindow.m_ushWidth;
|
||||
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
{
|
||||
m_pDisplay.SetWidth(ConvertUnitMeasure(pPropertie.second, m_oDeviceWindow.m_ushWidth, ScalingDirectionX), unLevel, bHardMode);
|
||||
m_pDisplay.SetWidth(ConvertUnitMeasure(pPropertie.second, nParentValue, 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.SetWidth(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), nParentValue, ScalingDirectionX), unLevel, true);
|
||||
m_pDisplay.SetImportantWidth(true);
|
||||
}
|
||||
|
||||
// std::wstring wsWidth;
|
||||
|
||||
|
||||
|
||||
// if (unPositionImp == std::wstring::npos)
|
||||
// wsWidth = pPropertie.second;
|
||||
// else
|
||||
// wsWidth = pPropertie.second.substr(0, unPositionImp - 1);
|
||||
|
||||
// wsWidth = ConvertUnitMeasure(wsWidth, m_oDeviceWindow.m_ushWidth, ScalingDirectionX);
|
||||
// int nWidth = std::stoi(wsWidth);
|
||||
|
||||
// if (m_oDeviceWindow.m_ushWidth != nWidth)
|
||||
// m_pDisplay.SetWidth(m_oDeviceWindow.m_ushWidth - nWidth, unLevel);
|
||||
break;
|
||||
}
|
||||
CASE(L"height"):
|
||||
{
|
||||
const size_t unPositionImp = pPropertie.second.find(L"!i");
|
||||
if (unPositionImp == std::wstring::npos)
|
||||
{
|
||||
m_pDisplay.SetHeight(ConvertUnitMeasure(pPropertie.second, m_oDeviceWindow.m_ushWidth, ScalingDirectionY), unLevel, bHardMode);
|
||||
}
|
||||
else if (unPositionImp != 0)
|
||||
{
|
||||
m_pDisplay.SetHeight(ConvertUnitMeasure(pPropertie.second.substr(0, unPositionImp - 1), m_oDeviceWindow.m_ushWidth, ScalingDirectionY), unLevel, true);
|
||||
m_pDisplay.SetImportantHeight(true);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -1008,11 +1058,12 @@ namespace NSCSS
|
||||
if (sStyle.empty())
|
||||
return;
|
||||
|
||||
const std::vector<std::wstring> arWords = NS_STATIC_FUNCTIONS::GetWordsWithSigns(sStyle, L" :;");
|
||||
const std::vector<std::wstring> arWords = NS_STATIC_FUNCTIONS::GetWordsWithSigns(sStyle, L":;");
|
||||
|
||||
std::wstring sProperty, sValue;
|
||||
|
||||
for (std::vector<std::wstring>::const_iterator iWord = arWords.begin(); iWord != arWords.end(); ++iWord)
|
||||
{
|
||||
if ((*iWord).back() == L':')
|
||||
{
|
||||
sProperty = *iWord;
|
||||
@ -1021,9 +1072,15 @@ namespace NSCSS
|
||||
else
|
||||
{
|
||||
sValue += *iWord;
|
||||
if ((*iWord).back() == L';')
|
||||
|
||||
if (L' ' == sValue.front())
|
||||
sValue.erase(0, 1);
|
||||
|
||||
if (!sValue.empty() && ((*iWord).back() == L';' || iWord == (arWords.end() - 1)))
|
||||
{
|
||||
sValue.pop_back();
|
||||
if (sValue.back() == L';')
|
||||
sValue.pop_back();
|
||||
|
||||
std::transform(sProperty.begin(), sProperty.end(), sProperty.begin(), tolower);
|
||||
std::transform(sValue.begin(), sValue.end(), sValue.begin(), tolower);
|
||||
AddPropSel(sProperty, sValue, unLevel, bHardMode);
|
||||
@ -1031,6 +1088,7 @@ namespace NSCSS
|
||||
sValue.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!sProperty.empty() && !sValue.empty())
|
||||
AddPropSel(sProperty, sValue, bHardMode);
|
||||
@ -1153,7 +1211,7 @@ namespace NSCSS
|
||||
sValueString += L' ';
|
||||
}
|
||||
else if (sValueTemp.find(L"in") != std::wstring::npos)
|
||||
{
|
||||
{
|
||||
int nValue = ConvertIn(sValueTemp);
|
||||
|
||||
Scale(nValue, enScalingDirection);
|
||||
@ -1289,7 +1347,6 @@ namespace NSCSS
|
||||
|
||||
inline int CCompiledStyle::ConvertPxToPc(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(0.16667f / static_cast<float>(m_nDpi) * dValue + 0.5f);
|
||||
}
|
||||
|
||||
@ -1385,7 +1442,6 @@ namespace NSCSS
|
||||
|
||||
inline int CCompiledStyle::ConvertMmToCm(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(dValue / 10.0f + 0.5f);
|
||||
}
|
||||
|
||||
@ -1396,13 +1452,11 @@ namespace NSCSS
|
||||
|
||||
inline int CCompiledStyle::ConvertMmToPt(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(0.23262f * dValue + 0.5f);
|
||||
}
|
||||
|
||||
inline int CCompiledStyle::ConvertMmToPx(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(static_cast<float>(m_nDpi) / 25.4f * dValue + 0.5f);
|
||||
}
|
||||
|
||||
@ -1440,19 +1494,16 @@ namespace NSCSS
|
||||
|
||||
inline int CCompiledStyle::ConvertInToCm(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(dValue * 2.54f + 0.5f);
|
||||
}
|
||||
|
||||
inline int CCompiledStyle::ConvertInToPc(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(dValue / 72.0f + 0.5f);
|
||||
}
|
||||
|
||||
inline int CCompiledStyle::ConvertInToPt(const float& dValue) const
|
||||
{
|
||||
|
||||
return static_cast<int>(dValue / 6.0f + 0.5f);
|
||||
}
|
||||
|
||||
@ -1475,7 +1526,7 @@ namespace NSCSS
|
||||
return ConvertPtToPx(dValue);
|
||||
case Default:
|
||||
case Point:
|
||||
return static_cast<int>(dValue + 0.5f);
|
||||
return static_cast<int>(dValue + 0.5f);
|
||||
case Cantimeter:
|
||||
return ConvertPtToCm(dValue);
|
||||
case Millimeter:
|
||||
|
||||
@ -509,11 +509,16 @@ namespace NSCSS
|
||||
|
||||
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_sStyle});
|
||||
|
||||
if(oFindCountStyle != m_mStatictics->end())
|
||||
if (oFindCountStyle != m_mStatictics->end())
|
||||
{
|
||||
if ((bIsSettings && oFindCountStyle->second < MaxNumberRepetitions) ||
|
||||
(!bIsSettings && oFindCountStyle->second >= MaxNumberRepetitions))
|
||||
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
|
||||
|
||||
else if (!bIsSettings)
|
||||
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
|
||||
}
|
||||
else if (bIsSettings)
|
||||
pStyle->AddStyle(arSelectors[i].m_sStyle, i + 1, true);
|
||||
}
|
||||
|
||||
if (!bIsSettings)
|
||||
|
||||
@ -306,7 +306,7 @@ namespace NSCSS
|
||||
|
||||
public:
|
||||
|
||||
Font() : fSize (fNoneValue),
|
||||
Font() : fSize (24.0f),
|
||||
enStretch (FontStretch::none),
|
||||
enStyle (FontStyle::none),
|
||||
enVariant (FontVariant::none),
|
||||
@ -886,11 +886,14 @@ namespace NSCSS
|
||||
|
||||
void SetLineHeight(const std::wstring &sLineHeight, const unsigned int& unLevel, const bool& bHardMode = false)
|
||||
{
|
||||
if (sLineHeight.empty() || (bImportants[5] && !bHardMode))
|
||||
if (sLineHeight.empty() || (bImportants[5] && !bHardMode) || unLevel <= arLevels[5])
|
||||
return;
|
||||
|
||||
if (sLineHeight == L"normal")
|
||||
fLineHeight = 1.2;
|
||||
{
|
||||
arLevels[5] = unLevel;
|
||||
fLineHeight = 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
const float fValue = wcstof(sLineHeight.c_str(), NULL);
|
||||
@ -1111,9 +1114,6 @@ namespace NSCSS
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
if (!bPermission)
|
||||
return true;
|
||||
|
||||
return fTopSide == fNoneValue && fRightSide == fNoneValue && fBottomSide == fNoneValue && fLeftSide == fNoneValue;
|
||||
};
|
||||
|
||||
@ -1322,33 +1322,70 @@ namespace NSCSS
|
||||
fLeftSide += wcstof(sLeftMargin.c_str(), NULL);
|
||||
}
|
||||
|
||||
std::wstring GetTopSide() const
|
||||
bool GetPermission() const
|
||||
{
|
||||
if (fTopSide < 0 || !bPermission)
|
||||
return bPermission;
|
||||
}
|
||||
|
||||
double GetTopSide() const
|
||||
{
|
||||
if (fTopSide < 0)
|
||||
return 0;
|
||||
|
||||
return fTopSide;
|
||||
}
|
||||
|
||||
std::wstring GetTopSideW() const
|
||||
{
|
||||
if (fTopSide < 0)
|
||||
return std::wstring();
|
||||
|
||||
return std::to_wstring(static_cast<short int>(fTopSide * 10.0f + 0.5f));
|
||||
}
|
||||
|
||||
std::wstring GetRightSide() const
|
||||
double GetRightSide() const
|
||||
{
|
||||
if (fRightSide < 0 || !bPermission)
|
||||
if (fRightSide < 0)
|
||||
return 0;
|
||||
|
||||
return fRightSide;
|
||||
}
|
||||
|
||||
std::wstring GetRightSideW() const
|
||||
{
|
||||
if (fRightSide < 0)
|
||||
return std::wstring();
|
||||
|
||||
return (fRightSide >= -128.0f) ? std::to_wstring(static_cast<short int>(fRightSide * 10.0f + ((fLeftSide > 0) ? 0.5f : -0.5f))) : L"-1280";
|
||||
}
|
||||
|
||||
std::wstring GetBottomSide() const
|
||||
double GetBottomSide() const
|
||||
{
|
||||
if (fBottomSide < 0 || !bPermission)
|
||||
if (fBottomSide < 0)
|
||||
return 0;
|
||||
|
||||
return fBottomSide;
|
||||
}
|
||||
|
||||
std::wstring GetBottomSideW() const
|
||||
{
|
||||
if (fBottomSide < 0)
|
||||
return std::wstring();
|
||||
|
||||
return std::to_wstring(static_cast<short int>(fBottomSide * 10.0f + 0.5f));
|
||||
}
|
||||
|
||||
std::wstring GetLeftSide() const
|
||||
double GetLeftSide() const
|
||||
{
|
||||
if (fLeftSide < 0 || !bPermission)
|
||||
if (fLeftSide < 0)
|
||||
return 0;
|
||||
|
||||
return fLeftSide;
|
||||
}
|
||||
|
||||
std::wstring GetLeftSideW() const
|
||||
{
|
||||
if (fLeftSide < 0)
|
||||
return std::wstring();
|
||||
|
||||
return (fLeftSide >= -128.0f) ? std::to_wstring(static_cast<short int>(fLeftSide * 10.0f + ((fLeftSide > 0) ? 0.5f : -0.5f))) : L"-1280";
|
||||
@ -1478,7 +1515,7 @@ namespace NSCSS
|
||||
|
||||
void SetAlign(const std::wstring& sAlign, const unsigned int& unLevel, const bool& bHardMode = false)
|
||||
{
|
||||
if (sAlign.empty() || (bImportants[1] && !bHardMode))
|
||||
if (sAlign.empty() || (bImportants[1] && !bHardMode) || unLevel <= arLevels[1])
|
||||
return;
|
||||
|
||||
if (sAlign == L"center")
|
||||
@ -1763,7 +1800,7 @@ namespace NSCSS
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
return fWidth < 0;
|
||||
return fWidth < 0;
|
||||
}
|
||||
|
||||
void SetWidthWithoutChecking(const float& fWidth, const unsigned int& unLevel, const bool &bHardMode = false)
|
||||
@ -2490,7 +2527,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()
|
||||
{
|
||||
@ -2659,17 +2696,18 @@ namespace NSCSS
|
||||
{
|
||||
std::wstring wsDisplay;
|
||||
int nWidth;
|
||||
int nHeight;
|
||||
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} {};
|
||||
Display() : wsDisplay(L"inline"), nWidth(-1), nHeight(-1), wsAlign(), bImportants{false, false, false, false}, arLevels{0, 0, 0, 0} {};
|
||||
|
||||
void ClearImportants()
|
||||
{
|
||||
bImportants = {false, false, false};
|
||||
bImportants = {false, false, false, false};
|
||||
}
|
||||
|
||||
Display operator+=(const Display& oDisplay)
|
||||
@ -2679,6 +2717,7 @@ namespace NSCSS
|
||||
|
||||
wsDisplay = oDisplay.wsDisplay;
|
||||
nWidth = oDisplay.nWidth;
|
||||
nHeight = oDisplay.nHeight;
|
||||
wsAlign = oDisplay.wsAlign;
|
||||
|
||||
return *this;
|
||||
@ -2710,13 +2749,25 @@ namespace NSCSS
|
||||
oSecondDisplay.nWidth = -1;
|
||||
}
|
||||
|
||||
if (oFirstDisplay.bImportants[2] && !oSecondDisplay.bImportants[2] && !oFirstDisplay.wsAlign.empty())
|
||||
if (oFirstDisplay.bImportants[2] && !oSecondDisplay.bImportants[2] && oFirstDisplay.nHeight > 0)
|
||||
oSecondDisplay.nHeight = -1;
|
||||
else if (oSecondDisplay.bImportants[2] && !oFirstDisplay.bImportants[2] && oSecondDisplay.nHeight > 0)
|
||||
oFirstDisplay.nHeight = -1;
|
||||
else if (oSecondDisplay.nHeight > 0)
|
||||
{
|
||||
if (oFirstDisplay.arLevels[2] < oSecondDisplay.arLevels[2])
|
||||
oFirstDisplay.nHeight = -1;
|
||||
else
|
||||
oSecondDisplay.nHeight = -1;
|
||||
}
|
||||
|
||||
if (oFirstDisplay.bImportants[3] && !oSecondDisplay.bImportants[3] && !oFirstDisplay.wsAlign.empty())
|
||||
oSecondDisplay.wsAlign.clear();
|
||||
else if (oSecondDisplay.bImportants[2] && !oFirstDisplay.bImportants[2] && !oSecondDisplay.wsAlign.empty())
|
||||
else if (oSecondDisplay.bImportants[3] && !oFirstDisplay.bImportants[3] && !oSecondDisplay.wsAlign.empty())
|
||||
oFirstDisplay.wsAlign.clear();
|
||||
else if (!oSecondDisplay.wsAlign.empty())
|
||||
{
|
||||
if (oFirstDisplay.arLevels[2] < oSecondDisplay.arLevels[2])
|
||||
if (oFirstDisplay.arLevels[3] < oSecondDisplay.arLevels[3])
|
||||
oFirstDisplay.wsAlign.clear();
|
||||
else
|
||||
oSecondDisplay.wsAlign.clear();
|
||||
@ -2725,17 +2776,17 @@ namespace NSCSS
|
||||
|
||||
bool operator==(const Display& oDisplay) const
|
||||
{
|
||||
return wsDisplay == oDisplay.wsDisplay && nWidth == oDisplay.nWidth && wsAlign == oDisplay.wsAlign;
|
||||
return wsDisplay == oDisplay.wsDisplay && nWidth == oDisplay.nWidth && nHeight == oDisplay.nHeight && wsAlign == oDisplay.wsAlign;
|
||||
}
|
||||
|
||||
bool Empty() const
|
||||
{
|
||||
return (L"inline" == wsDisplay || wsDisplay.empty()) && (nWidth < 0) && (wsAlign.empty());
|
||||
return (L"inline" == wsDisplay || wsDisplay.empty()) && (nWidth < 0) && (nHeight < 0) && (wsAlign.empty());
|
||||
}
|
||||
|
||||
void SetImportantAll(const bool &bImportant)
|
||||
{
|
||||
bImportants = {bImportant, bImportant, bImportant};
|
||||
bImportants = {bImportant, bImportant, bImportant, bImportant};
|
||||
}
|
||||
|
||||
void SetImportantDisplay(const bool &bImportant)
|
||||
@ -2748,11 +2799,16 @@ namespace NSCSS
|
||||
bImportants[1] = bImportant;
|
||||
}
|
||||
|
||||
void SetImportantAlign(const bool& bImportant)
|
||||
void SetImportantHeight(const bool &bImportant)
|
||||
{
|
||||
bImportants[2] = bImportant;
|
||||
}
|
||||
|
||||
void SetImportantAlign(const bool& bImportant)
|
||||
{
|
||||
bImportants[3] = bImportant;
|
||||
}
|
||||
|
||||
void SetDisplay(const std::wstring& wsNewDisplay, const unsigned int& unLevel, const bool &bHardMode = false)
|
||||
{
|
||||
if (wsNewDisplay.empty() || (bImportants[0] && !bHardMode))
|
||||
@ -2782,15 +2838,34 @@ namespace NSCSS
|
||||
arLevels[1] = unLevel;
|
||||
nWidth = nValue;
|
||||
}
|
||||
|
||||
void SetHeight(const std::wstring& wsNewValue, const unsigned int& unLevel, const bool &bHardMode = false)
|
||||
{
|
||||
if (wsNewValue.empty() || !iswdigit(wsNewValue[0]) || (bImportants[2] && !bHardMode))
|
||||
return;
|
||||
|
||||
arLevels[2] = unLevel;
|
||||
nHeight = std::stoi(wsNewValue);
|
||||
}
|
||||
|
||||
void SetHeight(int nValue, const unsigned int& unLevel, const bool &bHardMode = false)
|
||||
{
|
||||
if (bImportants[2] && !bHardMode)
|
||||
return;
|
||||
|
||||
arLevels[2] = unLevel;
|
||||
nHeight = nValue;
|
||||
}
|
||||
|
||||
void SetAlign(const std::wstring& sAlign, const unsigned int& unLevel, const bool& bHardMode = false)
|
||||
{
|
||||
if (sAlign.empty() || (bImportants[2] && !bHardMode))
|
||||
if (sAlign.empty() || (bImportants[3] && !bHardMode))
|
||||
return;
|
||||
|
||||
if (L"center" == sAlign || L"left" == sAlign || L"start" == sAlign ||
|
||||
L"right" == sAlign || L"end" == sAlign)
|
||||
{
|
||||
arLevels[2] = unLevel;
|
||||
arLevels[3] = unLevel;
|
||||
wsAlign = sAlign;
|
||||
}
|
||||
}
|
||||
@ -2808,6 +2883,19 @@ namespace NSCSS
|
||||
return std::to_wstring(nWidth);
|
||||
}
|
||||
|
||||
int GetWidth() const
|
||||
{
|
||||
return nWidth;
|
||||
}
|
||||
|
||||
std::wstring GetHeightW() const
|
||||
{
|
||||
if (nHeight < 0)
|
||||
return std::wstring();
|
||||
|
||||
return std::to_wstring(nHeight);
|
||||
}
|
||||
|
||||
std::wstring GetAlign() const
|
||||
{
|
||||
return wsAlign;
|
||||
|
||||
@ -254,10 +254,10 @@ namespace NSCSS
|
||||
std::wstring sInfValue;
|
||||
sInfValue.reserve(64);
|
||||
|
||||
if (!oStyle.m_pMargin.Empty())
|
||||
if (!oStyle.m_pMargin.Empty() && oStyle.m_pMargin.GetPermission())
|
||||
{
|
||||
const std::wstring& sLeftSide = oStyle.m_pMargin.GetLeftSide();
|
||||
const std::wstring& sRightSide = oStyle.m_pMargin.GetRightSide();
|
||||
const std::wstring& sLeftSide = oStyle.m_pMargin.GetLeftSideW();
|
||||
const std::wstring& sRightSide = oStyle.m_pMargin.GetRightSideW();
|
||||
|
||||
if (!sLeftSide.empty())
|
||||
sInfValue += L"w:left=\"" + sLeftSide + L"\" ";
|
||||
@ -274,19 +274,22 @@ namespace NSCSS
|
||||
std::wstring sSpacingValue;
|
||||
sSpacingValue.reserve(128);
|
||||
|
||||
if (!oStyle.m_pMargin.Empty())
|
||||
if (!oStyle.m_pMargin.Empty() && oStyle.m_pMargin.GetPermission())
|
||||
{
|
||||
sSpacingValue += L"w:after=\"" + oStyle.m_pMargin.GetTopSide() + L"\" ";
|
||||
sSpacingValue += L"w:before=\"" + oStyle.m_pMargin.GetTopSide() + L"\" ";
|
||||
sSpacingValue += L"w:afterAutospacing=\"1\" w:after=\"" + oStyle.m_pMargin.GetTopSideW() + L"\" ";
|
||||
sSpacingValue += L"w:beforeAutospacing=\"1\" w:before=\"" + oStyle.m_pMargin.GetTopSideW() + L"\" ";
|
||||
}
|
||||
else if (!oStyle.m_pBorder.Empty())
|
||||
sSpacingValue += L"w:after=\"0\" w:before=\"0\" ";
|
||||
else/* if (!oStyle.m_pBorder.Empty() || !oStyle.m_pMargin.GetPermission())*/
|
||||
sSpacingValue += L"w:after=\"0\" w:before=\"0\"";
|
||||
|
||||
const std::wstring &sLineHeight = oStyle.m_pFont.GetLineHeight();
|
||||
if (!sLineHeight.empty())
|
||||
{
|
||||
sSpacingValue += L"w:line=\"" + sLineHeight + L"\" ";
|
||||
sSpacingValue += L"w:lineRule=\"auto\"";
|
||||
sSpacingValue += L" w:line=\"" + sLineHeight + L"\" w:lineRule=\"auto\"";
|
||||
}
|
||||
else if (!oStyle.m_pBorder.Empty())
|
||||
{
|
||||
sSpacingValue += L" w:line=\"" + std::to_wstring(static_cast<short int>(oStyle.m_pFont.GetSize() * 12 + 0.5f)) + L"\" w:lineRule=\"auto\"";
|
||||
}
|
||||
else if (!oStyle.m_pBorder.Empty())
|
||||
sSpacingValue += L"w:line=\"240\" w:lineRule=\"auto\" ";
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -36,6 +36,10 @@
|
||||
#pragma comment(lib, "Wininet")
|
||||
#pragma comment(lib, "Ole32.lib")
|
||||
|
||||
#ifdef GetTempPath
|
||||
#undef GetTempPath
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Константа для максимального числа символов в строке
|
||||
@ -86,7 +90,13 @@ namespace NSNetwork
|
||||
CoInitialize ( NULL );
|
||||
if ( /*S_OK != _DownloadFile ( m_sFileUrl )*/TRUE )
|
||||
{
|
||||
DeleteUrlCacheEntry(m_sDownloadFileUrl.c_str());
|
||||
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(E_ABORT == hrResultAll /*&& m_bIsExit->load()*/)
|
||||
|
||||
@ -738,6 +738,12 @@ namespace NSDoctRenderer
|
||||
oBuilder.WriteString(sConvertionParams);
|
||||
}
|
||||
|
||||
std::wstring sDstTmpDir = NSDirectory::CreateDirectoryWithUniqueName(m_sFileDir);
|
||||
|
||||
oBuilder.WriteString(L"<m_sTempDir>");
|
||||
oBuilder.WriteEncodeXmlString(sDstTmpDir);
|
||||
oBuilder.WriteString(L"</m_sTempDir>");
|
||||
|
||||
oBuilder.WriteString(L"</TaskQueueDataConvert>");
|
||||
|
||||
std::wstring sXmlConvert = oBuilder.GetData();
|
||||
@ -852,6 +858,7 @@ namespace NSDoctRenderer
|
||||
}
|
||||
#endif
|
||||
|
||||
NSDirectory::DeleteDirectory(sDstTmpDir);
|
||||
NSFile::CFileBinary::Remove(sTempFileForParams);
|
||||
|
||||
LOGGER_SPEED_LAP("save_convert")
|
||||
|
||||
@ -327,7 +327,8 @@ namespace NSDoctRenderer
|
||||
}
|
||||
else
|
||||
{
|
||||
NSJSBase::CJSDataBuffer oBuffer = js_result2->toTypedArray()->getData();
|
||||
JSSmart<CJSTypedArray> typedArray = js_result2->toTypedArray();
|
||||
NSJSBase::CJSDataBuffer oBuffer = typedArray->getData();
|
||||
|
||||
NSFile::CFileBinary oFile;
|
||||
if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
|
||||
@ -464,7 +465,8 @@ namespace NSDoctRenderer
|
||||
}
|
||||
else
|
||||
{
|
||||
NSJSBase::CJSDataBuffer oBuffer = js_result2->toTypedArray()->getData();
|
||||
JSSmart<CJSTypedArray> typedArray = js_result2->toTypedArray();
|
||||
NSJSBase::CJSDataBuffer oBuffer = typedArray->getData();
|
||||
|
||||
NSFile::CFileBinary oFile;
|
||||
if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
|
||||
@ -520,7 +522,10 @@ namespace NSDoctRenderer
|
||||
{
|
||||
JSSmart<CJSObject> objNative = js_result2->toObject();
|
||||
|
||||
NSJSBase::CJSDataBuffer oBuffer = objNative->get("data")->toTypedArray()->getData();
|
||||
JSSmart<CJSValue> oDataArray = objNative->get("data");
|
||||
JSSmart<CJSTypedArray> oTypedArray = oDataArray->toTypedArray();
|
||||
|
||||
NSJSBase::CJSDataBuffer oBuffer = oTypedArray->getData();
|
||||
std::wstring sThemeName = objNative->get("name")->toStringW();
|
||||
int nDataLen = objNative->get("dataLen")->toInt32();
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
JSSmart<CJSValue> CGraphicsEmbed::init(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm)
|
||||
{
|
||||
m_pInternal->init((NSNativeControl::CNativeControl*)Native->toObject()->getNative()->getObject(), width_px->toDouble(), height_px->toDouble(), width_mm->toDouble(), height_mm->toDouble());
|
||||
m_pInternal->init((NSNativeControl::CNativeControl*)Native->toObjectSmart()->getNative()->getObject(), width_px->toDouble(), height_px->toDouble(), width_mm->toDouble(), height_mm->toDouble());
|
||||
return NULL;
|
||||
}
|
||||
JSSmart<CJSValue> CGraphicsEmbed::EndDraw()
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
#include "./TextMeasurerEmbed.h"
|
||||
#include "./../../fontengine/TextShaper.h"
|
||||
|
||||
#define RAW_POINTER(value) ((CPointerEmbedObject*)value->toObject()->getNative())->Data
|
||||
#define POINTER_OBJECT(value) ((CPointerEmbedObject*)value->toObject()->getNative())
|
||||
#define RAW_POINTER(value) ((CPointerEmbedObject*)value->toObjectSmart()->getNative())->Data
|
||||
#define POINTER_OBJECT(value) ((CPointerEmbedObject*)value->toObjectSmart()->getNative())
|
||||
|
||||
// в js не хотим следить, чтобы в каждом face была ссылка на library - т.е. чтобы
|
||||
// сначала удалились все face, а потом library - поэтому делаем свой счетчик ссылок
|
||||
// и следим за library сами. Т.е. используем FT_Library_Reference/FT_Library_UnReference
|
||||
|
||||
|
||||
class CExternalPointerJS : public NSShaper::CExternalPointer
|
||||
{
|
||||
@ -36,7 +41,8 @@ JSSmart<CJSValue> CTextMeasurerEmbed::FT_Malloc(JSSmart<CJSValue> typed_array_or
|
||||
}
|
||||
else
|
||||
{
|
||||
CJSDataBuffer pBuffer = typed_array_or_len->toTypedArray()->getData();
|
||||
JSSmart<CJSTypedArray> typedArray = typed_array_or_len->toTypedArray();
|
||||
CJSDataBuffer pBuffer = typedArray->getData();
|
||||
pData = malloc(pBuffer.Len);
|
||||
memcpy(pData, pBuffer.Data, pBuffer.Len);
|
||||
if (pBuffer.IsExternalize)
|
||||
@ -48,14 +54,14 @@ JSSmart<CJSValue> CTextMeasurerEmbed::FT_Malloc(JSSmart<CJSValue> typed_array_or
|
||||
}
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::FT_Free(JSSmart<CJSValue> pointer)
|
||||
{
|
||||
CPointerEmbedObject* pEmbed = (CPointerEmbedObject*)pointer->toObject()->getNative();
|
||||
CPointerEmbedObject* pEmbed = (CPointerEmbedObject*)pointer->toObjectSmart()->getNative();
|
||||
pEmbed->Free();
|
||||
return CJSContext::createUndefined();
|
||||
}
|
||||
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::FT_Init()
|
||||
{
|
||||
CPointerEmbedObject* pointer = new CPointerEmbedObject(NSShaper::FT_Library_Init(), [](void* data) { NSShaper::FT_Library_Destroy(data); });
|
||||
CPointerEmbedObject* pointer = new CPointerEmbedObject(NSShaper::FT_Library_Init(), [](void* data) { NSShaper::FT_Library_UnReference(data); });
|
||||
return pointer->createObject();
|
||||
}
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::FT_Set_TrueType_HintProp(JSSmart<CJSValue> library, JSSmart<CJSValue> tt_interpreter)
|
||||
@ -65,15 +71,22 @@ JSSmart<CJSValue> CTextMeasurerEmbed::FT_Set_TrueType_HintProp(JSSmart<CJSValue>
|
||||
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::FT_Open_Face(JSSmart<CJSValue> library, JSSmart<CJSValue> memory, JSSmart<CJSValue> size, JSSmart<CJSValue> face_index)
|
||||
{
|
||||
void* face = NSShaper::FT_Open_Face(RAW_POINTER(library), (unsigned char*)RAW_POINTER(memory), size->toUInt32(), face_index->toInt32());
|
||||
CPointerEmbedObject* pointer = new CPointerEmbedObject(face, [](void* data) { NSShaper::FT_Done_Face(data); });
|
||||
void* ftlibrary = RAW_POINTER(library);
|
||||
void* face = NSShaper::FT_Open_Face(ftlibrary, (unsigned char*)RAW_POINTER(memory), size->toUInt32(), face_index->toInt32());
|
||||
if (NULL != face)
|
||||
NSShaper::FT_Library_Reference(ftlibrary);
|
||||
CPointerEmbedObject* pointer = new CPointerEmbedObject(face, [](void* data) { NSShaper::FT_Done_Face_With_Library(data); });
|
||||
return pointer->createObject();
|
||||
}
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::FT_Open_Face2(JSSmart<CJSValue> library, JSSmart<CJSValue> array, JSSmart<CJSValue> face_index)
|
||||
{
|
||||
CJSDataBuffer buffer = array->toTypedArray()->getData();
|
||||
void* face = NSShaper::FT_Open_Face(RAW_POINTER(library), (unsigned char*)buffer.Data, (unsigned int)buffer.Len, face_index->toInt32());
|
||||
CPointerEmbedObject* pointer = new CPointerEmbedObject(face, NSPointerObjectDeleters::EmptyDeleter);
|
||||
void* ftlibrary = RAW_POINTER(library);
|
||||
JSSmart<CJSTypedArray> typedArray = array->toTypedArray();
|
||||
CJSDataBuffer buffer = typedArray->getData();
|
||||
void* face = NSShaper::FT_Open_Face(ftlibrary, (unsigned char*)buffer.Data, (unsigned int)buffer.Len, face_index->toInt32());
|
||||
if (NULL != face)
|
||||
NSShaper::FT_Library_Reference(ftlibrary);
|
||||
CPointerEmbedObject* pointer = new CPointerEmbedObject(face, [](void* data) { NSShaper::FT_Done_Face_With_Library(data); });
|
||||
return pointer->createObject();
|
||||
}
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::FT_GetFaceInfo(JSSmart<CJSValue> face)
|
||||
@ -137,7 +150,7 @@ JSSmart<CJSValue> CTextMeasurerEmbed::FT_GetFaceMaxAdvanceX(JSSmart<CJSValue> fa
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::HB_LanguageFromString(JSSmart<CJSValue> language_bcp_47)
|
||||
{
|
||||
void* Data = NSShaper::HB_LanguageFromString(language_bcp_47->toStringA());
|
||||
CPointerEmbedObject* pObject = new CPointerEmbedObject(Data, [](void* data) { NSShaper::HB_free(data); });
|
||||
CPointerEmbedObject* pObject = new CPointerEmbedObject(Data, NSPointerObjectDeleters::EmptyDeleter);
|
||||
return pObject->createObject();
|
||||
}
|
||||
|
||||
@ -147,11 +160,14 @@ JSSmart<CJSValue> CTextMeasurerEmbed::HB_ShapeText(JSSmart<CJSValue> face, JSSma
|
||||
CPointerEmbedObject* pFont = POINTER_OBJECT(font);
|
||||
CExternalPointerJS result;
|
||||
|
||||
CJSDataBuffer buffer = text->toTypedArray()->getData();
|
||||
JSSmart<CJSTypedArray> typedArray = text->toTypedArray();
|
||||
CJSDataBuffer buffer = typedArray->getData();
|
||||
|
||||
char* pText = (char*)buffer.Data;
|
||||
|
||||
NSShaper::HB_ShapeText(RAW_POINTER(face), pFont->Data, pText,
|
||||
nFeatures->toUInt32(), nScript->toUInt32(), nDirection->toUInt32(), RAW_POINTER(nLanguage), &result);
|
||||
nFeatures->toUInt32(), nScript->toUInt32(), nDirection->toUInt32(), RAW_POINTER(nLanguage),
|
||||
&result, true);
|
||||
|
||||
if (buffer.IsExternalize)
|
||||
buffer.Free();
|
||||
@ -162,9 +178,16 @@ JSSmart<CJSValue> CTextMeasurerEmbed::HB_ShapeText(JSSmart<CJSValue> face, JSSma
|
||||
return CJSContext::createUint8Array(result.Data, result.Len, false);
|
||||
}
|
||||
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::HB_FontMalloc()
|
||||
{
|
||||
CPointerEmbedObject* pObject = new CPointerEmbedObject(NULL, [](void* data) { NSShaper::HB_FontFree(data); });
|
||||
return pObject->createObject();
|
||||
}
|
||||
|
||||
JSSmart<CJSValue> CTextMeasurerEmbed::HB_FontFree(JSSmart<CJSValue> font)
|
||||
{
|
||||
NSShaper::HB_FontFree(RAW_POINTER(font));
|
||||
CPointerEmbedObject* pFont = POINTER_OBJECT(font);
|
||||
pFont->Free();
|
||||
return CJSContext::createUndefined();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -47,6 +47,7 @@ public:
|
||||
JSSmart<CJSValue> HB_ShapeText(JSSmart<CJSValue> face, JSSmart<CJSValue> font, JSSmart<CJSValue> text,
|
||||
JSSmart<CJSValue> nFeatures, JSSmart<CJSValue> nScript, JSSmart<CJSValue> nDirection, JSSmart<CJSValue> nLanguage);
|
||||
|
||||
JSSmart<CJSValue> HB_FontMalloc();
|
||||
JSSmart<CJSValue> HB_FontFree(JSSmart<CJSValue> font);
|
||||
#endif
|
||||
|
||||
|
||||
@ -70,7 +70,8 @@ JSSmart<CJSValue> CZipEmbed::addFile(JSSmart<CJSValue> filePath, JSSmart<CJSValu
|
||||
if (!m_pFolder || !filePath->isString() || !typedArray->isTypedArray())
|
||||
return CJSContext::createBool(false);
|
||||
|
||||
CJSDataBuffer buffer = typedArray->toTypedArray()->getData();
|
||||
JSSmart<CJSTypedArray> typedArray2 = typedArray->toTypedArray();
|
||||
CJSDataBuffer buffer = typedArray2->getData();
|
||||
m_pFolder->write(filePath->toStringW(), buffer.Data, (DWORD)buffer.Len);
|
||||
|
||||
if (buffer.IsExternalize)
|
||||
|
||||
@ -97,8 +97,7 @@ JSSmart<CJSValue> CBuilderEmbed::builder_OpenTmpFile(JSSmart<CJSValue> path, JSS
|
||||
p->m_internal->m_pBuilder = m_pBuilder;
|
||||
p->m_internal->OpenFile(sPath, sParams);
|
||||
CJSValueJSC* pRet = new CJSValueJSC();
|
||||
pRet->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
pRet->value = [JSValue valueWithObject:(id)p inContext:pRet->context];
|
||||
pRet->value = [JSValue valueWithObject:(id)p inContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return pRet;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
JSSmart<CJSValue> CPointerEmbedObject::createObject()
|
||||
{
|
||||
CJSValueJSC* pRet = new CJSValueJSC();
|
||||
pRet->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
pRet->value = [JSValue valueWithObject:(id)[[CJSCPointer alloc] initWithPointer:this] inContext:pRet->context];
|
||||
pRet->value = [JSValue valueWithObject:(id)[[CJSCPointer alloc] initWithPointer:this] inContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return pRet;
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
||||
-(JSValue*) HB_LanguageFromString : (JSValue*)lang;
|
||||
-(JSValue*) HB_ShapeText : (JSValue*) face : (JSValue*) font : (JSValue*) text : (JSValue*) nFeatures : (JSValue*) nScript : (JSValue*) nDirection : (JSValue*) nLanguage;
|
||||
-(JSValue*) HB_FontMalloc;
|
||||
-(JSValue*) HB_FontFree : (JSValue*)font;
|
||||
#endif
|
||||
|
||||
@ -66,6 +67,7 @@ FUNCTION_WRAPPER_JS_1(FT_GetFaceMaxAdvanceX, FT_GetFaceMaxAdvanceX)
|
||||
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
||||
FUNCTION_WRAPPER_JS_1(HB_LanguageFromString, HB_LanguageFromString)
|
||||
FUNCTION_WRAPPER_JS_7(HB_ShapeText, HB_ShapeText)
|
||||
FUNCTION_WRAPPER_JS(HB_FontMalloc, HB_FontMalloc)
|
||||
FUNCTION_WRAPPER_JS_1(HB_FontFree, HB_FontFree)
|
||||
#endif
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ namespace NSMeasurer
|
||||
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
||||
FUNCTION_WRAPPER_V8_1(_HB_LanguageFromString, HB_LanguageFromString)
|
||||
FUNCTION_WRAPPER_V8_7(_HB_ShapeText, HB_ShapeText)
|
||||
FUNCTION_WRAPPER_V8 (_HB_FontMalloc, HB_FontMalloc)
|
||||
FUNCTION_WRAPPER_V8_1(_HB_FontFree, HB_FontFree)
|
||||
#endif
|
||||
|
||||
@ -64,6 +65,7 @@ namespace NSMeasurer
|
||||
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
||||
NSV8Objects::Template_Set(result, "HB_LanguageFromString", _HB_LanguageFromString);
|
||||
NSV8Objects::Template_Set(result, "HB_ShapeText", _HB_ShapeText);
|
||||
NSV8Objects::Template_Set(result, "HB_ShapeText", _HB_FontMalloc);
|
||||
NSV8Objects::Template_Set(result, "HB_FontFree", _HB_FontFree);
|
||||
#endif
|
||||
|
||||
|
||||
@ -50,6 +50,8 @@ namespace NSJSBase
|
||||
virtual CJSArray* toArray() = 0;
|
||||
virtual CJSTypedArray* toTypedArray() = 0;
|
||||
virtual CJSFunction* toFunction() = 0;
|
||||
|
||||
virtual JSSmart<CJSObject> toObjectSmart() { return toObject(); }
|
||||
};
|
||||
|
||||
class CJSEmbedObjectPrivateBase
|
||||
|
||||
@ -23,11 +23,6 @@ namespace NSJSBase
|
||||
JSContext* context;
|
||||
std::vector<ASC_THREAD_ID> m_arThreads;
|
||||
|
||||
static bool g_oldVersion;
|
||||
|
||||
// считаем, что vector будет небольшим, поэтому он будет быстрее, чем map
|
||||
static std::vector<std::pair<ASC_THREAD_ID, JSContext*>> g_contexts;
|
||||
|
||||
public:
|
||||
CJSContextPrivate()
|
||||
{
|
||||
@ -38,53 +33,8 @@ namespace NSJSBase
|
||||
context = nil;
|
||||
}
|
||||
|
||||
static JSContext* GetCurrentContext()
|
||||
{
|
||||
ASC_THREAD_ID nCurrentThread = NSThreads::GetCurrentThreadId();
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, JSContext*>>::const_iterator i = g_contexts.begin(); i != g_contexts.end(); i++)
|
||||
{
|
||||
if (i->first == nCurrentThread)
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
return [JSContext currentContext];
|
||||
}
|
||||
|
||||
private:
|
||||
static bool RegisterContext(JSContext* ctx, ASC_THREAD_ID* id = NULL)
|
||||
{
|
||||
ASC_THREAD_ID nCurrentThread = (id == NULL) ? NSThreads::GetCurrentThreadId() : *id;
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, JSContext*>>::const_iterator i = g_contexts.begin(); i != g_contexts.end(); i++)
|
||||
{
|
||||
if (i->first == nCurrentThread)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
g_contexts.push_back(std::pair<ASC_THREAD_ID, JSContext*>(nCurrentThread, ctx));
|
||||
return true;
|
||||
}
|
||||
|
||||
static void UnregisterContextForId(ASC_THREAD_ID nCurrentThread)
|
||||
{
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, JSContext*>>::const_iterator i = g_contexts.begin(); i != g_contexts.end(); i++)
|
||||
{
|
||||
if (i->first == nCurrentThread)
|
||||
{
|
||||
g_contexts.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void UnregisterContext()
|
||||
{
|
||||
UnregisterContextForId(NSThreads::GetCurrentThreadId());
|
||||
}
|
||||
|
||||
friend class CJSContext;
|
||||
static JSContext* GetCurrentContext();
|
||||
static bool IsOldVersion();
|
||||
};
|
||||
}
|
||||
|
||||
@ -95,21 +45,14 @@ namespace NSJSBase
|
||||
{
|
||||
public:
|
||||
JSValue* value;
|
||||
JSContext* context;
|
||||
|
||||
CJSValueJSCTemplate()
|
||||
{
|
||||
value = nil;
|
||||
context = nil;
|
||||
}
|
||||
CJSValueJSCTemplate(JSValue* _value)
|
||||
{
|
||||
value = _value;
|
||||
context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
|
||||
if (context == nil) {
|
||||
context = _value.context;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
@ -117,7 +60,6 @@ namespace NSJSBase
|
||||
virtual ~CJSValueJSCTemplate()
|
||||
{
|
||||
value = nil;
|
||||
context = nil;
|
||||
}
|
||||
|
||||
virtual bool isUndefined();
|
||||
@ -144,6 +86,13 @@ namespace NSJSBase
|
||||
virtual CJSArray* toArray();
|
||||
virtual CJSTypedArray* toTypedArray();
|
||||
virtual CJSFunction* toFunction();
|
||||
|
||||
JSContext* getContext()
|
||||
{
|
||||
if (nil == value || nil == value.context)
|
||||
return CJSContextPrivate::GetCurrentContext();
|
||||
return value.context;
|
||||
}
|
||||
};
|
||||
|
||||
typedef CJSValueJSCTemplate<CJSValue> CJSValueJSC;
|
||||
@ -161,14 +110,12 @@ namespace NSJSBase
|
||||
virtual ~CJSObjectJSC()
|
||||
{
|
||||
value = nil;
|
||||
context = nil;
|
||||
}
|
||||
|
||||
virtual CJSValue* get(const char* name)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = [value valueForProperty:[[NSString alloc] initWithUTF8String:name]];
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
@ -180,12 +127,12 @@ namespace NSJSBase
|
||||
|
||||
virtual void set(const char* name, const int& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithInt32:_value inContext: context] forProperty:[[NSString alloc] initWithUTF8String:name]];
|
||||
[value setValue:[JSValue valueWithInt32:_value inContext: getContext()] forProperty:[[NSString alloc] initWithUTF8String:name]];
|
||||
}
|
||||
|
||||
virtual void set(const char* name, const double& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithDouble:_value inContext: context] forProperty:[[NSString alloc] initWithUTF8String:name]];
|
||||
[value setValue:[JSValue valueWithDouble:_value inContext: getContext()] forProperty:[[NSString alloc] initWithUTF8String:name]];
|
||||
}
|
||||
|
||||
virtual CJSEmbedObject* getNative()
|
||||
@ -213,7 +160,6 @@ namespace NSJSBase
|
||||
}
|
||||
|
||||
CJSValueJSC* _return = new CJSValueJSC();
|
||||
_return->context = context;
|
||||
_return->value = [value invokeMethod: [[NSString alloc] initWithUTF8String:name]
|
||||
withArguments: arr];
|
||||
|
||||
@ -225,7 +171,6 @@ namespace NSJSBase
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = value;
|
||||
//_value->value = [JSValue valueWithJSValueRef:[value JSValueRef] inContext:context];
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
@ -242,7 +187,6 @@ namespace NSJSBase
|
||||
virtual ~CJSArrayJSC()
|
||||
{
|
||||
value = nil;
|
||||
context = nil;
|
||||
}
|
||||
|
||||
virtual int getCount()
|
||||
@ -257,7 +201,6 @@ namespace NSJSBase
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = [value valueAtIndex:(NSUInteger)index];
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
@ -274,22 +217,22 @@ namespace NSJSBase
|
||||
|
||||
virtual void set(const int& index, const bool& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithBool:_value inContext : context] atIndex:index];
|
||||
[value setValue:[JSValue valueWithBool:_value inContext : getContext()] atIndex:index];
|
||||
}
|
||||
|
||||
virtual void set(const int& index, const int& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithInt32:_value inContext : context] atIndex:index];
|
||||
[value setValue:[JSValue valueWithInt32:_value inContext : getContext()] atIndex:index];
|
||||
}
|
||||
|
||||
virtual void set(const int& index, const double& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithDouble:_value inContext : context] atIndex:index];
|
||||
[value setValue:[JSValue valueWithDouble:_value inContext : getContext()] atIndex:index];
|
||||
}
|
||||
|
||||
virtual void add_null()
|
||||
{
|
||||
[value setValue:[JSValue valueWithNullInContext:context] atIndex:m_count++];
|
||||
[value setValue:[JSValue valueWithNullInContext:getContext()] atIndex:m_count++];
|
||||
}
|
||||
|
||||
virtual void add_undefined()
|
||||
@ -299,22 +242,22 @@ namespace NSJSBase
|
||||
|
||||
virtual void add_bool(const bool& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithBool:_value inContext : context] atIndex:m_count++];
|
||||
[value setValue:[JSValue valueWithBool:_value inContext : getContext()] atIndex:m_count++];
|
||||
}
|
||||
|
||||
virtual void add_byte(const BYTE& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithInt32:(int)_value inContext : context] atIndex:m_count++];
|
||||
[value setValue:[JSValue valueWithInt32:(int)_value inContext : getContext()] atIndex:m_count++];
|
||||
}
|
||||
|
||||
virtual void add_int(const int& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithInt32:_value inContext : context] atIndex:m_count++];
|
||||
[value setValue:[JSValue valueWithInt32:_value inContext : getContext()] atIndex:m_count++];
|
||||
}
|
||||
|
||||
virtual void add_double(const double& _value)
|
||||
{
|
||||
[value setValue:[JSValue valueWithDouble:_value inContext : context] atIndex:m_count++];
|
||||
[value setValue:[JSValue valueWithDouble:_value inContext : getContext()] atIndex:m_count++];
|
||||
}
|
||||
|
||||
virtual void add_stringa(const std::string& _value)
|
||||
@ -331,7 +274,6 @@ namespace NSJSBase
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = value;
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
@ -341,19 +283,19 @@ namespace NSJSBase
|
||||
public:
|
||||
CJSTypedArrayJSC(JSContext* _context, BYTE* data = NULL, int count = 0, const bool& isExternalize = true)
|
||||
{
|
||||
context = _context;
|
||||
if (0 >= count)
|
||||
return;
|
||||
if (!CJSContextPrivate::g_oldVersion)
|
||||
|
||||
if (!CJSContextPrivate::IsOldVersion())
|
||||
{
|
||||
JSObjectRef object = JSObjectMakeTypedArrayWithBytesNoCopy(context.JSGlobalContextRef,
|
||||
JSObjectRef object = JSObjectMakeTypedArrayWithBytesNoCopy(_context.JSGlobalContextRef,
|
||||
kJSTypedArrayTypeUint8Array,
|
||||
(void*)data, (size_t)count,
|
||||
isExternalize ? data_no_destroy_memory : data_destroy_memory,
|
||||
nullptr, nullptr);
|
||||
if (object)
|
||||
{
|
||||
value = [JSValue valueWithJSValueRef:object inContext:context];
|
||||
value = [JSValue valueWithJSValueRef:object inContext:_context];
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -370,7 +312,6 @@ namespace NSJSBase
|
||||
virtual ~CJSTypedArrayJSC()
|
||||
{
|
||||
value = nil;
|
||||
context = nil;
|
||||
}
|
||||
|
||||
static void data_destroy_memory(void* bytes, void* deallocatorContext)
|
||||
@ -385,7 +326,8 @@ namespace NSJSBase
|
||||
{
|
||||
if (nil == value)
|
||||
return 0;
|
||||
if (!CJSContextPrivate::g_oldVersion)
|
||||
JSContext* context = getContext();
|
||||
if (!CJSContextPrivate::IsOldVersion())
|
||||
{
|
||||
JSObjectRef obj = JSValueToObject(context.JSGlobalContextRef, value.JSValueRef, NULL);
|
||||
return (int)JSObjectGetTypedArrayByteLength(context.JSGlobalContextRef, obj, NULL);
|
||||
@ -398,8 +340,9 @@ namespace NSJSBase
|
||||
|
||||
virtual CJSDataBuffer getData()
|
||||
{
|
||||
JSContext* context = getContext();
|
||||
CJSDataBuffer buffer;
|
||||
if (!CJSContextPrivate::g_oldVersion)
|
||||
if (!CJSContextPrivate::IsOldVersion())
|
||||
{
|
||||
JSObjectRef obj = JSValueToObject(context.JSGlobalContextRef, value.JSValueRef, NULL);
|
||||
buffer.IsExternalize = false;
|
||||
@ -431,7 +374,6 @@ namespace NSJSBase
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = value;
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
};
|
||||
@ -445,7 +387,6 @@ namespace NSJSBase
|
||||
virtual ~CJSFunctionJSC()
|
||||
{
|
||||
value = nil;
|
||||
context = nil;
|
||||
}
|
||||
|
||||
virtual CJSValue* Call(CJSValue* recv, int argc, JSSmart<CJSValue> argv[])
|
||||
@ -458,7 +399,6 @@ namespace NSJSBase
|
||||
}
|
||||
|
||||
CJSValueJSC* _return = new CJSValueJSC();
|
||||
_return->context = context;
|
||||
_return->value = [value callWithArguments:arr];
|
||||
|
||||
return _return;
|
||||
@ -470,7 +410,6 @@ namespace NSJSBase
|
||||
{
|
||||
CJSObjectJSC* _value = new CJSObjectJSC();
|
||||
_value->value = value;
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
@ -479,16 +418,14 @@ namespace NSJSBase
|
||||
{
|
||||
CJSArrayJSC* _value = new CJSArrayJSC();
|
||||
_value->value = value;
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CJSTypedArray* CJSValueJSCTemplate<T>::toTypedArray()
|
||||
{
|
||||
CJSTypedArrayJSC* _value = new CJSTypedArrayJSC(context);
|
||||
CJSTypedArrayJSC* _value = new CJSTypedArrayJSC(getContext());
|
||||
_value->value = value;
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
@ -497,7 +434,6 @@ namespace NSJSBase
|
||||
{
|
||||
CJSFunctionJSC* _value = new CJSFunctionJSC();
|
||||
_value->value = value;
|
||||
_value->context = context;
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
@ -509,13 +445,11 @@ namespace NSJSBase
|
||||
{
|
||||
public:
|
||||
JSContext* context;
|
||||
JSSmart<CJSContext> smartContext;
|
||||
|
||||
public:
|
||||
CJSCTryCatch() : CJSTryCatch()
|
||||
{
|
||||
smartContext = CJSContext::GetCurrent();
|
||||
context = smartContext->m_internal->context;
|
||||
context = CJSContextPrivate::GetCurrentContext();
|
||||
}
|
||||
virtual ~CJSCTryCatch()
|
||||
{
|
||||
|
||||
@ -3,9 +3,106 @@
|
||||
|
||||
using namespace NSJSBase;
|
||||
|
||||
std::vector<std::pair<ASC_THREAD_ID, JSContext*>> NSJSBase::CJSContextPrivate::g_contexts;
|
||||
class CGlobalContext
|
||||
{
|
||||
private:
|
||||
// считаем, что vector будет небольшим, поэтому он будет быстрее, чем map
|
||||
std::vector<std::pair<ASC_THREAD_ID, CJSContextPrivate*>> m_contexts;
|
||||
bool m_bIsOldVersion;
|
||||
|
||||
bool NSJSBase::CJSContextPrivate::g_oldVersion = false;
|
||||
CGlobalContext()
|
||||
{
|
||||
m_bIsOldVersion = false;
|
||||
#ifndef _IOS
|
||||
if (@available(macOS 10.12, *))
|
||||
{
|
||||
// none
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bIsOldVersion = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
~CGlobalContext()
|
||||
{
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, CJSContextPrivate*>>::iterator i = m_contexts.begin(); i != m_contexts.end(); i++)
|
||||
{
|
||||
CJSContextPrivate* ctx = i->second;
|
||||
delete ctx;
|
||||
}
|
||||
m_contexts.clear();
|
||||
}
|
||||
|
||||
public:
|
||||
bool RegisterContext(CJSContextPrivate* ctx, ASC_THREAD_ID* id = NULL)
|
||||
{
|
||||
ASC_THREAD_ID nCurrentThread = (id == NULL) ? NSThreads::GetCurrentThreadId() : *id;
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, CJSContextPrivate*>>::const_iterator i = m_contexts.begin(); i != m_contexts.end(); i++)
|
||||
{
|
||||
if (i->first == nCurrentThread)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CJSContextPrivate* pContext = new CJSContextPrivate();
|
||||
pContext->context = ctx->context;
|
||||
m_contexts.push_back(std::pair<ASC_THREAD_ID, CJSContextPrivate*>(nCurrentThread, pContext));
|
||||
return true;
|
||||
}
|
||||
void UnregisterContextForId(ASC_THREAD_ID nCurrentThread)
|
||||
{
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, CJSContextPrivate*>>::iterator i = m_contexts.begin(); i != m_contexts.end(); i++)
|
||||
{
|
||||
if (i->first == nCurrentThread)
|
||||
{
|
||||
CJSContextPrivate* ctx = i->second;
|
||||
delete ctx;
|
||||
|
||||
m_contexts.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void UnregisterContext()
|
||||
{
|
||||
UnregisterContextForId(NSThreads::GetCurrentThreadId());
|
||||
}
|
||||
|
||||
bool IsOldVersion()
|
||||
{
|
||||
return m_bIsOldVersion;
|
||||
}
|
||||
|
||||
JSContext* GetCurrent()
|
||||
{
|
||||
ASC_THREAD_ID nCurrentThread = NSThreads::GetCurrentThreadId();
|
||||
for (std::vector<std::pair<ASC_THREAD_ID, CJSContextPrivate*>>::const_iterator i = m_contexts.begin(); i != m_contexts.end(); i++)
|
||||
{
|
||||
if (i->first == nCurrentThread)
|
||||
{
|
||||
return i->second->context;
|
||||
}
|
||||
}
|
||||
return [JSContext currentContext];
|
||||
}
|
||||
|
||||
static CGlobalContext& GetInstance()
|
||||
{
|
||||
static CGlobalContext instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
|
||||
JSContext* CJSContextPrivate::GetCurrentContext()
|
||||
{
|
||||
return CGlobalContext::GetInstance().GetCurrent();
|
||||
}
|
||||
bool CJSContextPrivate::IsOldVersion()
|
||||
{
|
||||
return CGlobalContext::GetInstance().IsOldVersion();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool CJSValueJSCTemplate<T>::isUndefined()
|
||||
@ -35,12 +132,12 @@ bool CJSValueJSCTemplate<T>::isString()
|
||||
template<typename T>
|
||||
bool CJSValueJSCTemplate<T>::isArray()
|
||||
{
|
||||
return (value == nil) ? false : JSValueIsArray(context.JSGlobalContextRef, value.JSValueRef);
|
||||
return (value == nil) ? false : JSValueIsArray(getContext().JSGlobalContextRef, value.JSValueRef);
|
||||
}
|
||||
template<typename T>
|
||||
bool CJSValueJSCTemplate<T>::isTypedArray()
|
||||
{
|
||||
return (value == nil) ? false : (kJSTypedArrayTypeNone == JSValueGetTypedArrayType(context.JSGlobalContextRef, value.JSValueRef, NULL));
|
||||
return (value == nil) ? false : (kJSTypedArrayTypeNone == JSValueGetTypedArrayType(getContext().JSGlobalContextRef, value.JSValueRef, NULL));
|
||||
}
|
||||
template<typename T>
|
||||
bool CJSValueJSCTemplate<T>::isObject()
|
||||
@ -60,12 +157,12 @@ bool CJSValueJSCTemplate<T>::isEmpty()
|
||||
template<typename T>
|
||||
void CJSValueJSCTemplate<T>::doUndefined()
|
||||
{
|
||||
value = [JSValue valueWithUndefinedInContext:context];
|
||||
value = [JSValue valueWithUndefinedInContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
}
|
||||
template<typename T>
|
||||
void CJSValueJSCTemplate<T>::doNull()
|
||||
{
|
||||
value = [JSValue valueWithNullInContext:context];
|
||||
value = [JSValue valueWithNullInContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
}
|
||||
template<typename T>
|
||||
bool CJSValueJSCTemplate<T>::toBool()
|
||||
@ -118,29 +215,22 @@ namespace NSJSBase
|
||||
void CJSContext::Initialize()
|
||||
{
|
||||
m_internal->context = [[JSContext alloc] init];
|
||||
CJSContextPrivate::RegisterContext(m_internal->context);
|
||||
|
||||
#ifndef _IOS
|
||||
if (@available(macOS 10.12, *))
|
||||
CGlobalContext::GetInstance().RegisterContext(m_internal);
|
||||
if (CGlobalContext::GetInstance().IsOldVersion())
|
||||
{
|
||||
// none
|
||||
[m_internal->context evaluateScript:@"function jsc_toBase64(r){for(var o=[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\"H\",\"I\",\"J\",\"K\",\"L\",\"M\",\"N\",\"O\",\"P\",\"Q\",\"R\",\"S\",\"T\",\"U\",\"V\",\"W\",\"X\",\"Y\",\"Z\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\",\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"+\",\"/\"],a=r.length,f=4*(a/3>>0),n=f/76>>0,t=19,v=0,e=[],i=\"\",s=0;s<=n;s++){s==n&&(t=f%76/4>>0);for(var u=0;u<t;u++){for(var c=0,h=0;h<3;h++)c|=r[0+v++],c<<=8;i=\"\";for(var A=0;A<4;A++){i+=o[c>>>26&255],c<<=6,c&=4294967295}e.push(i)}}if(n=a%3!=0?a%3+1:0){for(c=0,h=0;h<3;h++)h<a%3&&(c|=r[0+v++]),c<<=8;i=\"\";for(A=0;A<n;A++){i+=o[c>>>26&255],c<<=6}t=0!=n?4-n:0;for(u=0;u<t;u++)i+=\"=\";e.push(i)}return e.join(\"\")}function jsc_fromBase64(r,o){for(var a,f=r.length,n=0,t=new Array(void 0===o?f:o),v=t,e=0,i=0;e<f;){for(var s=0,u=0,c=0;c<4&&!(f<=e);c++){var h=65<=(a=r.charCodeAt(e++))&&a<=90?a-65:97<=a&&a<=122?a-71:48<=a&&a<=57?a+4:43==a?62:47==a?63:-1;-1!=h?(s<<=6,s|=h,u+=6):c--}for(s<<=24-u,i=u>>>3,c=0;c<i;c++)v[n++]=(16711680&s)>>>16,s<<=8}return t}\n"];
|
||||
}
|
||||
else
|
||||
{
|
||||
CJSContextPrivate::g_oldVersion = true;
|
||||
[m_internal->context evaluateScript:@"var Uint8Array=Array;function jsc_toBase64(r){for(var o=[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\"H\",\"I\",\"J\",\"K\",\"L\",\"M\",\"N\",\"O\",\"P\",\"Q\",\"R\",\"S\",\"T\",\"U\",\"V\",\"W\",\"X\",\"Y\",\"Z\",\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\",\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"+\",\"/\"],a=r.length,f=4*(a/3>>0),n=f/76>>0,t=19,v=0,e=[],i=\"\",s=0;s<=n;s++){s==n&&(t=f%76/4>>0);for(var u=0;u<t;u++){for(var c=0,h=0;h<3;h++)c|=r[0+v++],c<<=8;i=\"\";for(var A=0;A<4;A++){i+=o[c>>>26&255],c<<=6,c&=4294967295}e.push(i)}}if(n=a%3!=0?a%3+1:0){for(c=0,h=0;h<3;h++)h<a%3&&(c|=r[0+v++]),c<<=8;i=\"\";for(A=0;A<n;A++){i+=o[c>>>26&255],c<<=6}t=0!=n?4-n:0;for(u=0;u<t;u++)i+=\"=\";e.push(i)}return e.join(\"\")}function jsc_fromBase64(r,o){for(var a,f=r.length,n=0,t=new Array(void 0===o?f:o),v=t,e=0,i=0;e<f;){for(var s=0,u=0,c=0;c<4&&!(f<=e);c++){var h=65<=(a=r.charCodeAt(e++))&&a<=90?a-65:97<=a&&a<=122?a-71:48<=a&&a<=57?a+4:43==a?62:47==a?63:-1;-1!=h?(s<<=6,s|=h,u+=6):c--}for(s<<=24-u,i=u>>>3,c=0;c<i;c++)v[n++]=(16711680&s)>>>16,s<<=8}return t}\n"];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void CJSContext::Dispose()
|
||||
{
|
||||
m_internal->context = nil;
|
||||
CJSContextPrivate::UnregisterContext();
|
||||
|
||||
for (std::vector<ASC_THREAD_ID>::const_iterator i = m_internal->m_arThreads.begin(); i != m_internal->m_arThreads.end(); i++)
|
||||
{
|
||||
CJSContextPrivate::UnregisterContextForId(*i);
|
||||
CGlobalContext::GetInstance().UnregisterContextForId(*i);
|
||||
}
|
||||
|
||||
CGlobalContext::GetInstance().UnregisterContext();
|
||||
m_internal->context = nil;
|
||||
}
|
||||
|
||||
void CJSContext::CreateContext()
|
||||
@ -156,7 +246,6 @@ namespace NSJSBase
|
||||
CJSObject* CJSContext::GetGlobal()
|
||||
{
|
||||
CJSObjectJSC* ret = new CJSObjectJSC();
|
||||
ret->context = m_internal->context;
|
||||
ret->value = [m_internal->context globalObject];
|
||||
return ret;
|
||||
}
|
||||
@ -189,7 +278,6 @@ namespace NSJSBase
|
||||
CJSValue* CJSContext::createUndefined()
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->doUndefined();
|
||||
return _value;
|
||||
}
|
||||
@ -197,7 +285,6 @@ namespace NSJSBase
|
||||
CJSValue* CJSContext::createNull()
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->doNull();
|
||||
return _value;
|
||||
}
|
||||
@ -205,39 +292,34 @@ namespace NSJSBase
|
||||
CJSValue* CJSContext::createBool(const bool& value)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [JSValue valueWithBool:(value ? YES : NO) inContext:_value->context];
|
||||
_value->value = [JSValue valueWithBool:(value ? YES : NO) inContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return _value;
|
||||
}
|
||||
|
||||
CJSValue* CJSContext::createInt(const int& value)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [JSValue valueWithInt32:((int32_t) value) inContext:_value->context];
|
||||
_value->value = [JSValue valueWithInt32:((int32_t) value) inContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return _value;
|
||||
}
|
||||
|
||||
CJSValue* CJSContext::createUInt(const unsigned int& value)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [JSValue valueWithUInt32:((uint32_t) value) inContext:_value->context];
|
||||
_value->value = [JSValue valueWithUInt32:((uint32_t) value) inContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return _value;
|
||||
}
|
||||
|
||||
CJSValue* CJSContext::createDouble(const double& value)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [JSValue valueWithDouble:value inContext:_value->context];
|
||||
_value->value = [JSValue valueWithDouble:value inContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return _value;
|
||||
}
|
||||
|
||||
CJSValue* CJSContext::createString(const char* value, const int& len)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [NSString stringWithUtf8Buffer:value length:(size_t)((len == -1) ? strlen(value) : len)];
|
||||
return _value;
|
||||
}
|
||||
@ -245,7 +327,6 @@ namespace NSJSBase
|
||||
CJSValue* CJSContext::createString(const std::string& value)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [NSString stringWithAString:value];
|
||||
return _value;
|
||||
}
|
||||
@ -253,7 +334,6 @@ namespace NSJSBase
|
||||
CJSValue* CJSContext::createString(const std::wstring& value)
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [NSString stringWithWString:value];
|
||||
return _value;
|
||||
}
|
||||
@ -261,16 +341,14 @@ namespace NSJSBase
|
||||
CJSObject* CJSContext::createObject()
|
||||
{
|
||||
CJSObjectJSC* _value = new CJSObjectJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [JSValue valueWithNewObjectInContext:_value->context];
|
||||
_value->value = [JSValue valueWithNewObjectInContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return _value;
|
||||
}
|
||||
|
||||
CJSArray* CJSContext::createArray(const int& count)
|
||||
{
|
||||
CJSArrayJSC* _value = new CJSArrayJSC();
|
||||
_value->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
_value->value = [JSValue valueWithNewArrayInContext:_value->context];
|
||||
_value->value = [JSValue valueWithNewArrayInContext:NSJSBase::CJSContextPrivate::GetCurrentContext()];
|
||||
return _value;
|
||||
}
|
||||
|
||||
@ -285,7 +363,6 @@ namespace NSJSBase
|
||||
{
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = [m_internal->context evaluateScript:[NSString stringWithAString:script]];
|
||||
_value->context = m_internal->context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
@ -313,7 +390,7 @@ namespace NSJSBase
|
||||
}
|
||||
bool CJSContext::IsSupportNativeTypedArrays()
|
||||
{
|
||||
return (CJSContextPrivate::g_oldVersion == false) ? true : false;
|
||||
return (CJSContextPrivate::IsOldVersion() == false) ? true : false;
|
||||
}
|
||||
|
||||
CJSValue* CJSContext::JSON_Parse(const char *sTmp)
|
||||
@ -327,13 +404,12 @@ namespace NSJSBase
|
||||
|
||||
CJSValueJSC* _value = new CJSValueJSC();
|
||||
_value->value = [JSValue valueWithJSValueRef:oValueJSRef inContext: m_internal->context];
|
||||
_value->context = m_internal->context;
|
||||
return _value;
|
||||
}
|
||||
|
||||
void CJSContext::MoveToThread(ASC_THREAD_ID* id)
|
||||
{
|
||||
if (CJSContextPrivate::RegisterContext(m_internal->context, id))
|
||||
if (CGlobalContext::GetInstance().RegisterContext(m_internal, id))
|
||||
{
|
||||
m_internal->m_arThreads.push_back((NULL == id) ? NSThreads::GetCurrentThreadId() : *id);
|
||||
}
|
||||
|
||||
@ -191,6 +191,18 @@ namespace NSShaper
|
||||
{
|
||||
::FT_Done_FreeType((FT_Library)library);
|
||||
}
|
||||
void FT_Library_Reference(void* library)
|
||||
{
|
||||
FT_Reference_Library((FT_Library)library);
|
||||
}
|
||||
void FT_Library_UnReference(void* library_)
|
||||
{
|
||||
FT_Library library = (FT_Library)library_;
|
||||
if (library->refcount == 1)
|
||||
::FT_Done_FreeType(library);
|
||||
else
|
||||
::FT_Done_Library(library);
|
||||
}
|
||||
|
||||
int FT_Set_TrueType_HintProp(void* library, unsigned int interpreter_version)
|
||||
{
|
||||
@ -234,6 +246,18 @@ namespace NSShaper
|
||||
::FT_Done_Face((FT_Face)face);
|
||||
}
|
||||
|
||||
void FT_Done_Face_With_Library(void* face)
|
||||
{
|
||||
FT_Face ftface = (FT_Face)face;
|
||||
FT_Library library = ftface->driver->root.library;
|
||||
|
||||
bool bIsNeedUnreferenceLibrary = (1 == ftface->internal->refcount) ? true : false;
|
||||
::FT_Done_Face(ftface);
|
||||
|
||||
if (bIsNeedUnreferenceLibrary)
|
||||
FT_Library_UnReference(library);
|
||||
}
|
||||
|
||||
unsigned int FT_SetCMapForCharCode(void* face_pointer, unsigned int unicode)
|
||||
{
|
||||
if (!face_pointer)
|
||||
@ -639,13 +663,15 @@ namespace NSShaper
|
||||
{
|
||||
return (void*)hb_language_from_string(language_bcp_47.c_str(), language_bcp_47.length());
|
||||
}
|
||||
void HB_free(void* data)
|
||||
|
||||
static void _hb_ft_face_destroy_js(void *data)
|
||||
{
|
||||
HB_free(data);
|
||||
FT_Done_Face_With_Library(data);
|
||||
}
|
||||
|
||||
inline void HB_ShapeTextRaw(void* face, void*& font, char* text_str, const size_t& text_length,
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage, CExternalPointer* result)
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage,
|
||||
CExternalPointer* result, bool bIsJSVersion)
|
||||
{
|
||||
// init features
|
||||
if (!g_userfeatures_init)
|
||||
@ -671,7 +697,15 @@ namespace NSShaper
|
||||
hb_font_t* pFont;
|
||||
if (NULL == font)
|
||||
{
|
||||
pFont = hb_ft_font_create((FT_Face)face, NULL);
|
||||
if (!bIsJSVersion)
|
||||
{
|
||||
pFont = hb_ft_font_create_referenced((FT_Face)face);
|
||||
}
|
||||
else
|
||||
{
|
||||
FT_Reference_Face((FT_Face)face);
|
||||
pFont = hb_ft_font_create((FT_Face)face, _hb_ft_face_destroy_js);
|
||||
}
|
||||
hb_ft_font_set_funcs(pFont);
|
||||
font = (void*)pFont;
|
||||
}
|
||||
@ -730,19 +764,23 @@ namespace NSShaper
|
||||
}
|
||||
|
||||
void HB_ShapeText(void* face, void*& font, char* text,
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage, CExternalPointer* result)
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage,
|
||||
CExternalPointer* result, bool bIsJSVersion)
|
||||
{
|
||||
HB_ShapeTextRaw(face, font, text, strlen(text), nFeatures, nScript, nDirection, nLanguage, result);
|
||||
HB_ShapeTextRaw(face, font, text, strlen(text), nFeatures, nScript, nDirection, nLanguage, result, bIsJSVersion);
|
||||
}
|
||||
|
||||
void HB_ShapeText(void* face, void*& font, const std::string& text,
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage, CExternalPointer* result)
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage,
|
||||
CExternalPointer* result, bool bIsJSVersion)
|
||||
{
|
||||
HB_ShapeTextRaw(face, font, (char*)text.c_str(), text.length(), nFeatures, nScript, nDirection, nLanguage, result);
|
||||
HB_ShapeTextRaw(face, font, (char*)text.c_str(), text.length(), nFeatures, nScript, nDirection, nLanguage, result, bIsJSVersion);
|
||||
}
|
||||
|
||||
void HB_FontFree(void* font)
|
||||
{
|
||||
if (NULL == font)
|
||||
return;
|
||||
hb_font_destroy((hb_font_t*)font);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,11 +56,14 @@ namespace NSShaper
|
||||
|
||||
GRAPHICS_DECL void* FT_Library_Init();
|
||||
GRAPHICS_DECL void FT_Library_Destroy(void* library);
|
||||
GRAPHICS_DECL void FT_Library_UnReference(void* library);
|
||||
GRAPHICS_DECL void FT_Library_Reference(void* library);
|
||||
|
||||
GRAPHICS_DECL int FT_Set_TrueType_HintProp(void* library, unsigned int interpreter_version);
|
||||
|
||||
GRAPHICS_DECL void* FT_Open_Face(void* library, unsigned char* memory, unsigned int size, int face_index);
|
||||
GRAPHICS_DECL void FT_Done_Face(void* face);
|
||||
GRAPHICS_DECL void FT_Done_Face_With_Library(void* face);
|
||||
|
||||
GRAPHICS_DECL bool FT_GetFaceInfo(void* face, CExternalPointer* result);
|
||||
GRAPHICS_DECL bool FT_Get_Glyph_Measure_Params(void* face, bool is_vector, CExternalPointer* result);
|
||||
@ -80,13 +83,14 @@ namespace NSShaper
|
||||
|
||||
#ifdef SUPPORT_HARFBUZZ_SHAPER
|
||||
GRAPHICS_DECL void* HB_LanguageFromString(const std::string language_bcp_47);
|
||||
GRAPHICS_DECL void HB_free(void* data);
|
||||
|
||||
GRAPHICS_DECL void HB_ShapeText(void* face, void*& font, char* text,
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage, CExternalPointer* result);
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage,
|
||||
CExternalPointer* result, bool bIsJSVersion = false);
|
||||
|
||||
GRAPHICS_DECL void HB_ShapeText(void* face, void*& font, const std::string& text,
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage, CExternalPointer* result);
|
||||
unsigned int nFeatures, unsigned int nScript, unsigned int nDirection, void* nLanguage,
|
||||
CExternalPointer* result, bool bIsJSVersion = false);
|
||||
|
||||
GRAPHICS_DECL void HB_FontFree(void* font);
|
||||
#endif
|
||||
|
||||
@ -188,7 +188,7 @@ AscFonts.HB_ShapeText = function(fontFile, text, features, script, direction, la
|
||||
}
|
||||
|
||||
if (!fontFile["GetHBFont"]())
|
||||
fontFile["SetHBFont"](g_native_engine["FT_Malloc"](0));
|
||||
fontFile["SetHBFont"](g_native_engine["HB_FontMalloc"]());
|
||||
|
||||
let data = g_native_engine["HB_ShapeText"](fontFile["GetFace"](), fontFile["GetHBFont"](), text.pointer, features, script, direction, hb_cache_languages[language]);
|
||||
if (!data)
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -67,10 +67,8 @@ namespace MetaFile
|
||||
|
||||
void CXmlOutput::Clear()
|
||||
{
|
||||
if (NULL != m_pXmlWriter)
|
||||
delete m_pXmlWriter;
|
||||
else if (NULL != m_pXmlLiteReader)
|
||||
delete m_pXmlLiteReader;
|
||||
RELEASEOBJECT(m_pXmlWriter);
|
||||
RELEASEOBJECT(m_pXmlLiteReader);
|
||||
}
|
||||
|
||||
bool CXmlOutput::IsWriter() const
|
||||
|
||||
@ -60,7 +60,19 @@
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
class CEmfClip;
|
||||
struct TRenderConditional
|
||||
{
|
||||
IMetaFileBase* m_pFile;
|
||||
|
||||
int m_lDrawPathType;
|
||||
double m_dX; // Координаты левого верхнего угла
|
||||
double m_dY; //
|
||||
double m_dW; //
|
||||
double m_dH; //
|
||||
double m_dScaleX; // Коэффициенты сжатия/растяжения, чтобы
|
||||
double m_dScaleY; // результирующая картинка была нужных размеров.
|
||||
bool m_bStartedPath;
|
||||
};
|
||||
|
||||
class CMetaFileRenderer : public IOutputDevice
|
||||
{
|
||||
@ -75,6 +87,7 @@ namespace MetaFile
|
||||
m_dH = dHeight;
|
||||
|
||||
m_pRenderer = NULL;
|
||||
m_pSecondConditional = NULL;
|
||||
|
||||
if (!pRenderer)
|
||||
return;
|
||||
@ -103,20 +116,38 @@ namespace MetaFile
|
||||
//m_pRenderer->PathCommandEnd();
|
||||
}
|
||||
|
||||
CMetaFileRenderer(const CMetaFileRenderer &oMetaFileRenderer, IMetaFileBase *pFile)
|
||||
virtual ~CMetaFileRenderer()
|
||||
{
|
||||
m_pFile = pFile;
|
||||
RELEASEOBJECT(m_pSecondConditional)
|
||||
}
|
||||
|
||||
m_dX = oMetaFileRenderer.m_dX;
|
||||
m_dY = oMetaFileRenderer.m_dY;
|
||||
m_dW = oMetaFileRenderer.m_dW;
|
||||
m_dH = oMetaFileRenderer.m_dH;
|
||||
void CreateConditional(IMetaFileBase* pFile)
|
||||
{
|
||||
RELEASEOBJECT(m_pSecondConditional);
|
||||
|
||||
m_pRenderer = oMetaFileRenderer.m_pRenderer;
|
||||
m_pSecondConditional = new TRenderConditional();
|
||||
|
||||
UpdateScale();
|
||||
SaveConditional(*m_pSecondConditional);
|
||||
|
||||
m_bStartedPath = false;
|
||||
m_pSecondConditional->m_pFile = pFile;
|
||||
}
|
||||
|
||||
void ChangeConditional()
|
||||
{
|
||||
if (NULL != m_pSecondConditional)
|
||||
{
|
||||
TRenderConditional oRenderConditional;
|
||||
SaveConditional(oRenderConditional);
|
||||
|
||||
SetConditional(*m_pSecondConditional);
|
||||
|
||||
*m_pSecondConditional = oRenderConditional;
|
||||
}
|
||||
}
|
||||
|
||||
IMetaFileBase* GetFile() const
|
||||
{
|
||||
return m_pFile;
|
||||
}
|
||||
|
||||
void UpdateScale()
|
||||
@ -134,10 +165,6 @@ namespace MetaFile
|
||||
m_dScaleY = (nB - nT <= 0) ? 1 : m_dH / (double)(nB - nT);
|
||||
}
|
||||
|
||||
~CMetaFileRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void Begin()
|
||||
{
|
||||
UpdateScale();
|
||||
@ -736,6 +763,32 @@ namespace MetaFile
|
||||
|
||||
private:
|
||||
|
||||
void SaveConditional(TRenderConditional& oRenderConditional)
|
||||
{
|
||||
oRenderConditional.m_pFile = m_pFile;
|
||||
oRenderConditional.m_lDrawPathType = m_lDrawPathType;
|
||||
oRenderConditional.m_dX = m_dX;
|
||||
oRenderConditional.m_dY = m_dY;
|
||||
oRenderConditional.m_dW = m_dW;
|
||||
oRenderConditional.m_dH = m_dH;
|
||||
oRenderConditional.m_dScaleX = m_dScaleX;
|
||||
oRenderConditional.m_dScaleY = m_dScaleY;
|
||||
oRenderConditional.m_bStartedPath = m_bStartedPath;
|
||||
}
|
||||
|
||||
void SetConditional(const TRenderConditional& oRenderConditional)
|
||||
{
|
||||
m_pFile = oRenderConditional.m_pFile;
|
||||
m_lDrawPathType = oRenderConditional.m_lDrawPathType;
|
||||
m_dX = oRenderConditional.m_dX;
|
||||
m_dY = oRenderConditional.m_dY;
|
||||
m_dW = oRenderConditional.m_dW;
|
||||
m_dH = oRenderConditional.m_dH;
|
||||
m_dScaleX = oRenderConditional.m_dScaleX;
|
||||
m_dScaleY = oRenderConditional.m_dScaleY;
|
||||
m_bStartedPath = oRenderConditional.m_bStartedPath;
|
||||
}
|
||||
|
||||
void CheckStartPath(bool bMoveTo)
|
||||
{
|
||||
if (!m_bStartedPath)
|
||||
@ -1111,6 +1164,8 @@ namespace MetaFile
|
||||
double m_dScaleX; // Коэффициенты сжатия/растяжения, чтобы
|
||||
double m_dScaleY; // результирующая картинка была нужных размеров.
|
||||
bool m_bStartedPath;
|
||||
|
||||
TRenderConditional *m_pSecondConditional;
|
||||
};
|
||||
}
|
||||
#endif // _METAFILE_COMMON_METAFILERENDERER_H
|
||||
|
||||
@ -54,8 +54,7 @@ namespace MetaFile
|
||||
|
||||
~CEmfFile()
|
||||
{
|
||||
if (NULL != m_pParser)
|
||||
delete m_pParser;
|
||||
RELEASEOBJECT(m_pParser);
|
||||
}
|
||||
|
||||
bool OpenFromEmfFile(const wchar_t* wsFilePath)
|
||||
|
||||
@ -6,8 +6,7 @@ namespace MetaFile
|
||||
CEmfInterpretator::CEmfInterpretator(const wchar_t* wsFilepath) :
|
||||
unFileSize(0), unNumberRecords(0), ushNuberDescriptors(0)
|
||||
{
|
||||
m_pOutStream = new NSFile::CFileBinary();
|
||||
bool result = m_pOutStream->CreateFileW(wsFilepath);
|
||||
m_pOutStream = new NSFile::CFileBinary();
|
||||
}
|
||||
|
||||
CEmfInterpretator::CEmfInterpretator(const CEmfInterpretator& oEmfInterpretator, const bool bIsLite)
|
||||
|
||||
@ -18,6 +18,9 @@ namespace MetaFile
|
||||
|
||||
InterpretatorType GetType() const override;
|
||||
|
||||
void CreateConditional(IMetaFileBase* pFile) override {};
|
||||
void ChangeConditional() override {};
|
||||
|
||||
void HANDLE_EMR_HEADER(const TEmfHeader& oTEmfHeader) override ;
|
||||
void HANDLE_EMR_ALPHABLEND(const TEmfAlphaBlend& oTEmfAlphaBlend, CDataStream &oDataStream) override ;
|
||||
void HANDLE_EMR_STRETCHDIBITS(const TEmfStretchDIBITS& oTEmfStretchDIBITS, CDataStream &oDataStream) override ;
|
||||
|
||||
@ -1,22 +1,17 @@
|
||||
#include "CEmfInterpretatorArray.h"
|
||||
|
||||
#include "CEmfInterpretator.h"
|
||||
#include "CEmfInterpretatorXml.h"
|
||||
#include "CEmfInterpretatorRender.h"
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
CEmfInterpretatorArray::CEmfInterpretatorArray(){}
|
||||
|
||||
CEmfInterpretatorArray::CEmfInterpretatorArray(const CEmfInterpretatorArray &oInterpretator)
|
||||
: m_arInterpretators(oInterpretator.m_arInterpretators){}
|
||||
: m_arInterpretators(oInterpretator.m_arInterpretators)
|
||||
{}
|
||||
|
||||
CEmfInterpretatorArray::~CEmfInterpretatorArray()
|
||||
{
|
||||
for (CEmfInterpretatorBase* pInterpretator : m_arInterpretators)
|
||||
delete pInterpretator;
|
||||
|
||||
m_arInterpretators.clear();
|
||||
}
|
||||
|
||||
void CEmfInterpretatorArray::AddEmfInterpretator(const wchar_t *wsFilepath)
|
||||
@ -51,6 +46,18 @@ namespace MetaFile
|
||||
return InterpretatorType::Array;
|
||||
}
|
||||
|
||||
void CEmfInterpretatorArray::CreateConditional(IMetaFileBase *pFile)
|
||||
{
|
||||
for (CEmfInterpretatorBase* pInterpretator : m_arInterpretators)
|
||||
pInterpretator->CreateConditional(pFile);
|
||||
}
|
||||
|
||||
void CEmfInterpretatorArray::ChangeConditional()
|
||||
{
|
||||
for (CEmfInterpretatorBase* pInterpretator : m_arInterpretators)
|
||||
pInterpretator->ChangeConditional();
|
||||
}
|
||||
|
||||
void CEmfInterpretatorArray::Begin()
|
||||
{
|
||||
for (CEmfInterpretatorBase* pInterpretator : m_arInterpretators)
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
#ifndef CEMFINTERPRETATORARRAY_H
|
||||
#define CEMFINTERPRETATORARRAY_H
|
||||
|
||||
#include "CEmfInterpretator.h"
|
||||
#include "CEmfInterpretatorXml.h"
|
||||
#include "CEmfInterpretatorBase.h"
|
||||
#include "CEmfInterpretatorRender.h"
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
@ -12,12 +15,17 @@ namespace MetaFile
|
||||
CEmfInterpretatorArray(const CEmfInterpretatorArray& oInterpretator);
|
||||
virtual ~CEmfInterpretatorArray();
|
||||
|
||||
CEmfInterpretatorArray& operator=(const CEmfInterpretatorArray& oEmfInterpretatorArray);
|
||||
|
||||
void AddEmfInterpretator(const wchar_t* wsFilepath);
|
||||
void AddXmlInterpretator(const wchar_t* wsFilepath);
|
||||
void AddRenderInterpretator(IOutputDevice* pIOutputDevice);
|
||||
|
||||
InterpretatorType GetType() const override;
|
||||
|
||||
void CreateConditional(IMetaFileBase* pFile) override;
|
||||
void ChangeConditional() override;
|
||||
|
||||
void Begin() override;
|
||||
void End() override;
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
#ifndef CEMFINTERPRETATORBASE_H
|
||||
#define CEMFINTERPRETATORBASE_H
|
||||
|
||||
#include "../EmfTypes.h"
|
||||
#include "../EmfObjects.h"
|
||||
#include "../../CXmlOutput.h"
|
||||
#include "../../Common/IOutputDevice.h"
|
||||
#include "../../Common/MetaFile.h"
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
@ -21,6 +20,9 @@ namespace MetaFile
|
||||
public:
|
||||
virtual InterpretatorType GetType() const = 0;
|
||||
|
||||
virtual void CreateConditional(IMetaFileBase*) = 0;
|
||||
virtual void ChangeConditional() = 0;
|
||||
|
||||
virtual void HANDLE_EMR_HEADER(const TEmfHeader&) = 0;
|
||||
virtual void HANDLE_EMR_ALPHABLEND(const TEmfAlphaBlend&, CDataStream&) = 0;
|
||||
virtual void HANDLE_EMR_STRETCHDIBITS(const TEmfStretchDIBITS&, CDataStream&) = 0;
|
||||
|
||||
@ -5,14 +5,23 @@ namespace MetaFile
|
||||
CEmfInterpretatorRender::CEmfInterpretatorRender(IOutputDevice* pIOutputDevice) :
|
||||
m_pMetaFileRenderer(static_cast<CMetaFileRenderer*>(pIOutputDevice)){}
|
||||
|
||||
CEmfInterpretatorRender::CEmfInterpretatorRender(const CEmfInterpretatorRender &oInterpretator, IMetaFileBase *pFile)
|
||||
: m_pMetaFileRenderer(new CMetaFileRenderer(*oInterpretator.m_pMetaFileRenderer, pFile)){}
|
||||
|
||||
InterpretatorType CEmfInterpretatorRender::GetType() const
|
||||
{
|
||||
return InterpretatorType::Render;
|
||||
}
|
||||
|
||||
void CEmfInterpretatorRender::CreateConditional(IMetaFileBase* pFile)
|
||||
{
|
||||
if (NULL != m_pMetaFileRenderer)
|
||||
m_pMetaFileRenderer->CreateConditional(pFile);
|
||||
}
|
||||
|
||||
void CEmfInterpretatorRender::ChangeConditional()
|
||||
{
|
||||
if (NULL != m_pMetaFileRenderer)
|
||||
m_pMetaFileRenderer->ChangeConditional();
|
||||
}
|
||||
|
||||
void CEmfInterpretatorRender::Begin()
|
||||
{
|
||||
if (NULL != m_pMetaFileRenderer)
|
||||
|
||||
@ -10,10 +10,12 @@ namespace MetaFile
|
||||
{
|
||||
public:
|
||||
CEmfInterpretatorRender(IOutputDevice* pIOutputDevice);
|
||||
CEmfInterpretatorRender(const CEmfInterpretatorRender& oInterpretator, IMetaFileBase* pFile);
|
||||
|
||||
InterpretatorType GetType() const override;
|
||||
|
||||
void CreateConditional(IMetaFileBase* pFile) override;
|
||||
void ChangeConditional() override;
|
||||
|
||||
void Begin() override;
|
||||
void End() override;
|
||||
|
||||
|
||||
@ -8,8 +8,17 @@ namespace MetaFile
|
||||
m_wsXmlFilePath(wsFilePath){}
|
||||
|
||||
CEmfInterpretatorXml::CEmfInterpretatorXml(const CEmfInterpretatorXml &oInterpretator)
|
||||
: m_pOutputXml(oInterpretator.m_pOutputXml),
|
||||
m_wsXmlFilePath(oInterpretator.m_wsXmlFilePath){}
|
||||
: m_pOutputXml(NULL),
|
||||
m_wsXmlFilePath(oInterpretator.m_wsXmlFilePath)
|
||||
{
|
||||
if (NULL == oInterpretator.m_pOutputXml)
|
||||
return;
|
||||
|
||||
if (oInterpretator.m_pOutputXml->IsWriter())
|
||||
m_pOutputXml = new CXmlOutput(TypeXmlOutput::IsWriter);
|
||||
else
|
||||
m_pOutputXml = new CXmlOutput(TypeXmlOutput::IsReader);
|
||||
}
|
||||
|
||||
CEmfInterpretatorXml::~CEmfInterpretatorXml()
|
||||
{
|
||||
|
||||
@ -30,6 +30,9 @@ namespace MetaFile
|
||||
|
||||
InterpretatorType GetType() const override;
|
||||
|
||||
void CreateConditional(IMetaFileBase* pFile) override {};
|
||||
void ChangeConditional() override {};
|
||||
|
||||
void SetOutputDevice(const wchar_t *wsFilePath);
|
||||
|
||||
void HANDLE_EMR_HEADER(const TEmfHeader& oTEmfHeader) override ;
|
||||
|
||||
@ -17,6 +17,7 @@ namespace MetaFile
|
||||
ClearFile();
|
||||
|
||||
RELEASEOBJECT(m_pEmfPlusParser);
|
||||
RELEASEOBJECT(m_pInterpretator);
|
||||
}
|
||||
|
||||
bool CEmfParser::OpenFromFile(const wchar_t *wsFilePath)
|
||||
@ -1392,8 +1393,13 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
m_pEmfPlusParser->SetStream(m_oStream.GetCurPtr(), m_ulRecordSize - 8);
|
||||
|
||||
m_pInterpretator->ChangeConditional();
|
||||
|
||||
m_pEmfPlusParser->PlayFile();
|
||||
|
||||
m_pInterpretator->ChangeConditional();
|
||||
|
||||
m_oStream.Skip(m_ulRecordSize - 8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,9 +624,7 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
CEmfParserBase::~CEmfParserBase()
|
||||
{
|
||||
RELEASEOBJECT(m_pInterpretator)
|
||||
}
|
||||
{}
|
||||
|
||||
void CEmfParserBase::PlayMetaFile(){}
|
||||
|
||||
@ -770,16 +768,14 @@ namespace MetaFile
|
||||
|
||||
void CEmfParserBase::SetInterpretator(IOutputDevice *pOutput)
|
||||
{
|
||||
if (NULL != m_pInterpretator)
|
||||
delete m_pInterpretator;
|
||||
RELEASEOBJECT(m_pInterpretator);
|
||||
|
||||
m_pInterpretator = new CEmfInterpretatorRender(pOutput);
|
||||
}
|
||||
|
||||
void CEmfParserBase::SetInterpretator(const wchar_t *wsFilePath, InterpretatorType oInterpretatorType)
|
||||
{
|
||||
if (NULL != m_pInterpretator)
|
||||
delete m_pInterpretator;
|
||||
RELEASEOBJECT(m_pInterpretator);
|
||||
|
||||
if(oInterpretatorType == InterpretatorType::XML)
|
||||
m_pInterpretator = new CEmfInterpretatorXml(wsFilePath);
|
||||
@ -789,8 +785,7 @@ namespace MetaFile
|
||||
|
||||
void CEmfParserBase::SetInterpretator(IOutputDevice *pOutput, const wchar_t *wsFilePath)
|
||||
{
|
||||
if (NULL != m_pInterpretator)
|
||||
delete m_pInterpretator;
|
||||
RELEASEOBJECT(m_pInterpretator);
|
||||
|
||||
CEmfInterpretatorArray* pEmfInterpretatorArray = new CEmfInterpretatorArray;
|
||||
pEmfInterpretatorArray->AddRenderInterpretator(pOutput);
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
#ifndef CEMFPARSERBASE_H
|
||||
#define CEMFPARSERBASE_H
|
||||
|
||||
#include "../EmfTypes.h"
|
||||
#include "../EmfObjects.h"
|
||||
#include "../../Common/MetaFileUtils.h"
|
||||
//#include "../EmfTypes.h"
|
||||
//#include "../EmfObjects.h"
|
||||
//#include "../../Common/MetaFileUtils.h"
|
||||
|
||||
#include "../EmfPlayer.h"
|
||||
#include "../EmfPath.h"
|
||||
|
||||
#include "../../Common/MetaFile.h"
|
||||
|
||||
#include "../../../../fontengine/FontManager.h"
|
||||
|
||||
#include "../EmfInterpretator/CEmfInterpretatorBase.h"
|
||||
|
||||
@ -73,8 +73,6 @@
|
||||
#include "../EmfInterpretator/CEmfInterpretatorArray.h"
|
||||
#include "../EmfInterpretator/CEmfInterpretatorRender.h"
|
||||
|
||||
#include "../../Common/CPathConverter.h"
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
static std::map<unsigned short, std::wstring> ActionNamesEmfPlus =
|
||||
@ -143,7 +141,7 @@ namespace MetaFile
|
||||
{0x402D, L"EMFPLUS_TRANSLATEWORLDTRANSFORM"}
|
||||
};
|
||||
|
||||
CEmfPlusParser::CEmfPlusParser(const CEmfInterpretatorBase *pEmfInterpretator, const TEmfHeader& oHeader)
|
||||
CEmfPlusParser::CEmfPlusParser(CEmfInterpretatorBase *pEmfInterpretator, const TEmfHeader& oHeader)
|
||||
: m_bBanEmfProcessing(false),
|
||||
m_unLogicalDpiX(96),
|
||||
m_unLogicalDpiY(96),
|
||||
@ -153,32 +151,18 @@ namespace MetaFile
|
||||
|
||||
if (NULL != pEmfInterpretator)
|
||||
{
|
||||
if (pEmfInterpretator->GetType() == Emf)
|
||||
{
|
||||
m_pInterpretator = new CEmfInterpretator(*(CEmfInterpretator*)pEmfInterpretator);
|
||||
}
|
||||
else if (pEmfInterpretator->GetType() == Render)
|
||||
{
|
||||
m_pInterpretator = new CEmfInterpretatorRender(*(CEmfInterpretatorRender*)pEmfInterpretator, this);
|
||||
}
|
||||
else if (pEmfInterpretator->GetType() == XML)
|
||||
{
|
||||
m_pInterpretator = new CEmfInterpretatorXml(*(CEmfInterpretatorXml*)pEmfInterpretator);
|
||||
}
|
||||
else if (pEmfInterpretator->GetType() == Array)
|
||||
{
|
||||
m_pInterpretator = new CEmfInterpretatorArray(*(CEmfInterpretatorArray*)pEmfInterpretator);
|
||||
}
|
||||
m_pInterpretator = pEmfInterpretator;
|
||||
|
||||
m_pInterpretator->CreateConditional(this);
|
||||
}
|
||||
}
|
||||
|
||||
CEmfPlusParser::~CEmfPlusParser()
|
||||
{
|
||||
ClearFile();
|
||||
RELEASEOBJECT(m_pInterpretator);
|
||||
|
||||
for (EmfPlusObjects::const_iterator pIter = m_mObjects.begin(); pIter != m_mObjects.end(); ++pIter)
|
||||
delete[] pIter->second;
|
||||
delete pIter->second;
|
||||
}
|
||||
|
||||
bool CEmfPlusParser::OpenFromFile(const wchar_t *wsFilePath)
|
||||
@ -723,39 +707,7 @@ namespace MetaFile
|
||||
|
||||
m_oStream >> unCustomStartCapSize;
|
||||
|
||||
unsigned int unStart = m_oStream.Tell();
|
||||
|
||||
m_oStream.Skip(4); //Version
|
||||
|
||||
int nType;
|
||||
|
||||
m_oStream >> nType;
|
||||
|
||||
if (CustomLineCapDataTypeDefault == nType)
|
||||
{
|
||||
TEmfPlusCustomLineCapData *pLineCapData = new TEmfPlusCustomLineCapData;
|
||||
|
||||
m_oStream >> *pLineCapData;
|
||||
|
||||
if (CustomLineCapDataFillPath == pLineCapData->unCustomLineCapDataFlags ||
|
||||
CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags)
|
||||
{
|
||||
m_oStream.Skip(4); // FillPathLength or LinePathLength
|
||||
pLineCapData->pPath = ReadPath();
|
||||
}
|
||||
|
||||
pEmfPlusPen->LineStartCapData = pLineCapData;
|
||||
}
|
||||
else if (CustomLineCapDataTypeAdjustableArrow == nType)
|
||||
{
|
||||
TEmfPlusCustomLineCapArrowData *pLineCapData = new TEmfPlusCustomLineCapArrowData;
|
||||
|
||||
m_oStream >> *pLineCapData;
|
||||
|
||||
pEmfPlusPen->LineStartCapData = pLineCapData;
|
||||
}
|
||||
|
||||
m_oStream.Skip(unCustomStartCapSize - (m_oStream.Tell() - unStart));
|
||||
m_oStream.Skip(unCustomStartCapSize); // EmfPlusCustomStartCapData object
|
||||
}
|
||||
if (unFlags & PEN_DATA_CUSTOMENDCAP)
|
||||
{
|
||||
@ -763,39 +715,7 @@ namespace MetaFile
|
||||
|
||||
m_oStream >> unCustomEndCapSize;
|
||||
|
||||
unsigned int unStart = m_oStream.Tell();
|
||||
|
||||
m_oStream.Skip(4); //Version
|
||||
|
||||
int nType;
|
||||
|
||||
m_oStream >> nType;
|
||||
|
||||
if (CustomLineCapDataTypeDefault == nType)
|
||||
{
|
||||
TEmfPlusCustomLineCapData *pLineCapData = new TEmfPlusCustomLineCapData;
|
||||
|
||||
m_oStream >> *pLineCapData;
|
||||
|
||||
if (CustomLineCapDataFillPath == pLineCapData->unCustomLineCapDataFlags ||
|
||||
CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags)
|
||||
{
|
||||
m_oStream.Skip(4); // FillPathLength or LinePathLength
|
||||
pLineCapData->pPath = ReadPath();
|
||||
}
|
||||
|
||||
pEmfPlusPen->LineEndCapData = pLineCapData;
|
||||
}
|
||||
else if (CustomLineCapDataTypeAdjustableArrow == nType)
|
||||
{
|
||||
TEmfPlusCustomLineCapArrowData *pLineCapData = new TEmfPlusCustomLineCapArrowData;
|
||||
|
||||
m_oStream >> *pLineCapData;
|
||||
|
||||
pEmfPlusPen->LineEndCapData = pLineCapData;
|
||||
}
|
||||
|
||||
m_oStream.Skip(unCustomEndCapSize - (m_oStream.Tell() - unStart));
|
||||
m_oStream.Skip(unCustomEndCapSize); // EmfPlusCustomEndCapData object
|
||||
}
|
||||
|
||||
pEmfPlusPen->Brush = ReadBrush();
|
||||
@ -915,6 +835,8 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
return pPath;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -924,7 +846,7 @@ namespace MetaFile
|
||||
CEmfPlusPath *pPath = new CEmfPlusPath();
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unPathPointCount; ++unIndex)
|
||||
{
|
||||
{
|
||||
switch (ExpressValue(arPointTypes[unIndex], 0, 3))
|
||||
{
|
||||
case PathPointTypeStart: pPath->MoveTo(arPoints[unIndex].X, arPoints[unIndex].Y); break;
|
||||
@ -994,6 +916,16 @@ namespace MetaFile
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// std::vector<TEmfPlusPointF> CEmfPlusParser::ReadPointsF(unsigned int unPointCount)
|
||||
// {
|
||||
// std::vector<TEmfPlusPointF> arPoints(unPointCount);
|
||||
|
||||
// for (unsigned int unIndex = 0; unIndex < unPointCount; ++unIndex)
|
||||
// m_oStream >> arPoints[unIndex];
|
||||
|
||||
// return arPoints;
|
||||
// }
|
||||
|
||||
template<typename PointType>
|
||||
std::vector<PointType> CEmfPlusParser::ReadPoints(unsigned int unPointCount)
|
||||
{
|
||||
@ -1327,8 +1259,7 @@ namespace MetaFile
|
||||
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X, arPoints[2].Y - arPoints[0].Y,
|
||||
(NULL != pNewBuffer) ? pNewBuffer : pPixels, unWidth, unHeight);
|
||||
|
||||
if (NULL != pNewBuffer)
|
||||
delete [] pNewBuffer;
|
||||
RELEASEARRAYOBJECTS(pNewBuffer);
|
||||
}
|
||||
}
|
||||
else if (MetafileDataTypeWmf == eMetafileType ||
|
||||
@ -1407,8 +1338,7 @@ namespace MetaFile
|
||||
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X, arPoints[2].Y - arPoints[0].Y,
|
||||
(NULL != pNewBuffer) ? pNewBuffer : pPixels, unWidth, unHeight);
|
||||
|
||||
if (NULL != pNewBuffer)
|
||||
delete [] pNewBuffer;
|
||||
RELEASEARRAYOBJECTS(pNewBuffer);
|
||||
}
|
||||
}
|
||||
//TODO: общую часть в идеале нужно вынести
|
||||
@ -1421,14 +1351,24 @@ namespace MetaFile
|
||||
|
||||
NSFile::CFileBinary oFile;
|
||||
|
||||
const std::wstring wsFilePath = oFile.GetTempPath() + L"\\temp.tmp";
|
||||
const std::wstring wsFilePath = oFile.GetTempPath() + L"/temp.tmp";
|
||||
|
||||
if (!oFile.CreateFileW(wsFilePath))
|
||||
return;
|
||||
|
||||
if (!oFile.WriteFile(pBuffer, unSize))
|
||||
{
|
||||
oFile.CloseFile();
|
||||
return;
|
||||
}
|
||||
|
||||
oFile.CreateFileW(wsFilePath);
|
||||
oFile.WriteFile(pBuffer, unSize);
|
||||
oFile.CloseFile();
|
||||
|
||||
Aggplus::CImage oImage(wsFilePath);
|
||||
|
||||
if (Aggplus::WrongState == oImage.GetLastStatus())
|
||||
return;
|
||||
|
||||
unsigned int unWidth, unHeight;
|
||||
|
||||
unWidth = oImage.GetWidth();
|
||||
@ -1711,13 +1651,13 @@ namespace MetaFile
|
||||
m_oStream.ReadBytes(pString, unGlyphCount);
|
||||
}
|
||||
|
||||
std::wstring wsString;
|
||||
std::wstring wsString;
|
||||
|
||||
wsString = NSStringExt::CConverter::GetUnicodeFromUTF16((unsigned short*)pString, unGlyphCount);
|
||||
wsString = NSStringExt::CConverter::GetUnicodeFromUTF16((unsigned short*)pString, unGlyphCount);
|
||||
|
||||
RELEASEARRAYOBJECTS(pString)
|
||||
RELEASEARRAYOBJECTS(pString)
|
||||
|
||||
std::vector<TEmfPlusPointF> arGlyphPos = ReadPoints<TEmfPlusPointF>(unGlyphCount);
|
||||
std::vector<TEmfPlusPointF> arGlyphPos = ReadPoints<TEmfPlusPointF>(unGlyphCount);
|
||||
|
||||
if (0x00000001 == unMatrixPresent)
|
||||
{
|
||||
@ -1969,7 +1909,12 @@ namespace MetaFile
|
||||
CEmfPlusPath *pPath = GetPath(shOgjectIndex);
|
||||
|
||||
if (NULL != pPath)
|
||||
{
|
||||
{
|
||||
if (pPath->m_pCommands.size() == 2)
|
||||
{
|
||||
LOGGING(L"TEST")
|
||||
}
|
||||
|
||||
CEmfPlusPen *pEmfPlusPen = GetPen(unPenId);
|
||||
|
||||
if (NULL == pEmfPlusPen) return;
|
||||
@ -1979,13 +1924,7 @@ namespace MetaFile
|
||||
if (NULL != pEmfPlusPen->Brush)
|
||||
m_pDC->SetBrush(pEmfPlusPen->Brush);
|
||||
|
||||
CPathConverter oPathConverter;
|
||||
CEmfPath oNewPath, oLineCapPath;
|
||||
|
||||
oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen);
|
||||
|
||||
oNewPath.DrawWithoutClean(m_pInterpretator, true, false);
|
||||
oLineCapPath.DrawWithoutClean(m_pInterpretator, false, true);
|
||||
pPath->DrawWithoutClean(m_pInterpretator, true, false);
|
||||
|
||||
if (NULL != pEmfPlusPen->Brush)
|
||||
m_pDC->RemoveBrush(pEmfPlusPen->Brush);
|
||||
@ -2468,6 +2407,10 @@ namespace MetaFile
|
||||
{
|
||||
LOGGING(L"Object Pen with index: " << shObjectIndex)
|
||||
|
||||
if (10 == shObjectIndex)
|
||||
{
|
||||
LOGGING(L"TEST")
|
||||
}
|
||||
CEmfPlusPen *pEmfPlusPen = ReadPen();
|
||||
|
||||
RegisterObject(pEmfPlusPen, shObjectIndex);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#ifndef CEMFPLUSPARSER_H
|
||||
#define CEMFPLUSPARSER_H
|
||||
|
||||
#include "../../Common/MetaFileUtils.h"
|
||||
#include "../../Common/MetaFile.h"
|
||||
//#include "../../Common/MetaFileUtils.h"
|
||||
//#include "../../Common/MetaFile.h"
|
||||
#include "../EmfPlusObjects.h"
|
||||
#include "CEmfParserBase.h"
|
||||
#include "../EmfPlusTypes.h"
|
||||
@ -13,7 +13,7 @@ namespace MetaFile
|
||||
class CEmfPlusParser : public CEmfParserBase
|
||||
{
|
||||
public:
|
||||
CEmfPlusParser(const CEmfInterpretatorBase *pEmfInterpretator, const TEmfHeader& oHeader);
|
||||
CEmfPlusParser(CEmfInterpretatorBase *pEmfInterpretator, const TEmfHeader& oHeader);
|
||||
virtual ~CEmfPlusParser();
|
||||
|
||||
bool OpenFromFile(const wchar_t* wsFilePath) override;
|
||||
|
||||
@ -23,6 +23,10 @@ core_windows:CONFIG += no_batch
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/html/gumbo.pri)
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/html/css/CssCalculator.pri)
|
||||
|
||||
CONFIG += core_boost_libs
|
||||
CONFIG += core_boost_regex
|
||||
include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
|
||||
|
||||
ADD_DEPENDENCY(kernel, UnicodeConverter, graphics, kernel_network)
|
||||
|
||||
SOURCES += htmlfile2.cpp
|
||||
|
||||
@ -26,6 +26,8 @@
|
||||
#include "../DesktopEditor/graphics/pro/Graphics.h"
|
||||
#include "htmlfile2.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#ifndef VALUE2STR
|
||||
#define VALUE_TO_STRING(x) #x
|
||||
#define VALUE2STR(x) VALUE_TO_STRING(x)
|
||||
@ -103,10 +105,10 @@ public:
|
||||
|
||||
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));
|
||||
//Установим размер исходного и нового окна для Css калькулятора (должны быть одинаковые единицы измерения (желательно пункты))
|
||||
//Это нужно для масштабирования некоторых значений
|
||||
m_oStylesCalculator.SetSizeSourceWindow(NSCSS::CSizeWindow(4940 * (1366 / (8.26667 * m_oStylesCalculator.GetDpi())), 0));
|
||||
m_oStylesCalculator.SetSizeDeviceWindow(NSCSS::CSizeWindow(4940, 0));
|
||||
}
|
||||
|
||||
~CHtmlFile2_Private()
|
||||
@ -342,7 +344,7 @@ public:
|
||||
|
||||
if (m_bInP)
|
||||
m_oDocXml.WriteString(L"</w:p>");
|
||||
m_oDocXml.WriteString(L"<w:sectPr/></w:body></w:document>");
|
||||
m_oDocXml.WriteString(L"<w:sectPr w:rsidR=\"0007083F\" w:rsidRPr=\"0007083F\" w:rsidSect=\"0007612E\"><w:pgSz w:w=\"12240\" w:h=\"15840\"/><w:pgMar w:gutter=\"0\" w:footer=\"720\" w:header=\"720\" w:left=\"720\" w:bottom=\"720\" w:right=\"720\" w:top=\"720\"/><w:cols w:space=\"720\"/><w:docGrid w:linePitch=\"360\"/></w:sectPr></w:body></w:document>");
|
||||
NSFile::CFileBinary oDocumentWriter;
|
||||
if (oDocumentWriter.CreateFileW(m_sDst + L"/word/document.xml"))
|
||||
{
|
||||
@ -1066,6 +1068,7 @@ private:
|
||||
it2 = std::find_if(mTable.begin(), mTable.end(), [j] (const CTc& item){ return item.i == 0 && item.j == j; });
|
||||
}
|
||||
|
||||
GetSubClass(oXml, sSelectors);
|
||||
oXml->WriteString(L"<w:tc><w:tcPr><w:textDirection w:val=\"lrTb\"/><w:noWrap w:val=\"false\"/><w:tcBorders>");
|
||||
oXml->WriteString(!sBorders.empty() ? sBorders : L"<w:left w:val=\"none\" w:color=\"000000\"/><w:top w:val=\"none\" w:color=\"000000\"/><w:right w:val=\"none\" w:color=\"000000\"/><w:bottom w:val=\"none\" w:color=\"000000\"/>");
|
||||
oXml->WriteString(L"</w:tcBorders>");
|
||||
@ -1079,21 +1082,52 @@ private:
|
||||
for(int k = i + 1; k < i + nRowspan; k++)
|
||||
mTable.push_back({k, j, sColspan});
|
||||
}
|
||||
|
||||
NSCSS::CCompiledStyle oStyleSetting = m_oStylesCalculator.GetCompiledStyle({sSelectors.back()}, true);
|
||||
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle({sSelectors.back()}, false);
|
||||
|
||||
NSCSS::CCompiledStyle::StyleEquation(oStyle, oStyleSetting);
|
||||
|
||||
int nWidth = oStyle.m_pDisplay.GetWidth();
|
||||
std::wstring wsType = L"dxa";
|
||||
|
||||
//Если ширина указана в %, то используем тип dxa, если же в других ндтнтцах измерения, то в pct
|
||||
#if 1
|
||||
// проблема с regex в старом gcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52719)
|
||||
boost::wregex oWidthRegex(L"((width)+)[\\s]*:[\\s]*(.+%)");
|
||||
bool bIsWidthPct = boost::regex_search(sSelectors.back().m_sStyle, oWidthRegex);
|
||||
#else
|
||||
std::wregex oWidthRegex(L"((width)+)[\\s]*:[\\s]*(.+%)");
|
||||
bool bIsWidthPct = std::regex_search(sSelectors.back().m_sStyle.data(), oWidthRegex);
|
||||
#endif
|
||||
|
||||
if (bIsWidthPct)
|
||||
wsType = L"pct";
|
||||
else
|
||||
nWidth *= 10;
|
||||
//-------------------------
|
||||
|
||||
if (nWidth > 0)
|
||||
oXml->WriteString(L"<w:tcW w:w=\"" + std::to_wstring(nWidth) + L"\" w:type=\"" + wsType + L"\"/>");
|
||||
else
|
||||
oXml->WriteString(L"<w:tcW w:w=\"0\" w:type=\"auto\"/>");
|
||||
|
||||
if(nColspan != 1)
|
||||
{
|
||||
oXml->WriteString(L"<w:gridSpan w:val=\"");
|
||||
oXml->WriteString(std::to_wstring(nColspan));
|
||||
oXml->WriteString(L"\"/>");
|
||||
j += nColspan - 1;
|
||||
oXml->WriteString(L"<w:gridSpan w:val=\"");
|
||||
oXml->WriteString(std::to_wstring(nColspan - ((nColspan > 3) ? 1 : 0)));
|
||||
oXml->WriteString(L"\"/>");
|
||||
|
||||
j += nColspan - 1;
|
||||
}
|
||||
oXml->WriteString(L"</w:tcPr>");
|
||||
|
||||
oXml->WriteString(L"<w:hideMark/></w:tcPr>");
|
||||
size_t nEmpty = oXml->GetCurSize();
|
||||
m_bWasPStyle = false;
|
||||
|
||||
GetSubClass(oXml, sSelectors);
|
||||
// Читаем th. Ячейка заголовка таблицы. Выравнивание посередине. Выделяется полужирным
|
||||
if(m_oLightReader.GetName() == L"th")
|
||||
{
|
||||
{
|
||||
CTextSettings oTSR(oTS);
|
||||
oTSR.sRStyle += L"<w:b/>";
|
||||
readStream(oXml, sSelectors, oTSR);
|
||||
@ -1148,22 +1182,64 @@ private:
|
||||
|
||||
NSCSS::CCompiledStyle oStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors, false);
|
||||
|
||||
// Начало таблицы
|
||||
std::wstring wsTable = L"<w:tbl><w:tblPr><w:tblStyle w:val=\"\"/>";
|
||||
if (oXml->GetSubData(oXml->GetCurSize() - 6) != L"</w:p>")
|
||||
oXml->WriteString(L"<w:p><w:pPr><w:spacing w:beforeLines=\"0\" w:before=\"0\" w:afterLines=\"0\" w:after=\"0\"/><w:rPr><w:vanish/><w:sz w:val=\"2\"/><w:szCs w:val=\"2\"/></w:rPr></w:pPr></w:p>");
|
||||
|
||||
std::wstring wsWidth = oStyle.m_pDisplay.GetWidthW();
|
||||
// Начало таблицы
|
||||
std::wstring wsTable = L"<w:tbl><w:tblPr>";
|
||||
|
||||
int nWidth = oStyle.m_pDisplay.GetWidth();
|
||||
std::wstring wsAlign = oStyle.m_pDisplay.GetAlign();
|
||||
|
||||
if (!wsWidth.empty())
|
||||
wsTable += L"<w:tblW w:w=\"" + wsWidth + L"\" w:type=\"pct\"/>";
|
||||
if (0 < nWidth)
|
||||
wsTable += L"<w:tblW w:w=\"" + std::to_wstring(nWidth) + 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())
|
||||
{
|
||||
NSCSS::CNode oLastNode = sSelectors.back();
|
||||
sSelectors.pop_back();
|
||||
|
||||
NSCSS::CCompiledStyle oTempSettingsStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors, true);
|
||||
|
||||
wsAlign = oTempSettingsStyle.m_pText.GetAlign();
|
||||
|
||||
if (wsAlign.empty())
|
||||
{
|
||||
NSCSS::CCompiledStyle oTempStyle = m_oStylesCalculator.GetCompiledStyle(sSelectors, false);
|
||||
|
||||
wsAlign = oTempStyle.m_pText.GetAlign();
|
||||
}
|
||||
|
||||
sSelectors.push_back(oLastNode);
|
||||
}
|
||||
|
||||
if (!oStyle.m_pMargin.Empty() && (0 < oStyle.m_pMargin.GetTopSide() || 0 < oStyle.m_pMargin.GetBottomSide()))
|
||||
{
|
||||
wsTable += L"<w:tblCellMar>";
|
||||
|
||||
if (0 < oStyle.m_pMargin.GetTopSide())
|
||||
wsTable += L"<w:top w:w=\"" + std::to_wstring(static_cast<short int>(oStyle.m_pMargin.GetTopSide() * 10 + 0.5f)) + L"\" w:type=\"dxa\"/>";
|
||||
|
||||
// if (0 < oStyle.m_pMargin.GetLeftSide())
|
||||
// wsTable += L"<w:left w:w=\"" + std::to_wstring(static_cast<short int>(oStyle.m_pMargin.GetLeftSide() * 10 + 0.5f)) + L"\" w:type=\"dxa\"/>";
|
||||
|
||||
if (0 < oStyle.m_pMargin.GetBottomSide())
|
||||
wsTable += L"<w:bottom w:w=\"" + std::to_wstring(static_cast<short int>(oStyle.m_pMargin.GetBottomSide() * 10 + 0.5f)) + L"\" w:type=\"dxa\"/>";
|
||||
|
||||
// if (0 < oStyle.m_pMargin.GetRightSide())
|
||||
// wsTable += L"<w:right w:w=\"" + std::to_wstring(static_cast<short int>(oStyle.m_pMargin.GetRightSide() * 10 + 0.5f)) + L"\" w:type=\"dxa\"/>";
|
||||
|
||||
wsTable += L"</w:tblCellMar>";
|
||||
}
|
||||
|
||||
if (!wsAlign.empty())
|
||||
wsTable += L"<w:jc w:val=\"" + wsAlign + L"\"/>";
|
||||
|
||||
wsTable += L"<w:tblLook w:val=\"04A0\" w:noVBand=\"1\" w:noHBand=\"0\" w:lastColumn=\"0\" w:firstColumn=\"1\" w:lastRow=\"0\" w:firstRow=\"1\"/>";
|
||||
wsTable += L"</w:tblPr>";
|
||||
|
||||
// borders
|
||||
@ -1171,8 +1247,7 @@ private:
|
||||
oStyle.m_pBorder.Unlock();
|
||||
if (oStyle.m_pBorder.Empty())
|
||||
{
|
||||
wsTable.insert(35, L"table");
|
||||
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
|
||||
{
|
||||
@ -1182,11 +1257,6 @@ private:
|
||||
std::wstring sSz = oStyle.m_pBorder.GetWidthBottomSideW();
|
||||
std::wstring sStyle = oStyle.m_pBorder.GetStyleBottomSide();
|
||||
|
||||
if (L"none" == sStyle)
|
||||
wsTable.insert(35, oStyle.GetId());
|
||||
else
|
||||
wsTable.insert(35, L"table");
|
||||
|
||||
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\"/>" +
|
||||
@ -1641,7 +1711,9 @@ private:
|
||||
size_t i = 0;
|
||||
while(i != sSelectors.size())
|
||||
{
|
||||
if(rStyle.find(L' ' + sSelectors[i].m_sName + L' ') != std::wstring::npos)
|
||||
if(rStyle.find(L' ' + sSelectors[i].m_sName + L' ') != std::wstring::npos &&
|
||||
sSelectors[i].m_sClass.empty() && sSelectors[i].m_sId.empty() &&
|
||||
sSelectors[i].m_sStyle.empty() && sSelectors[i].m_mAttrs.empty())
|
||||
{
|
||||
temporary.push_back(std::make_pair(i, sSelectors[i]));
|
||||
sSelectors.erase(sSelectors.begin() + i);
|
||||
|
||||
@ -97,7 +97,7 @@ int main()
|
||||
oParams.SetDescription(L"Description");
|
||||
|
||||
// Файл, который открываем
|
||||
std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/PrintRK.html";
|
||||
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));
|
||||
|
||||
@ -52,6 +52,7 @@
|
||||
#include "../DesktopEditor/graphics/pro/Image.h"
|
||||
|
||||
#include "../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "../Common/Network/FileTransporter/include/FileTransporter.h"
|
||||
|
||||
#include "OnlineOfficeBinToPdf.h"
|
||||
|
||||
@ -1230,8 +1231,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)
|
||||
{
|
||||
@ -1257,6 +1272,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)
|
||||
@ -1404,13 +1427,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);
|
||||
@ -1436,18 +1462,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;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Функции для выставления преобразования
|
||||
@ -2788,3 +2813,36 @@ unsigned char* CPdfRenderer::EncodeGID(const unsigned int& unGID, const unsigned
|
||||
pCodes[1] = ushCode & 0xFF;
|
||||
return pCodes;
|
||||
}
|
||||
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"";
|
||||
}
|
||||
|
||||
@ -243,12 +243,13 @@ 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);
|
||||
unsigned char* EncodeString(const unsigned int* pUnicodes, const unsigned int& unUnicodesCount, const unsigned int* pGIDs = NULL);
|
||||
unsigned char* EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount);
|
||||
std::wstring GetDownloadFile(const std::wstring& sUrl);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user