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

(1.0.0.149): ASCOfficeOdfFile

ods & odp - паттерный заливки 
свойство на открытие (xmlOptions) - presentationOnly

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@53157 954022d7-b5bf-4e40-9824-e11837661b57
parent 0dd6dfb9
......@@ -39,7 +39,7 @@ HRESULT ConvertOdp2Pptx(cpdoccore::odf::odf_document & inputDoc, const std::wstr
return S_OK;
}
HRESULT ConvertOO2OOX(const std::wstring &ext, const std::wstring & srcPath, const std::wstring & dstPath)
HRESULT ConvertOO2OOX(const std::wstring &ext, const std::wstring & srcPath, const std::wstring & dstPath, bool bOnlyPresentation)
{
HRESULT hr = S_OK;
......@@ -56,6 +56,9 @@ HRESULT ConvertOO2OOX(const std::wstring &ext, const std::wstring & srcPath, con
if (ext == L".odp")type = 3;
}
if (bOnlyPresentation && type != 3)return E_FAIL;
switch (type)
{
case 1:
......
#include <windows.h>
#include <string>
HRESULT ConvertOO2OOX(const std::wstring &ext, const std::wstring & srcPath, const std::wstring & dstPath);
\ No newline at end of file
HRESULT ConvertOO2OOX(const std::wstring &ext, const std::wstring & srcPath, const std::wstring & dstPath, bool bOnlyPresentation);
\ No newline at end of file
......@@ -19,6 +19,8 @@
#include "ConvertOO2OOX.h"
#include "..\..\..\..\Common\XmlUtils.h"
#pragma comment(lib, "cpformulasconvert-static.lib")
#pragma comment(lib, "cpxml-static.lib")
......@@ -40,6 +42,7 @@
COfficeOdfFile::COfficeOdfFile()
{
bOnlyPresentation = false;
office_utils_.CoCreateInstance(__uuidof(ASCOfficeUtils::COfficeUtils));
}
......@@ -66,6 +69,26 @@ boost::filesystem::wpath MakeTempDirectoryName(BSTR Dst)
}
bool COfficeOdfFile::loadOptionFromXML(CString parametr,BSTR sXMLOptions)
{
bool result = false;
XmlUtils::CXmlReader oXmlReader;
if( TRUE == oXmlReader.OpenFromXmlString( sXMLOptions ) )
{
if( TRUE == oXmlReader.ReadRootNode( _T("Options") ) )
{
if( TRUE == oXmlReader.ReadNode( parametr ) )
{
result = true;
}
}
}
return result;
}
HRESULT COfficeOdfFile::LoadFromFile(BSTR sSrcFileName, BSTR sDstPath, BSTR sXMLOptions)
{
HRESULT hr;
......@@ -98,6 +121,8 @@ HRESULT COfficeOdfFile::LoadFromFile(BSTR sSrcFileName, BSTR sDstPath, BSTR sXML
boost::filesystem::wpath dstTempPath = outputDir.string();
#endif
bOnlyPresentation = loadOptionFromXML(L"onlyPresentation", sXMLOptions);
try
{
boost::filesystem::create_directory(srcTempPath);
......@@ -161,7 +186,7 @@ HRESULT COfficeOdfFile::LoadFromFileImpl(const std::wstring & srcFileName,
return hr;
hr = ConvertOO2OOX(ext,srcTempPath, dstTempPath);
hr = ConvertOO2OOX(ext,srcTempPath, dstTempPath,bOnlyPresentation);
if FAILED(hr)
......
......@@ -92,6 +92,8 @@ private:
ATL::CComPtr< ASCOfficeUtils::IOfficeUtils > office_utils_;
private:
bool bOnlyPresentation;
bool loadOptionFromXML(CString parametr,BSTR sXMLOptions);
bool initialized();
HRESULT LoadFromFileImpl(const std::wstring & srcFileName,
const std::wstring & srcTempPath,
......
......@@ -2,6 +2,6 @@
//1
//0
//0
//145
#define INTVER 1,0,0,145
#define STRVER "1,0,0,145\0"
//149
#define INTVER 1,0,0,149
#define STRVER "1,0,0,149\0"
......@@ -585,6 +585,14 @@
RelativePath=".\src\odf\gradientstyle.h"
>
</File>
<File
RelativePath=".\src\odf\hatchstyle.cpp"
>
</File>
<File
RelativePath=".\src\odf\hatchstyle.h"
>
</File>
<File
RelativePath=".\src\odf\hyphenationkeep.cpp"
>
......
......@@ -49,11 +49,17 @@ std::pair<float,float> GetMaxDigitSizePixelsImpl(const wchar_t * fontName, float
for (int i = 0; i <= 9; ++i)
{
if (S_OK != (hr = fontMan->LoadString2( boost::lexical_cast<std::wstring>(i).c_str(), 0, 0)))
throw MeasureError();
return std::pair<float,float>(7,8);
float x, y, width, height;
if (S_OK != (hr = fontMan->MeasureString(&x, &y, &width, &height)))
throw MeasureError();
try
{
hr = fontMan->MeasureString(&x, &y, &width, &height);
}catch(...)
{
return std::pair<float,float>(7,8);
}
if (width> maxWidth)
maxWidth = width;
......
......@@ -181,8 +181,6 @@ void oox_serialize_bodyPr(std::wostream & strm, const std::vector<odf::_property
CP_XML_NODE(L"a:bodyPr")
{
_CP_OPT(int) iAlign;
odf::GetProperty(prop,L"textalign-horizontal",iAlign);
//if (iAlign) CP_XML_ATTR(L"name", val.name);
odf::GetProperty(prop,L"textalign-vertiacal",iAlign);
if (iAlign)
......@@ -202,6 +200,8 @@ void oox_serialize_bodyPr(std::wostream & strm, const std::vector<odf::_property
CP_XML_ATTR(L"anchor", L"just");break;
}
}
else CP_XML_ATTR(L"anchor", L"dist");break;
}
}
}
......
......@@ -190,12 +190,8 @@ void oox_serialize_gradient_fill(std::wostream & strm, const _oox_fill & val)
}break;
}
}
}
//gsLst (Gradient Stop List) 20.1.8.37
//lin (Linear Gradient Fill) 20.1.8.41
//path (Path Gradient) 20.1.8.46
//tileRect (Tile Rectangle) 20.1.8.59
}
}
void oox_serialize_hatch_fill(std::wostream & strm, const _oox_fill & val)
{
......@@ -204,8 +200,19 @@ void oox_serialize_hatch_fill(std::wostream & strm, const _oox_fill & val)
{
CP_XML_NODE(L"a:pattFill")
{
CP_XML_ATTR(L"prst",val.hatch->preset);
if (val.hatch->color_back_ref)
{
CP_XML_NODE(L"a:bgClr")
{
oox_serialize_srgb(CP_XML_STREAM(),*val.hatch->color_back_ref,val.opacity);
}
}
CP_XML_NODE(L"a:fgClr")
{
oox_serialize_srgb(CP_XML_STREAM(),val.hatch->color_ref,val.opacity);
}
}
}
}
void oox_serialize_fill(std::wostream & strm, const _oox_fill & val)
......
......@@ -52,6 +52,11 @@ namespace oox {
public:
oox_hatch_fill(){}
static oox_hatch_fill_ptr create();
std::wstring color_ref;
_CP_OPT(std::wstring) color_back_ref;
std::wstring preset;
};
////////////////////////////////////////////////////////////
class oox_gradient_fill;
......@@ -76,6 +81,7 @@ namespace oox {
double rect[4];
double angle;
std::vector<_color_position> colors;
};
//////////////////////////////////////////////////////////////////////////////
......
......@@ -26,18 +26,22 @@ void pptx_serialize_text(std::wostream & strm, const std::vector<odf::_property>
_CP_OPT(std::wstring) strTextContent;
odf::GetProperty(properties,L"text-content",strTextContent);
if (!strTextContent)return;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"p:txBody")
{
oox_serialize_bodyPr(CP_XML_STREAM(),properties);
if (strTextContent)
{
CP_XML_STREAM() << strTextContent.get();
}
else
{
CP_XML_NODE(L"a:p")//empty a:p
{
CP_XML_NODE(L"a:endParaRPr");
}
}
}
}
}
......@@ -87,27 +91,6 @@ void pptx_serialize_image(std::wostream & strm, _pptx_drawing const & val)
void pptx_serialize_shape(std::wostream & strm, _pptx_drawing const & val)
{
//std::wstring shapeType;
//
//if (val.sub_type<9 && val.sub_type>=0)
//{
// shapeType = _ooxShapeType[val.sub_type];
//}
//if (val.sub_type == 7)//custom
//{
// _CP_OPT(int) iVal;
// odf::GetProperty(val.additional,L"draw-type-index",iVal);
// if (iVal)shapeType = _OO_OOX_custom_shapes[*iVal].oox;
//}
//else if (val.sub_type<9 && val.sub_type>=0)
//{
// shapeType = _ooxShapeType[val.sub_type];
//}
//if ((val.place_holder_type_.length()>0) &&
// !(val.place_holder_type_== L"body" || val.place_holder_type_== L"title" || val.place_holder_type_== L"subTitle"))return;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"p:sp")
......
......@@ -269,6 +269,7 @@ void pptx_slide_context::process_images()
std::wstring fileName = BOOST_STRING_PATH(wpath(impl_->odfPacket_) / pic.xlink_href_);
drawing.fill.bitmap->bCrop = odf::parse_clipping(pic.clipping_string_,fileName,drawing.fill.bitmap->cropRect);
drawing.fill.bitmap->bStretch = true;
///////////////////////////////////////////////////////////////////////////////////////////////////
std::wstring ref;///
......
......@@ -231,45 +231,45 @@ void pptx_text_context::Impl::ApplyParagraphProperties(std::wstring style,odf::p
void pptx_text_context::Impl::write_pPr(std::wostream & strm)
{
get_styles_context().start();
//CP_XML_WRITER(strm)
//{
// CP_XML_NODE(L"a:pPr")
// {
strm << L"<a:pPr ";
int level = list_style_stack_.size()-1;
if (level>=0)
strm << L"lvl=\"" << level << L"\" ";
int level = list_style_stack_.size()-1;
odf::paragraph_format_properties paragraph_format_properties_;
ApplyParagraphProperties (styles_paragraph_, paragraph_format_properties_,odf::style_family::Paragraph);
paragraph_format_properties_.pptx_convert(pptx_context_);
const std::wstring & paragraphAttr = get_styles_context().paragraph_attr().str();
const std::wstring & paragraphNodes = get_styles_context().paragraph_nodes().str();
odf::paragraph_format_properties paragraph_format_properties_;
ApplyParagraphProperties (styles_paragraph_, paragraph_format_properties_,odf::style_family::Paragraph);
if (level < 0 && paragraphAttr.length() <1 && paragraphNodes.length()<1) return;
strm << L"<a:pPr ";
paragraph_format_properties_.pptx_convert(pptx_context_);
if (level>=0)
strm << L"lvl=\"" << level << L"\" ";
strm << get_styles_context().paragraph_attr().str();
strm << paragraphAttr;
strm << ">";
strm << get_styles_context().paragraph_nodes().str();
strm << paragraphNodes;
odf::list_style_container & list_styles = odf_context_.listStyleContainer();
odf::list_style_container & list_styles = odf_context_.listStyleContainer();
if (!list_styles.empty() && level>=0)
{
odf::text_list_style * s = list_styles.list_style_by_name(list_style_stack_.back());
if (s)
{
odf::office_element_ptr elm = s->get_content()[level];
if (elm)
{
elm->pptx_convert(pptx_context_);
}
strm << get_styles_context().list_style().str();
if (!list_styles.empty() && level>=0)
{
odf::text_list_style * s = list_styles.list_style_by_name(list_style_stack_.back());
if (s)
{
odf::office_element_ptr elm = s->get_content()[level];
if (elm)
{
elm->pptx_convert(pptx_context_);
}
strm << get_styles_context().list_style().str();
}
}
strm << L"</a:pPr>";
// }
//}
}
void pptx_text_context::Impl::write_rPr(std::wostream & strm)
......@@ -311,7 +311,8 @@ std::wstring pptx_text_context::Impl::dump_paragraph()
CP_XML_STREAM() << run_.str();
//CP_XML_NODE(L"a:endParaRPr") //- /
CP_XML_NODE(L"a:endParaRPr");
//- /
//{
// CP_XML_ATTR(L"dirty", 0);
//}
......@@ -338,7 +339,7 @@ void pptx_text_context::Impl::dump_run()
CP_XML_NODE(L"a:t")
{
//CP_XML_ATTR(L"xml:space", L"preserve"); ...
CP_XML_ATTR(L"xml:space", L"preserve");
CP_XML_STREAM() << content;
}
}
......@@ -458,20 +459,16 @@ void pptx_text_context::Impl::write_list_properties(std::wostream & strm)
{
if (!list_style_stack_.empty())
{
//if (first_element_list_item_)
{
const int id = odf_context_.listStyleContainer().id_by_name( current_list_style() );
//const int id = list_context_.id_by_name( current_list_style() );
CP_XML_WRITER(strm)
const int id = odf_context_.listStyleContainer().id_by_name( current_list_style() );
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"a:buAutoNum")
{
CP_XML_NODE(L"a:buAutoNum")
{
CP_XML_ATTR(L"type",L"arabicPeriod");
CP_XML_ATTR(L"startAt",id);//
}
first_element_list_item_ = false;
CP_XML_ATTR(L"type",L"arabicPeriod");
CP_XML_ATTR(L"startAt",id);//
}
}
first_element_list_item_ = false;
}
}
void pptx_text_context::Impl::write_list_styles(std::wostream & strm)//defaults style paragraph & lists
......
......@@ -27,12 +27,13 @@ void xlsx_serialize_text(std::wostream & strm, const std::vector<odf::_property>
{
_CP_OPT(std::wstring) strTextContent;
odf::GetProperty(properties,L"text-content",strTextContent);
if (strTextContent)
{
CP_XML_NODE(L"xdr:txBody")
{
oox_serialize_bodyPr(CP_XML_STREAM(),properties);
CP_XML_NODE(L"a:lstStyle");
CP_XML_NODE(L"xdr:txBody")
{
oox_serialize_bodyPr(CP_XML_STREAM(),properties);
CP_XML_NODE(L"a:lstStyle");
if (strTextContent)
{
CP_XML_NODE(L"a:p")
{
CP_XML_STREAM() << strTextContent.get();
......
......@@ -321,6 +321,7 @@ void xlsx_drawing_context::process_images(xlsx_table_metrics & table_metrics)
std::wstring fileName = BOOST_STRING_PATH(wpath(odf_packet_path_) / pic.xlink_href_);
drawing.fill.bitmap->bCrop = odf::parse_clipping(pic.clipping_string_,fileName,drawing.fill.bitmap->cropRect);
drawing.fill.bitmap->bStretch = true;
drawing.fill.bitmap->rId = impl_->get_mediaitems().add_or_find(pic.xlink_href_, drawing.type, isMediaInternal, ref);
impl_->add_drawing(drawing, isMediaInternal, drawing.fill.bitmap->rId , ref, drawing.type);
......
......@@ -184,6 +184,40 @@ int Compute_BorderWidth(const graphic_format_properties & graphicProperties, Bor
return get_value_emu(lengthValue);
}
void Compute_HatchFill(draw_hatch * image_style,oox::oox_hatch_fill_ptr fill)
{
int style =0;
if (image_style->draw_style_)style = image_style->draw_style_->get_type();
int angle = *image_style->draw_rotation_/10.;
if (image_style->draw_color_)fill->color_ref = image_style->draw_color_->get_hex_value();
double size =0;
if (image_style->draw_distance_)size = (image_style->draw_distance_->get_value_unit(length::cm));
switch(style)
{
case hatch_style::single:
if (angle == 0 || angle == 180) fill->preset = L"dkHorz";
else if (angle == 90 || angle == 270) fill->preset = L"dkVert";
else if ((angle>180 && angle <270)
|| (angle>0 && angle <90)) fill->preset = L"dkUpDiag";
else fill->preset = L"dkDnDiag";
break;
case hatch_style::doublee:
if (angle ==0 || angle == 90 || angle== 180 || angle == 270)
{
if (size > 0.2) fill->preset = L"lgGrid";
else fill->preset = L"smGrid";
}
else fill->preset = L"openDmnd";
break;
case hatch_style::triple:
fill->preset = L"pkt5";
break;
}
}
void Compute_GradientFill(draw_gradient * image_style,oox::oox_gradient_fill_ptr fill)
{
int style =0;
......@@ -276,9 +310,9 @@ void Compute_GradientFill(draw_gradient * image_style,oox::oox_gradient_fill_ptr
}
}break;
}
}
void Compute_GraphicFill(graphic_format_properties & props, styles_lite_container &styles, oox::_oox_fill & fill)
{
fill.type = 0;
......@@ -340,10 +374,27 @@ void Compute_GraphicFill(graphic_format_properties & props, styles_lite_containe
fill.gradient = oox::oox_gradient_fill::create();
Compute_GradientFill(image_style, fill.gradient);
}
}
}
if (props.draw_fill_hatch_name_)
{
const std::wstring style_name = L"hatch:" + *props.draw_fill_hatch_name_;
if (office_element_ptr style = styles.find_by_style_name(style_name))
{
if (draw_hatch * image_style = dynamic_cast<draw_hatch *>(style.get()))
{
fill.hatch = oox::oox_hatch_fill::create();
Compute_HatchFill(image_style, fill.hatch);
}
}
if ((fill.hatch) && (props.draw_fill_color_))
{
fill.hatch->color_back_ref = props.draw_fill_color_->get_hex_value();
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
#include "precompiled_cpodf.h"
#include "hatchstyle.h"
#include <ostream>
namespace cpdoccore {
namespace odf {
hatch_style hatch_style::parse(const std::wstring & Str)
{
std::wstring tmp = Str;
boost::algorithm::to_lower(tmp);
if (tmp == L"single")
return hatch_style( single );
else if (tmp == L"double")
return hatch_style( doublee );
else if (tmp == L"triple")
return hatch_style(triple );
else
{
BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
return hatch_style(single);
}
}
}
}
#pragma once
#include <iosfwd>
#include <string>
#include "odfattributes.h"
namespace cpdoccore {
namespace odf {
class hatch_style
{
public:
enum type
{
single,
doublee,
triple
};
hatch_style() {}
hatch_style(type _Type) : type_(_Type)
{}
type get_type() const
{
return type_;
};
static hatch_style parse(const std::wstring & Str);
private:
type type_;
};
std::wostream & operator << (std::wostream & _Wostream, const hatch_style & _Val);
}
APPLY_PARSE_XML_ATTRIBUTES(odf::hatch_style);
}
......@@ -428,7 +428,7 @@ void odf_document::Impl::parse_styles()
context_->drawStyles().add(L"bitmap:" + style->get_style_name(), elm);
}
BOOST_FOREACH(const office_element_ptr & elm, docStyles->draw_styles_.draw_opacity_)
BOOST_FOREACH(const office_element_ptr & elm, docStyles->draw_styles_.draw_opacity_)
{
draw_opacity * style = dynamic_cast<draw_opacity *>(elm.get());
......@@ -437,15 +437,15 @@ void odf_document::Impl::parse_styles()
context_->drawStyles().add(L"opacity:" + style->get_style_name(), elm);
}
// BOOST_FOREACH(const office_element_ptr & elm, docStyles->draw_styles_.draw_hatch_)
// {
// const draw_hatch_image * style = dynamic_cast<const draw_hatch_image *>(elm.get());
BOOST_FOREACH(const office_element_ptr & elm, docStyles->draw_styles_.draw_hatch_)
{
draw_hatch * style = dynamic_cast<draw_hatch *>(elm.get());
// if (!style)
// continue;
if (!style)
continue;
//context_->drawStyles().add(L"hatch:" + style->get_style_name(), elm);
// }
context_->drawStyles().add(L"hatch:" + style->get_style_name(), elm);
}
}
while(0); // end parse styles
}
......
......@@ -28,6 +28,8 @@ void graphic_format_properties::add_attributes( const xml::attributes_wc_ptr & A
CP_APPLY_ATTR(L"draw:wrap-influence-on-position", draw_wrap_influence_on_position_);
CP_APPLY_ATTR(L"draw:textarea-horizontal-align", draw_textarea_horizontal_align_);
CP_APPLY_ATTR(L"draw:textarea-vertical-align", draw_textarea_vertical_align_);
CP_APPLY_ATTR(L"draw:fill-hatch-solid", draw_fill_hatch_solid_);
CP_APPLY_ATTR(L"draw:stroke", draw_stroke_);
CP_APPLY_ATTR(L"draw:stroke-dash", draw_stroke_dash_);
......@@ -106,6 +108,7 @@ void graphic_format_properties::apply_from(const graphic_format_properties & Oth
_CP_APPLY_PROP2(draw_marker_end_);
_CP_APPLY_PROP2(draw_opacity_);
_CP_APPLY_PROP2(draw_image_opacity_);
_CP_APPLY_PROP2(draw_fill_hatch_solid_);
_CP_APPLY_PROP2(draw_textarea_horizontal_align_);
_CP_APPLY_PROP2(draw_textarea_vertical_align_);
......
......@@ -241,6 +241,24 @@ void draw_gradient::add_child_element( xml::sax * Reader, const ::std::wstring &
CP_NOT_APPLICABLE_ELM();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * draw_hatch::ns = L"draw";
const wchar_t * draw_hatch::name = L"hatch";
void draw_hatch::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"draw:name", draw_name_);
CP_APPLY_ATTR(L"draw:display-name", draw_display_name_);
CP_APPLY_ATTR(L"draw:style", draw_style_);
CP_APPLY_ATTR(L"draw:color", draw_color_);
CP_APPLY_ATTR(L"draw:distance", draw_distance_);
CP_APPLY_ATTR(L"draw:rotation", draw_rotation_);
}
void draw_hatch::add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name)
{
CP_NOT_APPLICABLE_ELM();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * draw_opacity::ns = L"draw";
const wchar_t * draw_opacity::name = L"opacity";
......
......@@ -31,6 +31,7 @@
#include "common_attlists.h"
#include "noteclass.h"
#include "gradientstyle.h"
#include "hatchstyle.h"
#include "styles_list.h"
......@@ -153,6 +154,35 @@ private:
};
CP_REGISTER_OFFICE_ELEMENT2(draw_gradient);
/////////////////////////////////////////////////////////////////////////////////////////////////
/// \class style_draw_hatch
class draw_hatch : public office_element_impl<draw_hatch>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeStyleDrawHatch;
CPDOCCORE_DEFINE_VISITABLE();
std::wstring get_style_name(){return draw_name_.get_value_or(L"");}
_CP_OPT(hatch_style) draw_style_;
_CP_OPT(int) draw_rotation_;
_CP_OPT(length) draw_distance_;
_CP_OPT(color) draw_color_;
private:
_CP_OPT(std::wstring) draw_name_;
_CP_OPT(std::wstring) draw_display_name_;
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name);
friend class odf_document;
};
CP_REGISTER_OFFICE_ELEMENT2(draw_hatch);
/////////////////////////////////////////////////////////////////////////////////////////////////
/// \class style_draw_gradient
class draw_opacity : public office_element_impl<draw_opacity>
{
......
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