summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-06-06 10:16:39 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-06-06 10:28:18 +0200
commit639571d52b1b7e4cf912803642ca245c5dd86839 (patch)
tree922062b01450f95debcc0075e16fbb217152d19e
parent31650d5b4255c484faec11d570cb98a80f0120cc (diff)
2nd part of bnc#870233: import font color from color fragment for SmartArts
SmartArt import ignores some fragments during import if drawing fragment exists, which seems to be not complete. In this case font style is blank (white) in data (and drawing) fragment and the real value is defined in the ignored color fragment. So first make color fragment parsing work, then apply font color of "node0" style on nodes of the SmartArt. Actually, it's a workaround, because "node0" style label is hardcoded, for a proper solution layout fragment should be parsed too to get the right style label, but it interferes with the drawing fragment by now. Change-Id: I7db89176a07eee928563d42d3896fbd02190dfa8
-rw-r--r--include/oox/drawingml/shape.hxx4
-rw-r--r--include/oox/ppt/pptshapegroupcontext.hxx3
-rw-r--r--oox/source/drawingml/diagram/diagram.cxx39
-rw-r--r--oox/source/drawingml/diagram/diagramfragmenthandler.cxx49
-rw-r--r--oox/source/ppt/pptshapegroupcontext.cxx13
-rw-r--r--sd/qa/unit/data/pptx/bnc870233_2.pptxbin0 -> 55758 bytes
-rw-r--r--sd/qa/unit/import-tests.cxx68
7 files changed, 135 insertions, 41 deletions
diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx
index fcb499940019..f8e1b7c8e8d7 100644
--- a/include/oox/drawingml/shape.hxx
+++ b/include/oox/drawingml/shape.hxx
@@ -176,6 +176,9 @@ public:
const ::std::vector<OUString>&
getExtDrawings() { return maExtDrawings; }
void addExtDrawingRelId( const OUString &rRelId ) { maExtDrawings.push_back( rRelId ); }
+ // Set font color only for extdrawings.
+ void setFontRefColorForNodes(const Color& rColor) { maFontRefColorForNodes = rColor; }
+ const Color& getFontRefColorForNodes() const { return maFontRefColorForNodes; }
void setLockedCanvas(bool bLockedCanvas);
bool getLockedCanvas();
void setWps(bool bWps);
@@ -267,6 +270,7 @@ protected:
com::sun::star::awt::Size maSize;
com::sun::star::awt::Point maPosition;
::std::vector<OUString> maExtDrawings;
+ Color maFontRefColorForNodes;
private:
enum FrameType
diff --git a/include/oox/ppt/pptshapegroupcontext.hxx b/include/oox/ppt/pptshapegroupcontext.hxx
index f4e1d7a3e892..847d9b6479ee 100644
--- a/include/oox/ppt/pptshapegroupcontext.hxx
+++ b/include/oox/ppt/pptshapegroupcontext.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_OOX_PPT_PPTSHAPEGROUPCONTEXT_HXX
#include <oox/drawingml/shapegroupcontext.hxx>
+#include <oox/drawingml/color.hxx>
#include <oox/ppt/slidepersist.hxx>
namespace oox { namespace ppt {
@@ -30,7 +31,9 @@ class PPTShapeGroupContext : public ::oox::drawingml::ShapeGroupContext
SlidePersistPtr mpSlidePersistPtr;
ShapeLocation meShapeLocation;
oox::drawingml::ShapePtr pGraphicShape;
+
void importExtDrawings();
+ void applyFontRefColor(oox::drawingml::ShapePtr pShape, const oox::drawingml::Color& rFontRefColor);
public:
PPTShapeGroupContext(
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index 70d938ad1ea2..a4ad2798a309 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -320,7 +320,6 @@ void Diagram::build( )
#endif
}
-
void Diagram::addTo( const ShapePtr & pParentShape )
{
// collect data, init maps
@@ -432,7 +431,7 @@ void loadDiagram( ShapePtr& pShape,
}
// extLst is present, lets bet on that and ignore the rest of the data from here
- if( !pData->getExtDrawings().size() )
+ if( pData->getExtDrawings().empty() )
{
// layout
if( !rLayoutPath.isEmpty() )
@@ -459,25 +458,33 @@ void loadDiagram( ShapePtr& pShape,
pDiagram,
xRefQStyle);
}
-
- // colors
- if( !rColorStylePath.isEmpty() )
- {
- rtl::Reference< core::FragmentHandler > xRefColorStyle(
- new ColorFragmentHandler( rFilter, rColorStylePath, pDiagram->getColors() ));
-
- importFragment(rFilter,
- loadFragment(rFilter,xRefColorStyle),
- "OOXColor",
- pDiagram,
- xRefColorStyle);
- }
} else {
// We still want to add the XDocuments to the DiagramDomMap
DiagramDomMap& rMainDomMap = pDiagram->getDomMap();
rMainDomMap[OUString("OOXLayout")] = loadFragment(rFilter,rLayoutPath);
rMainDomMap[OUString("OOXStyle")] = loadFragment(rFilter,rQStylePath);
- rMainDomMap[OUString("OOXColor")] = loadFragment(rFilter,rColorStylePath);
+ }
+
+ // colors
+ if( !rColorStylePath.isEmpty() )
+ {
+ rtl::Reference< core::FragmentHandler > xRefColorStyle(
+ new ColorFragmentHandler( rFilter, rColorStylePath, pDiagram->getColors() ));
+
+ importFragment(rFilter,
+ loadFragment(rFilter,xRefColorStyle),
+ "OOXColor",
+ pDiagram,
+ xRefColorStyle);
+ }
+
+ if( !pData->getExtDrawings().empty() )
+ {
+ const DiagramColorMap::const_iterator aColor = pDiagram->getColors().find("node0");
+ if( aColor != pDiagram->getColors().end() )
+ {
+ pShape->setFontRefColorForNodes(aColor->second.maTextFillColor);
+ }
}
// diagram loaded. now lump together & attach to shape
diff --git a/oox/source/drawingml/diagram/diagramfragmenthandler.cxx b/oox/source/drawingml/diagram/diagramfragmenthandler.cxx
index aa14178ed2b1..7c132340340e 100644
--- a/oox/source/drawingml/diagram/diagramfragmenthandler.cxx
+++ b/oox/source/drawingml/diagram/diagramfragmenthandler.cxx
@@ -166,7 +166,7 @@ DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFi
void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
{
- if( getCurrentElement() == DGM_TOKEN( styleDef ) )
+ if( getCurrentElement() == DGM_TOKEN( styleLbl ) )
{
maStyleName = rAttribs.getString( XML_name, OUString() );
maStyleEntry = mrStylesMap[maStyleName];
@@ -203,30 +203,29 @@ ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
case DGM_TOKEN(colorsDef):
return nElement == DGM_TOKEN(styleLbl) ? this : NULL;
case DGM_TOKEN(styleLbl):
- return ((nElement == DGM_TOKEN(fillClrLst)) ||
- (nElement == DGM_TOKEN(linClrLst)) ||
- (nElement == DGM_TOKEN(effectClrLst)) ||
- (nElement == DGM_TOKEN(txLinClrLst)) ||
- (nElement == DGM_TOKEN(txFillClrLst)) ||
- (nElement == DGM_TOKEN(txEffectClrLst))) ? this : NULL;
-
- // the actual colors - defer to color fragment handlers.
-
- // TODO(F1): well, actually, there might be *several* color
- // definitions in it, after all its called list. but
- // apparently colorChoiceContext doesn't handle that anyway...
- case DGM_TOKEN(fillClrLst):
- return new ColorContext( *this, maColorEntry.maFillColor );
- case DGM_TOKEN(linClrLst):
- return new ColorContext( *this, maColorEntry.maLineColor );
- case DGM_TOKEN(effectClrLst):
- return new ColorContext( *this, maColorEntry.maEffectColor );
- case DGM_TOKEN(txFillClrLst):
- return new ColorContext( *this, maColorEntry.maTextFillColor );
- case DGM_TOKEN(txLinClrLst):
- return new ColorContext( *this, maColorEntry.maTextLineColor );
- case DGM_TOKEN(txEffectClrLst):
- return new ColorContext( *this, maColorEntry.maTextEffectColor );
+ {
+ switch( nElement )
+ {
+ // the actual colors - defer to color fragment handlers.
+
+ // TODO(F1): well, actually, there might be *several* color
+ // definitions in it, after all its called list. but
+ // apparently ColorContext doesn't handle that anyway...
+ case DGM_TOKEN(fillClrLst):
+ return new ColorContext( *this, maColorEntry.maFillColor );
+ case DGM_TOKEN(linClrLst):
+ return new ColorContext( *this, maColorEntry.maLineColor );
+ case DGM_TOKEN(effectClrLst):
+ return new ColorContext( *this, maColorEntry.maEffectColor );
+ case DGM_TOKEN(txFillClrLst):
+ return new ColorContext( *this, maColorEntry.maTextFillColor );
+ case DGM_TOKEN(txLinClrLst):
+ return new ColorContext( *this, maColorEntry.maTextLineColor );
+ case DGM_TOKEN(txEffectClrLst):
+ return new ColorContext( *this, maColorEntry.maTextEffectColor );
+ }
+ break;
+ }
}
return 0;
diff --git a/oox/source/ppt/pptshapegroupcontext.cxx b/oox/source/ppt/pptshapegroupcontext.cxx
index e25bf6561d0b..0fd517f0c14c 100644
--- a/oox/source/ppt/pptshapegroupcontext.cxx
+++ b/oox/source/ppt/pptshapegroupcontext.cxx
@@ -132,11 +132,24 @@ void PPTShapeGroupContext::importExtDrawings( )
mpMasterShapePtr,
mpGroupShapePtr,
pGraphicShape ) );
+ // Apply font color imported from color fragment
+ if( pGraphicShape->getFontRefColorForNodes().isUsed() )
+ applyFontRefColor(mpGroupShapePtr, pGraphicShape->getFontRefColorForNodes());
}
pGraphicShape = oox::drawingml::ShapePtr( (PPTShape *)NULL );
}
}
+void PPTShapeGroupContext::applyFontRefColor(oox::drawingml::ShapePtr pShape, const oox::drawingml::Color& rFontRefColor)
+{
+ pShape->getShapeStyleRefs()[XML_fontRef].maPhClr = rFontRefColor;
+ std::vector< oox::drawingml::ShapePtr >& vChildren = pShape->getChildren();
+ for( std::vector< oox::drawingml::ShapePtr >::iterator aIter = vChildren.begin(); aIter != vChildren.end(); ++aIter )
+ {
+ applyFontRefColor( *aIter ,rFontRefColor);
+ }
+}
+
void PPTShapeGroupContext::onEndElement()
{
importExtDrawings();
diff --git a/sd/qa/unit/data/pptx/bnc870233_2.pptx b/sd/qa/unit/data/pptx/bnc870233_2.pptx
new file mode 100644
index 000000000000..7f4fc715aab4
--- /dev/null
+++ b/sd/qa/unit/data/pptx/bnc870233_2.pptx
Binary files differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index b9418b4d99ca..ce0d9d17c220 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -76,6 +76,7 @@ public:
void testMediaEmbedding();
void testBnc870237();
void testBnc870233_1();
+ void testBnc870233_2();
CPPUNIT_TEST_SUITE(SdFiltersTest);
CPPUNIT_TEST(testDocumentLayout);
@@ -102,6 +103,7 @@ public:
CPPUNIT_TEST(testMediaEmbedding);
CPPUNIT_TEST(testBnc870237);
CPPUNIT_TEST(testBnc870233_1);
+ CPPUNIT_TEST(testBnc870233_2);
CPPUNIT_TEST_SUITE_END();
};
@@ -832,6 +834,72 @@ void SdFiltersTest::testBnc870233_1()
xDocShRef->DoClose();
}
+void SdFiltersTest::testBnc870233_2()
+{
+ ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/bnc870233_2.pptx"));
+ xDocShRef = saveAndReload( xDocShRef, PPTX );
+
+ SdDrawDocument *pDoc = xDocShRef->GetDoc();
+ CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
+ const SdrPage *pPage = pDoc->GetPage (1);
+ CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
+
+ // The problem was in some SmartArts font color was wrong
+
+ // First smart art has blue font color (direct formatting)
+ {
+ const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
+ CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
+ const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject();
+ std::vector<EECharAttrib> rLst;
+ aEdit.GetCharAttribs(0, rLst);
+ for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
+ {
+ const SvxColorItem *pCharColor = dynamic_cast<const SvxColorItem *>((*it).pAttr);
+ if( pCharColor )
+ {
+ CPPUNIT_ASSERT_EQUAL( sal_uInt32(0x0000ff), pCharColor->GetValue().GetColor());
+ }
+ }
+ }
+
+ // Second smart art has "dk2" font color (style)
+ {
+ const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
+ CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
+ const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject();
+ std::vector<EECharAttrib> rLst;
+ aEdit.GetCharAttribs(0, rLst);
+ for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
+ {
+ const SvxColorItem *pCharColor = dynamic_cast<const SvxColorItem *>((*it).pAttr);
+ if( pCharColor )
+ {
+ CPPUNIT_ASSERT_EQUAL( sal_uInt32(0x1F497D), pCharColor->GetValue().GetColor());
+ }
+ }
+ }
+
+ // Third smart art has white font color (style)
+ {
+ const SdrTextObj *pObj = dynamic_cast<SdrTextObj *>( pPage->GetObj( 2 ) );
+ CPPUNIT_ASSERT_MESSAGE( "no object", pObj != NULL);
+ const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject();
+ std::vector<EECharAttrib> rLst;
+ aEdit.GetCharAttribs(0, rLst);
+ for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
+ {
+ const SvxColorItem *pCharColor = dynamic_cast<const SvxColorItem *>((*it).pAttr);
+ if( pCharColor )
+ {
+ CPPUNIT_ASSERT_EQUAL( sal_uInt32(0xffffff), pCharColor->GetValue().GetColor());
+ }
+ }
+ }
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);