Skip to main content
GameDev.net gamedev.net
🔒 Locked

Text formatting data structure/algo?

Started by Z01 May 29, 2003 at 9:08 PM 3 replies 850+ views
Original Post
Z01
Z01
I need to write a high quality multiline editable text box in OpenGL. The textbox must be resizable. It will only have one font. I don't expect the user to type more than 4k characters in it. It should be easy to support word wrap. I need some kind of data structure & algorithm that is good for this kind of thing. The big problems with the easier approaches: *can't use a simple block of memory because inserting directly in that block requires you to move everything down in the block *can't use an array of char*'s that stores each line because when the user resizes the text box a lot this will fragment memory badly, plus all the new's and delete's are bad for framerate One of the big problems is that I need an easy way to keep track of where the line beginnings are so I can render each line, rather than traversing the text each frame and determining which lines are visible, where the line breaks are and what the scrollbars should be set to. Anyone have any ideas or references to algorithms/data structures for such a problem? I spend a bit of time looking at how some of the linux free source word processors handle it, but it seems kind of overkill. I'm thinking along the line of splitting the text into a linked list of hunks that are like 24 characters long each and having another data structure like a deque to keep track of the line beginnings. Edit - minor stuff [edited by - Z01 on May 29, 2003 10:12:16 PM]
antareus
antareus
Look into a rope...google on "sgi rope."
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Z01
Z01
Thanks for the replies, I think I''ve pretty much decided which way I''m going to go.

Btw, after a great deal of searching last night I found an overview of methods used in text editors:

http://www.cs.unm.edu/~crowley/papers/sds/sds.html

The one I discribed in my post is the "Fixed Sized Buffer Method" and the one used by the free-source word processors was "The Piece Table Method".

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.