Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:52:39+00:00 2026-05-31T18:52:39+00:00

For laying out a long string into pages, I can use CTFramesetterCreateFrame to create

  • 0

For laying out a long string into pages, I can use CTFramesetterCreateFrame to create CTFrameRef and then move forward the start index in the string for creating next CTFrameRef. This is easy since the start index is moving forward, and the Core Text APIs support this kind of layout natively.

Now I am stuck in a situation that I want to turn to the previous page.

For example, The length of the long string is 1000, now the start index of the current page(or CTFrameRef) is 500, and I want to turn to the previous page, how do I know what index to start? I can’t cache all the indices for each page or calculate from the start of the string, cause the string can be very very long that won’t fit in memory(I will need to read the string from a file block by block). I have scanned the CT* APIs, there’s no such API that supports laying out text backwards.

Any ideas on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:52:41+00:00Added an answer on May 31, 2026 at 6:52 pm

    The reason that there’s no API for this is that there’s no efficient context-independent way of doing this other than trying to typeset the whole page by trial and error to find the best start index, which as you can imagine would be an intensive operation.

    If each page of your text has a set width, and is just a rectangular CTFrame, this how you can do this:

    1. “Estimate” the string range for the previous page (e.g. assume it has the the same length as the current page.
    2. Overshoot that estimate by a reasonable large factor (e.g. 1.5/2x the length) up to a reasonable. Choose the the overshot range so it starts at the start of a paragraph.
    3. Create a frame with that range as you normally would, but make the frame’s much larger than usual.
    4. Get line information from the frame and from the end start counting the height by going back line by line.
    5. You can find the actual previous page starts from the index of the first line that fits, and use it to create the actual CTFrame.

    Although this should work, I still recommend you try to find a way of avoiding this if possible. Notice that this breaks down as soon as you have a more complex pagination algorithm, and even in this case it uses 1.5/2x memory. Here are a few suggestions on how you can do this:

    1. Cache the indexes (at least up to the current position.) Each page can probably hold ~1000 characters, so your cache size will be 0.1% the size of the whole text, and you have to do it at least once for the first time you’re showing the text. You can make the cache even smaller by storing indexes for every n page.

    2. If it applies, break your string into logical substrings, for example based on page break or section breaks, Then typeset that each substring as a whole for a range of pages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After laying out some ideas in Processing, I've decided to move my MIDI project
I want to avoid laying out a view programmatically. I want to only use
I was looking into laying out some instructions on top of one of my
When laying out a WinForm in Visual Studio you get the ability to resize
After laying out my schema diagram in SQL Server (both 2000 and 2005), I
In laying out a page with absolute positioning, I realized that it rendered differently
Does anyone have any tricks for quickly laying out the asp.net html markup for
I have a question about laying out some swing components. Say, I have a
Does anyone know of a good tool for laying out class diagrams and the
I have been debating using css with div's and laying out elements, and really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.