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
Context
- Finding character after Formula anchor point · Rheinländer
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.