Files
core/ASCOfficePPTXFile/PPTXFormat/Logic/TxBody.cpp
Elen.Subbotina 2276da418e правки под Linux после исправлений под iOs . BOOL -> bool (TRUE->true, FALSE->false)
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62078 954022d7-b5bf-4e40-9824-e11837661b57
2016-05-20 23:57:10 +03:00

356 lines
11 KiB
C++

#pragma once
//#include "stdafx.h"
#include "./TxBody.h"
#include "../Theme.h"
#include "./ClrMap.h"
namespace PPTX
{
namespace Logic
{
CString TxBody::GetDocxTxBoxContent(NSBinPptxRW::CBinaryFileWriter* pWriter, const nullable<ShapeStyle>& shape_style)
{
CString strXml = _T("<w:txbxContent ");
strXml += _T("\
xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" \
xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" \
xmlns:o=\"urn:schemas-microsoft-com:office:office\" \
xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" \
xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" \
xmlns:v=\"urn:schemas-microsoft-com:vml\" \
xmlns:ve=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" \
xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" \
xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" \
xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" \
xmlns:w10=\"urn:schemas-microsoft-com:office:word\" \
xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" \
xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" \
xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" \
xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" \
xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" \
xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" \
xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" \
xmlns:a14=\"http://schemas.microsoft.com/office/drawing/2010/main\" \
xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"");
strXml += _T(">");
smart_ptr<PPTX::WrapperFile> pTheme = pWriter->ThemeDoc->smart_dynamic_cast<PPTX::WrapperFile>();
smart_ptr<PPTX::WrapperWritingElement> pClrMap = pWriter->ClrMapDoc->smart_dynamic_cast<PPTX::WrapperWritingElement>();
CString sThemeFont = _T("");
DWORD dwColor = 0;
if (shape_style.is_init() && shape_style->fontRef.idx.is_init())
{
if (shape_style->fontRef.idx->get() == _T("major"))
sThemeFont = _T("+mj-lt");
else
sThemeFont = _T("+mn-lt");
}
NSBinPptxRW::CXmlWriter oWriter;
oWriter.WriteString(strXml);
double dKoef = 635; // emu -> 20pt
size_t nCount = Paragrs.size();
for (size_t i = 0; i < nCount; ++i)
{
PPTX::Logic::Paragraph& oPar = Paragrs[i];
oWriter.StartNode(_T("w:p"));
oWriter.StartAttributes();
oWriter.EndAttributes();
nullable<PPTX::Logic::RunProperties> pRunProps;
pRunProps = new PPTX::Logic::RunProperties();
if (oPar.pPr.is_init())
{
nullable<PPTX::Logic::TextParagraphPr> pPr;
pPr = new PPTX::Logic::TextParagraphPr();
if (oPar.pPr->lvl.is_init() && lstStyle.is_init())
{
int nLvl = *oPar.pPr->lvl;
if (nLvl >= 0 && nLvl < 10)
{
if (lstStyle->levels[nLvl].is_init())
{
lstStyle->levels[nLvl]->Merge(pPr);
if (lstStyle->levels[nLvl]->defRPr.is_init())
lstStyle->levels[nLvl]->defRPr->Merge(pRunProps);
}
}
}
oPar.pPr->Merge(pPr);
if (pPr->indent.is_init() || pPr->marL.is_init() || pPr->marR.is_init())
{
oWriter.StartNode(_T("w:ind"));
oWriter.StartAttributes();
if (oPar.pPr->marL.is_init())
oWriter.WriteAttribute(_T("w:left"), (int)((double)(*pPr->marL) / 635));
if (oPar.pPr->marR.is_init())
oWriter.WriteAttribute(_T("w:right"), (int)((double)(*pPr->marR) / 635));
if (oPar.pPr->indent.is_init())
oWriter.WriteAttribute(_T("w:firstLine"), (int)((double)(*pPr->indent) / 635));
oWriter.EndAttributes();
oWriter.EndNode(_T("w:ind"));
}
if (true)
{
oWriter.WriteString(_T("<w:spacing w:before=\"0\" w:after=\"0\" />"));
}
if (pPr->algn.is_init())
{
LONG _code = pPr->algn->GetBYTECode();
oWriter.StartNode(_T("w:jc"));
switch (_code)
{
case 0:
// center
oWriter.WriteAttribute(_T("w:val"), (CString)_T("center"));
break;
case 2:
case 3:
// both
oWriter.WriteAttribute(_T("w:val"), (CString)_T("both"));
break;
case 5:
// right
oWriter.WriteAttribute(_T("w:val"), (CString)_T("right"));
break;
default:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("left"));
break;
}
oWriter.EndAttributes();
oWriter.EndNode(_T("w:jc"));
}
if (pPr->fontAlgn.is_init())
{
BYTE nFA = pPr->fontAlgn->GetBYTECode();
oWriter.StartNode(_T("w:textAlignment"));
switch (nFA)
{
case 0:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("auto"));
break;
case 1:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("bottom"));
break;
case 2:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("baseline"));
break;
case 3:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("center"));
break;
case 4:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("top"));
break;
default:
oWriter.WriteAttribute(_T("w:val"), (CString)_T("baseline"));
break;
}
oWriter.EndAttributes();
oWriter.EndNode(_T("w:textAlignment"));
}
}
size_t nCountRuns = oPar.RunElems.size();
for (size_t j = 0; j < nCountRuns; ++j)
{
if (oPar.RunElems[j].is<PPTX::Logic::Run>())
{
PPTX::Logic::Run& oRun = oPar.RunElems[j].as<PPTX::Logic::Run>();
nullable<PPTX::Logic::RunProperties> pRPr;
pRPr = new PPTX::Logic::RunProperties();
if (_T("") != sThemeFont)
{
pRPr->latin = new PPTX::Logic::TextFont();
pRPr->latin->typeface = sThemeFont;
pRPr->ea = new PPTX::Logic::TextFont();
pRPr->ea->typeface = sThemeFont;
pRPr->cs = new PPTX::Logic::TextFont();
pRPr->cs->typeface = sThemeFont;
pRPr->sym = new PPTX::Logic::TextFont();
pRPr->sym->typeface = sThemeFont;
}
pRunProps->Merge(pRPr);
if (oRun.rPr.is_init())
oRun.rPr->Merge(pRPr);
bool bIsWriteColor = false;
DWORD dwColor = 0;
if (pRPr->Fill.is_init() && pRPr->Fill.is<PPTX::Logic::SolidFill>())
{
PPTX::Logic::SolidFill& oFill = pRPr->Fill.as<PPTX::Logic::SolidFill>();
if (oFill.Color.is_init())
{
bIsWriteColor = true;
dwColor = oFill.Color.GetRGBColor(pTheme, pClrMap, 0);
}
}
else if (shape_style.is_init() && shape_style->fontRef.Color.is_init())
{
bIsWriteColor = true;
dwColor = shape_style->fontRef.Color.GetRGBColor(pTheme, pClrMap, 0);
}
oWriter.StartNode(_T("w:r"));
oWriter.EndAttributes();
// run props
oWriter.StartNode(_T("w:rPr"));
oWriter.EndAttributes();
if (pRPr->latin.is_init() || pRPr->ea.is_init() || pRPr->cs.is_init())
{
oWriter.StartNode(_T("w:rFonts"));
if (pRPr->latin.is_init())
{
CString sPick = pWriter->m_pCommon->m_pNativePicker->GetTypefacePick(pRPr->latin.get2());
if (sPick == _T("minor") || sPick == _T("+mn-lt"))
{
oWriter.WriteAttribute(_T("w:asciiTheme"), (CString)_T("minorHAnsi"));
oWriter.WriteAttribute(_T("w:hAnsiTheme"), (CString)_T("minorHAnsi"));
}
else if (sPick == _T("major") || sPick == _T("+mj-lt"))
{
oWriter.WriteAttribute(_T("w:asciiTheme"), (CString)_T("majorHAnsi"));
oWriter.WriteAttribute(_T("w:hAnsiTheme"), (CString)_T("majorHAnsi"));
}
else
{
oWriter.WriteAttribute(_T("w:ascii"), sPick);
oWriter.WriteAttribute(_T("w:hAnsi"), sPick);
}
}
if (pRPr->ea.is_init())
{
CString sPick = pWriter->m_pCommon->m_pNativePicker->GetTypefacePick(pRPr->ea.get2());
if (sPick == _T("minor") || sPick == _T("+mn-lt"))
{
oWriter.WriteAttribute(_T("w:eastAsiaTheme"), (CString)_T("minorEastAsia"));
}
else if (sPick == _T("major") || sPick == _T("+mj-lt"))
{
oWriter.WriteAttribute(_T("w:eastAsiaTheme"), (CString)_T("majorEastAsia"));
}
else
{
oWriter.WriteAttribute(_T("w:eastAsia"), sPick);
}
}
if (pRPr->cs.is_init())
{
CString sPick = pWriter->m_pCommon->m_pNativePicker->GetTypefacePick(pRPr->cs.get2());
if (sPick == _T("minor") || sPick == _T("+mn-lt"))
{
oWriter.WriteAttribute(_T("w:cstheme"), (CString)_T("minorBidi"));
}
else if (sPick == _T("major") || sPick == _T("+mj-lt"))
{
oWriter.WriteAttribute(_T("w:cstheme"), (CString)_T("majorBidi"));
}
else
{
oWriter.WriteAttribute(_T("w:cs"), sPick);
}
}
oWriter.WriteNodeEnd(_T("w:rFonts"), true, true);
}
if (bIsWriteColor)
{
BYTE _r = (BYTE)((dwColor >> 16) & 0xFF);
BYTE _g = (BYTE)((dwColor >> 8) & 0xFF);
BYTE _b = (BYTE)((dwColor) & 0xFF);
CString sHex = _T("");
sHex.Format(_T("<w:color w:val=\"%02X%02X%02X\" />"), _r, _g, _b);
oWriter.WriteString(sHex);
}
if (pRPr->b.get_value_or(false))
oWriter.WriteString(_T("<w:b/>"));
if (pRPr->i.get_value_or(false))
oWriter.WriteString(_T("<w:i/>"));
if (pRPr->strike.is_init())
{
BYTE lType = pRPr->strike->GetBYTECode();
if (0 == lType)
oWriter.WriteString(_T("<w:dstrike/>"));
else if (2 == lType)
oWriter.WriteString(_T("<w:strike/>"));
}
if (pRPr->sz.is_init())
{
double dSize = (double)pRPr->sz.get();
dSize /= 100;
int nSize = (int)(dSize * 2);
CString strFS = _T("");
strFS.Format(_T("<w:sz w:val=\"%d\"/><w:szCs w:val=\"%d\"/>"), nSize, nSize);
oWriter.WriteString(strFS);
}
if (pRPr->u.is_init())
{
BYTE lType = pRPr->u->GetBYTECode();
if (12 != lType)
oWriter.WriteString(_T("<w:u w:val=\"single\"/>"));
}
oWriter.EndNode(_T("w:rPr"));
oWriter.StartNode(_T("w:t"));
oWriter.StartAttributes();
oWriter.WriteAttribute(_T("xml:space"), (CString)_T("preserve"));
oWriter.EndAttributes();
oWriter.WriteString(oRun.GetText());
oWriter.EndNode(_T("w:t"));
oWriter.EndNode(_T("w:r"));
}
}
oWriter.EndNode(_T("w:p"));
}
oWriter.WriteString(_T("</w:txbxContent>"));
return oWriter.GetXmlString();
}
} // namespace Logic
} // namespace PPTX