Microstation CE: Get actual side of Text element

We're working on a huge porting from 100+ MA applications from V8i to Connect Edition.
One of the problems we're encountering regards the old mdlText_extract API.
In order to determine the size of an existing text element, we so far use the following code:

MSElement* pElement = ...;

char     text[256];
TextSize tileSize;
TextSize textSize;
mdlText_extract(NULL, NULL, NULL, NULL, text, NULL, NULL, NULL, &tileSize, &textSize, pElement);
printf("Text '%s' has tileSize (%.1lf, %.1lf) and textSize (%.1lf, %.1lf)\n",
       text, tileSize.width, tileSize.height, textSize.width, textSize.height);

It has the following output:

Text 'TTF3' has tileSize (525.0, 1200.0) and textSize (1901.5, 1200.0)
Text 'ODF10' has tileSize (420.0, 1200.0) and textSize (1785.7, 1200.0)

I tried the code as suggested by the link:

https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/112563/connect-c-textblock-code-to-replace-mdltext_extract

ElementHandle eh(pElement, ACTIVEMODEL);
TextBlockPtr  textBlock = TextHandlerBase::GetFirstTextPartValue(eh);
DPoint2d      fontSize = textBlock->GetRunPropertiesForAdd().GetFontSize();
DRange3d      range = textBlock->GetNominalRange();
printf("FontSize of %ls: (%.1lf, %.1lf)\n", textBlock->ToString().GetWCharCP(), fontSize.x, fontSize.y);
printf("low/high: (%.1lf, %.1lf) / (%.1lf, %.1lf)\n", range.low.x, range.low.y, range.high.x, range.high.y);
printf("doc.width: %.1lf\n", textBlock->GetProperties().GetDocumentWidth());

But this gives me the output:

FontSize of TTF3: (0.0, 12.0)
low/high: (0.0, -12.0) / (0.0, 0.0)
doc.width: 0.0
FontSize of ODF10: (0.0, 12.0)
low/high: (0.0, -12.0) / (0.0, 0.0)
doc.width: 0.0

In other words, I get the height of the text (expressed as the fontsize) but not the width.

Any idea how to get the actual width and height of an existing text element?
I didn't find anything useful within the TextBlock class.

Thanks,

Robert Kock

Parents
  • Determine the size of an existing text element

    While snuggled up amid autumn blankets, I was browsing the API help — it's a great way to combat insomnia — when I came across the TextString class: Used to draw a single-line collection of like-formatted characters.

    It has some methods that may be useful to you...

    • GetExtents Gets the bounds of this entire instance in local coordinates
    • GetWidth Gets the width of the extents
    • GetHeight Gets the height of the extents

    And several more.  It's not clear how one constructs a TextString.  It looks like you have to use a static Create() method, but I can find no examples.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Determine the size of an existing text element

    While snuggled up amid autumn blankets, I was browsing the API help — it's a great way to combat insomnia — when I came across the TextString class: Used to draw a single-line collection of like-formatted characters.

    It has some methods that may be useful to you...

    • GetExtents Gets the bounds of this entire instance in local coordinates
    • GetWidth Gets the width of the extents
    • GetHeight Gets the height of the extents

    And several more.  It's not clear how one constructs a TextString.  It looks like you have to use a static Create() method, but I can find no examples.

     
    Regards, Jon Summers
    LA Solutions

Children