View Issue Details

IDProjectCategoryView StatusLast Update
0032473FPCPackagespublic2018-01-01 18:13
ReporterAndi FriessAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformDell XPSOSWin10 / 64 ProOS VersionWin10 / 64 Pro
Product Version3.1.1Product Buildtrunk 
Target VersionFixed in Version3.2.0 
Summary0032473: fcl-image feature request: make load of freetyp library dynamicaly
Descriptionfeature request: make load of freetyp library dynamicaly.

Actually the freetype(-6.dll) is only static bounded, so it is not possible to have the lib in system dir only.

If the library is loaded dynamic, so is it possible, like other used dll in fpc.

 
Additional Informationthe patch is NOT well tested.
TagsNo tags attached.
Fixed in Revision37865
FPCOldBugId
FPCTarget
Attached Files
  • freetypeh.patch (32,689 bytes)
    Index: packages/fcl-image/src/freetype.pp
    ===================================================================
    --- packages/fcl-image/src/freetype.pp	(revision 37325)
    +++ packages/fcl-image/src/freetype.pp	(working copy)
    @@ -17,7 +17,7 @@
     
     interface
     
    -uses sysutils, classes, freetypeh, FPImgCmn;
    +uses sysutils, classes, freetypehdyn, FPImgCmn;
     
     { TODO : take resolution in account to find the size }
     { TODO : speed optimization: search glyphs with a hash-function/tree/binary search/... }
    Index: packages/fcl-image/src/freetypeh.inc
    ===================================================================
    --- packages/fcl-image/src/freetypeh.inc	(nonexistent)
    +++ packages/fcl-image/src/freetypeh.inc	(working copy)
    @@ -0,0 +1,508 @@
    +{
    +    This file is part of the Free Pascal run time library.
    +    Copyright (c) 2003 by the Free Pascal development team
    +
    +    Basic canvas definitions.
    +
    +    See the file COPYING.FPC, included in this distribution,
    +    for details about the copyright.
    +
    +    This program is distributed in the hope that it will be useful,
    +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    +
    + **********************************************************************}
    +{ Note that these are not all the availlable calls from the dll yet.
    +  This unit is used by TStringBitMaps and FTFont }
    +
    +interface
    +
    +{$IFDEF LOAD_DYNAMICALLY}
    +  {$DEFINE D}
    +  {$UNDEF S}
    +{$ELSE}
    +  {$DEFINE S}
    +  {$UNDEF D}
    +{$ENDIF}
    +
    +
    +{$ifdef D}
    +uses
    +  SysUtils, DynLibs;
    +{$endif}
    +
    +const
    +
    +{$packrecords c}
    +
    +// Windows
    +{$ifdef windows}
    +  freetypedll = 'freetype-6.dll';   // version 2.1.4
    +  {$define ft_found_platform}
    +{$endif}
    +// Mac OS X
    +{$ifdef darwin}
    +  freetypedll = 'libfreetype'; // Doesn't seam to matter much.
    +  {$linklib freetype}          // This one is the important part,
    +                               // but you also need to pass to fpc
    +                               // the following command:
    +                               // -k-L/usr/X11/lib
    +                               // or another place where it can find
    +                               // libfreetype.dylib
    +  {$define ft_found_platform}
    +{$endif}
    +// LINUX
    +{$if defined(UNIX) and not defined(darwin)}
    +  freetypedll = 'freetype';
    +  {$define ft_found_platform}
    +{$endif}
    +// Other platforms
    +{$ifndef ft_found_platform}
    +  freetypedll = 'freetype';
    +{$endif}
    +
    +
    +
    +type
    +  FT_Encoding = array[0..3] of char;
    +
    +const
    +  FT_FACE_FLAG_SCALABLE = 1 shl 0;
    +  FT_FACE_FLAG_FIXED_SIZES = 1 shl 1;
    +  FT_FACE_FLAG_FIXED_WIDTH = 1 shl 2;
    +  FT_FACE_FLAG_SFNT = 1 shl 3;
    +  FT_FACE_FLAG_HORIZONTAL = 1 shl 4;
    +  FT_FACE_FLAG_VERTICAL = 1 shl 5;
    +  FT_FACE_FLAG_KERNING = 1 shl 6;
    +  FT_FACE_FLAG_FAST_GLYPHS = 1 shl 7;
    +  FT_FACE_FLAG_MULTIPLE_MASTERS = 1 shl 8;
    +  FT_FACE_FLAG_GLYPH_NAMES = 1 shl 9;
    +  FT_FACE_FLAG_EXTERNAL_STREAM = 1 shl 10;
    +
    +  FT_STYLE_FLAG_ITALIC = 1 shl 0;
    +  FT_STYLE_FLAG_BOLD = 1 shl 1;
    +
    +  FT_LOAD_DEFAULT =          $0000;
    +  FT_LOAD_NO_SCALE =         $0001;
    +  FT_LOAD_NO_HINTING =       $0002;
    +  FT_LOAD_RENDER =           $0004;
    +  FT_LOAD_NO_BITMAP =        $0008;
    +  FT_LOAD_VERTICAL_LAYOUT =  $0010;
    +  FT_LOAD_FORCE_AUTOHINT =   $0020;
    +  FT_LOAD_CROP_BITMAP =      $0040;
    +  FT_LOAD_PEDANTIC =         $0080;
    +  FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = $0200;
    +  FT_LOAD_NO_RECURSE =       $0400;
    +  FT_LOAD_IGNORE_TRANSFORM = $0800;
    +  FT_LOAD_MONOCHROME =       $1000;
    +  FT_LOAD_LINEAR_DESIGN =    $2000;
    +
    +  ft_glyph_format_none      = $00000000;
    +  ft_glyph_format_composite = $636F6D70; //comp 099 111 109 112
    +  ft_glyph_format_bitmap    = $62697473; //bits 098 105 116 115
    +  ft_glyph_format_outline   = $6F75746C; //outl 111 117 116 108
    +  ft_glyph_format_plotter   = $706C6F74; //plot 112 108 111 116
    +
    +  FT_ENCODING_MS_SYMBOL : FT_Encoding = 'symb';
    +  FT_ENCODING_UNICODE : FT_Encoding = 'unic';
    +  FT_ENCODING_MS_SJIS : FT_Encoding = 'sjis';
    +  FT_ENCODING_MS_GB2312 : FT_Encoding = 'gb  ';
    +  FT_ENCODING_MS_BIG5 : FT_Encoding = 'big5';
    +  FT_ENCODING_MS_WANSUNG : FT_Encoding = 'wans';
    +  FT_ENCODING_MS_JOHAB : FT_Encoding = 'joha';
    +  FT_ENCODING_ADOBE_STANDARD : FT_Encoding = 'ADOB';
    +  FT_ENCODING_ADOBE_EXPERT : FT_Encoding = 'ADBE';
    +  FT_ENCODING_ADOBE_CUSTOM : FT_Encoding = 'ADBC';
    +  FT_ENCODING_ADOBE_LATIN_1 : FT_Encoding = 'lat1';
    +  FT_ENCODING_OLD_LATIN_2 : FT_Encoding = 'lat2';
    +  FT_ENCODING_APPLE_ROMAN : FT_Encoding = 'armn';
    +
    +  ft_glyph_bbox_unscaled  = 0; //* return unscaled font units           */
    +  ft_glyph_bbox_subpixels = 0; //* return unfitted 26.6 coordinates     */
    +  ft_glyph_bbox_gridfit   = 1; //* return grid-fitted 26.6 coordinates  */
    +  ft_glyph_bbox_truncate  = 2; //* return coordinates in integer pixels */
    +  ft_glyph_bbox_pixels    = 3; //* return grid-fitted pixel coordinates */
    +
    +  FT_KERNING_DEFAULT  = 0;
    +  FT_KERNING_UNFITTED = 1;
    +  FT_KERNING_UNSCALED = 2;
    +
    +
    +type
    +
    +  FT_Bool = boolean;
    +  FT_FWord = smallint;
    +  FT_UFWord = word;
    +  FT_Char = char;
    +  FT_Byte = byte;
    +  FT_String = char;
    +  FT_Short = smallint;
    +  FT_UShort = word;
    +  FT_Int = longint;
    +  FT_UInt = longword;
    +  {$if defined(cpu64) and not(defined(win64) and defined(cpux86_64))}
    +  FT_Long = int64;
    +  FT_ULong = qword;
    +  FT_Pos = int64;
    +  {$ELSE}
    +  FT_Long = longint;
    +  FT_ULong = longword;
    +  FT_Pos = longint;
    +  {$ENDIF}
    +  FT_F2Dot14 = smallint;
    +  FT_F26Dot6 = longint;
    +  FT_Fixed = FT_Long;
    +  FT_Error = longint;
    +  FT_Pointer = pointer;
    +  //FT_Offset = size_t;
    +  //FT_PtrDist = size_t;
    +
    +  FT_Render_Mode = (FT_RENDER_MODE_NORMAL, FT_RENDER_MODE_LIGHT,
    +      FT_RENDER_MODE_MONO, FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V,
    +      FT_RENDER_MODE_MAX);
    +
    +  FT_UnitVector_ = record
    +      x : FT_F2Dot14;
    +      y : FT_F2Dot14;
    +   end;
    +  FT_UnitVector = FT_UnitVector_;
    +
    +  FT_Matrix = record
    +      xx : FT_Fixed;
    +      xy : FT_Fixed;
    +      yx : FT_Fixed;
    +      yy : FT_Fixed;
    +   end;
    +  PFT_Matrix = ^FT_Matrix;
    +
    +  FT_Data = record
    +      pointer : ^FT_Byte;
    +      length : FT_Int;
    +   end;
    +
    +  FT_Generic_Finalizer = procedure (AnObject:pointer);cdecl;
    +
    +  FT_Generic = record
    +      data : pointer;
    +      finalizer : FT_Generic_Finalizer;
    +   end;
    +
    +  FT_Glyph_Metrics = record
    +    width : FT_Pos;
    +    height : FT_Pos;
    +    horiBearingX : FT_Pos;
    +    horiBearingY : FT_Pos;
    +    horiAdvance : FT_Pos;
    +    vertBearingX : FT_Pos;
    +    vertBearingY : FT_Pos;
    +    vertAdvance : FT_Pos;
    +  end;
    +
    +  FT_Bitmap_Size = record
    +    height : FT_Short;
    +    width : FT_Short;
    +  end;
    +  AFT_Bitmap_Size = array [0..1023] of FT_Bitmap_Size;
    +  PFT_Bitmap_Size = ^AFT_Bitmap_Size;
    +
    +  FT_Vector = record
    +    x : FT_Pos;
    +    y : FT_Pos;
    +  end;
    +  PFT_Vector = ^FT_Vector;
    +
    +  FT_BBox = record
    +    xMin, yMin : FT_Pos;
    +    xMax, yMax : FT_Pos;
    +  end;
    +  PFT_BBox = ^FT_BBox;
    +
    +  FT_Bitmap = record
    +    rows : integer;
    +    width : integer;
    +    pitch : integer;
    +    buffer : pointer;
    +    num_grays : shortint;
    +    pixel_mode : char;
    +    palette_mode : char;
    +    palette : pointer;
    +  end;
    +
    +  FT_Outline = record
    +    n_contours,
    +    n_points : smallint;
    +    points : PFT_Vector;
    +    tags : pchar;
    +    contours : ^smallint;
    +    flags : integer;
    +  end;
    +  PFT_Outline = ^FT_Outline;
    +
    +  FT_Outline_MoveToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
    +  FT_Outline_LineToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
    +  FT_Outline_ConicToFunc = function(const control, to_: PFT_Vector; user: Pointer): integer;
    +  FT_Outline_CubicToFunc = function(const control1, control2, to_: PFT_Vector; user: Pointer): integer;
    +
    +  FT_Outline_Funcs = record
    +    move_to: FT_Outline_MoveToFunc;
    +    line_to: FT_Outline_LineToFunc;
    +    conic_to: FT_Outline_ConicToFunc;
    +    cubic_to: FT_Outline_CubicToFunc;
    +    shift: integer;
    +    delta: FT_Pos;
    +  end;
    +  PFT_Outline_Funcs = ^FT_Outline_Funcs;
    +
    +  FT_Size_Metrics = record
    +    x_ppem : FT_UShort;
    +    y_ppem : FT_UShort;
    +    x_scale : FT_Fixed;
    +    y_scale : FT_Fixed;
    +    ascender : FT_Pos;
    +    descender : FT_Pos;
    +    height : FT_Pos;
    +    max_advance : FT_Pos;
    +  end;
    +
    +
    +  PFT_Library = ^TFT_Library;
    +  //PPFT_Library = ^PFT_Library;
    +  PFT_Face = ^TFT_Face;
    +  //PPFT_Face = ^PFT_Face;
    +  PFT_Charmap = ^TFT_Charmap;
    +  PPFT_Charmap = ^PFT_Charmap;
    +  PFT_GlyphSlot = ^TFT_GlyphSlot;
    +  PFT_Subglyph = ^TFT_Subglyph;
    +  PFT_Size = ^TFT_Size;
    +
    +  PFT_Glyph = ^TFT_Glyph;
    +  //PPFT_Glyph = ^PFT_Glyph;
    +  PFT_BitmapGlyph = ^TFT_BitmapGlyph;
    +  PFT_OutlineGlyph = ^TFT_OutlineGlyph;
    +
    +
    +  TFT_Library = record
    +  end;
    +
    +  TFT_Charmap = record
    +    face : PFT_Face;
    +    encoding : FT_Encoding;
    +    platform_id, encoding_id : FT_UShort;
    +  end;
    +
    +  TFT_Size = record
    +    face : PFT_Face;
    +    generic : FT_Generic;
    +    metrics : FT_Size_Metrics;
    +    //internal : FT_Size_Internal;
    +  end;
    +
    +  TFT_Subglyph = record  // TODO
    +  end;
    +
    +  TFT_GlyphSlot = record
    +    alibrary : PFT_Library;
    +    face : PFT_Face;
    +    next : PFT_GlyphSlot;
    +    flags : FT_UInt;
    +    generic : FT_Generic;
    +    metrics : FT_Glyph_Metrics;
    +    linearHoriAdvance : FT_Fixed;
    +    linearVertAdvance : FT_Fixed;
    +    advance : FT_Vector;
    +    format : longword;
    +    bitmap : FT_Bitmap;
    +    bitmap_left : FT_Int;
    +    bitmap_top : FT_Int;
    +    outline : FT_Outline;
    +    num_subglyphs : FT_UInt;
    +    subglyphs : PFT_SubGlyph;
    +    control_data : pointer;
    +    control_len : longint;
    +    other : pointer;
    +  end;
    +
    +  TFT_Face = record
    +    num_faces : FT_Long;
    +    face_index : FT_Long;
    +    face_flags : FT_Long;
    +    style_flags : FT_Long;
    +    num_glyphs : FT_Long;
    +    family_name : pchar;
    +    style_name : pchar;
    +    num_fixed_sizes : FT_Int;
    +    available_sizes : PFT_Bitmap_Size;     // is array
    +    num_charmaps : FT_Int;
    +    charmaps : PPFT_CharMap;               // is array
    +    generic : FT_Generic;
    +    bbox : FT_BBox;
    +    units_per_EM : FT_UShort;
    +    ascender : FT_Short;
    +    descender : FT_Short;
    +    height : FT_Short;
    +    max_advance_width : FT_Short;
    +    max_advance_height : FT_Short;
    +    underline_position : FT_Short;
    +    underline_thickness : FT_Short;
    +    glyph : PFT_GlyphSlot;
    +    size : PFT_Size;
    +    charmap : PFT_CharMap;
    +  end;
    +
    +  TFT_Glyph = record
    +    FTlibrary : PFT_Library;
    +    clazz : pointer;
    +    aFormat : longword;
    +    advance : FT_Vector;
    +  end;
    +
    +  TFT_BitmapGlyph = record
    +    root : TFT_Glyph;
    +    left, top : FT_Int;
    +    bitmap : FT_Bitmap;
    +  end;
    +
    +  TFT_OutlineGlyph = record
    +    root : TFT_Glyph;
    +    outline : FT_Outline;
    +  end;
    +
    +//Base Interface
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Done_Face(face: PFT_Face){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Done_Face';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Done_FreeType(alibrary: PFT_Library){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Done_FreeType';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Get_Char_Index(face: PFT_Face; charcode: FT_ULong){$IFDEF D}: function{$ENDIF}(): FT_UInt; cdecl; {$IFDEF S}external freetypedll Name 'FT_Get_Char_Index';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Get_Kerning(face: PFT_Face; left_glyph, right_glyph, kern_mode: FT_UInt; out akerning: FT_Vector){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Get_Kerning';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Init_FreeType(var alibrary: PFT_Library){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Init_FreeType';{$ENDIF}
    +function FT_IS_SCALABLE(face: PFT_Face): boolean;
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Load_Char(face: PFT_Face; charcode: FT_ULong; load_flags: longint){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Load_Char';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Load_Glyph(face: PFT_Face; glyph_index: FT_UInt; load_flags: longint){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Load_Glyph';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_New_Face(alibrary: PFT_Library; filepathname: PChar; face_index: integer; var aface: PFT_Face){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_New_Face';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Set_Char_Size(face: PFT_Face; char_width, char_height: FT_F26dot6; horz_res, vert_res: FT_UInt){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Set_Char_Size';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Set_Pixel_Sizes(face: PFT_Face; pixel_width, pixel_height: FT_UInt){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Set_Pixel_Sizes';{$ENDIF}
    +{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Set_Transform(face: PFT_Face; matrix: PFT_Matrix; delta: PFT_Vector); cdecl; {$IFDEF S}external freetypedll Name 'FT_Set_Transform';{$ENDIF}
    +
    +//Outline Processing
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Outline_Decompose(outline: PFT_Outline; const func_interface: PFT_Outline_Funcs; user: Pointer){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Outline_Decompose';{$ENDIF}
    +
    +//FreeType Version
    +{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Library_Version(alibrary: PFT_Library; var amajor, aminor, apatch: integer); cdecl; {$IFDEF S}external freetypedll Name 'FT_Library_Version';{$ENDIF}
    +
    +//Glyph Management
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Get_Glyph(slot: PFT_GlyphSlot; out aglyph: PFT_Glyph){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Get_Glyph';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Glyph_Copy(Source: PFT_Glyph; out target: PFT_Glyph){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_Copy';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Glyph_To_Bitmap(var the_glyph: PFT_Glyph; render_mode: FT_Render_Mode; origin: PFT_Vector; Destroy: FT_Bool){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_To_Bitmap';{$ENDIF}
    +{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Glyph_Transform(glyph: PFT_Glyph; matrix: PFT_Matrix; delta: PFT_Vector){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_Transform';{$ENDIF}
    +{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Done_Glyph(glyph: PFT_Glyph); cdecl; {$IFDEF S}external freetypedll Name 'FT_Done_Glyph';{$ENDIF}
    +{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Glyph_Get_CBox(glyph: PFT_Glyph; bbox_mode: FT_UInt; var acbox: FT_BBox); cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_Get_CBox';{$ENDIF}
    +
    +{$IFDEF D}
    +function InitializeFreetypeANSI(const LibraryName: AnsiString = ''): Integer; //needed as TLibraryLoadFunction
    +function InitializeFreetype(const LibraryName: UnicodeString = ''): Integer;
    +function TryInitializeFreetype(const LibraryName: Unicodestring = ''): Integer;
    +function ReleaseFreetype: Integer;
    +procedure ReleaseFreetype; //needed as TLibraryUnLoadFunction
    +
    +var
    +  FreetypeLibraryHandle: TLibHandle;
    +  FreetypeDefaultLibrary: String = freetypedll;
    +  FreetypeLoadedLibrary: UnicodeString;
    +{$ENDIF D}
    +
    +implementation
    +
    +function FT_IS_SCALABLE(face: PFT_Face): boolean;
    +begin
    +  Result := (face^.face_flags and FT_FACE_FLAG_SCALABLE) = 1;
    +end;
    +
    +{$IFDEF D}
    +
    +resourcestring
    +  SErrLoadFailed     = 'Can not load Freetype library "%s". Check your installation.';
    +  SErrAlreadyLoaded  = 'Freetype interface already initialized from library %s.';
    +
    +procedure LoadAddresses(LibHandle: TLibHandle);
    +begin
    +  pointer(FT_Done_FreeType) := GetProcedureAddress(LibHandle,'FT_Done_FreeType');
    +  pointer(FT_Get_Char_Index) := GetProcedureAddress(LibHandle,'FT_Get_Char_Index');
    +  pointer(FT_Get_Kerning) := GetProcedureAddress(LibHandle,'FT_Get_Kerning');
    +  pointer(FT_Init_FreeType) := GetProcedureAddress(LibHandle,'FT_Init_FreeType');
    +  pointer(FT_Load_Char) := GetProcedureAddress(LibHandle,'FT_Load_Char');
    +  pointer(FT_Load_Glyph) := GetProcedureAddress(LibHandle,'FT_Load_Glyph');
    +  pointer(FT_New_Face) := GetProcedureAddress(LibHandle,'FT_New_Face';);
    +  pointer(FT_Set_Char_Size) := GetProcedureAddress(LibHandle,'FT_Set_Char_Size');
    +  pointer(FT_Set_Pixel_Sizes) := GetProcedureAddress(LibHandle,'FT_Set_Pixel_Sizes');
    +  pointer(FT_Set_Transform) := GetProcedureAddress(LibHandle,'FT_Set_Transform');
    +  pointer(FT_Outline_Decompose) := GetProcedureAddress(LibHandle,'FT_Outline_Decompose');
    +  pointer(FT_Library_Version) := GetProcedureAddress(LibHandle,'FT_Library_Version');
    +  pointer(FT_Get_Glyph) := GetProcedureAddress(LibHandle,'FT_Get_Glyph');
    +  pointer(FT_Glyph_Copy) := GetProcedureAddress(LibHandle,'FT_Glyph_Copy');
    +  pointer(FT_Glyph_To_Bitmap) := GetProcedureAddress(LibHandle,'FT_Glyph_To_Bitmap');
    +  pointer(FT_Glyph_Transform) := GetProcedureAddress(LibHandle,'FT_Glyph_Transform');
    +  pointer(FT_Done_Glyph) := GetProcedureAddress(LibHandle,'FT_Done_Glyph');
    +  pointer(FT_Glyph_Get_CBox) := GetProcedureAddress(LibHandle,'FT_Glyph_Get_CBox');
    +end;
    +
    +var
    +  RefCount: Integer;
    +
    +function TryInitializeFreetype(const LibraryName: UnicodeString): Integer;
    +
    +Var
    +  N  : UnicodeString;
    +begin
    +  N:=LibraryName;
    +  if (N='') then
    +    N:=FreetypeDefaultLibrary;
    +  result:=InterlockedIncrement(RefCount);
    +  if result  = 1 then
    +  begin
    +    FreetypeLibraryHandle := LoadLibrary(N);
    +    if (FreetypeLibraryHandle = NilHandle) then
    +    begin
    +      RefCount := 0;
    +      Exit(-1);
    +    end;
    +    FreetypeLoadedLibrary := N;
    +    LoadAddresses(FreetypeLibraryHandle);
    +  end;
    +end;
    +
    +function  InitializeFreetype(const LibraryName: UnicodeString) :integer;
    +begin
    +  if (LibraryName<>'') and (FreetypeLoadedLibrary <> '') and (FreetypeLoadedLibrary <> LibraryName) then
    +    raise EInoutError.CreateFmt(SErrAlreadyLoaded,[FreetypeLoadedLibrary]);
    +
    +  result:= TryInitializeFreetype(LibraryName);
    +  if result=-1 then
    +    if LibraryName='' then
    +      raise EInOutError.CreateFmt(SErrLoadFailed,[FreetypeDefaultLibrary])
    +    else
    +      raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
    +end;
    +
    +function  InitializeFreetypeANSI(const LibraryName: AnsiString):integer;
    +begin
    +  result:=InitializeFreetype(LibraryName);
    +end;
    +
    +function ReleaseFreetype:integer;
    +begin
    +  if InterlockedDecrement(RefCount) <= 0 then
    +  begin
    +    if FreetypeLibraryHandle <> NilHandle then
    +      UnloadLibrary(FreetypeLibraryHandle);
    +    FreetypeLibraryHandle := NilHandle;
    +    FreetypeLoadedLibrary := '';
    +    RefCount := 0;
    +  end;
    +end;
    +
    +procedure ReleaseFreetype;
    +begin
    +  ReleaseFreetype;
    +end;
    +
    +{$ENDIF D}
    +
    +
    Index: packages/fcl-image/src/freetypeh.pp
    ===================================================================
    --- packages/fcl-image/src/freetypeh.pp	(revision 37325)
    +++ packages/fcl-image/src/freetypeh.pp	(working copy)
    @@ -15,378 +15,6 @@
     {$mode objfpc}
     unit freetypeh;
     
    -{ Note that these are not all the availlable calls from the dll yet.
    -  This unit is used by TStringBitMaps and FTFont }
    +{$i freetype.inc}
     
    -interface
    -
    -const
    -
    -{$packrecords c}
    -
    -// Windows
    -{$ifdef windows}
    -  freetypedll = 'freetype-6.dll';   // version 2.1.4
    -  {$define ft_found_platform}
    -{$endif}
    -// Mac OS X
    -{$ifdef darwin}
    -  freetypedll = 'libfreetype'; // Doesn't seam to matter much.
    -  {$linklib freetype}          // This one is the important part,
    -                               // but you also need to pass to fpc
    -                               // the following command:
    -                               // -k-L/usr/X11/lib
    -                               // or another place where it can find
    -                               // libfreetype.dylib
    -  {$define ft_found_platform}
    -{$endif}
    -// LINUX
    -{$if defined(UNIX) and not defined(darwin)}
    -  freetypedll = 'freetype';
    -  {$define ft_found_platform}
    -{$endif}
    -// Other platforms
    -{$ifndef ft_found_platform}
    -  freetypedll = 'freetype';
    -{$endif}
    -
    -type
    -  FT_Encoding = array[0..3] of char;
    -
    -const
    -  FT_FACE_FLAG_SCALABLE = 1 shl 0;
    -  FT_FACE_FLAG_FIXED_SIZES = 1 shl 1;
    -  FT_FACE_FLAG_FIXED_WIDTH = 1 shl 2;
    -  FT_FACE_FLAG_SFNT = 1 shl 3;
    -  FT_FACE_FLAG_HORIZONTAL = 1 shl 4;
    -  FT_FACE_FLAG_VERTICAL = 1 shl 5;
    -  FT_FACE_FLAG_KERNING = 1 shl 6;
    -  FT_FACE_FLAG_FAST_GLYPHS = 1 shl 7;
    -  FT_FACE_FLAG_MULTIPLE_MASTERS = 1 shl 8;
    -  FT_FACE_FLAG_GLYPH_NAMES = 1 shl 9;
    -  FT_FACE_FLAG_EXTERNAL_STREAM = 1 shl 10;
    -
    -  FT_STYLE_FLAG_ITALIC = 1 shl 0;
    -  FT_STYLE_FLAG_BOLD = 1 shl 1;
    -
    -  FT_LOAD_DEFAULT =          $0000;
    -  FT_LOAD_NO_SCALE =         $0001;
    -  FT_LOAD_NO_HINTING =       $0002;
    -  FT_LOAD_RENDER =           $0004;
    -  FT_LOAD_NO_BITMAP =        $0008;
    -  FT_LOAD_VERTICAL_LAYOUT =  $0010;
    -  FT_LOAD_FORCE_AUTOHINT =   $0020;
    -  FT_LOAD_CROP_BITMAP =      $0040;
    -  FT_LOAD_PEDANTIC =         $0080;
    -  FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = $0200;
    -  FT_LOAD_NO_RECURSE =       $0400;
    -  FT_LOAD_IGNORE_TRANSFORM = $0800;
    -  FT_LOAD_MONOCHROME =       $1000;
    -  FT_LOAD_LINEAR_DESIGN =    $2000;
    -
    -  ft_glyph_format_none      = $00000000;
    -  ft_glyph_format_composite = $636F6D70; //comp 099 111 109 112
    -  ft_glyph_format_bitmap    = $62697473; //bits 098 105 116 115
    -  ft_glyph_format_outline   = $6F75746C; //outl 111 117 116 108
    -  ft_glyph_format_plotter   = $706C6F74; //plot 112 108 111 116
    -
    -  FT_ENCODING_MS_SYMBOL : FT_Encoding = 'symb';
    -  FT_ENCODING_UNICODE : FT_Encoding = 'unic';
    -  FT_ENCODING_MS_SJIS : FT_Encoding = 'sjis';
    -  FT_ENCODING_MS_GB2312 : FT_Encoding = 'gb  ';
    -  FT_ENCODING_MS_BIG5 : FT_Encoding = 'big5';
    -  FT_ENCODING_MS_WANSUNG : FT_Encoding = 'wans';
    -  FT_ENCODING_MS_JOHAB : FT_Encoding = 'joha';
    -  FT_ENCODING_ADOBE_STANDARD : FT_Encoding = 'ADOB';
    -  FT_ENCODING_ADOBE_EXPERT : FT_Encoding = 'ADBE';
    -  FT_ENCODING_ADOBE_CUSTOM : FT_Encoding = 'ADBC';
    -  FT_ENCODING_ADOBE_LATIN_1 : FT_Encoding = 'lat1';
    -  FT_ENCODING_OLD_LATIN_2 : FT_Encoding = 'lat2';
    -  FT_ENCODING_APPLE_ROMAN : FT_Encoding = 'armn';
    -
    -  ft_glyph_bbox_unscaled  = 0; //* return unscaled font units           */
    -  ft_glyph_bbox_subpixels = 0; //* return unfitted 26.6 coordinates     */
    -  ft_glyph_bbox_gridfit   = 1; //* return grid-fitted 26.6 coordinates  */
    -  ft_glyph_bbox_truncate  = 2; //* return coordinates in integer pixels */
    -  ft_glyph_bbox_pixels    = 3; //* return grid-fitted pixel coordinates */
    -
    -  FT_KERNING_DEFAULT  = 0;
    -  FT_KERNING_UNFITTED = 1;
    -  FT_KERNING_UNSCALED = 2;
    -
    -
    -type
    -
    -  FT_Bool = boolean;
    -  FT_FWord = smallint;
    -  FT_UFWord = word;
    -  FT_Char = char;
    -  FT_Byte = byte;
    -  FT_String = char;
    -  FT_Short = smallint;
    -  FT_UShort = word;
    -  FT_Int = longint;
    -  FT_UInt = longword;
    -  {$if defined(cpu64) and not(defined(win64) and defined(cpux86_64))}
    -  FT_Long = int64;
    -  FT_ULong = qword;
    -  FT_Pos = int64;
    -  {$ELSE}
    -  FT_Long = longint;
    -  FT_ULong = longword;
    -  FT_Pos = longint;
    -  {$ENDIF}
    -  FT_F2Dot14 = smallint;
    -  FT_F26Dot6 = longint;
    -  FT_Fixed = FT_Long;
    -  FT_Error = longint;
    -  FT_Pointer = pointer;
    -  //FT_Offset = size_t;
    -  //FT_PtrDist = size_t;
    -
    -  FT_Render_Mode = (FT_RENDER_MODE_NORMAL, FT_RENDER_MODE_LIGHT,
    -      FT_RENDER_MODE_MONO, FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V,
    -      FT_RENDER_MODE_MAX);
    -
    -  FT_UnitVector_ = record
    -      x : FT_F2Dot14;
    -      y : FT_F2Dot14;
    -   end;
    -  FT_UnitVector = FT_UnitVector_;
    -
    -  FT_Matrix = record
    -      xx : FT_Fixed;
    -      xy : FT_Fixed;
    -      yx : FT_Fixed;
    -      yy : FT_Fixed;
    -   end;
    -  PFT_Matrix = ^FT_Matrix;
    -
    -  FT_Data = record
    -      pointer : ^FT_Byte;
    -      length : FT_Int;
    -   end;
    -
    -  FT_Generic_Finalizer = procedure (AnObject:pointer);cdecl;
    -
    -  FT_Generic = record
    -      data : pointer;
    -      finalizer : FT_Generic_Finalizer;
    -   end;
    -
    -  FT_Glyph_Metrics = record
    -    width : FT_Pos;
    -    height : FT_Pos;
    -    horiBearingX : FT_Pos;
    -    horiBearingY : FT_Pos;
    -    horiAdvance : FT_Pos;
    -    vertBearingX : FT_Pos;
    -    vertBearingY : FT_Pos;
    -    vertAdvance : FT_Pos;
    -  end;
    -
    -  FT_Bitmap_Size = record
    -    height : FT_Short;
    -    width : FT_Short;
    -  end;
    -  AFT_Bitmap_Size = array [0..1023] of FT_Bitmap_Size;
    -  PFT_Bitmap_Size = ^AFT_Bitmap_Size;
    -
    -  FT_Vector = record
    -    x : FT_Pos;
    -    y : FT_Pos;
    -  end;
    -  PFT_Vector = ^FT_Vector;
    -
    -  FT_BBox = record
    -    xMin, yMin : FT_Pos;
    -    xMax, yMax : FT_Pos;
    -  end;
    -  PFT_BBox = ^FT_BBox;
    -
    -  FT_Bitmap = record
    -    rows : integer;
    -    width : integer;
    -    pitch : integer;
    -    buffer : pointer;
    -    num_grays : shortint;
    -    pixel_mode : char;
    -    palette_mode : char;
    -    palette : pointer;
    -  end;
    -
    -  FT_Outline = record
    -    n_contours,
    -    n_points : smallint;
    -    points : PFT_Vector;
    -    tags : pchar;
    -    contours : ^smallint;
    -    flags : integer;
    -  end;
    -  PFT_Outline = ^FT_Outline;
    -
    -  FT_Outline_MoveToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
    -  FT_Outline_LineToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
    -  FT_Outline_ConicToFunc = function(const control, to_: PFT_Vector; user: Pointer): integer;
    -  FT_Outline_CubicToFunc = function(const control1, control2, to_: PFT_Vector; user: Pointer): integer;
    -
    -  FT_Outline_Funcs = record
    -    move_to: FT_Outline_MoveToFunc;
    -    line_to: FT_Outline_LineToFunc;
    -    conic_to: FT_Outline_ConicToFunc;
    -    cubic_to: FT_Outline_CubicToFunc;
    -    shift: integer;
    -    delta: FT_Pos;
    -  end;
    -  PFT_Outline_Funcs = ^FT_Outline_Funcs;
    -
    -  FT_Size_Metrics = record
    -    x_ppem : FT_UShort;
    -    y_ppem : FT_UShort;
    -    x_scale : FT_Fixed;
    -    y_scale : FT_Fixed;
    -    ascender : FT_Pos;
    -    descender : FT_Pos;
    -    height : FT_Pos;
    -    max_advance : FT_Pos;
    -  end;
    -
    -
    -  PFT_Library = ^TFT_Library;
    -  //PPFT_Library = ^PFT_Library;
    -  PFT_Face = ^TFT_Face;
    -  //PPFT_Face = ^PFT_Face;
    -  PFT_Charmap = ^TFT_Charmap;
    -  PPFT_Charmap = ^PFT_Charmap;
    -  PFT_GlyphSlot = ^TFT_GlyphSlot;
    -  PFT_Subglyph = ^TFT_Subglyph;
    -  PFT_Size = ^TFT_Size;
    -
    -  PFT_Glyph = ^TFT_Glyph;
    -  //PPFT_Glyph = ^PFT_Glyph;
    -  PFT_BitmapGlyph = ^TFT_BitmapGlyph;
    -  PFT_OutlineGlyph = ^TFT_OutlineGlyph;
    -
    -
    -  TFT_Library = record
    -  end;
    -
    -  TFT_Charmap = record
    -    face : PFT_Face;
    -    encoding : FT_Encoding;
    -    platform_id, encoding_id : FT_UShort;
    -  end;
    -
    -  TFT_Size = record
    -    face : PFT_Face;
    -    generic : FT_Generic;
    -    metrics : FT_Size_Metrics;
    -    //internal : FT_Size_Internal;
    -  end;
    -
    -  TFT_Subglyph = record  // TODO
    -  end;
    -
    -  TFT_GlyphSlot = record
    -    alibrary : PFT_Library;
    -    face : PFT_Face;
    -    next : PFT_GlyphSlot;
    -    flags : FT_UInt;
    -    generic : FT_Generic;
    -    metrics : FT_Glyph_Metrics;
    -    linearHoriAdvance : FT_Fixed;
    -    linearVertAdvance : FT_Fixed;
    -    advance : FT_Vector;
    -    format : longword;
    -    bitmap : FT_Bitmap;
    -    bitmap_left : FT_Int;
    -    bitmap_top : FT_Int;
    -    outline : FT_Outline;
    -    num_subglyphs : FT_UInt;
    -    subglyphs : PFT_SubGlyph;
    -    control_data : pointer;
    -    control_len : longint;
    -    other : pointer;
    -  end;
    -
    -  TFT_Face = record
    -    num_faces : FT_Long;
    -    face_index : FT_Long;
    -    face_flags : FT_Long;
    -    style_flags : FT_Long;
    -    num_glyphs : FT_Long;
    -    family_name : pchar;
    -    style_name : pchar;
    -    num_fixed_sizes : FT_Int;
    -    available_sizes : PFT_Bitmap_Size;     // is array
    -    num_charmaps : FT_Int;
    -    charmaps : PPFT_CharMap;               // is array
    -    generic : FT_Generic;
    -    bbox : FT_BBox;
    -    units_per_EM : FT_UShort;
    -    ascender : FT_Short;
    -    descender : FT_Short;
    -    height : FT_Short;
    -    max_advance_width : FT_Short;
    -    max_advance_height : FT_Short;
    -    underline_position : FT_Short;
    -    underline_thickness : FT_Short;
    -    glyph : PFT_GlyphSlot;
    -    size : PFT_Size;
    -    charmap : PFT_CharMap;
    -  end;
    -
    -  TFT_Glyph = record
    -    FTlibrary : PFT_Library;
    -    clazz : pointer;
    -    aFormat : longword;
    -    advance : FT_Vector;
    -  end;
    -
    -  TFT_BitmapGlyph = record
    -    root : TFT_Glyph;
    -    left, top : FT_Int;
    -    bitmap : FT_Bitmap;
    -  end;
    -
    -  TFT_OutlineGlyph = record
    -    root : TFT_Glyph;
    -    outline : FT_Outline;
    -  end;
    -
    -//Base Interface
    -function FT_Done_Face(face: PFT_Face): integer; cdecl; external freetypedll Name 'FT_Done_Face';
    -function FT_Done_FreeType(alibrary: PFT_Library): integer; cdecl; external freetypedll Name 'FT_Done_FreeType';
    -function FT_Get_Char_Index(face: PFT_Face; charcode: FT_ULong): FT_UInt; cdecl; external freetypedll Name 'FT_Get_Char_Index';
    -function FT_Get_Kerning(face: PFT_Face; left_glyph, right_glyph, kern_mode: FT_UInt; out akerning: FT_Vector): integer; cdecl; external freetypedll Name 'FT_Get_Kerning';
    -function FT_Init_FreeType(var alibrary: PFT_Library): integer; cdecl; external freetypedll Name 'FT_Init_FreeType';
    -function FT_IS_SCALABLE(face: PFT_Face): boolean;
    -function FT_Load_Char(face: PFT_Face; charcode: FT_ULong; load_flags: longint): integer; cdecl; external freetypedll Name 'FT_Load_Char';
    -function FT_Load_Glyph(face: PFT_Face; glyph_index: FT_UInt; load_flags: longint): integer; cdecl; external freetypedll Name 'FT_Load_Glyph';
    -function FT_New_Face(alibrary: PFT_Library; filepathname: PChar; face_index: integer; var aface: PFT_Face): integer; cdecl; external freetypedll Name 'FT_New_Face';
    -function FT_Set_Char_Size(face: PFT_Face; char_width, char_height: FT_F26dot6; horz_res, vert_res: FT_UInt): integer; cdecl; external freetypedll Name 'FT_Set_Char_Size';
    -function FT_Set_Pixel_Sizes(face: PFT_Face; pixel_width, pixel_height: FT_UInt): integer; cdecl; external freetypedll Name 'FT_Set_Pixel_Sizes';
    -procedure FT_Set_Transform(face: PFT_Face; matrix: PFT_Matrix; delta: PFT_Vector); cdecl; external freetypedll Name 'FT_Set_Transform';
    -
    -//Outline Processing
    -function FT_Outline_Decompose(outline: PFT_Outline; const func_interface: PFT_Outline_Funcs; user: Pointer): integer; cdecl; external freetypedll Name 'FT_Outline_Decompose';
    -
    -//FreeType Version
    -procedure FT_Library_Version(alibrary: PFT_Library; var amajor, aminor, apatch: integer); cdecl; external freetypedll Name 'FT_Library_Version';
    -
    -//Glyph Management
    -function FT_Get_Glyph(slot: PFT_GlyphSlot; out aglyph: PFT_Glyph): integer; cdecl; external freetypedll Name 'FT_Get_Glyph';
    -function FT_Glyph_Copy(Source: PFT_Glyph; out target: PFT_Glyph): integer; cdecl; external freetypedll Name 'FT_Glyph_Copy';
    -function FT_Glyph_To_Bitmap(var the_glyph: PFT_Glyph; render_mode: FT_Render_Mode; origin: PFT_Vector; Destroy: FT_Bool): integer; cdecl; external freetypedll Name 'FT_Glyph_To_Bitmap';
    -function FT_Glyph_Transform(glyph: PFT_Glyph; matrix: PFT_Matrix; delta: PFT_Vector): integer; cdecl; external freetypedll Name 'FT_Glyph_Transform';
    -procedure FT_Done_Glyph(glyph: PFT_Glyph); cdecl; external freetypedll Name 'FT_Done_Glyph';
    -procedure FT_Glyph_Get_CBox(glyph: PFT_Glyph; bbox_mode: FT_UInt; var acbox: FT_BBox); cdecl; external freetypedll Name 'FT_Glyph_Get_CBox';
    -
    -implementation
    -
    -function FT_IS_SCALABLE(face: PFT_Face): boolean;
    -begin
    -  Result := (face^.face_flags and FT_FACE_FLAG_SCALABLE) = 1;
    -end;
    -
     end.
    Index: packages/fcl-image/src/freetypehdyn.pp
    ===================================================================
    --- packages/fcl-image/src/freetypehdyn.pp	(nonexistent)
    +++ packages/fcl-image/src/freetypehdyn.pp	(working copy)
    @@ -0,0 +1,27 @@
    +{
    +    This file is part of the Free Pascal run time library.
    +    Copyright (c) 2003 by the Free Pascal development team
    +
    +    Basic canvas definitions.
    +
    +    See the file COPYING.FPC, included in this distribution,
    +    for details about the copyright.
    +
    +    This program is distributed in the hope that it will be useful,
    +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    +
    + **********************************************************************}
    +{$mode objfpc}
    +unit freetypehdyn;
    +
    +{$DEFINE LOAD_DYNAMICALLY}
    +{$i freetype.inc}
    +
    +initialization
    +  InitializeFreetype(freetypedll);
    +
    +finalization
    +  ReleaseFreetype;
    +
    +end.
    
    freetypeh.patch (32,689 bytes)

Activities

Andi Friess

2017-09-26 13:39

reporter  

freetypeh.patch (32,689 bytes)
Index: packages/fcl-image/src/freetype.pp
===================================================================
--- packages/fcl-image/src/freetype.pp	(revision 37325)
+++ packages/fcl-image/src/freetype.pp	(working copy)
@@ -17,7 +17,7 @@
 
 interface
 
-uses sysutils, classes, freetypeh, FPImgCmn;
+uses sysutils, classes, freetypehdyn, FPImgCmn;
 
 { TODO : take resolution in account to find the size }
 { TODO : speed optimization: search glyphs with a hash-function/tree/binary search/... }
Index: packages/fcl-image/src/freetypeh.inc
===================================================================
--- packages/fcl-image/src/freetypeh.inc	(nonexistent)
+++ packages/fcl-image/src/freetypeh.inc	(working copy)
@@ -0,0 +1,508 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2003 by the Free Pascal development team
+
+    Basic canvas definitions.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+{ Note that these are not all the availlable calls from the dll yet.
+  This unit is used by TStringBitMaps and FTFont }
+
+interface
+
+{$IFDEF LOAD_DYNAMICALLY}
+  {$DEFINE D}
+  {$UNDEF S}
+{$ELSE}
+  {$DEFINE S}
+  {$UNDEF D}
+{$ENDIF}
+
+
+{$ifdef D}
+uses
+  SysUtils, DynLibs;
+{$endif}
+
+const
+
+{$packrecords c}
+
+// Windows
+{$ifdef windows}
+  freetypedll = 'freetype-6.dll';   // version 2.1.4
+  {$define ft_found_platform}
+{$endif}
+// Mac OS X
+{$ifdef darwin}
+  freetypedll = 'libfreetype'; // Doesn't seam to matter much.
+  {$linklib freetype}          // This one is the important part,
+                               // but you also need to pass to fpc
+                               // the following command:
+                               // -k-L/usr/X11/lib
+                               // or another place where it can find
+                               // libfreetype.dylib
+  {$define ft_found_platform}
+{$endif}
+// LINUX
+{$if defined(UNIX) and not defined(darwin)}
+  freetypedll = 'freetype';
+  {$define ft_found_platform}
+{$endif}
+// Other platforms
+{$ifndef ft_found_platform}
+  freetypedll = 'freetype';
+{$endif}
+
+
+
+type
+  FT_Encoding = array[0..3] of char;
+
+const
+  FT_FACE_FLAG_SCALABLE = 1 shl 0;
+  FT_FACE_FLAG_FIXED_SIZES = 1 shl 1;
+  FT_FACE_FLAG_FIXED_WIDTH = 1 shl 2;
+  FT_FACE_FLAG_SFNT = 1 shl 3;
+  FT_FACE_FLAG_HORIZONTAL = 1 shl 4;
+  FT_FACE_FLAG_VERTICAL = 1 shl 5;
+  FT_FACE_FLAG_KERNING = 1 shl 6;
+  FT_FACE_FLAG_FAST_GLYPHS = 1 shl 7;
+  FT_FACE_FLAG_MULTIPLE_MASTERS = 1 shl 8;
+  FT_FACE_FLAG_GLYPH_NAMES = 1 shl 9;
+  FT_FACE_FLAG_EXTERNAL_STREAM = 1 shl 10;
+
+  FT_STYLE_FLAG_ITALIC = 1 shl 0;
+  FT_STYLE_FLAG_BOLD = 1 shl 1;
+
+  FT_LOAD_DEFAULT =          $0000;
+  FT_LOAD_NO_SCALE =         $0001;
+  FT_LOAD_NO_HINTING =       $0002;
+  FT_LOAD_RENDER =           $0004;
+  FT_LOAD_NO_BITMAP =        $0008;
+  FT_LOAD_VERTICAL_LAYOUT =  $0010;
+  FT_LOAD_FORCE_AUTOHINT =   $0020;
+  FT_LOAD_CROP_BITMAP =      $0040;
+  FT_LOAD_PEDANTIC =         $0080;
+  FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = $0200;
+  FT_LOAD_NO_RECURSE =       $0400;
+  FT_LOAD_IGNORE_TRANSFORM = $0800;
+  FT_LOAD_MONOCHROME =       $1000;
+  FT_LOAD_LINEAR_DESIGN =    $2000;
+
+  ft_glyph_format_none      = $00000000;
+  ft_glyph_format_composite = $636F6D70; //comp 099 111 109 112
+  ft_glyph_format_bitmap    = $62697473; //bits 098 105 116 115
+  ft_glyph_format_outline   = $6F75746C; //outl 111 117 116 108
+  ft_glyph_format_plotter   = $706C6F74; //plot 112 108 111 116
+
+  FT_ENCODING_MS_SYMBOL : FT_Encoding = 'symb';
+  FT_ENCODING_UNICODE : FT_Encoding = 'unic';
+  FT_ENCODING_MS_SJIS : FT_Encoding = 'sjis';
+  FT_ENCODING_MS_GB2312 : FT_Encoding = 'gb  ';
+  FT_ENCODING_MS_BIG5 : FT_Encoding = 'big5';
+  FT_ENCODING_MS_WANSUNG : FT_Encoding = 'wans';
+  FT_ENCODING_MS_JOHAB : FT_Encoding = 'joha';
+  FT_ENCODING_ADOBE_STANDARD : FT_Encoding = 'ADOB';
+  FT_ENCODING_ADOBE_EXPERT : FT_Encoding = 'ADBE';
+  FT_ENCODING_ADOBE_CUSTOM : FT_Encoding = 'ADBC';
+  FT_ENCODING_ADOBE_LATIN_1 : FT_Encoding = 'lat1';
+  FT_ENCODING_OLD_LATIN_2 : FT_Encoding = 'lat2';
+  FT_ENCODING_APPLE_ROMAN : FT_Encoding = 'armn';
+
+  ft_glyph_bbox_unscaled  = 0; //* return unscaled font units           */
+  ft_glyph_bbox_subpixels = 0; //* return unfitted 26.6 coordinates     */
+  ft_glyph_bbox_gridfit   = 1; //* return grid-fitted 26.6 coordinates  */
+  ft_glyph_bbox_truncate  = 2; //* return coordinates in integer pixels */
+  ft_glyph_bbox_pixels    = 3; //* return grid-fitted pixel coordinates */
+
+  FT_KERNING_DEFAULT  = 0;
+  FT_KERNING_UNFITTED = 1;
+  FT_KERNING_UNSCALED = 2;
+
+
+type
+
+  FT_Bool = boolean;
+  FT_FWord = smallint;
+  FT_UFWord = word;
+  FT_Char = char;
+  FT_Byte = byte;
+  FT_String = char;
+  FT_Short = smallint;
+  FT_UShort = word;
+  FT_Int = longint;
+  FT_UInt = longword;
+  {$if defined(cpu64) and not(defined(win64) and defined(cpux86_64))}
+  FT_Long = int64;
+  FT_ULong = qword;
+  FT_Pos = int64;
+  {$ELSE}
+  FT_Long = longint;
+  FT_ULong = longword;
+  FT_Pos = longint;
+  {$ENDIF}
+  FT_F2Dot14 = smallint;
+  FT_F26Dot6 = longint;
+  FT_Fixed = FT_Long;
+  FT_Error = longint;
+  FT_Pointer = pointer;
+  //FT_Offset = size_t;
+  //FT_PtrDist = size_t;
+
+  FT_Render_Mode = (FT_RENDER_MODE_NORMAL, FT_RENDER_MODE_LIGHT,
+      FT_RENDER_MODE_MONO, FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V,
+      FT_RENDER_MODE_MAX);
+
+  FT_UnitVector_ = record
+      x : FT_F2Dot14;
+      y : FT_F2Dot14;
+   end;
+  FT_UnitVector = FT_UnitVector_;
+
+  FT_Matrix = record
+      xx : FT_Fixed;
+      xy : FT_Fixed;
+      yx : FT_Fixed;
+      yy : FT_Fixed;
+   end;
+  PFT_Matrix = ^FT_Matrix;
+
+  FT_Data = record
+      pointer : ^FT_Byte;
+      length : FT_Int;
+   end;
+
+  FT_Generic_Finalizer = procedure (AnObject:pointer);cdecl;
+
+  FT_Generic = record
+      data : pointer;
+      finalizer : FT_Generic_Finalizer;
+   end;
+
+  FT_Glyph_Metrics = record
+    width : FT_Pos;
+    height : FT_Pos;
+    horiBearingX : FT_Pos;
+    horiBearingY : FT_Pos;
+    horiAdvance : FT_Pos;
+    vertBearingX : FT_Pos;
+    vertBearingY : FT_Pos;
+    vertAdvance : FT_Pos;
+  end;
+
+  FT_Bitmap_Size = record
+    height : FT_Short;
+    width : FT_Short;
+  end;
+  AFT_Bitmap_Size = array [0..1023] of FT_Bitmap_Size;
+  PFT_Bitmap_Size = ^AFT_Bitmap_Size;
+
+  FT_Vector = record
+    x : FT_Pos;
+    y : FT_Pos;
+  end;
+  PFT_Vector = ^FT_Vector;
+
+  FT_BBox = record
+    xMin, yMin : FT_Pos;
+    xMax, yMax : FT_Pos;
+  end;
+  PFT_BBox = ^FT_BBox;
+
+  FT_Bitmap = record
+    rows : integer;
+    width : integer;
+    pitch : integer;
+    buffer : pointer;
+    num_grays : shortint;
+    pixel_mode : char;
+    palette_mode : char;
+    palette : pointer;
+  end;
+
+  FT_Outline = record
+    n_contours,
+    n_points : smallint;
+    points : PFT_Vector;
+    tags : pchar;
+    contours : ^smallint;
+    flags : integer;
+  end;
+  PFT_Outline = ^FT_Outline;
+
+  FT_Outline_MoveToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
+  FT_Outline_LineToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
+  FT_Outline_ConicToFunc = function(const control, to_: PFT_Vector; user: Pointer): integer;
+  FT_Outline_CubicToFunc = function(const control1, control2, to_: PFT_Vector; user: Pointer): integer;
+
+  FT_Outline_Funcs = record
+    move_to: FT_Outline_MoveToFunc;
+    line_to: FT_Outline_LineToFunc;
+    conic_to: FT_Outline_ConicToFunc;
+    cubic_to: FT_Outline_CubicToFunc;
+    shift: integer;
+    delta: FT_Pos;
+  end;
+  PFT_Outline_Funcs = ^FT_Outline_Funcs;
+
+  FT_Size_Metrics = record
+    x_ppem : FT_UShort;
+    y_ppem : FT_UShort;
+    x_scale : FT_Fixed;
+    y_scale : FT_Fixed;
+    ascender : FT_Pos;
+    descender : FT_Pos;
+    height : FT_Pos;
+    max_advance : FT_Pos;
+  end;
+
+
+  PFT_Library = ^TFT_Library;
+  //PPFT_Library = ^PFT_Library;
+  PFT_Face = ^TFT_Face;
+  //PPFT_Face = ^PFT_Face;
+  PFT_Charmap = ^TFT_Charmap;
+  PPFT_Charmap = ^PFT_Charmap;
+  PFT_GlyphSlot = ^TFT_GlyphSlot;
+  PFT_Subglyph = ^TFT_Subglyph;
+  PFT_Size = ^TFT_Size;
+
+  PFT_Glyph = ^TFT_Glyph;
+  //PPFT_Glyph = ^PFT_Glyph;
+  PFT_BitmapGlyph = ^TFT_BitmapGlyph;
+  PFT_OutlineGlyph = ^TFT_OutlineGlyph;
+
+
+  TFT_Library = record
+  end;
+
+  TFT_Charmap = record
+    face : PFT_Face;
+    encoding : FT_Encoding;
+    platform_id, encoding_id : FT_UShort;
+  end;
+
+  TFT_Size = record
+    face : PFT_Face;
+    generic : FT_Generic;
+    metrics : FT_Size_Metrics;
+    //internal : FT_Size_Internal;
+  end;
+
+  TFT_Subglyph = record  // TODO
+  end;
+
+  TFT_GlyphSlot = record
+    alibrary : PFT_Library;
+    face : PFT_Face;
+    next : PFT_GlyphSlot;
+    flags : FT_UInt;
+    generic : FT_Generic;
+    metrics : FT_Glyph_Metrics;
+    linearHoriAdvance : FT_Fixed;
+    linearVertAdvance : FT_Fixed;
+    advance : FT_Vector;
+    format : longword;
+    bitmap : FT_Bitmap;
+    bitmap_left : FT_Int;
+    bitmap_top : FT_Int;
+    outline : FT_Outline;
+    num_subglyphs : FT_UInt;
+    subglyphs : PFT_SubGlyph;
+    control_data : pointer;
+    control_len : longint;
+    other : pointer;
+  end;
+
+  TFT_Face = record
+    num_faces : FT_Long;
+    face_index : FT_Long;
+    face_flags : FT_Long;
+    style_flags : FT_Long;
+    num_glyphs : FT_Long;
+    family_name : pchar;
+    style_name : pchar;
+    num_fixed_sizes : FT_Int;
+    available_sizes : PFT_Bitmap_Size;     // is array
+    num_charmaps : FT_Int;
+    charmaps : PPFT_CharMap;               // is array
+    generic : FT_Generic;
+    bbox : FT_BBox;
+    units_per_EM : FT_UShort;
+    ascender : FT_Short;
+    descender : FT_Short;
+    height : FT_Short;
+    max_advance_width : FT_Short;
+    max_advance_height : FT_Short;
+    underline_position : FT_Short;
+    underline_thickness : FT_Short;
+    glyph : PFT_GlyphSlot;
+    size : PFT_Size;
+    charmap : PFT_CharMap;
+  end;
+
+  TFT_Glyph = record
+    FTlibrary : PFT_Library;
+    clazz : pointer;
+    aFormat : longword;
+    advance : FT_Vector;
+  end;
+
+  TFT_BitmapGlyph = record
+    root : TFT_Glyph;
+    left, top : FT_Int;
+    bitmap : FT_Bitmap;
+  end;
+
+  TFT_OutlineGlyph = record
+    root : TFT_Glyph;
+    outline : FT_Outline;
+  end;
+
+//Base Interface
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Done_Face(face: PFT_Face){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Done_Face';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Done_FreeType(alibrary: PFT_Library){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Done_FreeType';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Get_Char_Index(face: PFT_Face; charcode: FT_ULong){$IFDEF D}: function{$ENDIF}(): FT_UInt; cdecl; {$IFDEF S}external freetypedll Name 'FT_Get_Char_Index';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Get_Kerning(face: PFT_Face; left_glyph, right_glyph, kern_mode: FT_UInt; out akerning: FT_Vector){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Get_Kerning';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Init_FreeType(var alibrary: PFT_Library){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Init_FreeType';{$ENDIF}
+function FT_IS_SCALABLE(face: PFT_Face): boolean;
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Load_Char(face: PFT_Face; charcode: FT_ULong; load_flags: longint){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Load_Char';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Load_Glyph(face: PFT_Face; glyph_index: FT_UInt; load_flags: longint){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Load_Glyph';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_New_Face(alibrary: PFT_Library; filepathname: PChar; face_index: integer; var aface: PFT_Face){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_New_Face';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Set_Char_Size(face: PFT_Face; char_width, char_height: FT_F26dot6; horz_res, vert_res: FT_UInt){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Set_Char_Size';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Set_Pixel_Sizes(face: PFT_Face; pixel_width, pixel_height: FT_UInt){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Set_Pixel_Sizes';{$ENDIF}
+{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Set_Transform(face: PFT_Face; matrix: PFT_Matrix; delta: PFT_Vector); cdecl; {$IFDEF S}external freetypedll Name 'FT_Set_Transform';{$ENDIF}
+
+//Outline Processing
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Outline_Decompose(outline: PFT_Outline; const func_interface: PFT_Outline_Funcs; user: Pointer){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Outline_Decompose';{$ENDIF}
+
+//FreeType Version
+{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Library_Version(alibrary: PFT_Library; var amajor, aminor, apatch: integer); cdecl; {$IFDEF S}external freetypedll Name 'FT_Library_Version';{$ENDIF}
+
+//Glyph Management
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Get_Glyph(slot: PFT_GlyphSlot; out aglyph: PFT_Glyph){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Get_Glyph';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Glyph_Copy(Source: PFT_Glyph; out target: PFT_Glyph){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_Copy';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Glyph_To_Bitmap(var the_glyph: PFT_Glyph; render_mode: FT_Render_Mode; origin: PFT_Vector; Destroy: FT_Bool){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_To_Bitmap';{$ENDIF}
+{$IFDEF S}function{$ELSE}var{$ENDIF} FT_Glyph_Transform(glyph: PFT_Glyph; matrix: PFT_Matrix; delta: PFT_Vector){$IFDEF D}: function{$ENDIF}(): integer; cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_Transform';{$ENDIF}
+{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Done_Glyph(glyph: PFT_Glyph); cdecl; {$IFDEF S}external freetypedll Name 'FT_Done_Glyph';{$ENDIF}
+{$IFDEF S}procedure{$ELSE}var{$ENDIF} FT_Glyph_Get_CBox(glyph: PFT_Glyph; bbox_mode: FT_UInt; var acbox: FT_BBox); cdecl; {$IFDEF S}external freetypedll Name 'FT_Glyph_Get_CBox';{$ENDIF}
+
+{$IFDEF D}
+function InitializeFreetypeANSI(const LibraryName: AnsiString = ''): Integer; //needed as TLibraryLoadFunction
+function InitializeFreetype(const LibraryName: UnicodeString = ''): Integer;
+function TryInitializeFreetype(const LibraryName: Unicodestring = ''): Integer;
+function ReleaseFreetype: Integer;
+procedure ReleaseFreetype; //needed as TLibraryUnLoadFunction
+
+var
+  FreetypeLibraryHandle: TLibHandle;
+  FreetypeDefaultLibrary: String = freetypedll;
+  FreetypeLoadedLibrary: UnicodeString;
+{$ENDIF D}
+
+implementation
+
+function FT_IS_SCALABLE(face: PFT_Face): boolean;
+begin
+  Result := (face^.face_flags and FT_FACE_FLAG_SCALABLE) = 1;
+end;
+
+{$IFDEF D}
+
+resourcestring
+  SErrLoadFailed     = 'Can not load Freetype library "%s". Check your installation.';
+  SErrAlreadyLoaded  = 'Freetype interface already initialized from library %s.';
+
+procedure LoadAddresses(LibHandle: TLibHandle);
+begin
+  pointer(FT_Done_FreeType) := GetProcedureAddress(LibHandle,'FT_Done_FreeType');
+  pointer(FT_Get_Char_Index) := GetProcedureAddress(LibHandle,'FT_Get_Char_Index');
+  pointer(FT_Get_Kerning) := GetProcedureAddress(LibHandle,'FT_Get_Kerning');
+  pointer(FT_Init_FreeType) := GetProcedureAddress(LibHandle,'FT_Init_FreeType');
+  pointer(FT_Load_Char) := GetProcedureAddress(LibHandle,'FT_Load_Char');
+  pointer(FT_Load_Glyph) := GetProcedureAddress(LibHandle,'FT_Load_Glyph');
+  pointer(FT_New_Face) := GetProcedureAddress(LibHandle,'FT_New_Face';);
+  pointer(FT_Set_Char_Size) := GetProcedureAddress(LibHandle,'FT_Set_Char_Size');
+  pointer(FT_Set_Pixel_Sizes) := GetProcedureAddress(LibHandle,'FT_Set_Pixel_Sizes');
+  pointer(FT_Set_Transform) := GetProcedureAddress(LibHandle,'FT_Set_Transform');
+  pointer(FT_Outline_Decompose) := GetProcedureAddress(LibHandle,'FT_Outline_Decompose');
+  pointer(FT_Library_Version) := GetProcedureAddress(LibHandle,'FT_Library_Version');
+  pointer(FT_Get_Glyph) := GetProcedureAddress(LibHandle,'FT_Get_Glyph');
+  pointer(FT_Glyph_Copy) := GetProcedureAddress(LibHandle,'FT_Glyph_Copy');
+  pointer(FT_Glyph_To_Bitmap) := GetProcedureAddress(LibHandle,'FT_Glyph_To_Bitmap');
+  pointer(FT_Glyph_Transform) := GetProcedureAddress(LibHandle,'FT_Glyph_Transform');
+  pointer(FT_Done_Glyph) := GetProcedureAddress(LibHandle,'FT_Done_Glyph');
+  pointer(FT_Glyph_Get_CBox) := GetProcedureAddress(LibHandle,'FT_Glyph_Get_CBox');
+end;
+
+var
+  RefCount: Integer;
+
+function TryInitializeFreetype(const LibraryName: UnicodeString): Integer;
+
+Var
+  N  : UnicodeString;
+begin
+  N:=LibraryName;
+  if (N='') then
+    N:=FreetypeDefaultLibrary;
+  result:=InterlockedIncrement(RefCount);
+  if result  = 1 then
+  begin
+    FreetypeLibraryHandle := LoadLibrary(N);
+    if (FreetypeLibraryHandle = NilHandle) then
+    begin
+      RefCount := 0;
+      Exit(-1);
+    end;
+    FreetypeLoadedLibrary := N;
+    LoadAddresses(FreetypeLibraryHandle);
+  end;
+end;
+
+function  InitializeFreetype(const LibraryName: UnicodeString) :integer;
+begin
+  if (LibraryName<>'') and (FreetypeLoadedLibrary <> '') and (FreetypeLoadedLibrary <> LibraryName) then
+    raise EInoutError.CreateFmt(SErrAlreadyLoaded,[FreetypeLoadedLibrary]);
+
+  result:= TryInitializeFreetype(LibraryName);
+  if result=-1 then
+    if LibraryName='' then
+      raise EInOutError.CreateFmt(SErrLoadFailed,[FreetypeDefaultLibrary])
+    else
+      raise EInOutError.CreateFmt(SErrLoadFailed,[LibraryName]);
+end;
+
+function  InitializeFreetypeANSI(const LibraryName: AnsiString):integer;
+begin
+  result:=InitializeFreetype(LibraryName);
+end;
+
+function ReleaseFreetype:integer;
+begin
+  if InterlockedDecrement(RefCount) <= 0 then
+  begin
+    if FreetypeLibraryHandle <> NilHandle then
+      UnloadLibrary(FreetypeLibraryHandle);
+    FreetypeLibraryHandle := NilHandle;
+    FreetypeLoadedLibrary := '';
+    RefCount := 0;
+  end;
+end;
+
+procedure ReleaseFreetype;
+begin
+  ReleaseFreetype;
+end;
+
+{$ENDIF D}
+
+
Index: packages/fcl-image/src/freetypeh.pp
===================================================================
--- packages/fcl-image/src/freetypeh.pp	(revision 37325)
+++ packages/fcl-image/src/freetypeh.pp	(working copy)
@@ -15,378 +15,6 @@
 {$mode objfpc}
 unit freetypeh;
 
-{ Note that these are not all the availlable calls from the dll yet.
-  This unit is used by TStringBitMaps and FTFont }
+{$i freetype.inc}
 
-interface
-
-const
-
-{$packrecords c}
-
-// Windows
-{$ifdef windows}
-  freetypedll = 'freetype-6.dll';   // version 2.1.4
-  {$define ft_found_platform}
-{$endif}
-// Mac OS X
-{$ifdef darwin}
-  freetypedll = 'libfreetype'; // Doesn't seam to matter much.
-  {$linklib freetype}          // This one is the important part,
-                               // but you also need to pass to fpc
-                               // the following command:
-                               // -k-L/usr/X11/lib
-                               // or another place where it can find
-                               // libfreetype.dylib
-  {$define ft_found_platform}
-{$endif}
-// LINUX
-{$if defined(UNIX) and not defined(darwin)}
-  freetypedll = 'freetype';
-  {$define ft_found_platform}
-{$endif}
-// Other platforms
-{$ifndef ft_found_platform}
-  freetypedll = 'freetype';
-{$endif}
-
-type
-  FT_Encoding = array[0..3] of char;
-
-const
-  FT_FACE_FLAG_SCALABLE = 1 shl 0;
-  FT_FACE_FLAG_FIXED_SIZES = 1 shl 1;
-  FT_FACE_FLAG_FIXED_WIDTH = 1 shl 2;
-  FT_FACE_FLAG_SFNT = 1 shl 3;
-  FT_FACE_FLAG_HORIZONTAL = 1 shl 4;
-  FT_FACE_FLAG_VERTICAL = 1 shl 5;
-  FT_FACE_FLAG_KERNING = 1 shl 6;
-  FT_FACE_FLAG_FAST_GLYPHS = 1 shl 7;
-  FT_FACE_FLAG_MULTIPLE_MASTERS = 1 shl 8;
-  FT_FACE_FLAG_GLYPH_NAMES = 1 shl 9;
-  FT_FACE_FLAG_EXTERNAL_STREAM = 1 shl 10;
-
-  FT_STYLE_FLAG_ITALIC = 1 shl 0;
-  FT_STYLE_FLAG_BOLD = 1 shl 1;
-
-  FT_LOAD_DEFAULT =          $0000;
-  FT_LOAD_NO_SCALE =         $0001;
-  FT_LOAD_NO_HINTING =       $0002;
-  FT_LOAD_RENDER =           $0004;
-  FT_LOAD_NO_BITMAP =        $0008;
-  FT_LOAD_VERTICAL_LAYOUT =  $0010;
-  FT_LOAD_FORCE_AUTOHINT =   $0020;
-  FT_LOAD_CROP_BITMAP =      $0040;
-  FT_LOAD_PEDANTIC =         $0080;
-  FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = $0200;
-  FT_LOAD_NO_RECURSE =       $0400;
-  FT_LOAD_IGNORE_TRANSFORM = $0800;
-  FT_LOAD_MONOCHROME =       $1000;
-  FT_LOAD_LINEAR_DESIGN =    $2000;
-
-  ft_glyph_format_none      = $00000000;
-  ft_glyph_format_composite = $636F6D70; //comp 099 111 109 112
-  ft_glyph_format_bitmap    = $62697473; //bits 098 105 116 115
-  ft_glyph_format_outline   = $6F75746C; //outl 111 117 116 108
-  ft_glyph_format_plotter   = $706C6F74; //plot 112 108 111 116
-
-  FT_ENCODING_MS_SYMBOL : FT_Encoding = 'symb';
-  FT_ENCODING_UNICODE : FT_Encoding = 'unic';
-  FT_ENCODING_MS_SJIS : FT_Encoding = 'sjis';
-  FT_ENCODING_MS_GB2312 : FT_Encoding = 'gb  ';
-  FT_ENCODING_MS_BIG5 : FT_Encoding = 'big5';
-  FT_ENCODING_MS_WANSUNG : FT_Encoding = 'wans';
-  FT_ENCODING_MS_JOHAB : FT_Encoding = 'joha';
-  FT_ENCODING_ADOBE_STANDARD : FT_Encoding = 'ADOB';
-  FT_ENCODING_ADOBE_EXPERT : FT_Encoding = 'ADBE';
-  FT_ENCODING_ADOBE_CUSTOM : FT_Encoding = 'ADBC';
-  FT_ENCODING_ADOBE_LATIN_1 : FT_Encoding = 'lat1';
-  FT_ENCODING_OLD_LATIN_2 : FT_Encoding = 'lat2';
-  FT_ENCODING_APPLE_ROMAN : FT_Encoding = 'armn';
-
-  ft_glyph_bbox_unscaled  = 0; //* return unscaled font units           */
-  ft_glyph_bbox_subpixels = 0; //* return unfitted 26.6 coordinates     */
-  ft_glyph_bbox_gridfit   = 1; //* return grid-fitted 26.6 coordinates  */
-  ft_glyph_bbox_truncate  = 2; //* return coordinates in integer pixels */
-  ft_glyph_bbox_pixels    = 3; //* return grid-fitted pixel coordinates */
-
-  FT_KERNING_DEFAULT  = 0;
-  FT_KERNING_UNFITTED = 1;
-  FT_KERNING_UNSCALED = 2;
-
-
-type
-
-  FT_Bool = boolean;
-  FT_FWord = smallint;
-  FT_UFWord = word;
-  FT_Char = char;
-  FT_Byte = byte;
-  FT_String = char;
-  FT_Short = smallint;
-  FT_UShort = word;
-  FT_Int = longint;
-  FT_UInt = longword;
-  {$if defined(cpu64) and not(defined(win64) and defined(cpux86_64))}
-  FT_Long = int64;
-  FT_ULong = qword;
-  FT_Pos = int64;
-  {$ELSE}
-  FT_Long = longint;
-  FT_ULong = longword;
-  FT_Pos = longint;
-  {$ENDIF}
-  FT_F2Dot14 = smallint;
-  FT_F26Dot6 = longint;
-  FT_Fixed = FT_Long;
-  FT_Error = longint;
-  FT_Pointer = pointer;
-  //FT_Offset = size_t;
-  //FT_PtrDist = size_t;
-
-  FT_Render_Mode = (FT_RENDER_MODE_NORMAL, FT_RENDER_MODE_LIGHT,
-      FT_RENDER_MODE_MONO, FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V,
-      FT_RENDER_MODE_MAX);
-
-  FT_UnitVector_ = record
-      x : FT_F2Dot14;
-      y : FT_F2Dot14;
-   end;
-  FT_UnitVector = FT_UnitVector_;
-
-  FT_Matrix = record
-      xx : FT_Fixed;
-      xy : FT_Fixed;
-      yx : FT_Fixed;
-      yy : FT_Fixed;
-   end;
-  PFT_Matrix = ^FT_Matrix;
-
-  FT_Data = record
-      pointer : ^FT_Byte;
-      length : FT_Int;
-   end;
-
-  FT_Generic_Finalizer = procedure (AnObject:pointer);cdecl;
-
-  FT_Generic = record
-      data : pointer;
-      finalizer : FT_Generic_Finalizer;
-   end;
-
-  FT_Glyph_Metrics = record
-    width : FT_Pos;
-    height : FT_Pos;
-    horiBearingX : FT_Pos;
-    horiBearingY : FT_Pos;
-    horiAdvance : FT_Pos;
-    vertBearingX : FT_Pos;
-    vertBearingY : FT_Pos;
-    vertAdvance : FT_Pos;
-  end;
-
-  FT_Bitmap_Size = record
-    height : FT_Short;
-    width : FT_Short;
-  end;
-  AFT_Bitmap_Size = array [0..1023] of FT_Bitmap_Size;
-  PFT_Bitmap_Size = ^AFT_Bitmap_Size;
-
-  FT_Vector = record
-    x : FT_Pos;
-    y : FT_Pos;
-  end;
-  PFT_Vector = ^FT_Vector;
-
-  FT_BBox = record
-    xMin, yMin : FT_Pos;
-    xMax, yMax : FT_Pos;
-  end;
-  PFT_BBox = ^FT_BBox;
-
-  FT_Bitmap = record
-    rows : integer;
-    width : integer;
-    pitch : integer;
-    buffer : pointer;
-    num_grays : shortint;
-    pixel_mode : char;
-    palette_mode : char;
-    palette : pointer;
-  end;
-
-  FT_Outline = record
-    n_contours,
-    n_points : smallint;
-    points : PFT_Vector;
-    tags : pchar;
-    contours : ^smallint;
-    flags : integer;
-  end;
-  PFT_Outline = ^FT_Outline;
-
-  FT_Outline_MoveToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
-  FT_Outline_LineToFunc = function(const to_: PFT_Vector; user: Pointer): integer;
-  FT_Outline_ConicToFunc = function(const control, to_: PFT_Vector; user: Pointer): integer;
-  FT_Outline_CubicToFunc = function(const control1, control2, to_: PFT_Vector; user: Pointer): integer;
-
-  FT_Outline_Funcs = record
-    move_to: FT_Outline_MoveToFunc;
-    line_to: FT_Outline_LineToFunc;
-    conic_to: FT_Outline_ConicToFunc;
-    cubic_to: FT_Outline_CubicToFunc;
-    shift: integer;
-    delta: FT_Pos;
-  end;
-  PFT_Outline_Funcs = ^FT_Outline_Funcs;
-
-  FT_Size_Metrics = record
-    x_ppem : FT_UShort;
-    y_ppem : FT_UShort;
-    x_scale : FT_Fixed;
-    y_scale : FT_Fixed;
-    ascender : FT_Pos;
-    descender : FT_Pos;
-    height : FT_Pos;
-    max_advance : FT_Pos;
-  end;
-
-
-  PFT_Library = ^TFT_Library;
-  //PPFT_Library = ^PFT_Library;
-  PFT_Face = ^TFT_Face;
-  //PPFT_Face = ^PFT_Face;
-  PFT_Charmap = ^TFT_Charmap;
-  PPFT_Charmap = ^PFT_Charmap;
-  PFT_GlyphSlot = ^TFT_GlyphSlot;
-  PFT_Subglyph = ^TFT_Subglyph;
-  PFT_Size = ^TFT_Size;
-
-  PFT_Glyph = ^TFT_Glyph;
-  //PPFT_Glyph = ^PFT_Glyph;
-  PFT_BitmapGlyph = ^TFT_BitmapGlyph;
-  PFT_OutlineGlyph = ^TFT_OutlineGlyph;
-
-
-  TFT_Library = record
-  end;
-
-  TFT_Charmap = record
-    face : PFT_Face;
-    encoding : FT_Encoding;
-    platform_id, encoding_id : FT_UShort;
-  end;
-
-  TFT_Size = record
-    face : PFT_Face;
-    generic : FT_Generic;
-    metrics : FT_Size_Metrics;
-    //internal : FT_Size_Internal;
-  end;
-
-  TFT_Subglyph = record  // TODO
-  end;
-
-  TFT_GlyphSlot = record
-    alibrary : PFT_Library;
-    face : PFT_Face;
-    next : PFT_GlyphSlot;
-    flags : FT_UInt;
-    generic : FT_Generic;
-    metrics : FT_Glyph_Metrics;
-    linearHoriAdvance : FT_Fixed;
-    linearVertAdvance : FT_Fixed;
-    advance : FT_Vector;
-    format : longword;
-    bitmap : FT_Bitmap;
-    bitmap_left : FT_Int;
-    bitmap_top : FT_Int;
-    outline : FT_Outline;
-    num_subglyphs : FT_UInt;
-    subglyphs : PFT_SubGlyph;
-    control_data : pointer;
-    control_len : longint;
-    other : pointer;
-  end;
-
-  TFT_Face = record
-    num_faces : FT_Long;
-    face_index : FT_Long;
-    face_flags : FT_Long;
-    style_flags : FT_Long;
-    num_glyphs : FT_Long;
-    family_name : pchar;
-    style_name : pchar;
-    num_fixed_sizes : FT_Int;
-    available_sizes : PFT_Bitmap_Size;     // is array
-    num_charmaps : FT_Int;
-    charmaps : PPFT_CharMap;               // is array
-    generic : FT_Generic;
-    bbox : FT_BBox;
-    units_per_EM : FT_UShort;
-    ascender : FT_Short;
-    descender : FT_Short;
-    height : FT_Short;
-    max_advance_width : FT_Short;
-    max_advance_height : FT_Short;
-    underline_position : FT_Short;
-    underline_thickness : FT_Short;
-    glyph : PFT_GlyphSlot;
-    size : PFT_Size;
-    charmap : PFT_CharMap;
-  end;
-
-  TFT_Glyph = record
-    FTlibrary : PFT_Library;
-    clazz : pointer;
-    aFormat : longword;
-    advance : FT_Vector;
-  end;
-
-  TFT_BitmapGlyph = record
-    root : TFT_Glyph;
-    left, top : FT_Int;
-    bitmap : FT_Bitmap;
-  end;
-
-  TFT_OutlineGlyph = record
-    root : TFT_Glyph;
-    outline : FT_Outline;
-  end;
-
-//Base Interface
-function FT_Done_Face(face: PFT_Face): integer; cdecl; external freetypedll Name 'FT_Done_Face';
-function FT_Done_FreeType(alibrary: PFT_Library): integer; cdecl; external freetypedll Name 'FT_Done_FreeType';
-function FT_Get_Char_Index(face: PFT_Face; charcode: FT_ULong): FT_UInt; cdecl; external freetypedll Name 'FT_Get_Char_Index';
-function FT_Get_Kerning(face: PFT_Face; left_glyph, right_glyph, kern_mode: FT_UInt; out akerning: FT_Vector): integer; cdecl; external freetypedll Name 'FT_Get_Kerning';
-function FT_Init_FreeType(var alibrary: PFT_Library): integer; cdecl; external freetypedll Name 'FT_Init_FreeType';
-function FT_IS_SCALABLE(face: PFT_Face): boolean;
-function FT_Load_Char(face: PFT_Face; charcode: FT_ULong; load_flags: longint): integer; cdecl; external freetypedll Name 'FT_Load_Char';
-function FT_Load_Glyph(face: PFT_Face; glyph_index: FT_UInt; load_flags: longint): integer; cdecl; external freetypedll Name 'FT_Load_Glyph';
-function FT_New_Face(alibrary: PFT_Library; filepathname: PChar; face_index: integer; var aface: PFT_Face): integer; cdecl; external freetypedll Name 'FT_New_Face';
-function FT_Set_Char_Size(face: PFT_Face; char_width, char_height: FT_F26dot6; horz_res, vert_res: FT_UInt): integer; cdecl; external freetypedll Name 'FT_Set_Char_Size';
-function FT_Set_Pixel_Sizes(face: PFT_Face; pixel_width, pixel_height: FT_UInt): integer; cdecl; external freetypedll Name 'FT_Set_Pixel_Sizes';
-procedure FT_Set_Transform(face: PFT_Face; matrix: PFT_Matrix; delta: PFT_Vector); cdecl; external freetypedll Name 'FT_Set_Transform';
-
-//Outline Processing
-function FT_Outline_Decompose(outline: PFT_Outline; const func_interface: PFT_Outline_Funcs; user: Pointer): integer; cdecl; external freetypedll Name 'FT_Outline_Decompose';
-
-//FreeType Version
-procedure FT_Library_Version(alibrary: PFT_Library; var amajor, aminor, apatch: integer); cdecl; external freetypedll Name 'FT_Library_Version';
-
-//Glyph Management
-function FT_Get_Glyph(slot: PFT_GlyphSlot; out aglyph: PFT_Glyph): integer; cdecl; external freetypedll Name 'FT_Get_Glyph';
-function FT_Glyph_Copy(Source: PFT_Glyph; out target: PFT_Glyph): integer; cdecl; external freetypedll Name 'FT_Glyph_Copy';
-function FT_Glyph_To_Bitmap(var the_glyph: PFT_Glyph; render_mode: FT_Render_Mode; origin: PFT_Vector; Destroy: FT_Bool): integer; cdecl; external freetypedll Name 'FT_Glyph_To_Bitmap';
-function FT_Glyph_Transform(glyph: PFT_Glyph; matrix: PFT_Matrix; delta: PFT_Vector): integer; cdecl; external freetypedll Name 'FT_Glyph_Transform';
-procedure FT_Done_Glyph(glyph: PFT_Glyph); cdecl; external freetypedll Name 'FT_Done_Glyph';
-procedure FT_Glyph_Get_CBox(glyph: PFT_Glyph; bbox_mode: FT_UInt; var acbox: FT_BBox); cdecl; external freetypedll Name 'FT_Glyph_Get_CBox';
-
-implementation
-
-function FT_IS_SCALABLE(face: PFT_Face): boolean;
-begin
-  Result := (face^.face_flags and FT_FACE_FLAG_SCALABLE) = 1;
-end;
-
 end.
Index: packages/fcl-image/src/freetypehdyn.pp
===================================================================
--- packages/fcl-image/src/freetypehdyn.pp	(nonexistent)
+++ packages/fcl-image/src/freetypehdyn.pp	(working copy)
@@ -0,0 +1,27 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2003 by the Free Pascal development team
+
+    Basic canvas definitions.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+{$mode objfpc}
+unit freetypehdyn;
+
+{$DEFINE LOAD_DYNAMICALLY}
+{$i freetype.inc}
+
+initialization
+  InitializeFreetype(freetypedll);
+
+finalization
+  ReleaseFreetype;
+
+end.
freetypeh.patch (32,689 bytes)

Michael Van Canneyt

2017-12-29 15:28

administrator   ~0105113

Indeed not well tested. It didn't even compile :)

I did it somewhat different, tested on linux; all works OK.

Andi Friess

2018-01-01 18:13

reporter   ~0105230

THX

Issue History

Date Modified Username Field Change
2017-09-26 13:39 Andi Friess New Issue
2017-09-26 13:39 Andi Friess File Added: freetypeh.patch
2017-09-26 16:45 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-09-26 16:45 Michael Van Canneyt Status new => assigned
2017-12-29 15:28 Michael Van Canneyt Fixed in Revision => 37865
2017-12-29 15:28 Michael Van Canneyt Note Added: 0105113
2017-12-29 15:28 Michael Van Canneyt Status assigned => resolved
2017-12-29 15:28 Michael Van Canneyt Fixed in Version => 3.2.0
2017-12-29 15:28 Michael Van Canneyt Resolution open => fixed
2018-01-01 18:13 Andi Friess Note Added: 0105230
2018-01-01 18:13 Andi Friess Status resolved => closed