Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:23:58+00:00 2026-05-18T04:23:58+00:00

I’m using an NSMutableAttribtuedString in order to build a string with formatting, which I

  • 0

I’m using an NSMutableAttribtuedString in order to build a string with formatting, which I then pass to Core Text to render into a frame. The problem is, that I need to use superscript and subscript. Unless these characters are available in the font (most fonts don’t support it), then setting the property kCTSuperscriptAttributeName does nothing at all.

So I guess I’m left with the only option, which is to fake it by changing the font size and moving the base line. I can do the font size bit, but don’t know the code for altering the base line. Can anyone help please?

Thanks!

EDIT: I’m thinking, considering the amount of time I have available to sort this problem, of editing a font so that it’s given a subscript “2”… Either that or finding a built-in iPad font which does. Does anyone know of any serif font with a subscript “2” I can use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:23:58+00:00Added an answer on May 18, 2026 at 4:23 am

    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.

    Hence, you probably need to interfere in the rendering process yourself. For example:

    • create a CTFramesetter, e.g. via CTFramesetterCreateWithAttributedString
    • get a CTFrame from that via CTFramesetterCreateFrame
    • use CTFrameGetLineOrigins and CTFrameGetLines 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)
    • from those, for lines with no superscript or subscript, just use CTLineDraw and forget about it
    • for those with superscript or subscript, use CTLineGetGlyphRuns to get an array of CTRun objects describing the various glyphs on the line
    • on each run, use CTRunGetStringIndices to determine which source characters are in the run; if none that you want to superscript or subscript are included, just use CTRunDraw to draw the thing
    • otherwise, use CTRunGetGlyphs to break the run into individual glyphs and CTRunGetPositions to figure out where they would be drawn in the normal run of things
    • use CGContextShowGlyphsAtPoint as appropriate, having tweaked the text matrix for those you want in superscript or subscript

    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.

    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).

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
In order to apply a triggered animation to all ToolTip s in my app,
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
I want use html5's new tag to play a wav file (currently only supported
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.