mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 00:03:33 +08:00
revert revisions 59572, 59565, 59564, 59563, 59556, 59550, 59548, 59547, 59546, 59545, 59544, 59543, 59542, 59541, 59533, 59531, 59523, 59519, 59503, 59499, 59490. git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@59588 954022d7-b5bf-4e40-9824-e11837661b57
107 lines
3.4 KiB
C++
107 lines
3.4 KiB
C++
#ifndef FONT_TABLE_WRITER
|
|
#define FONT_TABLE_WRITER
|
|
|
|
#include "../../XlsxSerializerCom/Common/Common.h"
|
|
#include "../../DesktopEditor/fontengine/FontManager.h"
|
|
|
|
namespace Writers
|
|
{
|
|
static CString g_string_ft_Start = _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:fonts xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" mc:Ignorable=\"w14\">");
|
|
static CString g_string_ft_End = _T("</w:fonts>");
|
|
|
|
class FontTableWriter
|
|
{
|
|
XmlUtils::CStringWriter m_oWriter;
|
|
CString m_sDir;
|
|
CApplicationFonts m_oApplicationFonts;
|
|
CFontManager* m_pFontManager;
|
|
public:
|
|
std::map<CString, int> m_mapFonts;
|
|
public:
|
|
FontTableWriter(CString sDir, CString sFontDir):m_sDir(sDir)
|
|
{
|
|
if(sFontDir.IsEmpty())
|
|
m_oApplicationFonts.Initialize();
|
|
else
|
|
m_oApplicationFonts.InitializeFromFolder(string2std_string(sFontDir));
|
|
CFontList* pFontList = m_oApplicationFonts.GetList();
|
|
if(NULL != pFontList)
|
|
{
|
|
std::wstring sDefaultFont(_T("Arial"));
|
|
pFontList->SetDefaultFont(sDefaultFont);
|
|
}
|
|
m_pFontManager = m_oApplicationFonts.GenerateFontManager();
|
|
}
|
|
~FontTableWriter()
|
|
{
|
|
RELEASEOBJECT(m_pFontManager);
|
|
}
|
|
|
|
void Write()
|
|
{
|
|
m_oWriter.WriteString(g_string_ft_Start);
|
|
|
|
//Òå øðèôòû êîòîðûå âñåãäà ïèøåì â FontTable
|
|
bool bCalibri = false;
|
|
bool bTimes = false;
|
|
bool bCambria = false;
|
|
for (std::map<CString, int>::const_iterator it = m_mapFonts.begin(); it != m_mapFonts.end(); ++it)
|
|
{
|
|
const CString& sFontName = it->first;
|
|
if(_T("Calibri") == sFontName)
|
|
bCalibri = true;
|
|
else if(_T("Times New Roman") == sFontName)
|
|
bTimes = true;
|
|
else if(_T("Cambria") == sFontName)
|
|
bCambria = true;
|
|
WriteFont(sFontName);
|
|
}
|
|
if(false == bCalibri)
|
|
WriteFont(_T("Calibri"));
|
|
if(false == bTimes)
|
|
WriteFont(_T("Times New Roman"));
|
|
if(false == bCambria)
|
|
WriteFont(_T("Cambria"));
|
|
|
|
m_oWriter.WriteString(g_string_ft_End);
|
|
|
|
CFile oFile;
|
|
oFile.CreateFile(m_sDir + _T("\\word\\fontTable.xml"));
|
|
oFile.WriteStringUTF8(m_oWriter.GetData());
|
|
oFile.CloseFile();
|
|
}
|
|
void WriteFont(CString sFontName)
|
|
{
|
|
CString sPanose;
|
|
bool bUsePanose = false;
|
|
if(NULL != m_pFontManager)
|
|
{
|
|
CFontSelectFormat oFontSelectFormat;
|
|
oFontSelectFormat.wsName = new std::wstring;
|
|
*oFontSelectFormat.wsName = std::wstring(sFontName.GetString());
|
|
CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelectFormat);
|
|
if(NULL != pFontInfo)
|
|
{
|
|
for(int i = 0; i < 10; ++i)
|
|
{
|
|
BYTE cElem = pFontInfo->m_aPanose[i];
|
|
if(0 != cElem)
|
|
bUsePanose = true;
|
|
if(cElem > 0xF)
|
|
sPanose.AppendFormat(_T("%X"), cElem);
|
|
else
|
|
sPanose.AppendFormat(_T("0%X"), cElem);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
sFontName = XmlUtils::EncodeXmlString(sFontName);
|
|
m_oWriter.WriteString(_T("<w:font w:name=\"") + sFontName + _T("\">"));
|
|
if(bUsePanose && !sPanose.IsEmpty())
|
|
m_oWriter.WriteString(_T("<w:panose1 w:val=\"")+sPanose+_T("\"/>"));
|
|
m_oWriter.WriteString(CString(_T("</w:font>")));
|
|
}
|
|
};
|
|
}
|
|
#endif // #ifndef FONT_TABLE_WRITER
|