Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 4589 → Rev 4590

/branches/Version13x/Scribus/scribus/plugins/fileloader/oodraw/oodrawimp.cpp
162,7 → 162,7
interactive = true;
PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("OODrawImport");
QString wdir = prefs->get("wdir", ".");
CustomFDialog diaf(ScMW, wdir, QObject::tr("Open"), QObject::tr("OpenOffice.org Draw (*.sxd);;All Files (*)"));
CustomFDialog diaf(ScMW, wdir, QObject::tr("Open"), QObject::tr("OpenOffice.org Draw (*.sxd *.odg);;All Files (*)"));
if (diaf.exec())
{
fileName = diaf.selectedFile();
252,6 → 252,8
bool OODPlug::convert()
{
bool ret = false;
bool isOODraw2 = false;
QDomNode drawPagePNode;
int PageCounter = 0;
createStyleMap( inpStyles );
QDomElement docElem = inpContents.documentElement();
260,7 → 262,7
insertStyles( automaticStyles.toElement() );
QDomNode body = docElem.namedItem( "office:body" );
QDomNode drawPage = body.namedItem( "draw:page" );
if (drawPage.isNull() )
if ( drawPage.isNull() )
{
QDomNode offDraw = body.namedItem( "office:drawing" );
drawPage = offDraw.namedItem( "draw:page" );
271,14 → 273,28
}
else
{
QMessageBox::warning( ScMW, CommonStrings::trWarning, tr("OpenOffice Draw 2.0 documents are currently not supported.") );
return false;
isOODraw2 = true;
drawPagePNode = body.namedItem( "office:drawing" );
}
}
else
drawPagePNode = body;
StyleStack::Mode mode = isOODraw2 ? StyleStack::OODraw2x : StyleStack::OODraw1x;
m_styleStack.setMode( mode );
QDomElement dp = drawPage.toElement();
QDomElement *master = m_styles[dp.attribute( "draw:master-page-name" )];
QDomElement *style = m_styles[master->attribute( "style:page-master-name" )];
QDomElement properties = style->namedItem( "style:properties" ).toElement();
QDomElement *style = NULL;
QDomElement properties;
if (isOODraw2)
{
style = m_styles[master->attribute( "style:page-layout-name" )];
properties = style->namedItem( "style:page-layout-properties" ).toElement();
}
else
{
style = m_styles[master->attribute( "style:page-master-name" )];
properties = style->namedItem( "style:properties" ).toElement();
}
double width = !properties.attribute( "fo:page-width" ).isEmpty() ? parseUnit(properties.attribute( "fo:page-width" ) ) : 550.0;
double height = !properties.attribute( "fo:page-height" ).isEmpty() ? parseUnit(properties.attribute( "fo:page-height" ) ) : 841.0;
if (!interactive)
344,7 → 360,7
qApp->setOverrideCursor(QCursor(Qt::waitCursor), true);
if (!Doku->PageColors.contains("Black"))
Doku->PageColors.insert("Black", ScColor(0, 0, 0, 255));
for( QDomNode drawPag = body.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling() )
for( QDomNode drawPag = drawPagePNode.firstChild(); !drawPag.isNull(); drawPag = drawPag.nextSibling() )
{
QDomElement dpg = drawPag.toElement();
if (!interactive)
444,7 → 460,7
QString STag = b.tagName();
QString drawID = b.attribute("draw:name");
storeObjectStyles(b);
if( m_styleStack.hasAttribute("draw:stroke"))
if( m_styleStack.hasAttribute("draw:stroke") )
{
if( m_styleStack.attribute( "draw:stroke" ) == "none" )
lwidth = 0.0;
697,6 → 713,8
bool firstPa = false;
for ( QDomNode n = b.firstChild(); !n.isNull(); n = n.nextSibling() )
{
if ( !n.hasAttributes() && !n.hasChildNodes() )
continue;
int FontSize = Doku->toolSettings.defSize;
int AbsStyle = 0;
QDomElement e = n.toElement();
/branches/Version13x/Scribus/scribus/plugins/fileloader/oodraw/stylestack.cpp
30,6 → 30,7
StyleStack::StyleStack()
{
clear();
fillNodeNameList(m_nodeNames, StyleStack::OODraw1x);
}
 
StyleStack::~StyleStack()
36,6 → 37,12
{
}
 
void StyleStack::setMode( const StyleStack::Mode mode )
{
m_nodeNames.clear();
fillNodeNameList(m_nodeNames, mode);
}
 
void StyleStack::clear()
{
m_stack.clear();
73,7 → 80,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name );
if ( properties.hasAttribute( name ) )
return true;
}
88,7 → 95,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name );
if ( properties.hasAttribute( name ) )
return properties.attribute( name );
}
105,7 → 112,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name, fullName );
if ( properties.hasAttribute( name ) || properties.hasAttribute( fullName ) )
return true;
}
122,7 → 129,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name, fullName );
if ( properties.hasAttribute( fullName ) )
return properties.attribute( fullName );
if ( properties.hasAttribute( name ) )
143,7 → 150,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name );
if ( properties.hasAttribute( name ) ) {
QString value = properties.attribute( name );
if ( value.endsWith( "%" ) )
161,7 → 168,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name );
if ( !properties.namedItem( name ).isNull() )
return true;
}
175,7 → 182,7
while ( it != m_stack.begin() )
{
--it;
QDomElement properties = (*it).namedItem( "style:properties" ).toElement();
QDomElement properties = searchAttribute( *it, m_nodeNames, name );
if ( !properties.namedItem( name ).isNull() )
return properties.namedItem( name );
}
201,3 → 208,59
// Can this ever happen?
return "Standard";
}
 
void StyleStack::fillNodeNameList( QStringList& names, const StyleStack::Mode mode )
{
if ( mode == StyleStack::OODraw2x )
{
names.append("style:graphic-properties");
names.append("style:paragraph-properties");
names.append("style:page-layout-properties");
names.append("style:drawing-page-properties");
names.append("style:text-properties");
}
else
names.append("style:properties");
}
 
QDomElement StyleStack::searchAttribute( const QDomElement& element, const QStringList& names,const QString& name ) const
{
QDomElement node;
QDomNodeList childNodes;
childNodes = element.childNodes();
for ( uint i = 0; i < childNodes.count(); i++ )
{
QDomNode n = childNodes.item(i);
if ( n.isElement() )
{
QDomElement* e = (QDomElement*) (&n);
if ( (names.findIndex(e->nodeName()) >= 0) && e->hasAttribute(name) )
{
node = *e;
break;
}
}
}
return node;
}
 
QDomElement StyleStack::searchAttribute( const QDomElement& element, const QStringList& names, const QString& name, const QString& fullName ) const
{
QDomElement node;
QDomNodeList childNodes;
childNodes = element.childNodes();
for ( uint i = 0; i < childNodes.count(); i++ )
{
QDomNode n = childNodes.item(i);
if ( n.isElement() )
{
QDomElement* e = (QDomElement*) (&n);
if ( (names.findIndex(e->nodeName()) >= 0) && (e->hasAttribute(name) || e->hasAttribute(fullName)) )
{
node = *e;
break;
}
}
}
return node;
}
/branches/Version13x/Scribus/scribus/plugins/fileloader/oodraw/stylestack.h
30,6 → 30,7
#include <qvaluelist.h>
#include <qdom.h>
#include <qvaluestack.h>
#include <qstringlist.h>
 
/**
* This class implements a stack for the different styles of an object.
59,6 → 60,17
StyleStack();
virtual ~StyleStack();
 
enum Mode
{
OODraw1x = 1,
OODraw2x = 2
};
 
/**
* Set attribute analysis mode.
*/
void setMode( const StyleStack::Mode mode );
 
/**
* Clears the complete stack.
*/
88,7 → 100,7
/**
* Check if any of the styles on the stack has an attribute called 'name'.
*/
bool hasAttribute( const QString& name ) const;
bool hasAttribute( const QString& name ) const;
 
/**
* Search for the attribute called 'name', starting on top of the stack,
107,7 → 119,7
* Search for the attribute called 'name', starting on top of the stack,
* and return it.
*/
QString attribute( const QString& name, const QString& detail ) const;
QString attribute( const QString& name, const QString& detail ) const;
 
/**
* Check if any of the styles on the stack has a child node called 'name'.
132,6 → 144,10
QString userStyleName() const;
 
private:
 
// Node names to look for style properties
QStringList m_nodeNames;
 
// For save/restore: stack of "marks". Each mark is an index in m_stack.
QValueStack<int> m_marks;
 
138,6 → 154,15
// We use QValueList instead of QValueStack because we need access to all styles
// not only the top one.
QValueList<QDomElement> m_stack;
 
// Get node name to look for according to property type
void fillNodeNameList( QStringList& names, const StyleStack::Mode mode );
 
// Search a specific attribute amongst childs of an element
QDomElement searchAttribute( const QDomElement& element, const QStringList& names,const QString& name ) const;
 
// Search a specific attribute amongst childs of an element
QDomElement searchAttribute( const QDomElement& element, const QStringList& names, const QString& name, const QString& fullName ) const;
};