[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kword/part/frames
From:       Thomas Zander <zander () kde ! org>
Date:       2010-03-10 14:26:40
Message-ID: 1268231200.452184.360.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1101667 by zander:

Fixes crash on loading doc with anchored image

BUG:212336
In the constructor we assumed the presence of a parent shape that in some
cases is wrong. The parent shape is set in the check() method at a later time
so take that into account.

 M  +59 -46    KWAnchorStrategy.cpp  
 M  +3 -1      KWAnchorStrategy.h  


--- trunk/koffice/kword/part/frames/KWAnchorStrategy.cpp #1101666:1101667
@@ -36,44 +36,7 @@
         m_lastVerticalAnchorAlignment(KoTextAnchor::TopOfFrame),
         m_lastHorizontalAnchorAlignment(KoTextAnchor::Left)
 {
-    // figure out until what cursor position we need to layout to get all the info \
                we need
-    switch (m_anchor->horizontalAlignment()) {
-    case KoTextAnchor::ClosestToBinding:
-    case KoTextAnchor::Left:
-    case KoTextAnchor::FurtherFromBinding:
-    case KoTextAnchor::Right:
-    case KoTextAnchor::Center: {
-        KoTextShapeData *data = \
                qobject_cast<KoTextShapeData*>(anchor->shape()->parent()->userData());
                
-        Q_ASSERT(data);
-        m_knowledgePoint = data->position();
-        break;
-    }
-    case KoTextAnchor::HorizontalOffset:
-        m_knowledgePoint = anchor->positionInDocument();
-    }
-    switch (m_anchor->verticalAlignment()) {
-    case KoTextAnchor::TopOfParagraph:
-        m_knowledgePoint = qMax(m_knowledgePoint,
-                                \
                anchor->document()->findBlock(anchor->positionInDocument()).position() \
                + 1);
-        break;
-    case KoTextAnchor::VerticalOffset:
-    case KoTextAnchor::AboveCurrentLine:
-    case KoTextAnchor::BelowCurrentLine:
-        m_knowledgePoint = qMax(m_knowledgePoint, anchor->positionInDocument());
-        break;
-    case KoTextAnchor::TopOfFrame:
-    case KoTextAnchor::BottomOfFrame: {
-        KoTextShapeData *data = \
                qobject_cast<KoTextShapeData*>(anchor->shape()->parent()->userData());
                
-        Q_ASSERT(data);
-        m_knowledgePoint = qMax(m_knowledgePoint, data->position() + 1);
-        break;
-    }
-    case KoTextAnchor::BottomOfParagraph: {
-        QTextBlock block = \
                anchor->document()->findBlock(anchor->positionInDocument());
-        m_knowledgePoint = qMax(m_knowledgePoint, block.position() + block.length() \
                - 2);
-        break;
-    }
-    }
+    calculateKnowledgePoint();
 }
 
 KWAnchorStrategy::~KWAnchorStrategy()
@@ -82,6 +45,18 @@
 
 bool KWAnchorStrategy::checkState(KoTextDocumentLayout::LayoutState *state)
 {
+    if (m_anchor->shape()->parent() == 0) { // it should be parented to our current \
shape +        KoShapeContainer *sc = dynamic_cast<KoShapeContainer*>(state->shape);
+        if (sc == 0) {
+            kWarning(32002) << "Failed to attach the anchored shape to a text \
shape..."; +            return false;
+        }
+        sc->addChild(m_anchor->shape());
+        calculateKnowledgePoint();
+    }
+    if (m_knowledgePoint < 0)
+        return false;
+
     if (m_lastknownPosInDoc != m_anchor->positionInDocument()
             || m_lastOffset != m_anchor->offset()
             || m_lastVerticalAnchorAlignment != m_anchor->verticalAlignment()
@@ -106,14 +81,6 @@
 
 // TODO rewrite the below to account for rotation etc.
     QRectF boundingRect = m_anchor->shape()->boundingRect();
-    if (m_anchor->shape()->parent() == 0) { // it should be parented to our current \
                shape
-        KoShapeContainer *sc = dynamic_cast<KoShapeContainer*>(state->shape);
-        if (sc == 0) {
-            kWarning(32002) << "Failed to attach the anchored shape to a text \
                shape...";
-            return false;
-        }
-        sc->addChild(m_anchor->shape());
-    }
     QRectF containerBoundingRect = m_anchor->shape()->parent()->boundingRect();
     QPointF newPosition;
     switch (m_anchor->horizontalAlignment()) {
@@ -246,3 +213,49 @@
     return m_anchor->shape();
 }
 
+void KWAnchorStrategy::calculateKnowledgePoint()
+{
+    m_knowledgePoint = -1;
+    // figure out until what cursor position we need to layout to get all the info \
we need +    switch (m_anchor->horizontalAlignment()) {
+    case KoTextAnchor::ClosestToBinding:
+    case KoTextAnchor::Left:
+    case KoTextAnchor::FurtherFromBinding:
+    case KoTextAnchor::Right:
+    case KoTextAnchor::Center: {
+        if (m_anchor->shape()->parent() == 0) // not enough info yet.
+            return;
+        KoTextShapeData *data = \
qobject_cast<KoTextShapeData*>(m_anchor->shape()->parent()->userData()); +        \
Q_ASSERT(data); +        m_knowledgePoint = data->position();
+        break;
+    }
+    case KoTextAnchor::HorizontalOffset:
+        m_knowledgePoint = m_anchor->positionInDocument();
+    }
+    switch (m_anchor->verticalAlignment()) {
+    case KoTextAnchor::TopOfParagraph:
+        m_knowledgePoint = qMax(m_knowledgePoint,
+                                \
m_anchor->document()->findBlock(m_anchor->positionInDocument()).position() + 1); +    \
break; +    case KoTextAnchor::VerticalOffset:
+    case KoTextAnchor::AboveCurrentLine:
+    case KoTextAnchor::BelowCurrentLine:
+        m_knowledgePoint = qMax(m_knowledgePoint, m_anchor->positionInDocument());
+        break;
+    case KoTextAnchor::TopOfFrame:
+    case KoTextAnchor::BottomOfFrame: {
+        if (m_anchor->shape()->parent() == 0) // not enough info yet.
+            return;
+        KoTextShapeData *data = \
qobject_cast<KoTextShapeData*>(m_anchor->shape()->parent()->userData()); +        \
Q_ASSERT(data); +        m_knowledgePoint = qMax(m_knowledgePoint, data->position() + \
1); +        break;
+    }
+    case KoTextAnchor::BottomOfParagraph: {
+        QTextBlock block = \
m_anchor->document()->findBlock(m_anchor->positionInDocument()); +        \
m_knowledgePoint = qMax(m_knowledgePoint, block.position() + block.length() - 2); +   \
break; +    }
+    }
+}
--- trunk/koffice/kword/part/frames/KWAnchorStrategy.h #1101666:1101667
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
- * Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2007, 2009, 2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -74,6 +74,8 @@
     }
 
 private:
+    void calculateKnowledgePoint();
+
     KoTextAnchor *const m_anchor;
     int m_knowledgePoint; // the cursor position at which the layout process has \
gathered enough info to do our work  bool m_finished;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic