Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no baseline setting amongst the CTParagraphStyleSpecifiers or the defined string attribute name constants. I think it's therefore safe to conclude that CoreText does not itself support a baseline adjust property on text. There's a reference made to baseline placement in CTTypesetter, but I can't tie that to any ability to vary the baseline over the course of a line in the iPad's CoreText.</p> <p>Hence, you probably need to interfere in the rendering process yourself. For example:</p> <ul> <li>create a CTFramesetter, e.g. via <code>CTFramesetterCreateWithAttributedString</code></li> <li>get a CTFrame from that via <code>CTFramesetterCreateFrame</code></li> <li>use <code>CTFrameGetLineOrigins</code> and <code>CTFrameGetLines</code> to get an array of CTLines and where they should be drawn (ie, the text with suitable paragraph/line breaks and all your other kerning/leading/other positioning text attributes applied)</li> <li>from those, for lines with no superscript or subscript, just use <code>CTLineDraw</code> and forget about it</li> <li>for those with superscript or subscript, use <code>CTLineGetGlyphRuns</code> to get an array of CTRun objects describing the various glyphs on the line</li> <li>on each run, use <code>CTRunGetStringIndices</code> to determine which source characters are in the run; if none that you want to superscript or subscript are included, just use <code>CTRunDraw</code> to draw the thing</li> <li>otherwise, use <code>CTRunGetGlyphs</code> to break the run into individual glyphs and <code>CTRunGetPositions</code> to figure out where they would be drawn in the normal run of things</li> <li>use <code>CGContextShowGlyphsAtPoint</code> as appropriate, having tweaked the text matrix for those you want in superscript or subscript</li> </ul> <p>I haven't yet found a way to query whether a font has the relevant hints for automatic superscript/subscript generation, which makes things a bit tricky. If you're desperate and don't have a solution to that, it's probably easier just not to use CoreText's stuff at all — in which case you should probably define your own attribute (that's why [NS/CF]AttributedString allow arbitrary attributes to be applied, identified by string name) and use the normal NSString searching methods to identify regions that need to be printed in superscript or subscript from blind.</p> <p>For performance reasons, binary search is probably the way to go on searching all lines, the runs within a line and the glyphs within a run for those you're interested in. Assuming you have a custom UIView subclass to draw CoreText content, it's probably smarter to do it ahead of time rather than upon every drawRect: (or the equivalent methods, if e.g. you're using a CATiledLayer).</p> <p>Also, the CTRun methods have variants that request a pointer to a C array containing the things you're asking for copies of, possibly saving you a copy operation but not necessarily succeeding. Check the documentation. I've just made sure that I'm sketching a workable solution rather than necessarily plotting the absolutely optimal route through the CoreText API.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload