This is related to bug https://bugs.kde.org/show_bug.cgi?id=274905 or to be 
more exact to the objects displayed at the top of the first page which should 
not be displayed.

The problem:
The anchored objects are anchored to a header/footer which is never created 
and displayed cause no page with such a pageStyle exists in the document. So 
we end with displayed shapes that are anchored to a textshape that isn't 
visible.

A possible solution:
That's not so easy cause there are quit a lot different ways to address the 
problem. Attached is the most simple solution I was able to come up with. I 
like that solution cause a) it's at one place and not spread into different 
files and b) it's short, easy to read+understand. But then I am not 100% sure 
if there are cases where we actually end with an anchored shape that should be 
displayed but is never proper resized. My tests didn't show any such cases.

Alternate solutions:
1) hide them in Words' rootAreaProvider::doPostLayout method. I don't like 
that cause imho it's a generic problem we should imho better solve in the 
textlayout-lib.
2) Check if the passes paragraphRect in 
KoTextDocumentLayout::setAnchoringParagraphRect isEmpty and just always hide 
shapes if that's the case. This would assume that the paragraphRect never can 
be empty for valid areas. I don't know if that assumption is true.
3) ?
diff --git a/libs/kotext/KoTextAnchor.cpp b/libs/kotext/KoTextAnchor.cpp
index 4fbb0e4..24cc809 100644
--- a/libs/kotext/KoTextAnchor.cpp
+++ b/libs/kotext/KoTextAnchor.cpp
@@ -101,6 +101,7 @@ KoTextAnchor::KoTextAnchor(KoShape *shape)
 {
     Q_D(KoTextAnchor);
     shape->setAnchored(true);
+    shape->setVisible(false);
     d->fakeAsChar = false;
 }
 
@@ -193,6 +194,13 @@ void KoTextAnchor::resize(const QTextDocument *document, QTextInlineObject objec
     Q_UNUSED(pd);
     Q_D(KoTextAnchor);
 
+    if (!d->shape->isVisible()) {
+        // Per default the shape this anchor presents is hidden and we only make it visible once an explicit resize-request
+        // was made. This prevents shapes that are anchored at e.g. hidden textboxes to not become visible as long as they
+        // are not asked to resize.
+        d->shape->setVisible(true);
+    }
+
     // important detail; top of anchored shape is at the baseline.
     QFontMetricsF fm(format.font(), pd);
     if (d->behaveAsCharacter == true) {
_______________________________________________
calligra-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/calligra-devel

Reply via email to