package provide Freetype::ftgxval 0.1

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

set FT_VALIDATE_feat_INDEX     0
set FT_VALIDATE_mort_INDEX     1
set FT_VALIDATE_morx_INDEX     2
set FT_VALIDATE_bsln_INDEX     3
set FT_VALIDATE_just_INDEX     4
set FT_VALIDATE_kern_INDEX     5
set FT_VALIDATE_opbd_INDEX     6
set FT_VALIDATE_trak_INDEX     7
set FT_VALIDATE_prop_INDEX     8
set FT_VALIDATE_lcar_INDEX     9
set FT_VALIDATE_GX_LAST_INDEX  $FT_VALIDATE_lcar_INDEX

set FT_VALIDATE_GX_LENGTH      [expr $FT_VALIDATE_GX_LAST_INDEX + 1]

set FT_VALIDATE_GX_START       [expr 0x4000]
proc FT_VALIDATE_GX_BITFIELD {tag} {
    uplevel "expr \$FT_VALIDATE_GX_START << \[set FT_VALIDATE_${tag}_INDEX\]"
}
set FT_VALIDATE_feat      [FT_VALIDATE_GX_BITFIELD feat]
set FT_VALIDATE_mort      [FT_VALIDATE_GX_BITFIELD mort]
set FT_VALIDATE_morx      [FT_VALIDATE_GX_BITFIELD morx]
set FT_VALIDATE_bsln      [FT_VALIDATE_GX_BITFIELD bsln]
set FT_VALIDATE_just      [FT_VALIDATE_GX_BITFIELD just]
set FT_VALIDATE_kern      [FT_VALIDATE_GX_BITFIELD kern]
set FT_VALIDATE_opbd      [FT_VALIDATE_GX_BITFIELD opbd]
set FT_VALIDATE_trak      [FT_VALIDATE_GX_BITFIELD trak]
set FT_VALIDATE_prop      [FT_VALIDATE_GX_BITFIELD prop]
set FT_VALIDATE_lcar      [FT_VALIDATE_GX_BITFIELD lcar]
set FT_VALIDATE_GX [expr {$FT_VALIDATE_feat | 
                          $FT_VALIDATE_mort | 
                          $FT_VALIDATE_morx | 
                          $FT_VALIDATE_bsln | 
                          $FT_VALIDATE_just | 
                          $FT_VALIDATE_kern | 
                          $FT_VALIDATE_opbd | 
                          $FT_VALIDATE_trak | 
                          $FT_VALIDATE_prop | 
                          $FT_VALIDATE_lcar}]


::ffidl::callout _FT_TrueTypeGX_Validate {pointer FT_UInt pointer-var FT_UInt} int \
    [::ffidl::symbol $::ft::lib FT_TrueTypeGX_Validate]
proc FT_TrueTypeGX_Validate {face validation_flags tablesVarName} {
    upvar $tablesVarName tables
    set size [expr {[::ffidl::info sizeof FT_Bytes] * $::FT_VALIDATE_GX_LENGTH}]
    set buf [binary format x$size]
    set result [_FT_TrueTypeGX_Validate [$face getPointer] \
        $validation_flags buf $::FT_VALIDATE_GX_LENGTH]
        puts result=$result
    if {$result == 0} {
        set tables [::ft::_bytearray_to_list $buf FT_Bytes]
    }
    return $result
}

::ffidl::callout _FT_TrueTypeGX_Free {pointer pointer-var} void \
    [::ffidl::symbol $::ft::lib FT_TrueTypeGX_Free]
proc FT_TrueTypeGX_Free {face table} {
    set buf [::ft::_bytearray_from_list $table FT_Bytes]
    _FT_TrueTypeGX_Free [$face getPointer] buf
}


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