Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

331
Views
Get all Glyphs of a UIFont that have a descender

Is there a way to get all the glyphs of a UIFont that contain a true descender? It seems that using CTLineGetTypographicBounds is not accurate and returns the exact same descent value for every line. I thought it would provide the information that I needed but it did not. So now I am looking to see if I can build a character set from the glyphs that contain true descenders unless there is another way. The ultimate goal would be able to see if a line of text is below the baseline.

  let line = CTLineCreateWithAttributedString(NSAttributedString(string: s, attributes: attr))
  //let's get the real descent test
   var a : CGFloat = 0
   var d : CGFloat = 0
   var l : CGFloat = 0
   let bounds = CTLineGetTypographicBounds(line, &a, &d, &l)
   print("the descent is \(d)")
   print("the ascent is \(a)")
   print("the leading is \(l)")
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since it seems that your actual goal is to determine whether a string contains a character with a descender, you can use Core Text to look at the bounding rect of each glyph. If the bounding rect's origin in negative, this means the glyph starts below the baseline. This will be true for characters such as y but also ,.

func checkDescender(string: String) {
    let uiFont = UIFont.systemFont(ofSize: 14) // Pick your font
    let font = CTFontCreateWithName(uiFont.fontName as CFString, uiFont.pointSize, nil)
    for ch in string.unicodeScalars {
        let utf16codepoints = Array(ch.utf16)
        var glyphs: [CGGlyph] = [0, 0]
        let hasGlyph = CTFontGetGlyphsForCharacters(font, utf16codepoints, &glyphs, utf16codepoints.count)
        if hasGlyph {
            let rect = CTFontGetBoundingRectsForGlyphs(font, .default, glyphs, nil, 1)
            // print("\(ch) has bounding box of \(rect)")
            if rect.origin.y < 0 {
                print("\(ch) goes below the baseline by \(-rect.origin.y)")
            }
        }
    }
}

checkDescender(string: "Ymy,")

You might want to add additional checks to only look at letters depending on your needs.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!