Skip to main content
Ch__Efstathios
Inspiring
April 12, 2016
Answered

How can I get the current paragraph?

  • April 12, 2016
  • 1 reply
  • 1240 views

I want to get the current paragraph where the insertion point is.

How can I do this in FDK?

This topic has been closed for replies.
Correct answer Russ Ward

Ch,

I can answer some of these questions but if you decided that this thread is answered, please give the credit to Mike.

Regarding the check for an FO_Pgf object, you should not need that. I think there is some obscure case where F_ApiGetTextRange() gives you an object that is not a paragraph... I forget exactly but I think it has to do with a text line graphic object or something like that. I could be wrong. In any case, if you have a normal text flow with an insertion point, you will get a paragraph object.

This line will abort the operation if any text is selected. Do you really want that?

if (insertionPoint.beg.objId != insertionPoint.end.objId) 



This line will abort the operation if multiple paragraphs are selected. Do you really want that? Without this check, you would still get the text of the first selected paragraph.

if (insertionPoint.beg.offset != insertionPoint.end.offset)


Otherwise, the code looks OK to me, at least as far as the FDK calls. Are you having problems with it?


Russ

1 reply

Participating Frequently
April 13, 2016

Read the section Getting and setting the insertion point or text selection in the FDK Programmer’s Guide.

The code below is from memory, but should give you the idea of what is required. You should add error checking, and test it.

F_ObjHandleT activeDoc;

F_TextRangeT textRange;

activeDoc = F_ApiGetId(0, FV_SessionId, FP_ActiveDoc);

textRange = F_ApiGetTextRange(FV_SessionId, activeDoc, FP_TextSelection);

/*

* textRange.beg.objId is the ID of the paragraph or text line at the start of the current selection

* textRange.end.objId is the ID of the paragraph or text line at the end of the current selection

*/

if (F_ApiGetObjectType(activeDoc, textRange.beg.objId) == FO_Pgf) {

     // we have a paragraph

}
else {

     // we have a text line

}

Ch__Efstathios
Inspiring
April 13, 2016

I have done the following solution:

Do you believe that we can do it better or fix any bug in it?

bool FMClient::GetCurrentParagraphWithInsertionPoint(ParagraphWithPointT & paragraphWithPoint)

    {

        F_ObjHandleT docId = F_ApiGetId(FV_SessionId, FV_SessionId, FP_ActiveDoc);

        if (!docId)

        {

            return false;

        }

        F_TextRangeT insertionPoint = F_ApiGetTextRange(FV_SessionId, docId, FP_TextSelection);

        if (! insertionPoint.beg.objId)

        {

            return false;

        }

        if (insertionPoint.beg.objId != insertionPoint.end.objId)

        {

            return false;

        }

        if (insertionPoint.beg.offset != insertionPoint.end.offset)

        {

            return false;

        }

        CExpandingString paragraph;

        F_TextItemsT textItems = F_ApiGetText(docId, insertionPoint.beg.objId, FTI_String);

        for (UIntT i = 0; i < textItems.len; i++)

        {

            paragraph.Append(textItems.val.u.sdata);

        }

        F_ApiDeallocateTextItems(&textItems);

        paragraphWithPoint.paragraph = paragraph.TakeContents();

        paragraphWithPoint.point = insertionPoint.beg.offset;

        return true;

    }

I get from the active document the selection point (in case there is no selection point or the selection point is between different objects or the begin and end offsets are different we return false).

After that, I get all text items with string from the object of the selection and append all text to a dynamic allocated string.

Lastly, I return the paragraph as concatenated dynamic string and also the point where the cursor where inside this paragraph.

Do you believe we can do it better?

Also if you could help me about this problem it would be great: https://forums.adobe.com/thread/2138451

Ch__Efstathios
Inspiring
April 13, 2016

Currently in my solution I do not use the FO_Pgf. Is this a problem?