Commit 0c4b3b78 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader -fix strange image file name, fix smallCaps

parent b782624f
...@@ -91,18 +91,37 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ ...@@ -91,18 +91,37 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ
if (uri.empty()) return L""; if (uri.empty()) return L"";
std::wstring sExt; std::wstring sExt;
int n = uri.rfind(L"."); std::wstring f_name = odf_packet_ + FILE_SEPARATOR_STR + uri;
if (n>0) sExt = uri.substr(n);
else if (n==0) sExt = detectImageFileExtension(f_name); //4EA0AA6E-479D-4002-A6AA-6D6C88EC6D65.odt - image - "opentbs_added_1.phpxvkeg" = png
if (sExt.empty())
{ {
//тута скорее всего OleReplacement int n = uri.find(L"ObjectReplacements");
n = uri.find(L"ObjectReplacements"); if (n >= 0)
if (n>=0) {
f_name = odf_packet_ + uri.substr(1, uri.length() - 1);
sExt = detectImageFileExtension(f_name);
}
if (sExt.empty())
{ {
//то что есть ..
int n = uri.rfind(L".");
if (n > 0)
sExt = uri.substr(n);
}
}
return get_default_file_name(type) + boost::lexical_cast<std::wstring>(Num) + sExt;
}
std::wstring mediaitems::detectImageFileExtension(std::wstring &fileName)
{
CFile file; CFile file;
CString f_name = std_string2string(odf_packet_) + std_string2string(uri.substr(1,uri.length()-1)); std::wstring sExt;
if (file.OpenFile(f_name) == S_OK) if (file.OpenFile(std_string2string(fileName)) == S_OK)
{ {
BYTE buffer[128]; BYTE buffer[128];
int buffer_size = 128; int buffer_size = 128;
...@@ -113,18 +132,11 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ ...@@ -113,18 +132,11 @@ std::wstring mediaitems::create_file_name(const std::wstring & uri, RelsType typ
CImageFileFormatChecker image_checker; CImageFileFormatChecker image_checker;
sExt = image_checker.DetectFormatByData(buffer, buffer_size); sExt = image_checker.DetectFormatByData(buffer, buffer_size);
if (sExt.length() > 0) sExt = std::wstring(L".") + sExt; if (!sExt.empty()) sExt = std::wstring(L".") + sExt;
}
}
} }
//todooo проверить return sExt;
return get_default_file_name(type) + boost::lexical_cast<std::wstring>(Num) + sExt;
} }
std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, bool & isInternal, std::wstring & ref) std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, bool & isInternal, std::wstring & ref)
{ {
const bool isMediaInternal = utils::media::is_internal(href, odf_packet_); const bool isMediaInternal = utils::media::is_internal(href, odf_packet_);
...@@ -149,6 +161,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b ...@@ -149,6 +161,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b
std::wstring inputPath = isMediaInternal ? odf_packet_ + FILE_SEPARATOR_STR + href : href; std::wstring inputPath = isMediaInternal ? odf_packet_ + FILE_SEPARATOR_STR + href : href;
std::wstring outputPath = isMediaInternal ? ( sub_path + inputFileName) : href; std::wstring outputPath = isMediaInternal ? ( sub_path + inputFileName) : href;
if ( type == typeChart)outputPath= outputPath + L".xml"; if ( type == typeChart)outputPath= outputPath + L".xml";
std::wstring id; std::wstring id;
...@@ -176,7 +189,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b ...@@ -176,7 +189,7 @@ std::wstring mediaitems::add_or_find(const std::wstring & href, RelsType type, b
{ {
outputPath = outputPath.substr(0, n_svm) + L".png"; outputPath = outputPath.substr(0, n_svm) + L".png";
} }
//------------------------------------------------
id = std::wstring(L"picId") + boost::lexical_cast<std::wstring>(count_image+1); id = std::wstring(L"picId") + boost::lexical_cast<std::wstring>(count_image+1);
count_image++; count_image++;
} }
......
...@@ -85,7 +85,8 @@ public: ...@@ -85,7 +85,8 @@ public:
items_array & items() { return items_; } items_array & items() { return items_; }
private: private:
std::wstring create_file_name(const std::wstring & uri, RelsType type, size_t Num); std::wstring create_file_name (const std::wstring & uri, RelsType type, size_t Num);
std::wstring detectImageFileExtension (std::wstring &fileName);
items_array items_; items_array items_;
std::wstring odf_packet_; std::wstring odf_packet_;
......
...@@ -566,7 +566,7 @@ void text_format_properties_content::docx_convert(oox::docx_conversion_context & ...@@ -566,7 +566,7 @@ void text_format_properties_content::docx_convert(oox::docx_conversion_context &
} }
if (fo_font_variant_) if (fo_font_variant_)
{ {
_rPr << (fo_font_variant_->get_type() == font_variant::SmallCaps ? L"<w:smallCaps w:val=\"true\" />" : L"<w:smallCaps w:val=\"true\" />" ); _rPr << (fo_font_variant_->get_type() == font_variant::SmallCaps ? L"<w:smallCaps w:val=\"true\" />" : L"<w:smallCaps w:val=\"false\" />" );
} }
if (style_font_relief_) if (style_font_relief_)
{ {
...@@ -1057,7 +1057,7 @@ void text_format_properties_content::oox_convert (std::wostream & _rPr, bool gra ...@@ -1057,7 +1057,7 @@ void text_format_properties_content::oox_convert (std::wostream & _rPr, bool gra
} }
if (fo_font_variant_) if (fo_font_variant_)
{ {
_rPr << (fo_font_variant_->get_type() == font_variant::SmallCaps ? L"<w:smallCaps w:val=\"true\" />" : L"<w:smallCaps w:val=\"true\" />" ); _rPr << (fo_font_variant_->get_type() == font_variant::SmallCaps ? L"<w:smallCaps w:val=\"true\" />" : L"<w:smallCaps w:val=\"false\" />" );
} }
if (style_font_relief_) if (style_font_relief_)
{ {
......
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