Kaydet (Commit) 5a737fca authored tarafından Miklos Vajna's avatar Miklos Vajna

fdo#46361 oox: handle w:jc for groupshape textboxes

Change-Id: I21391d9a9f5b5173b599006287b33fdaab3c0c75
üst 6bf79576
......@@ -37,6 +37,12 @@ struct ShapeTypeModel;
// ============================================================================
/// A text paragraph in a textbox.
struct TextParagraphModel
{
OptValue<OUString> moParaAdjust; ///< Paragraph adjust (left, center, right, etc.)
};
/** Font settings for a text portion in a textbox. */
struct OOX_DLLPUBLIC TextFontModel
{
......@@ -57,10 +63,11 @@ struct OOX_DLLPUBLIC TextFontModel
/** A text portion in a textbox with the same formatting for all characters. */
struct TextPortionModel
{
TextParagraphModel maParagraph;
TextFontModel maFont;
OUString maText;
explicit TextPortionModel( const TextFontModel& rFont, const OUString& rText );
explicit TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText );
};
// ============================================================================
......@@ -72,7 +79,7 @@ public:
explicit TextBox(ShapeTypeModel& rTypeModel);
/** Appends a new text portion to the textbox. */
void appendPortion( const TextFontModel& rFont, const OUString& rText );
void appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText );
/** Returns the current number of text portions. */
inline size_t getPortionCount() const { return maPortions.size(); }
......
......@@ -36,6 +36,7 @@ public:
explicit TextPortionContext(
::oox::core::ContextHandler2Helper& rParent,
TextBox& rTextBox,
TextParagraphModel& rParagraph,
const TextFontModel& rParentFont,
sal_Int32 nElement,
const AttributeList& rAttribs );
......@@ -48,6 +49,7 @@ public:
private:
TextBox& mrTextBox;
TextParagraphModel maParagraph;
TextFontModel maFont;
size_t mnInitialPortions;
};
......@@ -65,10 +67,12 @@ public:
virtual ::oox::core::ContextHandlerRef
onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
virtual void onStartElement(const AttributeList& rAttribs) SAL_OVERRIDE;
virtual void onEndElement();
private:
TextBox& mrTextBox;
TextParagraphModel maParagraph;
};
// ============================================================================
......
......@@ -24,6 +24,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/text/XTextAppend.hpp>
#include <com/sun/star/text/WritingMode.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
namespace oox {
namespace vml {
......@@ -34,7 +35,8 @@ TextFontModel::TextFontModel()
{
}
TextPortionModel::TextPortionModel( const TextFontModel& rFont, const OUString& rText ) :
TextPortionModel::TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) :
maParagraph( rParagraph ),
maFont( rFont ),
maText( rText )
{
......@@ -50,9 +52,9 @@ TextBox::TextBox(ShapeTypeModel& rTypeModel)
{
}
void TextBox::appendPortion( const TextFontModel& rFont, const OUString& rText )
void TextBox::appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText )
{
maPortions.push_back( TextPortionModel( rFont, rText ) );
maPortions.push_back( TextPortionModel( rParagraph, rFont, rText ) );
}
const TextFontModel* TextBox::getFirstFont() const
......@@ -75,6 +77,7 @@ void TextBox::convert(uno::Reference<drawing::XShape> xShape) const
{
beans::PropertyValue aPropertyValue;
std::vector<beans::PropertyValue> aPropVec;
const TextParagraphModel& rParagraph = aIt->maParagraph;
const TextFontModel& rFont = aIt->maFont;
if (rFont.mobBold.has())
{
......@@ -88,6 +91,18 @@ void TextBox::convert(uno::Reference<drawing::XShape> xShape) const
aPropertyValue.Value = uno::makeAny(double(rFont.monSize.get()) / 2.);
aPropVec.push_back(aPropertyValue);
}
if (rParagraph.moParaAdjust.has())
{
style::ParagraphAdjust eAdjust = style::ParagraphAdjust_LEFT;
if (rParagraph.moParaAdjust.get() == "center")
eAdjust = style::ParagraphAdjust_CENTER;
else if (rParagraph.moParaAdjust.get() == "right")
eAdjust = style::ParagraphAdjust_RIGHT;
aPropertyValue.Name = "ParaAdjust";
aPropertyValue.Value = uno::makeAny(eAdjust);
aPropVec.push_back(aPropertyValue);
}
uno::Sequence<beans::PropertyValue> aPropSeq(aPropVec.size());
beans::PropertyValue* pValues = aPropSeq.getArray();
for (std::vector<beans::PropertyValue>::iterator i = aPropVec.begin(); i != aPropVec.end(); ++i)
......
......@@ -34,10 +34,11 @@ using ::oox::core::ContextHandlerRef;
// ============================================================================
TextPortionContext::TextPortionContext( ContextHandler2Helper& rParent,
TextBox& rTextBox, const TextFontModel& rParentFont,
TextBox& rTextBox, TextParagraphModel& rParagraph, const TextFontModel& rParentFont,
sal_Int32 nElement, const AttributeList& rAttribs ) :
ContextHandler2( rParent ),
mrTextBox( rTextBox ),
maParagraph( rParagraph ),
maFont( rParentFont ),
mnInitialPortions( rTextBox.getPortionCount() )
{
......@@ -96,7 +97,7 @@ ContextHandlerRef TextPortionContext::onCreateContext( sal_Int32 nElement, const
OSL_ENSURE( nElement != XML_font, "TextPortionContext::onCreateContext - nested <font> elements" );
if (getNamespace(getCurrentElement()) == NMSP_doc)
return this;
return new TextPortionContext( *this, mrTextBox, maFont, nElement, rAttribs );
return new TextPortionContext( *this, mrTextBox, maParagraph, maFont, nElement, rAttribs );
}
void TextPortionContext::onCharacters( const OUString& rChars )
......@@ -108,10 +109,10 @@ void TextPortionContext::onCharacters( const OUString& rChars )
{
case XML_span:
// replace all NBSP characters with SP
mrTextBox.appendPortion( maFont, rChars.replace( 0xA0, ' ' ) );
mrTextBox.appendPortion( maParagraph, maFont, rChars.replace( 0xA0, ' ' ) );
break;
default:
mrTextBox.appendPortion( maFont, rChars );
mrTextBox.appendPortion( maParagraph, maFont, rChars );
}
}
......@@ -126,7 +127,7 @@ void TextPortionContext::onStartElement(const AttributeList& rAttribs)
maFont.monSize = rAttribs.getInteger( OOX_TOKEN(doc, val) );
break;
case OOX_TOKEN(doc, br):
mrTextBox.appendPortion( maFont, "\n" );
mrTextBox.appendPortion( maParagraph, maFont, "\n" );
break;
}
}
......@@ -153,7 +154,7 @@ void TextPortionContext::onEndElement()
meantime, the space character has to be added manually.
*/
if( mrTextBox.getPortionCount() == mnInitialPortions )
mrTextBox.appendPortion( maFont, OUString( sal_Unicode( ' ' ) ) );
mrTextBox.appendPortion( maParagraph, maFont, OUString( sal_Unicode( ' ' ) ) );
}
// ============================================================================
......@@ -207,22 +208,41 @@ ContextHandlerRef TextBoxContext::onCreateContext( sal_Int32 nElement, const Att
else if (nElement == OOX_TOKEN(doc, txbxContent)) return this;
break;
case XML_div:
if( nElement == XML_font ) return new TextPortionContext( *this, mrTextBox, TextFontModel(), nElement, rAttribs );
if( nElement == XML_font ) return new TextPortionContext( *this, mrTextBox, maParagraph, TextFontModel(), nElement, rAttribs );
break;
case OOX_TOKEN(doc, txbxContent):
if (nElement == OOX_TOKEN(doc, p)) return this;
break;
case OOX_TOKEN(doc, p):
if (nElement == OOX_TOKEN(doc, r)) return new TextPortionContext( *this, mrTextBox, TextFontModel(), nElement, rAttribs );
if (nElement == OOX_TOKEN(doc, r))
return new TextPortionContext( *this, mrTextBox, maParagraph, TextFontModel(), nElement, rAttribs );
else
return this;
break;
case OOX_TOKEN(doc, pPr):
return this;
break;
}
return 0;
}
void TextBoxContext::onStartElement(const AttributeList& rAttribs)
{
switch (getCurrentElement())
{
case OOX_TOKEN(doc, jc):
maParagraph.moParaAdjust = rAttribs.getString( OOX_TOKEN(doc, val) );
break;
}
}
void TextBoxContext::onEndElement()
{
if (getCurrentElement() == OOX_TOKEN(doc, p))
mrTextBox.appendPortion( TextFontModel(), "\n" );
{
mrTextBox.appendPortion( maParagraph, TextFontModel(), "\n" );
maParagraph = TextParagraphModel();
}
}
// ============================================================================
......
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