Distribute text top-to-bottom instead of left-to-right -
i'm working on view that's implementing multi-column text layout using coretext (using ctframesetter
).
coretext fills each frame completely, when call ctframesettercreateframe
3 rects make columns, layout that's similar following image:
so left column filled completely, middle column partially , right column empty. instead, i'd text distribute on 3 columns take least vertical space possible, in image:
how achieve coretext?
i don't mind going low-level here, drawing each ctrun
hand option if necessary.
one idea came create large frame width of column , figure out ctline
draw in column. has few limitations:
- it work if columns had same width.
- it not work clipping paths.
unfortunately, i'll need use clipping paths (as in kctframeclippingpathsattributename
) idea out. live fixed column width limitation, though.
another idea reduce height until last frame overflows that's pretty brute-force way surely wastes resources.
(btw, due compability requirements use of textkit classes nstextstorage
isn't possible; resulting view intended used on mac , ios, needs work on ios < 7)
since there doesn't seem non-expensive way solve this, here's how i've done it:
i did go "reduce height until last frame overflows" approach. reduce height, have clipping path (kctframeclippingpathsattributename
) rectangle fills bottom of view required height.
the expensive simple way have been increase rectangle height until text doesn't fit inside last frame more.
instead i've implemented binary search that. demo app, find correct height after 8-10 recursions still expensive @ least it's pixel-perfect , doesn't rely on other information other "did last frame overflow".
Comments
Post a Comment