0

I have an NSLayoutManager, two NSTextContainers, and an NSTextStorage object.

I add strings one by one to the textStorage object until the first textContainer is full, then I use the amount of text added to that textContainer draw a page in my book app.

99% of the time the isAtEnd flag in didCompleteLayoutForTextContainer will tell me when the first text container got full.

However, in a rare case, if I add a string to the textStorage it will actually remove text from the first text container!

For example, when the first text container has this string in it (and is almost full):

 \n\n\n\n\n\nMexico  \n\nBook Covers from Germany  \n\n \n\n \n\n Book Covers from Germany Special Edition  \n\nBook Covers from Denmark  Sweden \n\nBook Covers from Japan \n\nBook Covers From Finland  \n\nBook Covers From Greece

if I add this string to the textStorage:

Spain  \n\nBook Covers From Iceland  \n\nBook Covers From Netherlands  \n\nBook Covers from Norway

the layoutManager will move the word "Greece" from the first textContainer and move it to the second textContainer.

I would have rather had the layoutManager tell me that the first textContainer was full before I attempted to add a new string and have it do this unexpected behavior.

Can anyone tell me why this is happening? or tell me how I can tell when this will happen again so that I can figure out when the first textContainer is really full?

Thanks!

user714171
  • 363
  • 1
  • 3
  • 12

1 Answers1

0

May be create subclass to NSTypesetter and override the method layoutParagraphAtPoint() . This method returns next character that will be at the beginning of nexy paragraph, or may be at end of textContainer - I am not sure.

ion
  • 819
  • 10
  • 8