How to get text area rectangle from shape type, position, size and adjustment values?

Regina Henschel rb.henschel at t-online.de
Wed Jul 27 19:08:33 UTC 2022


Hi Miklos,

Miklos Vajna schrieb am 27.07.2022 um 11:18:
> Hi Regina,
> 
> On Sun, Jul 24, 2022 at 11:59:28PM +0200, Regina Henschel <rb.henschel at t-online.de> wrote:
>> I know that the calculation of moTextOffFoo values in transform2dcontext is
>> correct in principle. But I am very unhappy with calculating the position
>> and size of the required text area rectangle by hand using the preset
>> geometry. I have now done this for the shape types that I know are in the
>> preset SmartArts. But the user can also exchange these shapes with others in
>> the UI of MS Office. So the calculation of the text area rectangle would
>> have to be done for all preset shapes. That's why I'm looking for another
>> way.
> 
> Briefly reading presetShapeDefinitions.xml from the OOXML spec, the
> calculation of the text rectangle seems to be part of the preset, so
> it's not something you can calculate in general.

The text rectangle often uses guide values, indeed.
> 
>> At that point I have the type of the shape and know position, size and
>> adjustment values. If I had a ready CustomShape, I could get the needed text
>> area rectangle with the method getTextBounds(). But in
>> transform2dcontext.cxx there is no CustomShape. Or do I miss something?

In the meantime I have tried to get a CustomShape from an XShape. But 
that gives a nullptr.

>>
>> Is there any way to make such a shape temporarily so that you can use
>> getTextBounds()? Or maybe someone has another idea how to get the text area
>> rectangle from type, position, size and adjustment values?
> 
> Other preset data is generated from the spec, the generated result is at
> oox/source/drawingml/customshapes/oox-drawingml-cs-presets. Would it be
> possible to include the text rectangle information in that file as well?

The text rectangle information is already there. It is in "Path". "Path" 
contains "Coordinates", "Segments" and "TextFrames".

> 
> Failing that, if we have this information in svx/ for custom shape
> instances, then seprating this functionality into a function that you
> can call from oox/ sounds reasonable. I just fear that OOXML has much
> more preset types compared to the old binary formats, and perhaps svx/
> preset data represents what was the feature set of binary formats.

The calculations in svx are made by EnhancedCustomShape2d. But that 
needs in its ctor a SdrObjCustomShape. The calculations in 
EnhancedCustomShape2d works for OOXML-shapes too. It takes care of 
svg:viewBox="0 0 0 0" and subview, which is used by OOXML-shapes.

The calculations need "Segments" and "Equations", but the 
oox::drawingml::Shape has at that time only mnShapePresetType in its 
mpCustomShapePropertiesPtr.

I think, that separating the functionality is not possible, because the 
ctor of EnhancedCustomShape2d makes heavy use of the SdrObjCustomShape.
So if I get "Segments", "Equations" and "TextFrames" from 
oox-drawingml-cs-presets somehow, I would need to rewrite the functions 
using EnhancedCustomShape2d as kind of template.

Considering the effort involved, it probably makes more sense to wait 
and see if users complain. The predefined diagrams work in Impress. And 
the time is surely better spent to find out why the shapes of a diagram 
are missing in Calc and why size and position are wrong in Writer.

I was only hoping that someone knows something that is unknown to me as 
an amateur developer.

Kind regards,
Regina





More information about the LibreOffice mailing list