Commit db00cb58 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

git-svn-id:...

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62973 954022d7-b5bf-4e40-9824-e11837661b57
parent 9e031837
...@@ -53,9 +53,8 @@ docx_conversion_context::~docx_conversion_context() ...@@ -53,9 +53,8 @@ docx_conversion_context::~docx_conversion_context()
} }
void docx_conversion_context::set_font_directory(std::wstring pathFonts) void docx_conversion_context::set_font_directory(std::wstring pathFonts)
{ {
if (applicationFonts_ == NULL) return; if (applicationFonts_)
applicationFonts_->InitializeFromFolder(pathFonts);
applicationFonts_->InitializeFromFolder(pathFonts);
} }
std::wstring styles_map::get(const std::wstring & Name, odf_types::style_family::type Type) std::wstring styles_map::get(const std::wstring & Name, odf_types::style_family::type Type)
{ {
......
...@@ -494,7 +494,7 @@ public: ...@@ -494,7 +494,7 @@ public:
void end_comment(); void end_comment();
void set_process_headers_footers(bool Val) { process_headers_footers_ = Val; } void set_process_headers_footers(bool Val) { process_headers_footers_ = Val; }
headers_footers & get_headers_footers() { return headers_footers_; }; headers_footers & get_headers_footers() { return headers_footers_; }
header_footer_context & get_header_footer_context() { return header_footer_context_; } header_footer_context & get_header_footer_context() { return header_footer_context_; }
bool process_headers_footers_; bool process_headers_footers_;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <float.h> #include <float.h>
#include "../../DesktopEditor/fontengine/FontManager.h" #include "../../DesktopEditor/fontengine/FontManager.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
namespace cpdoccore { namespace cpdoccore {
namespace utils { namespace utils {
...@@ -59,16 +60,27 @@ std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName, ...@@ -59,16 +60,27 @@ std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName,
} }
std::pair<float, float> GetMaxDigitSizePixels(const std::wstring & fontName, double fontSize, double dpi, long fontStyle, CFontManager *pFontManager) std::pair<float, float> GetMaxDigitSizePixels(const std::wstring & fontName, double fontSize, double dpi, long fontStyle, CApplicationFonts *appFonts)
{ {
try try
{ {
_CP_LOG << "[info] : GetMaxDigitSizePixels..."; _CP_LOG << "[info] : GetMaxDigitSizePixels...";
std::pair<float, float> val = GetMaxDigitSizePixelsImpl(fontName, fontSize, dpi, fontStyle, pFontManager); if (appFonts)
{
CFontManager *pFontManager = appFonts->GenerateFontManager();
_CP_LOG << "ok" << std::endl; std::pair<float, float> val = GetMaxDigitSizePixelsImpl(fontName, fontSize, dpi, fontStyle, pFontManager);
return val;
if (pFontManager)
{
pFontManager->m_pApplication = NULL;
delete pFontManager;
}
_CP_LOG << "ok" << std::endl;
return val;
}
} }
catch(...) catch(...)
{ {
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
#include <utility> #include <utility>
#include <string> #include <string>
class CFontManager; class CApplicationFonts;
namespace cpdoccore { namespace cpdoccore {
namespace utils { namespace utils {
std::pair<float, float> GetMaxDigitSizePixels(const std::wstring & fontName, double fontSize, double dpi, long fontStyle, CFontManager *pFontManager); std::pair<float, float> GetMaxDigitSizePixels(const std::wstring & fontName, double fontSize, double dpi, long fontStyle, CApplicationFonts *appFonts);
} }
} }
...@@ -49,9 +49,8 @@ pptx_conversion_context::~pptx_conversion_context() ...@@ -49,9 +49,8 @@ pptx_conversion_context::~pptx_conversion_context()
} }
void pptx_conversion_context::set_font_directory(std::wstring pathFonts) void pptx_conversion_context::set_font_directory(std::wstring pathFonts)
{ {
if (applicationFonts_ == NULL) return; if (applicationFonts_ )
applicationFonts_->InitializeFromFolder(pathFonts);
applicationFonts_->InitializeFromFolder(pathFonts);
} }
// //
//void pptx_conversion_context::start_chart(std::wstring const & name) //void pptx_conversion_context::start_chart(std::wstring const & name)
......
...@@ -482,7 +482,7 @@ std::pair<float,float> xlsx_conversion_context::getMaxDigitSize() ...@@ -482,7 +482,7 @@ std::pair<float,float> xlsx_conversion_context::getMaxDigitSize()
else else
font_size =10; font_size =10;
maxDigitSize_ = utils::GetMaxDigitSizePixels(font_name.c_str(), font_size, /*getDefaultDpi()*/96., 0, applicationFonts_->GenerateFontManager()); maxDigitSize_ = utils::GetMaxDigitSizePixels(font_name.c_str(), font_size, /*getDefaultDpi()*/96., 0, applicationFonts_);
} }
return maxDigitSize_; return maxDigitSize_;
} }
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include "style_paragraph_properties.h" #include "style_paragraph_properties.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
namespace cpdoccore { namespace cpdoccore {
using namespace odf_types; using namespace odf_types;
...@@ -26,6 +29,20 @@ odf_conversion_context::odf_conversion_context(package::odf_document * outputDoc ...@@ -26,6 +29,20 @@ odf_conversion_context::odf_conversion_context(package::odf_document * outputDoc
output_document_ = outputDocument; output_document_ = outputDocument;
current_object_ =0; current_object_ =0;
applicationFonts_ = new CApplicationFonts();
}
odf_conversion_context::~odf_conversion_context()
{
if (applicationFonts_)
delete applicationFonts_;
}
void odf_conversion_context::set_fonts_directory(std::wstring pathFonts)
{
if (applicationFonts_)
applicationFonts_->InitializeFromFolder(pathFonts);
} }
odf_style_context* odf_conversion_context::styles_context() odf_style_context* odf_conversion_context::styles_context()
...@@ -57,13 +74,6 @@ _mediaitems* odf_conversion_context::mediaitems() ...@@ -57,13 +74,6 @@ _mediaitems* odf_conversion_context::mediaitems()
return &objects_[current_object_].mediaitems; return &objects_[current_object_].mediaitems;
} }
odf_conversion_context::~odf_conversion_context()
{
}
void odf_conversion_context::end_document() void odf_conversion_context::end_document()
{ {
rels rels_; rels rels_;
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "mediaitems.h" #include "mediaitems.h"
class CApplicationFonts;
namespace cpdoccore { namespace cpdoccore {
namespace odf_writer { namespace odf_writer {
...@@ -36,10 +38,13 @@ public: ...@@ -36,10 +38,13 @@ public:
odf_conversion_context(package::odf_document * outputDocument); odf_conversion_context(package::odf_document * outputDocument);
virtual ~odf_conversion_context(); virtual ~odf_conversion_context();
virtual void start_document() = 0 ; void set_fonts_directory(std::wstring pathFonts);
virtual void start_document() = 0 ;
virtual void end_document(); virtual void end_document();
package::odf_document * output_document_; package::odf_document *output_document_;
CApplicationFonts *applicationFonts_;
virtual odf_drawing_context * drawing_context() = 0; virtual odf_drawing_context * drawing_context() = 0;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "odf_text_context.h" #include "odf_text_context.h"
#include "paragraph_elements.h" #include "paragraph_elements.h"
namespace cpdoccore { namespace cpdoccore {
using namespace odf_types; using namespace odf_types;
...@@ -21,13 +22,13 @@ namespace odf_writer { ...@@ -21,13 +22,13 @@ namespace odf_writer {
namespace utils namespace utils
{ {
void calculate_size_font_symbols(_font_metrix & metrix) void calculate_size_font_symbols(_font_metrix & metrix, CApplicationFonts *appFonts)
{ {
double appr_px = 0;//(int)_gdi_graphics_::calculate_size_symbol_asc(metrix.font_name,metrix.font_size,metrix.italic,metrix.bold); double appr_px = _graphics_utils_::calculate_size_symbol_asc(metrix.font_name,metrix.font_size,metrix.italic,metrix.bold, appFonts);
if (appr_px <0.01) if (appr_px <0.01)
{ {
appr_px = /*(int)*/_gdi_graphics_::calculate_size_symbol(metrix.font_name,metrix.font_size,false/*metrix.italic*/,false/*metrix.bold*/); appr_px = _graphics_utils_::calculate_size_symbol_win(metrix.font_name,metrix.font_size,false/*metrix.italic*/,false/*metrix.bold*/);
appr_px = ((int)(appr_px+0.5) + 2*(int)appr_px)/3.; appr_px = ((int)(appr_px+0.5) + 2*(int)appr_px)/3.;
} }
...@@ -321,7 +322,7 @@ void ods_conversion_context::calculate_font_metrix(std::wstring name, double siz ...@@ -321,7 +322,7 @@ void ods_conversion_context::calculate_font_metrix(std::wstring name, double siz
font_metrix_.font_name = name; font_metrix_.font_name = name;
//////////////////////////////////////////// ////////////////////////////////////////////
utils::calculate_size_font_symbols(font_metrix_); utils::calculate_size_font_symbols(font_metrix_, applicationFonts_);
} }
void ods_conversion_context::start_columns() void ods_conversion_context::start_columns()
......
...@@ -89,6 +89,8 @@ private: ...@@ -89,6 +89,8 @@ private:
odf_text_context* current_text_context_; odf_text_context* current_text_context_;
office_spreadsheet* root_spreadsheet_; office_spreadsheet* root_spreadsheet_;
}; };
......
...@@ -27,13 +27,13 @@ namespace odf_writer { ...@@ -27,13 +27,13 @@ namespace odf_writer {
namespace utils namespace utils
{ {
double calculate_size_font_symbols(std::wstring str_test, std::wstring font_name, double font_size) double calculate_size_font_symbols(std::wstring str_test, std::wstring font_name, double font_size, CApplicationFonts *appFonts)
{ {
double appr_px = 0;//(int)_gdi_graphics_::calculate_size_symbol_asc(metrix.font_name,metrix.font_size,metrix.italic,metrix.bold); double appr_px = _graphics_utils_::calculate_size_symbol_asc(font_name, font_size, false, false, appFonts);
if (appr_px <0.01) if (appr_px <0.01)
{ {
appr_px = /*(int)*/_gdi_graphics_::calculate_size_symbol(font_name,font_size,false,false, str_test); appr_px = _graphics_utils_::calculate_size_symbol_win(font_name, font_size, false, false, str_test);
//appr_px = ((int)(appr_px+0.5) + 2*(int)appr_px)/3.; //appr_px = ((int)(appr_px+0.5) + 2*(int)appr_px)/3.;
} }
...@@ -166,7 +166,7 @@ void odt_conversion_context::add_text_content(const std::wstring & text) ...@@ -166,7 +166,7 @@ void odt_conversion_context::add_text_content(const std::wstring & text)
std::wstring f_name = props->content().fo_font_family_.get_value_or(L"Arial"); std::wstring f_name = props->content().fo_font_family_.get_value_or(L"Arial");
double f_size = props->content().fo_font_size_.get_value_or(font_size(length(12,length::pt))).get_length().get_value_unit(length::pt); double f_size = props->content().fo_font_size_.get_value_or(font_size(length(12,length::pt))).get_length().get_value_unit(length::pt);
drop_cap_state_.characters_size_pt += utils::calculate_size_font_symbols(text, f_name, f_size); drop_cap_state_.characters_size_pt += utils::calculate_size_font_symbols(text, f_name, f_size, applicationFonts_);
} }
} }
} }
......
...@@ -253,7 +253,7 @@ void OoxConverter::convert(OOX::Vml::CImageData *vml_image_data) ...@@ -253,7 +253,7 @@ void OoxConverter::convert(OOX::Vml::CImageData *vml_image_data)
// - drawing_context // - drawing_context
if (pathImage.GetLength() < 1)return; if (pathImage.GetLength() < 1)return;
_gdi_graphics_::GetResolution(pathImage, Width, Height); _graphics_utils_::GetResolution(pathImage, Width, Height);
odf_context()->drawing_context()->start_area_properties(); odf_context()->drawing_context()->start_area_properties();
odf_context()->drawing_context()->start_bitmap_style(); odf_context()->drawing_context()->start_bitmap_style();
...@@ -312,7 +312,7 @@ void OoxConverter::convert(OOX::Vml::CFill *vml_fill) ...@@ -312,7 +312,7 @@ void OoxConverter::convert(OOX::Vml::CFill *vml_fill)
if (pathImage.GetLength() > 0) if (pathImage.GetLength() > 0)
{ {
odf_context()->drawing_context()->set_bitmap_link(string2std_string(pathImage)); odf_context()->drawing_context()->set_bitmap_link(string2std_string(pathImage));
_gdi_graphics_::GetResolution(pathImage, Width, Height); _graphics_utils_::GetResolution(pathImage, Width, Height);
} }
odf_context()->drawing_context()->set_image_style_repeat(1); odf_context()->drawing_context()->set_image_style_repeat(1);
} }
......
...@@ -29,12 +29,15 @@ namespace Oox2Odf ...@@ -29,12 +29,15 @@ namespace Oox2Odf
{ {
return (Val * 360000 * 2.54) / 72; return (Val * 360000 * 2.54) / 72;
} }
Converter::Converter(const std::wstring & path, std::wstring type, const ProgressCallback* CallBack) Converter::Converter(const std::wstring & path, std::wstring type, const std::wstring & fontsPath, const ProgressCallback* CallBack)
{ {
impl_ = NULL; impl_ = NULL;
if (type == L"text") impl_ = new DocxConverter(path, CallBack); if (type == L"text") impl_ = new DocxConverter(path, CallBack);
if (type == L"spreadsheet") impl_ = new XlsxConverter(path, CallBack); if (type == L"spreadsheet") impl_ = new XlsxConverter(path, CallBack);
if (impl_)
impl_->set_fonts_directory(fontsPath);
} }
Converter::~Converter() Converter::~Converter()
...@@ -73,7 +76,12 @@ bool OoxConverter::UpdateProgress(long nComplete) ...@@ -73,7 +76,12 @@ bool OoxConverter::UpdateProgress(long nComplete)
return FALSE; return FALSE;
} }
void OoxConverter::set_fonts_directory(const std::wstring &fontsPath)
{
odf_context()->set_fonts_directory(fontsPath);
}
void OoxConverter::convert(OOX::WritingElement *oox_unknown) void OoxConverter::convert(OOX::WritingElement *oox_unknown)
{ {
try try
...@@ -740,7 +748,7 @@ void OoxConverter::convert(OOX::Drawing::CBlipFillProperties *oox_bitmap_fill, C ...@@ -740,7 +748,7 @@ void OoxConverter::convert(OOX::Drawing::CBlipFillProperties *oox_bitmap_fill, C
if (pathImage.GetLength() > 0) if (pathImage.GetLength() > 0)
{ {
odf_context()->drawing_context()->set_bitmap_link(string2std_string(pathImage)); odf_context()->drawing_context()->set_bitmap_link(string2std_string(pathImage));
_gdi_graphics_::GetResolution(pathImage, Width, Height); _graphics_utils_::GetResolution(pathImage, Width, Height);
} }
else else
{ {
......
...@@ -300,6 +300,8 @@ public: ...@@ -300,6 +300,8 @@ public:
pCallBack = CallBack; pCallBack = CallBack;
bUserStopConvert = 0;} bUserStopConvert = 0;}
void set_fonts_directory (const std::wstring & fontsPath);
const ProgressCallback* pCallBack; const ProgressCallback* pCallBack;
short bUserStopConvert; short bUserStopConvert;
......
...@@ -2172,7 +2172,7 @@ void DocxConverter::convert(OOX::Drawing::CPicture * oox_picture) ...@@ -2172,7 +2172,7 @@ void DocxConverter::convert(OOX::Drawing::CPicture * oox_picture)
sID = oox_picture->m_oBlipFill.m_oBlip->m_oLink.GetValue(); sID = oox_picture->m_oBlipFill.m_oBlip->m_oLink.GetValue();
//??? //???
} }
_gdi_graphics_::GetResolution(pathImage, Width, Height); _graphics_utils_::GetResolution(pathImage, Width, Height);
} }
odt_context->start_image(string2std_string(pathImage)); odt_context->start_image(string2std_string(pathImage));
{ {
......
...@@ -11,7 +11,7 @@ namespace Oox2Odf ...@@ -11,7 +11,7 @@ namespace Oox2Odf
{ {
public: public:
Converter(const std::wstring & path, std::wstring type, const ProgressCallback* ffCallBack); Converter(const std::wstring & path, std::wstring type, const std::wstring & fontsPath, const ProgressCallback* ffCallBack);
virtual ~Converter(); virtual ~Converter();
public: public:
......
...@@ -1814,7 +1814,7 @@ void XlsxConverter::convert(OOX::Spreadsheet::CPic* oox_picture) ...@@ -1814,7 +1814,7 @@ void XlsxConverter::convert(OOX::Spreadsheet::CPic* oox_picture)
sID = oox_picture->m_oBlipFill->m_oBlip->m_oLink.GetValue(); sID = oox_picture->m_oBlipFill->m_oBlip->m_oLink.GetValue();
//??? //???
} }
_gdi_graphics_::GetResolution(pathImage, Width, Height); _graphics_utils_::GetResolution(pathImage, Width, Height);
} }
ods_context->start_image(string2std_string(pathImage)); ods_context->start_image(string2std_string(pathImage));
{ {
......
...@@ -7,92 +7,58 @@ ...@@ -7,92 +7,58 @@
#include <atlbase.h> #include <atlbase.h>
#include <gdiplus.h> #include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib") #pragma comment(lib, "gdiplus.lib")
#import "../../../Redist/ASCGraphics.dll" rename_namespace("ASCGraphics")
#endif #endif
namespace _gdi_graphics_
{
//todoooo !!!
std::pair<double,double> static GetMaxDigitSizePixelsImpl(const wchar_t * fontName, float fontSize, float dpi, long fontStyle)
{
float width = 70, height = 80;
#if defined(_WIN32) || defined(_WIN64)
CComPtr<ASCGraphics::IASCFontManager> fontMan;
HRESULT hr;
try
{
if (FAILED(hr = fontMan.CoCreateInstance(__uuidof(ASCGraphics::CASCFontManager))))
throw;
if (S_OK != (hr = fontMan->Initialize(L"")))
throw;
}
catch(...)
{
return std::pair<double,double>(7,8);
}
if (S_OK != (hr = fontMan->LoadFontByName(fontName, fontSize, fontStyle, dpi, dpi )))
{
if (S_OK != (hr = fontMan->LoadFontByName(L"Arial", fontSize, fontStyle, dpi, dpi )))
{
return std::pair<double,double>(7,8);
}
}
double maxWidth=0 ;
float x, y;
std::wstring TestString = L"0123456789";
#include "../../../DesktopEditor/raster/BgraFrame.h"
#include "../../../ASCOfficeOdfFile/src/docx/measuredigits.h"
if (S_OK != (hr = fontMan->LoadString2( TestString.c_str(), 0, 0))) class CFontManager;
return std::pair<double,double>(7,8);
try
{
hr = fontMan->MeasureString(&x, &y, &width, &height);
}catch(...)
{
return std::pair<double,double>(7,8);
}
#endif
return std::pair<double,double>(width/10.,height/10.);
}
namespace _graphics_utils_
{
bool static GetResolution(const wchar_t* fileName, double & Width, double &Height) //pt bool static GetResolution(const wchar_t* fileName, double & Width, double &Height) //pt
{ {
bool result =false; bool result =false;
CBgraFrame image;
if (result = image.OpenFile(fileName, 0 ))
{
Width = image.get_Width();
Height = image.get_Height();
result = true;
}
else
{
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken=0; ULONG_PTR gdiplusToken=0;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::Bitmap *file = new Gdiplus::Bitmap(fileName,false); Gdiplus::Bitmap *file = new Gdiplus::Bitmap(fileName,false);
if ((file) && (file->GetLastStatus()==Gdiplus::Ok)) if ((file) && (file->GetLastStatus()==Gdiplus::Ok))
{ {
Height = file->GetHeight(); Height = file->GetHeight();
Width = file->GetWidth(); Width = file->GetWidth();
double dpi_x = file->GetHorizontalResolution(); double dpi_x = file->GetHorizontalResolution();
double dpi_y = file->GetVerticalResolution(); double dpi_y = file->GetVerticalResolution();
if (dpi_x <1 )dpi_x = 96; if (dpi_x <1 )dpi_x = 96;
if (dpi_y <1 )dpi_y = 96; if (dpi_y <1 )dpi_y = 96;
Height = Height *72. / dpi_y; Height = Height *72. / dpi_y;
Width = Width * 72. /dpi_x; Width = Width * 72. /dpi_x;
result = true; result = true;
delete file; delete file;
} }
Gdiplus::GdiplusShutdown(gdiplusToken); Gdiplus::GdiplusShutdown(gdiplusToken);
#endif #endif
}
return result; return result;
} }
double static calculate_size_symbol(std::wstring name, double size, bool italic, bool bold, std::wstring test_str = L"") double static calculate_size_symbol_win(std::wstring name, double size, bool italic, bool bold, std::wstring test_str = L"")
{ {
double result =0; double result =0;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
...@@ -140,11 +106,10 @@ namespace _gdi_graphics_ ...@@ -140,11 +106,10 @@ namespace _gdi_graphics_
#endif #endif
return result; return result;
} }
double static calculate_size_symbol_asc(std::wstring name, double size, bool italic, bool bold) double static calculate_size_symbol_asc(std::wstring name, double size, bool italic, bool bold , CApplicationFonts *appFonts)
{ {
std::pair<float,float> val = GetMaxDigitSizePixelsImpl(name.c_str(), size, 96., 0); std::pair<float,float> val = cpdoccore::utils::GetMaxDigitSizePixels(name, size, 96., 0 , appFonts);
return val.first;
return val.first;
} }
}; };
...@@ -316,7 +316,7 @@ namespace StreamUtils ...@@ -316,7 +316,7 @@ namespace StreamUtils
ULONG lReadByte = 0; ULONG lReadByte = 0;
lReadByte = pStream->read(pMem, 4); lReadByte = pStream->read(pMem, 4);
#ifdef _DEBUG #if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
ATLASSERT(4 == lReadByte); ATLASSERT(4 == lReadByte);
#endif #endif
......
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