Commit e4d043c1 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader - поправлены кодировки файла, ....

parent 763e543a
#include "formulasconvert.h"
#include "formulasconvert.h"
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
......@@ -132,7 +132,7 @@ namespace formulasconvert {
}
// çàìåíÿåì ôîðìàò àäðåñàöèè ÿ÷ååê
// заменяем формат адресации ячеек
// [.A1] -> A1
// [.A1:.B5] -> A1:B5
// [Sheet2.A1:B5] -> Sheet2!A1:B5
......@@ -168,7 +168,7 @@ void odf2oox_converter::Impl::replace_named_ref(std::wstring & expr)
expr = res;
}
// ðàñïîçíàåì è çàìåíÿåì ôîðìàò ôîðìóëû
// распознаем и заменяем формат формулы
// of:=(Formula) -> (Formula)
bool odf2oox_converter::Impl::check_formula(std::wstring& expr)
{
......@@ -202,8 +202,8 @@ std::wstring replace_semicolons_formater(boost::wsmatch const & what)
}
// TODO
// çàìåíèòü òî÷êè ñ çàïÿòîé âî âñåõ âõîæäåíèÿõ êðîìå íàõîäÿùèõñÿ â êàâû÷êàõ --*è â ôèãóðíûõ ñêîáêàõ*--
// TODO: ïðîâåðèòü êàê ñîõðàíÿþòñÿ êàâû÷êè â ñòðîêå
// заменить точки с запятой во всех вхождениях кроме находящихся в кавычках --*и в фигурных скобках*--
// TODO: проверить как сохраняются кавычки в строке
void odf2oox_converter::Impl::replace_semicolons(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
......@@ -244,12 +244,12 @@ std::wstring replace_space_PROBEL(boost::wsmatch const & what)
else if (what[3].matched)
return what[3].str();
}
std::wstring replace_point_ÒÎÑHKA(boost::wsmatch const & what)
std::wstring replace_point_ТОСHKA(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L".", L"ÒÎÑHKA");
boost::algorithm::replace_all(inner, L".", L"ТОСHKA");
return inner;
}
else if (what[2].matched)
......@@ -298,7 +298,7 @@ bool is_forbidden(const std::wstring & formula)
return false;
}
// çàìåíèòü âåðòèêàëüíóþ ÷åðòó âî âñåõ âõîæäåíèÿõ â ôèãóðíûõ ñêîáêàõ, íî íå âíóòðè ñòðîê
// заменить вертикальную черту во всех вхождениях в фигурных скобках, но не внутри строк
void odf2oox_converter::Impl::replace_vertical(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
......@@ -308,7 +308,7 @@ void odf2oox_converter::Impl::replace_vertical(std::wstring& expr)
boost::match_default | boost::format_all);
expr = res;
}
// çàìåíèòü ïðîáåë âî âñåõ âõîæäåíèÿõ íà çàïÿòóþ
// заменить пробел во всех вхождениях на запятую
void odf2oox_converter::Impl::replace_space(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
......@@ -324,12 +324,12 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr)
if (is_forbidden(expr))
return L"NULLFORMULA()";
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// ïîèñê òîãî ÷òî â àïîñòðîôàõ è çàìåíà òàì òî÷åê íà ÒÎÑHKA
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там точек на ТОСHKA
std::wstring workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_ÒÎÑHKA,
&replace_point_ТОСHKA,
boost::match_default | boost::format_all);
boost::algorithm::replace_all(workstr, L" ", L"PROBEL");
......@@ -343,7 +343,7 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr)
int res_find=0;
if ((res_find = workstr.find(L"CONCATINATE")) > 0)
{
//ìîãóò áûòü ÷àñòè÷íî çàäàíû äèàïàçîíû
//могут быть частично заданы диапазоны
//todooo
}
......@@ -355,7 +355,7 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr)
//Sheet2.C3:Sheet2.C19 Sheet2.L29:Sheet2.L36
//â
//в
//Sheet2!C3:C19,Sheet2!L27:L34
std::wstring odf2oox_converter::Impl::convert_chart_distance(const std::wstring& expr)
{
......@@ -363,7 +363,7 @@ std::wstring odf2oox_converter::Impl::convert_chart_distance(const std::wstring&
return L"NULLFORMULA()";
std::wstring workstr = expr;
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// ïîèñê òîãî ÷òî â àïîñòðîôàõ è çàìåíà òàì ïðîáåëîâ íà PROBEL
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там пробелов на PROBEL
workstr = boost::regex_replace(
expr,
......@@ -371,7 +371,7 @@ std::wstring odf2oox_converter::Impl::convert_chart_distance(const std::wstring&
&replace_space_PROBEL,
boost::match_default | boost::format_all);
//ðàñïàðñèòü ïî äèàïàçîíàì - îäô-ïðîáåë, èê-ýëü-çàïÿòàÿ
//распарсить по диапазонам - одф-пробел, ик-эль-запятая
std::vector<std::wstring> distance_inp;
std::vector<std::wstring> distance_out;
......@@ -418,7 +418,7 @@ std::wstring odf2oox_converter::Impl::convert_chart_distance(const std::wstring&
}
boost::algorithm::replace_all(result, L"PROBEL", L" ");
return result.substr(0, result.size()-1);// ìèíóñ ïîñëåäíÿÿ ëèøíÿÿ çàïÿòàÿ
return result.substr(0, result.size()-1);// минус последняя лишняя запятая
}
odf2oox_converter::odf2oox_converter(): impl_(new odf2oox_converter::Impl)
{
......@@ -438,12 +438,12 @@ std::wstring odf2oox_converter::convert_chart_distance(const std::wstring& expr)
}
std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr)
{
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// ïîèñê òîãî ÷òî â àïîñòðîôàõ è çàìåíà òàì òî÷åê íà ÒÎÑHKA
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там точек на ТОСHKA
std::wstring workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_ÒÎÑHKA,
&replace_point_ТОСHKA,
boost::match_default | boost::format_all);
boost::algorithm::replace_all(workstr, L" ", L"PROBEL");
......@@ -458,12 +458,12 @@ std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr)
}
std::wstring odf2oox_converter::convert_named_expr(const std::wstring& expr)
{
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// ïîèñê òîãî ÷òî â àïîñòðîôàõ è çàìåíà òàì òî÷åê íà ÒÎÑHKA
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там точек на ТОСHKA
std::wstring workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_ÒÎÑHKA,
&replace_point_ТОСHKA,
boost::match_default | boost::format_all);
boost::algorithm::replace_all(workstr, L" ", L"PROBEL");
......@@ -476,7 +476,7 @@ std::wstring odf2oox_converter::convert_named_expr(const std::wstring& expr)
int res_find=0;
if ((res_find = workstr.find(L"CONCATINATE")) > 0)
{
//ìîãóò áûòü ÷àñòè÷íî çàäàíû äèàïàçîíû
//могут быть частично заданы диапазоны
//todooo
}
......
#include "formulasconvert.h"
#include "formulasconvert.h"
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
......@@ -107,7 +107,7 @@ public:
//}
//
//
// заменяем формат адресации ячеек НАОБОРОТ
// [.A1] -> A1
// [.A1:.B5] -> A1:B5
// [Sheet2.A1:B5] -> Sheet2!A1:B5
......@@ -218,7 +218,7 @@ std::wstring oox2odf_converter::Impl::replace_cells_range_formater2(boost::wsmat
//
//}
// 1!$A$1 -> $1.$A$1
// Лист1!$A$1 -> $Лист1.$A$1
void oox2odf_converter::Impl::replace_named_ref(std::wstring & expr)
{
......@@ -289,8 +289,8 @@ std::wstring replace_semicolons_formater(boost::wsmatch const & what)
}
// TODO
// --* *--
// TODO:
// заменить запятые на точки с запятой во всех вхождениях кроме находящихся в кавычках --*и в фигурных скобках*--
// TODO: проверить как сохраняются кавычки в строке
void oox2odf_converter::Impl::replace_semicolons(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
......@@ -368,7 +368,7 @@ bool is_forbidden1(const std::wstring & formula)
// boost::match_default | boost::format_all);
// expr = res;
//}
// ,
// заменить вертикальную черту во всех вхождениях в фигурных скобках, но не внутри строк
void oox2odf_converter::Impl::replace_vertical(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
......@@ -378,7 +378,7 @@ void oox2odf_converter::Impl::replace_vertical(std::wstring& expr)
boost::match_default | boost::format_all);
expr = res;
}
//
// заменить запятую во всех вхождениях на пробел
void oox2odf_converter::Impl::replace_space(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
......@@ -579,7 +579,7 @@ std::wstring oox2odf_converter::Impl::convert_conditional_formula(const std::wst
}
//Sheet2!C3:C19,Sheet2!L27:L34
//
//в
//Sheet2.C3:Sheet2.C19 Sheet2.L29:Sheet2.L36
//todooo
std::wstring oox2odf_converter::Impl::convert_chart_distance(const std::wstring& expr1)
......@@ -591,7 +591,7 @@ std::wstring oox2odf_converter::Impl::convert_chart_distance(const std::wstring&
res= expr.rfind(L")");
if (res ==expr.size()-2) expr = expr.substr(0, res);
// - -, --
//распарсить по диапазонам - одф-пробел, ик-эль-запятая
std::vector<std::wstring> distance_inp;
std::vector<std::wstring> distance_out;
......
......@@ -8,17 +8,6 @@
#include "../../DesktopEditor/fontengine/FontManager.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
double getSystemDPI()
{
//При запросе системных настроек-проблема в linux без графического интерфейса.
//Используется в GetMaxDigitSizePixels для измерения символов, можно указывать любой dpi,
//потому что после измерения pix переводятся обратно в метрические величины.
//Используется для конвертации картинок с процентными размерами oox->odf. Из редактора никогда не приходят относительные размеры,
//думаю тут несущественнен dpi.
return 96.;
}
namespace cpdoccore {
namespace utils {
......@@ -77,7 +66,8 @@ std::pair<float, float> GetMaxDigitSizePixelsImpl(const std::wstring & fontName,
if (box.fMaxY - box.fMinY < minHeight) minHeight = box.fMaxY - box.fMinY;
}
return std::pair<float, float>(maxWidth / 5.f, maxHeight);
double width = (minWidth + 2 * maxWidth) /3. /5.;
return std::pair<float, float>(width, maxHeight);
}
......
......@@ -5,10 +5,6 @@
class CApplicationFonts;
double getSystemDPI();
namespace cpdoccore {
namespace utils {
......
......@@ -12,48 +12,6 @@
namespace cpdoccore {
namespace oox {
void oox_chart_legend::oox_serialize_default_text(std::wostream & _Wostream)
{
if (content_.text_properties_.size() < 1)return;
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE(L"c:txPr")
{
CP_XML_NODE(L"a:bodyPr");
CP_XML_NODE(L"a:lstStyle");
CP_XML_NODE(L"a:p")
{
CP_XML_NODE(L"a:pPr")
{
CP_XML_NODE(L"a:defRPr")
{
_CP_OPT(double) dVal;
_CP_OPT(int) iVal;
_CP_OPT(std::wstring) sVal;
if (odf_reader::GetProperty(content_.text_properties_,L"font-size",dVal))
CP_XML_ATTR(L"sz", (int)(dVal.get()*100));
if ((odf_reader::GetProperty(content_.text_properties_,L"font-style",iVal)) && (*iVal >0))
CP_XML_ATTR(L"i", "true");
if ((odf_reader::GetProperty(content_.text_properties_,L"font-weight",iVal)) && (*iVal >0))
CP_XML_ATTR(L"b", "true");
if (odf_reader::GetProperty(content_.text_properties_,L"font-color",sVal))
CP_XML_NODE(L"a:solidFill")
{
CP_XML_NODE(L"a:srgbClr"){CP_XML_ATTR(L"val", sVal.get());}
}
}
}
}
}
}
}
void oox_chart_legend::oox_serialize(std::wostream & _Wostream)
{
if (content_.bEnabled == false) return;
......@@ -77,10 +35,10 @@ void oox_chart_legend::oox_serialize(std::wostream & _Wostream)
CP_XML_ATTR(L"val", 0);
}
shape.set(content_.graphic_properties_,content_.fill_);
shape.set(content_.graphic_properties_, content_.fill_);
shape.oox_serialize(CP_XML_STREAM());
oox_serialize_default_text(CP_XML_STREAM());
oox_serialize_default_text(CP_XML_STREAM(), content_.text_properties_);
}
}
......
......@@ -19,7 +19,6 @@ public:
odf_reader::chart::simple content_;
private:
void oox_serialize_default_text(std::wostream & _Wostream);
cpdoccore::oox::oox_layout layout_; //layout (Layout) 21.2.2.88
......
......@@ -359,10 +359,10 @@ void oox_chart_series::oox_serialize_common(std::wostream & _Wostream)
bool bEmpty_dPt = true;
for (int i = 0 ; i < content_.points_.size(); i++)
{
if (content_.points_[i].graphic_properties_.size() > 0 ||
content_.points_[i].fill_.type >= 0)
if (content_.points_[i].bEnabled)
{
bEmpty_dPt = false;
break;
}
}
......@@ -382,6 +382,8 @@ void oox_chart_series::oox_serialize_common(std::wostream & _Wostream)
shape.set( content_.points_[i].graphic_properties_, content_.points_[i].fill_);
shape.oox_serialize(CP_XML_STREAM());
}
oox_serialize_default_text(CP_XML_STREAM(), content_.points_[i].text_properties_);
}
}
}
......
......@@ -33,5 +33,48 @@ void oox_chart_shape::set(std::vector<odf_reader::_property> & prop,_oox_fill &
fill_ = fill;
}
void oox_serialize_default_text(std::wostream & _Wostream, std::vector<odf_reader::_property>& properties)
{
if (properties.size() < 1)return;
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE(L"c:txPr")
{
CP_XML_NODE(L"a:bodyPr");
CP_XML_NODE(L"a:lstStyle");
CP_XML_NODE(L"a:p")
{
CP_XML_NODE(L"a:pPr")
{
CP_XML_NODE(L"a:defRPr")
{
_CP_OPT(double) dVal;
_CP_OPT(int) iVal;
_CP_OPT(std::wstring) sVal;
if (odf_reader::GetProperty(properties, L"font-size",dVal))
CP_XML_ATTR(L"sz", (int)(dVal.get()*100));
if ((odf_reader::GetProperty(properties, L"font-style",iVal)) && (*iVal >0))
CP_XML_ATTR(L"i", "true");
if ((odf_reader::GetProperty(properties, L"font-weight",iVal)) && (*iVal >0))
CP_XML_ATTR(L"b", "true");
if (odf_reader::GetProperty(properties, L"font-color",sVal))
CP_XML_NODE(L"a:solidFill")
{
CP_XML_NODE(L"a:srgbClr"){CP_XML_ATTR(L"val", sVal.get());}
}
}
}
}
}
}
}
}
}
......@@ -10,6 +10,9 @@
namespace cpdoccore {
namespace oox {
void oox_serialize_default_text(std::wostream & _Wostream, std::vector<odf_reader::_property>& properties);
class oox_chart_shape: boost::noncopyable
{
public:
......
......@@ -11,7 +11,11 @@ namespace oox {
void oox_title::oox_serialize(std::wostream & _Wostream)
{
if (content_.content_.length()<1) return;
if (content_.content_.length() < 1)
{
// txPr
return;
}
CP_XML_WRITER(_Wostream)
{
......
......@@ -492,7 +492,7 @@ std::pair<float,float> xlsx_conversion_context::getMaxDigitSize()
else
font_size =10;
maxDigitSize_ = utils::GetMaxDigitSizePixels(font_name.c_str(), font_size, getSystemDPI(), 0, applicationFonts_);
maxDigitSize_ = utils::GetMaxDigitSizePixels(font_name.c_str(), font_size, 96., 0, applicationFonts_);
}
return maxDigitSize_;
}
......
......@@ -681,9 +681,12 @@ void process_build_chart::visit(const chart_data_point & val)
if (val.chart_data_point_attlist_.common_attlist_.chart_style_name_)
{
ApplyGraphicProperties (val.chart_data_point_attlist_.common_attlist_.chart_style_name_.get_value_or(L""),
chart_build_.series_.back().points_.back().graphic_properties_,
chart_build_.series_.back().points_.back().fill_);
chart_build_.series_.back().points_.back().bEnabled = true;
std::wstring style_name = val.chart_data_point_attlist_.common_attlist_.chart_style_name_.get_value_or(L"");
ApplyGraphicProperties (style_name, chart_build_.series_.back().points_.back().graphic_properties_,
chart_build_.series_.back().points_.back().fill_);
ApplyTextProperties (style_name, chart_build_.series_.back().points_.back().text_properties_);
}
}
......
......@@ -91,14 +91,11 @@ namespace chart {
};
struct series : public simple
{
struct point
struct point : public simple
{
point(unsigned int rep/*, std::wstring const & styleName*/) : repeated_(rep)/*, style_name_(styleName)*/{}
unsigned int repeated_;
std::vector<_property> graphic_properties_;
oox::_oox_fill fill_;
unsigned int repeated_;
};
std::wstring name_;
......
......@@ -23,8 +23,6 @@
#include "../../../DesktopEditor/raster/BgraFrame.h"
#include "../../../DesktopEditor/raster/Metafile/MetaFile.h"
extern double getSystemDPI();
namespace _image_file_
{
bool GetResolution(const wchar_t* fileName, int & Width, int &Height, CApplicationFonts * appFonts)
......@@ -100,7 +98,7 @@ bool parse_clipping(std::wstring strClipping,std::wstring fileName, double_4 & c
if (Points_pt.size() > 3)// ..
{
float dpi_ = 96.;///getSystemDPI();
float dpi_ = 96.;
clip_rect[0] = dpi_ * Points_pt[3].get_value_unit(length::inch);
clip_rect[1] = dpi_ * Points_pt[0].get_value_unit(length::inch);
clip_rect[2] = dpi_ * Points_pt[1].get_value_unit(length::inch);
......
......@@ -19,8 +19,6 @@
#include "../docx/xlsx_cell_format.h"
#include "../formulasconvert/formulasconvert.h"
extern double getSystemDPI();
namespace cpdoccore {
using namespace odf_types;
......@@ -340,7 +338,7 @@ namespace {
double pixToSize(double pixels, double maxDigitSize)
{
return (int((pixels-5)/maxDigitSize*100.+0.5))/100.;
return (int(( pixels - 5)/ maxDigitSize * 100. + 0.5)) /100. * 0.9;
}
double cmToChars (double cm)
{
......@@ -430,7 +428,7 @@ void table_table_column::xlsx_convert(oox::xlsx_conversion_context & Context)
in_width = 0.0;
}
const double pixDpi = in_width * getSystemDPI();
const double pixDpi = in_width * 96.;
width = pixToSize(pixDpi, Context.getMaxDigitSize().first);
//const double width = cmToChars(prop->style_table_column_properties_attlist_.style_column_width_->get_value_unit(length::cm));
......@@ -782,7 +780,8 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
}
else
{
skip_next_cell = true;
if (last_cell_) // Vehicle log book.ods (row = 24 and more)
skip_next_cell = true;
}
Context.end_table_cell();
......
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