package provide Freetype::ftstroke 0.1

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


ft::struct define FT_Stroker {
}

set FT_STROKER_LINEJOIN_ROUND          0
set FT_STROKER_LINEJOIN_BEVEL          1
set FT_STROKER_LINEJOIN_MITER_VARIABLE 2
set FT_STROKER_LINEJOIN_MITER          $FT_STROKER_LINEJOIN_MITER_VARIABLE
set FT_STROKER_LINEJOIN_MITER_FIXED    3
::ffidl::typedef FT_Stroker_LineJoin int

set FT_STROKER_LINECAP_BUTT   0
set FT_STROKER_LINECAP_ROUND  1
set FT_STROKER_LINECAP_SQUARE 2
::ffidl::typedef FT_Stroker_LineCap int

set FT_STROKER_BORDER_LEFT  0
set FT_STROKER_BORDER_RIGHT 1
::ffidl::typedef FT_StrokerBorder int

::ffidl::callout _FT_Outline_GetInsideBorder {pointer} FT_StrokerBorder \
    [::ffidl::symbol $::ft::lib FT_Outline_GetInsideBorder]
proc  FT_Outline_GetInsideBorder {outline} {
    set result [_FT_Outline_GetInsideBorder [$outline getPointer]]
    return $result
}

::ffidl::callout _FT_Outline_GetOutsideBorder {pointer} FT_StrokerBorder \
    [::ffidl::symbol $::ft::lib FT_Outline_GetOutsideBorder]
proc  FT_Outline_GetOutsideBorder {outline} {
    set result [_FT_Outline_GetOutsideBorder [$outline getPointer]]
    return $result
}

::ffidl::callout _FT_Stroker_New {pointer pointer-var} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_New]
proc  FT_Stroker_New {library strokerVarName} {
    set p [::ft::_bytearray_from_pointer 0]
    set result [_FT_Stroker_New [$library getPointer] p]
    if {$result == 0} {
        upvar $strokerVarName stroker
        set stroker [FT_Stroker new [ft::_bytearray_to_pointer $p]]
    }
    return $result
}

::ffidl::callout _FT_Stroker_Set {pointer FT_Fixed FT_Stroker_LineCap
    FT_Stroker_LineJoin FT_Fixed} void \
    [::ffidl::symbol $::ft::lib FT_Stroker_Set]
proc  FT_Stroker_Set {stroker radius line_cap line_join miter_limit} {
    _FT_Stroker_Set [$stroker getPointer] $radius \
        $line_cap $line_join $miter_limit
    return
}

::ffidl::callout _FT_Stroker_Rewind {pointer} void \
    [::ffidl::symbol $::ft::lib FT_Stroker_Rewind]
proc  FT_Stroker_Rewind {stroker} {
    _FT_Stroker_Rewind [$stroker getPointer] 
    return
}

::ffidl::callout _FT_Stroker_ParseOutline {pointer pointer FT_Bool} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_ParseOutline]
proc  FT_Stroker_ParseOutline {stroker outline opened} {
    set result [_FT_Stroker_ParseOutline [$stroker getPointer] [$outline getPointer] $opened]
    return $result
}

::ffidl::callout _FT_Stroker_BeginSubPath {pointer pointer FT_Bool} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_BeginSubPath]
proc  FT_Stroker_BeginSubPath {stroker to opened} {
    set result [_FT_Stroker_BeginSubPath [$stroker getPointer] [$to getPointer] $opened]
    return $result
}

::ffidl::callout _FT_Stroker_EndSubPath {pointer} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_EndSubPath]
proc  FT_Stroker_EndSubPath {stroker} {
    set result [_FT_Stroker_EndSubPath [$stroker getPointer]]
    return $result
}

::ffidl::callout _FT_Stroker_LineTo {pointer pointer} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_LineTo]
proc  FT_Stroker_LineTo {stroker to} {
    set result [_FT_Stroker_LineTo [$stroker getPointer] [$to getPointer]]
    return $result
}

::ffidl::callout _FT_Stroker_ConicTo {pointer pointer pointer} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_ConicTo]
proc  FT_Stroker_ConicTo {stroker control to} {
    set result [_FT_Stroker_ConicTo [$stroker getPointer] [$control getPointer] [$to getPointer]]
    return $result
}

::ffidl::callout _FT_Stroker_CubicTo {pointer pointer pointer pointer} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_CubicTo]
proc  FT_Stroker_CubicTo {stroker control1 control2 to} {
    set result [_FT_Stroker_CubicTo [$stroker getPointer] [$control1 getPointer] [$control2 getPointer] [$to getPointer]]
    return $result
}

::ffidl::callout _FT_Stroker_GetBorderCounts {pointer FT_StrokerBorder pointer-var pointer-var} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_GetBorderCounts]
proc  FT_Stroker_GetBorderCounts {stroker border num_pointsVarName num_contoursVarName} {
    set p1 [::ft::_bytearray_from FT_UInt 0]
    set p2 [::ft::_bytearray_from FT_UInt 0]
    set result [_FT_Stroker_GetBorderCounts [$stroker getPointer] $border p1 p2]
    if {$result == 0} {
        uplevel [list set $num_pointsVarName   [::ft::_bytearray_to FT_UInt $p1]]
        uplevel [list set $num_contoursVarName [::ft::_bytearray_to FT_UInt $p2]]
    }
    return $result
}

::ffidl::callout _FT_Stroker_ExportBorder {pointer FT_StrokerBorder pointer} void \
    [::ffidl::symbol $::ft::lib FT_Stroker_ExportBorder]
proc  FT_Stroker_ExportBorder {stroker border outline} {
    _FT_Stroker_ExportBorder [$stroker getPointer] $border [$outline getPointer]
    return
}

::ffidl::callout _FT_Stroker_GetCounts {pointer pointer-var pointer-var} int \
    [::ffidl::symbol $::ft::lib FT_Stroker_GetCounts]
proc  FT_Stroker_GetCounts {stroker num_pointsVarName num_contoursVarName} {
    set p1 [::ft::_bytearray_from_pointer 0]
    set p2 [::ft::_bytearray_from_pointer 0]
    set result [_FT_Stroker_GetCounts [$stroker getPointer] p1 p2]
    if {$result == 0} {
        uplevel [list set $num_pointsVarName   [::ft::_bytearray_to FT_UInt $p1]]
        uplevel [list set $num_contoursVarName [::ft::_bytearray_to FT_UInt $p2]]
    }
    return $result
}

::ffidl::callout _FT_Stroker_Export {pointer pointer} void \
    [::ffidl::symbol $::ft::lib FT_Stroker_Export]
proc  FT_Stroker_Export {stroker outline} {
    _FT_Stroker_Export [$stroker getPointer] [$outline getPointer]
    return
}

::ffidl::callout _FT_Stroker_Done {pointer} void \
    [::ffidl::symbol $::ft::lib FT_Stroker_Done]
proc  FT_Stroker_Done {stroker} {
    _FT_Stroker_Done [$stroker getPointer]
    return
}

::ffidl::callout _FT_Glyph_Stroke {pointer-var pointer FT_Bool} int \
    [::ffidl::symbol $::ft::lib FT_Glyph_Stroke]
proc  FT_Glyph_Stroke {glyphVarName stroker destroy} {
    upvar $glyphVarName glyph
    set p [::ft::_bytearray_from_pointer [$glyph getPointer]]
    set result [_FT_Glyph_Stroke p [$stroker getPointer] $destroy]
    if {$result == 0} {
        set glyph [FT_Glyph new [::ft::_bytearray_to_pointer $p]]
    }
    return $result
}

::ffidl::callout _FT_Glyph_StrokeBorder {pointer-var pointer FT_Bool FT_Bool} int \
    [::ffidl::symbol $::ft::lib FT_Glyph_StrokeBorder]
proc  FT_Glyph_StrokeBorder {glyphVarName stroker inside destroy} {
    upvar $glyphVarName glyph
    set p [::ft::_bytearray_from_pointer [$glyph getPointer]]
    set result [_FT_Glyph_StrokeBorder p [$stroker getPointer] $inside $destroy]
    if {$result == 0} {
        set glyph [FT_Glyph new [::ft::_bytearray_to_pointer $p]]
    }
    return $result
}

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