; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: FreeType library constants and structures.
;
;  Target OS: Linux
;
;  Dependencies:
;
;  Notes:
;_________________________________________________________________________________________


FT_FACE_FLAG_SCALABLE           = $0001
FT_FACE_FLAG_FIXED_SIZES        = $0002
FT_FACE_FLAG_FIXED_WIDTH        = $0004
FT_FACE_FLAG_SFNT               = $0008
FT_FACE_FLAG_HORIZONTAL         = $0010
FT_FACE_FLAG_VERTICAL           = $0020
FT_FACE_FLAG_KERNING            = $0040
FT_FACE_FLAG_FAST_GLYPHS        = $0080
FT_FACE_FLAG_MULTIPLE_MASTERS   = $0100
FT_FACE_FLAG_GLYPH_NAMES        = $0200
FT_FACE_FLAG_EXTERNAL_STREAM    = $0400
FT_FACE_FLAG_HINTER             = $0800
FT_FACE_FLAG_CID_KEYED          = $1000
FT_FACE_FLAG_TRICKY             = $2000


FT_LOAD_DEFAULT                         =  $0
FT_LOAD_NO_SCALE                        =  $1
FT_LOAD_NO_HINTING                      =  $2
FT_LOAD_RENDER                          =  $4
FT_LOAD_NO_BITMAP                       =  $8
FT_LOAD_VERTICAL_LAYOUT                 =  $10
FT_LOAD_FORCE_AUTOHINT                  =  $20
FT_LOAD_CROP_BITMAP                     =  $40          ; deprecated, ignored
FT_LOAD_PEDANTIC                        =  $80
FT_LOAD_ADVANCE_ONLY                    =  $100
FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH     =  $200         ; deprecated, ignored
FT_LOAD_NO_RECURSE                      =  $400
FT_LOAD_IGNORE_TRANSFORM                =  $800
FT_LOAD_MONOCHROME                      =  $1000
FT_LOAD_LINEAR_DESIGN                   =  $2000
FT_LOAD_SBITS_ONLY                      =  $4000
FT_LOAD_NO_AUTOHINT                     =  $8000
FT_LOAD_COLOR                           =  $100000

FT_ADVANCE_FLAG_FAST_ONLY               =  $20000000


FT_RENDER_MODE_NORMAL = 0
FT_RENDER_MODE_LIGHT  = 1
FT_RENDER_MODE_MONO   = 2
FT_RENDER_MODE_LCD    = 3
FT_RENDER_MODE_LCD_V  = 4
FT_RENDER_MODE_MAX    = 5

struc FT_LOAD_TARGET x {
  . = (x and 15) shl 16
}

FT_LOAD_TARGET_NORMAL FT_LOAD_TARGET  FT_RENDER_MODE_NORMAL
FT_LOAD_TARGET_LIGHT  FT_LOAD_TARGET  FT_RENDER_MODE_LIGHT
FT_LOAD_TARGET_MONO   FT_LOAD_TARGET  FT_RENDER_MODE_MONO
FT_LOAD_TARGET_LCD    FT_LOAD_TARGET  FT_RENDER_MODE_LCD
FT_LOAD_TARGET_LCD_V  FT_LOAD_TARGET  FT_RENDER_MODE_LCD_V



FT_PIXEL_MODE_NONE  = 0
FT_PIXEL_MODE_MONO  = 1
FT_PIXEL_MODE_GRAY  = 2
FT_PIXEL_MODE_GRAY2 = 3
FT_PIXEL_MODE_GRAY4 = 4
FT_PIXEL_MODE_LCD   = 5
FT_PIXEL_MODE_LCD_V = 6
FT_PIXEL_MODE_BGRA  = 7


struct FT_Generic
  .data         dd ?
  .finalizer    dd ?    ; pointer to procedure with one argument.
ends

struct FT_BBox
  .xMin         dd ?
  .yMin         dd ?
  .xMax         dd ?
  .yMax         dd ?
ends

struct FT_Vector
  .x dd ?
  .y dd ?
ends

struct FT_Bitmap
  .rows         dd ?
  .width        dd ?
  .pitch        dd ?
  .buffer       dd ?    ; pointer to the buffer.
  .num_grays    dw ?
  .pixel_mode   db ?
  .palette_mode db ?
  .palette      dd ?    ; pointer to the palette.
ends




struct FT_Outline
  .n_contours  dw  ?
  .n_points    dw  ?
  .points      dd  ?    ; pointer to array of FT_Vector elements.
  .tags        dd  ?    ; pointer to byte array.
  .contours    dd  ?    ; pointer to word array.
  .flags       dd  ?
ends



struct  FT_Glyph_Metrics
  .width        dd ?
  .height       dd ?
  .horiBearingX dd ?
  .horiBearingY dd ?
  .horiAdvance  dd ?

  .vertBearingX dd ?
  .vertBearingY dd ?
  .vertAdvance  dd ?
ends



struct FT_GlyphSlot
  .library      dd ?
  .face         dd ?    ; parent FT_Face object
  .next         dd ?    ; pointer tp FT_GlyphSlot
  .reserved     dd ?
  .generic      FT_Generic

  .metrics      FT_Glyph_Metrics
  .linearHoriAdvance dd ?
  .linearVertAdvance dd ?

  .advance      FT_Vector

  .format       dd ?

  .bitmap       FT_Bitmap
  .bitmap_left  dd ?
  .bitmap_top   dd ?

  .outline      FT_Outline

  .num_subglyphs dd ?
  .subglyphs     dd ?   ; pointer to array of FT_SubGlyphRec elements.

  .control_data  dd ?
  .control_len   dd ?

  .lsb_delta     dd ?
  .rsb_delta     dd ?

  .other         dd ?
  .internal      dd ?   ; pointer to FT_Slot_InternalRec
ends


struct FT_FaceRec
  .num_faces    dd ?
  .face_index   dd ?
  .face_flags   dd ?
  .style_flags  dd ?
  .num_glyphs   dd ?
  .family_name  dd ?
  .style_name   dd ?

  .num_fixed_sizes dd ?
  .available_sizes dd ?

  .num_charmaps dd ?
  .charmaps     dd ?
  .generic      FT_Generic

; scalable fonts members down to .underline_thickness

  .bbpx                 FT_BBox

  .units_per_EM         dw ?
  .ascender             dw ?
  .descender            dw ?
  .height               dw ?

  .max_advance_width    dw ?
  .max_advance_height   dw ?

  .underline_position   dw ?
  .underline_thickness  dw ?


  .glyph        dd  ?   ; pointer to FT_GlyphSlot
  .size         dd  ?   ; pointer to FT_Size
  .charmap      dd  ?   ; pointer to FT_CharMap

; down is the private part.

ends


struct FT_GlyphRec
  .library      dd      ?
  .clazz        dd      ?
  .format       dd      ?
  .advance      FT_Vector
ends


struct FT_BitmapGlyphRec
  .root         FT_GlyphRec
  .left         dd ?
  .top          dd ?
  .bitmap       FT_Bitmap
ends


FT_SIZE_REQUEST_TYPE_NOMINAL    = 0
FT_SIZE_REQUEST_TYPE_REAL_DIM   = 1
FT_SIZE_REQUEST_TYPE_BBOX       = 2
FT_SIZE_REQUEST_TYPE_CELL       = 3
FT_SIZE_REQUEST_TYPE_SCALES     = 4


struct FT_Size_RequestRec
  .type            dd  ?
  .width           dd  ?
  .height          dd  ?
  .horiResolution  dd  ?
  .vertResolution  dd  ?
ends


struct FT_Size_Metrics
  .x_ppem       dw      ?       ; horizontal pixels per EM
  .y_ppem       dw      ?       ; vertical pixels per EM

  .x_scale      dd      ?       ; scaling values used to convert font
  .y_scale      dd      ?       ; units to 26.6 fractional pixels

  .ascender     dd      ?       ; ascender in 26.6 frac. pixels
  .descender    dd      ?       ; descender in 26.6 frac. pixels
  .height       dd      ?       ; text height in 26.6 frac. pixels
  .max_advance  dd      ?       ; max horizontal advance, in 26.6 pixels
ends


struct FT_SizeRec
  .face         dd  ?           ; parent face object
  .generic      FT_Generic      ; generic pointer for client uses
  .metrics      FT_Size_Metrics ; size metrics
  .internal:
ends


struct FTC_ScalerRec
  .face_id dd ?
  .width   dd ?
  .height  dd ?
  .pixel   dd ?
  .x_res   dd ?
  .y_res   dd ?
ends


struct FTC_ImageType
  .face_id  dd  ?
  .width    dd  ?
  .height   dd  ?
  .flags    dd  ?
ends




interface FT_Face_Requester, .face_id, .library, .request_data, .pFace