Z order of two shapes set to the same value (0)

Hello,

I have a document in which two elements are overlapping (one is displayed on top of the other) - example attached.
After reading the document with aspose words and checking Z-order of the shapes using https://reference.aspose.com/java/words/com.aspose.words/shapebase#zorder , both shapes return Z value = 0.
Is this a bug in Aspose? If one shape is displayed on top of the other I would expect the top one to have higher Z order than the bottom one?
In that case, how can I know which shape is displayed first (is on top)?

test.zip (18.0 KB)

@ELSSAM_elsevier_com

Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. Please change the shape’s position from inline to “in front of text” and set its order “bring to front” or “send to back”. After setting it, please use Shape.ZOrder property to get the desired output.

Thank you for your reply. Unfortunately, It’s not possible in our project to modify the content of word documents.
If we open the same word document several times, the objects are always displayed in the same way. That means that there is an information on their order available somewhere - maybe the order they occur in xml?
So the information is there but it’s not available in Aspose interface. In this case I still consider it a bug in Aspose Words or at least a missing feature.
Is there any chance this problem will be solved in future releases?

@ELSSAM_elsevier_com

Thanks for your inquiry. Yes, your understanding is correct. However, the ZOrder is set for one shape in your document. You can check it by re-saving it to DOCX using MS Word, and unzip the DOCX. You can find the document’s detail in document.xml.

You can also test ShapeBase.ZOrder property by creating simple Word document with some shapes.

However, the ZOrder is set for one shape in your document.

Could you please tell me for which of the shapes from attached example Zorder is set?
The issue is in not being able to get which of the shapes is displayed in front just by using Aspose Words.
Just to be clear, I’m adding a Java code to reproduce the issue:

Node node = document;
        while (node != document.getLastSection().getBody().getLastParagraph().getLastChild()) {
            node = node.nextPreOrder(document);
            if (node != null) {
                int node_type = node.getNodeType();
                if (node_type == NodeType.SHAPE){
                    Shape nodeShape = (Shape) node;
                    System.out.println("Shape type: " + String.valueOf(nodeShape.getShapeType()));
                    System.out.println("Shape Z order: " + String.valueOf(nodeShape.getZOrder()));
                    System.out.println("Shape Wrap Type: " + String.valueOf(nodeShape.getWrapType()));
                }
            }
        }

Running it with previously provided example (test.doc where textbox is displayed in front of the image), produces the following output:
Shape type: 75
Shape Z order: 0
Shape Wrap Type: 0
Shape type: 202
Shape Z order: 0
Shape Wrap Type: 3

Both shapes have Zorder set to 0 therefore there is no way to say which of them is in front by looking at Z ordering.
Wraptype of the image is 0 (INLINE) and of the textbox is 3 (behind OR in front of the text), which means I also cannot use information about wrapType to determine which shape is in front because Aspose does not differentiate between “in front of text” and “behind text” options as it is possible in MS Word (WrapType Enum | Aspose.Words for .NET).
Inside provided example, textbox is set (from MS Word) to be displayed “in front of text”.

Conclusion:
Given the information above, it seems like Aspose Words is not able to determine which of the shapes is displayed in front, or am I missing something here? If that’s a case, this is a valid bug and not “expected behavior”.

@ELSSAM_elsevier_com

Thanks for your inquiry. We have logged this problem in our issue tracking system as WORDSNET-18234. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@ELSSAM_elsevier_com

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue ( WORDSNET-18234) as ‘Not a Bug’.

Aspose.Words returns universal representation of “z-order” among supported formats. Rtf, DOCX, WML and etc store “z-order” value in the format specific way. If you will save the document to DOCX by MS Word, then markup will looking like this:

<mc:AlternateContent>
  <mc:Choice Requires="wps">
    <w:drawing>
      <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251657728" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1">
        .....
        .....
      </wp:anchor>
    </w:drawing>
  </mc:Choice>
  <mc:Fallback>
    <w:pict>
      <v:shape id="文本框 2" o:spid="_x0000_s1026" type="#_x0000_t202" style="z-index:251657728; ..... />
        .....
        .....
      </v:shape>
    </w:pict>
  </mc:Fallback>
</mc:AlternateContent>

Here "relativeHeight=“251657728"” is relative Z-ordering of DrawingML shape. And this value also is set for “fallback” VML shape.

If we save the DOC to DOCX using MS Word and check the document.xml, one shape has z-index:251657728. So, it is the way how Word generates “Z-Order” value while saving to DOCX.

Moreover, “ZOrder” is not applicable for inline shapes. One of shapes is inline, so it is not taken in attention while calculating “ZOrder”. “ZOrder” property equals to default value (zero) for inline shapes.