Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetGlyphWidths using sk_font_get_widths_bounds #33

Open
aakrandan opened this issue Jun 21, 2023 · 1 comment
Open

GetGlyphWidths using sk_font_get_widths_bounds #33

aakrandan opened this issue Jun 21, 2023 · 1 comment

Comments

@aakrandan
Copy link

aakrandan commented Jun 21, 2023

`public func getGlyphWidths(text: String) -> [Float] {
var paint: Paint? = nil
var textChar = Character

    var n = countGlyphs(str: text)
    if n <= 0 {
        return [Float]()
    }
    
    var widths: [Float] = Array.init (repeating: Float.zero, count: Int(n))
    var bounds: [Rect] = Array.init (repeating: Rect(width: 0, height: 0), count: Int(n))
    
    var w: UnsafeMutablePointer<Float>? = nil
    if !widths.isEmpty {
        w = UnsafeMutablePointer<Float>.allocate(capacity: widths.count)
        w?.initialize(from: &widths, count: widths.count)
    }

    var b: UnsafeMutablePointer<Rect>? = nil
    if !bounds.isEmpty {
        b = UnsafeMutablePointer<Rect>.allocate(capacity: bounds.count)
        b?.initialize(from: &bounds, count: bounds.count)
    }

    
    if var glyphs = getGlyphs(str: text) {
        sk_font_get_widths_bounds(handle, &glyphs, Int32 (glyphs.count), w, b, paint?.handle)
    }
    
    
    // Deallocate memory and free pointers when done
    w?.deallocate()
    b?.deallocate()
    
    return widths
}

`
I have implemented the above API, could you please let me know if there is something that i missed here?

@aakrandan
Copy link
Author

For some reason the format is not working for me, but i hope the code i pasted is readable.
Any help is appreciated.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant