Solipsism Gradient

Rainer Brockerhoff’s blog

Browsing Posts published by Rainer Brockerhoff

Re: Text editing…

No comments

Yet Another interim progress report on XRay II.

Turns out some of my problems with the hex editor were due to overuse of the idea to have my scrollview’s delegate do everything (including standing in for the First Responder). So I changed back to a simpler model. I now have a single view inside my scroll view as the delegate, and it stays in place – it just checks the scrollbar’s status to decide what to draw.

As this subview is declared as NSView<NSTextInput> – meaning it’s a plain subclass of NSView that obeys the NSTextInput protocol – it’s also a descendant of NSResponder, and now stuff started “just working”. Seems obvious in retrospect, of course. There’s lots of details about implementing that protocol, but it’s mostly working now; I’m still not doing any actual editing, but that’s the top item on my list of things to do next.

Several other issues are being worked on in the meantime. Many things are more complex than I anticipated, but I believe the final result will be worthwhile. The actual plugin interface is still mutating from day to day, mostly because the actual usage patterns are hard to anticipate. I have two plugins partially working: File Metadata and File Forks (which use the basic hex editor to do its work).

I’m now making a separate version of the main XRay II application to be used as the plugin developer base. This will be a stripped-down version of the application: it’ll run only the two basic plugins and a third one, the one being developed. It will also have some debugging infrastructure in place.

Next, I’ll use this to start up projects for at least two more, perhaps more, plugins of different types, both reusing basic UI elements from the main application. Hopefully this will give me enough variations to publish a rich but robust plugin interface. I envision stopping development on the main application as soon as possible – perhaps even this year, if all goes well – and doing all the rest inside plugins.

Text editing…

No comments

Autoresizing NSTextFields are now working quite well, except in one instance – when there are several of them stacked and the window is resized several times very rapidly. I’ve left this alone for now while tackling another problem: text editing. Let me explain this a little.

One of my basic UI elements is a fast hex editor view. Here’s what it looks like at present:

Three columns, hex displacement at the left, hex characters in the center, MacOSRoman (or any other encoding) to the right. All in a scrolling view. That’s where things began to get strange. For normal Cocoa use, you’d normally define an NSTextView inside an NSScrollView. The three columns might be done by NSTextBlocks, as this will be Tiger-only. Or three different NSTextContainers, each one referencing an aspect of the same NSTextStorage…

The main stumbling point here is, I want to be able to edit very large files with no performance penalty. Files tens of gigabytes in size or even larger. All the standard Cocoa text objects above are out; they use 32-bit offsets and ranges for text sizes and selections, meaning things are limited to 4GB (or even 2GB in some cases). Also, NSTextView becomes slow as molasses well before text sizes reach those magnitudes, as the entire text needs to be laid out first to determine line breaks. Also, RAM requirements to generate the hex interpretation go up – remember a standard Mac OS X app can allocate just a little over 2GB of RAM. Finally, NSScrollView uses floats to track the scroll thumb position, meaning that scroll tracking becomes imprecise when you’re trying to track millions of lines.

Well, my fate apparently is to recode most of the NeXT-era UI widgets anyway – see RBSplitView. I tackled the scroller problem first, as I needed it for the file browser anyway, and soon had a special scroll view that tracked scrolling positions with unsigned 64-bit displacements – large enough for the largest file supported by Mac OS X – and faster and simpler than the standard one. It basically consists of the vertical NSScroller and the empty (document) space to its left; no intervening NSClipView. Any subviews are relocated by the offset when the scroller changes and drawing is optimized to the visible portion.

I also put in the option to have the view’s delegate redraw the visible portion directly – this was the idea I had to optimize the hex editor. Indeed, drawing is very fast; I have my own cached CoreGraphics bitmaps of the characters, and blit them to the visible portion of the sscroll view. And only the necessary part of the displayed file needs to be accessed, thanks to mapping only that part to memory with mmap(). And putting in editing later would be easy once the display portion is finished…

Famous last words. Turns out that the Cocoa text system is rather more complex than I expected – the standard NSTextView/NSTextField objects hide that very successfully from the “normal” developer. After several days of reading the very terse docs, and trying to find out which methods are called where, I’m finally at a point where the normal text input methods are working. However, I still can’t figure out how the standard copy/cut/paste menu items are enabled, and the whole process is still too clunky for wider use.

Stay tuned for developments…

C4[0] is over

No comments

Jon Rentzsch’s C4 Conference, zeroth issue, is over. And by all accounts, a great success; wish I could have attended, but I’d already spent my conference credits on WWDC this year.

Maybe next year I’ll manage it, if I can attend something else important/interesting in the US before or afterwards. Meanwhile, here’s the best bit:

In most conferences, some folks will congregate in the hallways to hang out…

But with C4, I didn?t catch any conversations in the hallway. Olof said “The main room was the hallway. It was all hallway.”

Sounds good to me…

I’ll wait for the videos to become available, but I already know I’ll want to comment on John Gruber‘s talk.

Re: Happenings

No comments

Still on the subject of network backup devices, I hadn’t been to Tom’s Networking for quite some time, and their page on NAS devices is very informative. There are quite a number of new options coming out; well worth a visit.

So, I needed to autoresize NSTextFields in XRay II (vertically only). Sort of a poor man’s WebView. This had to “just work” on certain NSTextFields used by third-party plugins, though, without any extra code or subclassing by the plugin writer.

There are two problems there. One is finding out the actual optimum vertical size, while editing and while not, for any type of border or bezel. Here’s the code I finally worked out, with the kind help of Daniel Jalkut:

- (NSSize)minSizeForContent {
   NSRect frame = [self frame];
   NSRect newf = frame;
   NSTextView* editor = nil;
   if ((editor = (NSTextView*)[self currentEditor])) {
      newf = [[editor layoutManager] usedRectForTextContainer:[editor textContainer]];
      newf.size.height += frame.size.height-[[self cell] drawingRectForBounds:frame].size.height;
   } else {
      newf.size.height = HUGE_VALF;
      newf.size = [[self cell] cellSizeForBounds:newf];
   }
   frame.size.height = newf.size.height;
   return frame.size;
}

So I put this into a category of NSTextField and did some runtime diddling with implementation pointers, but for other uses it could well be in a subclass.

The second problem is properly pushing down the views below the field when it is resized. The solution I ended up coding is a little too gnarly to post here, and it depends on the field and its sibling views being inside a custom NSView subclass with flipped coordinates… still, it seems to work well enough now, so I’ll leave it there and work on other stuff.

Re: Sony Reader

No comments

Panasonic quickly followed with the Words Gear. 1024×600 pixels at 211 dpi, half the weight of the Sony Reader, and the form factor is like a paperback with 20mm sawed off the bottom. It has an SD card slot, which is a good idea, and the design looks better; however it seems to use a standard LCD screen instead of e-paper, which means lower battery life.

Sony Reader

No comments

So, Sony’s Reader is out. This seems to be the first e-book reader that uses electronic paper and has a chance to be more than just a brief clunky curiosity.

The specs aren’t all that good, though. On the positive side, the display has a reasonable 170 dpi (200 to 300 is considered optimal for simulating actual paper) and battery life is reasonable at 7500 page turns. On the negative side, the display shows just 800×600 pixels and the dimensions aren’t ideal – slightly larger than a standard paperback, although a little thinner. From the pictures, the lines are too short for my taste, and 4-level grayscale isn’t enough to do proper antialiasing. And $349 is a little on the expensive side. It plays MP3 files but with only 64MB of memory that’s not much use.

My ideal e-book reader would have a 200 dpi screen which reproduces exactly the printable area of a standard paperback, which would mean a screen 1200 pixels tall and 700 pixels wide. Since the device has to compete against paperbacks, dimensions, weight and (ideally) price should be very similar. The Connect Store shows weirdly mixed prices; some, around the $6 level, not totally unreasonable, while others are in hardcover range. Come on, it’s not as if e-books have to pay for all that overhead of printing, binding, distributing, shipping, remaindering, and so forth. $4 should make e-books more accessible while at the same time paying better royalties to authors.

In 1989, Ben Bova wrote Cyberbooks, a funny and prescient tale of what would happen if such a subversive device as a cybernetic book would actually be brought on the market. Well, he didn’t foresee the emergence (only a very few years later) of the tubes, erhm, Internet, but it’s still a very readable story. Needless to say it seems to have sunk with very few traces; it’s out of print and Amazon has no cover picture available, and I know nobody else who has a copy.

Coming back to the present, I believe Apple should take a shot at this device. Jonathan Ive can do a much better design than the Sony Reader with one cerebral hemisphere tied behind his back, and a 1200×700, 200 dpi screen with 16 or more gray levels will certainly leave the labs soon.

Posted by Um dia a menos:
Um dia a menos linked to this post

Neutralidade

Carlos Afonso escreve no Oppi:

A neutralidade da Internet, como já alertava Lawrence Lessig há cinco anos, significa que os provedores de acesso e de infovias não podem controlar como os usuários utilizam a rede. Não podem censurar datagramas nem …

Photos licensed by Creative Commons license. Unless otherwise noted, content © 2002-2024 by Rainer Brockerhoff. Iravan child theme by Rainer Brockerhoff, based on Arjuna-X, a WordPress Theme by SRS Solutions. jQuery UI based on Aristo.