Commit f5ccf59b authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

XlsFormat, OdfFormat - уточнение вычисления ширины колонок

parent 1d3e864b
......@@ -39,7 +39,7 @@ std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName,
{
if (FALSE == (hr = pFontManager->LoadFontByName(L"Arial", fontSize, fontStyle, dpi, dpi )))
{
return std::pair<float, float>(7,8);
return std::pair<float, float>(7, 8);
}
}
......@@ -49,12 +49,15 @@ std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName,
float minWidth = 0xffff;
float minHeight = 0xffff;
for (int i = 0; i <= 9; ++i)
// for (int i = 0; i <= 9; ++i)
{
if (FALSE == (hr = pFontManager->LoadString2( boost::lexical_cast<std::wstring>(i), 0, 0)))
return std::pair<float, float>(7,8);
//if (FALSE == (hr = pFontManager->LoadString2( boost::lexical_cast<std::wstring>(i), 0, 0)))
// return std::pair<float, float>(7,8);
if (FALSE == (hr = pFontManager->LoadString2( L"xxxxx" , 0, 0)))
return std::pair<float, float>(7,8);
TBBox box;
TBBox box;
try
{
box = pFontManager->MeasureString();
......@@ -74,7 +77,7 @@ std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName,
if (box.fMaxY - box.fMinY < minHeight) minHeight = box.fMaxY - box.fMinY;
}
return std::pair<float, float>((minWidth + 2*maxWidth)/3.f,maxHeight);
return std::pair<float, float>(maxWidth / 5.f, maxHeight);
}
......@@ -104,7 +107,7 @@ std::pair<float, float> GetMaxDigitSizePixels(const std::wstring & fontName, dou
{
// TODO: default value!
}
return std::pair<float, float>(7,8);
return std::pair<float, float>(7, 8);
}
}
......
// ASCOfficeOdfFileWTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "../../OfficeUtils/src/OfficeUtils.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <string>
#import "..\..\Redist\ASCOfficeOdfFileW.dll" rename_namespace("ASCOfficeOdfFileW") raw_interfaces_only
#include "../../Common/DocxFormat/Source/Base/Base.h"
#include "../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h"
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
#define HR_RET(HR) if FAILED(hr = (HR)) { _ASSERTE(false); return -1; }
#include "../source/Oox2OdfConverter/Oox2OdfConverter.h"
class CCallback : public ASCOfficeOdfFileW::_IAVSOfficeFileTemplateEvents
std::wstring DetectTypeDocument(const std::wstring & pathOOX)
{
public:
CCallback(){m_cnt=0;}
virtual ~CCallback(){}
STDMETHOD(GetTypeInfoCount)(UINT*) { return E_NOTIMPL; }
STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo**) { return E_NOTIMPL; }
STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, UINT, LCID, DISPID*) { return E_NOTIMPL; }
STDMETHOD(Invoke)(
DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS* pDispParams,
VARIANT* pVarResult,
EXCEPINFO* pExcepInfo,
UINT* puArgErr)
std::wstring sRes;
CFile file;
CString fileContentType = std_string2string(pathOOX + FILE_SEPARATOR_STR + L"[Content_Types].xml");
if (file.OpenFile(fileContentType) != S_OK) return sRes;
int nBufferSize = min (file.GetFileSize(), 4096);
BYTE *pBuffer = new BYTE[nBufferSize];
file.ReadFile(pBuffer, nBufferSize);
file.CloseFile();
if (pBuffer != NULL)
{
switch(dispIdMember)
{
case 1:
std::cout << "\nPercent : " << pDispParams->rgvarg[0].lVal / 10000. << "%\n";
return(S_OK);
break;
default:
return(E_NOTIMPL);
}
}
STDMETHOD(QueryInterface)(REFIID iid, LPVOID* ppv)
{
if ((iid == __uuidof(ASCOfficeOdfFileW::_IAVSOfficeFileTemplateEvents)) ||
(iid == __uuidof(IDispatch)) ||
(iid == __uuidof(IUnknown)))
*ppv = this;
else {
*ppv = 0;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
STDMETHOD_(ULONG,AddRef)() {
return InterlockedIncrement(&m_cnt);
}
const char *docxFormatLine = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
const char *dotxFormatLine = "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml";
const char *docmFormatLine = "application/vnd.ms-word.document.macroEnabled.main+xml";
const char *dotmFormatLine = "application/vnd.ms-word.template.macroEnabledTemplate.main+xml";
STDMETHOD_(ULONG,Release)() {
InterlockedDecrement(&m_cnt);
if (m_cnt!=0) return m_cnt;
delete this;
return 0;
}
protected:
LONG m_cnt;
private:
};
const char *xlsxFormatLine = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
const char *xltxFormatLine = "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml";
const char *xlsmFormatLine = "application/vnd.ms-excel.sheet.macroEnabled.main+xml";
const char *xltmFormatLine = "application/vnd.ms-excel.template.macroEnabled.main+xml";
const char *pptxFormatLine = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
const char *ppsxFormatLine = "application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml";
const char *potxFormatLine = "application/vnd.openxmlformats-officedocument.presentationml.template.main+xml";
const char *pptmFormatLine = "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml";
const char *ppsmFormatLine = "application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml";
const char *potmFormatLine = "application/vnd.ms-powerpoint.template.macroEnabled.main+xml";
int ConvertSingle(int argc, _TCHAR* argv[])
{
ATL::CComPtr<ASCOfficeOdfFileW::IAVSOfficeFileTemplate> officeOdfFileW;
HRESULT hr;
HR_RET(officeOdfFileW.CoCreateInstance(__uuidof(ASCOfficeOdfFileW::COfficeOdfFileW)));
//_______________________________________________________________________________________________________
IUnknown *pUnk;
IConnectionPointContainer* pContainer;
IConnectionPoint* pCP;
CCallback *pEvents = NULL;
DWORD dwAdvise=0;
pEvents = new CCallback;
pEvents->AddRef();
HR_RET(officeOdfFileW->QueryInterface(IID_IConnectionPointContainer, (void**)&pContainer));
HR_RET(pContainer->FindConnectionPoint(__uuidof(ASCOfficeOdfFileW::_IAVSOfficeFileTemplateEvents),&pCP));
HR_RET(pEvents->QueryInterface(IID_IUnknown,(VOID **)&pUnk));
HR_RET(pCP->Advise(pUnk,&dwAdvise));
pContainer->Release();pContainer=NULL;
pUnk->Release(); pUnk=NULL;
//_________________________________________________________________________________________________________
boost::timer t1;
officeOdfFileW->SaveToFile(ATL::CComBSTR(argv[2]), ATL::CComBSTR(argv[1]), NULL);
std::string strContentTypes((char*)pBuffer, nBufferSize);
std::cout << "\n\nTime : " << t1.elapsed() << "\n";
//____________________________________________________________________________________________________
int res = 0;
if ( (res = strContentTypes.find(docxFormatLine))>0 || (res = strContentTypes.find(dotxFormatLine))>0 ||
(res = strContentTypes.find(docmFormatLine))>0 || (res = strContentTypes.find(dotmFormatLine))>0)
{
sRes = L"text";
}
else if ((res = strContentTypes.find(xlsxFormatLine))>0 || (res = strContentTypes.find(xltxFormatLine))>0 ||
(res = strContentTypes.find(xlsmFormatLine))>0 || (res = strContentTypes.find(xltmFormatLine))>0)
{
sRes = L"spreadsheet";
}
else if ((res = strContentTypes.find(pptxFormatLine) > 0) || /*(res = strContentTypes.find(ppsxFormatLine))>0 ||*/
(res = strContentTypes.find(potxFormatLine))>0 || (res = strContentTypes.find(pptmFormatLine))>0 ||
(res = strContentTypes.find(ppsmFormatLine))>0 || (res = strContentTypes.find(potmFormatLine))>0 ||
(res = strContentTypes.find(ppsxFormatLine)) >0 )
{
}
delete []pBuffer;
pBuffer = NULL;
pCP->Unadvise(dwAdvise);
pCP->Release();
pEvents->Release();
return 0;
}
return sRes;
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
if (argc < 3)
return -1;
return ConvertSingle(argc, argv);
HRESULT hr = S_OK;
boost::timer t1;
//////////////////////////////////////////////////////////////////////////
std::wstring srcFileName = argv[1];
std::wstring dstPath = argv[2];
std::wstring outputDir = FileSystem::Directory::GetFolderPath(dstPath);
std::wstring srcTempPath = FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);
std::wstring dstTempPath = FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);
//
COfficeUtils oCOfficeUtils(NULL);
if (S_OK != oCOfficeUtils.ExtractToDirectory(srcFileName.c_str(), srcTempPath.c_str(), NULL, 0))
return S_FALSE;
std::wstring type = DetectTypeDocument(srcTempPath);
Oox2Odf::Converter converter(srcTempPath, type, L"C:\\Windows\\Fonts", NULL);
converter.convert();
converter.write(dstTempPath);
FileSystem::Directory::DeleteDirectory(srcTempPath);
if (hr != S_OK) return hr;
if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstPath.c_str(), -1))
return hr;
FileSystem::Directory::DeleteDirectory(dstTempPath);
////////////////////////////////////////////////////////////////////////
std::cout << "\n\nTime : " << t1.elapsed() << "\n";
return 0;
}
......@@ -332,64 +332,16 @@
<File
RelativePath=".\ASCOfficeOdfFileWTest.cpp"
>
</File>
<File
RelativePath=".\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\stdafx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
......
========================================================================
CONSOLE APPLICATION : ASCOfficeOdfFileWTest Project Overview
========================================================================
AppWizard has created this ASCOfficeOdfFileWTest application for you.
This file contains a summary of what you will find in each of the files that
make up your ASCOfficeOdfFileWTest application.
ASCOfficeOdfFileWTest.vcproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
ASCOfficeOdfFileWTest.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named ASCOfficeOdfFileWTest.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////
// stdafx.cpp : source file that includes just the standard includes
// ASCOfficeOdfFileWTest.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <windef.h>
#include <wingdi.h>
using namespace ATL;
......@@ -475,9 +475,17 @@ void ods_conversion_context::start_image(const std::wstring & image_file_name)
}
double ods_conversion_context:: convert_symbol_width(double val)
{
double pixels = (double)(((256. * val + (int)(128. / font_metrix_.approx_symbol_size)) / 256.) * font_metrix_.approx_symbol_size);
//width = ((int)((column_width * Digit_Width + 5) / Digit_Width * 256 )) / 256.;
//width = (int)(((256. * width + ((int)(128. / Digit_Width ))) / 256. ) * Digit_Width ); //in pixels
//
//_dxR = dxR / 1024. * width * 9525.; // to emu
val = ((int)((val * font_metrix_.approx_symbol_size + 5) / font_metrix_.approx_symbol_size * 256 )) / 256.;
double pixels = (int)(((256. * val + ((int)(128. / font_metrix_.approx_symbol_size ))) / 256. ) * font_metrix_.approx_symbol_size ); //in pixels
return pixels* 72./96;
return pixels * 4.8387; //* 9525. * 72.0 / (360000.0 * 2.54);
}
}
}
......@@ -3,32 +3,29 @@ Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OdfFormatWriterLib", "..\source\win32\OdfFormat.vcproj", "{E5A67556-44DA-4481-8F87-0A3AEDBD20DD}"
ProjectSection(ProjectDependencies) = postProject
{C739151F-5384-41DF-A1A6-F089E2C1AD56} = {C739151F-5384-41DF-A1A6-F089E2C1AD56}
{609ED938-3CA8-4BED-B363-25096D4C4812} = {609ED938-3CA8-4BED-B363-25096D4C4812}
{9CAA294E-58C3-4CEB-ABA0-CB9786CA5540} = {9CAA294E-58C3-4CEB-ABA0-CB9786CA5540}
{94954A67-A853-43B1-A727-6EF2774C5A6A} = {94954A67-A853-43B1-A727-6EF2774C5A6A}
{9CAA294E-58C3-4CEB-ABA0-CB9786CA5540} = {9CAA294E-58C3-4CEB-ABA0-CB9786CA5540}
{609ED938-3CA8-4BED-B363-25096D4C4812} = {609ED938-3CA8-4BED-B363-25096D4C4812}
{C739151F-5384-41DF-A1A6-F089E2C1AD56} = {C739151F-5384-41DF-A1A6-F089E2C1AD56}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Oox2OdfConverter", "..\source\win32\Oox2OdfConverter.vcproj", "{BEE01B53-244A-44E6-8947-ED9342D9247E}"
ProjectSection(ProjectDependencies) = postProject
{A100103A-353E-45E8-A9B8-90B87CC5C0B0} = {A100103A-353E-45E8-A9B8-90B87CC5C0B0}
{21663823-DE45-479B-91D0-B4FEF4916EF0} = {21663823-DE45-479B-91D0-B4FEF4916EF0}
{94954A67-A853-43B1-A727-6EF2774C5A6A} = {94954A67-A853-43B1-A727-6EF2774C5A6A}
{E5A67556-44DA-4481-8F87-0A3AEDBD20DD} = {E5A67556-44DA-4481-8F87-0A3AEDBD20DD}
{94954A67-A853-43B1-A727-6EF2774C5A6A} = {94954A67-A853-43B1-A727-6EF2774C5A6A}
{21663823-DE45-479B-91D0-B4FEF4916EF0} = {21663823-DE45-479B-91D0-B4FEF4916EF0}
{A100103A-353E-45E8-A9B8-90B87CC5C0B0} = {A100103A-353E-45E8-A9B8-90B87CC5C0B0}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASCOfficeOdfFileWTest", "..\ASCOfficeOdfFileWTest\ASCOfficeOdfFileWTest.vcproj", "{FBA8446A-150F-4A10-B4DA-1022048D6473}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocxFormat", "..\..\Common\DocxFormat\Projects\DocxFormat2005.vcproj", "{A100103A-353E-45E8-A9B8-90B87CC5C0B0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASCOfficeOdfFileW", "ASCOfficeOdfFileW.vcproj", "{6258296E-ABCE-4BC6-9F4A-8522CD615603}"
ProjectSection(ProjectDependencies) = postProject
{F8274B05-168E-4D6E-B843-AA7510725363} = {F8274B05-168E-4D6E-B843-AA7510725363}
{C739151F-5384-41DF-A1A6-F089E2C1AD56} = {C739151F-5384-41DF-A1A6-F089E2C1AD56}
{BEE01B53-244A-44E6-8947-ED9342D9247E} = {BEE01B53-244A-44E6-8947-ED9342D9247E}
{A100103A-353E-45E8-A9B8-90B87CC5C0B0} = {A100103A-353E-45E8-A9B8-90B87CC5C0B0}
{37CA072A-5BDE-498B-B3A7-5E404F5F9BF2} = {37CA072A-5BDE-498B-B3A7-5E404F5F9BF2}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocxFormat", "..\..\Common\DocxFormat\Projects\DocxFormat2005.vcproj", "{A100103A-353E-45E8-A9B8-90B87CC5C0B0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml2", "..\..\Common\DocxFormat\Source\XML\libxml2\win_build\libxml2.vcproj", "{21663823-DE45-479B-91D0-B4FEF4916EF0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OdfFormulasConvert", "..\..\ASCOfficeOdfFile\win32\formulasconvert.vcproj", "{94954A67-A853-43B1-A727-6EF2774C5A6A}"
......@@ -39,22 +36,22 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OdfCommon", "..\..\ASCOffic
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raster", "..\..\DesktopEditor\raster\raster_vs2005.vcproj", "{9CAA294E-58C3-4CEB-ABA0-CB9786CA5540}"
ProjectSection(ProjectDependencies) = postProject
{EE1B576A-07C5-4ACC-920F-81C41DD0C8C1} = {EE1B576A-07C5-4ACC-920F-81C41DD0C8C1}
{BC52A07C-A797-423D-8C4F-8678805BBB36} = {BC52A07C-A797-423D-8C4F-8678805BBB36}
{EE1B576A-07C5-4ACC-920F-81C41DD0C8C1} = {EE1B576A-07C5-4ACC-920F-81C41DD0C8C1}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jbig2", "..\..\DesktopEditor\raster\JBig2\win32\jbig2.vcproj", "{EE1B576A-07C5-4ACC-920F-81C41DD0C8C1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cximage", "..\..\DesktopEditor\cximage\CxImage\cximage_vs2005.vcproj", "{BC52A07C-A797-423D-8C4F-8678805BBB36}"
ProjectSection(ProjectDependencies) = postProject
{818753F2-DBB9-4D3B-898A-A604309BE470} = {818753F2-DBB9-4D3B-898A-A604309BE470}
{FFDA5DA1-BB65-4695-B678-BE59B4A1355D} = {FFDA5DA1-BB65-4695-B678-BE59B4A1355D}
{9A037A69-D1DF-4505-AB2A-6CB3641C476E} = {9A037A69-D1DF-4505-AB2A-6CB3641C476E}
{40A69F40-063E-43FD-8543-455495D8733E} = {40A69F40-063E-43FD-8543-455495D8733E}
{0588563C-F05C-428C-B21A-DD74756628B3} = {0588563C-F05C-428C-B21A-DD74756628B3}
{DF861D33-9BC1-418C-82B1-581F590FE169} = {DF861D33-9BC1-418C-82B1-581F590FE169}
{764C3A2D-FB0F-428E-B1C7-62D1DD2CE239} = {764C3A2D-FB0F-428E-B1C7-62D1DD2CE239}
{43A0E60E-5C4A-4C09-A29B-7683F503BBD7} = {43A0E60E-5C4A-4C09-A29B-7683F503BBD7}
{764C3A2D-FB0F-428E-B1C7-62D1DD2CE239} = {764C3A2D-FB0F-428E-B1C7-62D1DD2CE239}
{DF861D33-9BC1-418C-82B1-581F590FE169} = {DF861D33-9BC1-418C-82B1-581F590FE169}
{0588563C-F05C-428C-B21A-DD74756628B3} = {0588563C-F05C-428C-B21A-DD74756628B3}
{40A69F40-063E-43FD-8543-455495D8733E} = {40A69F40-063E-43FD-8543-455495D8733E}
{9A037A69-D1DF-4505-AB2A-6CB3641C476E} = {9A037A69-D1DF-4505-AB2A-6CB3641C476E}
{FFDA5DA1-BB65-4695-B678-BE59B4A1355D} = {FFDA5DA1-BB65-4695-B678-BE59B4A1355D}
{818753F2-DBB9-4D3B-898A-A604309BE470} = {818753F2-DBB9-4D3B-898A-A604309BE470}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jasper", "..\..\DesktopEditor\cximage\jasper\jasper_vs2005.vcproj", "{FFDA5DA1-BB65-4695-B678-BE59B4A1355D}"
......@@ -214,34 +211,6 @@ Global
{A100103A-353E-45E8-A9B8-90B87CC5C0B0}.Unicode Release|Win32.Build.0 = Release|Win32
{A100103A-353E-45E8-A9B8-90B87CC5C0B0}.Unicode Release|x64.ActiveCfg = Release|x64
{A100103A-353E-45E8-A9B8-90B87CC5C0B0}.Unicode Release|x64.Build.0 = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug Multithreaded|Win32.ActiveCfg = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug Multithreaded|x64.ActiveCfg = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug Multithreaded|x64.Build.0 = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug Singlethreaded|Win32.ActiveCfg = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug Singlethreaded|x64.ActiveCfg = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug Singlethreaded|x64.Build.0 = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug|Win32.ActiveCfg = Debug|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug|Win32.Build.0 = Debug|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug|x64.ActiveCfg = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Debug|x64.Build.0 = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release Multithreaded|Win32.ActiveCfg = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release Multithreaded|x64.ActiveCfg = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release Multithreaded|x64.Build.0 = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release Singlethreaded|Win32.ActiveCfg = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release Singlethreaded|x64.ActiveCfg = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release Singlethreaded|x64.Build.0 = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release|Win32.ActiveCfg = Release|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release|Win32.Build.0 = Release|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release|x64.ActiveCfg = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Release|x64.Build.0 = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Debug|Win32.ActiveCfg = Debug|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Debug|Win32.Build.0 = Debug|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Debug|x64.ActiveCfg = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Debug|x64.Build.0 = Debug|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Release|Win32.ActiveCfg = Release|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Release|Win32.Build.0 = Release|Win32
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Release|x64.ActiveCfg = Release|x64
{6258296E-ABCE-4BC6-9F4A-8522CD615603}.Unicode Release|x64.Build.0 = Release|x64
{21663823-DE45-479B-91D0-B4FEF4916EF0}.Debug Multithreaded|Win32.ActiveCfg = Debug|x64
{21663823-DE45-479B-91D0-B4FEF4916EF0}.Debug Multithreaded|x64.ActiveCfg = Debug|x64
{21663823-DE45-479B-91D0-B4FEF4916EF0}.Debug Multithreaded|x64.Build.0 = Debug|x64
......
......@@ -26,7 +26,7 @@ int _tmain(int argc, _TCHAR* argv[])
std::wstring dstTempPath = FileSystem::Directory::CreateDirectoryWithUniqueName(outputDir);
hr = ConvertXls2Xlsx(srcFileName, dstTempPath, NULL);
hr = ConvertXls2Xlsx(srcFileName, dstTempPath, L"C:\\Windows\\Fonts", NULL);
if (hr != S_OK) return hr;
......
......@@ -85,6 +85,11 @@ const int MulBlank::GetRow() const
return static_cast<unsigned short>(rw);
}
const int MulBlank::GetColumn() const
{
return static_cast<unsigned short>(colFirst);
}
int MulBlank::serialize(std::wostream & stream)
{
CP_XML_WRITER(stream)
......
......@@ -39,7 +39,8 @@ public:
void writeFields(CFRecord& record);
void readFields(CFRecord& record);
const int GetRow() const;
const int GetRow() const;
const int GetColumn() const;
int serialize(std::wostream & stream);
......
......@@ -31,8 +31,6 @@ void MulRk::readFields(CFRecord& record)
{
global_info_ = record.getGlobalWorkbookInfo();
Col colFirst;
Col colLast;
// A little hack to extract colLast before it is used
record.skipNunBytes(record.getDataSize() - sizeof(unsigned short));
record >> colLast;
......@@ -55,6 +53,11 @@ const int MulRk::GetRow() const
return static_cast<unsigned short>(rw);
}
const int MulRk::GetColumn() const
{
return static_cast<unsigned short>(colFirst);
}
int MulRk::serialize(std::wostream & stream)
{
CP_XML_WRITER(stream)
......
......@@ -22,11 +22,15 @@ public:
void writeFields(CFRecord& record);
void readFields(CFRecord& record);
const int GetRow() const;
const int GetRow() const;
const int GetColumn() const;
int serialize(std::wostream & stream);
//-----------------------------
GlobalWorkbookInfoPtr global_info_;
Col colFirst;
Col colLast;
Rw rw;
BiffStructurePtrVector rgrkrec;
BiffStructurePtrVector cells;
......
......@@ -88,9 +88,9 @@ int Row::serialize(std::wostream &stream)
if (ixfe_val && xf_set)
{
int xf = ixfe_val > global_info_->cellStyleXfs_count ? ixfe_val - global_info_->cellStyleXfs_count : ixfe_val;
int xf = ixfe_val >= global_info_->cellStyleXfs_count ? ixfe_val - global_info_->cellStyleXfs_count : ixfe_val;
if (xf < global_info_->cellXfs_count)
if (xf < global_info_->cellXfs_count && xf >= 0)
{
CP_XML_ATTR(L"s", xf);
CP_XML_ATTR(L"customFormat", true);
......
......@@ -59,6 +59,8 @@ void OfficeArtClientAnchorSheet::loadFields(XLS::CFRecord& record)
void OfficeArtClientAnchorSheet::calculate()
{
global_info->GetDigitFontSizePixels();
XLS::GlobalWorkbookInfo::_sheet_size_info zero;
XLS::GlobalWorkbookInfo::_sheet_size_info & sheet_info = global_info->current_sheet >=0 ?
global_info->sheet_size_info[global_info->current_sheet - 1] : zero;
......@@ -67,35 +69,34 @@ void OfficeArtClientAnchorSheet::calculate()
//1 inch = 72 point
//1 emu = 360000 * 2.54 inch
double kfCol = 360000 / 72.;
//double kfCol = 1250.;//360000 / 72. / 4.;
double kfRow = ( 360000 * 2.54 / 72) / 256. ;
double Digit_Width = 8.43;
double column_width = 0;
double Digit_Width = global_info->defaultDigitFontSize.first;
double Digit_Height = global_info->defaultDigitFontSize.second;
double width = 0 , column_width = 0;
if (sheet_info.customColumnsWidth.find(colL) != sheet_info.customColumnsWidth.end())
{
column_width = sheet_info.customColumnsWidth[colL] / 1024.;
column_width = sheet_info.customColumnsWidth[colL];
}
else
column_width = sheet_info.defaultColumnWidth / 1024.;
else column_width = sheet_info.defaultColumnWidth;
//double width = ((int)((column_width * Maximum_Digit_Width + 5 ) / Maximum_Digit_Width * 256. )) / 256.; //px
double width = (double)(((256. * column_width + (int)(128. / Digit_Width)) / 256.) * Digit_Width) * 72 / 96.;
//width = ((int)((column_width * Digit_Width + 5) / Digit_Width * 256 )) / 256.;
width = (int)(((256. * column_width/*width*/ + ((int)(128. / Digit_Width ))) / 256. ) * Digit_Width ); //in pixels
_dxL = dxL * kfCol * width;
_dxL = dxL / 1024. * width * 9525. ; //9525 => pixels to emu
if (sheet_info.customColumnsWidth.find(colR) != sheet_info.customColumnsWidth.end())
{
column_width = sheet_info.customColumnsWidth[colR] / 1024.;
column_width = sheet_info.customColumnsWidth[colR];
}
else
column_width = sheet_info.defaultColumnWidth / 1024.;
else column_width = sheet_info.defaultColumnWidth;
width = (double)(((256. * column_width + (int)(128. / Digit_Width)) / 256.) * Digit_Width) * 72 / 96.;
//width = ((int)((column_width * Digit_Width + 5) / Digit_Width * 256 )) / 256.;
width = (int)(((256. * column_width/*width*/ + ((int)(128. / Digit_Width ))) / 256. ) * Digit_Width ); //in pixels
_dxR = dxR * kfCol * width;
_dxR = dxR / 1024. * width * 9525.;
//---------------------------------------------------------------------------------------------------
if (sheet_info.customRowsHeight.find(rwT) != sheet_info.customRowsHeight.end())
{
......@@ -112,45 +113,45 @@ void OfficeArtClientAnchorSheet::calculate()
_dyB = dyB * kfRow * sheet_info.defaultRowHeight;
//----------------------------------------------------------------------------------------------------
for (int i = 0 ; i < colL; i++)
{
if (sheet_info.customColumnsWidth.find(i) != sheet_info.customColumnsWidth.end())
_x += 256 * kfCol * sheet_info.customColumnsWidth[i];
else
_x += 256 * kfCol * sheet_info.defaultColumnWidth;
}
_x += _dxL;
for (int i = colL ; i < colR; i++)
{
if (sheet_info.customColumnsWidth.find(i) != sheet_info.customColumnsWidth.end())
_cx += 256 * kfCol * sheet_info.customColumnsWidth[i];
else
_cx += 256 * kfCol * sheet_info.defaultColumnWidth;
}
_cx += _dxR;
for (int i = 0 ; i < rwT; i++)
{
if (sheet_info.customRowsHeight.find(i) != sheet_info.customRowsHeight.end())
{
_y += 256 * kfRow * sheet_info.customRowsHeight[i];
}
else
_y += 256 * kfRow * sheet_info.defaultRowHeight;
}
_y += _dyT;
for (int i = rwT ; i < rwB; i++)
{
if (sheet_info.customRowsHeight.find(i) != sheet_info.customRowsHeight.end())
{
_cy += 256 * kfRow * sheet_info.customRowsHeight[i];
}
else
_cy += 256 * kfRow * sheet_info.defaultRowHeight;
}
_cy += _dyT;
//for (int i = 0 ; i < colL; i++)
//{
// if (sheet_info.customColumnsWidth.find(i) != sheet_info.customColumnsWidth.end())
// _x += 256 * kfCol * sheet_info.customColumnsWidth[i];
// else
// _x += 256 * kfCol * sheet_info.defaultColumnWidth;
//}
//_x += _dxL;
//for (int i = colL ; i < colR; i++)
//{
// if (sheet_info.customColumnsWidth.find(i) != sheet_info.customColumnsWidth.end())
// _cx += 256 * kfCol * sheet_info.customColumnsWidth[i];
// else
// _cx += 256 * kfCol * sheet_info.defaultColumnWidth;
//}
//_cx += _dxR;
//for (int i = 0 ; i < rwT; i++)
//{
// if (sheet_info.customRowsHeight.find(i) != sheet_info.customRowsHeight.end())
// {
// _y += 256 * kfRow * sheet_info.customRowsHeight[i];
// }
// else
// _y += 256 * kfRow * sheet_info.defaultRowHeight;
//}
//_y += _dyT;
//for (int i = rwT ; i < rwB; i++)
//{
// if (sheet_info.customRowsHeight.find(i) != sheet_info.customRowsHeight.end())
// {
// _cy += 256 * kfRow * sheet_info.customRowsHeight[i];
// }
// else
// _cy += 256 * kfRow * sheet_info.defaultRowHeight;
//}
//_cy += _dyT;
}
......
......@@ -140,7 +140,7 @@ struct _CompareColumnCell
else
return false;
}
}CompareColumCell;
}CompareColumnCell;
int CELL_GROUP::serialize(std::wostream & stream)
{
......@@ -154,9 +154,10 @@ int CELL_GROUP::serialize(std::wostream & stream)
for (std::map<int, std::list<BaseObjectPtr>>::iterator it_row = m_cells.begin(); it_row != m_cells.end(); it_row++)
{
it_row->second.sort(CompareColumCell);
it_row->second.sort(CompareColumnCell);
Row * row = NULL;
if (current_row != m_rows.end())
{
row = dynamic_cast<Row *>(current_row->get());
......@@ -178,9 +179,9 @@ int CELL_GROUP::serialize(std::wostream & stream)
if (row->ixfe_val && xf_set)
{
int xf = ixfe_val > global_info_->cellStyleXfs_count ? row->ixfe_val - global_info_->cellStyleXfs_count : row->ixfe_val;
int xf = row->ixfe_val >= global_info_->cellStyleXfs_count ? row->ixfe_val - global_info_->cellStyleXfs_count : row->ixfe_val;
if (xf < global_info_->cellXfs_count)
if (xf < global_info_->cellXfs_count && xf >= 0)
{
CP_XML_ATTR(L"s", xf);
CP_XML_ATTR(L"customFormat", true);
......
......@@ -52,43 +52,43 @@ const bool CELL::loadContent(BinProcessor& proc)
}
else if(proc.optional(blank))
{
RowNumber = blank.getLocation().getRow();
ColumnNumber = formula_union.getLocation().getColumn();
RowNumber = blank.getLocation().getRow();
ColumnNumber = blank.getLocation().getColumn();
}
else if(proc.optional(mulblank))
{
RowNumber = mulblank.GetRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = mulblank.GetColumn();
}
else if(proc.optional(rk))
{
RowNumber = rk.getLocation().getRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = rk.getLocation().getColumn();
}
else if(proc.optional(mulrk))
{
RowNumber = mulrk.GetRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = mulrk.GetColumn();
}
else if(proc.optional(boolerr))
{
RowNumber = boolerr.getLocation().getRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = boolerr.getLocation().getColumn();
}
else if(proc.optional(number))
{
RowNumber = number.getLocation().getRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = number.getLocation().getColumn();
}
else if(proc.optional(label))//
{
RowNumber = label.cell.getLocation().getRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = label.cell.getLocation().getColumn();
}
else if(proc.optional(labelsst))
{
RowNumber = labelsst.getLocation().getRow();
ColumnNumber = formula_union.getLocation().getColumn();
ColumnNumber = labelsst.getLocation().getColumn();
}
else
{
......
#include "GlobalWorkbookInfo.h"
#include <boost/lexical_cast.hpp>
#include <Logic/Biff_records/Font.h>
#include "../../../DesktopEditor/fontengine/FontManager.h"
#include "../../../DesktopEditor/fontengine/ApplicationFonts.h"
namespace XLS
{;
{
std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName, double fontSize, double dpi, long fontStyle, CFontManager *pFontManager)
{
if (pFontManager == NULL) return std::pair<float, float>(7,8);
int hr = FALSE;
if (FALSE == (hr = pFontManager->LoadFontByName(fontName, fontSize, fontStyle, dpi, dpi )))
{
if (FALSE == (hr = pFontManager->LoadFontByName(L"Arial", fontSize, fontStyle, dpi, dpi )))
{
return std::pair<float, float>(7,8);
}
}
float maxWidth = 0;
float maxHeight = 0;
float minWidth = 0xffff;
float minHeight = 0xffff;
//for (int i = 0; i <= 9; ++i)
{
//if (FALSE == (hr = pFontManager->LoadString2( boost::lexical_cast<std::wstring>(i), 0, 0)))
// return std::pair<float, float>(7,8);
if (FALSE == (hr = pFontManager->LoadString2( L"xxxxx", 0, 0)))
return std::pair<float, float>(7,8);
TBBox box;
try
{
box = pFontManager->MeasureString();
}catch(...)
{
return std::pair<float, float>(7,8);
}
if (box.fMaxX < -0xffff+1 || box.fMaxY < -0xffff+1 ||
box.fMinX > 0xffff-1 || box.fMinY > 0xffff-1)
return std::pair<float, float>(7,8);
if (box.fMaxX - box.fMinX > maxWidth) maxWidth = box.fMaxX - box.fMinX;
if (box.fMaxY - box.fMinY > maxHeight) maxHeight = box.fMaxY - box.fMinY;
if (box.fMaxX - box.fMinX < minWidth) minWidth = box.fMaxX - box.fMinX;
if (box.fMaxY - box.fMinY < minHeight) minHeight = box.fMaxY - box.fMinY;
}
double width = (minWidth + 2 * maxWidth) /3. /5.;
return std::pair<float, float>(width, maxHeight);
}
GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConverter * xls_converter_)
: CodePage(code_page)
......@@ -11,7 +71,7 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver
last_AXES_id = initial_AXES_id;
Version = 0x0600; // xls
Version = 0x0600;
xls_converter = xls_converter_;
......@@ -22,8 +82,16 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver
cellXfs_count = 0;
cellStyleXfs_count = 0;
cellStyleDxfs_count = 0;
defaultDigitFontSize = std::pair<float, float>(0, 0);
applicationFonts = NULL;
}
GlobalWorkbookInfo::~GlobalWorkbookInfo()
{
if (applicationFonts)
delete applicationFonts;
}
const size_t GlobalWorkbookInfo::RegisterBorderId(const BorderInfo& border)
{
......@@ -70,11 +138,52 @@ void GlobalWorkbookInfo::RegisterPaletteColor(int id, const std::wstring & rgb)
colors_palette.insert(std::pair<int, std::wstring>(id, rgb));
}
const unsigned int GlobalWorkbookInfo::GenerateAXESId()
unsigned int GlobalWorkbookInfo::GenerateAXESId()
{
return last_AXES_id += 1;
}
void GlobalWorkbookInfo::GetDigitFontSizePixels()
{
if (defaultDigitFontSize.first > 0.01) return;
if (applicationFonts == NULL)
{
applicationFonts = new CApplicationFonts();
applicationFonts->InitializeFromFolder(fontsDirectory);
}
defaultDigitFontSize = std::pair<float, float>(7,8);
if (m_arFonts->size() < 1) return;
Font * font = dynamic_cast<Font*>(m_arFonts->at(0).get());
if (!font) return;
std::wstring fontName = font->fontName.value();
double fontSize = font->dyHeight /20.;
try
{
if (applicationFonts)
{
CFontManager *pFontManager = applicationFonts->GenerateFontManager();
std::pair<float, float> val = GetMaxDigitSizePixelsImpl(fontName, fontSize, 96., 0, pFontManager);
if (pFontManager)
{
pFontManager->m_pApplication = NULL;
delete pFontManager;
}
defaultDigitFontSize = val;
}
}
catch(...)
{
// TODO: default value!
}
}
} // namespace XLS
\ No newline at end of file
......@@ -10,7 +10,7 @@
#include "../Crypt/Decryptor.h"
class XlsConverter;
class CApplicationFonts;
namespace XLS
{;
......@@ -33,13 +33,17 @@ class GlobalWorkbookInfo
{
public:
GlobalWorkbookInfo(const unsigned short code_page, XlsConverter * xls_converter_);
~GlobalWorkbookInfo();
const size_t RegisterBorderId (const BorderInfo& border);
const size_t RegisterFillId (const FillInfo& fill);
void RegisterFontColorId (int id, const FillInfoExt & font_color);
void RegisterPaletteColor(int id, const std::wstring & argb);
void GetDigitFontSizePixels();
unsigned int GenerateAXESId();
const unsigned int GenerateAXESId();
unsigned short CodePage;
CRYPT::DecryptorPtr decryptor;
......@@ -77,12 +81,15 @@ public:
std::map<int, double> customRowsHeight;
double defaultColumnWidth;
double defaultRowHeight;
double defaultRowHeight;
};
std::vector<_sheet_size_info> sheet_size_info;
int Version;
std::pair<float, float> defaultDigitFontSize;
CApplicationFonts *applicationFonts;
std::wstring fontsDirectory;
int Version;
int cmt_rules;
int cellXfs_count;
......
......@@ -5,9 +5,9 @@
#include "../../../Common/OfficeFileErrorDescription.h"
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const ProgressCallback* pCallBack)
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring & fontsPath, const ProgressCallback* pCallBack)
{
XlsConverter converter(srcFile, dstPath, pCallBack);
XlsConverter converter(srcFile, dstPath, fontsPath, pCallBack);
if (converter.isError())
{
......
......@@ -2,4 +2,4 @@
struct ProgressCallback;
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const ProgressCallback* CallBack);
\ No newline at end of file
long ConvertXls2Xlsx(const std::wstring & srcFile, const std::wstring & dstPath, const std::wstring& fontsPath, const ProgressCallback* CallBack);
\ No newline at end of file
......@@ -86,7 +86,7 @@ typedef struct tagBITMAPCOREHEADER {
} BITMAPCOREHEADER;
#endif
XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _xlsx_path, const ProgressCallback* CallBack)
XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _xlsx_path, const std::wstring & fontsPath, const ProgressCallback* CallBack)
{
xlsx_path = _xlsx_path;
output_document = NULL;
......@@ -138,7 +138,7 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
}
xls_global_info = boost::shared_ptr<XLS::GlobalWorkbookInfo>(new XLS::GlobalWorkbookInfo(workbook_code_page, this));
xls_global_info->fontsDirectory = fontsPath;
XLS::CFStreamCacheReader stream_reader(cfile.getWorkbookStream(), xls_global_info);
......
......@@ -59,7 +59,7 @@ namespace ODRAW
class XlsConverter
{
public:
XlsConverter(const std::wstring & xls_file, const std::wstring & xlsx_path, const ProgressCallback* ffCallBack);
XlsConverter(const std::wstring & xls_file, const std::wstring & xlsx_path, const std::wstring & fontsPath, const ProgressCallback* ffCallBack);
~XlsConverter() ;
oox::xlsx_conversion_context * xlsx_context;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment