Highlighted

textFrameUtils.GetTextInFrame() only gets visible text

Explorer ,
Oct 31, 2020

Copy link to clipboard

Copied

Hello,

I am using textFrameUtils.GetTextInFrame() to read the text in a CT_TEXT_FRAME object. This works well, except that, if there is text overflow, then the function only returns the text that is visible. I could not find another funtion or a parameter that would get the full text contained in a textbox.

Very best regards,

Olivier

Hi,

 

I was able to get the full text in a box by making a different version of the function GetTextFrameTextRange() where the line 

result = InDesign::TextRange(textModel, startIndex, span, RangeData::kLeanForward);

is replaced by 

charactersInPrimaryStoryThread--;
result = InDesign::TextRange(textModel, startIndex, charactersInPrimaryStoryThread, RangeData::kLeanForward);

and then making a different version of the function GetTextFrameTextRange() where the line

*outStr = this->GetWideStringFromTextFrame(mcf);

is replaced by

InDesign::TextRange tr = this->GetTextFrameFullTextIncludingOverflowRange(mcf);
*outStr = GetWideStringFromTextRange(tr);

This is quite a pain just to get the text in the box, but it works.

Very best regards,

Olivier

 

 

TOPICS
SDK

Views

114

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

textFrameUtils.GetTextInFrame() only gets visible text

Explorer ,
Oct 31, 2020

Copy link to clipboard

Copied

Hello,

I am using textFrameUtils.GetTextInFrame() to read the text in a CT_TEXT_FRAME object. This works well, except that, if there is text overflow, then the function only returns the text that is visible. I could not find another funtion or a parameter that would get the full text contained in a textbox.

Very best regards,

Olivier

Hi,

 

I was able to get the full text in a box by making a different version of the function GetTextFrameTextRange() where the line 

result = InDesign::TextRange(textModel, startIndex, span, RangeData::kLeanForward);

is replaced by 

charactersInPrimaryStoryThread--;
result = InDesign::TextRange(textModel, startIndex, charactersInPrimaryStoryThread, RangeData::kLeanForward);

and then making a different version of the function GetTextFrameTextRange() where the line

*outStr = this->GetWideStringFromTextFrame(mcf);

is replaced by

InDesign::TextRange tr = this->GetTextFrameFullTextIncludingOverflowRange(mcf);
*outStr = GetWideStringFromTextRange(tr);

This is quite a pain just to get the text in the box, but it works.

Very best regards,

Olivier

 

 

TOPICS
SDK

Views

115

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 31, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

HI,

 

Are you able to upload a code snippet where you use this method? or possible a small sample that shows the problem?

 

Regards

 

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2020 0
Explorer ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi Malcolm,

I just have a reference to a UIDRef, aBoxID, and using it I call:

WideString outStr;
ErrorCode outError = textFrameUtils.GetTextInFrame(aBoxID, &outStr);

The above works fine, as long as there is no text overflow, but if there is text overflow, than it only returns the portion of the text that is visible (ie. the text that fits in the box).

Very best regards,

Olivier

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi Olivier,

I'm not into SDK programming, but I can see a similar problem when doing this with ExtendScript scripting.

 

 

textFrame.texts[0]

 

 

will get you all the text contained by the text frame. Not the text that overflows.

At least with ExtendScript, I cannot speak for SDK programming, you have to calculate the text that is in overflow, if there is any overflow.

 

One could do this like that ( working example is using a user selected text frame that shows some overflow ) :

 

 

var textFrame = app.selection[0];

var lastInsertionPointInFrame = textFrame.texts[0].insertionPoints[-1];
var lastInsertionPointInStory = textFrame.texts[0].parentStory.insertionPoints[-1];

var overflowText = textFrame.texts[0].parent.insertionPoints.itemByRange
( 
	lastInsertionPointInFrame , 
	lastInsertionPointInStory
);

// Do something with the overflow text.
// E.g. color it "Magenta"
overflowText.fillColor = app.documents[0].colors.itemByName("Magenta");

 

 

 

You may find a similar way with SDK programming.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2020 0
Explorer ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi Uwe,

Thnak you very much for our codes samples.

I have found similar functions in the SDK and will try to figure it out.

I am surprised, however, that there is no simple function to get the text in a box.

In the Quark SDK, it's the opposite, finding the visible text is actually hard work.

Very best regards,

Olivier

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2020 0
Adobe Community Professional ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi,

 

What about this -

ErrorCode SnpManipulateTextFrame::InspectTextInFrame(const UIDRef& graphicFrameUIDRef)
{
	ErrorCode status = kFailure;
	do {
		InterfacePtr<IMultiColumnTextFrame> mcf(graphicFrameUIDRef.GetDataBase(), this->GetTextContentUID(graphicFrameUIDRef), UseDefaultIID());
		ASSERT(mcf);
		if (!mcf) {
			break;
		}
		WideString wstr = this->GetWideStringFromTextFrame(mcf);
		PMString str(wstr);
		SNIPLOG("%s", str.GetPlatformString().c_str());
		status = kSuccess;
	} while(false);
	return status;
}

 

Taken from the SnippetRunner Project, SnpManipulateTextFrame.cpp - If you build and run the Snippet Runner project you should be able to see if this helps.

 

Regards

 

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2020 0
Explorer ,
Nov 02, 2020

Copy link to clipboard

Copied

Hi Malcolm,

Thank you very much for your suggestion.

Our implementation of textFrameUtils.GetTextInFrame() uses the exact same code you suggest, as we probably copied it from the same sample project. But unfortunately, it only returns the text that is visible, not any text that has overflowed.

Very best regards,

Olivier

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2020 0
Adobe Community Professional ,
Nov 03, 2020

Copy link to clipboard

Copied

Hi,

 

Many thanks for responding Olivier, I will take a look around using that snippet as a starting point to see if I can solve the problem.

 

Regards

 

Malcolm

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 03, 2020 0
Explorer ,
Nov 07, 2020

Copy link to clipboard

Copied

Hi,

 

I was able to get the full text in a box by making a different version of the function GetTextFrameTextRange() where the line 

result = InDesign::TextRange(textModel, startIndex, span, RangeData::kLeanForward);

is replaced by 

charactersInPrimaryStoryThread--;
result = InDesign::TextRange(textModel, startIndex, charactersInPrimaryStoryThread, RangeData::kLeanForward);

and then making a different version of the function GetTextFrameTextRange() where the line

*outStr = this->GetWideStringFromTextFrame(mcf);

is replaced by

InDesign::TextRange tr = this->GetTextFrameFullTextIncludingOverflowRange(mcf);
*outStr = GetWideStringFromTextRange(tr);

This is quite a pain just to get the text in the box, but it works.

Very best regards,

Olivier

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2020 0
Explorer ,
Nov 08, 2020

Copy link to clipboard

Copied

ERRATUM: the second occurrence of "GetTextFrameTextRange()" in my post above should in fact be "GetTextInFrame()".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 08, 2020 0