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()
}
void docx_conversion_context::set_font_directory(std::wstring pathFonts)
{
if (applicationFonts_ == NULL) return;
applicationFonts_->InitializeFromFolder(pathFonts);
if (applicationFonts_)
applicationFonts_->InitializeFromFolder(pathFonts);
}
std::wstring styles_map::get(const std::wstring & Name, odf_types::style_family::type Type)
{
......
......@@ -494,7 +494,7 @@ public:
void end_comment();
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_; }
bool process_headers_footers_;
......
......@@ -6,6 +6,7 @@
#include <float.h>
#include "../../DesktopEditor/fontengine/FontManager.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
namespace cpdoccore {
namespace utils {
......@@ -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
{
_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;
return val;
std::pair<float, float> val = GetMaxDigitSizePixelsImpl(fontName, fontSize, dpi, fontStyle, pFontManager);
if (pFontManager)
{
pFontManager->m_pApplication = NULL;
delete pFontManager;
}
_CP_LOG << "ok" << std::endl;
return val;
}
}
catch(...)
{
......
......@@ -3,12 +3,12 @@
#include <utility>
#include <string>
class CFontManager;
class CApplicationFonts;
namespace cpdoccore {
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()
}
void pptx_conversion_context::set_font_directory(std::wstring pathFonts)
{
if (applicationFonts_ == NULL) return;
applicationFonts_->InitializeFromFolder(pathFonts);
if (applicationFonts_ )
applicationFonts_->InitializeFromFolder(pathFonts);
}
//
//void pptx_conversion_context::start_chart(std::wstring const & name)
......
......@@ -482,7 +482,7 @@ std::pair<float,float> xlsx_conversion_context::getMaxDigitSize()
else
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_;
}
......
......@@ -13,6 +13,9 @@
#include "style_paragraph_properties.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
namespace cpdoccore {
using namespace odf_types;
......@@ -26,6 +29,20 @@ odf_conversion_context::odf_conversion_context(package::odf_document * outputDoc
output_document_ = outputDocument;
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()
......@@ -57,13 +74,6 @@ _mediaitems* odf_conversion_context::mediaitems()
return &objects_[current_object_].mediaitems;
}
odf_conversion_context::~odf_conversion_context()
{
}
void odf_conversion_context::end_document()
{
rels rels_;
......
......@@ -10,6 +10,8 @@
#include "mediaitems.h"
class CApplicationFonts;
namespace cpdoccore {
namespace odf_writer {
......@@ -36,10 +38,13 @@ public:
odf_conversion_context(package::odf_document * outputDocument);
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();
package::odf_document * output_document_;
package::odf_document *output_document_;
CApplicationFonts *applicationFonts_;
virtual odf_drawing_context * drawing_context() = 0;
......
......@@ -12,6 +12,7 @@
#include "odf_text_context.h"
#include "paragraph_elements.h"
namespace cpdoccore {
using namespace odf_types;
......@@ -21,13 +22,13 @@ namespace odf_writer {
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)
{
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.;
}
......@@ -321,7 +322,7 @@ void ods_conversion_context::calculate_font_metrix(std::wstring name, double siz
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()
......
......@@ -89,6 +89,8 @@ private:
odf_text_context* current_text_context_;
office_spreadsheet* root_spreadsheet_;
};
......
......@@ -27,13 +27,13 @@ namespace odf_writer {
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)
{
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.;
}
......@@ -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");
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)
// - drawing_context
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_bitmap_style();
......@@ -312,7 +312,7 @@ void OoxConverter::convert(OOX::Vml::CFill *vml_fill)
if (pathImage.GetLength() > 0)
{
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);
}
......
......@@ -29,12 +29,15 @@ namespace Oox2Odf
{
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;
if (type == L"text") impl_ = new DocxConverter(path, CallBack);
if (type == L"spreadsheet") impl_ = new XlsxConverter(path, CallBack);
if (impl_)
impl_->set_fonts_directory(fontsPath);
}
Converter::~Converter()
......@@ -73,7 +76,12 @@ bool OoxConverter::UpdateProgress(long nComplete)
return FALSE;
}
void OoxConverter::set_fonts_directory(const std::wstring &fontsPath)
{
odf_context()->set_fonts_directory(fontsPath);
}
void OoxConverter::convert(OOX::WritingElement *oox_unknown)
{
try
......@@ -740,7 +748,7 @@ void OoxConverter::convert(OOX::Drawing::CBlipFillProperties *oox_bitmap_fill, C
if (pathImage.GetLength() > 0)
{
odf_context()->drawing_context()->set_bitmap_link(string2std_string(pathImage));
_gdi_graphics_::GetResolution(pathImage, Width, Height);
_graphics_utils_::GetResolution(pathImage, Width, Height);
}
else
{
......
......@@ -300,6 +300,8 @@ public:
pCallBack = CallBack;
bUserStopConvert = 0;}
void set_fonts_directory (const std::wstring & fontsPath);
const ProgressCallback* pCallBack;
short bUserStopConvert;
......
......@@ -2172,7 +2172,7 @@ void DocxConverter::convert(OOX::Drawing::CPicture * oox_picture)
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));
{
......
......@@ -11,7 +11,7 @@ namespace Oox2Odf
{
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();
public:
......
......@@ -1814,7 +1814,7 @@ void XlsxConverter::convert(OOX::Spreadsheet::CPic* oox_picture)
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));
{
......
......@@ -7,92 +7,58 @@
#include <atlbase.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
#import "../../../Redist/ASCGraphics.dll" rename_namespace("ASCGraphics")
#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)))
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.);
}
class CFontManager;
namespace _graphics_utils_
{
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)
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken=0;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken=0;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Gdiplus::Bitmap *file = new Gdiplus::Bitmap(fileName,false);
if ((file) && (file->GetLastStatus()==Gdiplus::Ok))
{
Height = file->GetHeight();
Width = file->GetWidth();
Gdiplus::Bitmap *file = new Gdiplus::Bitmap(fileName,false);
if ((file) && (file->GetLastStatus()==Gdiplus::Ok))
{
Height = file->GetHeight();
Width = file->GetWidth();
double dpi_x = file->GetHorizontalResolution();
double dpi_y = file->GetVerticalResolution();
double dpi_x = file->GetHorizontalResolution();
double dpi_y = file->GetVerticalResolution();
if (dpi_x <1 )dpi_x = 96;
if (dpi_y <1 )dpi_y = 96;
if (dpi_x <1 )dpi_x = 96;
if (dpi_y <1 )dpi_y = 96;
Height = Height *72. / dpi_y;
Width = Width * 72. /dpi_x;
result = true;
delete file;
}
Gdiplus::GdiplusShutdown(gdiplusToken);
Height = Height *72. / dpi_y;
Width = Width * 72. /dpi_x;
result = true;
delete file;
}
Gdiplus::GdiplusShutdown(gdiplusToken);
#endif
}
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;
#if defined(_WIN32) || defined(_WIN64)
......@@ -140,11 +106,10 @@ namespace _gdi_graphics_
#endif
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);
return val.first;
std::pair<float,float> val = cpdoccore::utils::GetMaxDigitSizePixels(name, size, 96., 0 , appFonts);
return val.first;
}
};
......@@ -316,7 +316,7 @@ namespace StreamUtils
ULONG lReadByte = 0;
lReadByte = pStream->read(pMem, 4);
#ifdef _DEBUG
#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
ATLASSERT(4 == lReadByte);
#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