File indexing completed on 2024-05-12 16:37:11
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2005 David Faure <faure@kde.org> 0003 * Copyright (C) 2007-2010 Thomas Zander <zander@kde.org> 0004 * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org> 0005 * Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com> 0006 * Copyright (C) 2007-2009 Thorsten Zachmann <zachmann@kde.org> 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #include "KWOdfSharedLoadingData.h" 0025 #include "KWOdfLoader.h" 0026 #include "KWDocument.h" 0027 #include "frames/KWTextFrameSet.h" 0028 #include "frames/KWCopyShape.h" 0029 0030 #include <KoTextShapeData.h> 0031 #include <KoOdfLoadingContext.h> 0032 #include <KoShapeLoadingContext.h> 0033 #include <KoXmlNS.h> 0034 #include <KoUnit.h> 0035 0036 #include <QTextCursor> 0037 0038 KWOdfSharedLoadingData::KWOdfSharedLoadingData(KWOdfLoader *loader) 0039 : KoTextSharedLoadingData() 0040 , m_loader(loader) 0041 { 0042 KoShapeLoadingContext::addAdditionalAttributeData( 0043 KoShapeLoadingContext::AdditionalAttributeData( 0044 KoXmlNS::text, "anchor-type", "text:anchor-type")); 0045 KoShapeLoadingContext::addAdditionalAttributeData( 0046 KoShapeLoadingContext::AdditionalAttributeData( 0047 KoXmlNS::text, "anchor-page-number", "text:anchor-page-number")); 0048 } 0049 0050 void KWOdfSharedLoadingData::shapeInserted(KoShape *shape, const KoXmlElement &element, KoShapeLoadingContext &context) 0051 { 0052 shape->removeAdditionalAttribute("text:anchor-type"); 0053 const KoXmlElement *style = 0; 0054 if (element.hasAttributeNS(KoXmlNS::draw, "style-name")) { 0055 style = context.odfLoadingContext().stylesReader().findStyle( 0056 element.attributeNS(KoXmlNS::draw, "style-name"), "graphic", 0057 context.odfLoadingContext().useStylesAutoStyles()); 0058 } 0059 0060 if (shape->shapeId() == "TextShape_SHAPEID") { 0061 KoXmlElement textBox(KoXml::namedItemNS(element, KoXmlNS::draw, "text-box")); 0062 if (!textBox.isNull()) { 0063 QString nextName = textBox.attributeNS(KoXmlNS::draw, "chain-next-name"); 0064 m_nextShapeNames.insert(shape, nextName); 0065 m_shapesToProcess.append(shape); 0066 0067 if (textBox.hasAttributeNS(KoXmlNS::fo, "min-height")) { 0068 shape->setMinimumHeight(KoUnit::parseValue(textBox.attributeNS(KoXmlNS::fo, "min-height"))); 0069 QSizeF newSize = shape->size(); 0070 if (newSize.height() < shape->minimumHeight()) { 0071 newSize.setHeight(shape->minimumHeight()); 0072 shape->setSize(newSize); 0073 } 0074 } 0075 KWTextFrameSet *fs = new KWTextFrameSet(m_loader->document()); 0076 fs->setName(m_loader->document()->uniqueFrameSetName(shape->name())); 0077 KWFrame *frame = new KWFrame(shape, fs); 0078 if (style) 0079 fillFrameProperties(frame, *style); 0080 } 0081 } else { 0082 KWFrameSet *fs = new KWFrameSet(); 0083 fs->setName(m_loader->document()->uniqueFrameSetName(shape->name())); 0084 KWFrame *frame = new KWFrame(shape, fs); 0085 if (style) 0086 fillFrameProperties(frame, *style); 0087 m_loader->document()->addFrameSet(fs); 0088 } 0089 } 0090 0091 bool KWOdfSharedLoadingData::fillFrameProperties(KWFrame *frame, const KoXmlElement &style) 0092 { 0093 KoXmlElement properties(KoXml::namedItemNS(style, KoXmlNS::style, "graphic-properties")); 0094 if (properties.isNull()) 0095 return frame; 0096 0097 return true; 0098 } 0099 0100 void KWOdfSharedLoadingData::connectFlowingTextShapes() 0101 { 0102 while (!m_shapesToProcess.isEmpty()) { 0103 KoShape *shape = m_shapesToProcess.takeFirst(); 0104 KWTextFrameSet *fs = dynamic_cast<KWTextFrameSet *>(KWFrameSet::from(shape)); 0105 m_loader->document()->addFrameSet(fs); 0106 0107 while (shape) { 0108 QString nextName = m_nextShapeNames[shape]; 0109 shape = 0; 0110 0111 foreach (KoShape *s, m_shapesToProcess) { 0112 if (s->name() == nextName) { 0113 shape = s; 0114 m_shapesToProcess.removeAll(shape); 0115 new KWFrame(shape, fs); 0116 break; 0117 } 0118 } 0119 } 0120 } 0121 }