Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
14 changes: 14 additions & 0 deletions OdfFile/Test/test_odf/docx2odt_header_drawing_anchor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,17 @@ TEST(DocxToOdtHeaderDrawingAnchor, DrawingInTheTableOfTheBodyStaysACellDrawing)
EXPECT_EQ(attribute(line, L"text:anchor-type"), L"char");
EXPECT_EQ(attribute(graphic_properties(content, line), L"style:vertical-rel"), L"paragraph-content");
}

TEST(DocxToOdtDrawing, PreservesImageTitleAndDescription)
{
const auto dir = convert_ooxml_to_odf_dir(L"ExampleFiles/image_alt_text.docx");
ASSERT_FALSE(dir.empty());
const auto xml = read_part(dir, L"content.xml");
const auto start = xml.find(L"<draw:frame ");
const auto end = xml.find(L"</draw:frame>", start);
ASSERT_NE(start, std::wstring::npos);
ASSERT_NE(end, std::wstring::npos);
const auto frame = xml.substr(start, end - start);
EXPECT_NE(frame.find(L"<svg:title>A &amp; B</svg:title>"), std::wstring::npos);
EXPECT_NE(frame.find(L"<svg:desc>One pixel</svg:desc>"), std::wstring::npos);
}
11 changes: 11 additions & 0 deletions OdfFile/Writer/Converter/DocxConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

#include "../Format/odf_text_context.h"
#include "../Format/odf_drawing_context.h"
#include "../Format/draw_frame.h"

#include "../Format/styles.h"

Expand Down Expand Up @@ -3617,10 +3618,13 @@ void DocxConverter::convert(OOX::Logic::CDrawing *oox_drawing)
{
if (oox_drawing == nullptr) return;

const PPTX::Logic::CNvPr *docPr = nullptr;

odt_context->start_drawing_context();
if (oox_drawing->m_oAnchor.IsInit())
{
convert(oox_drawing->m_oAnchor.GetPointer());
docPr = oox_drawing->m_oAnchor->m_oDocPr.GetPointer();

odf_context()->drawing_context()->start_drawing();
OoxConverter::convert(&oox_drawing->m_oAnchor->m_oGraphic);
Expand All @@ -3629,12 +3633,19 @@ void DocxConverter::convert(OOX::Logic::CDrawing *oox_drawing)
else if (oox_drawing->m_oInline.IsInit())
{
convert(oox_drawing->m_oInline.GetPointer());
docPr = oox_drawing->m_oInline->m_oDocPr.GetPointer();

odf_context()->drawing_context()->start_drawing();
OoxConverter::convert(&oox_drawing->m_oInline->m_oGraphic);
odt_context->drawing_context()->set_anchor(odf_types::anchor_type::AsChar);
odf_context()->drawing_context()->end_drawing();
}
auto *frame = dynamic_cast<odf_writer::draw_frame*>(odt_context->drawing_context()->get_root_element().get());
if (frame && docPr)
{
if (docPr->title.IsInit()) frame->svg_title_ = *docPr->title;
if (docPr->descr.IsInit()) frame->svg_desc_ = *docPr->descr;
}
odt_context->end_drawing_context();
}
void DocxConverter::convert(OOX::Drawing::CAnchor* oox_anchor)
Expand Down
8 changes: 8 additions & 0 deletions OdfFile/Writer/Format/draw_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ void draw_frame::serialize(std::wostream & _Wostream)
if (office_event_listeners_)office_event_listeners_->serialize(CP_XML_STREAM());

draw_base::serialize(CP_XML_STREAM());
if (!svg_title_.empty())
{
CP_XML_NODE(L"svg:title") { CP_XML_CONTENT(svg_title_); }
}
if (!svg_desc_.empty())
{
CP_XML_NODE(L"svg:desc") { CP_XML_CONTENT(svg_desc_); }
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions OdfFile/Writer/Format/draw_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class draw_frame : public draw_base
virtual void serialize(std::wostream & _Wostream);

int idx_in_owner ;
std::wstring svg_title_;
std::wstring svg_desc_;

draw_frame_attlist draw_frame_attlist_;

Expand Down
1 change: 1 addition & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ path = [
"OdfFile/Test/test_odf/ExampleFiles/deletion_over_paragraph_break.docx",
"OdfFile/Test/test_odf/ExampleFiles/format_change_same_id.docx",
"OdfFile/Test/test_odf/ExampleFiles/deletion_same_id_apart.docx",
"OdfFile/Test/test_odf/ExampleFiles/image_alt_text.docx",
"OdfFile/Test/test_odf/ExampleFiles/column_break_after_text.docx",
"OdfFile/Test/test_odf/ExampleFiles/cell_merged_without_covered_cells.xlsx",
"OdfFile/Test/test_odf/ExampleFiles/cell_repeated_empty_styled.xlsx",
Expand Down