• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

What influences offsets in text ranges ?

Community Expert ,
Nov 04, 2021 Nov 04, 2021

Copy link to clipboard

Copied

Dear friends,

I know that anchors of any types add 1 to an offset and that element boundaries also add 1. But how about character formats? My experiments show, that they do not count, but in the problem discussed here, they obviously have an influence. I use the following script to check the selection or location:

 

var oDoc = app.ActiveDoc, begin, end, oTR;
oTR = oDoc.TextSelection;
begin = oTR.beg.offset;
end   = oTR.end.offset;
$.writeln (begin, " ", end);

 

and have this situation (you see 3 character formats applied):

object-offsets.png

Can somebody enlighten me?

TOPICS
Scripting

Views

113

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
community guidelines
Contributor ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Hi Klaus,

 

If I dump all text items for a paragraph, hopefully the same as your example, I get the following:

 

0: FTI_PgfBegin 0x1f02711d
0: FTI_LineBegin
0: FTI_String "Without "
8: FTI_CharPropsChange 0x8000000
8: FTI_String "mmm"
11: FTI_CharPropsChange 0x8000000
11: FTI_String " "
12: FTI_CharPropsChange 0x20000000
12: FTI_String "special"
19: FTI_CharPropsChange 0x20000000
19: FTI_String " "
20: FTI_FrameAnchor 0x1704113b
21: FTI_CharPropsChange 0x4000000
21: FTI_String "mmm"
24: FTI_CharPropsChange 0x4000000
24: FTI_String " and normal again."
42: FTI_LineEnd 0x0
42: FTI_PgfEnd 0x1f02711d

 

And if I run your script I get 0 42.

 

This all appears to be as expected?

 

Jon

Votes

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
community guidelines
Community Expert ,
Nov 17, 2021 Nov 17, 2021

Copy link to clipboard

Copied

LATEST

I didn't follow the other thread closely, but one thing to be aware of with text items: If you loop through them from the front of the paragraph and make some changes to the paragraph inside your loop, you may change the offsets of items not yet processed. If I am making changes to the paragraph, I will loop through the text items backwards so that this isn't a problem.

textItems = pgf.GetText (...);
count = textItems.length;
for (i = count - 1; i >= 0; i -= 1) {
    //...
}

Votes

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
community guidelines