mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-03-20 23:48:13 +08:00
Compare commits
6 Commits
core-win-3
...
core-win-3
| Author | SHA1 | Date | |
|---|---|---|---|
| 55e4902d66 | |||
| 2dc1ad5af7 | |||
| ab0def1840 | |||
| 957972e3be | |||
| 49e31f2c0c | |||
| 4585e86fb7 |
@ -45,7 +45,7 @@ namespace cpdoccore {
|
||||
namespace odf_writer {
|
||||
|
||||
|
||||
/// style:header-footer-properties-attlist
|
||||
// style:header-footer-properties-attlist
|
||||
class style_header_footer_properties_attlist
|
||||
{
|
||||
public:
|
||||
@ -53,11 +53,11 @@ public:
|
||||
|
||||
_CP_OPT(odf_types::length) svg_height_;
|
||||
_CP_OPT(odf_types::length) fo_min_height_;
|
||||
odf_types::common_horizontal_margin_attlist common_horizontal_margin_attlist_;
|
||||
odf_types::common_horizontal_margin_attlist common_horizontal_margin_attlist_;
|
||||
odf_types::common_vertical_margin_attlist common_vertical_margin_attlist_;
|
||||
odf_types::common_margin_attlist common_margin_attlist_;
|
||||
odf_types::common_border_attlist common_border_attlist_;
|
||||
odf_types::common_border_line_width_attlist common_border_line_width_attlist_;
|
||||
odf_types::common_border_line_width_attlist common_border_line_width_attlist_;
|
||||
odf_types::common_padding_attlist common_padding_attlist_;
|
||||
odf_types::common_background_color_attlist common_background_color_attlist_;
|
||||
odf_types::common_shadow_attlist common_shadow_attlist_;
|
||||
@ -65,7 +65,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/// style:header-footer-properties
|
||||
// style:header-footer-properties
|
||||
class style_header_footer_properties : public office_element_impl<style_header_footer_properties>
|
||||
{
|
||||
public:
|
||||
@ -89,7 +89,7 @@ public:
|
||||
CP_REGISTER_OFFICE_ELEMENT2(style_header_footer_properties)
|
||||
|
||||
|
||||
/// common:style-header-footer-attlist
|
||||
// common:style-header-footer-attlist
|
||||
class common_style_header_footer_attlist
|
||||
{
|
||||
public:
|
||||
@ -98,7 +98,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/// header:footer-content
|
||||
// header:footer-content
|
||||
class header_footer_content
|
||||
{
|
||||
public:
|
||||
|
||||
@ -325,9 +325,9 @@ bool odf_page_layout_context::add_footer(int type)
|
||||
//настраить нужно 1 раз
|
||||
if (!layout_state_list_.back().footer_size_) return true;
|
||||
|
||||
style_header_footer_properties * footer_props = get_footer_properties();
|
||||
style_header_footer_properties *footer_props = get_footer_properties();
|
||||
if (!footer_props)return true;
|
||||
style_page_layout_properties * props = get_properties();
|
||||
style_page_layout_properties *props = get_properties();
|
||||
if (!props)return true;
|
||||
|
||||
length length_ = length(layout_state_list_.back().footer_size_->get_value_unit(length::cm),length::cm);
|
||||
@ -369,9 +369,13 @@ bool odf_page_layout_context::add_header(int type)
|
||||
create_element(L"style", L"header-left", root_header_footer_, odf_context_);
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
create_element(L"style", L"header-first", root_header_footer_, odf_context_);
|
||||
}
|
||||
else
|
||||
{
|
||||
create_element(L"style", L"header", root_header_footer_, odf_context_);
|
||||
}
|
||||
|
||||
if (!root_header_footer_) return false;
|
||||
|
||||
@ -383,13 +387,13 @@ bool odf_page_layout_context::add_header(int type)
|
||||
//настроить нужно один раз
|
||||
if (!layout_state_list_.back().header_size_) return true;
|
||||
|
||||
style_header_footer_properties * header_props = get_header_properties();
|
||||
style_header_footer_properties *header_props = get_header_properties();
|
||||
if (!header_props)return true;
|
||||
|
||||
style_page_layout_properties * props = get_properties();
|
||||
style_page_layout_properties *props = get_properties();
|
||||
if (!props)return true;
|
||||
|
||||
length length_ = length(layout_state_list_.back().header_size_->get_value_unit(length::cm),length::cm);
|
||||
length length_ = length(layout_state_list_.back().header_size_->get_value_unit(length::cm), length::cm);
|
||||
|
||||
_CP_OPT(length) top_;
|
||||
|
||||
@ -418,6 +422,16 @@ bool odf_page_layout_context::add_header(int type)
|
||||
return true;
|
||||
}
|
||||
|
||||
void odf_page_layout_context::set_header_footer_image(office_element_ptr image)
|
||||
{
|
||||
style_header_footer_properties *header_footer_props = get_footer_properties();
|
||||
if (!header_footer_props)return;
|
||||
|
||||
if (!header_footer_props->style_background_image_ )// картинка общая для всех четных, нечетных, первых, так же нету центральных, левых, правых
|
||||
{
|
||||
header_footer_props->style_background_image_ = image;
|
||||
}
|
||||
}
|
||||
void odf_page_layout_context::set_page_border_offset (int type)
|
||||
{
|
||||
if (type < 1) return;
|
||||
|
||||
@ -98,12 +98,14 @@ public:
|
||||
bool add_footer(int type);
|
||||
void set_footer_size(_CP_OPT(odf_types::length) length_);
|
||||
|
||||
bool add_header(int type);
|
||||
bool add_header(int type);
|
||||
void set_header_size(_CP_OPT(odf_types::length) length_);
|
||||
|
||||
void set_background (_CP_OPT(odf_types::color) & color, int type);
|
||||
void set_header_footer_image (office_element_ptr image);
|
||||
void set_background (_CP_OPT(odf_types::color) & color, int type);
|
||||
|
||||
void set_page_number_format (_CP_OPT(int) & type, _CP_OPT(int) & start);
|
||||
|
||||
void set_page_number_format (_CP_OPT(int) & type, _CP_OPT(int) & start);
|
||||
|
||||
office_element_ptr root_header_footer_; //для топовых элементов в style:footer
|
||||
|
||||
|
||||
@ -161,7 +161,18 @@ void odf_text_context::add_text_date(const std::wstring & text)
|
||||
text_date* s = dynamic_cast<text_date*>(s_elm.get());
|
||||
if (s) s->add_text(text);
|
||||
|
||||
if (current_level_.size()>0)
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
void odf_text_context::add_text_time(const std::wstring & text)
|
||||
{
|
||||
office_element_ptr s_elm;
|
||||
create_element(L"text", L"time", s_elm, odf_context_);
|
||||
|
||||
text_time* s = dynamic_cast<text_time*>(s_elm.get());
|
||||
if (s) s->add_text(text);
|
||||
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
void odf_text_context::add_text_page_number(const std::wstring & text)
|
||||
@ -172,9 +183,43 @@ void odf_text_context::add_text_page_number(const std::wstring & text)
|
||||
text_page_number* s = dynamic_cast<text_page_number*>(s_elm.get());
|
||||
if (s) s->add_text(text);
|
||||
|
||||
if (current_level_.size()>0)
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
void odf_text_context::add_text_page_count(const std::wstring & text)
|
||||
{
|
||||
office_element_ptr s_elm;
|
||||
create_element(L"text", L"page-count", s_elm, odf_context_);
|
||||
|
||||
text_page_count* s = dynamic_cast<text_page_count*>(s_elm.get());
|
||||
if (s) s->add_text(text);
|
||||
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
void odf_text_context::add_text_file_name(const std::wstring &text)
|
||||
{
|
||||
office_element_ptr s_elm;
|
||||
create_element(L"text", L"file-name", s_elm, odf_context_);
|
||||
|
||||
text_file_name* s = dynamic_cast<text_file_name*>(s_elm.get());
|
||||
if (s) s->add_text(text);
|
||||
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
void odf_text_context::add_text_sheet_name(const std::wstring &text)
|
||||
{
|
||||
office_element_ptr s_elm;
|
||||
create_element(L"text", L"sheet-name", s_elm, odf_context_);
|
||||
|
||||
text_sheet_name* s = dynamic_cast<text_sheet_name*>(s_elm.get());
|
||||
if (s) s->add_text(text);
|
||||
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
|
||||
void odf_text_context::add_text_space(int count)
|
||||
{
|
||||
office_element_ptr s_elm;
|
||||
@ -188,7 +233,7 @@ void odf_text_context::add_text_space(int count)
|
||||
//odf_element_state state={ s_elm, L"", office_element_ptr(), level};
|
||||
//text_elements_list_.push_back(state);
|
||||
|
||||
if (current_level_.size()>0)
|
||||
if (false == current_level_.empty())
|
||||
current_level_.back().elm->add_child_element(s_elm);
|
||||
}
|
||||
void odf_text_context::set_symbol_font(const std::wstring & font)
|
||||
@ -262,7 +307,7 @@ void odf_text_context::start_paragraph(office_element_ptr & elm, bool styled)
|
||||
paragraph_properties_ = style_->content_.get_style_paragraph_properties();
|
||||
}
|
||||
}
|
||||
else if (parent_paragraph_style_.length() >0)
|
||||
else if (false == parent_paragraph_style_.empty())
|
||||
{
|
||||
text_p* p = dynamic_cast<text_p*>(elm.get());
|
||||
if (p)p->paragraph_.paragraph_attrs_.text_style_name_ = parent_paragraph_style_;
|
||||
@ -287,7 +332,7 @@ void odf_text_context::start_paragraph(office_element_ptr & elm, bool styled)
|
||||
|
||||
void odf_text_context::end_paragraph()
|
||||
{
|
||||
if (single_paragraph_ == false && current_level_.size() > 0)
|
||||
if (false == single_paragraph_ && false == current_level_.empty())
|
||||
{
|
||||
current_level_.pop_back();
|
||||
}
|
||||
|
||||
@ -83,11 +83,15 @@ public:
|
||||
|
||||
void set_single_object (bool bSingle, style_paragraph_properties *para_props, style_text_properties *text_props);
|
||||
|
||||
void add_text_content (const std::wstring & text);
|
||||
void add_text_content (const std::wstring &text);
|
||||
void add_text_space (int count);
|
||||
void add_text_date (const std::wstring & text);
|
||||
void add_text_page_number(const std::wstring & text);
|
||||
|
||||
void add_text_date (const std::wstring &text);
|
||||
void add_text_time (const std::wstring &text);
|
||||
void add_text_page_number(const std::wstring &text);
|
||||
void add_text_page_count(const std::wstring &text);
|
||||
void add_text_file_name (const std::wstring &text);
|
||||
void add_text_sheet_name(const std::wstring &text);
|
||||
|
||||
void set_symbol_font (const std::wstring & font);
|
||||
void set_symbol_text (int sym);
|
||||
|
||||
|
||||
@ -140,9 +140,13 @@ void ods_conversion_context::add_defined_expression( const std::wstring & name,
|
||||
{
|
||||
table_context_.add_defined_expression(name,value, sheet_id, printable);
|
||||
}
|
||||
void ods_conversion_context::add_header_footer_image(const std::wstring & name, office_element_ptr image)
|
||||
{
|
||||
current_table().mapHeaderFooterImages.insert(std::make_pair(name, image));
|
||||
}
|
||||
void ods_conversion_context::start_sheet()
|
||||
{
|
||||
create_element(L"table", L"table",root_spreadsheet_->getContent(),this);
|
||||
create_element(L"table", L"table", root_spreadsheet_->getContent(), this);
|
||||
table_context_.start_table(root_spreadsheet_->getContent().back());
|
||||
|
||||
drawing_context()->set_styles_context(styles_context());
|
||||
@ -589,6 +593,19 @@ void ods_conversion_context::add_text_content(const std::wstring & text)
|
||||
current_text_context_->add_text_content(text);
|
||||
}
|
||||
}
|
||||
|
||||
void ods_conversion_context::add_text(const std::wstring &text)
|
||||
{
|
||||
office_element_ptr paragr_elm;
|
||||
create_element(L"text", L"p", paragr_elm, this);
|
||||
|
||||
current_text_context_->start_paragraph(paragr_elm);
|
||||
|
||||
current_text_context_->add_text_content(text);
|
||||
|
||||
current_text_context_->end_paragraph();
|
||||
}
|
||||
|
||||
void ods_conversion_context::start_cell_text()
|
||||
{
|
||||
start_text_context();
|
||||
@ -663,7 +680,112 @@ void ods_conversion_context::end_table_view()
|
||||
settings_context()->end_table();
|
||||
settings_context()->set_current_view(-1);
|
||||
}
|
||||
bool ods_conversion_context::start_header(int type)// 0 - odd, 1 - first, 2 - even
|
||||
{
|
||||
if (page_layout_context()->add_header(type) == false) return false;
|
||||
if (page_layout_context()->last_master() == NULL) return false;
|
||||
|
||||
start_text_context();
|
||||
text_context()->set_styles_context(page_layout_context()->get_local_styles_context());
|
||||
|
||||
text_context()->start_element(page_layout_context()->last_master()->get_last_element());
|
||||
|
||||
if (false == current_table().mapHeaderFooterImages.empty())
|
||||
{
|
||||
std::wstring mask = std::wstring(L"H") + (type == 1 ? L"FIRST" : (type == 2 ? L"EVEN" : L""));
|
||||
|
||||
std::map<std::wstring, office_element_ptr>::iterator pFind;
|
||||
|
||||
pFind = current_table().mapHeaderFooterImages.find(L"C" + mask);
|
||||
if (pFind == current_table().mapHeaderFooterImages.end())
|
||||
{
|
||||
pFind = current_table().mapHeaderFooterImages.find(L"L" + mask);
|
||||
if (pFind == current_table().mapHeaderFooterImages.end())
|
||||
{
|
||||
pFind = current_table().mapHeaderFooterImages.find(L"R" + mask);
|
||||
}
|
||||
}
|
||||
|
||||
if (pFind != current_table().mapHeaderFooterImages.end())
|
||||
{
|
||||
page_layout_context()->set_header_footer_image(pFind->second);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ods_conversion_context::start_footer(int type)
|
||||
{
|
||||
if (page_layout_context()->add_footer(type) == false) return false;
|
||||
if (page_layout_context()->last_master() == NULL) return false;
|
||||
|
||||
start_text_context();
|
||||
text_context()->set_styles_context(page_layout_context()->get_local_styles_context());
|
||||
|
||||
text_context()->start_element(page_layout_context()->last_master()->get_last_element());
|
||||
|
||||
if (false == current_table().mapHeaderFooterImages.empty())
|
||||
{
|
||||
std::wstring mask = std::wstring(L"F") + (type == 1 ? L"FIRST" : (type == 2 ? L"EVEN" : L""));
|
||||
|
||||
std::map<std::wstring, office_element_ptr>::iterator pFind;
|
||||
|
||||
pFind = current_table().mapHeaderFooterImages.find(L"C" + mask);
|
||||
if (pFind == current_table().mapHeaderFooterImages.end())
|
||||
{
|
||||
pFind = current_table().mapHeaderFooterImages.find(L"L" + mask);
|
||||
if (pFind == current_table().mapHeaderFooterImages.end())
|
||||
{
|
||||
pFind = current_table().mapHeaderFooterImages.find(L"R" + mask);
|
||||
}
|
||||
}
|
||||
|
||||
if (pFind != current_table().mapHeaderFooterImages.end())
|
||||
{
|
||||
page_layout_context()->set_header_footer_image(pFind->second);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void ods_conversion_context::end_header_footer()
|
||||
{
|
||||
if (text_context()->current_level_.size() > 1)
|
||||
{
|
||||
text_context()->end_paragraph();
|
||||
end_header_footer_region();
|
||||
}
|
||||
text_context()->end_element();
|
||||
end_text_context();
|
||||
}
|
||||
void ods_conversion_context::start_header_footer_region(int type)
|
||||
{
|
||||
if (text_context()->current_level_.size() > 1)
|
||||
{
|
||||
text_context()->end_paragraph();
|
||||
end_header_footer_region();
|
||||
}
|
||||
|
||||
office_element_ptr region_elm_;
|
||||
|
||||
if (type == 1)
|
||||
{
|
||||
create_element(L"style", L"region-left", region_elm_, this);
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
create_element(L"style", L"region-center", region_elm_, this);
|
||||
}
|
||||
else if (type == 3)
|
||||
{
|
||||
create_element(L"style", L"region-right", region_elm_, this);
|
||||
}
|
||||
|
||||
text_context()->start_element(region_elm_);
|
||||
text_context()->start_paragraph(false);
|
||||
}
|
||||
void ods_conversion_context::end_header_footer_region()
|
||||
{
|
||||
text_context()->end_element();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,6 +120,16 @@ public:
|
||||
void start_drawings();
|
||||
void end_drawings();
|
||||
|
||||
bool start_header(int type);
|
||||
bool start_footer(int type);
|
||||
void end_header_footer();
|
||||
void start_header_footer_region(int type);
|
||||
void end_header_footer_region();
|
||||
|
||||
void add_text(const std::wstring &text);
|
||||
|
||||
void add_header_footer_image(const std::wstring & name, office_element_ptr image);
|
||||
|
||||
double convert_symbol_width(double val);
|
||||
|
||||
void add_defined_range (const std::wstring & name, const std::wstring & cell_range, int sheet_id, bool printable = false);
|
||||
|
||||
@ -410,6 +410,8 @@ public:
|
||||
|
||||
std::wstring office_table_name_;
|
||||
std::vector<ods_comment_state> comments_;
|
||||
|
||||
std::map<std::wstring, office_element_ptr> mapHeaderFooterImages;
|
||||
private:
|
||||
|
||||
struct _spanned_info
|
||||
|
||||
@ -1450,6 +1450,84 @@ void style_font_face::serialize(std::wostream & strm)
|
||||
}
|
||||
}
|
||||
}
|
||||
// style:region-left
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const wchar_t * style_region_left::ns = L"style";
|
||||
const wchar_t * style_region_left::name = L"region-left";
|
||||
|
||||
void style_region_left::add_child_element( const office_element_ptr & child)
|
||||
{
|
||||
content_.push_back(child);
|
||||
}
|
||||
void style_region_left::create_child_element(const std::wstring & Ns, const std::wstring & Name)
|
||||
{
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
void style_region_left::serialize(std::wostream & strm)
|
||||
{
|
||||
CP_XML_WRITER(strm)
|
||||
{
|
||||
CP_XML_NODE_SIMPLE()
|
||||
{
|
||||
for (size_t i = 0; i < content_.size(); i++)
|
||||
{
|
||||
content_[i]->serialize(CP_XML_STREAM());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// style:region-right
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const wchar_t * style_region_right::ns = L"style";
|
||||
const wchar_t * style_region_right::name = L"region-right";
|
||||
|
||||
void style_region_right::add_child_element( const office_element_ptr & child)
|
||||
{
|
||||
content_.push_back(child);
|
||||
}
|
||||
void style_region_right::create_child_element(const std::wstring & Ns, const std::wstring & Name)
|
||||
{
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
void style_region_right::serialize(std::wostream & strm)
|
||||
{
|
||||
CP_XML_WRITER(strm)
|
||||
{
|
||||
CP_XML_NODE_SIMPLE()
|
||||
{
|
||||
for (size_t i = 0; i < content_.size(); i++)
|
||||
{
|
||||
content_[i]->serialize(CP_XML_STREAM());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// style:region-center
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const wchar_t * style_region_center::ns = L"style";
|
||||
const wchar_t * style_region_center::name = L"region-center";
|
||||
|
||||
void style_region_center::add_child_element( const office_element_ptr & child)
|
||||
{
|
||||
content_.push_back(child);
|
||||
}
|
||||
void style_region_center::create_child_element(const std::wstring & Ns, const std::wstring & Name)
|
||||
{
|
||||
CP_CREATE_ELEMENT(content_);
|
||||
}
|
||||
void style_region_center::serialize(std::wostream & strm)
|
||||
{
|
||||
CP_XML_WRITER(strm)
|
||||
{
|
||||
CP_XML_NODE_SIMPLE()
|
||||
{
|
||||
for (size_t i = 0; i < content_.size(); i++)
|
||||
{
|
||||
content_[i]->serialize(CP_XML_STREAM());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -952,5 +952,65 @@ public:
|
||||
|
||||
};
|
||||
CP_REGISTER_OFFICE_ELEMENT2(office_font_face_decls);
|
||||
|
||||
// style:region-left
|
||||
class style_region_left : public office_element_impl<style_region_left>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
static const wchar_t * name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typeStyleRegionLeft;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
virtual void serialize(std::wostream & strm);
|
||||
virtual void create_child_element ( const std::wstring & Ns, const std::wstring & Name);
|
||||
virtual void add_child_element ( const office_element_ptr & child);
|
||||
|
||||
office_element_ptr_array content_;
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(style_region_left);
|
||||
|
||||
// style:region-right
|
||||
class style_region_right : public office_element_impl<style_region_right>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
static const wchar_t * name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typeStyleRegionRight;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
virtual void serialize(std::wostream & strm);
|
||||
virtual void create_child_element ( const std::wstring & Ns, const std::wstring & Name);
|
||||
virtual void add_child_element ( const office_element_ptr & child);
|
||||
|
||||
office_element_ptr_array content_;
|
||||
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(style_region_right);
|
||||
|
||||
|
||||
// style:region-center
|
||||
class style_region_center : public office_element_impl<style_region_center>
|
||||
{
|
||||
public:
|
||||
static const wchar_t * ns;
|
||||
static const wchar_t * name;
|
||||
static const xml::NodeType xml_type = xml::typeElement;
|
||||
static const ElementType type = typeStyleRegionCenter;
|
||||
CPDOCCORE_DEFINE_VISITABLE();
|
||||
|
||||
virtual void serialize(std::wostream & strm);
|
||||
virtual void create_child_element ( const std::wstring & Ns, const std::wstring & Name);
|
||||
virtual void add_child_element ( const office_element_ptr & child);
|
||||
|
||||
office_element_ptr_array content_;
|
||||
|
||||
};
|
||||
|
||||
CP_REGISTER_OFFICE_ELEMENT2(style_region_center);
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,21 +366,236 @@ void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
convert(oox_sheet->m_oSheetViews.GetPointer());
|
||||
convert(oox_sheet->m_oHeaderFooter.GetPointer());
|
||||
convert(oox_sheet->m_oPageSetup.GetPointer());
|
||||
convert(oox_sheet->m_oPageMargins.GetPointer());
|
||||
convert(oox_sheet->m_oPicture.GetPointer());
|
||||
convert(oox_sheet->m_oSheetProtection.GetPointer());
|
||||
|
||||
convert(oox_sheet->m_oLegacyDrawingHF.GetPointer());
|
||||
convert(oox_sheet->m_oHeaderFooter.GetPointer());
|
||||
|
||||
OoxConverter::convert(oox_sheet->m_oExtLst.GetPointer());
|
||||
|
||||
xlsx_current_container = old_container;
|
||||
}
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CHeaderFooter * oox_header_footer)
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CLegacyDrawingHFWorksheet *oox_background)
|
||||
{
|
||||
if (!oox_background) return;
|
||||
if (!oox_background->m_oId.IsInit()) return;
|
||||
|
||||
smart_ptr<OOX::File> file = find_file_by_id(oox_background->m_oId->GetValue());
|
||||
smart_ptr<OOX::CVmlDrawing> vmlDrawing = file.smart_dynamic_cast<OOX::CVmlDrawing>();
|
||||
|
||||
if (false == vmlDrawing.IsInit()) return;
|
||||
|
||||
oox_current_child_document = dynamic_cast<OOX::IFileContainer*>(vmlDrawing.GetPointer());
|
||||
|
||||
for (boost::unordered_map<std::wstring, OOX::CVmlDrawing::_vml_shape>::iterator it = vmlDrawing->m_mapShapes.begin(); it!= vmlDrawing->m_mapShapes.end(); ++it)
|
||||
{
|
||||
OOX::Vml::CShape* pShape = dynamic_cast<OOX::Vml::CShape*>(it->second.pElement);
|
||||
|
||||
if ((pShape) && (pShape->m_sId.IsInit()))
|
||||
{
|
||||
for (size_t i = 0; i < pShape->m_arrItems.size(); ++i)
|
||||
{
|
||||
OOX::Vml::CImageData* pImage = dynamic_cast<OOX::Vml::CImageData*>(pShape->m_arrItems[i]);
|
||||
if (pImage)
|
||||
{
|
||||
odf_writer::office_element_ptr fill_image_element;
|
||||
|
||||
std::wstring pathImage, href, sID = pImage->m_oId.IsInit() ? pImage->m_rId->GetValue() : (pImage->m_oRelId.IsInit() ? pImage->m_oRelId->GetValue() : L"");
|
||||
|
||||
pathImage = find_link_by_id(sID, 1);
|
||||
href = ods_context->add_image(pathImage);
|
||||
|
||||
if (false == href.empty())
|
||||
{
|
||||
odf_writer::create_element(L"style", L"background-image", fill_image_element, ods_context);
|
||||
|
||||
odf_writer::style_background_image * fill_image = dynamic_cast<odf_writer::style_background_image*>(fill_image_element.get());
|
||||
if (!fill_image) return;
|
||||
|
||||
fill_image->xlink_attlist_ = odf_types::common_xlink_attlist();
|
||||
fill_image->xlink_attlist_->type_ = odf_types::xlink_type::Simple;
|
||||
fill_image->xlink_attlist_->actuate_ = odf_types::xlink_actuate::OnLoad;
|
||||
fill_image->xlink_attlist_->href_ = href;
|
||||
|
||||
ods_context->add_header_footer_image(*pShape->m_sId, fill_image_element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
oox_current_child_document = NULL;
|
||||
}
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CHeaderFooter *oox_header_footer)
|
||||
{
|
||||
if (!oox_header_footer) return;
|
||||
|
||||
bool bFirst = oox_header_footer->m_oDifferentFirst.IsInit() ? oox_header_footer->m_oDifferentFirst->ToBool() : false;
|
||||
bool bEven = oox_header_footer->m_oDifferentOddEven.IsInit() ? oox_header_footer->m_oDifferentOddEven->ToBool() : false;
|
||||
|
||||
if (bEven || oox_header_footer->m_oOddHeader.IsInit())
|
||||
{
|
||||
if (true == ods_context->start_header(0))
|
||||
{
|
||||
convert(oox_header_footer->m_oOddHeader.GetPointer());
|
||||
}
|
||||
ods_context->end_header_footer();
|
||||
}
|
||||
if (bEven ||oox_header_footer->m_oOddFooter.IsInit())
|
||||
{
|
||||
if (true == ods_context->start_footer(0))
|
||||
{
|
||||
convert(oox_header_footer->m_oOddFooter.GetPointer());
|
||||
}
|
||||
ods_context->end_header_footer();
|
||||
}
|
||||
if (bEven ||oox_header_footer->m_oEvenHeader.IsInit())
|
||||
{
|
||||
if (true == ods_context->start_header(1))
|
||||
{
|
||||
convert(oox_header_footer->m_oEvenHeader.GetPointer());
|
||||
}
|
||||
ods_context->end_header_footer();
|
||||
}
|
||||
if (bEven ||oox_header_footer->m_oEvenFooter.IsInit())
|
||||
{
|
||||
if (true == ods_context->start_footer(1))
|
||||
{
|
||||
convert(oox_header_footer->m_oEvenFooter.GetPointer());
|
||||
}
|
||||
ods_context->end_header_footer();
|
||||
}
|
||||
if (bFirst || oox_header_footer->m_oFirstHeader.IsInit())
|
||||
{
|
||||
if (true == ods_context->start_header(2))
|
||||
{
|
||||
convert(oox_header_footer->m_oFirstHeader.GetPointer());
|
||||
}
|
||||
ods_context->end_header_footer();
|
||||
}
|
||||
if (bFirst || oox_header_footer->m_oFirstFooter.IsInit())
|
||||
{
|
||||
if (true == ods_context->start_footer(2))
|
||||
{
|
||||
convert(oox_header_footer->m_oFirstFooter.GetPointer());
|
||||
}
|
||||
ods_context->end_header_footer();
|
||||
}
|
||||
}
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CHeaderFooterElement *oox_header_footer)
|
||||
{
|
||||
if (!oox_header_footer) return;
|
||||
|
||||
size_t pos = 0;
|
||||
odf_writer::style_text_properties current_text_props;
|
||||
|
||||
int type_add = 0;
|
||||
while(pos < oox_header_footer->m_sText.size())
|
||||
{
|
||||
if (oox_header_footer->m_sText[pos] == L'&')
|
||||
{
|
||||
pos++;
|
||||
wchar_t comm = oox_header_footer->m_sText[pos];
|
||||
|
||||
switch(comm)
|
||||
{
|
||||
case 'L': ods_context->start_header_footer_region(1); pos++; break;
|
||||
case 'C': ods_context->start_header_footer_region(2); pos++; break;
|
||||
case 'R': ods_context->start_header_footer_region(3); pos++; break;
|
||||
|
||||
case 'A': type_add = 1; pos++; break;
|
||||
case 'P': type_add = 2; pos++; break;
|
||||
case 'N': type_add = 3; pos++; break;
|
||||
case 'D': type_add = 4; pos++; break;
|
||||
case 'T': type_add = 5; pos++; break;
|
||||
case 'F': type_add = 6; pos++; break;
|
||||
case 'Z': type_add = 7; pos++; break;
|
||||
case '&': type_add = 8; pos++; break;
|
||||
case 'G': pos++; break;
|
||||
|
||||
case 'E': current_text_props.content_.style_text_underline_type_ = odf_types::line_type::Double; pos++; break;
|
||||
case 'X': current_text_props.content_.style_text_position_ = odf_types::text_position(+33.); pos++; break;
|
||||
case 'Y': current_text_props.content_.style_text_position_ = odf_types::text_position(-33.); pos++; break;
|
||||
case 'B': current_text_props.content_.fo_font_weight_ = odf_types::font_weight(odf_types::font_weight::WBold); pos++; break;
|
||||
case 'I': current_text_props.content_.fo_font_style_ = odf_types::font_style(odf_types::font_style::Italic); pos++; break;
|
||||
case 'U': current_text_props.content_.style_text_underline_type_= odf_types::line_type(odf_types::line_type::Single); pos++; break;
|
||||
case 'S': current_text_props.content_.style_text_line_through_type_ = odf_types::line_type(odf_types::line_type::Single); pos++; break;
|
||||
case 'K':
|
||||
{
|
||||
pos++;
|
||||
std::wstring color = oox_header_footer->m_sText.substr(pos, 6); pos += 6;
|
||||
|
||||
current_text_props.content_.fo_color_ = odf_types::color(L"#" + color);
|
||||
};break;
|
||||
case '\"':
|
||||
{
|
||||
pos = oox_header_footer->m_sText.find(L'\"', pos + 1); pos++;
|
||||
}break;
|
||||
default:
|
||||
{
|
||||
int font_size = 0;
|
||||
pos++;
|
||||
if (comm >= L'0' && comm <= L'9')
|
||||
{
|
||||
font_size = comm - L'0';
|
||||
wchar_t comm1 = oox_header_footer->m_sText[pos];
|
||||
if (comm1 >= L'0' && comm1 <= L'9')
|
||||
{
|
||||
pos++;
|
||||
font_size = (font_size * 10) + (comm1 - L'0');
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
if (font_size > 0)
|
||||
{
|
||||
current_text_props.content_.fo_font_size_ = odf_types::font_size(odf_types::length(font_size, odf_types::length::pt));
|
||||
}
|
||||
}break;
|
||||
|
||||
//&nn Prints the characters that follow in the specified font size. Use a two-digit number to specify a size in points.
|
||||
}
|
||||
size_t next = oox_header_footer->m_sText.find(L'&', pos);
|
||||
if (next == std::wstring::npos) next = oox_header_footer->m_sText.length();
|
||||
|
||||
if (type_add > 0 || next - pos > 0)
|
||||
{
|
||||
ods_context->text_context()->get_styles_context()->create_style(L"", odf_types::style_family::Text, true, false, -1);
|
||||
odf_writer::style_text_properties *text_properties = ods_context->text_context()->get_styles_context()->last_state()->get_text_properties();
|
||||
text_properties->content_.apply_from(current_text_props.content_);
|
||||
|
||||
ods_context->text_context()->start_span(true);
|
||||
|
||||
switch(type_add)
|
||||
{
|
||||
case 1: ods_context->text_context()->add_text_sheet_name(L"???"); break;
|
||||
case 2: ods_context->text_context()->add_text_page_number(L"1"); break;
|
||||
case 3: ods_context->text_context()->add_text_page_count(L"99"); break;
|
||||
case 4: ods_context->text_context()->add_text_date(L"00.00.0000"); break;
|
||||
case 5: ods_context->text_context()->add_text_time(L"00:00"); break;
|
||||
case 6: ods_context->text_context()->add_text_file_name(L"???"); break;
|
||||
case 7: ods_context->text_context()->add_text_file_name(L"???"); break;
|
||||
case 8: ods_context->text_context()->add_text_content(L"&"); break;
|
||||
}
|
||||
type_add = 0;
|
||||
std::wstring text;
|
||||
if (next - pos > 0)
|
||||
{
|
||||
text = oox_header_footer->m_sText.substr(pos, next - pos);
|
||||
if (false == text.empty())
|
||||
ods_context->text_context()->add_text_content(text);
|
||||
}
|
||||
ods_context->text_context()->end_span();
|
||||
}
|
||||
pos = next;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CSheetProtection *oox_prot)
|
||||
{
|
||||
if (!oox_prot) return;
|
||||
@ -923,9 +1138,9 @@ void XlsxConverter::convert(OOX::Spreadsheet::CRPr *oox_run_pr)
|
||||
bool automatic = true;
|
||||
bool root = false;
|
||||
|
||||
ods_context->styles_context()->create_style(L"",odf_types::style_family::Text, automatic, root, -1);
|
||||
ods_context->styles_context()->create_style(L"", odf_types::style_family::Text, automatic, root, -1);
|
||||
|
||||
odf_writer::style_text_properties * text_properties = ods_context->styles_context()->last_state()->get_text_properties();
|
||||
odf_writer::style_text_properties *text_properties = ods_context->styles_context()->last_state()->get_text_properties();
|
||||
if (text_properties == NULL)return;
|
||||
|
||||
if (oox_run_pr->m_oBold.IsInit())
|
||||
@ -1398,9 +1613,26 @@ void XlsxConverter::convert(OOX::Spreadsheet::CPageSetup *oox_page)
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CPageMargins *oox_page)
|
||||
{
|
||||
if (!oox_page) return;
|
||||
_CP_OPT(double) top, left,right,header,footer,bottom;
|
||||
_CP_OPT(odf_types::length) top, left, right, bottom, other;
|
||||
|
||||
ods_context->page_layout_context()->set_page_margin(top, left, bottom, right, header, footer);
|
||||
if (oox_page->m_oTop.IsInit()) top = odf_types::length(oox_page->m_oTop->GetValue(), odf_types::length::pt);
|
||||
if (oox_page->m_oLeft.IsInit()) left = odf_types::length(oox_page->m_oLeft->GetValue(), odf_types::length::pt);
|
||||
if (oox_page->m_oRight.IsInit()) right = odf_types::length(oox_page->m_oRight->GetValue(), odf_types::length::pt);
|
||||
if (oox_page->m_oBottom.IsInit()) bottom = odf_types::length(oox_page->m_oBottom->GetValue(), odf_types::length::pt);
|
||||
|
||||
ods_context->page_layout_context()->set_page_margin(top, left, bottom, right);
|
||||
|
||||
if (oox_page->m_oFooter.IsInit())
|
||||
{
|
||||
other = odf_types::length(oox_page->m_oFooter->GetValue(), odf_types::length::pt);
|
||||
ods_context->page_layout_context()->set_footer_size(other);
|
||||
}
|
||||
|
||||
if (oox_page->m_oHeader.IsInit())
|
||||
{
|
||||
other = odf_types::length(oox_page->m_oHeader->GetValue(), odf_types::length::pt);
|
||||
ods_context->page_layout_context()->set_header_size(other);
|
||||
}
|
||||
|
||||
}
|
||||
void XlsxConverter::convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format_pr)
|
||||
|
||||
@ -98,6 +98,8 @@ namespace OOX
|
||||
class CDataValidations;
|
||||
class CSheetProtection;
|
||||
class CDataValidation;
|
||||
class CHeaderFooterElement;
|
||||
class CLegacyDrawingHFWorksheet;
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,6 +165,9 @@ namespace Oox2Odf
|
||||
void convert(OOX::Spreadsheet::CTableColumns *oox_table_part_columns);
|
||||
void convert(OOX::Spreadsheet::CPictureWorksheet *oox_background);
|
||||
void convert(OOX::Spreadsheet::CHeaderFooter *oox_header_footer);
|
||||
void convert(OOX::Spreadsheet::CLegacyDrawingHFWorksheet *oox_background);
|
||||
void convert(OOX::Spreadsheet::CHeaderFooterElement *oox_header_footer);
|
||||
void convert();
|
||||
|
||||
void convert(OOX::Spreadsheet::CCol *oox_column);
|
||||
void convert(OOX::Spreadsheet::CRow *oox_row, OOX::Spreadsheet::CRow *oox_row_prev);
|
||||
|
||||
@ -1028,7 +1028,7 @@ void CFontList::ToBuffer(BYTE** pDstData, LONG* pLen, std::wstring strDirectory,
|
||||
}
|
||||
|
||||
*pDstData = pData;
|
||||
*pLen = lDataSize;
|
||||
*pLen = (LONG)(pDataMem - pData);
|
||||
}
|
||||
|
||||
NSFonts::CFontInfo* CFontList::GetByParams(NSFonts::CFontSelectFormat& oSelect, bool bIsDictionaryUse)
|
||||
|
||||
@ -1,756 +1,220 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
//#include "ApplicationFonts.h"
|
||||
#include "ApplicationFontsWorker.h"
|
||||
#include "../common/File.h"
|
||||
#include "../common/Array.h"
|
||||
#include "../common/Directory.h"
|
||||
#include "./MemoryStream.h"
|
||||
#include "./../graphics/pro/Fonts.h"
|
||||
|
||||
using namespace NSFonts;
|
||||
|
||||
namespace NSFontsApplication
|
||||
{
|
||||
void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
|
||||
{
|
||||
size_t posn = 0;
|
||||
while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
|
||||
{
|
||||
text.replace(posn, replaceFrom.length(), replaceTo);
|
||||
posn += replaceTo.length();
|
||||
}
|
||||
}
|
||||
|
||||
class CTextItem
|
||||
{
|
||||
protected:
|
||||
wchar_t* m_pData;
|
||||
size_t m_lSize;
|
||||
|
||||
wchar_t* m_pDataCur;
|
||||
size_t m_lSizeCur;
|
||||
|
||||
public:
|
||||
CTextItem()
|
||||
{
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = m_lSize;
|
||||
}
|
||||
CTextItem(const CTextItem& oSrc)
|
||||
{
|
||||
m_pData = NULL;
|
||||
*this = oSrc;
|
||||
}
|
||||
CTextItem& operator=(const CTextItem& oSrc)
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_lSize = oSrc.m_lSize;
|
||||
m_lSizeCur = oSrc.m_lSizeCur;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, oSrc.m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CTextItem(const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
}
|
||||
CTextItem(wchar_t* pData, const size_t& nLen)
|
||||
{
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = m_lSize;
|
||||
m_pDataCur = m_pData + m_lSize;
|
||||
}
|
||||
CTextItem(wchar_t* pData, BYTE* pUnicodeChecker = NULL)
|
||||
{
|
||||
size_t nLen = GetStringLen(pData);
|
||||
|
||||
m_lSize = nLen;
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
memcpy(m_pData, pData, m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = m_lSize;
|
||||
m_pDataCur = m_pData + m_lSize;
|
||||
|
||||
if (NULL != pUnicodeChecker)
|
||||
{
|
||||
wchar_t* pMemory = m_pData;
|
||||
while (pMemory < m_pDataCur)
|
||||
{
|
||||
if (!pUnicodeChecker[*pMemory])
|
||||
*pMemory = wchar_t(' ');
|
||||
++pMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual ~CTextItem()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
}
|
||||
|
||||
inline void AddSize(const size_t& nSize)
|
||||
{
|
||||
if (NULL == m_pData)
|
||||
{
|
||||
m_lSize = 1000;
|
||||
if (nSize > m_lSize)
|
||||
m_lSize = nSize;
|
||||
|
||||
m_pData = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
|
||||
m_lSizeCur = 0;
|
||||
m_pDataCur = m_pData;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
while ((m_lSizeCur + nSize) > m_lSize)
|
||||
{
|
||||
m_lSize *= 2;
|
||||
}
|
||||
|
||||
wchar_t* pRealloc = (wchar_t*)realloc(m_pData, m_lSize * sizeof(wchar_t));
|
||||
if (NULL != pRealloc)
|
||||
{
|
||||
// реаллок сработал
|
||||
m_pData = pRealloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t* pMalloc = (wchar_t*)malloc(m_lSize * sizeof(wchar_t));
|
||||
memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(wchar_t));
|
||||
|
||||
free(m_pData);
|
||||
m_pData = pMalloc;
|
||||
m_pDataCur = m_pData + m_lSizeCur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
inline void operator+=(const std::wstring& oTemp)
|
||||
{
|
||||
WriteString(oTemp.c_str(), oTemp.length());
|
||||
}
|
||||
inline wchar_t operator[](const size_t& nIndex)
|
||||
{
|
||||
if (nIndex < m_lSizeCur)
|
||||
return m_pData[nIndex];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void AddSpace()
|
||||
{
|
||||
AddSize(1);
|
||||
*m_pDataCur = wchar_t(' ');
|
||||
|
||||
++m_lSizeCur;
|
||||
++m_pDataCur;
|
||||
}
|
||||
inline void CorrectUnicode(const BYTE* pUnicodeChecker)
|
||||
{
|
||||
if (NULL != pUnicodeChecker)
|
||||
{
|
||||
wchar_t* pMemory = m_pData;
|
||||
while (pMemory < m_pDataCur)
|
||||
{
|
||||
if (!pUnicodeChecker[*pMemory])
|
||||
*pMemory = wchar_t(' ');
|
||||
++pMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void RemoveLastSpaces()
|
||||
{
|
||||
wchar_t* pMemory = m_pDataCur - 1;
|
||||
while ((pMemory > m_pData) && (wchar_t(' ') == *pMemory))
|
||||
{
|
||||
--pMemory;
|
||||
--m_lSizeCur;
|
||||
--m_pDataCur;
|
||||
}
|
||||
|
||||
}
|
||||
inline bool IsSpace()
|
||||
{
|
||||
if (1 != m_lSizeCur)
|
||||
return false;
|
||||
return (wchar_t(' ') == *m_pData);
|
||||
}
|
||||
|
||||
public:
|
||||
inline void WriteString(const wchar_t* pString, const size_t& nLen)
|
||||
{
|
||||
AddSize(nLen);
|
||||
memcpy(m_pDataCur, pString, nLen * sizeof(wchar_t));
|
||||
m_pDataCur += nLen;
|
||||
m_lSizeCur += nLen;
|
||||
}
|
||||
inline size_t GetCurSize()
|
||||
{
|
||||
return m_lSizeCur;
|
||||
}
|
||||
inline size_t GetSize()
|
||||
{
|
||||
return m_lSize;
|
||||
}
|
||||
inline void Clear()
|
||||
{
|
||||
RELEASEMEM(m_pData);
|
||||
|
||||
m_pData = NULL;
|
||||
m_lSize = 0;
|
||||
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
inline void ClearNoAttack()
|
||||
{
|
||||
m_pDataCur = m_pData;
|
||||
m_lSizeCur = 0;
|
||||
}
|
||||
|
||||
inline size_t GetStringLen(wchar_t* pData)
|
||||
{
|
||||
wchar_t* s = pData;
|
||||
for (; *s != 0; ++s);
|
||||
return (size_t)(s - pData);
|
||||
}
|
||||
|
||||
inline std::wstring GetCString()
|
||||
{
|
||||
std::wstring str(m_pData, (int)m_lSizeCur);
|
||||
return str;
|
||||
}
|
||||
inline wchar_t* GetBuffer()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
};
|
||||
|
||||
class CStringWriter : public CTextItem
|
||||
{
|
||||
public:
|
||||
CStringWriter() : CTextItem()
|
||||
{
|
||||
}
|
||||
virtual ~CStringWriter()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
inline void Write(CStringWriter& oWriter)
|
||||
{
|
||||
CTextItem::WriteString(oWriter.m_pData, oWriter.m_lSizeCur);
|
||||
}
|
||||
};
|
||||
|
||||
class CFontInfoJS
|
||||
{
|
||||
public:
|
||||
std::wstring m_sName;
|
||||
|
||||
int m_lIndexR;
|
||||
int m_lFaceIndexR;
|
||||
int m_lIndexI;
|
||||
int m_lFaceIndexI;
|
||||
int m_lIndexB;
|
||||
int m_lFaceIndexB;
|
||||
int m_lIndexBI;
|
||||
int m_lFaceIndexBI;
|
||||
|
||||
CFontInfoJS()
|
||||
{
|
||||
m_sName = L"";
|
||||
|
||||
m_lIndexR = -1;
|
||||
m_lFaceIndexR = -1;
|
||||
m_lIndexI = -1;
|
||||
m_lFaceIndexI = -1;
|
||||
m_lIndexB = -1;
|
||||
m_lFaceIndexB = -1;
|
||||
m_lIndexBI = -1;
|
||||
m_lFaceIndexBI = -1;
|
||||
}
|
||||
|
||||
CFontInfoJS(const CFontInfoJS& oSrc)
|
||||
{
|
||||
*this = oSrc;
|
||||
}
|
||||
|
||||
CFontInfoJS& operator=(const CFontInfoJS& oSrc)
|
||||
{
|
||||
m_sName = oSrc.m_sName;
|
||||
|
||||
m_lIndexR = oSrc.m_lIndexR;
|
||||
m_lIndexI = oSrc.m_lIndexI;
|
||||
m_lIndexB = oSrc.m_lIndexB;
|
||||
m_lIndexBI = oSrc.m_lIndexBI;
|
||||
|
||||
m_lFaceIndexR = oSrc.m_lFaceIndexR;
|
||||
m_lFaceIndexI = oSrc.m_lFaceIndexI;
|
||||
m_lFaceIndexB = oSrc.m_lFaceIndexB;
|
||||
m_lFaceIndexBI = oSrc.m_lFaceIndexBI;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
static std::vector<std::wstring> SaveAllFontsJS(NSFonts::IApplicationFonts* applicationFonts, CStringWriter& oWriterJS)
|
||||
{
|
||||
std::vector<std::wstring> arrNames;
|
||||
|
||||
std::vector<NSFonts::CFontInfo*>* pList = applicationFonts->GetList()->GetFonts();
|
||||
|
||||
#ifdef _IOS
|
||||
|
||||
size_t nOldCount = pList->size();
|
||||
for (size_t i = 0; i < nOldCount; i++)
|
||||
{
|
||||
CFontInfo* pInfo = pList->operator [](i);
|
||||
|
||||
if (pInfo->m_wsFontName.find(L".") == 0)
|
||||
{
|
||||
pList->erase(pList->begin() + i);
|
||||
// странные шрифты какие-то есть в ios
|
||||
//pList->RemoveAt(i);
|
||||
i--;
|
||||
nOldCount--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
size_t nCount = pList->size();
|
||||
|
||||
// сначала строим массив всех файлов шрифтов
|
||||
std::map<std::wstring, LONG> mapFontFiles;
|
||||
std::map<LONG, std::wstring> mapFontFiles2;
|
||||
LONG lFontFiles = 0;
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
CFontInfo* pInfo = pList->operator [](i);
|
||||
|
||||
if (mapFontFiles.find(pInfo->m_wsFontPath) == mapFontFiles.end())
|
||||
{
|
||||
mapFontFiles.insert(std::pair<std::wstring, LONG>(pInfo->m_wsFontPath, lFontFiles));
|
||||
mapFontFiles2.insert(std::pair<LONG, std::wstring>(lFontFiles, pInfo->m_wsFontPath));
|
||||
++lFontFiles;
|
||||
}
|
||||
}
|
||||
// -----------------------------------------
|
||||
|
||||
// теперь строим массив всех шрифтов по имени
|
||||
std::map<std::wstring, CFontInfoJS> mapFonts;
|
||||
CArray<std::wstring> arrFonts;
|
||||
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
CFontInfo* pInfo = (CFontInfo*)pList->operator [](i);
|
||||
std::wstring strPath = pInfo->m_wsFontPath;
|
||||
std::wstring strName = pInfo->m_wsFontName;
|
||||
|
||||
int lFontIndex = 0;
|
||||
int lFaceIndex = 0;
|
||||
|
||||
std::map<std::wstring, LONG>::iterator it = mapFontFiles.find(strPath);
|
||||
lFontIndex = (int)it->second;
|
||||
|
||||
if (pInfo->m_lIndex >= 0)
|
||||
lFaceIndex = (int)pInfo->m_lIndex;
|
||||
|
||||
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(pInfo->m_wsFontName);
|
||||
if (mapFonts.end() != pPair)
|
||||
{
|
||||
pPair->second.m_sName = pInfo->m_wsFontName;
|
||||
|
||||
if (pInfo->m_bBold && pInfo->m_bItalic)
|
||||
{
|
||||
pPair->second.m_lIndexBI = lFontIndex;
|
||||
pPair->second.m_lFaceIndexBI = lFaceIndex;
|
||||
}
|
||||
else if (pInfo->m_bBold)
|
||||
{
|
||||
pPair->second.m_lIndexB = lFontIndex;
|
||||
pPair->second.m_lFaceIndexB = lFaceIndex;
|
||||
}
|
||||
else if (pInfo->m_bItalic)
|
||||
{
|
||||
pPair->second.m_lIndexI = lFontIndex;
|
||||
pPair->second.m_lFaceIndexI = lFaceIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPair->second.m_lIndexR = lFontIndex;
|
||||
pPair->second.m_lFaceIndexR = lFaceIndex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CFontInfoJS fontInfo;
|
||||
|
||||
fontInfo.m_sName = pInfo->m_wsFontName;
|
||||
|
||||
if (pInfo->m_bBold && pInfo->m_bItalic)
|
||||
{
|
||||
fontInfo.m_lIndexBI = lFontIndex;
|
||||
fontInfo.m_lFaceIndexBI = lFaceIndex;
|
||||
}
|
||||
else if (pInfo->m_bBold)
|
||||
{
|
||||
fontInfo.m_lIndexB = lFontIndex;
|
||||
fontInfo.m_lFaceIndexB = lFaceIndex;
|
||||
}
|
||||
else if (pInfo->m_bItalic)
|
||||
{
|
||||
fontInfo.m_lIndexI = lFontIndex;
|
||||
fontInfo.m_lFaceIndexI = lFaceIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
fontInfo.m_lIndexR = lFontIndex;
|
||||
fontInfo.m_lFaceIndexR = lFaceIndex;
|
||||
}
|
||||
|
||||
mapFonts.insert(std::pair<std::wstring, CFontInfoJS>(fontInfo.m_sName, fontInfo));
|
||||
arrFonts.Add(fontInfo.m_sName);
|
||||
}
|
||||
}
|
||||
// -------------------------------------------
|
||||
|
||||
// теперь сортируем шрифты по имени ----------
|
||||
int nCountFonts = arrFonts.GetCount();
|
||||
for (int i = 0; i < nCountFonts; ++i)
|
||||
{
|
||||
for (int j = i + 1; j < nCountFonts; ++j)
|
||||
{
|
||||
if (arrFonts[i] > arrFonts[j])
|
||||
{
|
||||
std::wstring temp = arrFonts[i];
|
||||
arrFonts[i] = arrFonts[j];
|
||||
arrFonts[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
// -------------------------------------------
|
||||
|
||||
// и самое главное. Здесь должен скидываться скрипт для работы со всеми шрифтами.
|
||||
// все объекты, которые позволят не знать о существующих фонтах
|
||||
if (true)
|
||||
{
|
||||
// сначала все файлы
|
||||
size_t nCountFiles = mapFontFiles.size();
|
||||
if (nCountFiles == 0)
|
||||
oWriterJS += (L"window[\"__fonts_files\"] = []; \n\n");
|
||||
else
|
||||
{
|
||||
std::wstring* pMassFiles = new std::wstring[nCountFiles];
|
||||
for ( std::map<std::wstring, LONG>::iterator pos = mapFontFiles.begin(); pos != mapFontFiles.end(); ++pos)
|
||||
{
|
||||
std::wstring strFontId = pos->first;
|
||||
|
||||
string_replace(strFontId, L"\\\\", L"\\");
|
||||
string_replace(strFontId, L"\\", L"/");
|
||||
|
||||
//int nStart = strFontId.find_last_of(wchar_t('\\'));
|
||||
//strFontId = strFontId.substr(nStart + 1);
|
||||
|
||||
pMassFiles[pos->second] = strFontId;
|
||||
}
|
||||
|
||||
oWriterJS += (L"window[\"__fonts_files\"] = [\n");
|
||||
for (size_t nIndex = 0; nIndex < nCountFiles; ++nIndex)
|
||||
{
|
||||
oWriterJS += (L"\"");
|
||||
oWriterJS += (pMassFiles[nIndex]);
|
||||
if (nIndex != (nCountFiles - 1))
|
||||
oWriterJS += (L"\",\n");
|
||||
else
|
||||
oWriterJS += (L"\"");
|
||||
}
|
||||
oWriterJS += (L"\n];\n\n");
|
||||
|
||||
delete [] pMassFiles;
|
||||
}
|
||||
|
||||
oWriterJS += L"window[\"__fonts_infos\"] = [\n";
|
||||
|
||||
for (int index = 0; index < nCountFonts; ++index)
|
||||
{
|
||||
std::map<std::wstring, CFontInfoJS>::iterator pPair = mapFonts.find(arrFonts[index]);
|
||||
|
||||
char buffer[1000];
|
||||
sprintf(buffer, "\",%d,%d,%d,%d,%d,%d,%d,%d]", pPair->second.m_lIndexR, pPair->second.m_lFaceIndexR,
|
||||
pPair->second.m_lIndexI, pPair->second.m_lFaceIndexI,
|
||||
pPair->second.m_lIndexB, pPair->second.m_lFaceIndexB,
|
||||
pPair->second.m_lIndexBI, pPair->second.m_lFaceIndexBI);
|
||||
|
||||
std::string sBuffer(buffer);
|
||||
|
||||
oWriterJS += L"[\"";
|
||||
oWriterJS += pPair->second.m_sName;
|
||||
oWriterJS += NSFile::CUtf8Converter::GetUnicodeFromCharPtr(sBuffer);
|
||||
|
||||
if (index != (nCountFonts - 1))
|
||||
oWriterJS += (L",\n");
|
||||
else
|
||||
oWriterJS += (L"\n");
|
||||
|
||||
arrNames.push_back(pPair->second.m_sName);
|
||||
}
|
||||
oWriterJS += (L"];\n\n");
|
||||
|
||||
if (true)
|
||||
{
|
||||
BYTE* pData = NULL;
|
||||
LONG lLen = 0;
|
||||
applicationFonts->GetList()->ToBuffer(&pData, &lLen, L"", true);
|
||||
|
||||
char* cData64 = NULL;
|
||||
int nData64Dst = 0;
|
||||
NSFile::CBase64Converter::Encode(pData, (int)lLen, cData64, nData64Dst, NSBase64::B64_BASE64_FLAG_NOCRLF);
|
||||
|
||||
std::wstring sData64 = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(cData64, (LONG)nData64Dst, FALSE);
|
||||
|
||||
oWriterJS += (L"window[\"g_fonts_selection_bin\"] = \"");
|
||||
oWriterJS += sData64;
|
||||
oWriterJS += L"\";\n";
|
||||
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
RELEASEARRAYOBJECTS(cData64);
|
||||
}
|
||||
}
|
||||
|
||||
return arrNames;
|
||||
}
|
||||
|
||||
class CStreamReader
|
||||
{
|
||||
private:
|
||||
BYTE* Data;
|
||||
BYTE* DataEnd;
|
||||
BYTE* DataCur;
|
||||
|
||||
public:
|
||||
CStreamReader()
|
||||
{
|
||||
Data = NULL;
|
||||
DataEnd = NULL;
|
||||
DataCur = NULL;
|
||||
}
|
||||
CStreamReader(BYTE* pData, unsigned int nSize)
|
||||
{
|
||||
Data = pData;
|
||||
DataEnd = Data + nSize;
|
||||
DataCur = Data;
|
||||
}
|
||||
|
||||
inline bool IsNoEnd()
|
||||
{
|
||||
return (DataCur < DataEnd);
|
||||
}
|
||||
inline void Skip(int count)
|
||||
{
|
||||
DataCur += count;
|
||||
}
|
||||
inline BYTE* GetCur()
|
||||
{
|
||||
return DataCur;
|
||||
}
|
||||
|
||||
inline int GetInt32()
|
||||
{
|
||||
#ifdef _ARM_ALIGN_
|
||||
int ret = 0;
|
||||
memcpy(&ret, DataCur, sizeof(int));
|
||||
DataCur += 4;
|
||||
return ret;
|
||||
#else
|
||||
int ret = *((int*)DataCur);
|
||||
DataCur += 4;
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
inline BYTE GetUChar()
|
||||
{
|
||||
BYTE ret = *DataCur;
|
||||
++DataCur;
|
||||
return ret;
|
||||
}
|
||||
inline std::string GetString1()
|
||||
{
|
||||
int nLen = GetInt32();
|
||||
if (0 == nLen)
|
||||
return "";
|
||||
|
||||
std::string s((char*)DataCur, nLen);
|
||||
DataCur += nLen;
|
||||
return s;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CApplicationFontsWorker::CApplicationFontsWorker()
|
||||
{
|
||||
|
||||
}
|
||||
CApplicationFontsWorker::~CApplicationFontsWorker()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CApplicationFontsWorker::CheckApplication(bool bIsNeedSystemFonts,
|
||||
unsigned char* pDataSrc, unsigned int nLenSrc,
|
||||
unsigned char*& pDataDst, unsigned int& nLenDst)
|
||||
{
|
||||
std::vector<std::wstring> arrNames;
|
||||
|
||||
std::vector<std::wstring> fonts;
|
||||
NSFonts::IApplicationFonts* pFonts = NSFonts::NSApplication::Create();
|
||||
|
||||
pDataDst = NULL;
|
||||
nLenDst = 0;
|
||||
|
||||
if (bIsNeedSystemFonts)
|
||||
{
|
||||
fonts = pFonts->GetSetupFontFiles();
|
||||
}
|
||||
|
||||
for (std::vector<std::wstring>::iterator iter = m_arAdditionalFolders.begin(); iter != m_arAdditionalFolders.end(); ++iter)
|
||||
{
|
||||
NSDirectory::GetFiles2(*iter, fonts);
|
||||
}
|
||||
|
||||
if (NULL != pDataSrc)
|
||||
{
|
||||
// проверяем, поменялось ли чего
|
||||
NSFontsApplication::CStreamReader oReader(pDataSrc, nLenSrc);
|
||||
int nLenAllFonts = oReader.GetInt32();
|
||||
oReader.Skip(nLenAllFonts);
|
||||
|
||||
std::vector<std::wstring> arrOld;
|
||||
|
||||
int nCountCache = oReader.GetInt32();
|
||||
for (int i = 0; i < nCountCache; ++i)
|
||||
{
|
||||
int nLen = oReader.GetInt32();
|
||||
arrOld.push_back(NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(oReader.GetCur(), (LONG)nLen));
|
||||
oReader.Skip(nLen);
|
||||
}
|
||||
|
||||
if (fonts.size() == arrOld.size())
|
||||
{
|
||||
int nCountFonts = (int)fonts.size();
|
||||
bool bIsBreak = false;
|
||||
for (int i = 0 ; i < nCountFonts; ++i)
|
||||
{
|
||||
if (fonts[i] != arrOld[i])
|
||||
{
|
||||
bIsBreak = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bIsBreak)
|
||||
{
|
||||
// ничего не поменялось
|
||||
int nCountNames = oReader.GetInt32();
|
||||
for (int i = 0; i < nCountNames; ++i)
|
||||
{
|
||||
int nLen = oReader.GetInt32();
|
||||
arrNames.push_back(NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(oReader.GetCur(), (LONG)nLen));
|
||||
oReader.Skip(nLen);
|
||||
}
|
||||
|
||||
return arrNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// произошли изменения
|
||||
pFonts->InitializeFromArrayFiles(fonts);
|
||||
|
||||
NSFontsApplication::CStringWriter oWriterJS;
|
||||
arrNames = NSFontsApplication::SaveAllFontsJS(pFonts, oWriterJS);
|
||||
|
||||
// теперь нужно записать новую дату
|
||||
NSMemoryStream::CMemoryStream oStream;
|
||||
std::string sAllFontsJS = NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(oWriterJS.GetBuffer(), (LONG)oWriterJS.GetCurSize());
|
||||
oStream.WriteStringA2(sAllFontsJS.c_str(), (int)sAllFontsJS.length());
|
||||
|
||||
int nCountF = (int)fonts.size();
|
||||
oStream.WriteLONG((LONG)nCountF);
|
||||
|
||||
for (int i = 0; i < nCountF; ++i)
|
||||
{
|
||||
std::string sTmp = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(fonts[i]);
|
||||
oStream.WriteStringA2(sTmp.c_str(), (int)sTmp.length());
|
||||
}
|
||||
|
||||
nCountF = (int)arrNames.size();
|
||||
oStream.WriteLONG((LONG)nCountF);
|
||||
for (std::vector<std::wstring>::iterator iter = arrNames.begin(); iter != arrNames.end(); ++iter)
|
||||
{
|
||||
std::string sTmp = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(*iter);
|
||||
oStream.WriteStringA2(sTmp.c_str(), (int)sTmp.length());
|
||||
}
|
||||
|
||||
nLenDst = (unsigned int)oStream.GetSize();
|
||||
pDataDst = new unsigned char[nLenDst];
|
||||
memcpy(pDataDst, oStream.GetData(), (size_t)nLenDst);
|
||||
|
||||
return arrNames;
|
||||
}
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2019
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "ApplicationFontsWorker.h"
|
||||
#include "application_generate_fonts.h"
|
||||
|
||||
CApplicationFontsWorker::CApplicationFontsWorker()
|
||||
{
|
||||
m_bIsUseSystemFonts = true;
|
||||
m_bIsNeedThumbnails = true;
|
||||
m_bIsUseOpenType = true;
|
||||
}
|
||||
CApplicationFontsWorker::~CApplicationFontsWorker()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NSFonts::IApplicationFonts* CApplicationFontsWorker::Check()
|
||||
{
|
||||
if (m_sDirectory.empty())
|
||||
return NULL;
|
||||
|
||||
std::wstring strAllFontsJSPath = m_sDirectory + L"/AllFonts.js";
|
||||
std::wstring strFontsSelectionBin = m_sDirectory + L"/font_selection.bin";
|
||||
|
||||
std::vector<std::string> strFonts;
|
||||
|
||||
if (true)
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
if (oFile.OpenFile(m_sDirectory + L"/fonts.log"))
|
||||
{
|
||||
int nSize = oFile.GetFileSize();
|
||||
char* pBuffer = new char[nSize];
|
||||
DWORD dwReaden = 0;
|
||||
oFile.ReadFile((BYTE*)pBuffer, nSize, dwReaden);
|
||||
oFile.CloseFile();
|
||||
|
||||
int nStart = 0;
|
||||
int nCur = nStart;
|
||||
for (; nCur < nSize; ++nCur)
|
||||
{
|
||||
if (pBuffer[nCur] == '\n')
|
||||
{
|
||||
int nEnd = nCur - 1;
|
||||
if (nEnd > nStart)
|
||||
{
|
||||
std::string s(pBuffer + nStart, nEnd - nStart + 1);
|
||||
strFonts.push_back(s);
|
||||
}
|
||||
nStart = nCur + 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] pBuffer;
|
||||
}
|
||||
|
||||
#ifdef ONLYOFFICE_FONTS_VERSION_
|
||||
if (0 != strFonts.size())
|
||||
{
|
||||
// check version!!!
|
||||
std::string sOO_Version = strFonts[0];
|
||||
if (0 != sOO_Version.find("ONLYOFFICE_FONTS_VERSION_"))
|
||||
{
|
||||
strFonts.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string sVersion = sOO_Version.substr(25);
|
||||
int nVersion = std::stoi(sVersion);
|
||||
if (nVersion != ONLYOFFICE_FONTS_VERSION_)
|
||||
strFonts.clear();
|
||||
else
|
||||
strFonts.erase(strFonts.begin());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
NSFonts::IApplicationFonts* pApplicationF = NSFonts::NSApplication::Create();
|
||||
std::vector<std::wstring> strFontsW_Cur;
|
||||
|
||||
if (m_bIsUseSystemFonts)
|
||||
strFontsW_Cur = pApplicationF->GetSetupFontFiles();
|
||||
|
||||
#if defined(_LINUX) && !defined(__ANDROID__)
|
||||
std::wstring sHome = GetHomeDirectory();
|
||||
if (!sHome.empty())
|
||||
{
|
||||
#ifdef _MAC
|
||||
NSDirectory::GetFiles2(sHome + L"/Library/Fonts", strFontsW_Cur, true);
|
||||
#else
|
||||
NSDirectory::GetFiles2(sHome + L"/.fonts", strFontsW_Cur, true);
|
||||
NSDirectory::GetFiles2(sHome + L"/.local/share/fonts", strFontsW_Cur, true);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
for (std::vector<std::wstring>::iterator i = m_arAdditionalFolders.begin(); i != m_arAdditionalFolders.end(); i++)
|
||||
{
|
||||
NSDirectory::GetFiles2(*i, strFontsW_Cur, true);
|
||||
}
|
||||
|
||||
bool bIsEqual = true;
|
||||
if (strFonts.size() != strFontsW_Cur.size())
|
||||
bIsEqual = false;
|
||||
|
||||
if (bIsEqual)
|
||||
{
|
||||
int nCount = (int)strFonts.size();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
if (strFonts[i] != NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(strFontsW_Cur[i].c_str(), strFontsW_Cur[i].length()))
|
||||
{
|
||||
bIsEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bIsEqual)
|
||||
{
|
||||
if (!NSFile::CFileBinary::Exists(strFontsSelectionBin))
|
||||
bIsEqual = false;
|
||||
}
|
||||
|
||||
if (!bIsEqual)
|
||||
{
|
||||
if (NSFile::CFileBinary::Exists(strAllFontsJSPath))
|
||||
NSFile::CFileBinary::Remove(strAllFontsJSPath);
|
||||
if (NSFile::CFileBinary::Exists(strFontsSelectionBin))
|
||||
NSFile::CFileBinary::Remove(strFontsSelectionBin);
|
||||
|
||||
if (strFonts.size() != 0)
|
||||
NSFile::CFileBinary::Remove(m_sDirectory + L"/fonts.log");
|
||||
|
||||
NSFile::CFileBinary oFile;
|
||||
oFile.CreateFileW(m_sDirectory + L"/fonts.log");
|
||||
#ifdef ONLYOFFICE_FONTS_VERSION_
|
||||
oFile.WriteStringUTF8(L"ONLYOFFICE_FONTS_VERSION_");
|
||||
oFile.WriteStringUTF8(std::to_wstring(ONLYOFFICE_FONTS_VERSION_));
|
||||
oFile.WriteFile((BYTE*)"\n", 1);
|
||||
#endif
|
||||
int nCount = (int)strFontsW_Cur.size();
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
{
|
||||
oFile.WriteStringUTF8(strFontsW_Cur[i]);
|
||||
oFile.WriteFile((BYTE*)"\n", 1);
|
||||
}
|
||||
oFile.CloseFile();
|
||||
|
||||
int nFlag = 3;
|
||||
if (!m_bIsUseOpenType)
|
||||
nFlag = 2;
|
||||
|
||||
pApplicationF->InitializeFromArrayFiles(strFontsW_Cur, nFlag);
|
||||
|
||||
NSCommon::SaveAllFontsJS(pApplicationF, strAllFontsJSPath, m_bIsNeedThumbnails ? m_sDirectory : L"", strFontsSelectionBin);
|
||||
}
|
||||
|
||||
pApplicationF->Release();
|
||||
pApplicationF = NSFonts::NSApplication::Create();
|
||||
pApplicationF->InitializeFromFolder(m_sDirectory);
|
||||
|
||||
return pApplicationF;
|
||||
}
|
||||
|
||||
std::string CApplicationFontsWorker::GetAllFonts()
|
||||
{
|
||||
std::string sAllFonts = "";
|
||||
NSFile::CFileBinary::ReadAllTextUtf8A(m_sDirectory + L"/AllFonts.js", sAllFonts);
|
||||
return sAllFonts;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CApplicationFontsWorker::GetFontNames(NSFonts::IApplicationFonts* pFonts)
|
||||
{
|
||||
std::vector<std::wstring> arNames;
|
||||
if (!pFonts || !pFonts->GetList())
|
||||
return arNames;
|
||||
std::vector<NSFonts::CFontInfo*>* arInfos = pFonts->GetList()->GetFonts();
|
||||
|
||||
std::map<std::wstring, bool> map;
|
||||
|
||||
for (std::vector<NSFonts::CFontInfo*>::iterator iter = arInfos->begin(); iter != arInfos->end(); iter++)
|
||||
{
|
||||
if (map.find((*iter)->m_wsFontName) == map.end())
|
||||
arNames.push_back((*iter)->m_wsFontName);
|
||||
}
|
||||
|
||||
std::sort(arNames.begin(), arNames.end());
|
||||
return arNames;
|
||||
}
|
||||
|
||||
@ -34,19 +34,25 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../graphics/pro/Fonts.h"
|
||||
|
||||
class CApplicationFontsWorker
|
||||
{
|
||||
public:
|
||||
std::vector<std::wstring> m_arAdditionalFolders;
|
||||
bool m_bIsUseSystemFonts;
|
||||
std::vector<std::wstring> m_arAdditionalFolders;
|
||||
std::wstring m_sDirectory;
|
||||
bool m_bIsNeedThumbnails;
|
||||
bool m_bIsUseOpenType;
|
||||
|
||||
public:
|
||||
CApplicationFontsWorker();
|
||||
~CApplicationFontsWorker();
|
||||
|
||||
std::vector<std::wstring> CheckApplication(bool bIsNeedSystemFonts,
|
||||
unsigned char* pDataSrc, unsigned int nLenSrc,
|
||||
unsigned char*& pDataDst, unsigned int& nLenDst);
|
||||
NSFonts::IApplicationFonts* Check();
|
||||
std::string GetAllFonts();
|
||||
|
||||
static std::vector<std::wstring> GetFontNames(NSFonts::IApplicationFonts* pFonts);
|
||||
};
|
||||
|
||||
#endif // _BUILD_APPLICATIONFONTSWORKER_H_
|
||||
|
||||
Reference in New Issue
Block a user