Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda