Custom layout shape
Submitted by Behdad Esfahbod
So I want to implement this feature to allow custom non-rectangular layout shapes. Think:
I say 'even' because the second link is more invovled, having lines that have more than one segment. Lets call them multi-segment lines, and act as if every segment was a regular line. They cause hard problems with mixed-direction text. In rtl, first the right segment should be filled.. But I think we can manage that since we have the line direction information.
So we'll introduce new api, something like:
void pango_layout_set_shape_callback (PangoLayout *layout, PangoSomeCallback callback, gpointer data);
The callback will receive the previous multi-segment line, current multi-segment line number, and current line ascent+descent, and returns:
The positions for the new multi-segment line. That is, a list of segments, each having an X position and width.
Y position and Y anchor (top, bottom, baseline).
Whether it should be called back again for this line if the line height changes.
The layout algorithm will start with logical ascent+descent of the first cluster of text for this line, and calls the callback, getting a list of segments for this multi-segment line. It will start filling them based on the line direction. It will go on and fill them just as if they were regular lines. At any point if putting a new cluster into the line changes line height, it will call into the callback to get new line placement.
Thinking about it again, it will get very clumsy very fast. Ok, lets try again. Forget about multi-segment lines. Repeat everything with single lines, but the callback will also get a line direction setting. So it can choose which segment to return next. Does this make more sense? It's still hard to get it right in the callback for more than two segments, but I don't really care about that case.