init repo
This commit is contained in:
4258
ActiveX/XlsxSerializerCom/Reader/BinaryWriter.h
Normal file
4258
ActiveX/XlsxSerializerCom/Reader/BinaryWriter.h
Normal file
File diff suppressed because it is too large
Load Diff
250
ActiveX/XlsxSerializerCom/Reader/CSVReader.h
Normal file
250
ActiveX/XlsxSerializerCom/Reader/CSVReader.h
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <stack>
|
||||
|
||||
namespace CSVReader
|
||||
{
|
||||
void AddCell(CString &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, BOOL bIsWrap)
|
||||
{
|
||||
while(!oDeleteChars.empty())
|
||||
{
|
||||
INT nIndex = oDeleteChars.top() - nStartCell;
|
||||
sText.Delete(nIndex);
|
||||
oDeleteChars.pop();
|
||||
}
|
||||
|
||||
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
|
||||
pCell->m_oType.Init();
|
||||
|
||||
WCHAR *pEndPtr;
|
||||
LONG lValue = wcstol(sText, &pEndPtr, 10);
|
||||
if (NULL != *pEndPtr)
|
||||
{
|
||||
|
||||
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
|
||||
pCell->m_oRichText.Init();
|
||||
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
|
||||
pText->m_sText = sText;
|
||||
pCell->m_oRichText->m_arrItems.Add(pText);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeNumber);
|
||||
pCell->m_oValue.Init();
|
||||
pCell->m_oValue->m_sText = sText;
|
||||
}
|
||||
|
||||
if (bIsWrap)
|
||||
{
|
||||
|
||||
pCell->m_oStyle.Init();
|
||||
pCell->m_oStyle->SetValue(1);
|
||||
}
|
||||
|
||||
pCell->m_oRef.Init();
|
||||
pCell->m_oRef = OOX::Spreadsheet::CWorksheet::combineRef(nRow, nCol);
|
||||
oRow.m_arrItems.Add(pCell);
|
||||
}
|
||||
void ReadFromCsvToXlsx(CString &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, CONST WCHAR wcDelimiter)
|
||||
{
|
||||
|
||||
oXlsx.CreateWorkbook();
|
||||
|
||||
oXlsx.CreateStyles();
|
||||
|
||||
|
||||
OOX::Spreadsheet::CStyles *pStyles = oXlsx.GetStyles();
|
||||
pStyles->m_oCellXfs.Init();
|
||||
pStyles->m_oCellXfs->m_oCount.Init();
|
||||
pStyles->m_oCellXfs->m_oCount->SetValue(2);
|
||||
|
||||
|
||||
OOX::Spreadsheet::CXfs* pXfs = NULL;
|
||||
pXfs = new OOX::Spreadsheet::CXfs();
|
||||
pXfs->m_oBorderId.Init();
|
||||
pXfs->m_oBorderId->SetValue(0);
|
||||
pXfs->m_oFillId.Init();
|
||||
pXfs->m_oFillId->SetValue(0);
|
||||
pXfs->m_oFontId.Init();
|
||||
pXfs->m_oFontId->SetValue(0);
|
||||
pXfs->m_oNumFmtId.Init();
|
||||
pXfs->m_oNumFmtId->SetValue(0);
|
||||
pStyles->m_oCellXfs->m_arrItems.Add(pXfs);
|
||||
|
||||
|
||||
pXfs = new OOX::Spreadsheet::CXfs();
|
||||
pXfs->m_oBorderId.Init();
|
||||
pXfs->m_oBorderId->SetValue(0);
|
||||
pXfs->m_oFillId.Init();
|
||||
pXfs->m_oFillId->SetValue(0);
|
||||
pXfs->m_oFontId.Init();
|
||||
pXfs->m_oFontId->SetValue(0);
|
||||
pXfs->m_oNumFmtId.Init();
|
||||
pXfs->m_oNumFmtId->SetValue(0);
|
||||
|
||||
pXfs->m_oApplyAlignment.Init();
|
||||
pXfs->m_oApplyAlignment->SetValue(SimpleTypes::onoffTrue);
|
||||
pXfs->m_oAligment.Init();
|
||||
pXfs->m_oAligment->m_oWrapText.Init();
|
||||
pXfs->m_oAligment->m_oWrapText->SetValue(SimpleTypes::onoffTrue);
|
||||
pStyles->m_oCellXfs->m_arrItems.Add(pXfs);
|
||||
|
||||
CString sSheetRId = _T("rId1");
|
||||
OOX::Spreadsheet::CWorksheet* pWorksheet = new OOX::Spreadsheet::CWorksheet();
|
||||
pWorksheet->m_oSheetData.Init();
|
||||
OOX::Spreadsheet::CSheet *pSheet = new OOX::Spreadsheet::CSheet();
|
||||
pSheet->m_oRid.Init();
|
||||
pSheet->m_oRid->SetValue(sSheetRId);
|
||||
|
||||
OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook();
|
||||
pWorkbook->m_oSheets.Init();
|
||||
pWorkbook->m_oSheets->m_arrItems.Add(pSheet);
|
||||
|
||||
MemoryMapping::CMappingFile oMappingFile = MemoryMapping::CMappingFile();
|
||||
if(FALSE != oMappingFile.Open(sFileName))
|
||||
{
|
||||
long nFileSize = oMappingFile.GetSize();
|
||||
LPCSTR pFileData = (LPCSTR)oMappingFile.GetData();
|
||||
|
||||
INT nSize = MultiByteToWideChar(nCodePage, 0, pFileData, nFileSize, NULL, 0);
|
||||
WCHAR *pTemp = new WCHAR [nSize];
|
||||
::ZeroMemory (pTemp, sizeof(WCHAR) * nSize);
|
||||
MultiByteToWideChar (nCodePage, 0, pFileData, nFileSize, pTemp, nSize);
|
||||
oMappingFile.Close();
|
||||
|
||||
CONST WCHAR wcNewLineN = _T('\n');
|
||||
CONST WCHAR wcNewLineR = _T('\r');
|
||||
CONST WCHAR wcQuote = _T('"');
|
||||
CONST WCHAR wcTab = _T('\t');
|
||||
|
||||
BOOL bIsWrap = FALSE;
|
||||
WCHAR wcCurrent;
|
||||
INT nStartCell = 0;
|
||||
std::stack<INT> oDeleteChars;
|
||||
BOOL bInQuote = FALSE;
|
||||
INT nIndexRow = 0;
|
||||
INT nIndexCol = 0;
|
||||
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(nIndexRow + 1);
|
||||
for (INT nIndex = 0; nIndex < nSize; ++nIndex)
|
||||
{
|
||||
wcCurrent = pTemp[nIndex];
|
||||
if (wcDelimiter == wcCurrent)
|
||||
{
|
||||
if (bInQuote)
|
||||
continue;
|
||||
|
||||
CString sCellText(pTemp + nStartCell, nIndex - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = FALSE;
|
||||
|
||||
nStartCell = nIndex + 1;
|
||||
if (nStartCell == nSize)
|
||||
{
|
||||
pWorksheet->m_oSheetData->m_arrItems.Add(pRow);
|
||||
pRow = NULL;
|
||||
}
|
||||
}
|
||||
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
|
||||
{
|
||||
if (bInQuote)
|
||||
{
|
||||
|
||||
bIsWrap = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nStartCell != nIndex)
|
||||
{
|
||||
CString sCellText(pTemp + nStartCell, nIndex - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
bIsWrap = FALSE;
|
||||
}
|
||||
|
||||
nStartCell = nIndex + 1;
|
||||
|
||||
pWorksheet->m_oSheetData->m_arrItems.Add(pRow);
|
||||
pRow = new OOX::Spreadsheet::CRow();
|
||||
pRow->m_oR.Init();
|
||||
pRow->m_oR->SetValue(++nIndexRow + 1);
|
||||
nIndexCol = 0;
|
||||
}
|
||||
else if (wcQuote == wcCurrent)
|
||||
{
|
||||
|
||||
if (FALSE == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
|
||||
{
|
||||
|
||||
bInQuote = !bInQuote;
|
||||
nStartCell = nIndex + 1;
|
||||
}
|
||||
else if (TRUE == bInQuote)
|
||||
{
|
||||
|
||||
oDeleteChars.push(nIndex);
|
||||
|
||||
|
||||
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
|
||||
++nIndex;
|
||||
else
|
||||
bInQuote = !bInQuote;
|
||||
}
|
||||
}
|
||||
else if (wcTab == wcCurrent)
|
||||
{
|
||||
|
||||
oDeleteChars.push(nIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (nStartCell != nSize)
|
||||
{
|
||||
|
||||
CString sCellText(pTemp + nStartCell, nSize - nStartCell);
|
||||
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
|
||||
pWorksheet->m_oSheetData->m_arrItems.Add(pRow);
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASEOBJECT(pRow);
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pTemp);
|
||||
}
|
||||
|
||||
CAtlMap<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
|
||||
arrWorksheets.SetAt(sSheetRId, pWorksheet);
|
||||
}
|
||||
}
|
||||
153
ActiveX/XlsxSerializerCom/Reader/FontProcessor.cpp
Normal file
153
ActiveX/XlsxSerializerCom/Reader/FontProcessor.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "FontProcessor.h"
|
||||
|
||||
namespace XlsxReader {
|
||||
|
||||
FontProcessor::FontProcessor()
|
||||
: m_pFontManager(NULL) {}
|
||||
|
||||
FontProcessor::~FontProcessor() {
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
}
|
||||
|
||||
void FontProcessor::setFontDir(const CString& fontDir) {
|
||||
this->m_sFontDir = fontDir;
|
||||
initFontManager();
|
||||
}
|
||||
void FontProcessor::setFontTable(const OOX::Spreadsheet::CFonts& oFonts) {
|
||||
for (int i = 0, length = oFonts.m_arrItems.GetSize(); i < length; ++i)
|
||||
{
|
||||
OOX::Spreadsheet::WritingElement* we = oFonts.m_arrItems[i];
|
||||
if(OOX::Spreadsheet::et_Font == we->getType())
|
||||
{
|
||||
OOX::Spreadsheet::CFont* pFont = static_cast<OOX::Spreadsheet::CFont*>(we);
|
||||
if(NULL != pFont)
|
||||
addToFontMap(pFont);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CString FontProcessor::getFont(const CString& name) {
|
||||
CString fontName = _T("Arial");
|
||||
if (fontMap.find(name) != fontMap.end())
|
||||
fontName = fontMap[name];
|
||||
else
|
||||
{
|
||||
OOX::CFont font;
|
||||
font.m_sName = name;
|
||||
addToFontMap(font);
|
||||
if (fontMap.find(name) != fontMap.end())
|
||||
fontName = fontMap[name];
|
||||
}
|
||||
return fontName;
|
||||
}
|
||||
|
||||
void FontProcessor::initFontManager() {
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
CoCreateInstance(__uuidof(AVSGraphics::CAVSFontManager), NULL, CLSCTX_ALL, __uuidof(AVSGraphics::IAVSFontManager), (void**) &m_pFontManager);
|
||||
|
||||
VARIANT var;
|
||||
var.vt = VT_BSTR;
|
||||
var.bstrVal = m_sFontDir.AllocSysString();
|
||||
m_pFontManager->SetAdditionalParam(L"InitializeFromFolder", var);
|
||||
RELEASESYSSTRING(var.bstrVal);
|
||||
|
||||
CString defaultFontName = _T("Arial");
|
||||
BSTR defFontName = defaultFontName.AllocSysString();
|
||||
fontManager->SetDefaultFont(defFontName);
|
||||
SysFreeString(defFontName);
|
||||
}
|
||||
|
||||
void FontProcessor::addToFontMap(OOX::Spreadsheet::CFont* pFont) {
|
||||
CString parw;
|
||||
parw += _T("<FontProperties>");
|
||||
if(pFont->m_oCharset.IsInit() && pFont->m_oCharset->m_oCharset.IsInit())
|
||||
{
|
||||
SimpleTypes::EFontCharset eCharset = pFont->m_oCharset->m_oCharset->GetValue();
|
||||
|
||||
if(SimpleTypes::fontcharsetANSI != eCharset && SimpleTypes::fontcharsetDefault != eCharset)
|
||||
parw += _T("<Charset value='") + pFont->m_oCharset->m_oCharset->ToHexString() + _T("'/>");
|
||||
}
|
||||
CString sFontName;
|
||||
if(pFont->m_oRFont.IsInit())
|
||||
sFontName = pFont->m_oRFont->ToString2();
|
||||
if(sFontName.IsEmpty())
|
||||
parw += _T("<Name value='") + CString(gc_sNoNameFont) + _T("'/>");
|
||||
else
|
||||
{
|
||||
|
||||
parw += _T("<Name value='")+ sFontName + _T("'/>");
|
||||
}
|
||||
if(pFont->m_oScheme->m_oFontScheme.IsInit())
|
||||
{
|
||||
}
|
||||
parw += _T("<FamilyClass name='") + font.m_oFamily.ToString() + _T("'/>");
|
||||
if(font.m_oPanose.IsInit())
|
||||
parw += _T("<Panose value='") + font.m_oPanose->ToString() + _T("'/>");
|
||||
if (font.m_oPitch.GetValue() == SimpleTypes::pitchFixed)
|
||||
parw += _T("<FixedWidth value='1'/>");
|
||||
else
|
||||
parw += _T("<FixedWidth value='0'/>");
|
||||
parw += _T("<UnicodeRange ");
|
||||
if (font.m_oUsb0.IsInit())
|
||||
parw += _T("range1='") + font.m_oUsb0->ToString() + _T("' ");
|
||||
if (font.m_oUsb1.IsInit())
|
||||
parw += _T("range2='") + font.m_oUsb1->ToString() + _T("' ");
|
||||
if (font.m_oUsb2.IsInit())
|
||||
parw += _T("range3='") + font.m_oUsb2->ToString() + _T("' ");
|
||||
if (font.m_oUsb3.IsInit())
|
||||
parw += _T("range4='") + font.m_oUsb3->ToString() + _T("' ");
|
||||
if (font.m_oCsb0.IsInit())
|
||||
parw += _T("coderange1='") + font.m_oCsb0->ToString() + _T("' ");
|
||||
if (font.m_oCsb1.IsInit())
|
||||
parw += _T("coderange2='") + font.m_oCsb1->ToString() + _T("' ");
|
||||
parw += _T("/>");
|
||||
parw += _T("</FontProperties>");
|
||||
CString params = parw.GetCString();
|
||||
|
||||
BSTR fontPath;
|
||||
long index = 0;
|
||||
BSTR bstrParams = params.AllocSysString();
|
||||
fontManager->GetWinFontByParams(bstrParams, &fontPath, &index);
|
||||
SysFreeString(bstrParams);
|
||||
int status = fontManager->LoadFontFromFile(fontPath, 12, 72, 72, index);
|
||||
SysFreeString(fontPath);
|
||||
|
||||
BSTR familyName;
|
||||
fontManager->GetFamilyName(&familyName);
|
||||
CString resFontName = familyName;
|
||||
SysFreeString(familyName);
|
||||
|
||||
fontMap[font.m_sName] = resFontName;
|
||||
}
|
||||
}
|
||||
176
ActiveX/XlsxSerializerCom/Reader/FontProcessor.h
Normal file
176
ActiveX/XlsxSerializerCom/Reader/FontProcessor.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2014
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||
* EU, LV-1021.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../stdafx.h"
|
||||
#include "../../Common/DocxFormat/Source/XlsxFormat/Styles/Fonts.h"
|
||||
|
||||
namespace BinXlsxRW {
|
||||
static TCHAR* gc_sNoNameFont = _T("NoNameFont");
|
||||
static TCHAR* gc_sDefaultFontName = _T("Arial");
|
||||
|
||||
class FontProcessor {
|
||||
ASCGraphics::IASCFontManager* m_pFontManager;
|
||||
CAtlMap<CString, CString> m_mapFontMap;
|
||||
|
||||
CString m_sFontDir;
|
||||
|
||||
public:
|
||||
FontProcessor():m_pFontManager(NULL){}
|
||||
~FontProcessor()
|
||||
{
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
}
|
||||
|
||||
void setFontDir(const CString& fontDir)
|
||||
{
|
||||
this->m_sFontDir = fontDir;
|
||||
initFontManager();
|
||||
}
|
||||
CString getFontDir()
|
||||
{
|
||||
return this->m_sFontDir;
|
||||
}
|
||||
void setFontTable(const OOX::Spreadsheet::CFonts& oFonts)
|
||||
{
|
||||
for (int i = 0, length = oFonts.m_arrItems.GetSize(); i < length; ++i)
|
||||
{
|
||||
OOX::Spreadsheet::CFont* pFont = oFonts.m_arrItems[i];
|
||||
if(NULL != pFont)
|
||||
addToFontMap(*pFont);
|
||||
}
|
||||
}
|
||||
ASCGraphics::IASCFontManager* getFontManager()
|
||||
{
|
||||
return m_pFontManager;
|
||||
}
|
||||
CString getFont(const CString& name)
|
||||
{
|
||||
CString fontName = gc_sDefaultFontName;
|
||||
CAtlMap<CString, CString>::CPair* pPair = m_mapFontMap.Lookup( name );
|
||||
if ( NULL == pPair )
|
||||
{
|
||||
if(!name.IsEmpty())
|
||||
{
|
||||
OOX::Spreadsheet::CFont oFont;
|
||||
oFont.m_oRFont.Init();
|
||||
oFont.m_oRFont->m_sVal = name;
|
||||
addToFontMap(oFont);
|
||||
pPair = m_mapFontMap.Lookup( name );
|
||||
if (NULL != pPair)
|
||||
fontName = pPair->m_value;
|
||||
}
|
||||
}
|
||||
else
|
||||
fontName = pPair->m_value;
|
||||
return fontName;
|
||||
}
|
||||
private:
|
||||
void initFontManager()
|
||||
{
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
CoCreateInstance(ASCGraphics::CLSID_CASCFontManager, NULL, CLSCTX_ALL, ASCGraphics::IID_IASCFontManager, (void**) &m_pFontManager);
|
||||
|
||||
VARIANT var;
|
||||
var.vt = VT_BSTR;
|
||||
var.bstrVal = m_sFontDir.AllocSysString();
|
||||
m_pFontManager->SetAdditionalParam(L"InitializeFromFolder", var);
|
||||
RELEASESYSSTRING(var.bstrVal);
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
CString defaultFontName = gc_sDefaultFontName;
|
||||
BSTR defFontName = defaultFontName.AllocSysString();
|
||||
m_pFontManager->SetDefaultFont(defFontName);
|
||||
SysFreeString(defFontName);
|
||||
#endif
|
||||
}
|
||||
|
||||
void addToFontMap(OOX::Spreadsheet::CFont& font)
|
||||
{
|
||||
CString parw;
|
||||
parw += _T("<FontProperties>");
|
||||
if(font.m_oCharset.IsInit() && font.m_oCharset->m_oCharset.IsInit())
|
||||
{
|
||||
SimpleTypes::Spreadsheet::EFontCharset eCharset = font.m_oCharset->m_oCharset->GetValue();
|
||||
|
||||
if(SimpleTypes::fontcharsetANSI != eCharset && SimpleTypes::fontcharsetDefault != eCharset)
|
||||
parw += _T("<Charset value='") + font.m_oCharset->m_oCharset->ToHexString() + _T("'/>");
|
||||
}
|
||||
CString sFontName;
|
||||
if(font.m_oScheme.IsInit() && font.m_oScheme->m_oFontScheme.IsInit())
|
||||
{
|
||||
|
||||
const SimpleTypes::Spreadsheet::EFontScheme eFontScheme = font.m_oScheme->m_oFontScheme->GetValue();
|
||||
if(SimpleTypes::Spreadsheet::fontschemeNone != eFontScheme)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
if(sFontName.IsEmpty() && font.m_oRFont.IsInit() && font.m_oRFont->m_sVal.IsInit())
|
||||
sFontName = font.m_oRFont->ToString2();
|
||||
if(sFontName.IsEmpty())
|
||||
parw += _T("<Name value='") + CString(gc_sNoNameFont) + _T("'/>");
|
||||
else
|
||||
{
|
||||
|
||||
parw += _T("<Name value='")+ sFontName + _T("'/>");
|
||||
}
|
||||
if(font.m_oFamily.IsInit() && font.m_oFamily->m_oFontFamily.IsInit())
|
||||
{
|
||||
parw += _T("<FamilyClass name='") + font.m_oFamily->m_oFontFamily->ToString() + _T("'/>");
|
||||
}
|
||||
parw += _T("</FontProperties>");
|
||||
CString params = parw;
|
||||
|
||||
BSTR fontPath;
|
||||
BSTR familyName;
|
||||
long index = 0;
|
||||
BSTR bstrParams = params.AllocSysString();
|
||||
|
||||
#ifdef BUILD_CONFIG_FULL_VERSION
|
||||
m_pFontManager->GetWinFontByParams(bstrParams, &fontPath, &index);
|
||||
int status = m_pFontManager->LoadFontFromFile(fontPath, 12, 72, 72, index);
|
||||
SysFreeString(fontPath);
|
||||
m_pFontManager->GetFamilyName(&familyName);
|
||||
#else
|
||||
m_pFontManager->GetWinFontByParams(bstrParams, &familyName, &fontPath, NULL, &index);
|
||||
#endif
|
||||
|
||||
CString resFontName = familyName;
|
||||
SysFreeString(fontPath);
|
||||
SysFreeString(familyName);
|
||||
SysFreeString(bstrParams);
|
||||
|
||||
m_mapFontMap.SetAt(sFontName, resFontName);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user