Commit d6907bd9 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader- Список.ods, Book 50.ods - именованые формулы, поправлен crop image файлов

parent 6370c8c2
...@@ -21,6 +21,9 @@ public: ...@@ -21,6 +21,9 @@ public:
// $1.$A$1 -> 1!$A$1 // $1.$A$1 -> 1!$A$1
std::wstring convert_named_ref(std::wstring const & expr); std::wstring convert_named_ref(std::wstring const & expr);
//a-la convert without check formula
std::wstring convert_named_expr(std::wstring const & expr);
//Sheet2.C3:Sheet2.C19 -> Sheet2!C3:C19 //Sheet2.C3:Sheet2.C19 -> Sheet2!C3:C19
std::wstring convert_chart_distance(std::wstring const & expr); std::wstring convert_chart_distance(std::wstring const & expr);
......
...@@ -429,7 +429,28 @@ std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr) ...@@ -429,7 +429,28 @@ std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr)
impl_->replace_named_ref(workstr); impl_->replace_named_ref(workstr);
return workstr; return workstr;
} }
std::wstring odf2oox_converter::convert_named_expr(const std::wstring& expr)
{
std::wstring workstr = expr;
boost::algorithm::replace_all(workstr, L" ", L"PROBEL");
boost::algorithm::replace_all(workstr, L"'", L"APOSTROF");
impl_->replace_cells_range(workstr);
impl_->replace_semicolons(workstr);
impl_->replace_vertical(workstr);
int res_find=0;
if ((res_find = workstr.find(L"CONCATINATE")) > 0)
{
//ìîãóò áûòü ÷àñòè÷íî çàäàíû äèàïàçîíû
//todooo
}
boost::algorithm::replace_all(workstr, L"PROBEL", L" ");
boost::algorithm::replace_all(workstr, L"APOSTROF", L"'");
return workstr;
}
std::wstring odf2oox_converter::convert_ref(std::wstring const & expr) std::wstring odf2oox_converter::convert_ref(std::wstring const & expr)
{ {
......
...@@ -406,7 +406,7 @@ void pptx_slide_context::process_images() ...@@ -406,7 +406,7 @@ void pptx_slide_context::process_images()
std::wstring fileName = impl_->odfPacket_ + FILE_SEPARATOR_STR + pic.xlink_href_; std::wstring fileName = impl_->odfPacket_ + FILE_SEPARATOR_STR + pic.xlink_href_;
drawing.fill.bitmap->bCrop = odf_reader::parse_clipping(pic.clipping_string_,fileName,drawing.fill.bitmap->cropRect); drawing.fill.bitmap->bCrop = odf_reader::parse_clipping(pic.clipping_string_,fileName,drawing.fill.bitmap->cropRect, NULL);
drawing.fill.bitmap->bStretch = true; drawing.fill.bitmap->bStretch = true;
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -15,7 +15,7 @@ namespace oox { ...@@ -15,7 +15,7 @@ namespace oox {
class xlsx_defined_names::Impl class xlsx_defined_names::Impl
{ {
public: public:
void add(std::wstring const & name, std::wstring const & ref) void add(std::wstring const & name, std::wstring const & ref, bool formula)
{ {
int is_file_link = 0; int is_file_link = 0;
...@@ -23,8 +23,17 @@ public: ...@@ -23,8 +23,17 @@ public:
if ((is_file_link = ref.find(L"/")) >=0) return; if ((is_file_link = ref.find(L"/")) >=0) return;
formulasconvert::odf2oox_converter converter; formulasconvert::odf2oox_converter converter;
std::wstring const f = converter.convert_named_ref(ref); std::wstring res;
name_and_ref_.push_back(name_and_ref(name, f));
if (formula)
{
res = converter.convert_named_expr(ref);
}
else
{
res = converter.convert_named_ref(ref);
}
name_and_ref_.push_back(name_and_ref(name, res));
} }
void xlsx_serialize(std::wostream & _Wostream) void xlsx_serialize(std::wostream & _Wostream)
...@@ -61,9 +70,9 @@ xlsx_defined_names::~xlsx_defined_names() ...@@ -61,9 +70,9 @@ xlsx_defined_names::~xlsx_defined_names()
{ {
} }
void xlsx_defined_names::add(std::wstring const & name, std::wstring const & ref) void xlsx_defined_names::add(std::wstring const & name, std::wstring const & ref, bool formula)
{ {
return impl_->add(name, ref); return impl_->add(name, ref, formula);
} }
void xlsx_defined_names::xlsx_serialize(std::wostream & _Wostream) void xlsx_defined_names::xlsx_serialize(std::wostream & _Wostream)
......
...@@ -16,7 +16,7 @@ namespace oox { ...@@ -16,7 +16,7 @@ namespace oox {
~xlsx_defined_names(); ~xlsx_defined_names();
public: public:
void add(std::wstring const & name, std::wstring const & ref); void add(std::wstring const & name, std::wstring const & ref, bool formula = false);
void xlsx_serialize(std::wostream & _Wostream); void xlsx_serialize(std::wostream & _Wostream);
private: private:
......
...@@ -247,7 +247,7 @@ void xlsx_serialize(std::wostream & strm, _xlsx_drawing & val) ...@@ -247,7 +247,7 @@ void xlsx_serialize(std::wostream & strm, _xlsx_drawing & val)
{ {
CP_XML_NODE(L"xdr:twoCellAnchor") CP_XML_NODE(L"xdr:twoCellAnchor")
{ {
//CP_XML_ATTR(L"editAs", L"absolute");//"absolute");oneCell CP_XML_ATTR(L"editAs", L"oneCell");//"absolute");oneCell
xlsx_serialize (CP_XML_STREAM(), val.from_); xlsx_serialize (CP_XML_STREAM(), val.from_);
xlsx_serialize (CP_XML_STREAM(), val.to_); xlsx_serialize (CP_XML_STREAM(), val.to_);
......
...@@ -467,7 +467,7 @@ void xlsx_drawing_context::process_image(drawing_object_description & obj,_xlsx_ ...@@ -467,7 +467,7 @@ void xlsx_drawing_context::process_image(drawing_object_description & obj,_xlsx_
} }
std::wstring fileName = odf_packet_path_ + FILE_SEPARATOR_STR + obj.xlink_href_; std::wstring fileName = odf_packet_path_ + FILE_SEPARATOR_STR + obj.xlink_href_;
drawing.fill.bitmap->bCrop = odf_reader::parse_clipping(obj.clipping_string_, fileName, drawing.fill.bitmap->cropRect); drawing.fill.bitmap->bCrop = odf_reader::parse_clipping(obj.clipping_string_, fileName, drawing.fill.bitmap->cropRect, NULL/*applicationFonts_*/);
drawing.fill.bitmap->bStretch = true; drawing.fill.bitmap->bStretch = true;
std::wstring ref;/// std::wstring ref;///
......
...@@ -21,49 +21,35 @@ ...@@ -21,49 +21,35 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#include "../../../DesktopEditor/raster/BgraFrame.h" #include "../../../DesktopEditor/raster/BgraFrame.h"
#include "../../../DesktopEditor/raster/MetaFile/MetaFile.h"
#if defined(_WIN32) || defined(_WIN64)
#include <Windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
#endif
extern double getSystemDPI(); extern double getSystemDPI();
namespace _image_file_ namespace _image_file_
{ {
bool GetResolution(const wchar_t* fileName, int & Width, int &Height) bool GetResolution(const wchar_t* fileName, int & Width, int &Height, CApplicationFonts * appFonts)
{ {
bool result =false;
CBgraFrame image; CBgraFrame image;
if (result = image.OpenFile(fileName, 0 )) MetaFile::CMetaFile meta_file(appFonts);
if ( meta_file.LoadFromFile(fileName))
{
double dX = 0, dY = 0, dW = 0, dH = 0;
meta_file.GetBounds(&dX, &dY, &dW, &dH);
Width = dW;
Height = dH;
}
else if ( image.OpenFile(fileName, 0 ))
{ {
Width = image.get_Width(); Width = image.get_Width();
Height = image.get_Height(); Height = image.get_Height();
result = true; return true;
} }
else
{
#if defined(_WIN32) || defined(_WIN64)
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();
result = true; return false;
delete file;
}
Gdiplus::GdiplusShutdown(gdiplusToken);
#endif
}
return result;
} }
}; };
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -83,28 +69,36 @@ int get_value_emu(double pt) ...@@ -83,28 +69,36 @@ int get_value_emu(double pt)
{ {
return static_cast<int>((pt* 360000 * 2.54) / 72); return static_cast<int>((pt* 360000 * 2.54) / 72);
} }
bool parse_clipping(std::wstring strClipping,std::wstring fileName, double_4 & clip_rect) bool parse_clipping(std::wstring strClipping,std::wstring fileName, double_4 & clip_rect, CApplicationFonts * appFonts)
{ {
memset(clip_rect, 0, 4*sizeof(double)); memset(clip_rect, 0, 4*sizeof(double));
if (strClipping.length() <1 || fileName.length()<1)return false; if (strClipping.length() <1 || fileName.length()<1)return false;
int fileWidth=0,fileHeight=0; //<top>, <right>, <bottom>, <left> - http://www.w3.org/TR/2001/REC-xsl-20011015/xslspec.html#clip
if (!_image_file_::GetResolution(fileName.data(),fileWidth,fileHeight) || fileWidth<1 || fileHeight<1)return false;
bool bEnableCrop = false;
std::vector<std::wstring> Points; std::vector<std::wstring> Points;
std::vector<length> Points_pt; std::vector<length> Points_pt;
boost::algorithm::split(Points,strClipping, boost::algorithm::is_any_of(L" ,"), boost::algorithm::token_compress_on); boost::algorithm::split(Points,strClipping, boost::algorithm::is_any_of(L" ,"), boost::algorithm::token_compress_on);
//<top>, <right>, <bottom>, <left> - http://www.w3.org/TR/2001/REC-xsl-20011015/xslspec.html#clip
BOOST_FOREACH(std::wstring const & p, Points) BOOST_FOREACH(std::wstring const & p, Points)
{ {
Points_pt.push_back(length::parse(p) ); Points_pt.push_back(length::parse(p) );
if (Points_pt.back().get_value() > 0.00001) bEnableCrop = true;
} }
if (Points_pt.size()>3)// ..
if (!bEnableCrop) return false;
int fileWidth=0,fileHeight=0;
if (!_image_file_::GetResolution(fileName.data(), fileWidth, fileHeight, appFonts) || fileWidth<1 || fileHeight<1) return false;
if (Points_pt.size() > 3)// ..
{ {
float dpi_ = 96.;///getSystemDPI(); float dpi_ = 96.;///getSystemDPI();
clip_rect[0] = dpi_ * Points_pt[3].get_value_unit(length::inch); clip_rect[0] = dpi_ * Points_pt[3].get_value_unit(length::inch);
......
...@@ -19,9 +19,11 @@ ...@@ -19,9 +19,11 @@
#include "datatypes/targetframename.h" #include "datatypes/targetframename.h"
#include "datatypes/common_attlists.h" #include "datatypes/common_attlists.h"
//class CApplicationFonts;
namespace _image_file_ namespace _image_file_
{ {
bool GetResolution(const wchar_t* fileName, int & Width, int &Height); bool GetResolution(const wchar_t* fileName, int & Width, int &Height, CApplicationFonts * appFonts);
} }
namespace cpdoccore { namespace cpdoccore {
...@@ -43,7 +45,7 @@ void Compute_GraphicFill(const odf_types::common_draw_fill_attlist & props, ...@@ -43,7 +45,7 @@ void Compute_GraphicFill(const odf_types::common_draw_fill_attlist & props,
const office_element_ptr & style_image, styles_lite_container &styles, oox::_oox_fill & fill); const office_element_ptr & style_image, styles_lite_container &styles, oox::_oox_fill & fill);
typedef double double_4[4]; typedef double double_4[4];
bool parse_clipping(std::wstring strClipping,std::wstring fileName,double_4 & clip_rect); bool parse_clipping(std::wstring strClipping,std::wstring fileName,double_4 & clip_rect, CApplicationFonts * appFonts);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class draw_a : public office_element_impl<draw_a> class draw_a : public office_element_impl<draw_a>
{ {
......
...@@ -1091,7 +1091,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context) ...@@ -1091,7 +1091,7 @@ void draw_image::docx_convert(oox::docx_conversion_context & Context)
std::wstring fileName = Context.root()->get_folder() + FILE_SEPARATOR_STR+ href; std::wstring fileName = Context.root()->get_folder() + FILE_SEPARATOR_STR+ href;
drawing.fill.bitmap->bCrop = parse_clipping(strRectClip,fileName,drawing.fill.bitmap->cropRect); drawing.fill.bitmap->bCrop = parse_clipping(strRectClip,fileName,drawing.fill.bitmap->cropRect, NULL/*Context.applicationFonts_*/);
} }
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -30,18 +30,7 @@ void table_named_expressions::add_child_element(xml::sax * Reader, ...@@ -30,18 +30,7 @@ void table_named_expressions::add_child_element(xml::sax * Reader,
const ::std::wstring & Ns, const ::std::wstring & Ns,
const ::std::wstring & Name) const ::std::wstring & Name)
{ {
if CP_CHECK_NAME(L"table", L"named-range") CP_CREATE_ELEMENT(content_);
{
CP_CREATE_ELEMENT(named_range_);
}
else if CP_CHECK_NAME(L"table", L"named-expression")
{
CP_CREATE_ELEMENT(named_expression_);
}
else
{
CP_NOT_APPLICABLE_ELM();
}
} }
void table_named_expressions::docx_convert(oox::docx_conversion_context & Context) void table_named_expressions::docx_convert(oox::docx_conversion_context & Context)
...@@ -50,7 +39,7 @@ void table_named_expressions::docx_convert(oox::docx_conversion_context & Contex ...@@ -50,7 +39,7 @@ void table_named_expressions::docx_convert(oox::docx_conversion_context & Contex
void table_named_expressions::xlsx_convert(oox::xlsx_conversion_context & Context) void table_named_expressions::xlsx_convert(oox::xlsx_conversion_context & Context)
{ {
BOOST_FOREACH(office_element_ptr const & elm, named_range_) BOOST_FOREACH(office_element_ptr const & elm, content_)
{ {
elm->xlsx_convert(Context); elm->xlsx_convert(Context);
} }
...@@ -99,6 +88,11 @@ void table_named_expression::docx_convert(oox::docx_conversion_context & Context ...@@ -99,6 +88,11 @@ void table_named_expression::docx_convert(oox::docx_conversion_context & Context
void table_named_expression::xlsx_convert(oox::xlsx_conversion_context & Context) void table_named_expression::xlsx_convert(oox::xlsx_conversion_context & Context)
{ {
if (table_expression_ && table_name_)
{
oox::xlsx_defined_names & ctx = Context.get_xlsx_defined_names();
ctx.add(table_name_.get(), table_expression_.get(), true);
}
} }
void table_named_expression::add_attributes(xml::attributes_wc_ptr const & Attributes) void table_named_expression::add_attributes(xml::attributes_wc_ptr const & Attributes)
......
...@@ -13,9 +13,7 @@ ...@@ -13,9 +13,7 @@
namespace cpdoccore { namespace cpdoccore {
namespace odf_reader { namespace odf_reader {
/// \class table_named_expressions // table:named-expressions
/// \brief table:named-expressions
/// table-named-expressions
class table_named_expressions : public office_element_impl<table_named_expressions> class table_named_expressions : public office_element_impl<table_named_expressions>
{ {
public: public:
...@@ -34,16 +32,13 @@ private: ...@@ -34,16 +32,13 @@ private:
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name); virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name);
private: private:
office_element_ptr_array named_range_; office_element_ptr_array content_;
office_element_ptr_array named_expression_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_named_expressions); CP_REGISTER_OFFICE_ELEMENT2(table_named_expressions);
/// \class table_named_range // table:named-range
/// \brief table:named-range
/// table-named-range
class table_named_range : public office_element_impl<table_named_range> class table_named_range : public office_element_impl<table_named_range>
{ {
public: public:
...@@ -71,9 +66,7 @@ private: ...@@ -71,9 +66,7 @@ private:
CP_REGISTER_OFFICE_ELEMENT2(table_named_range); CP_REGISTER_OFFICE_ELEMENT2(table_named_range);
/// \class table_named_expression // table:named-expression
/// \brief table:named-expression
/// table-named-expression
class table_named_expression : public office_element_impl<table_named_expression> class table_named_expression : public office_element_impl<table_named_expression>
{ {
public: public:
...@@ -97,11 +90,8 @@ private: ...@@ -97,11 +90,8 @@ private:
_CP_OPT(std::wstring) table_base_cell_address_; _CP_OPT(std::wstring) table_base_cell_address_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_named_expression); CP_REGISTER_OFFICE_ELEMENT2(table_named_expression);
} }
} }
......
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