LiveUI / FTCoreText

An open source Objective-C interface component that makes use of the CoreText framework to render static text content using a highly customisable markup syntax.
MIT License
781 stars 125 forks source link

let bullet tag define bullet glyph and separate, indented text style #6

Open algal opened 12 years ago

algal commented 12 years ago

Right now, the bullet tag defines one style that applies both to the bullet glyph and to the text associated with the bullet. For instance, font overrides bulletFont and color overrides bulletColor. After the following style, the bullet and the text are green and sixteen point:

FTCoreTextStyle *bulletStyle = [defaultStyle copy];
bulletStyle.name = FTCoreTextTagBullet;
bulletStyle.bulletFont = [UIFont fontWithName:@"TimesNewRomanPSMT" size:32.f];
bulletStyle.bulletColor = [UIColor orangeColor];
bulletStyle.bulletCharacter = @"❧";
bulletStyle.font = [UIFont fontWithName:@"Helvetica" size:16.0f];
bulletStyle.color = [UIColor greenColor];

It would be good if there could be two styles. Then you could use one font and colour for the bullet glyph (e.g., blue, Webdings) and the letter glyphs from another (e.g., black, Helvetica).

In addition, I may be wrong, but I think defining a separate style for the bullet text is necessary just to support the usual indentation of the non-initial lines of text associated with a list item, as it works for in HTML for instance. I'd be very interested in helping with this but I'm not sure where to start.

For instance, I am not sure how to use CoreText to produce this indentation style, or if what I've suggested is the approach that best fits the component's close fit to CoreText's own model

algal commented 12 years ago

My original comment here referred to two issues: (1) separate style for the bullet character and for the bullet's text; (2) bullet text indented according to the usual HTML "list style."

I still believe (1) is in fact a bug, given that the API defines bulletFont and bulletColor, presumably to distinguish it from the text font and text colour of the style, but then in my experiments one overrides the other.

However, as regards (2), I did some digging and realised you can already get this effect using FTCoreText by setting the left value of the paragraphInset to the desired BulletIndent distance. I have to admit I'm quite puzzled why this works.

From experimenting with CoreText directly, I find you can only produce the effect by setting three values (FirstLineHeadIndent=0, TabStop1=BulletIndent, and HeadIndent=BulletIndent) and then beginning the text like "\t". However, from examining the FTCoreText code, and logging the paragraph style with CFShow, I can see that the FTCoreText is only setting two of these values.

I suppose FTCoreText is doing something else, outside of the CTParagraphStyle, that affects layout.