1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "XMLTextFrameContext.hxx"
12 #include "XMLBase64ImportContext.hxx"
13 #include "txtparai.hxx"
15 #include "xmltext.hxx"
17 #include <sal/log.hxx>
19 using namespace com::sun::star
;
21 namespace writerperfect::exp
25 /// Handler for <draw:text-box>.
26 class XMLTextBoxContext
: public XMLImportContext
29 XMLTextBoxContext(XMLImport
& rImport
);
31 rtl::Reference
<XMLImportContext
>
32 CreateChildContext(const OUString
& rName
,
33 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
36 startElement(const OUString
& rName
,
37 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
38 void SAL_CALL
endElement(const OUString
& rName
) override
;
42 XMLTextBoxContext::XMLTextBoxContext(XMLImport
& rImport
)
43 : XMLImportContext(rImport
)
47 rtl::Reference
<XMLImportContext
> XMLTextBoxContext::CreateChildContext(
48 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
50 return CreateTextChildContext(GetImport(), rName
);
53 void XMLTextBoxContext::startElement(
54 const OUString
& /*rName*/,
55 const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
57 GetImport().GetGenerator().openTextBox(librevenge::RVNGPropertyList());
60 void XMLTextBoxContext::endElement(const OUString
& /*rName*/)
62 GetImport().GetGenerator().closeTextBox();
67 /// Handler for <draw:image>.
68 class XMLTextImageContext
: public XMLImportContext
71 XMLTextImageContext(XMLImport
& rImport
);
73 rtl::Reference
<XMLImportContext
>
74 CreateChildContext(const OUString
& rName
,
75 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
78 startElement(const OUString
& rName
,
79 const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
) override
;
80 void SAL_CALL
endElement(const OUString
& rName
) override
;
84 rtl::Reference
<XMLBase64ImportContext
> m_xBinaryData
;
88 XMLTextImageContext::XMLTextImageContext(XMLImport
& rImport
)
89 : XMLImportContext(rImport
)
93 rtl::Reference
<XMLImportContext
> XMLTextImageContext::CreateChildContext(
94 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
96 if (rName
== "office:binary-data")
98 m_xBinaryData
= new XMLBase64ImportContext(GetImport());
104 void XMLTextImageContext::startElement(
105 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
107 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
109 const OUString
& rAttributeName
= xAttribs
->getNameByIndex(i
);
110 if (rAttributeName
== "loext:mime-type" || rAttributeName
== "draw:mime-type")
111 m_aMimeType
= OUStringToOString(xAttribs
->getValueByIndex(i
), RTL_TEXTENCODING_UTF8
);
115 void XMLTextImageContext::endElement(const OUString
& /*rName*/)
117 librevenge::RVNGPropertyList aPropertyList
;
119 aPropertyList
.insert("librevenge:mime-type", m_aMimeType
.getStr());
120 if (m_xBinaryData
.is())
121 aPropertyList
.insert("office:binary-data", m_xBinaryData
->getBinaryData());
123 GetImport().GetGenerator().insertBinaryObject(aPropertyList
);
126 XMLTextFrameContext::XMLTextFrameContext(XMLImport
& rImport
)
127 : XMLImportContext(rImport
)
131 rtl::Reference
<XMLImportContext
> XMLTextFrameContext::CreateChildContext(
132 const OUString
& rName
, const css::uno::Reference
<css::xml::sax::XAttributeList
>& /*xAttribs*/)
134 if (rName
== "draw:image")
135 return new XMLTextImageContext(GetImport());
136 if (rName
== "draw:text-box")
137 return new XMLTextBoxContext(GetImport());
138 SAL_WARN("writerperfect", "XMLTextFrameContext::CreateChildContext: unhandled " << rName
);
142 void XMLTextFrameContext::startElement(
143 const OUString
& /*rName*/, const css::uno::Reference
<css::xml::sax::XAttributeList
>& xAttribs
)
145 librevenge::RVNGPropertyList aPropertyList
;
146 for (sal_Int16 i
= 0; i
< xAttribs
->getLength(); ++i
)
148 const OUString
& rAttributeName
= xAttribs
->getNameByIndex(i
);
149 const OUString
& rAttributeValue
= xAttribs
->getValueByIndex(i
);
151 if (rAttributeName
== "draw:style-name")
152 FillStyles(rAttributeValue
, GetImport().GetAutomaticGraphicStyles(),
153 GetImport().GetGraphicStyles(), aPropertyList
);
156 OString sName
= OUStringToOString(rAttributeName
, RTL_TEXTENCODING_UTF8
);
157 OString sValue
= OUStringToOString(rAttributeValue
, RTL_TEXTENCODING_UTF8
);
158 aPropertyList
.insert(sName
.getStr(), sValue
.getStr());
161 GetImport().GetGenerator().openFrame(aPropertyList
);
164 void XMLTextFrameContext::endElement(const OUString
& /*rName*/)
166 GetImport().GetGenerator().closeFrame();
169 } // namespace writerperfect::exp
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */