package provide Freetype::ftpfr 0.1

if {![info exists _source([file tail [info script]])]} {
package require Freetype::ft2build
package require $FT_FREETYPE

::ffidl::callout _FT_Get_PFR_Metrics \
    {pointer pointer-var pointer-var pointer-var pointer-var} int \
    [::ffidl::symbol $::ft::lib FT_Get_PFR_Metrics]
proc FT_Get_PFR_Metrics {face
                         outline_resolutionVarName
                         metrics_resolutionVarName
                         metrics_x_scaleVarName
                         metrics_y_scaleVarName} {
    upvar $outline_resolutionVarName outline_resolution
    upvar $metrics_resolutionVarName metrics_resolution
    upvar $metrics_x_scaleVarName    metrics_x_scale
    upvar $metrics_y_scaleVarName    metrics_y_scale
    set p1 [::ft::_bytearray_from FT_UInt 0]
    set p2 [::ft::_bytearray_from FT_UInt 0]
    set p3 [::ft::_bytearray_from FT_Fixed 0]
    set p4 [::ft::_bytearray_from FT_Fixed 0]
    set result [_FT_Get_PFR_Metrics [$face getPointer] p1 p2 p3 p4]
    if {$result == 0} {
        set $outline_resolution [::ft::_bytearray_to FT_UInt $p1]
        set $metrics_resolution [::ft::_bytearray_to FT_UInt $p2]
        set $metrics_x_scale    [::ft::_bytearray_to FT_Fixed $p3]
        set $metrics_y_scale    [::ft::_bytearray_to FT_Fixed $p4]
    }
    return $result
}

::ffidl::callout _FT_Get_PFR_Kerning {pointer FT_UInt FT_UInt pointer} int \
    [::ffidl::symbol $::ft::lib FT_Get_PFR_Kerning]
proc FT_Get_PFR_Kerning {face left right vectorVarName} {
    upvar $vectorVarName vector
    if {[info exists vector] == 0} {
        set p [$vector getPointer]
    } else {
        set temp [FT_Vector new]
        set p [$temp getPointer]
    }
    set result [_FT_Get_PFR_Kerning [$face getPointer] $left $right $p]
    if {$result == 0} {
        if {[info exists temp]} {
            set vector $temp
        }
    } else {
        $temp destroy
    }
    return $result
}

::ffidl::callout _FT_Get_PFR_Advance {pointer FT_UInt pointer-var} int \
    [::ffidl::symbol $::ft::lib FT_Get_PFR_Advance]
proc FT_Get_PFR_Advance {face gindex advanceVarName} {
    upvar $advanceVarName advance
    set p [::ft::_bytearray_from FT_Pos 0]
    set result [_FT_Get_PFR_Advance [$face getPointer] $gindex p]
    if {$result == 0} {
        set advance [::ft::_bytearray_to FT_Pos $p]
    }
    return $result
}

set _source([file tail [info script]]) 1
}
