Finding character after Formula anchor point

Rheinländer jrheinlaender at gmx.de
Fri Apr 19 23:21:23 PDT 2013


Hi,

I'm trying to find the character after a Formula's anchor. It's anchored
"as character" so I thought this would be easy...

// Create a model cursor at the anchor point
Reference < XTextContent > formula = ...
Reference < XText > xDocumentText = formula->getAnchor()->getText();
Reference < XTextCursor > xModelCursor =
xDocumentText->createTextCursorByRange(formula->getAnchor()->getEnd());

// Get the first paragraph of the cursor's text
Reference< XEnumerationAccess > xEnum(xModelCursor->getText(),
UNO_QUERY_THROW);
Reference< XEnumeration > xParaEnum = xEnum->createEnumeration(); 
if (!xParaEnum->hasMoreElements()) return false; // empty paragraph
Any paragraph = xParaEnum->nextElement();
Reference< XEnumerationAccess > xParaEnumAccess;
paragraph >>= xParaEnumAccess;

// Get the first text portion of the paragraph
Reference< XEnumeration > xPortionsEnum =
xParaEnumAccess->createEnumeration();
if (!xPortionsEnum->hasMoreElements()) return false; // empty text
portion in paragraph
Any portion = xPortionsEnum->nextElement();
 
// Check portion type
Reference < XPropertySet > xPS;
portion >>= xPS;
Any portionType = xPS->getPropertyValue(OU("TextPortionType"));
OUString pTypeStr;
portionType >>= pTypeStr;
 
// Extract string if type is text
if (pTypeStr == OU("Text")) {
  Reference < XTextRange > textrange;
  portion >>= textrange;
 
And the text after the anchor point should be contained in
textrange->getString(). At least that is what I thought. But instead I
get the first text portion of the whole document!

What exactly is returned by getAnchor() of a TextContent?

Thanks for any hints!
    Jan


More information about the LibreOffice mailing list