From 975c0a21ac8411d5cf2e8588e9725af240fddad0 Mon Sep 17 00:00:00 2001 From: tobigun Date: Fri, 17 Oct 2008 15:32:03 +0000 Subject: freetype stuff for testing git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1449 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/demo/Kopie von UFreeType.pas | 326 +++ src/lib/freetype/demo/Kopie von lesson43.dpr | 289 +++ src/lib/freetype/demo/UFont.pas | 2641 +++++++++++++++++++++++++ src/lib/freetype/demo/lesson43.bdsproj | 175 ++ src/lib/freetype/demo/lesson43.dpr | 366 ++++ src/lib/freetype/demo/lesson43.lpi | 272 +++ src/lib/freetype/freetype.pas | 2503 +++++++++++++++++++++++ 7 files changed, 6572 insertions(+) create mode 100644 src/lib/freetype/demo/Kopie von UFreeType.pas create mode 100644 src/lib/freetype/demo/Kopie von lesson43.dpr create mode 100644 src/lib/freetype/demo/UFont.pas create mode 100644 src/lib/freetype/demo/lesson43.bdsproj create mode 100644 src/lib/freetype/demo/lesson43.dpr create mode 100644 src/lib/freetype/demo/lesson43.lpi create mode 100644 src/lib/freetype/freetype.pas (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/demo/Kopie von UFreeType.pas b/src/lib/freetype/demo/Kopie von UFreeType.pas new file mode 100644 index 00000000..c1243aae --- /dev/null +++ b/src/lib/freetype/demo/Kopie von UFreeType.pas @@ -0,0 +1,326 @@ +unit UFreeType; + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +interface + +uses + FreeType, + gl, + glu, + classes, + sysutils; + +type + // This holds all of the information related to any + // freetype font that we want to create. + TFontData = class + h: single; ///< Holds the height of the font. + textures: array of GLuint; ///< Holds the texture id's + list_base: GLuint; ///< Holds the first display list id + + // The init function will create a font of + // of the height h from the file fname. + constructor Create(const fname: string; h: cardinal); + + // Free all the resources assosiated with the font. + destructor Destroy(); override; + end; + + TFreeType = class + public + // The flagship function of the library - this thing will print + // out text at window coordinates x,y, using the font ft_font. + // The current modelview matrix will also be applied to the text. + class procedure print(ft_font: TFontData; x, y: single; const str: string); + end; + + +implementation + + +// This function gets the first power of 2 >= the +// int that we pass it. +function next_p2 ( a: integer ): integer; inline; +begin + Result := 1; + while (Result < a) do + Result := Result shl 1; +end; + +type + PAGLuint = ^AGLuint; + AGLuint = array[0..High(Word)] of GLuint; + +// Create a display list coresponding to the given character. +procedure make_dlist ( face: FT_Face; ch: byte; list_base: GLuint; tex_base: PAGLuint ); +var + i, j: integer; + width, height: integer; + glyph: FT_Glyph; + bitmap_glyph: FT_BitmapGlyph; + bitmap: PFT_Bitmap; + expanded_data: array of GLubyte; + x, y: single; +begin + // The first thing we do is get FreeType to render our character + // into a bitmap. This actually requires a couple of FreeType commands: + + // Load the Glyph for our character. + if (FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ) <> 0) then + raise Exception.create('FT_Load_Glyph failed'); + + // Move the face's glyph into a Glyph object. + if (FT_Get_Glyph( face^.glyph, glyph ) <> 0) then + raise Exception.create('FT_Get_Glyph failed'); + + // Convert the glyph to a bitmap. + FT_Glyph_To_Bitmap( glyph, ft_render_mode_normal, nil, 1 ); + bitmap_glyph := FT_BitmapGlyph(glyph); + + // This reference will make accessing the bitmap easier + bitmap := @bitmap_glyph^.bitmap; + + // Use our helper function to get the widths of + // the bitmap data that we will need in order to create + // our texture. + width := next_p2( bitmap.width ); + height := next_p2( bitmap.rows ); + + // Allocate memory for the texture data. + SetLength(expanded_data, 2 * width * height); + + // Here we fill in the data for the expanded bitmap. + // Notice that we are using two channel bitmap (one for + // luminocity and one for alpha), but we assign + // both luminocity and alpha to the value that we + // find in the FreeType bitmap. + // We use the ?: operator so that value which we use + // will be 0 if we are in the padding zone, and whatever + // is the the Freetype bitmap otherwise. + for j := 0 to height-1 do + begin + for i := 0 to width-1 do + begin + if ((i >= bitmap.width) or (j >= bitmap.rows)) then + expanded_data[2*(i+j*width)] := 0 + else + expanded_data[2*(i+j*width)] := byte(bitmap.buffer[i + bitmap.width*j]); + expanded_data[2*(i+j*width)+1] := expanded_data[2*(i+j*width)]; + end; + end; + + + // Now we just setup some texture paramaters. + glBindTexture( GL_TEXTURE_2D, tex_base[integer(ch)]); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + // Here we actually create the texture itself, notice + // that we are using GL_LUMINANCE_ALPHA to indicate that + // we are using 2 channel data. + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, + 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, @expanded_data[0] ); + + //With the texture created, we don't need to expanded data anymore + SetLength(expanded_data, 0); + + //So now we can create the display list + glNewList(list_base+ch, GL_COMPILE); + + glBindTexture(GL_TEXTURE_2D, tex_base[ch]); + + glPushMatrix(); + + //first we need to move over a little so that + //the character has the right amount of space + //between it and the one before it. + glTranslatef(bitmap_glyph^.left, 0, 0); + + //Now we move down a little in the case that the + //bitmap extends past the bottom of the line + //(this is only true for characters like 'g' or 'y'. + glTranslatef(0, bitmap_glyph^.top - bitmap.rows, 0); + + //Now we need to account for the fact that many of + //our textures are filled with empty padding space. + //We figure what portion of the texture is used by + //the actual character and store that information in + //the x and y variables, then when we draw the + //quad, we will only reference the parts of the texture + //that we contain the character itself. + x := bitmap.width / width; + y := bitmap.rows / height; + + //Here we draw the texturemaped quads. + //The bitmap that we got from FreeType was not + //oriented quite like we would like it to be, + //so we need to link the texture to the quad + //so that the result will be properly aligned. + glBegin(GL_QUADS); + glTexCoord2d(0, 0); glVertex2f(0, bitmap.rows); + glTexCoord2d(0, y); glVertex2f(0, 0); + glTexCoord2d(x, y); glVertex2f(bitmap.width, 0); + glTexCoord2d(x, 0); glVertex2f(bitmap.width, bitmap.rows); + glEnd(); + + glPopMatrix(); + glTranslatef(face^.glyph^.advance.x shr 6, 0, 0); + + //increment the raster position as if we were a bitmap font. + //(only needed if you want to calculate text length) + //glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL); + + //Finnish the display list + glEndList(); +end; + + +constructor TFontData.Create(const fname: string; h: cardinal); +var + library_: FT_Library; + //The object in which Freetype holds information on a given + //font is called a "face". + face: FT_Face; + i: byte; +begin + //Allocate some memory to store the texture ids. + SetLength(textures, 128); + + Self.h := h; + + //Create and initilize a freetype font library. + if (FT_Init_FreeType( library_ ) <> 0) then + raise Exception.create('FT_Init_FreeType failed'); + + //This is where we load in the font information from the file. + //Of all the places where the code might die, this is the most likely, + //as FT_New_Face will die if the font file does not exist or is somehow broken. + if (FT_New_Face( library_, PChar(fname), 0, face ) <> 0) then + raise Exception.create('FT_New_Face failed (there is probably a problem with your font file)'); + + //For some twisted reason, Freetype measures font size + //in terms of 1/64ths of pixels. Thus, to make a font + //h pixels high, we need to request a size of h*64. + //(h shl 6 is just a prettier way of writting h*64) + FT_Set_Char_Size( face, h shl 6, h shl 6, 96, 96); + + //Here we ask opengl to allocate resources for + //all the textures and displays lists which we + //are about to create. + list_base := glGenLists(128); + glGenTextures( 128, @textures[0] ); + + //This is where we actually create each of the fonts display lists. + for i := 0 to 127 do + make_dlist(face, i, list_base, @textures[0]); + + //We don't need the face information now that the display + //lists have been created, so we free the assosiated resources. + FT_Done_Face(face); + + //Ditto for the library. + FT_Done_FreeType(library_); +end; + +destructor TFontData.Destroy(); +begin + glDeleteLists(list_base, 128); + glDeleteTextures(128, @textures[0]); + SetLength(textures, 0); +end; + +/// A fairly straight forward function that pushes +/// a projection matrix that will make object world +/// coordinates identical to window coordinates. +procedure pushScreenCoordinateMatrix(); inline; +var + viewport: array [0..3] of GLint; +begin + glPushAttrib(GL_TRANSFORM_BIT); + glGetIntegerv(GL_VIEWPORT, @viewport); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(viewport[0], viewport[2], viewport[1], viewport[3]); + glPopAttrib(); +end; + +/// Pops the projection matrix without changing the current +/// MatrixMode. +procedure pop_projection_matrix(); inline; +begin + glPushAttrib(GL_TRANSFORM_BIT); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); +end; + +///Much like Nehe's glPrint function, but modified to work +///with freetype fonts. +class procedure TFreeType.print(ft_font: TFontData; x, y: single; const str: string); +var + font: GLuint; + h: single; + i: cardinal; + lines: TStringList; + modelview_matrix: array[0..15] of single; +begin + // We want a coordinate system where things coresponding to window pixels. + pushScreenCoordinateMatrix(); + + font := ft_font.list_base; + h := ft_font.h / 0.63; //We make the height about 1.5* that of + + lines := TStringList.Create(); + ExtractStrings([#13], [], PChar(str), lines); + + glPushAttrib(GL_LIST_BIT or GL_CURRENT_BIT or GL_ENABLE_BIT or GL_TRANSFORM_BIT); + glMatrixMode(GL_MODELVIEW); + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glListBase(font); + + glGetFloatv(GL_MODELVIEW_MATRIX, @modelview_matrix); + + //This is where the text display actually happens. + //For each line of text we reset the modelview matrix + //so that the line's text will start in the correct position. + //Notice that we need to reset the matrix, rather than just translating + //down by h. This is because when each character is + //draw it modifies the current matrix so that the next character + //will be drawn immediatly after it. + for i := 0 to lines.Count-1 do + begin + glPushMatrix(); + glLoadIdentity(); + glTranslatef(x, y - h*i, 0); + glMultMatrixf(@modelview_matrix); + + // The commented out raster position stuff can be useful if you need to + // know the length of the text that you are creating. + // If you decide to use it make sure to also uncomment the glBitmap command + // in make_dlist(). + //glRasterPos2f(0,0); + glCallLists(Length(lines[i]), GL_UNSIGNED_BYTE, PChar(lines[i])); + //float rpos[4]; + //glGetFloatv(GL_CURRENT_RASTER_POSITION ,rpos); + //float len=x-rpos[0]; + + glPopMatrix(); + end; + + glPopAttrib(); + + pop_projection_matrix(); + + lines.Free(); +end; + +end. diff --git a/src/lib/freetype/demo/Kopie von lesson43.dpr b/src/lib/freetype/demo/Kopie von lesson43.dpr new file mode 100644 index 00000000..b49423fb --- /dev/null +++ b/src/lib/freetype/demo/Kopie von lesson43.dpr @@ -0,0 +1,289 @@ +program lesson43; +(* + * This code was created by Jeff Molofee '99 + * (ported to Linux/SDL by Ti Leggett '01) + * + * If you've found this code useful, please let me know. + * + * Visit Jeff at http://nehe.gamedev.net/ + * + * or for port-specific comments, questions, bugreports etc. + * email to leggett@eecs.tulane.edu + *) + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +{$APPTYPE Console} + +uses + moduleloader in '../../JEDI-SDL/SDL/Pas/moduleloader.pas', + SDL in '../../JEDI-SDL/SDL/Pas/sdl.pas', + gl in '../../JEDI-SDL/OpenGL/Pas/gl.pas', + glu in '../../JEDI-SDL/OpenGL/Pas/glu.pas', + ctypes in '../../ctypes/ctypes.pas', + FreeType in '../freetype.pas', + UFreeType in 'UFreeType.pas', + math, + sysutils; + +const + // screen width, height, and bit depth + SCREEN_WIDTH = 640; + SCREEN_HEIGHT = 480; + SCREEN_BPP = 16; + +var + our_font: TFontData; + // This is our SDL surface + surface: PSDL_Surface; + cnt1, cnt2: GLfloat; + +(* function to release/destroy our resources and restoring the old desktop *) +procedure Quit(returnCode: integer); +begin + // clean up the window + SDL_Quit( ); + + // and exit appropriately + Halt( returnCode ); +end; + +(* function to reset our viewport after a window resize *) +function resizeWindow(width: integer; height: integer): boolean; +var + // Height / width ration + ratio: GLfloat; +begin + // Protect against a divide by zero + if ( height = 0 ) then + height := 1; + + ratio := width / height; + + // Setup our viewport. + glViewport( 0, 0, GLsizei(width), GLsizei(height) ); + + // change to the projection matrix and set our viewing volume. + glMatrixMode( GL_PROJECTION ); + glLoadIdentity( ); + + // Set our perspective + gluPerspective( 45.0, ratio, 0.1, 100.0 ); + + // Make sure we're chaning the model view and not the projection + glMatrixMode( GL_MODELVIEW ); + + // Reset The View + glLoadIdentity( ); + + Result := true; +end; + +(* function to handle key press events *) +procedure handleKeyPress(keysym: PSDL_keysym); +begin + case ( keysym^.sym ) of + SDLK_ESCAPE: + begin + // ESC key was pressed + Quit( 0 ); + end; + SDLK_F1: + begin + // F1 key was pressed + // this toggles fullscreen mode + SDL_WM_ToggleFullScreen( surface ); + end; + end; +end; + +(* general OpenGL initialization function *) +function initGL(): boolean; +begin + // Enable smooth shading + glShadeModel( GL_SMOOTH ); + + // Set the background black + glClearColor( 0.0, 0.0, 0.0, 0.0 ); + + // Depth buffer setup + glClearDepth( 1.0 ); + + // Enables Depth Testing + glEnable( GL_DEPTH_TEST ); + + // The Type Of Depth Test To Do + glDepthFunc( GL_LEQUAL ); + + // Really Nice Perspective Calculations + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + + our_font := TFontData.Create('Test.ttf', 16); + + Result := true; +end; + +(* Here goes our drawing code *) +function drawGLScene(): boolean; +begin + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + glLoadIdentity(); // Reset The Current Modelview Matrix + glTranslatef(0.0, 0.0, -1.0); // Move One Unit Into The Screen + + // Blue Text + glColor3ub(0, 0, $ff); + + // Position The WGL Text On The Screen + glRasterPos2f(-0.40, 0.35); + + // Here We Print Some Text Using Our FreeType Font + // The only really important command is the actual print() call, + // but for the sake of making the results a bit more interesting + // I have put in some code to rotate and scale the text. + + // Red text + glColor3ub($ff, 0, 0); + + glPushMatrix(); + glLoadIdentity(); + glRotatef(cnt1, 0, 0,1); + glScalef(1, 0.8 + 0.3*cos(cnt1/5) ,1); + glTranslatef(-180, 0, 0); + TFreeType.print(our_font, 320, 240, 'Active FreeType Text - ' + FloatToStr(cnt1)); + glPopMatrix(); + + //Uncomment this to test out print's ability to handle newlines. + //TFreeType.print(our_font, 320, 200, 'Here'#13'there'#13'be'#13#13'newlines'#13'.'); + + cnt1 := cnt1 + 0.051; // Increase The First Counter + cnt2 := cnt2 + 0.005; // Increase The First Counter + + SDL_GL_SwapBuffers( ); + + Result := true; +end; + +var + // Flags to pass to SDL_SetVideoMode + videoFlags: integer; + // main loop variable + done: boolean = false; + // used to collect events + event: TSDL_Event; + // this holds some info about our display + videoInfo: PSDL_VideoInfo; + // whether or not the window is active + isActive: boolean = true; + +begin + // initialize SDL + if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) then + begin + writeln( ErrOutput, 'Video initialization failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // Fetch the video info + videoInfo := SDL_GetVideoInfo( ); + + if ( videoInfo = nil ) then + begin + writeln( ErrOutput, 'Video query failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Enable double buffering + + // the flags to pass to SDL_SetVideoMode + videoFlags := SDL_OPENGL; // Enable OpenGL in SDL + videoFlags := videoFlags or SDL_HWPALETTE; // Store the palette in hardware + videoFlags := videoFlags or SDL_RESIZABLE; // Enable window resizing + + // This checks to see if surfaces can be stored in memory + if ( videoInfo^.hw_available <> 0 ) then + videoFlags := videoFlags or SDL_HWSURFACE + else + videoFlags := videoFlags or SDL_SWSURFACE; + + // This checks if hardware blits can be done + if ( videoInfo^.blit_hw <> 0 ) then + videoFlags := videoFlags or SDL_HWACCEL; + + // Sets up OpenGL double buffering + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + // get a SDL surface + surface := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, + videoFlags ); + + // Verify there is a surface + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Video mode set failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // initialize OpenGL + initGL(); + + // resize the initial window + resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); + + // wait for events + while ( not done ) do + begin + { handle the events in the queue } + + while ( SDL_PollEvent( @event ) <> 0 ) do + begin + case( event.type_ ) of + SDL_ACTIVEEVENT: + begin + // Something's happend with our focus + // If we are iconified, we shouldn't draw the screen + if ( (event.active.state and SDL_APPACTIVE) <> 0 ) then + begin + if ( event.active.gain = 0 ) then + isActive := false + else + isActive := true; + end; + end; + SDL_VIDEORESIZE: + begin + // handle resize event + {$IFDEF UNIX} + surface := SDL_SetVideoMode( event.resize.w, + event.resize.h, + 16, videoFlags ); + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Could not get a surface after resize: ' + SDL_GetError( ) ); + Quit( 1 ); + end; + {$ENDIF} + resizeWindow( event.resize.w, event.resize.h ); + end; + SDL_KEYDOWN: + begin + // handle key presses + handleKeyPress( @event.key.keysym ); + end; + SDL_QUITEV: + begin + // handle quit requests + done := true; + end; + end; + end; + + // draw the scene + if ( isActive ) then + drawGLScene( ); + end; + + // clean ourselves up and exit + Quit( 0 ); +end. diff --git a/src/lib/freetype/demo/UFont.pas b/src/lib/freetype/demo/UFont.pas new file mode 100644 index 00000000..c15ff4ca --- /dev/null +++ b/src/lib/freetype/demo/UFont.pas @@ -0,0 +1,2641 @@ +unit UFont; + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +{$DEFINE HasInline} + +interface + +// Flip direction of y-axis. +// Default is a cartesian coordinate system with y-axis in upper direction +// but with USDX the y-axis is in lower direction. +{.$DEFINE FLIP_YAXIS} +{.$DEFINE BITMAP_FONT} + +uses + FreeType, + gl, + glext, + glu, + sdl, + {$IFDEF BITMAP_FONT} + UTexture, + {$ENDIF} + Math, + Classes, + SysUtils; + +type + + PGLubyteArray = ^TGLubyteArray; + TGLubyteArray = array[0 .. (MaxInt div SizeOf(GLubyte))-1] of GLubyte; + TGLubyteDynArray = array of GLubyte; + + TWideStringArray = array of WideString; + + TGLColor = packed record + case byte of + 0: ( vals: array[0..3] of GLfloat; ); + 1: ( r, g, b, a: GLfloat; ); + end; + + TBoundsDbl = record + Left, Right: double; + Bottom, Top: double; + end; + + TPositionDbl = record + X, Y: double; + end; + + TTextureSize = record + Width, Height: integer; + end; + + TBitmapCoords = record + Left, Top: double; + Width, Height: integer; + end; + + {** + * Abstract base class representing a glyph. + *} + TGlyph = class + protected + function GetAdvance(): TPositionDbl; virtual; abstract; + function GetBounds(): TBoundsDbl; virtual; abstract; + public + procedure Render(UseDisplayLists: boolean); virtual; abstract; + procedure RenderReflection(); virtual; abstract; + + {** Distance to next glyph (in pixels) *} + property Advance: TPositionDbl read GetAdvance; + {** Glyph bounding box (in pixels) *} + property Bounds: TBoundsDbl read GetBounds; + end; + + {** + * Font styles used by TFont.Style + *} + TFontStyle = set of (Italic, Underline, Reflect); + + {** + * Base font class. + *} + TFont = class + private + {** Non-virtual reset-method used in Create() and Reset() *} + procedure ResetIntern(); + + protected + fStyle: TFontStyle; + fUseKerning: boolean; + fLineSpacing: single; // must be inited by subclass + fReflectionSpacing: single; // must be inited by subclass to -2*Descender + fGlyphSpacing: single; + fReflectionPass: boolean; + + {** + * Splits lines in Text seperated by newline (char-code #13). + * @param Text: UTF-8 encoded string + * @param Lines: splitted WideString lines + *} + procedure SplitLines(const Text: UTF8String; var Lines: TWideStringArray); + + {** + * Print an array of WideStrings. Each array-item is a line of text. + * Lines of text are seperated by the line-spacing. + * This is the base function for all text drawing. + *} + procedure Print(const Text: TWideStringArray); overload; virtual; + + {** + * Draws an underline. + *} + procedure DrawUnderline(const Text: WideString); virtual; + + {** + * Renders (one) line of text. + *} + procedure Render(const Text: WideString); virtual; abstract; + + {** + * Returns the bounds of text-lines contained in Text. + * @param Advance: if true the right bound is set to the advance instead + * of the minimal right bound. + *} + function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; overload; virtual; abstract; + + {** + * Resets all user settings to default values. + * Override methods should always call the inherited version. + *} + procedure Reset(); virtual; + + function GetHeight(): single; virtual; abstract; + function GetAscender(): single; virtual; abstract; + function GetDescender(): single; virtual; abstract; + procedure SetLineSpacing(Spacing: single); virtual; + function GetLineSpacing(): single; virtual; + procedure SetGlyphSpacing(Spacing: single); virtual; + function GetGlyphSpacing(): single; virtual; + procedure SetReflectionSpacing(Spacing: single); virtual; + function GetReflectionSpacing(): single; virtual; + procedure SetStyle(Style: TFontStyle); virtual; + function GetStyle(): TFontStyle; virtual; + function GetUnderlinePosition(): single; virtual; abstract; + function GetUnderlineThickness(): single; virtual; abstract; + procedure SetUseKerning(Enable: boolean); virtual; + function GetUseKerning(): boolean; virtual; + procedure SetReflectionPass(Enable: boolean); virtual; + + {** Returns true if the current render-pass is used to draw the reflection *} + property ReflectionPass: boolean read fReflectionPass write SetReflectionPass; + + public + constructor Create(); + destructor Destroy(); override; + + {** + * Prints a text. + *} + procedure Print(const Text: WideString); overload; + {** UTF-8 version of @link Print(const Text: WideString) *} + procedure Print(const Text: string); overload; + + {** + * Calculates the bounding box (width and height) around Text. + * Works with Italic and Underline styles but reflections created + * with the Reflect style are not considered. + * Note that the width might differ due to kerning with appended text, + * e.g. Width('VA') <= Width('V') + Width('A'). + * @param Advance: if set to true, Result.Right is set to the advance of + * the given text rather than the min. right border. The advance width is + * bigger than the text's width as it additionally contains the advance + * and glyph-spacing of the last character. + *} + function BBox(const Text: WideString; Advance: boolean = false): TBoundsDbl; overload; + {** UTF-8 version of @link BBox(const Text: WideString) *} + function BBox(const Text: UTF8String; Advance: boolean = false): TBoundsDbl; overload; + + {** Font height *} + property Height: single read GetHeight; + {** Vertical distance from baseline to top of glyph *} + property Ascender: single read GetAscender; + {** Vertical distance from baseline to bottom of glyph *} + property Descender: single read GetDescender; + {** Vertical distance between two baselines *} + property LineSpacing: single read GetLineSpacing write SetLineSpacing; + {** Space between end and start of next glyph added to the advance width *} + property GlyphSpacing: single read GetGlyphSpacing write SetGlyphSpacing; + {** Distance between normal baseline and baseline of the reflection *} + property ReflectionSpacing: single read GetReflectionSpacing write SetReflectionSpacing; + {** Font style (italic/underline/...) *} + property Style: TFontStyle read GetStyle write SetStyle; + {** If set to true (default) kerning will be used if available *} + property UseKerning: boolean read GetUseKerning write SetUseKerning; + end; + +const + // max. number of mipmap levels that a TScalableFont can contain + cMaxMipmapLevel = 5; + +type + {** + * Wrapper around TFont to allow font size changes. + * The font is scaled to the requested size by a modelview matrix + * transformation (glScale) and not by rescaling the internal bitmap + * representation. This way changing the size is really fast but the result + * may lack quality on large or small scale factors. + *} + TScalableFont = class(TFont) + private + procedure ResetIntern(); + + protected + fScale: single; ///< current height to base-font height ratio + fAspect: single; ///< width to height aspect + fBaseFont: TFont; ///< shortcut for fMipmapFonts[0] + fUseMipmaps: boolean; ///< true if mipmap fonts are generated + /// Mipmap fonts (size[level+1] = size[level]/2) + fMipmapFonts: array[0..cMaxMipmapLevel] of TFont; + + procedure Render(const Text: WideString); override; + procedure Print(const Text: TWideStringArray); override; + function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; + + {** + * Callback called for creation of each mipmap font. + * Must be defined by the subclass. + * Mipmaps created by this method are managed and freed by TScalableFont. + *} + function CreateMipmap(Level: integer; Scale: single): TFont; virtual; abstract; + + {** + * Returns the mipmap level considering the current scale and projection + * matrix. + *} + function GetMipmapLevel(): integer; + + {** + * Returns the scale applied to the given mipmap font. + * fScale * fBaseFont.Height / fMipmapFont[Level].Height + *} + function GetMipmapScale(Level: integer): single; + + {** + * Chooses the mipmap that looks nicest with current scale and projection + * matrix. + *} + function ChooseMipmapFont(): TFont; + + procedure SetHeight(Height: single); virtual; + function GetHeight(): single; override; + procedure SetAspect(Aspect: single); virtual; + function GetAspect(): single; virtual; + function GetAscender(): single; override; + function GetDescender(): single; override; + procedure SetLineSpacing(Spacing: single); override; + function GetLineSpacing(): single; override; + procedure SetGlyphSpacing(Spacing: single); override; + function GetGlyphSpacing(): single; override; + procedure SetReflectionSpacing(Spacing: single); override; + function GetReflectionSpacing(): single; override; + procedure SetStyle(Style: TFontStyle); override; + function GetStyle(): TFontStyle; override; + function GetUnderlinePosition(): single; override; + function GetUnderlineThickness(): single; override; + procedure SetUseKerning(Enable: boolean); override; + + public + {** + * Creates a wrapper to make the base-font Font scalable. + * If UseMipmaps is set to true smaller fonts are created so that a + * resized (Height property changed) font looks nicer. + * The font passed is managed and freed by TScalableFont. + *} + constructor Create(Font: TFont; UseMipmaps: boolean); overload; + + {** + * Frees memory. The fonts passed on Create() and mipmap creation + * are freed too. + *} + destructor Destroy(); override; + + {** @see TFont.Reset *} + procedure Reset(); override; + + {** Font height *} + property Height: single read GetHeight write SetHeight; + {** Factor for font stretching (NewWidth = Width*Aspect), 1.0 by default *} + property Aspect: single read GetAspect write SetAspect; + end; + + {** + * Table for storage of max. 256 glyphs. + * Used for the second cache level. Indexed by the LSB of the WideChar + * char-code. + *} + PGlyphTable = ^TGlyphTable; + TGlyphTable = array[0..255] of TGlyph; + + {** + * Cache for glyphs of a single font. + * The cached glyphs are stored inside a hash-list. + * Hashing is performed in two steps: + * 1. the least significant byte (LSB) of the WideChar character code + * is removed (shr 8) and the result (we call it BaseCode here) looked up in + * the hash-list. + * 2. Each entry of the hash-list contains a table with max. 256 entries. + * The LSB of the char-code of a glyph is the table-offset of that glyph. + *} + TGlyphCache = class + private + fHash: TList; + + {** + * Finds a glyph-table storing cached glyphs with base-code BaseCode + * (= upper char-code bytes) in the hash-list and returns the table and + * its index. + * @param InsertPos: the position of the tyble in the list if it was found, + * otherwise the position the table should be inserted + *} + function FindGlyphTable(BaseCode: cardinal; out InsertPos: integer): PGlyphTable; + + public + constructor Create(); + destructor Destroy(); override; + + {** + * Add glyph Glyph with char-code ch to the cache. + * @returns @true on success, @false otherwise + *} + function AddGlyph(ch: WideChar; const Glyph: TGlyph): boolean; + + {** + * Removes the glyph with char-code ch from the cache. + *} + procedure DeleteGlyph(ch: WideChar); + + {** + * Removes the glyph with char-code ch from the cache. + *} + function GetGlyph(ch: WideChar): TGlyph; + + {** + * Checks if a glyph with char-code ch is cached. + *} + function HasGlyph(ch: WideChar): boolean; + + {** + * Remove and free all cached glyphs. If KeepBaseSet is set to + * true, cached characters in the range 0..255 will not be flushed. + *} + procedure FlushCache(KeepBaseSet: boolean); + end; + + {** + * Entry of a glyph-cache's (TGlyphCache) hash. + * Stores a BaseCode (upper-bytes of a glyph's char-code) and a table + * with all glyphs cached at the moment with that BaseCode. + *} + TGlyphCacheHashEntry = class + private + fBaseCode: cardinal; + public + GlyphTable: TGlyphTable; + + constructor Create(BaseCode: cardinal); + + {** Base-code (upper-bytes) of the glyphs stored in this entry's table *} + property BaseCode: cardinal read fBaseCode; + end; + + TCachedFont = class(TFont) + protected + fCache: TGlyphCache; + + {** + * Retrieves a cached glyph with char-code ch from cache. + * If the glyph is not already cached, it is loaded with LoadGlyph(). + *} + function GetGlyph(ch: WideChar): TGlyph; + + {** + * Callback to create (load) a glyph with char-code ch. + * Implemented by subclasses. + *} + function LoadGlyph(ch: WideChar): TGlyph; virtual; abstract; + + public + constructor Create(); + destructor Destroy(); override; + + {** + * Remove and free all cached glyphs. If KeepBaseSet is set to + * true, the base glyphs are not be flushed. + * @see TGlyphCache.FlushCache + *} + procedure FlushCache(KeepBaseSet: boolean); + end; + + TFTFont = class; + + {** + * Freetype glyph. + * Each glyph stores a texture with the glyph's image. + *} + TFTGlyph = class(TGlyph) + private + fCharIndex: FT_UInt; ///< Freetype specific char-index (<> char-code) + fDisplayList: GLuint; ///< Display-list ID + fTexture: GLuint; ///< Texture ID + fBitmapCoords: TBitmapCoords; ///< Left/Top offset and Width/Height of the bitmap (in pixels) + fTexOffset: TPositionDbl; ///< Right and bottom texture offset for removal of power-of-2 padding + fTexSize: TTextureSize; ///< Texture size in pixels + + fFont: TFTFont; ///< Font associated with this glyph + fAdvance: TPositionDbl; ///< Advance width of this glyph + fBounds: TBoundsDbl; ///< Glyph bounds + fOutset: single; ///< Extrusion outset + + {** + * Extrudes the outline of a glyph's bitmap stored in TexBuffer with size + * fTexSize by Outset pixels. + * This is useful to create bold or outlined fonts. + * TexBuffer must be 2*Ceil(Outset) pixels higher and wider than the + * original glyph bitmap, otherwise the glyph borders cannot be extruded + * correctly. + * The bitmap must be 2* pixels wider and higher than the + * original glyph's bitmap with the latter centered in it. + *} + procedure Extrude(var TexBuffer: TGLubyteDynArray; Outset: single); + + {** + * Creates an OpenGL texture (and display list) for the glyph. + * The glyph's and bitmap's metrics are set correspondingly. + * @param LoadFlags: flags passed to FT_Load_Glyph() + * @raises Exception if the glyph could not be initialized + *} + procedure CreateTexture(LoadFlags: FT_Int32); + + protected + function GetAdvance(): TPositionDbl; override; + function GetBounds(): TBoundsDbl; override; + + public + {** + * Creates a glyph with char-code ch from font Font. + * @param LoadFlags: flags passed to FT_Load_Glyph() + *} + constructor Create(Font: TFTFont; ch: WideChar; Outset: single; + LoadFlags: FT_Int32); + destructor Destroy(); override; + + {** Renders the glyph (normal render pass) *} + procedure Render(UseDisplayLists: boolean); override; + {** Renders the glyph's reflection *} + procedure RenderReflection(); override; + + {** Freetype specific char-index (<> char-code) *} + property CharIndex: FT_UInt read fCharIndex; + end; + + {** + * Freetype font class. + *} + TFTFont = class(TCachedFont) + private + procedure ResetIntern(); + + protected + fFilename: string; ///< filename of the font-file + fSize: integer; ///< Font base size (in pixels) + fOutset: single; ///< size of outset extrusion (in pixels) + fFace: FT_Face; ///< Holds the height of the font + fLoadFlags: FT_Int32; ///< FT glpyh load-flags + fFontUnitScale: TPositionDbl; ///< FT font-units to pixel ratio + fUseDisplayLists: boolean; ///< true: use display-lists, false: direct drawing + + {** @see TCachedFont.LoadGlyph *} + function LoadGlyph(ch: WideChar): TGlyph; override; + + procedure Render(const Text: WideString); override; + function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; + + function GetHeight(): single; override; + function GetAscender(): single; override; + function GetDescender(): single; override; + function GetUnderlinePosition(): single; override; + function GetUnderlineThickness(): single; override; + + property Face: FT_Face read fFace; + + public + {** + * Creates a font of size Size (in pixels) from the file Filename. + * If Outset (in pixels) is set to a value > 0 the glyphs will be extruded + * at their borders. Use it for e.g. a bold effect. + * @param LoadFlags: flags passed to FT_Load_Glyph() + * @raises Exception if the font-file could not be loaded + *} + constructor Create(const Filename: string; + Size: integer; Outset: single = 0.0; + LoadFlags: FT_Int32 = FT_LOAD_DEFAULT); + + {** + * Frees all resources associated with the font. + *} + destructor Destroy(); override; + + {** @see TFont.Reset *} + procedure Reset(); override; + + {** Size of the base font *} + property Size: integer read fSize; + {** Outset size *} + property Outset: single read fOutset; + end; + + TFTScalableFont = class(TScalableFont) + protected + function GetOutset(): single; virtual; + function CreateMipmap(Level: integer; Scale: single): TFont; override; + + public + {** + * Creates a scalable font of size Size (in pixels) from the file Filename. + * OutsetAmount is the ratio of the glyph extrusion. + * The extrusion in pixels is Size*OutsetAmount + * (0.0 -> no extrusion, 0.1 -> 10%). + *} + constructor Create(const Filename: string; + Size: integer; OutsetAmount: single = 0.0; + UseMipmaps: boolean = true); + + {** @see TGlyphCache.FlushCache *} + procedure FlushCache(KeepBaseSet: boolean); + + {** Outset size (in pixels) of the scaled font *} + property Outset: single read GetOutset; + end; + + + {** + * Represents a freetype font with an additional outline around its glyphs. + * The outline size is passed on creation and cannot be changed later. + *} + TFTOutlineFont = class(TFont) + private + fFilename: string; + fSize: integer; + fOutset: single; + fInnerFont, fOutlineFont: TFTFont; + fOutlineColor: TGLColor; + + procedure ResetIntern(); + + protected + procedure DrawUnderline(const Text: WideString); override; + procedure Render(const Text: WideString); override; + function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; + + function GetHeight(): single; override; + function GetAscender(): single; override; + function GetDescender(): single; override; + procedure SetLineSpacing(Spacing: single); override; + procedure SetGlyphSpacing(Spacing: single); override; + procedure SetReflectionSpacing(Spacing: single); override; + procedure SetStyle(Style: TFontStyle); override; + function GetStyle(): TFontStyle; override; + function GetUnderlinePosition(): single; override; + function GetUnderlineThickness(): single; override; + procedure SetUseKerning(Enable: boolean); override; + procedure SetReflectionPass(Enable: boolean); override; + + public + constructor Create(const Filename: string; + Size: integer; Outset: single; + LoadFlags: FT_Int32 = FT_LOAD_DEFAULT); + destructor Destroy; override; + + {** Sets the color of the outline *} + procedure SetOutlineColor(r, g, b: GLfloat; a: GLfloat = 1.0); + + {** @see TGlyphCache.FlushCache *} + procedure FlushCache(KeepBaseSet: boolean); + + {** @see TFont.Reset *} + procedure Reset(); override; + + {** Size of the base font *} + property Size: integer read fSize; + {** Outset size *} + property Outset: single read fOutset; + end; + + {** + * Wrapper around TOutlineFont to allow font resizing. + * @see TScalableFont + *} + TFTScalableOutlineFont = class(TScalableFont) + protected + function GetOutset(): single; virtual; + function CreateMipmap(Level: integer; Scale: single): TFont; override; + + public + constructor Create(const Filename: string; + Size: integer; OutsetAmount: single; + UseMipmaps: boolean = true); + + {** Sets the color of the outline *} + procedure SetOutlineColor(r, g, b: GLfloat; a: GLfloat = 1.0); + + {** @see TGlyphCache.FlushCache *} + procedure FlushCache(KeepBaseSet: boolean); + + {** Outset size *} + property Outset: single read GetOutset; + end; + +{$IFDEF BITMAP_FONT} + + {** + * A bitmapped font loads it's glyphs from a bitmap and stores them in a + * texture. Unicode characters are not supported (but could be by supporting + * multiple textures each storing a subset of unicode glyphs). + * For backward compatibility only. + *} + TBitmapFont = class(TFont) + private + fTex: TTexture; + fTexSize: integer; + fBaseline: integer; + fAscender: integer; + fDescender: integer; + fWidths: array[0..255] of byte; // half widths + fOutline: integer; + fTempColor: TGLColor; ///< colours for the reflection + + procedure ResetIntern(); + + procedure RenderChar(ch: WideChar; var AdvanceX: real); + + {** + * Load font widths from an info file. + * @param InfoFile: the name of the info (.dat) file + * @raises Exception if the file is corrupted + *} + procedure LoadFontInfo(const InfoFile: string); + + protected + procedure Render(const Text: WideString); override; + function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; + + function GetHeight(): single; override; + function GetAscender(): single; override; + function GetDescender(): single; override; + function GetUnderlinePosition(): single; override; + function GetUnderlineThickness(): single; override; + + public + {** + * Creates a bitmapped font from image Filename and font width info + * loaded from the corresponding file with ending .dat. + * @param Baseline: y-coord of the baseline given in cartesian coords + * (y-axis up) and from the lower edge of the glyphs bounding box + * @param Ascender: pixels from baseline to top of highest glyph + *} + constructor Create(const Filename: string; Outline: integer; + Baseline, Ascender, Descender: integer); + destructor Destroy(); override; + + {** + * Corrects font widths provided by the info file. + * NewWidth := Width * WidthMult + WidthAdd + *} + procedure CorrectWidths(WidthMult: real; WidthAdd: integer); + + {** @see TFont.Reset *} + procedure Reset(); override; + end; + +{$ENDIF BITMAP_FONT} + + TFreeType = class + public + {** + * Returns a pointer to the freetype library singleton. + * If non exists, freetype will be initialized. + * @raises Exception if initialization failed + *} + class function GetLibrary(): FT_Library; + class procedure FreeLibrary(); + end; + + +implementation + +uses Types; + +const + // shear factor used for the italic effect (bigger value -> more bending) + cShearFactor = 0.25; + cShearMatrix: array[0..15] of GLfloat = ( + 1, 0, 0, 0, + cShearFactor, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + ); + cShearMatrixInv: array[0..15] of GLfloat = ( + 1, 0, 0, 0, + -cShearFactor, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + ); + +var + LibraryInst: FT_Library; + +function NewGLColor(r, g, b, a: GLfloat): TGLColor; +begin + Result.r := r; + Result.g := g; + Result.b := b; + Result.a := a; +end; + +{** + * Returns the first power of 2 >= Value. + *} +function NextPowerOf2(Value: integer): integer; {$IFDEF HasInline}inline;{$ENDIF} +begin + Result := 1; + while (Result < Value) do + Result := Result shl 1; +end; + + +{* + * TFont + *} + +constructor TFont.Create(); +begin + inherited; + ResetIntern(); +end; + +destructor TFont.Destroy(); +begin + inherited; +end; + +procedure TFont.ResetIntern(); +begin + fStyle := []; + fUseKerning := true; + fGlyphSpacing := 0.0; + fReflectionPass := false; + + // must be set by subclasses + fLineSpacing := 0.0; + fReflectionSpacing := 0.0; +end; + +procedure TFont.Reset(); +begin + ResetIntern(); +end; + +procedure TFont.SplitLines(const Text: UTF8String; var Lines: TWideStringArray); +var + LineList: TStringList; + LineIndex: integer; +begin + // split lines on newline (there is no WideString version of ExtractStrings) + LineList := TStringList.Create(); + ExtractStrings([#13], [], PChar(Text), LineList); + + // create an array of WideStrins from the UTF-8 string-list + SetLength(Lines, LineList.Count); + for LineIndex := 0 to LineList.Count-1 do + Lines[LineIndex] := UTF8Decode(LineList[LineIndex]); + LineList.Free(); +end; + +function TFont.BBox(const Text: UTF8String; Advance: boolean): TBoundsDbl; +var + LineArray: TWideStringArray; +begin + SplitLines(Text, LineArray); + Result := BBox(LineArray, Advance); + SetLength(LineArray, 0); +end; + +function TFont.BBox(const Text: WideString; Advance: boolean): TBoundsDbl; +begin + Result := BBox(UTF8Encode(Text), Advance); +end; + +procedure TFont.Print(const Text: TWideStringArray); +var + LineIndex: integer; +begin + // recursively call this function to draw reflected text + if ((Reflect in Style) and not ReflectionPass) then + begin + ReflectionPass := true; + Print(Text); + ReflectionPass := false; + end; + + // store current color, enable-flags, matrix-mode + glPushAttrib(GL_CURRENT_BIT or GL_ENABLE_BIT or GL_TRANSFORM_BIT); + + // set OpenGL state + glMatrixMode(GL_MODELVIEW); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + { + // TODO: just draw texels with alpha > 0 to avoid setting z-buffer for them? + glAlphaFunc(GL_GREATER, 0); + glEnable(GL_ALPHA_TEST); + + //TODO: Do we need depth-testing? + if (ReflectionPass) then + begin + glDepthMask(0); + glEnable(GL_DEPTH_TEST); + end; + } + + {$IFDEF FLIP_YAXIS} + glPushMatrix(); + glScalef(1, -1, 1); + {$ENDIF} + + // display text + for LineIndex := 0 to High(Text) do + begin + glPushMatrix(); + + // move to baseline + glTranslatef(0, -LineSpacing*LineIndex, 0); + + if ((Underline in Style) and not ReflectionPass) then + begin + glDisable(GL_TEXTURE_2D); + DrawUnderline(Text[LineIndex]); + glEnable(GL_TEXTURE_2D); + end; + + // draw reflection + if (ReflectionPass) then + begin + // set reflection spacing + glTranslatef(0, -ReflectionSpacing, 0); + // flip y-axis + glScalef(1, -1, 1); + end; + + // shear for italic effect + if (Italic in Style) then + glMultMatrixf(@cShearMatrix); + + // render text line + Render(Text[LineIndex]); + + glPopMatrix(); + end; + + // restore settings + {$IFDEF FLIP_YAXIS} + glPopMatrix(); + {$ENDIF} + glPopAttrib(); +end; + +procedure TFont.Print(const Text: string); +var + LineArray: TWideStringArray; +begin + SplitLines(Text, LineArray); + Print(LineArray); + SetLength(LineArray, 0); +end; + +procedure TFont.Print(const Text: WideString); +begin + Print(UTF8Encode(Text)); +end; + +procedure TFont.DrawUnderline(const Text: WideString); +var + UnderlineY1, UnderlineY2: single; + Bounds: TBoundsDbl; +begin + UnderlineY1 := GetUnderlinePosition(); + UnderlineY2 := UnderlineY1 + GetUnderlineThickness(); + Bounds := BBox(Text); + glRectf(Bounds.Left, UnderlineY1, Bounds.Right, UnderlineY2); +end; + +procedure TFont.SetStyle(Style: TFontStyle); +begin + fStyle := Style; +end; + +function TFont.GetStyle(): TFontStyle; +begin + Result := fStyle; +end; + +procedure TFont.SetLineSpacing(Spacing: single); +begin + fLineSpacing := Spacing; +end; + +function TFont.GetLineSpacing(): single; +begin + Result := fLineSpacing; +end; + +procedure TFont.SetGlyphSpacing(Spacing: single); +begin + fGlyphSpacing := Spacing; +end; + +function TFont.GetGlyphSpacing(): single; +begin + Result := fGlyphSpacing; +end; + +procedure TFont.SetReflectionSpacing(Spacing: single); +begin + fReflectionSpacing := Spacing; +end; + +function TFont.GetReflectionSpacing(): single; +begin + Result := fReflectionSpacing; +end; + +procedure TFont.SetUseKerning(Enable: boolean); +begin + fUseKerning := Enable; +end; + +function TFont.GetUseKerning(): boolean; +begin + Result := fUseKerning; +end; + +procedure TFont.SetReflectionPass(Enable: boolean); +begin + fReflectionPass := Enable; +end; + + +{* + * TScalableFont + *} + +constructor TScalableFont.Create(Font: TFont; UseMipmaps: boolean); +var + MipmapLevel: integer; +begin + inherited Create(); + + fBaseFont := Font; + fMipmapFonts[0] := Font; + fUseMipmaps := UseMipmaps; + ResetIntern(); + + // create mipmap fonts if requested + if (UseMipmaps) then + begin + for MipmapLevel := 1 to cMaxMipmapLevel do + begin + fMipmapFonts[MipmapLevel] := CreateMipmap(MipmapLevel, 1/(1 shl MipmapLevel)); + // stop if no smaller mipmap font is returned + if (fMipmapFonts[MipmapLevel] = nil) then + Break; + end; + end; +end; + +destructor TScalableFont.Destroy(); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + fMipmapFonts[Level].Free; + inherited; +end; + +procedure TScalableFont.ResetIntern(); +begin + fScale := 1.0; + fAspect := 1.0; +end; + +procedure TScalableFont.Reset(); +var + Level: integer; +begin + inherited; + ResetIntern(); + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + fMipmapFonts[Level].Reset(); +end; + +{** + * Returns the mipmap level to use with regard to the current projection + * and modelview matrix, font scale and aspect. + * + * Note: + * - for Freetype fonts, hinting and grid-fitting must be disabled, otherwise + * the glyph widths/heights ratios and advance widths of the mipmap fonts + * do not match as they are adjusted sligthly (e.g. an 'a' at size 12px has + * width 12px, but at size 6px width 8px). + * - returned mipmap-level is used for all glyphs of the current text to print. + * This is faster, much easier to handle, since we just need to create + * multiple sized fonts and select the one we need for the mipmap-level and + * it avoids that neighbored glyphs use different mipmap-level which might + * look odd because one glyph might look blurry and the other sharp. + * + * Motivation: + * We do not use OpenGL for mipmapping as the results are very bad. At least + * with automatic mipmap generation (gluBuildMipmaps) the fonts look rather + * blurry. + * Defining our own mipmaps by creating multiple textures with + * for different mimap levels is a pain, as the font size passed to freetype + * is not the size of the bitmaps created and it does not guarantee that a + * glyph bitmap of a font with font-size s/2 is half the size of the font with + * font-size s. If the bitmap size is just a single pixel bigger than the half + * we might need a texture of the next power-of-2 and the texture would not be + * half of the size of the next bigger mipmap. In addition we use a fixed one + * pixel sized border to smooth the texture (see cTexSmoothBorder) and maybe + * an outset that is added to the font, so creating a glyph mipmap that is + * exactly half the size of the next bigger one is a very difficult task. + * + * Solution: + * Use mipmap textures that are not exactly half the size of the next mipmap + * level. OpenGL does not support this (at least not without extensions). + * The trickiest task is to determine the mipmap to use by calculating the + * amount of minification that is performed in this function. + *} +function TScalableFont.GetMipmapLevel(): integer; +var + ModelMatrix, ProjMatrix: T16dArray; + WinCoords: array[0..2, 0..2] of GLdouble; + ViewPortArray: TViewPortArray; + Dist, Dist2: double; + WidthScale, HeightScale: double; +const + // width/height of square used for determining the scale + cTestSize = 10.0; + // an offset to the mipmap-level to adjust the change-over of two consecutive + // mipmap levels. If for example the bias is 0.1 and unbiased level is 1.9 + // the result level will be 2. A bias of 0.5 is equal to rounding. + // With bias=0.1 we prefer larger mipmaps over smaller ones. + cBias = 0.2; +begin + // 1. retrieve current transformation matrices for gluProject + glGetDoublev(GL_MODELVIEW_MATRIX, @ModelMatrix); + glGetDoublev(GL_PROJECTION_MATRIX, @ProjMatrix); + glGetIntegerv(GL_VIEWPORT, @ViewPortArray); + + // 2. project three of the corner points of a square with size cTestSize + // to window coordinates (the square is just a dummy for a glyph) + + // project point (x1, y1) to window corrdinates + gluProject(0, 0, 0, + ModelMatrix, ProjMatrix, ViewPortArray, + @WinCoords[0][0], @WinCoords[0][1], @WinCoords[0][2]); + // project point (x2, y1) to window corrdinates + gluProject(cTestSize, 0, 0, + ModelMatrix, ProjMatrix, ViewPortArray, + @WinCoords[1][0], @WinCoords[1][1], @WinCoords[1][2]); + // project point (x1, y2) to window corrdinates + gluProject(0, cTestSize, 0, + ModelMatrix, ProjMatrix, ViewPortArray, + @WinCoords[2][0], @WinCoords[2][1], @WinCoords[2][2]); + + // 3. Lets see how much the width and height of the square changed. + // Calculate the width and height as displayed on the screen in window + // coordinates and calculate the ratio to the original coordinates in + // modelview space so the ratio gives us the scale (minification here). + + // projected width ||(x1, y1) - (x2, y1)|| + Dist := (WinCoords[0][0] - WinCoords[1][0]); + Dist2 := (WinCoords[0][1] - WinCoords[1][1]); + WidthScale := cTestSize / Sqrt(Dist*Dist + Dist2*Dist2); + + // projected height ||(x1, y1) - (x1, y2)|| + Dist := (WinCoords[0][0] - WinCoords[2][0]); + Dist2 := (WinCoords[0][1] - WinCoords[2][1]); + HeightScale := cTestSize / Sqrt(Dist*Dist + Dist2*Dist2); + + //writeln(Format('Scale %f, %f', [WidthScale, HeightScale])); + + // 4. Now that we have got the scale, take the bigger minification scale + // and get it to a logarithmic scale as each mipmap is 1/2 the size of its + // predecessor (Mipmap_size[i] = Mipmap_size[i-1]/2). + // The result is our mipmap-level = the index of the mipmap to use. + + // Level > 0: Minification; < 0: Magnification + Result := Trunc(Log2(Max(WidthScale, HeightScale)) + cBias); + + // clamp to valid range + if (Result < 0) then + Result := 0; + if (Result > High(fMipmapFonts)) then + Result := High(fMipmapFonts); +end; + +function TScalableFont.GetMipmapScale(Level: integer): single; +begin + if (fMipmapFonts[Level] = nil) then + begin + Result := -1; + Exit; + end; + + Result := fScale * fMipmapFonts[0].Height / fMipmapFonts[Level].Height; +end; + +{** + * Returns the correct mipmap font for the current scale and projection + * matrix. The modelview scale is adjusted to the mipmap level, so + * Result.Print() will display the font in the correct size. + *} +function TScalableFont.ChooseMipmapFont(): TFont; +var + DesiredLevel: integer; + Level: integer; + MipmapScale: single; +begin + Result := nil; + DesiredLevel := GetMipmapLevel(); + + // get the smallest mipmap available for the desired level + // as not all levels must be assigned to a font. + for Level := DesiredLevel downto 0 do + begin + if (fMipmapFonts[Level] <> nil) then + begin + Result := fMipmapFonts[Level]; + Break; + end; + end; + + // since the mipmap font (if level > 0) is smaller than the base-font + // we have to scale to get its size right. + MipmapScale := fMipmapFonts[0].Height/Result.Height; + glScalef(MipmapScale, MipmapScale, 0); +end; + +procedure TScalableFont.Print(const Text: TWideStringArray); +begin + glPushMatrix(); + glScalef(fScale * fAspect, fScale, 0); + if (fUseMipmaps) then + ChooseMipmapFont().Print(Text) + else + fBaseFont.Print(Text); + glPopMatrix(); +end; + +procedure TScalableFont.Render(const Text: WideString); +begin + Assert(false, 'Unused TScalableFont.Render() was called'); +end; + +function TScalableFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; +begin + Result := fBaseFont.BBox(Text, Advance); + Result.Left := Result.Left * fScale; + Result.Right := Result.Right * fScale; + Result.Top := Result.Top * fScale; + Result.Bottom := Result.Bottom * fScale; +end; + +procedure TScalableFont.SetHeight(Height: single); +begin + fScale := Height / fBaseFont.GetHeight(); +end; + +function TScalableFont.GetHeight(): single; +begin + Result := fBaseFont.GetHeight() * fScale; +end; + +procedure TScalableFont.SetAspect(Aspect: single); +begin + fAspect := Aspect; +end; + +function TScalableFont.GetAspect(): single; +begin + Result := fAspect; +end; + +function TScalableFont.GetAscender(): single; +begin + Result := fBaseFont.GetAscender() * fScale; +end; + +function TScalableFont.GetDescender(): single; +begin + Result := fBaseFont.GetDescender() * fScale; +end; + +procedure TScalableFont.SetLineSpacing(Spacing: single); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + fMipmapFonts[Level].SetLineSpacing(Spacing / GetMipmapScale(Level)); +end; + +function TScalableFont.GetLineSpacing(): single; +begin + Result := fBaseFont.GetLineSpacing() * fScale; +end; + +procedure TScalableFont.SetGlyphSpacing(Spacing: single); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + fMipmapFonts[Level].SetGlyphSpacing(Spacing / GetMipmapScale(Level)); +end; + +function TScalableFont.GetGlyphSpacing(): single; +begin + Result := fBaseFont.GetGlyphSpacing() * fScale; +end; + +procedure TScalableFont.SetReflectionSpacing(Spacing: single); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + fMipmapFonts[Level].SetReflectionSpacing(Spacing / GetMipmapScale(Level)); +end; + +function TScalableFont.GetReflectionSpacing(): single; +begin + Result := fBaseFont.GetLineSpacing() * fScale; +end; + +procedure TScalableFont.SetStyle(Style: TFontStyle); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + fMipmapFonts[Level].SetStyle(Style); +end; + +function TScalableFont.GetStyle(): TFontStyle; +begin + Result := fBaseFont.GetStyle(); +end; + +function TScalableFont.GetUnderlinePosition(): single; +begin + Result := fBaseFont.GetUnderlinePosition(); +end; + +function TScalableFont.GetUnderlineThickness(): single; +begin + Result := fBaseFont.GetUnderlinePosition(); +end; + +procedure TScalableFont.SetUseKerning(Enable: boolean); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + fMipmapFonts[Level].SetUseKerning(Enable); +end; + + +{* + * TCachedFont + *} + +constructor TCachedFont.Create(); +begin + inherited; + fCache := TGlyphCache.Create(); +end; + +destructor TCachedFont.Destroy(); +begin + fCache.Free; + inherited; +end; + +function TCachedFont.GetGlyph(ch: WideChar): TGlyph; +begin + Result := fCache.GetGlyph(ch); + if (Result = nil) then + begin + Result := LoadGlyph(ch); + if (not fCache.AddGlyph(ch, Result)) then + Result.Free; + end; +end; + +procedure TCachedFont.FlushCache(KeepBaseSet: boolean); +begin + fCache.FlushCache(KeepBaseSet); +end; + + +{* + * TFTFont + *} + +constructor TFTFont.Create( + const Filename: string; + Size: integer; Outset: single; + LoadFlags: FT_Int32); +var + i: WideChar; +begin + inherited Create(); + + fFilename := Filename; + fSize := Size; + fOutset := Outset; + fLoadFlags := LoadFlags; + fUseDisplayLists := true; + + // load font information + if (FT_New_Face(TFreeType.GetLibrary(), PChar(Filename), 0, fFace) <> 0) then + raise Exception.Create('FT_New_Face: Could not load font ''' + Filename + ''''); + + // support scalable fonts only + if (not FT_IS_SCALABLE(fFace)) then + raise Exception.Create('Font is not scalable'); + + if (FT_Set_Pixel_Sizes(fFace, 0, Size) <> 0) then + raise Exception.Create('FT_Set_Pixel_Sizes failes'); + + // get scale factor for font-unit to pixel-size transformation + fFontUnitScale.X := fFace.size.metrics.x_ppem / fFace.units_per_EM; + fFontUnitScale.Y := fFace.size.metrics.y_ppem / fFace.units_per_EM; + + ResetIntern(); + + // pre-cache some commonly used glyphs (' ' - '~') + for i := #32 to #126 do + fCache.AddGlyph(i, TFTGlyph.Create(Self, i, Outset, LoadFlags)); +end; + +destructor TFTFont.Destroy(); +begin + // free face + FT_Done_Face(fFace); + inherited; +end; + +procedure TFTFont.ResetIntern(); +begin + // Note: outset and non outset fonts use same spacing + fLineSpacing := fFace.height * fFontUnitScale.Y; + fReflectionSpacing := -2*fFace.descender * fFontUnitScale.Y; +end; + +procedure TFTFont.Reset(); +begin + inherited; + ResetIntern(); +end; + +function TFTFont.LoadGlyph(ch: WideChar): TGlyph; +begin + Result := TFTGlyph.Create(Self, ch, Outset, fLoadFlags); +end; + +function TFTFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; +var + Glyph, PrevGlyph: TFTGlyph; + TextLine: WideString; + LineYOffset: single; + LineIndex, CharIndex: integer; + LineBounds: TBoundsDbl; + KernDelta: FT_Vector; + UnderlinePos: double; +begin + // Reset global bounds + Result.Left := Infinity; + Result.Right := 0; + Result.Bottom := Infinity; + Result.Top := 0; + + // reset last glyph + PrevGlyph := nil; + + // display text + for LineIndex := 0 to High(Text) do + begin + // get next text line + TextLine := Text[LineIndex]; + LineYOffset := -LineSpacing * LineIndex; + + // reset line bounds + LineBounds.Left := Infinity; + LineBounds.Right := 0; + LineBounds.Bottom := Infinity; + LineBounds.Top := 0; + + // for each glyph image, compute its bounding box + for CharIndex := 1 to Length(TextLine) do + begin + Glyph := TFTGlyph(GetGlyph(TextLine[CharIndex])); + if (Glyph <> nil) then + begin + // get kerning + if (fUseKerning and FT_HAS_KERNING(fFace) and (PrevGlyph <> nil)) then + begin + FT_Get_Kerning(fFace, PrevGlyph.CharIndex, Glyph.CharIndex, + FT_KERNING_UNSCALED, KernDelta); + LineBounds.Right := LineBounds.Right + KernDelta.x * fFontUnitScale.X; + end; + + // update left bound (must be done before right bound is updated) + if (LineBounds.Right + Glyph.Bounds.Left < LineBounds.Left) then + LineBounds.Left := LineBounds.Right + Glyph.Bounds.Left; + + // update right bound + if (CharIndex < Length(TextLine)) or // not the last character + (TextLine[CharIndex] = ' ') or // on space char (Bounds.Right = 0) + Advance then // or in advance mode + begin + // add advance and glyph spacing + LineBounds.Right := LineBounds.Right + Glyph.Advance.x + GlyphSpacing + end + else + begin + // add glyph's right bound + LineBounds.Right := LineBounds.Right + Glyph.Bounds.Right; + end; + + // update bottom and top bounds + if (Glyph.Bounds.Bottom < LineBounds.Bottom) then + LineBounds.Bottom := Glyph.Bounds.Bottom; + if (Glyph.Bounds.Top > LineBounds.Top) then + LineBounds.Top := Glyph.Bounds.Top; + end; + + PrevGlyph := Glyph; + end; + + // handle italic font style + if (Italic in Style) then + begin + LineBounds.Left := LineBounds.Left + LineBounds.Bottom * cShearFactor; + LineBounds.Right := LineBounds.Right + LineBounds.Top * cShearFactor; + end; + + // handle underlined font style + if (Underline in Style) then + begin + UnderlinePos := GetUnderlinePosition(); + if (UnderlinePos < LineBounds.Bottom) then + LineBounds.Bottom := UnderlinePos; + end; + + // add line offset + LineBounds.Bottom := LineBounds.Bottom + LineYOffset; + LineBounds.Top := LineBounds.Top + LineYOffset; + + // adjust global bounds + if (Result.Left > LineBounds.Left) then + Result.Left := LineBounds.Left; + if (Result.Right < LineBounds.Right) then + Result.Right := LineBounds.Right; + if (Result.Bottom > LineBounds.Bottom) then + Result.Bottom := LineBounds.Bottom; + if (Result.Top < LineBounds.Top) then + Result.Top := LineBounds.Top; + end; + + // if left or bottom bound was not set, set them to 0 + if (Result.Left = Infinity) then + Result.Left := 0.0; + if (Result.Bottom = Infinity) then + Result.Bottom := 0.0; +end; + +procedure TFTFont.Render(const Text: WideString); +var + CharIndex: integer; + Glyph, PrevGlyph: TFTGlyph; + KernDelta: FT_Vector; +begin + // reset last glyph + PrevGlyph := nil; + + // draw current line + for CharIndex := 1 to Length(Text) do + begin + Glyph := TFTGlyph(GetGlyph(Text[CharIndex])); + if (Assigned(Glyph)) then + begin + // get kerning + if (fUseKerning and FT_HAS_KERNING(fFace) and (PrevGlyph <> nil)) then + begin + FT_Get_Kerning(fFace, PrevGlyph.CharIndex, Glyph.CharIndex, + FT_KERNING_UNSCALED, KernDelta); + glTranslatef(KernDelta.x * fFontUnitScale.X, 0, 0); + end; + + if (ReflectionPass) then + Glyph.RenderReflection() + else + Glyph.Render(fUseDisplayLists); + + glTranslatef(Glyph.Advance.x + fGlyphSpacing, 0, 0); + end; + + PrevGlyph := Glyph; + end; +end; + +function TFTFont.GetHeight(): single; +begin + Result := Ascender - Descender; +end; + +function TFTFont.GetAscender(): single; +begin + Result := fFace.ascender * fFontUnitScale.Y + Outset*2; +end; + +function TFTFont.GetDescender(): single; +begin + // Note: outset is not part of the descender as the baseline is lifted + Result := fFace.descender * fFontUnitScale.Y; +end; + +function TFTFont.GetUnderlinePosition(): single; +begin + Result := fFace.underline_position * fFontUnitScale.Y - Outset; +end; + +function TFTFont.GetUnderlineThickness(): single; +begin + Result := fFace.underline_thickness * fFontUnitScale.Y + Outset*2; +end; + + +{* + * TFTScalableFont + *} + +constructor TFTScalableFont.Create(const Filename: string; + Size: integer; OutsetAmount: single; + UseMipmaps: boolean); +var + LoadFlags: FT_Int32; +begin + LoadFlags := FT_LOAD_DEFAULT; + // Disable hinting and grid-fitting to preserve font outlines at each font + // size, otherwise the font widths/heights do not match resulting in ugly + // text size changes during zooming. + // A drawback is a reduced quality with smaller font sizes but it is not that + // bad with gray-scaled rendering (at least it looks better than OpenGL's + // linear downscaling on minification). + if (UseMipmaps) then + LoadFlags := LoadFlags or FT_LOAD_NO_HINTING; + inherited Create( + TFTFont.Create(Filename, Size, Size * OutsetAmount, LoadFlags), + UseMipmaps); +end; + +function TFTScalableFont.CreateMipmap(Level: integer; Scale: single): TFont; +var + ScaledSize: integer; + BaseFont: TFTFont; +begin + Result := nil; + BaseFont := TFTFont(fBaseFont); + ScaledSize := Round(BaseFont.Size * Scale); + // do not create mipmap fonts < 8 pixels + if (ScaledSize < 8) then + Exit; + Result := TFTFont.Create(BaseFont.fFilename, + ScaledSize, BaseFont.fOutset * Scale, + FT_LOAD_DEFAULT or FT_LOAD_NO_HINTING); +end; + +function TFTScalableFont.GetOutset(): single; +begin + Result := TFTFont(fBaseFont).Outset * fScale; +end; + +procedure TFTScalableFont.FlushCache(KeepBaseSet: boolean); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + TFTFont(fMipmapFonts[Level]).FlushCache(KeepBaseSet); +end; + + +{* + * TOutlineFont + *} + +constructor TFTOutlineFont.Create( + const Filename: string; + Size: integer; Outset: single; + LoadFlags: FT_Int32); +begin + inherited Create(); + + fFilename := Filename; + fSize := Size; + fOutset := Outset; + + fInnerFont := TFTFont.Create(Filename, Size, 0.0, LoadFlags); + fOutlineFont := TFTFont.Create(Filename, Size, Outset, LoadFlags); + + ResetIntern(); +end; + +destructor TFTOutlineFont.Destroy; +begin + fOutlineFont.Free; + fInnerFont.Free; + inherited; +end; + +procedure TFTOutlineFont.ResetIntern(); +begin + // TODO: maybe swap fInnerFont/fOutlineFont.GlyphSpacing to use the spacing + // of the outline font? + //fInnerFont.GlyphSpacing := fOutset*2; + fOutlineFont.GlyphSpacing := -fOutset*2; + + fLineSpacing := fOutlineFont.LineSpacing; + fReflectionSpacing := fOutlineFont.ReflectionSpacing; + fOutlineColor := NewGLColor(0, 0, 0, 1); +end; + +procedure TFTOutlineFont.Reset(); +begin + inherited; + fInnerFont.Reset(); + fOutlineFont.Reset(); + ResetIntern(); +end; + +procedure TFTOutlineFont.DrawUnderline(const Text: WideString); +begin + glPushAttrib(GL_CURRENT_BIT); + glColor4fv(@fOutlineColor.vals); + fOutlineFont.DrawUnderline(Text); + glPopAttrib(); + + glPushMatrix(); + glTranslatef(fOutset, 0, 0); + fInnerFont.DrawUnderline(Text); + glPopMatrix(); +end; + +procedure TFTOutlineFont.Render(const Text: WideString); +begin + { setup and render outline font } + + // save old color + glPushAttrib(GL_CURRENT_BIT); + glColor4fv(@fOutlineColor.vals); + glPushMatrix(); + fOutlineFont.Render(Text); + glPopMatrix(); + glPopAttrib(); + + { setup and render inner font } + + glPushMatrix(); + glTranslatef(fOutset, fOutset, 0); + fInnerFont.Render(Text); + glPopMatrix(); +end; + +procedure TFTOutlineFont.SetOutlineColor(r, g, b: GLfloat; a: GLfloat); +begin + fOutlineColor := NewGLColor(r, g, b, a); +end; + +procedure TFTOutlineFont.FlushCache(KeepBaseSet: boolean); +begin + fOutlineFont.FlushCache(KeepBaseSet); + fInnerFont.FlushCache(KeepBaseSet); +end; + +function TFTOutlineFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; +begin + Result := fOutlineFont.BBox(Text, Advance); +end; + +function TFTOutlineFont.GetHeight(): single; +begin + Result := fOutlineFont.Height; +end; + +function TFTOutlineFont.GetAscender(): single; +begin + Result := fOutlineFont.Ascender; +end; + +function TFTOutlineFont.GetDescender(): single; +begin + Result := fOutlineFont.Descender; +end; + +procedure TFTOutlineFont.SetLineSpacing(Spacing: single); +begin + inherited SetLineSpacing(Spacing); + fInnerFont.LineSpacing := Spacing; + fOutlineFont.LineSpacing := Spacing; +end; + +procedure TFTOutlineFont.SetGlyphSpacing(Spacing: single); +begin + inherited SetGlyphSpacing(Spacing); + fInnerFont.GlyphSpacing := Spacing; + fOutlineFont.GlyphSpacing := Spacing - Outset*2; +end; + +procedure TFTOutlineFont.SetReflectionSpacing(Spacing: single); +begin + inherited SetReflectionSpacing(Spacing); + fInnerFont.ReflectionSpacing := Spacing; + fOutlineFont.ReflectionSpacing := Spacing; +end; + +procedure TFTOutlineFont.SetStyle(Style: TFontStyle); +begin + inherited SetStyle(Style); + fInnerFont.Style := Style; + fOutlineFont.Style := Style; +end; + +function TFTOutlineFont.GetStyle(): TFontStyle; +begin + Result := inherited GetStyle(); +end; + +function TFTOutlineFont.GetUnderlinePosition(): single; +begin + Result := fOutlineFont.GetUnderlinePosition(); +end; + +function TFTOutlineFont.GetUnderlineThickness(): single; +begin + Result := fOutlineFont.GetUnderlinePosition(); +end; + +procedure TFTOutlineFont.SetUseKerning(Enable: boolean); +begin + inherited SetUseKerning(Enable); + fInnerFont.fUseKerning := Enable; + fOutlineFont.fUseKerning := Enable; +end; + +procedure TFTOutlineFont.SetReflectionPass(Enable: boolean); +begin + inherited SetReflectionPass(Enable); + fInnerFont.fReflectionPass := Enable; + fOutlineFont.fReflectionPass := Enable; +end; + +{** + * TScalableOutlineFont + *} + +constructor TFTScalableOutlineFont.Create( + const Filename: string; + Size: integer; OutsetAmount: single; + UseMipmaps: boolean); +var + LoadFlags: FT_Int32; +begin + LoadFlags := FT_LOAD_DEFAULT; + // Disable hinting and grid-fitting (see TFTScalableFont.Create) + if (UseMipmaps) then + LoadFlags := LoadFlags or FT_LOAD_NO_HINTING; + inherited Create( + TFTOutlineFont.Create(Filename, Size, Size*OutsetAmount, LoadFlags), + UseMipmaps); +end; + +function TFTScalableOutlineFont.CreateMipmap(Level: integer; Scale: single): TFont; +var + ScaledSize: integer; + BaseFont: TFTOutlineFont; +begin + Result := nil; + BaseFont := TFTOutlineFont(fBaseFont); + ScaledSize := Round(BaseFont.Size*Scale); + // do not create mipmap fonts < 8 pixels + if (ScaledSize < 8) then + Exit; + Result := TFTOutlineFont.Create(BaseFont.fFilename, + ScaledSize, BaseFont.fOutset*Scale, + FT_LOAD_DEFAULT or FT_LOAD_NO_HINTING); +end; + +function TFTScalableOutlineFont.GetOutset(): single; +begin + Result := TFTOutlineFont(fBaseFont).Outset * fScale; +end; + +procedure TFTScalableOutlineFont.SetOutlineColor(r, g, b: GLfloat; a: GLfloat); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + TFTOutlineFont(fMipmapFonts[Level]).SetOutlineColor(r, g, b, a); +end; + +procedure TFTScalableOutlineFont.FlushCache(KeepBaseSet: boolean); +var + Level: integer; +begin + for Level := 0 to High(fMipmapFonts) do + if (fMipmapFonts[Level] <> nil) then + TFTOutlineFont(fMipmapFonts[Level]).FlushCache(KeepBaseSet); +end; + + +{* + * TFTGlyph + *} + +const + {** + * Size of the transparent border surrounding the glyph image in the texture. + * The border is necessary because OpenGL does not smooth texels at the + * border of a texture with the GL_CLAMP or GL_CLAMP_TO_EDGE styles. + * Without the border, magnified glyph textures look very ugly at their edges. + * It looks edgy, as if some pixels are missing especially on the left edge + * (just set cTexSmoothBorder to 0 to see what is meant by this). + * With the border even the glyphs edges are blended to the border (transparent) + * color and everything looks nice. + * + * Note: + * OpenGL already supports texture border by setting the border parameter + * of glTexImage*D() to 1 and using a texture size of 2^m+2b and setting the + * border pixels to the border color. In some forums it is discouraged to use + * the border parameter as only a few of the more modern graphics cards support + * this feature. On an ATI Radeon 9700 card, the slowed down to 0.5 fps and + * the glyph's background got black. So instead of using this feature we + * handle it on our own. The only drawback is that textures might get bigger + * because the border might require a higher power of 2 size instead of just + * two additional pixels. + *} + cTexSmoothBorder = 1; + +procedure TFTGlyph.Extrude(var TexBuffer: TGLubyteDynArray; Outset: single); + + procedure SetToMax(var Val1: GLubyte; Val2: GLubyte); {$IFDEF HasInline}inline;{$ENDIF} + begin + if (Val1 < Val2) then + Val1 := Val2; + end; + +var + I, X, Y: integer; + SrcBuffer,TmpBuffer: TGLubyteDynArray; + TexLine, TexLinePrev, TexLineNext: PGLubyteArray; + SrcLine: PGLubyteArray; + AlphaScale: single; + Value, ValueNeigh, ValueDiag: GLubyte; +const + // square-root of 2 used for diagonal neighbor pixels + cSqrt2 = 1.4142; + // number of ignored pixels on each edge of the bitmap. Consists of: + // - border used for font smoothing and + // - outer (extruded) bitmap pixel (because it is just written but never read) + cBorder = cTexSmoothBorder + 1; +begin + // allocate memory for temporary buffer + SetLength(SrcBuffer, Length(TexBuffer)); + FillChar(SrcBuffer[0], Length(TexBuffer), 0); + + // extrude pixel by pixel + for I := 1 to Ceil(Outset) do + begin + // swap arrays + TmpBuffer := TexBuffer; + TexBuffer := SrcBuffer; + SrcBuffer := TmpBuffer; + + // as long as we add an entire pixel of outset, use a solid color. + // If the fractional part is reached blend, e.g. outline=3.2 -> 3 solid + // pixels and one blended with alpha=0.2. + // For the fractional part I = Ceil(Outset) is always true. + if (I <= Outset) then + AlphaScale := 1 + else + AlphaScale := Outset - Trunc(Outset); + + // copy data to the expanded bitmap. + for Y := cBorder to fTexSize.Height - 2*cBorder do + begin + TexLine := @TexBuffer[Y*fTexSize.Width]; + TexLinePrev := @TexBuffer[(Y-1)*fTexSize.Width]; + TexLineNext := @TexBuffer[(Y+1)*fTexSize.Width]; + SrcLine := @SrcBuffer[Y*fTexSize.Width]; + + // expand current line's pixels + for X := cBorder to fTexSize.Width - 2*cBorder do + begin + Value := SrcLine[X]; + ValueNeigh := Round(Value * AlphaScale); + ValueDiag := Round(ValueNeigh / cSqrt2); + + SetToMax(TexLine[X], Value); + SetToMax(TexLine[X-1], ValueNeigh); + SetToMax(TexLine[X+1], ValueNeigh); + + SetToMax(TexLinePrev[X], ValueNeigh); + SetToMax(TexLinePrev[X-1], ValueDiag); + SetToMax(TexLinePrev[X+1], ValueDiag); + + SetToMax(TexLineNext[X], ValueNeigh); + SetToMax(TexLineNext[X-1], ValueDiag); + SetToMax(TexLineNext[X+1], ValueDiag); + end; + end; + end; + + TmpBuffer := nil; + SetLength(SrcBuffer, 0); +end; + +procedure TFTGlyph.CreateTexture(LoadFlags: FT_Int32); +var + X, Y: integer; + Glyph: FT_Glyph; + BitmapGlyph: FT_BitmapGlyph; + Bitmap: PFT_Bitmap; + BitmapLine: PChar; + BitmapBuffer: PChar; + TexBuffer: TGLubyteDynArray; + TexLine: PGLubyteArray; + CBox: FT_BBox; +begin + // load the Glyph for our character + if (FT_Load_Glyph(fFont.Face, fCharIndex, LoadFlags) <> 0) then + raise Exception.Create('FT_Load_Glyph failed'); + + // move the face's glyph into a Glyph object + if (FT_Get_Glyph(fFont.Face^.glyph, Glyph) <> 0) then + raise Exception.Create('FT_Get_Glyph failed'); + + // store scaled advance width/height in glyph-object + fAdvance.X := fFont.Face^.glyph^.advance.x / 64 + fOutset*2; + fAdvance.Y := fFont.Face^.glyph^.advance.y / 64 + fOutset*2; + + // get the contour's bounding box (in 1/64th pixels, not font-units) + FT_Glyph_Get_CBox(Glyph, FT_GLYPH_BBOX_UNSCALED, CBox); + // convert 1/64th values to double values + fBounds.Left := CBox.xMin / 64; + fBounds.Right := CBox.xMax / 64 + fOutset*2; + fBounds.Bottom := CBox.yMin / 64; + fBounds.Top := CBox.yMax / 64 + fOutset*2; + + // convert the glyph to a bitmap (and destroy original glyph image) + FT_Glyph_To_Bitmap(Glyph, ft_render_mode_normal, nil, 1); + BitmapGlyph := FT_BitmapGlyph(Glyph); + + // get bitmap offsets + fBitmapCoords.Left := BitmapGlyph^.left - cTexSmoothBorder; + // Note: add 1*fOutset for lifting the baseline so outset fonts to not intersect + // with the baseline; Ceil(fOutset) for the outset pixels added to the bitmap. + fBitmapCoords.Top := BitmapGlyph^.top + fOutset+Ceil(fOutset) + cTexSmoothBorder; + + // make accessing the bitmap easier + Bitmap := @BitmapGlyph^.bitmap; + // get bitmap dimensions + fBitmapCoords.Width := Bitmap.width + (Ceil(fOutset) + cTexSmoothBorder)*2; + fBitmapCoords.Height := Bitmap.rows + (Ceil(fOutset) + cTexSmoothBorder)*2; + + // get power-of-2 bitmap widths + fTexSize.Width := + NextPowerOf2(Bitmap.width + (Ceil(fOutset) + cTexSmoothBorder)*2); + fTexSize.Height := + NextPowerOf2(Bitmap.rows + (Ceil(fOutset) + cTexSmoothBorder)*2); + + // texture-widths ignoring empty (power-of-2) padding space + fTexOffset.X := fBitmapCoords.Width / fTexSize.Width; + fTexOffset.Y := fBitmapCoords.Height / fTexSize.Height; + + // allocate memory for texture data + SetLength(TexBuffer, fTexSize.Width * fTexSize.Height); + FillChar(TexBuffer[0], Length(TexBuffer), 0); + + // Freetype stores the bitmap with either upper (pitch is > 0) or lower + // (pitch < 0) glyphs line first. Set the buffer to the upper line. + // See http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-7.html + if (Bitmap.pitch > 0) then + BitmapBuffer := @Bitmap.buffer[0] + else + BitmapBuffer := @Bitmap.buffer[(Bitmap.rows-1) * Abs(Bitmap.pitch)]; + + // copy data to texture bitmap (upper line first). + for Y := 0 to Bitmap.rows-1 do + begin + // set pointer to first pixel in line that holds bitmap data. + // Each line starts with a cTexSmoothBorder pixel and multiple outset pixels + // that are added by Extrude() later. + TexLine := @TexBuffer[(Y + cTexSmoothBorder + Ceil(fOutset)) * fTexSize.Width + + cTexSmoothBorder + Ceil(fOutset)]; + // get next lower line offset, use pitch instead of width as it tells + // us the storage direction of the lines. In addition a line might be padded. + BitmapLine := @BitmapBuffer[Y * Bitmap.pitch]; + for X := 0 to Bitmap.width-1 do + TexLine[X] := GLubyte(BitmapLine[X]); + end; + + if (fOutset > 0) then + Extrude(TexBuffer, fOutset); + + // allocate resources for textures and display lists + glGenTextures(1, @fTexture); + + // setup texture paramaters + glBindTexture(GL_TEXTURE_2D, fTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + // create alpha-map (GL_ALPHA component only). + // TexCoord (0,0) corresponds to the top left pixel of the glyph, + // (1,1) to the bottom right pixel. So the glyph is flipped as OpenGL uses + // a cartesian (y-axis up) coordinate system for textures. + // See the cTexSmoothBorder comment for info on texture borders. + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, fTexSize.Width, fTexSize.Height, + 0, GL_ALPHA, GL_UNSIGNED_BYTE, @TexBuffer[0]); + + // free expanded data + SetLength(TexBuffer, 0); + + // create the display list + fDisplayList := glGenLists(1); + + // render to display-list + glNewList(fDisplayList, GL_COMPILE); + Render(false); + glEndList(); + + // free glyph data (bitmap, etc.) + FT_Done_Glyph(Glyph); +end; + +constructor TFTGlyph.Create(Font: TFTFont; ch: WideChar; Outset: single; + LoadFlags: FT_Int32); +begin + inherited Create(); + + fFont := Font; + fOutset := Outset; + + // get the Freetype char-index (use default UNICODE charmap) + fCharIndex := FT_Get_Char_Index(Font.fFace, FT_ULONG(ch)); + + CreateTexture(LoadFlags); +end; + +destructor TFTGlyph.Destroy; +begin + if (fDisplayList <> 0) then + glDeleteLists(fDisplayList, 1); + if (fTexture <> 0) then + glDeleteTextures(1, @fTexture); + inherited; +end; + +procedure TFTGlyph.Render(UseDisplayLists: boolean); +begin + // use display-lists if enabled and exit + if (UseDisplayLists) then + begin + glCallList(fDisplayList); + Exit; + end; + + glBindTexture(GL_TEXTURE_2D, fTexture); + glPushMatrix(); + + // move to top left glyph position + glTranslatef(fBitmapCoords.Left, fBitmapCoords.Top, 0); + + // draw glyph texture + glBegin(GL_QUADS); + // top right + glTexCoord2f(fTexOffset.X, 0); + glVertex2f(fBitmapCoords.Width, 0); + + // top left + glTexCoord2f(0, 0); + glVertex2f(0, 0); + + // bottom left + glTexCoord2f(0, fTexOffset.Y); + glVertex2f(0, -fBitmapCoords.Height); + + // bottom right + glTexCoord2f(fTexOffset.X, fTexOffset.Y); + glVertex2f(fBitmapCoords.Width, -fBitmapCoords.Height); + glEnd(); + + glPopMatrix(); +end; + +procedure TFTGlyph.RenderReflection(); +var + Color: TGLColor; + TexUpperPos: single; + TexLowerPos: single; + UpperPos: single; +const + CutOff = 0.6; +begin + glPushMatrix(); + glBindTexture(GL_TEXTURE_2D, fTexture); + glGetFloatv(GL_CURRENT_COLOR, @Color.vals); + + // add extra space to the left of the glyph + glTranslatef(fBitmapCoords.Left, 0, 0); + + // The upper position of the glyph, if CutOff is 1.0, it is fFont.Ascender. + // If CutOff is set to 0.5 only half of the glyph height is displayed. + UpperPos := fFont.Descender + fFont.Height * CutOff; + + // the glyph texture's height is just the height of the glyph but not the font + // height. Setting a color for the upper and lower bounds of the glyph results + // in different color gradients. So we have to set the color values for the + // descender and ascender (as we have a cutoff, for the upper-pos here) as + // these positions are font but not glyph specific. + + // To get the texture positions we have to enhance the texture at the top and + // bottom by the amount from the top to ascender (rather upper-pos here) and + // from the bottom (Height-Top) to descender. Then we have to convert those + // heights to texture coordinates by dividing by the bitmap Height and + // removing the power-of-2 padding space by multiplying with fTexOffset.Y + // (as fBitmapCoords.Height corresponds to fTexOffset.Y and not 1.0). + TexUpperPos := -(UpperPos - fBitmapCoords.Top) / fBitmapCoords.Height * fTexOffset.Y; + TexLowerPos := (-(fFont.Descender + fBitmapCoords.Height - fBitmapCoords.Top) / + fBitmapCoords.Height + 1) * fTexOffset.Y; + + // draw glyph texture + glBegin(GL_QUADS); + // top right + glColor4f(Color.r, Color.g, Color.b, 0); + glTexCoord2f(fTexOffset.X, TexUpperPos); + glVertex2f(fBitmapCoords.Width, UpperPos); + + // top left + glTexCoord2f(0, TexUpperPos); + glVertex2f(0, UpperPos); + + // bottom left + glColor4f(Color.r, Color.g, Color.b, Color.a-0.3); + glTexCoord2f(0, TexLowerPos); + glVertex2f(0, fFont.Descender); + + // bottom right + glTexCoord2f(fTexOffset.X, TexLowerPos); + glVertex2f(fBitmapCoords.Width, fFont.Descender); + glEnd(); + + glPopMatrix(); + + // restore old color + // Note: glPopAttrib(GL_CURRENT_BIT)/glPopAttrib() is much slower then + // glGetFloatv(GL_CURRENT_COLOR, ...)/glColor4fv(...) + glColor4fv(@Color.vals); +end; + +function TFTGlyph.GetAdvance(): TPositionDbl; +begin + Result := fAdvance; +end; + +function TFTGlyph.GetBounds(): TBoundsDbl; +begin + Result := fBounds; +end; + + +{* + * TGlyphCache + *} + +constructor TGlyphCache.Create(); +begin + inherited; + fHash := TList.Create(); +end; + +destructor TGlyphCache.Destroy(); +begin + // free cached glyphs + FlushCache(false); + + // destroy TList + fHash.Free; + + inherited; +end; + +function TGlyphCache.FindGlyphTable(BaseCode: cardinal; out InsertPos: integer): PGlyphTable; +var + I: integer; + Entry: TGlyphCacheHashEntry; +begin + Result := nil; + + for I := 0 to fHash.Count-1 do + begin + Entry := TGlyphCacheHashEntry(fHash[I]); + + if (Entry.BaseCode > BaseCode) then + begin + InsertPos := I; + Exit; + end; + + if (Entry.BaseCode = BaseCode) then + begin + InsertPos := I; + Result := @Entry.GlyphTable; + Exit; + end; + end; + + InsertPos := fHash.Count; +end; + +function TGlyphCache.AddGlyph(ch: WideChar; const Glyph: TGlyph): boolean; +var + BaseCode: cardinal; + GlyphCode: integer; + InsertPos: integer; + GlyphTable: PGlyphTable; + Entry: TGlyphCacheHashEntry; +begin + Result := false; + + BaseCode := cardinal(ch) shr 8; + GlyphTable := FindGlyphTable(BaseCode, InsertPos); + if (GlyphTable = nil) then + begin + Entry := TGlyphCacheHashEntry.Create(BaseCode); + GlyphTable := @Entry.GlyphTable; + fHash.Insert(InsertPos, Entry); + end; + + // get glyph table offset + GlyphCode := cardinal(ch) and $FF; + // insert glyph into table if not present + if (GlyphTable[GlyphCode] = nil) then + begin + GlyphTable[GlyphCode] := Glyph; + Result := true; + end; +end; + +procedure TGlyphCache.DeleteGlyph(ch: WideChar); +var + Table: PGlyphTable; + TableIndex, GlyphIndex: integer; + TableEmpty: boolean; +begin + // find table + Table := FindGlyphTable(cardinal(ch) shr 8, TableIndex); + if (Table = nil) then + Exit; + + // find glyph + GlyphIndex := cardinal(ch) and $FF; + if (Table[GlyphIndex] <> nil) then + begin + // destroy glyph + FreeAndNil(Table[GlyphIndex]); + + // check if table is empty + TableEmpty := true; + for GlyphIndex := 0 to High(Table^) do + begin + if (Table[GlyphIndex] <> nil) then + begin + TableEmpty := false; + Break; + end; + end; + + // free empty table + if (TableEmpty) then + begin + fHash.Delete(TableIndex); + end; + end; +end; + +function TGlyphCache.GetGlyph(ch: WideChar): TGlyph; +var + InsertPos: integer; + Table: PGlyphTable; +begin + Table := FindGlyphTable(cardinal(ch) shr 8, InsertPos); + if (Table = nil) then + Result := nil + else + Result := Table[cardinal(ch) and $FF]; +end; + +function TGlyphCache.HasGlyph(ch: WideChar): boolean; +begin + Result := (GetGlyph(ch) <> nil); +end; + +procedure TGlyphCache.FlushCache(KeepBaseSet: boolean); +var + EntryIndex, TableIndex: integer; + Entry: TGlyphCacheHashEntry; +begin + // destroy cached glyphs + for EntryIndex := 0 to fHash.Count-1 do + begin + Entry := TGlyphCacheHashEntry(fHash[EntryIndex]); + + // the base set (0-255) has BaseCode 0 as the upper bytes are 0. + if KeepBaseSet and (Entry.fBaseCode = 0) then + Continue; + + for TableIndex := 0 to High(Entry.GlyphTable) do + begin + if (Entry.GlyphTable[TableIndex] <> nil) then + FreeAndNil(Entry.GlyphTable[TableIndex]); + end; + FreeAndNil(Entry); + end; +end; + + +{* + * TGlyphCacheEntry + *} + +constructor TGlyphCacheHashEntry.Create(BaseCode: cardinal); +begin + inherited Create(); + fBaseCode := BaseCode; +end; + + +{* + * TFreeType + *} + +class function TFreeType.GetLibrary(): FT_Library; +begin + if (LibraryInst = nil) then + begin + // initialize freetype + if (FT_Init_FreeType(LibraryInst) <> 0) then + raise Exception.Create('FT_Init_FreeType failed'); + end; + Result := LibraryInst; +end; + +class procedure TFreeType.FreeLibrary(); +begin + if (LibraryInst <> nil) then + FT_Done_FreeType(LibraryInst); + LibraryInst := nil; +end; + + +{$IFDEF BITMAP_FONT} +{* + * TBitmapFont + *} + +constructor TBitmapFont.Create(const Filename: string; Outline: integer; + Baseline, Ascender, Descender: integer); +begin + inherited Create(); + + fTex := Texture.LoadTexture(true, Filename, TEXTURE_TYPE_TRANSPARENT, 0); + fTexSize := 1024; + fOutline := Outline; + fBaseline := Baseline; + fAscender := Ascender; + fDescender := Descender; + + LoadFontInfo(ChangeFileExt(Filename, '.dat')); + + ResetIntern(); +end; + +destructor TBitmapFont.Destroy(); +begin + glDeleteTextures(1, @fTex.TexNum); + inherited; +end; + +procedure TBitmapFont.ResetIntern(); +begin + fLineSpacing := Height; +end; + +procedure TBitmapFont.Reset(); +begin + inherited; + ResetIntern(); +end; + +procedure TBitmapFont.CorrectWidths(WidthMult: real; WidthAdd: integer); +var + Count: integer; +begin + for Count := 0 to 255 do + fWidths[Count] := Round(fWidths[Count] * WidthMult) + WidthAdd; +end; + +procedure TBitmapFont.LoadFontInfo(const InfoFile: string); +var + Stream: TFileStream; +begin + FillChar(fWidths[0], Length(fWidths), 0); + + Stream := nil; + try + Stream := TFileStream.Create(InfoFile, fmOpenRead); + Stream.Read(fWidths, 256); + except + raise Exception.Create('Could not read font info file ''' + InfoFile + ''''); + end; + Stream.Free; +end; + +function TBitmapFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; +var + LineIndex, CharIndex: integer; + CharCode: cardinal; + Line: WideString; + LineWidth: double; +begin + Result.Left := 0; + Result.Right := 0; + Result.Top := Height; + Result.Bottom := 0; + + for LineIndex := 0 to High(Text) do + begin + Line := Text[LineIndex]; + LineWidth := 0; + for CharIndex := 1 to Length(Line) do + begin + CharCode := Ord(Line[CharIndex]); + if (CharCode < Length(fWidths)) then + LineWidth := LineWidth + fWidths[CharCode]; + end; + if (LineWidth > Result.Right) then + Result.Right := LineWidth; + end; +end; + +procedure TBitmapFont.RenderChar(ch: WideChar; var AdvanceX: real); +var + TexX, TexY: real; + TexR, TexB: real; + GlyphWidth: real; + PL, PT: real; + PR, PB: real; + CharCode: cardinal; +begin + CharCode := Ord(ch); + if (CharCode > High(fWidths)) then + CharCode := 0; + + GlyphWidth := fWidths[CharCode]; + + // set texture positions + TexX := (CharCode mod 16) * 1/16 + 1/32 - (GlyphWidth/2 - fOutline)/fTexSize; + TexY := (CharCode div 16) * 1/16 + {2 texels} 2/fTexSize; + TexR := (CharCode mod 16) * 1/16 + 1/32 + (GlyphWidth/2 + fOutline)/fTexSize; + TexB := (1 + CharCode div 16) * 1/16 - {2 texels} 2/fTexSize; + + // set vector positions + PL := AdvanceX - fOutline; + PR := PL + GlyphWidth + fOutline*2; + PB := -fBaseline; + PT := PB + fTexSize div 16; + + (* + if (Font.Blend) then + begin + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + end; + *) + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, fTex.TexNum); + + if (not ReflectionPass) then + begin + glBegin(GL_QUADS); + glTexCoord2f(TexX, TexY); glVertex2f(PL, PT); + glTexCoord2f(TexX, TexB); glVertex2f(PL, PB); + glTexCoord2f(TexR, TexB); glVertex2f(PR, PB); + glTexCoord2f(TexR, TexY); glVertex2f(PR, PT); + glEnd; + end + else + begin + glDepthRange(0, 10); + glDepthFunc(GL_LEQUAL); + glEnable(GL_DEPTH_TEST); + + glBegin(GL_QUADS); + glTexCoord2f(TexX, TexY); glVertex2f(PL, PT); + glTexCoord2f(TexX, TexB); glVertex2f(PL, PB); + glTexCoord2f(TexR, TexB); glVertex2f(PR, PB); + glTexCoord2f(TexR, TexY); glVertex2f(PR, PT); + glEnd; + + glBegin(GL_QUADS); + glTexCoord2f(TexX, TexY); glVertex2f(PL, PT); + glTexCoord2f(TexX, TexB); glVertex2f(PL, PB); + glTexCoord2f(TexR, TexB); glVertex2f(PR, PB); + glTexCoord2f(TexR, TexY); glVertex2f(PR, PT); + +(* + glColor4f(fTempColor.r, fTempColor.g, fTempColor.b, 0.7); + glTexCoord2f(TexX, TexB); glVertex3f(PL, PB, 0); + glTexCoord2f(TexR, TexB); glVertex3f(PR, PB, 0); + + glColor4f(fTempColor.r, fTempColor.g, fTempColor.b, 0); + glTexCoord2f(TexR, (TexY + TexB)/2); glVertex3f(PR, (PT + PB)/2, 0); + glTexCoord2f(TexX, (TexY + TexB)/2); glVertex3f(PL, (PT + PB)/2, 0); +*) + glEnd; + + //write the colour back + glColor4fv(@fTempColor); + + glDisable(GL_DEPTH_TEST); + end; // reflection + + glDisable(GL_TEXTURE_2D); + (* + if (Font.Blend) then + glDisable(GL_BLEND); + *) + + AdvanceX := AdvanceX + GlyphWidth; +end; + +procedure TBitmapFont.Render(const Text: WideString); +var + CharIndex: integer; + AdvanceX: real; +begin + // if there is no text do nothing + if (Text = '') then + Exit; + + //Save the current color and alpha (for reflection) + glGetFloatv(GL_CURRENT_COLOR, @fTempColor); + + AdvanceX := 0; + for CharIndex := 1 to Length(Text) do + begin + RenderChar(Text[CharIndex], AdvanceX); + end; +end; + +function TBitmapFont.GetHeight(): single; +begin + Result := fAscender - fDescender; +end; + +function TBitmapFont.GetAscender(): single; +begin + Result := fAscender; +end; + +function TBitmapFont.GetDescender(): single; +begin + Result := fDescender; +end; + +function TBitmapFont.GetUnderlinePosition(): single; +begin + Result := -2.0; +end; + +function TBitmapFont.GetUnderlineThickness(): single; +begin + Result := 1.0; +end; + +{$ENDIF BITMAP_FONT} + + +initialization + +finalization + TFreeType.FreeLibrary(); + +end. diff --git a/src/lib/freetype/demo/lesson43.bdsproj b/src/lib/freetype/demo/lesson43.bdsproj new file mode 100644 index 00000000..30f88ab3 --- /dev/null +++ b/src/lib/freetype/demo/lesson43.bdsproj @@ -0,0 +1,175 @@ + + + + + + + + + + + + lesson43.dpr + + + 7.0 + + + 8 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 1 + 1 + 1 + True + True + WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; + + False + + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + True + False + False + False + True + True + True + True + True + True + + + + 0 + 0 + False + 1 + False + False + False + 16384 + 1048576 + 4194304 + + + + + + + + ..\..\JEDI-SDL\SDL\Pas + vclx;vcl;rtl;vclactnband + + + False + + + + + + False + + + True + False + + + + $00000000 + + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 1031 + 1252 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + diff --git a/src/lib/freetype/demo/lesson43.dpr b/src/lib/freetype/demo/lesson43.dpr new file mode 100644 index 00000000..8a470a2e --- /dev/null +++ b/src/lib/freetype/demo/lesson43.dpr @@ -0,0 +1,366 @@ +program lesson43; +(* + * This code was created by Jeff Molofee '99 + * (ported to Linux/SDL by Ti Leggett '01) + * + * If you've found this code useful, please let me know. + * + * Visit Jeff at http://nehe.gamedev.net/ + * + * or for port-specific comments, questions, bugreports etc. + * email to leggett@eecs.tulane.edu + *) + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +{$APPTYPE Console} + +{.$DEFINE FONT2} + +uses + moduleloader in '../../JEDI-SDL/SDL/Pas/moduleloader.pas', + SDL in '../../JEDI-SDL/SDL/Pas/sdl.pas', + gl in '../../JEDI-SDL/OpenGL/Pas/gl.pas', + glext in '../../JEDI-SDL/OpenGL/Pas/glext.pas', + glu in '../../JEDI-SDL/OpenGL/Pas/glu.pas', + ctypes in '../../ctypes/ctypes.pas', + FreeType in '../freetype.pas', + {$IFNDEF FONT2} + UFont in 'UFont.pas', + {$ELSE} + UFont2 in 'UFont2.pas', + {$ENDIF} + math, + sysutils; + +const + // screen width, height, and bit depth + SCREEN_WIDTH = 640; + SCREEN_HEIGHT = 480; + SCREEN_BPP = 16; + + //FONT_FILE = 'Test.ttf'; + //FONT_FILE = 'C:/Windows/Fonts/Arial.ttf'; + //FONT_FILE = 'C:/Windows/Fonts/SimSun.ttf'; + //FONT_FILE = 'C:/Windows/Fonts/SimSun.ttf'; + FONT_FILE = 'eurostarregularextended.ttf'; + +var + OurFont: TScalableFont; + // This is our SDL surface + surface: PSDL_Surface; + cnt1, cnt2: GLfloat; + +(* function to release/destroy our resources and restoring the old desktop *) +procedure Quit(returnCode: integer); +begin + OurFont.Free; + + // clean up the window + SDL_Quit( ); + + // and exit appropriately + Halt( returnCode ); +end; + +(* function to reset our viewport after a window resize *) +function resizeWindow(width: integer; height: integer): boolean; +begin + // Protect against a divide by zero + if ( height = 0 ) then + height := 1; + + // Setup our viewport. + glViewport( 0, 0, GLsizei(width), GLsizei(height) ); + + // change to the projection matrix and set our viewing volume. + glMatrixMode( GL_PROJECTION ); + glLoadIdentity( ); + + // Set our perspective + //gluOrtho2D(0, width, 0, height); + gluOrtho2D(0, 800, 0, 600); + + // Make sure we're chaning the model view and not the projection + glMatrixMode( GL_MODELVIEW ); + + // Reset The View + glLoadIdentity( ); + + Result := true; +end; + +(* function to handle key press events *) +procedure handleKeyPress(keysym: PSDL_keysym); +begin + case ( keysym^.sym ) of + SDLK_ESCAPE: + begin + // ESC key was pressed + Quit( 0 ); + end; + SDLK_F1: + begin + // F1 key was pressed + // this toggles fullscreen mode + SDL_WM_ToggleFullScreen( surface ); + end; + end; +end; + +(* general OpenGL initialization function *) +function initGL(): boolean; +begin + // Enable smooth shading + glShadeModel( GL_SMOOTH ); + + // Set the background black + //glClearColor( 1, 1, 1.0, 1.0 ); + //glClearColor( 0.3, 0.7, 1.0, 1.0 ); + glClearColor( 0.0, 0.0, 0.0, 1.0 ); + + // Depth buffer setup + glClearDepth( 1.0 ); + + // Enables Depth Testing + glEnable( GL_DEPTH_TEST ); + + // The Type Of Depth Test To Do + glDepthFunc( GL_LEQUAL ); + + // Really Nice Perspective Calculations + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + + //OurFont := TFTScalableFont.Create(FONT_FILE, 64); + //OurFont := TFTFont.Create(FONT_FILE, 128); + OurFont := TFTScalableOutlineFont.Create(FONT_FILE, 64, 0.05); + //OurFont.UseKerning := false; + TFTScalableOutlineFont(OurFont).SetOutlineColor(1, 0, 0); + //OurFont := TOutlineFont.Create(FONT_FILE, 32, 2); + //OurFont.LineSpacing := OurFont.LineSpacing * 0.5; + + Result := true; +end; + +var + NextTime: cardinal; + Counter: integer; + +type + TVector4d = array[0..3] of GLdouble; + +function NewVector4d(a, b, c, d: GLdouble): TVector4d; +begin + Result[0] := a; + Result[1] := b; + Result[2] := c; + Result[3] := d; +end; + +(* Here goes our drawing code *) +function drawGLScene(): boolean; +var + msg: WideString; + bounds: TBoundsDbl; + ClipPlaneEq: TVector4d; +begin + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + + //msg := 'Here'#13'there'#13'be'#13#13'newlines'#13'.'; + //msg := 'Here'#13'newlines'; + msg := 'Hallo Du';//Active FreeType Text - ' + FloatToStr(cnt1); + //msg := 'Hören'#13'其自诞生至今'#13'спецификация'; + + // Red text + glLoadIdentity(); + glTranslatef(cnt2, 240, 0); + if (cnt2 > 800) then + cnt2 := 0; + glTranslatef(30, 40, 0); + //glTranslatef(320, 240, 0); + //glRotatef(cnt1, 0, 0, 1); + //glScalef(1, 0.8 + 0.3*cos(cnt1/5), 1); + + OurFont.Style := [Italic, Underline, Reflect]; + //OurFont.GlyphSpacing := 10; + //OurFont.SetOutlineColor(0.5, 0.5, 0.5); + //OurFont.ReflectionSpacing := -4; + //OurFont.UseKerning := false; + OurFont.Height := 32;//cnt2; + //OurFont.Reset; + //OurFont.Aspect := 2; + + { + glColor3f(1, 1, 0); + bounds := OurFont.BBox(msg); + glRectf(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); + } + + { + glEnable(GL_CLIP_PLANE0); + ClipPlaneEq := NewVector4d(-1, 0, 0, bounds.Right/5); + glClipPlane(GL_CLIP_PLANE0, @ClipPlaneEq); + } + //glColor3f(1, 0, 0); + glColor3f(1, 1, 1); + //OurFont.ReflectionSpacing := 0; + OurFont.Print(msg); + + glTranslatef(0, 50, 0); + glColor3f(1, 1, 0); + bounds := OurFont.BBox('Hallo '); + glRectf(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); + OurFont.Print('Hallo '); + + { + ClipPlaneEq := NewVector4d(1, 0, 0, -bounds.Right/5); + glClipPlane(GL_CLIP_PLANE0, @ClipPlaneEq); + glColor3f(0, 0, 1); + OurFont.Print(msg); + glDisable(GL_CLIP_PLANE0); + //glColor3f(0, 1, 0); + //OurFont.Style := OurFont.Style - [Italic]; + //OurFont.Print(msg); + } + + cnt1 := cnt1 + 0.051; // Increase The First Counter + cnt2 := cnt2 + 0.005; // Increase The First Counter + + SDL_GL_SwapBuffers( ); + + Inc(Counter); + + if (NextTime < SDL_GetTicks()) then + begin + NextTime := SDL_GetTicks() + 2000; + writeln('FPS: ' + floattostr(Counter / 2.0)); + Counter := 0; + end; + + Result := true; +end; + +var + // Flags to pass to SDL_SetVideoMode + videoFlags: integer; + // main loop variable + done: boolean = false; + // used to collect events + event: TSDL_Event; + // this holds some info about our display + videoInfo: PSDL_VideoInfo; + // whether or not the window is active + isActive: boolean = true; + +begin + // initialize SDL + if ( SDL_Init( SDL_INIT_VIDEO or SDL_INIT_TIMER ) < 0 ) then + begin + writeln( ErrOutput, 'Video initialization failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // Fetch the video info + videoInfo := SDL_GetVideoInfo( ); + + if ( videoInfo = nil ) then + begin + writeln( ErrOutput, 'Video query failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Enable double buffering + + // the flags to pass to SDL_SetVideoMode + videoFlags := SDL_OPENGL; // Enable OpenGL in SDL + videoFlags := videoFlags or SDL_HWPALETTE; // Store the palette in hardware + videoFlags := videoFlags or SDL_RESIZABLE; // Enable window resizing + + // This checks to see if surfaces can be stored in memory + if ( videoInfo^.hw_available <> 0 ) then + videoFlags := videoFlags or SDL_HWSURFACE + else + videoFlags := videoFlags or SDL_SWSURFACE; + + // This checks if hardware blits can be done + if ( videoInfo^.blit_hw <> 0 ) then + videoFlags := videoFlags or SDL_HWACCEL; + + // Sets up OpenGL double buffering + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + // get a SDL surface + surface := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, + videoFlags ); + + // Verify there is a surface + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Video mode set failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // initialize OpenGL + initGL(); + + // resize the initial window + resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); + + // wait for events + while ( not done ) do + begin + { handle the events in the queue } + + while ( SDL_PollEvent( @event ) <> 0 ) do + begin + case( event.type_ ) of + SDL_ACTIVEEVENT: + begin + // Something's happend with our focus + // If we are iconified, we shouldn't draw the screen + if ( (event.active.state and SDL_APPACTIVE) <> 0 ) then + begin + if ( event.active.gain = 0 ) then + isActive := false + else + isActive := true; + end; + end; + SDL_VIDEORESIZE: + begin + // handle resize event + {$IFDEF UNIX} + surface := SDL_SetVideoMode( event.resize.w, + event.resize.h, + 16, videoFlags ); + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Could not get a surface after resize: ' + SDL_GetError( ) ); + Quit( 1 ); + end; + {$ENDIF} + resizeWindow( event.resize.w, event.resize.h ); + end; + SDL_KEYDOWN: + begin + // handle key presses + handleKeyPress( @event.key.keysym ); + end; + SDL_QUITEV: + begin + // handle quit requests + done := true; + end; + end; + end; + + // draw the scene + if ( isActive ) then + drawGLScene( ); + end; + + // clean ourselves up and exit + Quit( 0 ); +end. diff --git a/src/lib/freetype/demo/lesson43.lpi b/src/lib/freetype/demo/lesson43.lpi new file mode 100644 index 00000000..b6791f18 --- /dev/null +++ b/src/lib/freetype/demo/lesson43.lpi @@ -0,0 +1,272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/lib/freetype/freetype.pas b/src/lib/freetype/freetype.pas new file mode 100644 index 00000000..65cce749 --- /dev/null +++ b/src/lib/freetype/freetype.pas @@ -0,0 +1,2503 @@ +//---------------------------------------------------------------------------- +// FreeType2 pascal header +//---------------------------------------------------------------------------- +// Anti-Grain Geometry - Version 2.4 (Public License) +// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) +// +// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) +// Pascal Port By: Milan Marusinec alias Milano +// milan@marusinec.sk +// http://www.aggpas.org +// Copyright (c) 2005-2007 +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +//---------------------------------------------------------------------------- +// Adapted by the UltraStar Deluxe Team +//---------------------------------------------------------------------------- + +unit freetype; + +interface + +{$IFDEF FPC} + {$MODE DELPHI } + {$PACKENUM 4} (* use 4-byte enums *) + {$PACKRECORDS C} (* C/C++-compatible record packing *) +{$ELSE} + {$MINENUMSIZE 4} (* use 4-byte enums *) +{$ENDIF} + +uses + ctypes; + +const +{$IF Defined(MSWINDOWS)} + ft_lib = 'libfreetype-6.dll'; +{$ELSEIF Defined(DARWIN)} + ft_lib = 'libfreetype.dylib'; + {$LINKLIB libftgl} +{$ELSEIF Defined(UNIX)} + ft_lib = 'freetype.so'; +{$IFEND} + +type + FT_Byte = cuchar; + FT_Short = csshort; + FT_UShort = cushort; + FT_Int = csint; + FT_UInt = cuint; + FT_Int16 = cint16; + FT_UInt16 = cuint16; + FT_Int32 = cint32; + FT_UInt32 = cuint32; + FT_Long = cslong; + FT_ULong = culong; + + FT_Fixed = cslong; + FT_Pos = cslong; + FT_Error = cint; + FT_F26Dot6 = cslong; + FT_String = cchar; + FT_Bool = cuchar; + + PFT_Byte = ^FT_Byte; + PFT_Short = ^FT_Short; + PFT_String = ^FT_String; + + (*************************************************************************) + (* *) + (* *) + (* FT_FACE_FLAG_XXX *) + (* *) + (* *) + (* A list of bit flags used in the `face_flags' field of the *) + (* @FT_FaceRec structure. They inform client applications of *) + (* properties of the corresponding face. *) + (* *) + (* *) + (* FT_FACE_FLAG_SCALABLE :: *) + (* Indicates that the face provides vectorial outlines. This *) + (* doesn't prevent embedded bitmaps, i.e., a face can have both *) + (* this bit and @FT_FACE_FLAG_FIXED_SIZES set. *) + (* *) + (* FT_FACE_FLAG_FIXED_SIZES :: *) + (* Indicates that the face contains `fixed sizes', i.e., bitmap *) + (* strikes for some given pixel sizes. See the `num_fixed_sizes' *) + (* and `available_sizes' fields of @FT_FaceRec. *) + (* *) + (* FT_FACE_FLAG_FIXED_WIDTH :: *) + (* Indicates that the face contains fixed-width characters (like *) + (* Courier, Lucido, MonoType, etc.). *) + (* *) + (* FT_FACE_FLAG_SFNT :: *) + (* Indicates that the face uses the `sfnt' storage scheme. For *) + (* now, this means TrueType and OpenType. *) + (* *) + (* FT_FACE_FLAG_HORIZONTAL :: *) + (* Indicates that the face contains horizontal glyph metrics. This *) + (* should be set for all common formats. *) + (* *) + (* FT_FACE_FLAG_VERTICAL :: *) + (* Indicates that the face contains vertical glyph metrics. This *) + (* is only available in some formats, not all of them. *) + (* *) + (* FT_FACE_FLAG_KERNING :: *) + (* Indicates that the face contains kerning information. If set, *) + (* the kerning distance can be retrieved through the function *) + (* @FT_Get_Kerning. Note that if unset, this function will always *) + (* return the vector (0,0). *) + (* *) + (* FT_FACE_FLAG_FAST_GLYPHS :: *) + (* THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT. *) + (* *) + (* FT_FACE_FLAG_MULTIPLE_MASTERS :: *) + (* Indicates that the font contains multiple masters and is capable *) + (* of interpolating between them. See the multiple-masters *) + (* specific API for details. *) + (* *) + (* FT_FACE_FLAG_GLYPH_NAMES :: *) + (* Indicates that the font contains glyph names that can be *) + (* retrieved through @FT_Get_Glyph_Name. Note that some TrueType *) + (* fonts contain broken glyph name tables. Use the function *) + (* @FT_Has_PS_Glyph_Names when needed. *) + (* *) + (* FT_FACE_FLAG_EXTERNAL_STREAM :: *) + (* Used internally by FreeType to indicate that a face's stream was *) + (* provided by the client application and should not be destroyed *) + (* when @FT_Done_Face is called. Don't read or test this flag. *) + (* *) +const + FT_FACE_FLAG_SCALABLE = 1 shl 0; + FT_FACE_FLAG_KERNING = 1 shl 6; + + (*************************************************************************) + (* *) + (* *) + (* FT_Encoding *) + (* *) + (* *) + (* An enumeration used to specify encodings supported by charmaps. *) + (* Used in the @FT_Select_Charmap API function. *) + (* *) + (* *) + (* Because of 32-bit charcodes defined in Unicode (i.e., surrogates), *) + (* all character codes must be expressed as FT_Longs. *) + (* *) + (* The values of this type correspond to specific character *) + (* repertories (i.e. charsets), and not to text encoding methods *) + (* (like UTF-8, UTF-16, GB2312_EUC, etc.). *) + (* *) + (* Other encodings might be defined in the future. *) + (* *) + (* *) + (* FT_ENCODING_NONE :: *) + (* The encoding value 0 is reserved. *) + (* *) + (* FT_ENCODING_UNICODE :: *) + (* Corresponds to the Unicode character set. This value covers *) + (* all versions of the Unicode repertoire, including ASCII and *) + (* Latin-1. Most fonts include a Unicode charmap, but not all *) + (* of them. *) + (* *) + (* FT_ENCODING_MS_SYMBOL :: *) + (* Corresponds to the Microsoft Symbol encoding, used to encode *) + (* mathematical symbols in the 32..255 character code range. For *) + (* more information, see `http://www.ceviz.net/symbol.htm'. *) + (* *) + (* FT_ENCODING_SJIS :: *) + (* Corresponds to Japanese SJIS encoding. More info at *) + (* at `http://langsupport.japanreference.com/encoding.shtml'. *) + (* See note on multi-byte encodings below. *) + (* *) + (* FT_ENCODING_GB2312 :: *) + (* Corresponds to an encoding system for Simplified Chinese as used *) + (* used in mainland China. *) + (* *) + (* FT_ENCODING_BIG5 :: *) + (* Corresponds to an encoding system for Traditional Chinese as used *) + (* in Taiwan and Hong Kong. *) + (* *) + (* FT_ENCODING_WANSUNG :: *) + (* Corresponds to the Korean encoding system known as Wansung. *) + (* For more information see *) + (* `http://www.microsoft.com/typography/unicode/949.txt'. *) + (* *) + (* FT_ENCODING_JOHAB :: *) + (* The Korean standard character set (KS C-5601-1992), which *) + (* corresponds to MS Windows code page 1361. This character set *) + (* includes all possible Hangeul character combinations. *) + (* *) + (* FT_ENCODING_ADOBE_LATIN_1 :: *) + (* Corresponds to a Latin-1 encoding as defined in a Type 1 *) + (* Postscript font. It is limited to 256 character codes. *) + (* *) + (* FT_ENCODING_ADOBE_STANDARD :: *) + (* Corresponds to the Adobe Standard encoding, as found in Type 1, *) + (* CFF, and OpenType/CFF fonts. It is limited to 256 character *) + (* codes. *) + (* *) + (* FT_ENCODING_ADOBE_EXPERT :: *) + (* Corresponds to the Adobe Expert encoding, as found in Type 1, *) + (* CFF, and OpenType/CFF fonts. It is limited to 256 character *) + (* codes. *) + (* *) + (* FT_ENCODING_ADOBE_CUSTOM :: *) + (* Corresponds to a custom encoding, as found in Type 1, CFF, and *) + (* OpenType/CFF fonts. It is limited to 256 character codes. *) + (* *) + (* FT_ENCODING_APPLE_ROMAN :: *) + (* Corresponds to the 8-bit Apple roman encoding. Many TrueType and *) + (* OpenType fonts contain a charmap for this encoding, since older *) + (* versions of Mac OS are able to use it. *) + (* *) + (* FT_ENCODING_OLD_LATIN_2 :: *) + (* This value is deprecated and was never used nor reported by *) + (* FreeType. Don't use or test for it. *) + (* *) + (* FT_ENCODING_MS_SJIS :: *) + (* Same as FT_ENCODING_SJIS. Deprecated. *) + (* *) + (* FT_ENCODING_MS_GB2312 :: *) + (* Same as FT_ENCODING_GB2312. Deprecated. *) + (* *) + (* FT_ENCODING_MS_BIG5 :: *) + (* Same as FT_ENCODING_BIG5. Deprecated. *) + (* *) + (* FT_ENCODING_MS_WANSUNG :: *) + (* Same as FT_ENCODING_WANSUNG. Deprecated. *) + (* *) + (* FT_ENCODING_MS_JOHAB :: *) + (* Same as FT_ENCODING_JOHAB. Deprecated. *) + (* *) + (* *) + (* By default, FreeType automatically synthetizes a Unicode charmap *) + (* for Postscript fonts, using their glyph names dictionaries. *) + (* However, it will also report the encodings defined explicitly in *) + (* the font file, for the cases when they are needed, with the Adobe *) + (* values as well. *) + (* *) + (* FT_ENCODING_NONE is set by the BDF and PCF drivers if the charmap *) + (* is neither Unicode nor ISO-8859-1 (otherwise it is set to *) + (* FT_ENCODING_UNICODE). Use `FT_Get_BDF_Charset_ID' to find out *) + (* which encoding is really present. If, for example, the *) + (* `cs_registry' field is `KOI8' and the `cs_encoding' field is `R', *) + (* the font is encoded in KOI8-R. *) + (* *) + (* FT_ENCODING_NONE is always set (with a single exception) by the *) + (* winfonts driver. Use `FT_Get_WinFNT_Header' and examine the *) + (* `charset' field of the `FT_WinFNT_HeaderRec' structure to find out *) + (* which encoding is really present. For example, FT_WinFNT_ID_CP1251 *) + (* (204) means Windows code page 1251 (for Russian). *) + (* *) + (* FT_ENCODING_NONE is set if `platform_id' is `TT_PLATFORM_MACINTOSH' *) + (* and `encoding_id' is not `TT_MAC_ID_ROMAN' (otherwise it is set to *) + (* FT_ENCODING_APPLE_ROMAN). *) + (* *) + (* If `platform_id' is `TT_PLATFORM_MACINTOSH', use the function *) + (* `FT_Get_CMap_Language_ID' to query the Mac language ID which may be *) + (* needed to be able to distinguish Apple encoding variants. See *) + (* *) + (* http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/README.TXT *) + (* *) + (* to get an idea how to do that. Basically, if the language ID is 0, *) + (* dont use it, otherwise subtract 1 from the language ID. Then *) + (* examine `encoding_id'. If, for example, `encoding_id' is *) + (* `TT_MAC_ID_ROMAN' and the language ID (minus 1) is *) + (* `TT_MAC_LANGID_GREEK', it is the Greek encoding, not Roman. *) + (* `TT_MAC_ID_ARABIC' with `TT_MAC_LANGID_FARSI' means the Farsi *) + (* variant the Arabic encoding. *) + (* *) +type + PFT_Encoding = ^FT_Encoding; + FT_Encoding = array[0..3] of char; +const + FT_ENCODING_NONE: FT_Encoding = (#0 ,#0 ,#0 ,#0 ); + FT_ENCODING_MS_SYMBOL: FT_Encoding = ('s', 'y', 'm', 'b' ); + FT_ENCODING_UNICODE: FT_Encoding = ('u', 'n', 'i', 'c' ); + + FT_ENCODING_SJIS: FT_Encoding = ('s', 'j', 'i', 's'); + FT_ENCODING_GB2312: FT_Encoding = ('g', 'b', ' ', ' '); + FT_ENCODING_BIG5: FT_Encoding = ('b', 'i', 'g', '5'); + FT_ENCODING_WANSUNG: FT_Encoding = ('w', 'a', 'n', 's'); + FT_ENCODING_JOHAB: FT_Encoding = ('j', 'o', 'h', 'a'); + + (*************************************************************************) + (* *) + (* *) + (* FT_Glyph_Format *) + (* *) + (* *) + (* An enumeration type used to describe the format of a given glyph *) + (* image. Note that this version of FreeType only supports two image *) + (* formats, even though future font drivers will be able to register *) + (* their own format. *) + (* *) + (* *) + (* FT_GLYPH_FORMAT_NONE :: *) + (* The value 0 is reserved and does describe a glyph format. *) + (* *) + (* FT_GLYPH_FORMAT_COMPOSITE :: *) + (* The glyph image is a composite of several other images. This *) + (* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to *) + (* report compound glyphs (like accented characters). *) + (* *) + (* FT_GLYPH_FORMAT_BITMAP :: *) + (* The glyph image is a bitmap, and can be described as an *) + (* @FT_Bitmap. You generally need to access the `bitmap' field of *) + (* the @FT_GlyphSlotRec structure to read it. *) + (* *) + (* FT_GLYPH_FORMAT_OUTLINE :: *) + (* The glyph image is a vertorial outline made of line segments *) + (* and Bezier arcs; it can be described as an @FT_Outline; you *) + (* generally want to access the `outline' field of the *) + (* @FT_GlyphSlotRec structure to read it. *) + (* *) + (* FT_GLYPH_FORMAT_PLOTTER :: *) + (* The glyph image is a vectorial path with no inside/outside *) + (* contours. Some Type 1 fonts, like those in the Hershey family, *) + (* contain glyphs in this format. These are described as *) + (* @FT_Outline, but FreeType isn't currently capable of rendering *) + (* them correctly. *) + (* *) +type + FT_Glyph_Format = array[0..3] of char; +const + FT_GLYPH_FORMAT_NONE: FT_Glyph_Format = (#0, #0, #0, #0 ); + + FT_GLYPH_FORMAT_COMPOSITE: FT_Glyph_Format = ('c', 'o', 'm', 'p' ); + FT_GLYPH_FORMAT_BITMAP: FT_Glyph_Format = ('b', 'i', 't', 's' ); + FT_GLYPH_FORMAT_OUTLINE: FT_Glyph_Format = ('o', 'u', 't', 'l' ); + FT_GLYPH_FORMAT_PLOTTER: FT_Glyph_Format = ('p', 'l', 'o', 't' ); + + + (*************************************************************************) + (* *) + (* *) + (* FT_STYLE_FLAG_XXX *) + (* *) + (* *) + (* A list of bit-flags used to indicate the style of a given face. *) + (* These are used in the `style_flags' field of @FT_FaceRec. *) + (* *) + (* *) + (* FT_STYLE_FLAG_ITALIC :: *) + (* Indicates that a given face is italicized. *) + (* *) + (* FT_STYLE_FLAG_BOLD :: *) + (* Indicates that a given face is bold. *) + (* *) +const + FT_STYLE_FLAG_ITALIC = 1 shl 0; + FT_STYLE_FLAG_BOLD = 1 shl 1; + + + (*************************************************************************** + * + * @enum: + * FT_LOAD_XXX + * + * @description: + * A list of bit-field constants, used with @FT_Load_Glyph to indicate + * what kind of operations to perform during glyph loading. + * + * @values: + * FT_LOAD_DEFAULT :: + * Corresponding to 0, this value is used a default glyph load. In this + * case, the following will happen: + * + * 1. FreeType looks for a bitmap for the glyph corresponding to the + * face's current size. If one is found, the function returns. The + * bitmap data can be accessed from the glyph slot (see note below). + * + * 2. If no embedded bitmap is searched or found, FreeType looks for a + * scalable outline. If one is found, it is loaded from the font + * file, scaled to device pixels, then "hinted" to the pixel grid in + * order to optimize it. The outline data can be accessed from the + * glyph slot (see note below). + * + * Note that by default, the glyph loader doesn't render outlines into + * bitmaps. The following flags are used to modify this default + * behaviour to more specific and useful cases. + * + * FT_LOAD_NO_SCALE :: + * Don't scale the vector outline being loaded to 26.6 fractional + * pixels, but kept in font units. Note that this also disables + * hinting and the loading of embedded bitmaps. You should only use it + * when you want to retrieve the original glyph outlines in font units. + * + * FT_LOAD_NO_HINTING :: + * Don't hint glyph outlines after their scaling to device pixels. + * This generally generates "blurrier" glyphs in anti-aliased modes. + * + * This flag is ignored if @FT_LOAD_NO_SCALE is set. + * + * FT_LOAD_RENDER :: + * Render the glyph outline immediately into a bitmap before the glyph + * loader returns. By default, the glyph is rendered for the + * @FT_RENDER_MODE_NORMAL mode, which corresponds to 8-bit anti-aliased + * bitmaps using 256 opacity levels. You can use either + * @FT_LOAD_TARGET_MONO or @FT_LOAD_MONOCHROME to render 1-bit + * monochrome bitmaps. + * + * This flag is ignored if @FT_LOAD_NO_SCALE is set. + * + * FT_LOAD_NO_BITMAP :: + * Don't look for bitmaps when loading the glyph. Only scalable + * outlines will be loaded when available, and scaled, hinted, or + * rendered depending on other bit flags. + * + * This does not prevent you from rendering outlines to bitmaps + * with @FT_LOAD_RENDER, however. + * + * FT_LOAD_VERTICAL_LAYOUT :: + * Prepare the glyph image for vertical text layout. This basically + * means that `face.glyph.advance' will correspond to the vertical + * advance height (instead of the default horizontal advance width), + * and that the glyph image will be translated to match the vertical + * bearings positions. + * + * FT_LOAD_FORCE_AUTOHINT :: + * Force the use of the FreeType auto-hinter when a glyph outline is + * loaded. You shouldn't need this in a typical application, since it + * is mostly used to experiment with its algorithm. + * + * FT_LOAD_CROP_BITMAP :: + * Indicates that the glyph loader should try to crop the bitmap (i.e., + * remove all space around its black bits) when loading it. This is + * only useful when loading embedded bitmaps in certain fonts, since + * bitmaps rendered with @FT_LOAD_RENDER are always cropped by default. + * + * FT_LOAD_PEDANTIC :: + * Indicates that the glyph loader should perform pedantic + * verifications during glyph loading, rejecting invalid fonts. This + * is mostly used to detect broken glyphs in fonts. By default, + * FreeType tries to handle broken fonts also. + * + * FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH :: + * Indicates that the glyph loader should ignore the global advance + * width defined in the font. As far as we know, this is only used by + * the X-TrueType font server, in order to deal correctly with the + * incorrect metrics contained in DynaLab's TrueType CJK fonts. + * + * FT_LOAD_NO_RECURSE :: + * This flag is only used internally. It merely indicates that the + * glyph loader should not load composite glyphs recursively. Instead, + * it should set the `num_subglyph' and `subglyphs' values of the glyph + * slot accordingly, and set "glyph->format" to + * @FT_GLYPH_FORMAT_COMPOSITE. + * + * The description of sub-glyphs is not available to client + * applications for now. + * + * FT_LOAD_IGNORE_TRANSFORM :: + * Indicates that the glyph loader should not try to transform the + * loaded glyph image. This doesn't prevent scaling, hinting, or + * rendering. + * + * FT_LOAD_MONOCHROME :: + * This flag is used with @FT_LOAD_RENDER to indicate that you want + * to render a 1-bit monochrome glyph bitmap from a vectorial outline. + * + * Note that this has no effect on the hinting algorithm used by the + * glyph loader. You should better use @FT_LOAD_TARGET_MONO if you + * want to render monochrome-optimized glyph images instead. + * + * FT_LOAD_LINEAR_DESIGN :: + * Return the linearly scaled metrics expressed in original font units + * instead of the default 16.16 pixel values. + * + * FT_LOAD_NO_AUTOHINT :: + * Indicates that the auto-hinter should never be used to hint glyph + * outlines. This doesn't prevent native format-specific hinters from + * being used. This can be important for certain fonts where unhinted + * output is better than auto-hinted one. + * + * FT_LOAD_TARGET_NORMAL :: + * Use hinting for @FT_RENDER_MODE_NORMAL. + * + * FT_LOAD_TARGET_LIGHT :: + * Use hinting for @FT_RENDER_MODE_LIGHT. + * + * FT_LOAD_TARGET_MONO :: + * Use hinting for @FT_RENDER_MODE_MONO. + * + * FT_LOAD_TARGET_LCD :: + * Use hinting for @FT_RENDER_MODE_LCD. + * + * FT_LOAD_TARGET_LCD_V :: + * Use hinting for @FT_RENDER_MODE_LCD_V. + *) +const + 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; + + (* temporary hack! *) + FT_LOAD_SBITS_ONLY = $4000; + FT_LOAD_NO_AUTOHINT = $8000; + + (*************************************************************************) + (* *) + (* *) + (* FT_Render_Mode *) + (* *) + (* *) + (* An enumeration type that lists the render modes supported by *) + (* FreeType 2. Each mode corresponds to a specific type of scanline *) + (* conversion performed on the outline, as well as specific *) + (* hinting optimizations. *) + (* *) + (* For bitmap fonts the `bitmap->pixel_mode' field in the *) + (* @FT_GlyphSlotRec structure gives the format of the returned *) + (* bitmap. *) + (* *) + (* *) + (* FT_RENDER_MODE_NORMAL :: *) + (* This is the default render mode; it corresponds to 8-bit *) + (* anti-aliased bitmaps, using 256 levels of opacity. *) + (* *) + (* FT_RENDER_MODE_LIGHT :: *) + (* This is similar to @FT_RENDER_MODE_NORMAL -- you have to use *) + (* @FT_LOAD_TARGET_LIGHT in calls to @FT_Load_Glyph to get any *) + (* effect since the rendering process no longer influences the *) + (* positioning of glyph outlines. *) + (* *) + (* The resulting glyph shapes are more similar to the original, *) + (* while being a bit more fuzzy (`better shapes' instead of `better *) + (* contrast', so to say. *) + (* *) + (* FT_RENDER_MODE_MONO :: *) + (* This mode corresponds to 1-bit bitmaps. *) + (* *) + (* FT_RENDER_MODE_LCD :: *) + (* This mode corresponds to horizontal RGB/BGR sub-pixel displays, *) + (* like LCD-screens. It produces 8-bit bitmaps that are 3 times *) + (* the width of the original glyph outline in pixels, and which use *) + (* the @FT_PIXEL_MODE_LCD mode. *) + (* *) + (* FT_RENDER_MODE_LCD_V :: *) + (* This mode corresponds to vertical RGB/BGR sub-pixel displays *) + (* (like PDA screens, rotated LCD displays, etc.). It produces *) + (* 8-bit bitmaps that are 3 times the height of the original *) + (* glyph outline in pixels and use the @FT_PIXEL_MODE_LCD_V mode. *) + (* *) + (* *) + (* The LCD-optimized glyph bitmaps produced by FT_Render_Glyph are *) + (* _not filtered_ to reduce color-fringes. It is up to the caller to *) + (* perform this pass. *) + (* *) +type + FT_Render_Mode = FT_Int; + + + (*************************************************************************) + (* *) + (* *) + (* FT_Glyph_Metrics *) + (* *) + (* *) + (* A structure used to model the metrics of a single glyph. The *) + (* values are expressed in 26.6 fractional pixel format; if the flag *) + (* FT_LOAD_NO_SCALE is used, values are returned in font units *) + (* instead. *) + (* *) + (* *) + (* width :: *) + (* The glyph's width. *) + (* *) + (* height :: *) + (* The glyph's height. *) + (* *) + (* horiBearingX :: *) + (* Left side bearing for horizontal layout. *) + (* *) + (* horiBearingY :: *) + (* Top side bearing for horizontal layout. *) + (* *) + (* horiAdvance :: *) + (* Advance width for horizontal layout. *) + (* *) + (* vertBearingX :: *) + (* Left side bearing for vertical layout. *) + (* *) + (* vertBearingY :: *) + (* Top side bearing for vertical layout. *) + (* *) + (* vertAdvance :: *) + (* Advance height for vertical layout. *) + (* *) + FT_Glyph_Metrics = record + width , + height : FT_Pos; + + horiBearingX , + horiBearingY , + horiAdvance : FT_Pos; + + vertBearingX , + vertBearingY , + vertAdvance : FT_Pos; + end; + + + (*************************************************************************) + (* *) + (* *) + (* FT_Bitmap_Size *) + (* *) + (* *) + (* This structure models the size of a bitmap strike (i.e., a bitmap *) + (* instance of the font for a given resolution) in a fixed-size font *) + (* face. It is used for the `available_sizes' field of the *) + (* @FT_FaceRec structure. *) + (* *) + (* *) + (* height :: The (vertical) baseline-to-baseline distance in pixels. *) + (* It makes most sense to define the height of a bitmap *) + (* font in this way. *) + (* *) + (* width :: The average width of the font (in pixels). Since the *) + (* algorithms to compute this value are different for the *) + (* various bitmap formats, it can only give an additional *) + (* hint if the `height' value isn't sufficient to select *) + (* the proper font. For monospaced fonts the average width *) + (* is the same as the maximum width. *) + (* *) + (* size :: The point size in 26.6 fractional format this font shall *) + (* represent (for a given vertical resolution). *) + (* *) + (* x_ppem :: The horizontal ppem value (in 26.6 fractional format). *) + (* *) + (* y_ppem :: The vertical ppem value (in 26.6 fractional format). *) + (* Usually, this is the `nominal' pixel height of the font. *) + (* *) + (* *) + (* The values in this structure are taken from the bitmap font. If *) + (* the font doesn't provide a parameter it is set to zero to indicate *) + (* that the information is not available. *) + (* *) + (* The following formula converts from dpi to ppem: *) + (* *) + (* ppem = size * dpi / 72 *) + (* *) + (* where `size' is in points. *) + (* *) + (* Windows FNT: *) + (* The `size' parameter is not reliable: There exist fonts (e.g., *) + (* app850.fon) which have a wrong size for some subfonts; x_ppem *) + (* and y_ppem are thus set equal to pixel width and height given in *) + (* in the Windows FNT header. *) + (* *) + (* TrueType embedded bitmaps: *) + (* `size', `width', and `height' values are not contained in the *) + (* bitmap strike itself. They are computed from the global font *) + (* parameters. *) + (* *) + PFT_Bitmap_Size = ^FT_Bitmap_Size; + FT_Bitmap_Size = record + height, + width : FT_Short; + + size: FT_Pos; + + x_ppem: FT_Pos; + y_ppem: FT_Pos; + end; + + PAFT_Bitmap_Size = ^AFT_Bitmap_Size; + AFT_Bitmap_Size = array[0..High(Word)] of FT_Bitmap_Size; + + + (*************************************************************************) + (* *) + (* *) + (* FT_Vector *) + (* *) + (* *) + (* A simple structure used to store a 2D vector; coordinates are of *) + (* the FT_Pos type. *) + (* *) + (* *) + (* x :: The horizontal coordinate. *) + (* y :: The vertical coordinate. *) + (* *) + PFT_Vector = ^FT_Vector; + FT_Vector = record + x , + y : FT_Pos; + end; + + + (*************************************************************************) + (* *) + (* *) + (* FT_Outline *) + (* *) + (* *) + (* This structure is used to describe an outline to the scan-line *) + (* converter. *) + (* *) + (* *) + (* n_contours :: The number of contours in the outline. *) + (* *) + (* n_points :: The number of points in the outline. *) + (* *) + (* points :: A pointer to an array of `n_points' FT_Vector *) + (* elements, giving the outline's point coordinates. *) + (* *) + (* tags :: A pointer to an array of `n_points' chars, giving *) + (* each outline point's type. If bit 0 is unset, the *) + (* point is `off' the curve, i.e. a Bezier control *) + (* point, while it is `on' when set. *) + (* *) + (* Bit 1 is meaningful for `off' points only. If set, *) + (* it indicates a third-order Bezier arc control point; *) + (* and a second-order control point if unset. *) + (* *) + (* contours :: An array of `n_contours' shorts, giving the end *) + (* point of each contour within the outline. For *) + (* example, the first contour is defined by the points *) + (* `0' to `contours[0]', the second one is defined by *) + (* the points `contours[0]+1' to `contours[1]', etc. *) + (* *) + (* flags :: A set of bit flags used to characterize the outline *) + (* and give hints to the scan-converter and hinter on *) + (* how to convert/grid-fit it. See FT_Outline_Flags. *) + (* *) + PFT_Outline = ^FT_Outline; + FT_Outline = record + n_contours : FT_Short; + n_points : FT_Short; + + points : PFT_Vector; + tags : PChar; + contours : PFT_Short; + + flags : FT_Int; + end; + + + (*************************************************************************) + (* *) + (* *) + (* FT_Bitmap *) + (* *) + (* *) + (* A structure used to describe a bitmap or pixmap to the raster. *) + (* Note that we now manage pixmaps of various depths through the *) + (* `pixel_mode' field. *) + (* *) + (* *) + (* rows :: The number of bitmap rows. *) + (* *) + (* width :: The number of pixels in bitmap row. *) + (* *) + (* pitch :: The pitch's absolute value is the number of bytes *) + (* taken by one bitmap row, including padding. *) + (* However, the pitch is positive when the bitmap has *) + (* a `down' flow, and negative when it has an `up' *) + (* flow. In all cases, the pitch is an offset to add *) + (* to a bitmap pointer in order to go down one row. *) + (* *) + (* buffer :: A typeless pointer to the bitmap buffer. This *) + (* value should be aligned on 32-bit boundaries in *) + (* most cases. *) + (* *) + (* num_grays :: This field is only used with *) + (* `FT_PIXEL_MODE_GRAY'; it gives the number of gray *) + (* levels used in the bitmap. *) + (* *) + (* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. *) + (* See @FT_Pixel_Mode for possible values. *) + (* *) + (* palette_mode :: This field is only used with paletted pixel modes; *) + (* it indicates how the palette is stored. *) + (* *) + (* palette :: A typeless pointer to the bitmap palette; only *) + (* used for paletted pixel modes. *) + (* *) + (* *) + (* For now, the only pixel mode supported by FreeType are mono and *) + (* grays. However, drivers might be added in the future to support *) + (* more `colorful' options. *) + (* *) + (* When using pixel modes pal2, pal4 and pal8 with a void `palette' *) + (* field, a gray pixmap with respectively 4, 16, and 256 levels of *) + (* gray is assumed. This, in order to be compatible with some *) + (* embedded bitmap formats defined in the TrueType specification. *) + (* *) + (* Note that no font was found presenting such embedded bitmaps, so *) + (* this is currently completely unhandled by the library. *) + (* *) + PFT_Bitmap = ^FT_Bitmap; + FT_Bitmap = record + rows , + width : FT_Int; + pitch : FT_Int; + buffer : PChar; + num_grays : FT_Short; + pixel_mode , + palette_mode : char; + palette : pointer; + end; + + + (*************************************************************************) + (* *) + (* *) + (* FT_Face *) + (* *) + (* *) + (* A handle to a given typographic face object. A face object models *) + (* a given typeface, in a given style. *) + (* *) + (* *) + (* Each face object also owns a single @FT_GlyphSlot object, as well *) + (* as one or more @FT_Size objects. *) + (* *) + (* Use @FT_New_Face or @FT_Open_Face to create a new face object from *) + (* a given filepathname or a custom input stream. *) + (* *) + (* Use @FT_Done_Face to destroy it (along with its slot and sizes). *) + (* *) + (* *) + (* The @FT_FaceRec details the publicly accessible fields of a given *) + (* face object. *) + (* *) + FT_Face = ^FT_FaceRec; + + (*************************************************************************) + (* *) + (* *) + (* FT_CharMap *) + (* *) + (* *) + (* A handle to a given character map. A charmap is used to translate *) + (* character codes in a given encoding into glyph indexes for its *) + (* parent's face. Some font formats may provide several charmaps per *) + (* font. *) + (* *) + (* Each face object owns zero or more charmaps, but only one of them *) + (* can be "active" and used by @FT_Get_Char_Index or @FT_Load_Char. *) + (* *) + (* The list of available charmaps in a face is available through the *) + (* "face->num_charmaps" and "face->charmaps" fields of @FT_FaceRec. *) + (* *) + (* The currently active charmap is available as "face->charmap". *) + (* You should call @FT_Set_Charmap to change it. *) + (* *) + (* *) + (* When a new face is created (either through @FT_New_Face or *) + (* @FT_Open_Face), the library looks for a Unicode charmap within *) + (* the list and automatically activates it. *) + (* *) + (* *) + (* The @FT_CharMapRec details the publicly accessible fields of a *) + (* given character map. *) + (* *) + PFT_CharMap = ^FT_CharMap; + FT_CharMap = ^FT_CharMapRec; + + PAFT_CharMap = ^FT_CharMap; + AFT_CharMap = array[0..High(Word)] of FT_CharMap; + + (*************************************************************************) + (* *) + (* *) + (* FT_Library *) + (* *) + (* *) + (* A handle to a FreeType library instance. Each `library' is *) + (* completely independent from the others; it is the `root' of a set *) + (* of objects like fonts, faces, sizes, etc. *) + (* *) + (* It also embeds a memory manager (see @FT_Memory), as well as a *) + (* scan-line converter object (see @FT_Raster). *) + (* *) + (* *) + (* Library objects are normally created by @FT_Init_FreeType, and *) + (* destroyed with @FT_Done_FreeType. *) + (* *) + FT_Library = ^FT_LibraryRec; + FT_LibraryRec = record // internal + end; + + (*************************************************************************) + (* *) + (*
*) + (* glyph_management *) + (* *) + (* *) + (* Glyph Management *) + (* *) + (* <Abstract> *) + (* Generic interface to manage individual glyph data. *) + (* *) + (* <Description> *) + (* This section contains definitions used to manage glyph data *) + (* through generic FT_Glyph objects. Each of them can contain a *) + (* bitmap, a vector outline, or even images in other formats. *) + (* *) + (*************************************************************************) + + (* forward declaration to a private type *) + PFT_Glyph_Class = ^FT_Glyph_Class; + FT_Glyph_Class = record // internal + end; + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Glyph *) + (* *) + (* <Description> *) + (* Handle to an object used to model generic glyph images. It is a *) + (* pointer to the @FT_GlyphRec structure and can contain a glyph *) + (* bitmap or pointer. *) + (* *) + (* <Note> *) + (* Glyph objects are not owned by the library. You must thus release *) + (* them manually (through @FT_Done_Glyph) _before_ calling *) + (* @FT_Done_FreeType. *) + (* *) + FT_Glyph = ^FT_GlyphRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_GlyphRec *) + (* *) + (* <Description> *) + (* The root glyph structure contains a given glyph image plus its *) + (* advance width in 16.16 fixed float format. *) + (* *) + (* <Fields> *) + (* library :: A handle to the FreeType library object. *) + (* *) + (* clazz :: A pointer to the glyph's class. Private. *) + (* *) + (* format :: The format of the glyph's image. *) + (* *) + (* advance :: A 16.16 vector that gives the glyph's advance width. *) + (* *) + FT_GlyphRec = record + library_: FT_Library; + clazz: PFT_Glyph_Class; + format: FT_Glyph_Format; + advance: FT_Vector; + end; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_BitmapGlyph *) + (* *) + (* <Description> *) + (* A handle to an object used to model a bitmap glyph image. This is *) + (* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. *) + (* *) + FT_BitmapGlyph = ^FT_BitmapGlyphRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_BitmapGlyphRec *) + (* *) + (* <Description> *) + (* A structure used for bitmap glyph images. This really is a *) + (* `sub-class' of `FT_GlyphRec'. *) + (* *) + (* <Fields> *) + (* root :: The root FT_Glyph fields. *) + (* *) + (* left :: The left-side bearing, i.e., the horizontal distance *) + (* from the current pen position to the left border of the *) + (* glyph bitmap. *) + (* *) + (* top :: The top-side bearing, i.e., the vertical distance from *) + (* the current pen position to the top border of the glyph *) + (* bitmap. This distance is positive for upwards-y! *) + (* *) + (* bitmap :: A descriptor for the bitmap. *) + (* *) + (* <Note> *) + (* You can typecast FT_Glyph to FT_BitmapGlyph if you have *) + (* glyph->format == FT_GLYPH_FORMAT_BITMAP. This lets you access *) + (* the bitmap's contents easily. *) + (* *) + (* The corresponding pixel buffer is always owned by the BitmapGlyph *) + (* and is thus created and destroyed with it. *) + (* *) + FT_BitmapGlyphRec = record + root: FT_GlyphRec; + left: FT_Int; + top: FT_Int; + bitmap: FT_Bitmap; + end; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_OutlineGlyph *) + (* *) + (* <Description> *) + (* A handle to an object used to model an outline glyph image. This *) + (* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. *) + (* *) + FT_OutlineGlyph = ^FT_OutlineGlyphRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_OutlineGlyphRec *) + (* *) + (* <Description> *) + (* A structure used for outline (vectorial) glyph images. This *) + (* really is a `sub-class' of `FT_GlyphRec'. *) + (* *) + (* <Fields> *) + (* root :: The root FT_Glyph fields. *) + (* *) + (* outline :: A descriptor for the outline. *) + (* *) + (* <Note> *) + (* You can typecast FT_Glyph to FT_OutlineGlyph if you have *) + (* glyph->format == FT_GLYPH_FORMAT_OUTLINE. This lets you access *) + (* the outline's content easily. *) + (* *) + (* As the outline is extracted from a glyph slot, its coordinates are *) + (* expressed normally in 26.6 pixels, unless the flag *) + (* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). *) + (* *) + (* The outline's tables are always owned by the object and are *) + (* destroyed with it. *) + (* *) + FT_OutlineGlyphRec = record + root: FT_GlyphRec; + outline: FT_Outline; + end; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_SubGlyph *) + (* *) + (* <Description> *) + (* The subglyph structure is an internal object used to describe *) + (* subglyphs (for example, in the case of composites). *) + (* *) + (* <Note> *) + (* The subglyph implementation is not part of the high-level API, *) + (* hence the forward structure declaration. *) + (* *) + FT_SubGlyph = ^FT_SubGlyphRec; + FT_SubGlyphRec = record // internal + end; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Generic_Finalizer *) + (* *) + (* <Description> *) + (* Describes a function used to destroy the `client' data of any *) + (* FreeType object. See the description of the FT_Generic type for *) + (* details of usage. *) + (* *) + (* <Input> *) + (* The address of the FreeType object which is under finalization. *) + (* Its client data is accessed through its `generic' field. *) + (* *) + FT_Generic_Finalizer = procedure(AnObject : pointer ); cdecl; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Generic *) + (* *) + (* <Description> *) + (* Client applications often need to associate their own data to a *) + (* variety of FreeType core objects. For example, a text layout API *) + (* might want to associate a glyph cache to a given size object. *) + (* *) + (* Most FreeType object contains a `generic' field, of type *) + (* FT_Generic, which usage is left to client applications and font *) + (* servers. *) + (* *) + (* It can be used to store a pointer to client-specific data, as well *) + (* as the address of a `finalizer' function, which will be called by *) + (* FreeType when the object is destroyed (for example, the previous *) + (* client example would put the address of the glyph cache destructor *) + (* in the `finalizer' field). *) + (* *) + (* <Fields> *) + (* data :: A typeless pointer to any client-specified data. This *) + (* field is completely ignored by the FreeType library. *) + (* *) + (* finalizer :: A pointer to a `generic finalizer' function, which *) + (* will be called when the object is destroyed. If this *) + (* field is set to NULL, no code will be called. *) + (* *) + FT_Generic = record + data : pointer; + finalizer : FT_Generic_Finalizer; + end; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_BBox *) + (* *) + (* <Description> *) + (* A structure used to hold an outline's bounding box, i.e., the *) + (* coordinates of its extrema in the horizontal and vertical *) + (* directions. *) + (* *) + (* <Fields> *) + (* xMin :: The horizontal minimum (left-most). *) + (* *) + (* yMin :: The vertical minimum (bottom-most). *) + (* *) + (* xMax :: The horizontal maximum (right-most). *) + (* *) + (* yMax :: The vertical maximum (top-most). *) + (* *) + PFT_BBox = ^FT_BBox; + FT_BBox = record + xMin, yMin : FT_Pos; + xMax, yMax : FT_Pos; + end; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_GlyphSlot *) + (* *) + (* <Description> *) + (* A handle to a given `glyph slot'. A slot is a container where it *) + (* is possible to load any one of the glyphs contained in its parent *) + (* face. *) + (* *) + (* In other words, each time you call @FT_Load_Glyph or *) + (* @FT_Load_Char, the slot's content is erased by the new glyph data, *) + (* i.e. the glyph's metrics, its image (bitmap or outline), and *) + (* other control information. *) + (* *) + (* <Also> *) + (* @FT_GlyphSlotRec details the publicly accessible glyph fields. *) + (* *) + FT_GlyphSlot = ^FT_GlyphSlotRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_GlyphSlotRec *) + (* *) + (* <Description> *) + (* FreeType root glyph slot class structure. A glyph slot is a *) + (* container where individual glyphs can be loaded, be they *) + (* vectorial or bitmap/graymaps. *) + (* *) + (* <Fields> *) + (* library :: A handle to the FreeType library instance *) + (* this slot belongs to. *) + (* *) + (* face :: A handle to the parent face object. *) + (* *) + (* next :: In some cases (like some font tools), several *) + (* glyph slots per face object can be a good *) + (* thing. As this is rare, the glyph slots are *) + (* listed through a direct, single-linked list *) + (* using its `next' field. *) + (* *) + (* generic :: A typeless pointer which is unused by the *) + (* FreeType library or any of its drivers. It *) + (* can be used by client applications to link *) + (* their own data to each glyph slot object. *) + (* *) + (* metrics :: The metrics of the last loaded glyph in the *) + (* slot. The returned values depend on the last *) + (* load flags (see the @FT_Load_Glyph API *) + (* function) and can be expressed either in 26.6 *) + (* fractional pixels or font units. *) + (* *) + (* Note that even when the glyph image is *) + (* transformed, the metrics are not. *) + (* *) + (* linearHoriAdvance :: For scalable formats only, this field holds *) + (* the linearly scaled horizontal advance width *) + (* for the glyph (i.e. the scaled and unhinted *) + (* value of the hori advance). This can be *) + (* important to perform correct WYSIWYG layout. *) + (* *) + (* Note that this value is expressed by default *) + (* in 16.16 pixels. However, when the glyph is *) + (* loaded with the FT_LOAD_LINEAR_DESIGN flag, *) + (* this field contains simply the value of the *) + (* advance in original font units. *) + (* *) + (* linearVertAdvance :: For scalable formats only, this field holds *) + (* the linearly scaled vertical advance height *) + (* for the glyph. See linearHoriAdvance for *) + (* comments. *) + (* *) + (* advance :: This is the transformed advance width for the *) + (* glyph. *) + (* *) + (* format :: This field indicates the format of the image *) + (* contained in the glyph slot. Typically *) + (* FT_GLYPH_FORMAT_BITMAP, *) + (* FT_GLYPH_FORMAT_OUTLINE, and *) + (* FT_GLYPH_FORMAT_COMPOSITE, but others are *) + (* possible. *) + (* *) + (* bitmap :: This field is used as a bitmap descriptor *) + (* when the slot format is *) + (* FT_GLYPH_FORMAT_BITMAP. Note that the *) + (* address and content of the bitmap buffer can *) + (* change between calls of @FT_Load_Glyph and a *) + (* few other functions. *) + (* *) + (* bitmap_left :: This is the bitmap's left bearing expressed *) + (* in integer pixels. Of course, this is only *) + (* valid if the format is *) + (* FT_GLYPH_FORMAT_BITMAP. *) + (* *) + (* bitmap_top :: This is the bitmap's top bearing expressed in *) + (* integer pixels. Remember that this is the *) + (* distance from the baseline to the top-most *) + (* glyph scanline, upwards y-coordinates being *) + (* *positive*. *) + (* *) + (* outline :: The outline descriptor for the current glyph *) + (* image if its format is *) + (* FT_GLYPH_FORMAT_OUTLINE. *) + (* *) + (* num_subglyphs :: The number of subglyphs in a composite glyph. *) + (* This field is only valid for the composite *) + (* glyph format that should normally only be *) + (* loaded with the @FT_LOAD_NO_RECURSE flag. *) + (* For now this is internal to FreeType. *) + (* *) + (* subglyphs :: An array of subglyph descriptors for *) + (* composite glyphs. There are `num_subglyphs' *) + (* elements in there. Currently internal to *) + (* FreeType. *) + (* *) + (* control_data :: Certain font drivers can also return the *) + (* control data for a given glyph image (e.g. *) + (* TrueType bytecode, Type 1 charstrings, etc.). *) + (* This field is a pointer to such data. *) + (* *) + (* control_len :: This is the length in bytes of the control *) + (* data. *) + (* *) + (* other :: Really wicked formats can use this pointer to *) + (* present their own glyph image to client apps. *) + (* Note that the app will need to know about the *) + (* image format. *) + (* *) + (* lsb_delta :: The difference between hinted and unhinted *) + (* left side bearing while autohinting is *) + (* active. Zero otherwise. *) + (* *) + (* rsb_delta :: The difference between hinted and unhinted *) + (* right side bearing while autohinting is *) + (* active. Zero otherwise. *) + (* *) + (* <Note> *) + (* If @FT_Load_Glyph is called with default flags (see *) + (* @FT_LOAD_DEFAULT) the glyph image is loaded in the glyph slot in *) + (* its native format (e.g. a vectorial outline for TrueType and *) + (* Type 1 formats). *) + (* *) + (* This image can later be converted into a bitmap by calling *) + (* @FT_Render_Glyph. This function finds the current renderer for *) + (* the native image's format then invokes it. *) + (* *) + (* The renderer is in charge of transforming the native image through *) + (* the slot's face transformation fields, then convert it into a *) + (* bitmap that is returned in `slot->bitmap'. *) + (* *) + (* Note that `slot->bitmap_left' and `slot->bitmap_top' are also used *) + (* to specify the position of the bitmap relative to the current pen *) + (* position (e.g. coordinates [0,0] on the baseline). Of course, *) + (* `slot->format' is also changed to `FT_GLYPH_FORMAT_BITMAP' . *) + (* *) + (* <Note> *) + (* Here a small pseudo code fragment which shows how to use *) + (* `lsb_delta' and `rsb_delta': *) + (* *) + (* { *) + (* FT_Pos origin_x = 0; *) + (* FT_Pos prev_rsb_delta = 0; *) + (* *) + (* *) + (* for all glyphs do *) + (* <compute kern between current and previous glyph and add it to *) + (* `origin_x'> *) + (* *) + (* <load glyph with `FT_Load_Glyph'> *) + (* *) + (* if ( prev_rsb_delta - face->glyph->lsb_delta >= 32 ) *) + (* origin_x -= 64; *) + (* else if ( prev_rsb_delta - face->glyph->lsb_delta < -32 ) *) + (* origin_x += 64; *) + (* *) + (* prev_rsb_delta = face->glyph->rsb_delta; *) + (* *) + (* <save glyph image, or render glyph, or ...> *) + (* *) + (* origin_x += face->glyph->advance.x; *) + (* endfor *) + (* } *) + (* *) + FT_GlyphSlotRec = record + alibrary : FT_Library; + + face : FT_Face; + next : FT_GlyphSlot; + flags : FT_UInt; + + generic : FT_Generic; + metrics : FT_Glyph_Metrics; + + linearHoriAdvance , + linearVertAdvance : FT_Fixed; + + advance : FT_Vector; + format : FT_Glyph_Format; + bitmap : FT_Bitmap; + + bitmap_left , + bitmap_top : FT_Int; + + outline : FT_Outline; + + num_subglyphs : FT_UInt; + subglyphs : FT_SubGlyph; + + control_data : pointer; + control_len : longint; + + lsb_delta: FT_Pos; + rsb_delta: FT_Pos; + + other : pointer; + + //internal: FT_Slot_Internal; + end; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Size_Metrics *) + (* *) + (* <Description> *) + (* The size metrics structure returned scaled important distances for *) + (* a given size object. *) + (* *) + (* <Fields> *) + (* x_ppem :: The character width, expressed in integer pixels. *) + (* This is the width of the EM square expressed in *) + (* pixels, hence the term `ppem' (pixels per EM). *) + (* *) + (* y_ppem :: The character height, expressed in integer pixels. *) + (* This is the height of the EM square expressed in *) + (* pixels, hence the term `ppem' (pixels per EM). *) + (* *) + (* x_scale :: A simple 16.16 fixed point format coefficient used *) + (* to scale horizontal distances expressed in font *) + (* units to fractional (26.6) pixel coordinates. *) + (* *) + (* y_scale :: A simple 16.16 fixed point format coefficient used *) + (* to scale vertical distances expressed in font *) + (* units to fractional (26.6) pixel coordinates. *) + (* *) + (* ascender :: The ascender, expressed in 26.6 fixed point *) + (* pixels. Positive for ascenders above the *) + (* baseline. *) + (* *) + (* descender :: The descender, expressed in 26.6 fixed point *) + (* pixels. Negative for descenders below the *) + (* baseline. *) + (* *) + (* height :: The text height, expressed in 26.6 fixed point *) + (* pixels. Always positive. *) + (* *) + (* max_advance :: Maximum horizontal advance, expressed in 26.6 *) + (* fixed point pixels. Always positive. *) + (* *) + (* <Note> *) + (* For scalable fonts, the values of `ascender', `descender', and *) + (* `height' are scaled versions of `face->ascender', *) + (* `face->descender', and `face->height', respectively. *) + (* *) + (* Unfortunately, due to glyph hinting, these values might not be *) + (* exact for certain fonts. They thus must be treated as unreliable *) + (* with an error margin of at least one pixel! *) + (* *) + (* Indeed, the only way to get the exact pixel ascender and descender *) + (* is to render _all_ glyphs. As this would be a definite *) + (* performance hit, it is up to client applications to perform such *) + (* computations. *) + (* *) + FT_Size_Metrics = record + x_ppem , + y_ppem : FT_UShort; + x_scale , + y_scale : FT_Fixed; + + ascender , + descender : FT_Pos; + height : FT_Pos; + max_advance : FT_Pos; + end; + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Size *) + (* *) + (* <Description> *) + (* A handle to a given size object. Such an object models the data *) + (* that depends on the current _resolution_ and _character size_ in a *) + (* given @FT_Face. *) + (* *) + (* <Note> *) + (* Each face object owns one or more sizes. There is however a *) + (* single _active_ size for the face at any time that will be used by *) + (* functions like @FT_Load_Glyph, @FT_Get_Kerning, etc. *) + (* *) + (* You can use the @FT_Activate_Size API to change the current *) + (* active size of any given face. *) + (* *) + (* <Also> *) + (* The @FT_SizeRec structure details the publicly accessible fields *) + (* of a given face object. *) + (* *) + FT_Size = ^FT_SizeRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_SizeRec *) + (* *) + (* <Description> *) + (* FreeType root size class structure. A size object models the *) + (* resolution and pointsize dependent data of a given face. *) + (* *) + (* <Fields> *) + (* face :: Handle to the parent face object. *) + (* *) + (* generic :: A typeless pointer, which is unused by the FreeType *) + (* library or any of its drivers. It can be used by *) + (* client applications to link their own data to each size *) + (* object. *) + (* *) + (* metrics :: Metrics for this size object. This field is read-only. *) + (* *) + FT_SizeRec = record + face : FT_Face; + generic : FT_Generic; + metrics : FT_Size_Metrics; + //internal : FT_Size_Internal; + end; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_FaceRec *) + (* *) + (* <Description> *) + (* FreeType root face class structure. A face object models the *) + (* resolution and point-size independent data found in a font file. *) + (* *) + (* <Fields> *) + (* num_faces :: In the case where the face is located in a *) + (* collection (i.e., a file which embeds *) + (* several faces), this is the total number of *) + (* faces found in the resource. 1 by default. *) + (* Accessing non-existent face indices causes *) + (* an error. *) + (* *) + (* face_index :: The index of the face in its font file. *) + (* Usually, this is 0 for all normal font *) + (* formats. It can be > 0 in the case of *) + (* collections (which embed several fonts in a *) + (* single resource/file). *) + (* *) + (* face_flags :: A set of bit flags that give important *) + (* information about the face; see the *) + (* @FT_FACE_FLAG_XXX constants for details. *) + (* *) + (* style_flags :: A set of bit flags indicating the style of *) + (* the face (i.e., italic, bold, underline, *) + (* etc). See the @FT_STYLE_FLAG_XXX *) + (* constants. *) + (* *) + (* num_glyphs :: The total number of glyphs in the face. *) + (* *) + (* family_name :: The face's family name. This is an ASCII *) + (* string, usually in English, which describes *) + (* the typeface's family (like `Times New *) + (* Roman', `Bodoni', `Garamond', etc). This *) + (* is a least common denominator used to list *) + (* fonts. Some formats (TrueType & OpenType) *) + (* provide localized and Unicode versions of *) + (* this string. Applications should use the *) + (* format specific interface to access them. *) + (* *) + (* style_name :: The face's style name. This is an ASCII *) + (* string, usually in English, which describes *) + (* the typeface's style (like `Italic', *) + (* `Bold', `Condensed', etc). Not all font *) + (* formats provide a style name, so this field *) + (* is optional, and can be set to NULL. As *) + (* for `family_name', some formats provide *) + (* localized/Unicode versions of this string. *) + (* Applications should use the format specific *) + (* interface to access them. *) + (* *) + (* num_fixed_sizes :: The number of fixed sizes available in this *) + (* face. This should be set to 0 for scalable *) + (* fonts, unless its face includes a set of *) + (* glyphs (called a `strike') for the *) + (* specified sizes. *) + (* *) + (* available_sizes :: An array of sizes specifying the available *) + (* bitmap/graymap sizes that are contained in *) + (* in the font face. Should be set to NULL if *) + (* the field `num_fixed_sizes' is set to 0. *) + (* *) + (* num_charmaps :: The total number of character maps in the *) + (* face. *) + (* *) + (* charmaps :: A table of pointers to the face's charmaps. *) + (* Used to scan the list of available charmaps *) + (* -- this table might change after a call to *) + (* @FT_Attach_File or @FT_Attach_Stream (e.g. *) + (* if used to hook an additional encoding or *) + (* CMap to the face object). *) + (* *) + (* generic :: A field reserved for client uses. See the *) + (* @FT_Generic type description. *) + (* *) + (* bbox :: The font bounding box. Coordinates are *) + (* expressed in font units (see units_per_EM). *) + (* The box is large enough to contain any *) + (* glyph from the font. Thus, bbox.yMax can *) + (* be seen as the `maximal ascender', *) + (* bbox.yMin as the `minimal descender', and *) + (* the maximal glyph width is given by *) + (* `bbox.xMax-bbox.xMin' (not to be confused *) + (* with the maximal _advance_width_). Only *) + (* relevant for scalable formats. *) + (* *) + (* units_per_EM :: The number of font units per EM square for *) + (* this face. This is typically 2048 for *) + (* TrueType fonts, 1000 for Type1 fonts, and *) + (* should be set to the (unrealistic) value 1 *) + (* for fixed-sizes fonts. Only relevant for *) + (* scalable formats. *) + (* *) + (* ascender :: The face's ascender is the vertical *) + (* distance from the baseline to the topmost *) + (* point of any glyph in the face. This *) + (* field's value is positive, expressed in *) + (* font units. Some font designs use a value *) + (* different from `bbox.yMax'. Only relevant *) + (* for scalable formats. *) + (* *) + (* descender :: The face's descender is the vertical *) + (* distance from the baseline to the *) + (* bottommost point of any glyph in the face. *) + (* This field's value is *negative* for values *) + (* below the baseline. It is expressed in *) + (* font units. Some font designs use a value *) + (* different from `bbox.yMin'. Only relevant *) + (* for scalable formats. *) + (* *) + (* height :: The face's height is the vertical distance *) + (* from one baseline to the next when writing *) + (* several lines of text. Its value is always *) + (* positive, expressed in font units. The *) + (* value can be computed as *) + (* `ascender+descender+line_gap' where the *) + (* value of `line_gap' is also called *) + (* `external leading'. Only relevant for *) + (* scalable formats. *) + (* *) + (* max_advance_width :: The maximal advance width, in font units, *) + (* for all glyphs in this face. This can be *) + (* used to make word wrapping computations *) + (* faster. Only relevant for scalable *) + (* formats. *) + (* *) + (* max_advance_height :: The maximal advance height, in font units, *) + (* for all glyphs in this face. This is only *) + (* relevant for vertical layouts, and should *) + (* be set to the `height' for fonts that do *) + (* not provide vertical metrics. Only *) + (* relevant for scalable formats. *) + (* *) + (* underline_position :: The position, in font units, of the *) + (* underline line for this face. It's the *) + (* center of the underlining stem. Only *) + (* relevant for scalable formats. *) + (* *) + (* underline_thickness :: The thickness, in font units, of the *) + (* underline for this face. Only relevant for *) + (* scalable formats. *) + (* *) + (* glyph :: The face's associated glyph slot(s). This *) + (* object is created automatically with a new *) + (* face object. However, certain kinds of *) + (* applications (mainly tools like converters) *) + (* can need more than one slot to ease their *) + (* task. *) + (* *) + (* size :: The current active size for this face. *) + (* *) + (* charmap :: The current active charmap for this face. *) + (* *) + FT_FaceRec = record + num_faces : FT_Long; + face_index : FT_Long; + + face_flags : FT_Long; + style_flags : FT_Long; + + num_glyphs : FT_Long; + + family_name : PFT_String; + style_name : PFT_String; + + num_fixed_sizes : FT_Int; + available_sizes : PAFT_Bitmap_Size; // is array + + num_charmaps : FT_Int; + charmaps : PAFT_CharMap; // is array + + generic : FT_Generic; + + (*# the following are only relevant to scalable outlines *) + 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 : FT_GlyphSlot; + size : FT_Size; + charmap : FT_CharMap; + end; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_CharMapRec *) + (* *) + (* <Description> *) + (* The base charmap structure. *) + (* *) + (* <Fields> *) + (* face :: A handle to the parent face object. *) + (* *) + (* encoding :: An @FT_Encoding tag identifying the charmap. Use *) + (* this with @FT_Select_Charmap. *) + (* *) + (* platform_id :: An ID number describing the platform for the *) + (* following encoding ID. This comes directly from *) + (* the TrueType specification and should be emulated *) + (* for other formats. *) + (* *) + (* encoding_id :: A platform specific encoding number. This also *) + (* comes from the TrueType specification and should be *) + (* emulated similarly. *) + (* *) + FT_CharMapRec = record + face : FT_Face; + encoding : FT_Encoding; + platform_id : FT_UShort; + encoding_id : FT_UShort; + end; + +{ GLOBAL PROCEDURES } + + (*************************************************************************) + (* *) + (* @macro: *) + (* FT_CURVE_TAG ( flag ) *) + (* *) + function FT_CURVE_TAG (flag : char ) : char; + +const + FT_CURVE_TAG_ON = 1; + FT_CURVE_TAG_CONIC = 0; + FT_CURVE_TAG_CUBIC = 2; + + + (*************************************************************************) + (* *) + (* @macro: *) + (* FT_IS_SCALABLE( face ) *) + (* *) + (* @description: *) + (* A macro that returns true whenever a face object contains a *) + (* scalable font face (true for TrueType, Type 1, CID, and *) + (* OpenType/CFF font formats. *) + (* *) + function FT_IS_SCALABLE(face : FT_Face ) : cbool; + + (*************************************************************************) + (* *) + (* @macro: *) + (* FT_HAS_KERNING( face ) *) + (* *) + (* @description: *) + (* A macro that returns true whenever a face object contains kerning *) + (* data that can be accessed with @FT_Get_Kerning. *) + (* *) + function FT_HAS_KERNING(face : FT_Face ) : cbool; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Init_FreeType *) + (* *) + (* <Description> *) + (* Initializes a new FreeType library object. The set of modules *) + (* that are registered by this function is determined at build time. *) + (* *) + (* <Output> *) + (* alibrary :: A handle to a new library object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Init_FreeType(out alibrary : FT_Library ) : FT_Error; + cdecl; external ft_lib name 'FT_Init_FreeType'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Done_FreeType *) + (* *) + (* <Description> *) + (* Destroys a given FreeType library object and all of its childs, *) + (* including resources, drivers, faces, sizes, etc. *) + (* *) + (* <Input> *) + (* library :: A handle to the target library object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Done_FreeType(alibrary : FT_Library ) : FT_Error; + cdecl; external ft_lib name 'FT_Done_FreeType'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Attach_File *) + (* *) + (* <Description> *) + (* `Attaches' a given font file to an existing face. This is usually *) + (* to read additional information for a single face object. For *) + (* example, it is used to read the AFM files that come with Type 1 *) + (* fonts in order to add kerning data and other metrics. *) + (* *) + (* <InOut> *) + (* face :: The target face object. *) + (* *) + (* <Input> *) + (* filepathname :: An 8-bit pathname naming the `metrics' file. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* If your font file is in memory, or if you want to provide your *) + (* own input stream object, use @FT_Attach_Stream. *) + (* *) + (* The meaning of the `attach' action (i.e., what really happens when *) + (* the new file is read) is not fixed by FreeType itself. It really *) + (* depends on the font format (and thus the font driver). *) + (* *) + (* Client applications are expected to know what they are doing *) + (* when invoking this function. Most drivers simply do not implement *) + (* file attachments. *) + (* *) + function FT_Attach_File(face : FT_Face; filepathname : PChar ) : FT_Error; + cdecl; external ft_lib name 'FT_Attach_File'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_New_Memory_Face *) + (* *) + (* <Description> *) + (* Creates a new face object from a given resource and typeface index *) + (* using a font file already loaded into memory. *) + (* *) + (* <InOut> *) + (* library :: A handle to the library resource. *) + (* *) + (* <Input> *) + (* file_base :: A pointer to the beginning of the font data. *) + (* *) + (* file_size :: The size of the memory chunk used by the font data. *) + (* *) + (* face_index :: The index of the face within the resource. The *) + (* first face has index 0. *) + (* *) + (* <Output> *) + (* aface :: A handle to a new face object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* The font data bytes are used _directly_ by the @FT_Face object. *) + (* This means that they are not copied, and that the client is *) + (* responsible for releasing/destroying them _after_ the *) + (* corresponding call to @FT_Done_Face . *) + (* *) + (* Unlike FreeType 1.x, this function automatically creates a glyph *) + (* slot for the face object which can be accessed directly through *) + (* `face->glyph'. *) + (* *) + (* @FT_New_Memory_Face can be used to determine and/or check the font *) + (* format of a given font resource. If the `face_index' field is *) + (* negative, the function will _not_ return any face handle in *) + (* `aface'; the return value is 0 if the font format is recognized, *) + (* or non-zero otherwise. *) + (* *) + function FT_New_Memory_Face( + library_ : FT_Library; + file_base : PFT_Byte; + file_size , + face_index : FT_Long; + out aface : FT_Face ) : FT_Error; + cdecl; external ft_lib name 'FT_New_Memory_Face'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_New_Face *) + (* *) + (* <Description> *) + (* Creates a new face object from a given resource and typeface index *) + (* using a pathname to the font file. *) + (* *) + (* <InOut> *) + (* library :: A handle to the library resource. *) + (* *) + (* <Input> *) + (* pathname :: A path to the font file. *) + (* *) + (* face_index :: The index of the face within the resource. The *) + (* first face has index 0. *) + (* *) + (* <Output> *) + (* aface :: A handle to a new face object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* Unlike FreeType 1.x, this function automatically creates a glyph *) + (* slot for the face object which can be accessed directly through *) + (* `face->glyph'. *) + (* *) + (* @FT_New_Face can be used to determine and/or check the font format *) + (* of a given font resource. If the `face_index' field is negative, *) + (* the function will _not_ return any face handle in `aface'; the *) + (* return value is 0 if the font format is recognized, or non-zero *) + (* otherwise. *) + (* *) + (* Each new face object created with this function also owns a *) + (* default @FT_Size object, accessible as `face->size'. *) + (* *) + function FT_New_Face( + library_ : FT_Library; + filepathname : PChar; + face_index : FT_Long; + out aface : FT_Face ) : FT_Error; + cdecl; external ft_lib name 'FT_New_Face'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Done_Face *) + (* *) + (* <Description> *) + (* Discards a given face object, as well as all of its child slots *) + (* and sizes. *) + (* *) + (* <Input> *) + (* face :: A handle to a target face object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Done_Face(face : FT_Face ) : FT_Error; + cdecl; external ft_lib name 'FT_Done_Face'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Select_Charmap *) + (* *) + (* <Description> *) + (* Selects a given charmap by its encoding tag (as listed in *) + (* `freetype.h'). *) + (* *) + (* <InOut> *) + (* face :: A handle to the source face object. *) + (* *) + (* <Input> *) + (* encoding :: A handle to the selected charmap. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* This function will return an error if no charmap in the face *) + (* corresponds to the encoding queried here. *) + (* *) + function FT_Select_Charmap(face : FT_Face; encoding : FT_Encoding ) : FT_Error; + cdecl; external ft_lib name 'FT_Select_Charmap'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Get_Char_Index *) + (* *) + (* <Description> *) + (* Returns the glyph index of a given character code. This function *) + (* uses a charmap object to do the translation. *) + (* *) + (* <Input> *) + (* face :: A handle to the source face object. *) + (* *) + (* charcode :: The character code. *) + (* *) + (* <Return> *) + (* The glyph index. 0 means `undefined character code'. *) + (* *) + (* <Note> *) + (* FreeType computes its own glyph indices which are not necessarily *) + (* the same as used in the font in case the font is based on glyph *) + (* indices. Reason for this behaviour is to assure that index 0 is *) + (* never used, representing the missing glyph. *) + (* *) + function FT_Get_Char_Index(face : FT_Face; charcode : FT_ULong ) : FT_UInt; + cdecl; external ft_lib name 'FT_Get_Char_Index'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Load_Glyph *) + (* *) + (* <Description> *) + (* A function used to load a single glyph within a given glyph slot, *) + (* for a given size. *) + (* *) + (* <InOut> *) + (* face :: A handle to the target face object where the glyph *) + (* will be loaded. *) + (* *) + (* <Input> *) + (* glyph_index :: The index of the glyph in the font file. For *) + (* CID-keyed fonts (either in PS or in CFF format) *) + (* this argument specifies the CID value. *) + (* *) + (* load_flags :: A flag indicating what to load for this glyph. The *) + (* @FT_LOAD_XXX constants can be used to control the *) + (* glyph loading process (e.g., whether the outline *) + (* should be scaled, whether to load bitmaps or not, *) + (* whether to hint the outline, etc). *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* If the glyph image is not a bitmap, and if the bit flag *) + (* FT_LOAD_IGNORE_TRANSFORM is unset, the glyph image will be *) + (* transformed with the information passed to a previous call to *) + (* @FT_Set_Transform. *) + (* *) + (* Note that this also transforms the `face.glyph.advance' field, but *) + (* *not* the values in `face.glyph.metrics'. *) + (* *) + function FT_Load_Glyph( + face : FT_Face; + glyph_index : FT_UInt ; + load_flags : FT_Int32 ) : FT_Error; + cdecl; external ft_lib name 'FT_Load_Glyph'; + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Render_Mode *) + (* *) + (* <Description> *) + (* An enumeration type that lists the render modes supported by *) + (* FreeType 2. Each mode corresponds to a specific type of scanline *) + (* conversion performed on the outline, as well as specific *) + (* hinting optimizations. *) + (* *) + (* For bitmap fonts the `bitmap->pixel_mode' field in the *) + (* @FT_GlyphSlotRec structure gives the format of the returned *) + (* bitmap. *) + (* *) + (* <Values> *) + (* FT_RENDER_MODE_NORMAL :: *) + (* This is the default render mode; it corresponds to 8-bit *) + (* anti-aliased bitmaps, using 256 levels of opacity. *) + (* *) + (* FT_RENDER_MODE_LIGHT :: *) + (* This is similar to @FT_RENDER_MODE_NORMAL -- you have to use *) + (* @FT_LOAD_TARGET_LIGHT in calls to @FT_Load_Glyph to get any *) + (* effect since the rendering process no longer influences the *) + (* positioning of glyph outlines. *) + (* *) + (* The resulting glyph shapes are more similar to the original, *) + (* while being a bit more fuzzy (`better shapes' instead of `better *) + (* contrast', so to say. *) + (* *) + (* FT_RENDER_MODE_MONO :: *) + (* This mode corresponds to 1-bit bitmaps. *) + (* *) + (* FT_RENDER_MODE_LCD :: *) + (* This mode corresponds to horizontal RGB/BGR sub-pixel displays, *) + (* like LCD-screens. It produces 8-bit bitmaps that are 3 times *) + (* the width of the original glyph outline in pixels, and which use *) + (* the @FT_PIXEL_MODE_LCD mode. *) + (* *) + (* FT_RENDER_MODE_LCD_V :: *) + (* This mode corresponds to vertical RGB/BGR sub-pixel displays *) + (* (like PDA screens, rotated LCD displays, etc.). It produces *) + (* 8-bit bitmaps that are 3 times the height of the original *) + (* glyph outline in pixels and use the @FT_PIXEL_MODE_LCD_V mode. *) + (* *) + (* <Note> *) + (* The LCD-optimized glyph bitmaps produced by FT_Render_Glyph are *) + (* _not filtered_ to reduce color-fringes. It is up to the caller to *) + (* perform this pass. *) + (* *) +const + FT_RENDER_MODE_NORMAL = 0; + FT_RENDER_MODE_LIGHT = FT_RENDER_MODE_NORMAL + 1; + FT_RENDER_MODE_MONO = FT_RENDER_MODE_LIGHT + 1; + FT_RENDER_MODE_LCD = FT_RENDER_MODE_MONO + 1; + FT_RENDER_MODE_LCD_V = FT_RENDER_MODE_LCD + 1; + FT_RENDER_MODE_MAX = FT_RENDER_MODE_LCD_V + 1; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Render_Glyph *) + (* *) + (* <Description> *) + (* Converts a given glyph image to a bitmap. It does so by *) + (* inspecting the glyph image format, find the relevant renderer, and *) + (* invoke it. *) + (* *) + (* <InOut> *) + (* slot :: A handle to the glyph slot containing the image to *) + (* convert. *) + (* *) + (* <Input> *) + (* render_mode :: This is the render mode used to render the glyph *) + (* image into a bitmap. See FT_Render_Mode for a list *) + (* of possible values. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Render_Glyph(slot : FT_GlyphSlot; render_mode : FT_Render_Mode ) : FT_Error; + cdecl; external ft_lib name 'FT_Render_Glyph'; + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Kerning_Mode *) + (* *) + (* <Description> *) + (* An enumeration used to specify which kerning values to return in *) + (* @FT_Get_Kerning. *) + (* *) + (* <Values> *) + (* FT_KERNING_DEFAULT :: Return scaled and grid-fitted kerning *) + (* distances (value is 0). *) + (* *) + (* FT_KERNING_UNFITTED :: Return scaled but un-grid-fitted kerning *) + (* distances. *) + (* *) + (* FT_KERNING_UNSCALED :: Return the kerning vector in original font *) + (* units. *) + (* *) +const + FT_KERNING_DEFAULT = 0; + FT_KERNING_UNFITTED = 1; + FT_KERNING_UNSCALED = 2; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Get_Kerning *) + (* *) + (* <Description> *) + (* Returns the kerning vector between two glyphs of a same face. *) + (* *) + (* <Input> *) + (* face :: A handle to a source face object. *) + (* *) + (* left_glyph :: The index of the left glyph in the kern pair. *) + (* *) + (* right_glyph :: The index of the right glyph in the kern pair. *) + (* *) + (* kern_mode :: See @FT_Kerning_Mode for more information. *) + (* Determines the scale/dimension of the returned *) + (* kerning vector. *) + (* *) + (* <Output> *) + (* akerning :: The kerning vector. This is in font units for *) + (* scalable formats, and in pixels for fixed-sizes *) + (* formats. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* Only horizontal layouts (left-to-right & right-to-left) are *) + (* supported by this method. Other layouts, or more sophisticated *) + (* kernings, are out of the scope of this API function -- they can be *) + (* implemented through format-specific interfaces. *) + (* *) + function FT_Get_Kerning( + face : FT_Face; + left_glyph , + right_glyph , + kern_mode : FT_UInt; + out akerning : FT_Vector ) : FT_Error; + cdecl; external ft_lib name 'FT_Get_Kerning'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Set_Char_Size *) + (* *) + (* <Description> *) + (* Sets the character dimensions of a given face object. The *) + (* `char_width' and `char_height' values are used for the width and *) + (* height, respectively, expressed in 26.6 fractional points. *) + (* *) + (* If the horizontal or vertical resolution values are zero, a *) + (* default value of 72dpi is used. Similarly, if one of the *) + (* character dimensions is zero, its value is set equal to the other. *) + (* *) + (* <InOut> *) + (* face :: A handle to a target face object. *) + (* *) + (* <Input> *) + (* char_width :: The character width, in 26.6 fractional points. *) + (* *) + (* char_height :: The character height, in 26.6 fractional *) + (* points. *) + (* *) + (* horz_resolution :: The horizontal resolution. *) + (* *) + (* vert_resolution :: The vertical resolution. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* When dealing with fixed-size faces (i.e., non-scalable formats), *) + (* @FT_Set_Pixel_Sizes provides a more convenient interface. *) + (* *) + function FT_Set_Char_Size( + face : FT_Face; + char_width , + char_height : FT_F26dot6; + horz_res , + vert_res : FT_UInt) : FT_Error; + cdecl; external ft_lib name 'FT_Set_Char_Size'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Set_Pixel_Sizes *) + (* *) + (* <Description> *) + (* Sets the character dimensions of a given face object. The width *) + (* and height are expressed in integer pixels. *) + (* *) + (* If one of the character dimensions is zero, its value is set equal *) + (* to the other. *) + (* *) + (* <InOut> *) + (* face :: A handle to the target face object. *) + (* *) + (* <Input> *) + (* pixel_width :: The character width, in integer pixels. *) + (* *) + (* pixel_height :: The character height, in integer pixels. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* The values of `pixel_width' and `pixel_height' correspond to the *) + (* pixel values of the _typographic_ character size, which are NOT *) + (* necessarily the same as the dimensions of the glyph `bitmap *) + (* cells'. *) + (* *) + (* The `character size' is really the size of an abstract square *) + (* called the `EM', used to design the font. However, depending *) + (* on the font design, glyphs will be smaller or greater than the *) + (* EM. *) + (* *) + (* This means that setting the pixel size to, say, 8x8 doesn't *) + (* guarantee in any way that you will get glyph bitmaps that all fit *) + (* within an 8x8 cell (sometimes even far from it). *) + (* *) + (* For bitmap fonts, `pixel_height' usually is a reliable value for *) + (* the height of the bitmap cell. Drivers for bitmap font formats *) + (* which contain a single bitmap strike only (BDF, PCF, FNT) ignore *) + (* `pixel_width'. *) + (* *) + function FT_Set_Pixel_Sizes( + face : FT_Face; + pixel_width , + pixel_height : FT_UInt ) : FT_Error; + cdecl; external ft_lib name 'FT_Set_Pixel_Sizes'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Get_Glyph *) + (* *) + (* <Description> *) + (* A function used to extract a glyph image from a slot. *) + (* *) + (* <Input> *) + (* slot :: A handle to the source glyph slot. *) + (* *) + (* <Output> *) + (* aglyph :: A handle to the glyph object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Get_Glyph( + slot: FT_GlyphSlot; + out aglyph: FT_Glyph ): FT_Error; + cdecl; external ft_lib name 'FT_Get_Glyph'; + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Glyph_BBox_Mode *) + (* *) + (* <Description> *) + (* The mode how the values of @FT_Glyph_Get_CBox are returned. *) + (* *) + (* <Values> *) + (* FT_GLYPH_BBOX_UNSCALED :: *) + (* Return unscaled font units. *) + (* *) + (* FT_GLYPH_BBOX_SUBPIXELS :: *) + (* Return unfitted 26.6 coordinates. *) + (* *) + (* FT_GLYPH_BBOX_GRIDFIT :: *) + (* Return grid-fitted 26.6 coordinates. *) + (* *) + (* FT_GLYPH_BBOX_TRUNCATE :: *) + (* Return coordinates in integer pixels. *) + (* *) + (* FT_GLYPH_BBOX_PIXELS :: *) + (* Return grid-fitted pixel coordinates. *) + (* *) +type + FT_Glyph_BBox_Mode = FT_UInt; +const + FT_GLYPH_BBOX_UNSCALED = 0; + FT_GLYPH_BBOX_SUBPIXELS = 0; + FT_GLYPH_BBOX_GRIDFIT = 1; + FT_GLYPH_BBOX_TRUNCATE = 2; + FT_GLYPH_BBOX_PIXELS = 3; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Glyph_Get_CBox *) + (* *) + (* <Description> *) + (* Return a glyph's `control box'. The control box encloses all the *) + (* outline's points, including Bzier control points. Though it *) + (* coincides with the exact bounding box for most glyphs, it can be *) + (* slightly larger in some situations (like when rotating an outline *) + (* which contains Bzier outside arcs). *) + (* *) + (* Computing the control box is very fast, while getting the bounding *) + (* box can take much more time as it needs to walk over all segments *) + (* and arcs in the outline. To get the latter, you can use the *) + (* `ftbbox' component which is dedicated to this single task. *) + (* *) + (* <Input> *) + (* glyph :: A handle to the source glyph object. *) + (* *) + (* mode :: The mode which indicates how to interpret the returned *) + (* bounding box values. *) + (* *) + (* <Output> *) + (* acbox :: The glyph coordinate bounding box. Coordinates are *) + (* expressed in 1/64th of pixels if it is grid-fitted. *) + (* *) + (* <Note> *) + (* Coordinates are relative to the glyph origin, using the Y-upwards *) + (* convention. *) + (* *) + (* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode' *) + (* must be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font *) + (* units in 26.6 pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS *) + (* is another name for this constant. *) + (* *) + (* Note that the maximum coordinates are exclusive, which means that *) + (* one can compute the width and height of the glyph image (be it in *) + (* integer or 26.6 pixels) as: *) + (* *) + (* { *) + (* width = bbox.xMax - bbox.xMin; *) + (* height = bbox.yMax - bbox.yMin; *) + (* } *) + (* *) + (* Note also that for 26.6 coordinates, if `bbox_mode' is set to *) + (* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, *) + (* which corresponds to: *) + (* *) + (* { *) + (* bbox.xMin = FLOOR(bbox.xMin); *) + (* bbox.yMin = FLOOR(bbox.yMin); *) + (* bbox.xMax = CEILING(bbox.xMax); *) + (* bbox.yMax = CEILING(bbox.yMax); *) + (* } *) + (* *) + (* To get the bbox in pixel coordinates, set `bbox_mode' to *) + (* @FT_GLYPH_BBOX_TRUNCATE. *) + (* *) + (* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' *) + (* to @FT_GLYPH_BBOX_PIXELS. *) + (* *) + procedure FT_Glyph_Get_CBox( glyph: FT_Glyph; + bbox_mode: FT_UInt; + out acbox: FT_BBox ); + cdecl; external ft_lib name 'FT_Glyph_Get_CBox'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Glyph_To_Bitmap *) + (* *) + (* <Description> *) + (* Converts a given glyph object to a bitmap glyph object. *) + (* *) + (* <InOut> *) + (* the_glyph :: A pointer to a handle to the target glyph. *) + (* *) + (* <Input> *) + (* render_mode :: An enumeration that describe how the data is *) + (* rendered. *) + (* *) + (* origin :: A pointer to a vector used to translate the glyph *) + (* image before rendering. Can be 0 (if no *) + (* translation). The origin is expressed in *) + (* 26.6 pixels. *) + (* *) + (* destroy :: A boolean that indicates that the original glyph *) + (* image should be destroyed by this function. It is *) + (* never destroyed in case of error. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* The glyph image is translated with the `origin' vector before *) + (* rendering. *) + (* *) + (* The first parameter is a pointer to a FT_Glyph handle, that will *) + (* be replaced by this function. Typically, you would use (omitting *) + (* error handling): *) + (* *) + (* *) + (* { *) + (* FT_Glyph glyph; *) + (* FT_BitmapGlyph glyph_bitmap; *) + (* *) + (* *) + (* // load glyph *) + (* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); *) + (* *) + (* // extract glyph image *) + (* error = FT_Get_Glyph( face->glyph, &glyph ); *) + (* *) + (* // convert to a bitmap (default render mode + destroy old) *) + (* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) *) + (* { *) + (* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_DEFAULT, *) + (* 0, 1 ); *) + (* if ( error ) // glyph unchanged *) + (* ... *) + (* } *) + (* *) + (* // access bitmap content by typecasting *) + (* glyph_bitmap = (FT_BitmapGlyph)glyph; *) + (* *) + (* // do funny stuff with it, like blitting/drawing *) + (* ... *) + (* *) + (* // discard glyph image (bitmap or not) *) + (* FT_Done_Glyph( glyph ); *) + (* } *) + (* *) + (* *) + (* This function does nothing if the glyph format isn't scalable. *) + (* *) + function FT_Glyph_To_Bitmap(var the_glyph: FT_Glyph; + render_mode: FT_Render_Mode; + origin: PFT_Vector; + destroy: FT_Bool ): FT_Error; + cdecl; external ft_lib name 'FT_Glyph_To_Bitmap'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Done_Glyph *) + (* *) + (* <Description> *) + (* Destroys a given glyph. *) + (* *) + (* <Input> *) + (* glyph :: A handle to the target glyph object. *) + (* *) + procedure FT_Done_Glyph( glyph: FT_Glyph ); + cdecl; external ft_lib name 'FT_Done_Glyph'; + +implementation + + +{ FT_CURVE_TAG } +function FT_CURVE_TAG(flag : char ) : char; +begin + result := char(byte(flag) and 3); +end; + +{ FT_IS_SCALABLE } +function FT_IS_SCALABLE(face : FT_Face ) : cbool; +begin + result := cbool(face.face_flags and FT_FACE_FLAG_SCALABLE ); +end; + +{ FT_HAS_KERNING } +function FT_HAS_KERNING(face : FT_Face ) : cbool; +begin + result := cbool(face.face_flags and FT_FACE_FLAG_KERNING ); +end; + +end. + -- cgit v1.2.3 From 4d14de6c0a2ddcc6729afae5d446e653b8692d83 Mon Sep 17 00:00:00 2001 From: tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Sat, 18 Oct 2008 10:59:26 +0000 Subject: removed unneeded files git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1450 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/demo/Kopie von UFreeType.pas | 326 -------------------------- src/lib/freetype/demo/Kopie von lesson43.dpr | 289 ----------------------- 2 files changed, 615 deletions(-) delete mode 100644 src/lib/freetype/demo/Kopie von UFreeType.pas delete mode 100644 src/lib/freetype/demo/Kopie von lesson43.dpr (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/demo/Kopie von UFreeType.pas b/src/lib/freetype/demo/Kopie von UFreeType.pas deleted file mode 100644 index c1243aae..00000000 --- a/src/lib/freetype/demo/Kopie von UFreeType.pas +++ /dev/null @@ -1,326 +0,0 @@ -unit UFreeType; - -{$IFDEF FPC} - {$mode delphi}{$H+} -{$ENDIF} - -interface - -uses - FreeType, - gl, - glu, - classes, - sysutils; - -type - // This holds all of the information related to any - // freetype font that we want to create. - TFontData = class - h: single; ///< Holds the height of the font. - textures: array of GLuint; ///< Holds the texture id's - list_base: GLuint; ///< Holds the first display list id - - // The init function will create a font of - // of the height h from the file fname. - constructor Create(const fname: string; h: cardinal); - - // Free all the resources assosiated with the font. - destructor Destroy(); override; - end; - - TFreeType = class - public - // The flagship function of the library - this thing will print - // out text at window coordinates x,y, using the font ft_font. - // The current modelview matrix will also be applied to the text. - class procedure print(ft_font: TFontData; x, y: single; const str: string); - end; - - -implementation - - -// This function gets the first power of 2 >= the -// int that we pass it. -function next_p2 ( a: integer ): integer; inline; -begin - Result := 1; - while (Result < a) do - Result := Result shl 1; -end; - -type - PAGLuint = ^AGLuint; - AGLuint = array[0..High(Word)] of GLuint; - -// Create a display list coresponding to the given character. -procedure make_dlist ( face: FT_Face; ch: byte; list_base: GLuint; tex_base: PAGLuint ); -var - i, j: integer; - width, height: integer; - glyph: FT_Glyph; - bitmap_glyph: FT_BitmapGlyph; - bitmap: PFT_Bitmap; - expanded_data: array of GLubyte; - x, y: single; -begin - // The first thing we do is get FreeType to render our character - // into a bitmap. This actually requires a couple of FreeType commands: - - // Load the Glyph for our character. - if (FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ) <> 0) then - raise Exception.create('FT_Load_Glyph failed'); - - // Move the face's glyph into a Glyph object. - if (FT_Get_Glyph( face^.glyph, glyph ) <> 0) then - raise Exception.create('FT_Get_Glyph failed'); - - // Convert the glyph to a bitmap. - FT_Glyph_To_Bitmap( glyph, ft_render_mode_normal, nil, 1 ); - bitmap_glyph := FT_BitmapGlyph(glyph); - - // This reference will make accessing the bitmap easier - bitmap := @bitmap_glyph^.bitmap; - - // Use our helper function to get the widths of - // the bitmap data that we will need in order to create - // our texture. - width := next_p2( bitmap.width ); - height := next_p2( bitmap.rows ); - - // Allocate memory for the texture data. - SetLength(expanded_data, 2 * width * height); - - // Here we fill in the data for the expanded bitmap. - // Notice that we are using two channel bitmap (one for - // luminocity and one for alpha), but we assign - // both luminocity and alpha to the value that we - // find in the FreeType bitmap. - // We use the ?: operator so that value which we use - // will be 0 if we are in the padding zone, and whatever - // is the the Freetype bitmap otherwise. - for j := 0 to height-1 do - begin - for i := 0 to width-1 do - begin - if ((i >= bitmap.width) or (j >= bitmap.rows)) then - expanded_data[2*(i+j*width)] := 0 - else - expanded_data[2*(i+j*width)] := byte(bitmap.buffer[i + bitmap.width*j]); - expanded_data[2*(i+j*width)+1] := expanded_data[2*(i+j*width)]; - end; - end; - - - // Now we just setup some texture paramaters. - glBindTexture( GL_TEXTURE_2D, tex_base[integer(ch)]); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - - // Here we actually create the texture itself, notice - // that we are using GL_LUMINANCE_ALPHA to indicate that - // we are using 2 channel data. - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, - 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, @expanded_data[0] ); - - //With the texture created, we don't need to expanded data anymore - SetLength(expanded_data, 0); - - //So now we can create the display list - glNewList(list_base+ch, GL_COMPILE); - - glBindTexture(GL_TEXTURE_2D, tex_base[ch]); - - glPushMatrix(); - - //first we need to move over a little so that - //the character has the right amount of space - //between it and the one before it. - glTranslatef(bitmap_glyph^.left, 0, 0); - - //Now we move down a little in the case that the - //bitmap extends past the bottom of the line - //(this is only true for characters like 'g' or 'y'. - glTranslatef(0, bitmap_glyph^.top - bitmap.rows, 0); - - //Now we need to account for the fact that many of - //our textures are filled with empty padding space. - //We figure what portion of the texture is used by - //the actual character and store that information in - //the x and y variables, then when we draw the - //quad, we will only reference the parts of the texture - //that we contain the character itself. - x := bitmap.width / width; - y := bitmap.rows / height; - - //Here we draw the texturemaped quads. - //The bitmap that we got from FreeType was not - //oriented quite like we would like it to be, - //so we need to link the texture to the quad - //so that the result will be properly aligned. - glBegin(GL_QUADS); - glTexCoord2d(0, 0); glVertex2f(0, bitmap.rows); - glTexCoord2d(0, y); glVertex2f(0, 0); - glTexCoord2d(x, y); glVertex2f(bitmap.width, 0); - glTexCoord2d(x, 0); glVertex2f(bitmap.width, bitmap.rows); - glEnd(); - - glPopMatrix(); - glTranslatef(face^.glyph^.advance.x shr 6, 0, 0); - - //increment the raster position as if we were a bitmap font. - //(only needed if you want to calculate text length) - //glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL); - - //Finnish the display list - glEndList(); -end; - - -constructor TFontData.Create(const fname: string; h: cardinal); -var - library_: FT_Library; - //The object in which Freetype holds information on a given - //font is called a "face". - face: FT_Face; - i: byte; -begin - //Allocate some memory to store the texture ids. - SetLength(textures, 128); - - Self.h := h; - - //Create and initilize a freetype font library. - if (FT_Init_FreeType( library_ ) <> 0) then - raise Exception.create('FT_Init_FreeType failed'); - - //This is where we load in the font information from the file. - //Of all the places where the code might die, this is the most likely, - //as FT_New_Face will die if the font file does not exist or is somehow broken. - if (FT_New_Face( library_, PChar(fname), 0, face ) <> 0) then - raise Exception.create('FT_New_Face failed (there is probably a problem with your font file)'); - - //For some twisted reason, Freetype measures font size - //in terms of 1/64ths of pixels. Thus, to make a font - //h pixels high, we need to request a size of h*64. - //(h shl 6 is just a prettier way of writting h*64) - FT_Set_Char_Size( face, h shl 6, h shl 6, 96, 96); - - //Here we ask opengl to allocate resources for - //all the textures and displays lists which we - //are about to create. - list_base := glGenLists(128); - glGenTextures( 128, @textures[0] ); - - //This is where we actually create each of the fonts display lists. - for i := 0 to 127 do - make_dlist(face, i, list_base, @textures[0]); - - //We don't need the face information now that the display - //lists have been created, so we free the assosiated resources. - FT_Done_Face(face); - - //Ditto for the library. - FT_Done_FreeType(library_); -end; - -destructor TFontData.Destroy(); -begin - glDeleteLists(list_base, 128); - glDeleteTextures(128, @textures[0]); - SetLength(textures, 0); -end; - -/// A fairly straight forward function that pushes -/// a projection matrix that will make object world -/// coordinates identical to window coordinates. -procedure pushScreenCoordinateMatrix(); inline; -var - viewport: array [0..3] of GLint; -begin - glPushAttrib(GL_TRANSFORM_BIT); - glGetIntegerv(GL_VIEWPORT, @viewport); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(viewport[0], viewport[2], viewport[1], viewport[3]); - glPopAttrib(); -end; - -/// Pops the projection matrix without changing the current -/// MatrixMode. -procedure pop_projection_matrix(); inline; -begin - glPushAttrib(GL_TRANSFORM_BIT); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPopAttrib(); -end; - -///Much like Nehe's glPrint function, but modified to work -///with freetype fonts. -class procedure TFreeType.print(ft_font: TFontData; x, y: single; const str: string); -var - font: GLuint; - h: single; - i: cardinal; - lines: TStringList; - modelview_matrix: array[0..15] of single; -begin - // We want a coordinate system where things coresponding to window pixels. - pushScreenCoordinateMatrix(); - - font := ft_font.list_base; - h := ft_font.h / 0.63; //We make the height about 1.5* that of - - lines := TStringList.Create(); - ExtractStrings([#13], [], PChar(str), lines); - - glPushAttrib(GL_LIST_BIT or GL_CURRENT_BIT or GL_ENABLE_BIT or GL_TRANSFORM_BIT); - glMatrixMode(GL_MODELVIEW); - glDisable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glListBase(font); - - glGetFloatv(GL_MODELVIEW_MATRIX, @modelview_matrix); - - //This is where the text display actually happens. - //For each line of text we reset the modelview matrix - //so that the line's text will start in the correct position. - //Notice that we need to reset the matrix, rather than just translating - //down by h. This is because when each character is - //draw it modifies the current matrix so that the next character - //will be drawn immediatly after it. - for i := 0 to lines.Count-1 do - begin - glPushMatrix(); - glLoadIdentity(); - glTranslatef(x, y - h*i, 0); - glMultMatrixf(@modelview_matrix); - - // The commented out raster position stuff can be useful if you need to - // know the length of the text that you are creating. - // If you decide to use it make sure to also uncomment the glBitmap command - // in make_dlist(). - //glRasterPos2f(0,0); - glCallLists(Length(lines[i]), GL_UNSIGNED_BYTE, PChar(lines[i])); - //float rpos[4]; - //glGetFloatv(GL_CURRENT_RASTER_POSITION ,rpos); - //float len=x-rpos[0]; - - glPopMatrix(); - end; - - glPopAttrib(); - - pop_projection_matrix(); - - lines.Free(); -end; - -end. diff --git a/src/lib/freetype/demo/Kopie von lesson43.dpr b/src/lib/freetype/demo/Kopie von lesson43.dpr deleted file mode 100644 index b49423fb..00000000 --- a/src/lib/freetype/demo/Kopie von lesson43.dpr +++ /dev/null @@ -1,289 +0,0 @@ -program lesson43; -(* - * This code was created by Jeff Molofee '99 - * (ported to Linux/SDL by Ti Leggett '01) - * - * If you've found this code useful, please let me know. - * - * Visit Jeff at http://nehe.gamedev.net/ - * - * or for port-specific comments, questions, bugreports etc. - * email to leggett@eecs.tulane.edu - *) - -{$IFDEF FPC} - {$mode delphi}{$H+} -{$ENDIF} - -{$APPTYPE Console} - -uses - moduleloader in '../../JEDI-SDL/SDL/Pas/moduleloader.pas', - SDL in '../../JEDI-SDL/SDL/Pas/sdl.pas', - gl in '../../JEDI-SDL/OpenGL/Pas/gl.pas', - glu in '../../JEDI-SDL/OpenGL/Pas/glu.pas', - ctypes in '../../ctypes/ctypes.pas', - FreeType in '../freetype.pas', - UFreeType in 'UFreeType.pas', - math, - sysutils; - -const - // screen width, height, and bit depth - SCREEN_WIDTH = 640; - SCREEN_HEIGHT = 480; - SCREEN_BPP = 16; - -var - our_font: TFontData; - // This is our SDL surface - surface: PSDL_Surface; - cnt1, cnt2: GLfloat; - -(* function to release/destroy our resources and restoring the old desktop *) -procedure Quit(returnCode: integer); -begin - // clean up the window - SDL_Quit( ); - - // and exit appropriately - Halt( returnCode ); -end; - -(* function to reset our viewport after a window resize *) -function resizeWindow(width: integer; height: integer): boolean; -var - // Height / width ration - ratio: GLfloat; -begin - // Protect against a divide by zero - if ( height = 0 ) then - height := 1; - - ratio := width / height; - - // Setup our viewport. - glViewport( 0, 0, GLsizei(width), GLsizei(height) ); - - // change to the projection matrix and set our viewing volume. - glMatrixMode( GL_PROJECTION ); - glLoadIdentity( ); - - // Set our perspective - gluPerspective( 45.0, ratio, 0.1, 100.0 ); - - // Make sure we're chaning the model view and not the projection - glMatrixMode( GL_MODELVIEW ); - - // Reset The View - glLoadIdentity( ); - - Result := true; -end; - -(* function to handle key press events *) -procedure handleKeyPress(keysym: PSDL_keysym); -begin - case ( keysym^.sym ) of - SDLK_ESCAPE: - begin - // ESC key was pressed - Quit( 0 ); - end; - SDLK_F1: - begin - // F1 key was pressed - // this toggles fullscreen mode - SDL_WM_ToggleFullScreen( surface ); - end; - end; -end; - -(* general OpenGL initialization function *) -function initGL(): boolean; -begin - // Enable smooth shading - glShadeModel( GL_SMOOTH ); - - // Set the background black - glClearColor( 0.0, 0.0, 0.0, 0.0 ); - - // Depth buffer setup - glClearDepth( 1.0 ); - - // Enables Depth Testing - glEnable( GL_DEPTH_TEST ); - - // The Type Of Depth Test To Do - glDepthFunc( GL_LEQUAL ); - - // Really Nice Perspective Calculations - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); - - our_font := TFontData.Create('Test.ttf', 16); - - Result := true; -end; - -(* Here goes our drawing code *) -function drawGLScene(): boolean; -begin - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer - glLoadIdentity(); // Reset The Current Modelview Matrix - glTranslatef(0.0, 0.0, -1.0); // Move One Unit Into The Screen - - // Blue Text - glColor3ub(0, 0, $ff); - - // Position The WGL Text On The Screen - glRasterPos2f(-0.40, 0.35); - - // Here We Print Some Text Using Our FreeType Font - // The only really important command is the actual print() call, - // but for the sake of making the results a bit more interesting - // I have put in some code to rotate and scale the text. - - // Red text - glColor3ub($ff, 0, 0); - - glPushMatrix(); - glLoadIdentity(); - glRotatef(cnt1, 0, 0,1); - glScalef(1, 0.8 + 0.3*cos(cnt1/5) ,1); - glTranslatef(-180, 0, 0); - TFreeType.print(our_font, 320, 240, 'Active FreeType Text - ' + FloatToStr(cnt1)); - glPopMatrix(); - - //Uncomment this to test out print's ability to handle newlines. - //TFreeType.print(our_font, 320, 200, 'Here'#13'there'#13'be'#13#13'newlines'#13'.'); - - cnt1 := cnt1 + 0.051; // Increase The First Counter - cnt2 := cnt2 + 0.005; // Increase The First Counter - - SDL_GL_SwapBuffers( ); - - Result := true; -end; - -var - // Flags to pass to SDL_SetVideoMode - videoFlags: integer; - // main loop variable - done: boolean = false; - // used to collect events - event: TSDL_Event; - // this holds some info about our display - videoInfo: PSDL_VideoInfo; - // whether or not the window is active - isActive: boolean = true; - -begin - // initialize SDL - if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) then - begin - writeln( ErrOutput, 'Video initialization failed: ' + SDL_GetError() ); - Quit( 1 ); - end; - - // Fetch the video info - videoInfo := SDL_GetVideoInfo( ); - - if ( videoInfo = nil ) then - begin - writeln( ErrOutput, 'Video query failed: ' + SDL_GetError() ); - Quit( 1 ); - end; - - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Enable double buffering - - // the flags to pass to SDL_SetVideoMode - videoFlags := SDL_OPENGL; // Enable OpenGL in SDL - videoFlags := videoFlags or SDL_HWPALETTE; // Store the palette in hardware - videoFlags := videoFlags or SDL_RESIZABLE; // Enable window resizing - - // This checks to see if surfaces can be stored in memory - if ( videoInfo^.hw_available <> 0 ) then - videoFlags := videoFlags or SDL_HWSURFACE - else - videoFlags := videoFlags or SDL_SWSURFACE; - - // This checks if hardware blits can be done - if ( videoInfo^.blit_hw <> 0 ) then - videoFlags := videoFlags or SDL_HWACCEL; - - // Sets up OpenGL double buffering - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - - // get a SDL surface - surface := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, - videoFlags ); - - // Verify there is a surface - if ( surface = nil ) then - begin - writeln( ErrOutput, 'Video mode set failed: ' + SDL_GetError() ); - Quit( 1 ); - end; - - // initialize OpenGL - initGL(); - - // resize the initial window - resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); - - // wait for events - while ( not done ) do - begin - { handle the events in the queue } - - while ( SDL_PollEvent( @event ) <> 0 ) do - begin - case( event.type_ ) of - SDL_ACTIVEEVENT: - begin - // Something's happend with our focus - // If we are iconified, we shouldn't draw the screen - if ( (event.active.state and SDL_APPACTIVE) <> 0 ) then - begin - if ( event.active.gain = 0 ) then - isActive := false - else - isActive := true; - end; - end; - SDL_VIDEORESIZE: - begin - // handle resize event - {$IFDEF UNIX} - surface := SDL_SetVideoMode( event.resize.w, - event.resize.h, - 16, videoFlags ); - if ( surface = nil ) then - begin - writeln( ErrOutput, 'Could not get a surface after resize: ' + SDL_GetError( ) ); - Quit( 1 ); - end; - {$ENDIF} - resizeWindow( event.resize.w, event.resize.h ); - end; - SDL_KEYDOWN: - begin - // handle key presses - handleKeyPress( @event.key.keysym ); - end; - SDL_QUITEV: - begin - // handle quit requests - done := true; - end; - end; - end; - - // draw the scene - if ( isActive ) then - drawGLScene( ); - end; - - // clean ourselves up and exit - Quit( 0 ); -end. -- cgit v1.2.3 From d6770dd47dcb871f021868dec2b333527ffb8ee8 Mon Sep 17 00:00:00 2001 From: tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Sun, 26 Oct 2008 11:54:33 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1479 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/demo/UFont.pas | 2641 --------------------------- src/lib/freetype/demo/engine-test.bdsproj | 175 ++ src/lib/freetype/demo/engine-test.dpr | 336 ++++ src/lib/freetype/demo/engine-test.lpi | 173 ++ src/lib/freetype/demo/lesson43.bdsproj | 175 -- src/lib/freetype/demo/lesson43.dpr | 366 ---- src/lib/freetype/demo/lesson43.lpi | 272 --- src/lib/freetype/demo/nehe/UFreeType.pas | 326 ++++ src/lib/freetype/demo/nehe/lesson43.bdsproj | 175 ++ src/lib/freetype/demo/nehe/lesson43.dpr | 289 +++ src/lib/freetype/demo/nehe/readme.txt | 9 + src/lib/freetype/demo/switches.inc | 1 + 12 files changed, 1484 insertions(+), 3454 deletions(-) delete mode 100644 src/lib/freetype/demo/UFont.pas create mode 100644 src/lib/freetype/demo/engine-test.bdsproj create mode 100644 src/lib/freetype/demo/engine-test.dpr create mode 100644 src/lib/freetype/demo/engine-test.lpi delete mode 100644 src/lib/freetype/demo/lesson43.bdsproj delete mode 100644 src/lib/freetype/demo/lesson43.dpr delete mode 100644 src/lib/freetype/demo/lesson43.lpi create mode 100644 src/lib/freetype/demo/nehe/UFreeType.pas create mode 100644 src/lib/freetype/demo/nehe/lesson43.bdsproj create mode 100644 src/lib/freetype/demo/nehe/lesson43.dpr create mode 100644 src/lib/freetype/demo/nehe/readme.txt create mode 100644 src/lib/freetype/demo/switches.inc (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/demo/UFont.pas b/src/lib/freetype/demo/UFont.pas deleted file mode 100644 index c15ff4ca..00000000 --- a/src/lib/freetype/demo/UFont.pas +++ /dev/null @@ -1,2641 +0,0 @@ -unit UFont; - -{$IFDEF FPC} - {$mode delphi}{$H+} -{$ENDIF} - -{$DEFINE HasInline} - -interface - -// Flip direction of y-axis. -// Default is a cartesian coordinate system with y-axis in upper direction -// but with USDX the y-axis is in lower direction. -{.$DEFINE FLIP_YAXIS} -{.$DEFINE BITMAP_FONT} - -uses - FreeType, - gl, - glext, - glu, - sdl, - {$IFDEF BITMAP_FONT} - UTexture, - {$ENDIF} - Math, - Classes, - SysUtils; - -type - - PGLubyteArray = ^TGLubyteArray; - TGLubyteArray = array[0 .. (MaxInt div SizeOf(GLubyte))-1] of GLubyte; - TGLubyteDynArray = array of GLubyte; - - TWideStringArray = array of WideString; - - TGLColor = packed record - case byte of - 0: ( vals: array[0..3] of GLfloat; ); - 1: ( r, g, b, a: GLfloat; ); - end; - - TBoundsDbl = record - Left, Right: double; - Bottom, Top: double; - end; - - TPositionDbl = record - X, Y: double; - end; - - TTextureSize = record - Width, Height: integer; - end; - - TBitmapCoords = record - Left, Top: double; - Width, Height: integer; - end; - - {** - * Abstract base class representing a glyph. - *} - TGlyph = class - protected - function GetAdvance(): TPositionDbl; virtual; abstract; - function GetBounds(): TBoundsDbl; virtual; abstract; - public - procedure Render(UseDisplayLists: boolean); virtual; abstract; - procedure RenderReflection(); virtual; abstract; - - {** Distance to next glyph (in pixels) *} - property Advance: TPositionDbl read GetAdvance; - {** Glyph bounding box (in pixels) *} - property Bounds: TBoundsDbl read GetBounds; - end; - - {** - * Font styles used by TFont.Style - *} - TFontStyle = set of (Italic, Underline, Reflect); - - {** - * Base font class. - *} - TFont = class - private - {** Non-virtual reset-method used in Create() and Reset() *} - procedure ResetIntern(); - - protected - fStyle: TFontStyle; - fUseKerning: boolean; - fLineSpacing: single; // must be inited by subclass - fReflectionSpacing: single; // must be inited by subclass to -2*Descender - fGlyphSpacing: single; - fReflectionPass: boolean; - - {** - * Splits lines in Text seperated by newline (char-code #13). - * @param Text: UTF-8 encoded string - * @param Lines: splitted WideString lines - *} - procedure SplitLines(const Text: UTF8String; var Lines: TWideStringArray); - - {** - * Print an array of WideStrings. Each array-item is a line of text. - * Lines of text are seperated by the line-spacing. - * This is the base function for all text drawing. - *} - procedure Print(const Text: TWideStringArray); overload; virtual; - - {** - * Draws an underline. - *} - procedure DrawUnderline(const Text: WideString); virtual; - - {** - * Renders (one) line of text. - *} - procedure Render(const Text: WideString); virtual; abstract; - - {** - * Returns the bounds of text-lines contained in Text. - * @param Advance: if true the right bound is set to the advance instead - * of the minimal right bound. - *} - function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; overload; virtual; abstract; - - {** - * Resets all user settings to default values. - * Override methods should always call the inherited version. - *} - procedure Reset(); virtual; - - function GetHeight(): single; virtual; abstract; - function GetAscender(): single; virtual; abstract; - function GetDescender(): single; virtual; abstract; - procedure SetLineSpacing(Spacing: single); virtual; - function GetLineSpacing(): single; virtual; - procedure SetGlyphSpacing(Spacing: single); virtual; - function GetGlyphSpacing(): single; virtual; - procedure SetReflectionSpacing(Spacing: single); virtual; - function GetReflectionSpacing(): single; virtual; - procedure SetStyle(Style: TFontStyle); virtual; - function GetStyle(): TFontStyle; virtual; - function GetUnderlinePosition(): single; virtual; abstract; - function GetUnderlineThickness(): single; virtual; abstract; - procedure SetUseKerning(Enable: boolean); virtual; - function GetUseKerning(): boolean; virtual; - procedure SetReflectionPass(Enable: boolean); virtual; - - {** Returns true if the current render-pass is used to draw the reflection *} - property ReflectionPass: boolean read fReflectionPass write SetReflectionPass; - - public - constructor Create(); - destructor Destroy(); override; - - {** - * Prints a text. - *} - procedure Print(const Text: WideString); overload; - {** UTF-8 version of @link Print(const Text: WideString) *} - procedure Print(const Text: string); overload; - - {** - * Calculates the bounding box (width and height) around Text. - * Works with Italic and Underline styles but reflections created - * with the Reflect style are not considered. - * Note that the width might differ due to kerning with appended text, - * e.g. Width('VA') <= Width('V') + Width('A'). - * @param Advance: if set to true, Result.Right is set to the advance of - * the given text rather than the min. right border. The advance width is - * bigger than the text's width as it additionally contains the advance - * and glyph-spacing of the last character. - *} - function BBox(const Text: WideString; Advance: boolean = false): TBoundsDbl; overload; - {** UTF-8 version of @link BBox(const Text: WideString) *} - function BBox(const Text: UTF8String; Advance: boolean = false): TBoundsDbl; overload; - - {** Font height *} - property Height: single read GetHeight; - {** Vertical distance from baseline to top of glyph *} - property Ascender: single read GetAscender; - {** Vertical distance from baseline to bottom of glyph *} - property Descender: single read GetDescender; - {** Vertical distance between two baselines *} - property LineSpacing: single read GetLineSpacing write SetLineSpacing; - {** Space between end and start of next glyph added to the advance width *} - property GlyphSpacing: single read GetGlyphSpacing write SetGlyphSpacing; - {** Distance between normal baseline and baseline of the reflection *} - property ReflectionSpacing: single read GetReflectionSpacing write SetReflectionSpacing; - {** Font style (italic/underline/...) *} - property Style: TFontStyle read GetStyle write SetStyle; - {** If set to true (default) kerning will be used if available *} - property UseKerning: boolean read GetUseKerning write SetUseKerning; - end; - -const - // max. number of mipmap levels that a TScalableFont can contain - cMaxMipmapLevel = 5; - -type - {** - * Wrapper around TFont to allow font size changes. - * The font is scaled to the requested size by a modelview matrix - * transformation (glScale) and not by rescaling the internal bitmap - * representation. This way changing the size is really fast but the result - * may lack quality on large or small scale factors. - *} - TScalableFont = class(TFont) - private - procedure ResetIntern(); - - protected - fScale: single; ///< current height to base-font height ratio - fAspect: single; ///< width to height aspect - fBaseFont: TFont; ///< shortcut for fMipmapFonts[0] - fUseMipmaps: boolean; ///< true if mipmap fonts are generated - /// Mipmap fonts (size[level+1] = size[level]/2) - fMipmapFonts: array[0..cMaxMipmapLevel] of TFont; - - procedure Render(const Text: WideString); override; - procedure Print(const Text: TWideStringArray); override; - function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; - - {** - * Callback called for creation of each mipmap font. - * Must be defined by the subclass. - * Mipmaps created by this method are managed and freed by TScalableFont. - *} - function CreateMipmap(Level: integer; Scale: single): TFont; virtual; abstract; - - {** - * Returns the mipmap level considering the current scale and projection - * matrix. - *} - function GetMipmapLevel(): integer; - - {** - * Returns the scale applied to the given mipmap font. - * fScale * fBaseFont.Height / fMipmapFont[Level].Height - *} - function GetMipmapScale(Level: integer): single; - - {** - * Chooses the mipmap that looks nicest with current scale and projection - * matrix. - *} - function ChooseMipmapFont(): TFont; - - procedure SetHeight(Height: single); virtual; - function GetHeight(): single; override; - procedure SetAspect(Aspect: single); virtual; - function GetAspect(): single; virtual; - function GetAscender(): single; override; - function GetDescender(): single; override; - procedure SetLineSpacing(Spacing: single); override; - function GetLineSpacing(): single; override; - procedure SetGlyphSpacing(Spacing: single); override; - function GetGlyphSpacing(): single; override; - procedure SetReflectionSpacing(Spacing: single); override; - function GetReflectionSpacing(): single; override; - procedure SetStyle(Style: TFontStyle); override; - function GetStyle(): TFontStyle; override; - function GetUnderlinePosition(): single; override; - function GetUnderlineThickness(): single; override; - procedure SetUseKerning(Enable: boolean); override; - - public - {** - * Creates a wrapper to make the base-font Font scalable. - * If UseMipmaps is set to true smaller fonts are created so that a - * resized (Height property changed) font looks nicer. - * The font passed is managed and freed by TScalableFont. - *} - constructor Create(Font: TFont; UseMipmaps: boolean); overload; - - {** - * Frees memory. The fonts passed on Create() and mipmap creation - * are freed too. - *} - destructor Destroy(); override; - - {** @see TFont.Reset *} - procedure Reset(); override; - - {** Font height *} - property Height: single read GetHeight write SetHeight; - {** Factor for font stretching (NewWidth = Width*Aspect), 1.0 by default *} - property Aspect: single read GetAspect write SetAspect; - end; - - {** - * Table for storage of max. 256 glyphs. - * Used for the second cache level. Indexed by the LSB of the WideChar - * char-code. - *} - PGlyphTable = ^TGlyphTable; - TGlyphTable = array[0..255] of TGlyph; - - {** - * Cache for glyphs of a single font. - * The cached glyphs are stored inside a hash-list. - * Hashing is performed in two steps: - * 1. the least significant byte (LSB) of the WideChar character code - * is removed (shr 8) and the result (we call it BaseCode here) looked up in - * the hash-list. - * 2. Each entry of the hash-list contains a table with max. 256 entries. - * The LSB of the char-code of a glyph is the table-offset of that glyph. - *} - TGlyphCache = class - private - fHash: TList; - - {** - * Finds a glyph-table storing cached glyphs with base-code BaseCode - * (= upper char-code bytes) in the hash-list and returns the table and - * its index. - * @param InsertPos: the position of the tyble in the list if it was found, - * otherwise the position the table should be inserted - *} - function FindGlyphTable(BaseCode: cardinal; out InsertPos: integer): PGlyphTable; - - public - constructor Create(); - destructor Destroy(); override; - - {** - * Add glyph Glyph with char-code ch to the cache. - * @returns @true on success, @false otherwise - *} - function AddGlyph(ch: WideChar; const Glyph: TGlyph): boolean; - - {** - * Removes the glyph with char-code ch from the cache. - *} - procedure DeleteGlyph(ch: WideChar); - - {** - * Removes the glyph with char-code ch from the cache. - *} - function GetGlyph(ch: WideChar): TGlyph; - - {** - * Checks if a glyph with char-code ch is cached. - *} - function HasGlyph(ch: WideChar): boolean; - - {** - * Remove and free all cached glyphs. If KeepBaseSet is set to - * true, cached characters in the range 0..255 will not be flushed. - *} - procedure FlushCache(KeepBaseSet: boolean); - end; - - {** - * Entry of a glyph-cache's (TGlyphCache) hash. - * Stores a BaseCode (upper-bytes of a glyph's char-code) and a table - * with all glyphs cached at the moment with that BaseCode. - *} - TGlyphCacheHashEntry = class - private - fBaseCode: cardinal; - public - GlyphTable: TGlyphTable; - - constructor Create(BaseCode: cardinal); - - {** Base-code (upper-bytes) of the glyphs stored in this entry's table *} - property BaseCode: cardinal read fBaseCode; - end; - - TCachedFont = class(TFont) - protected - fCache: TGlyphCache; - - {** - * Retrieves a cached glyph with char-code ch from cache. - * If the glyph is not already cached, it is loaded with LoadGlyph(). - *} - function GetGlyph(ch: WideChar): TGlyph; - - {** - * Callback to create (load) a glyph with char-code ch. - * Implemented by subclasses. - *} - function LoadGlyph(ch: WideChar): TGlyph; virtual; abstract; - - public - constructor Create(); - destructor Destroy(); override; - - {** - * Remove and free all cached glyphs. If KeepBaseSet is set to - * true, the base glyphs are not be flushed. - * @see TGlyphCache.FlushCache - *} - procedure FlushCache(KeepBaseSet: boolean); - end; - - TFTFont = class; - - {** - * Freetype glyph. - * Each glyph stores a texture with the glyph's image. - *} - TFTGlyph = class(TGlyph) - private - fCharIndex: FT_UInt; ///< Freetype specific char-index (<> char-code) - fDisplayList: GLuint; ///< Display-list ID - fTexture: GLuint; ///< Texture ID - fBitmapCoords: TBitmapCoords; ///< Left/Top offset and Width/Height of the bitmap (in pixels) - fTexOffset: TPositionDbl; ///< Right and bottom texture offset for removal of power-of-2 padding - fTexSize: TTextureSize; ///< Texture size in pixels - - fFont: TFTFont; ///< Font associated with this glyph - fAdvance: TPositionDbl; ///< Advance width of this glyph - fBounds: TBoundsDbl; ///< Glyph bounds - fOutset: single; ///< Extrusion outset - - {** - * Extrudes the outline of a glyph's bitmap stored in TexBuffer with size - * fTexSize by Outset pixels. - * This is useful to create bold or outlined fonts. - * TexBuffer must be 2*Ceil(Outset) pixels higher and wider than the - * original glyph bitmap, otherwise the glyph borders cannot be extruded - * correctly. - * The bitmap must be 2* pixels wider and higher than the - * original glyph's bitmap with the latter centered in it. - *} - procedure Extrude(var TexBuffer: TGLubyteDynArray; Outset: single); - - {** - * Creates an OpenGL texture (and display list) for the glyph. - * The glyph's and bitmap's metrics are set correspondingly. - * @param LoadFlags: flags passed to FT_Load_Glyph() - * @raises Exception if the glyph could not be initialized - *} - procedure CreateTexture(LoadFlags: FT_Int32); - - protected - function GetAdvance(): TPositionDbl; override; - function GetBounds(): TBoundsDbl; override; - - public - {** - * Creates a glyph with char-code ch from font Font. - * @param LoadFlags: flags passed to FT_Load_Glyph() - *} - constructor Create(Font: TFTFont; ch: WideChar; Outset: single; - LoadFlags: FT_Int32); - destructor Destroy(); override; - - {** Renders the glyph (normal render pass) *} - procedure Render(UseDisplayLists: boolean); override; - {** Renders the glyph's reflection *} - procedure RenderReflection(); override; - - {** Freetype specific char-index (<> char-code) *} - property CharIndex: FT_UInt read fCharIndex; - end; - - {** - * Freetype font class. - *} - TFTFont = class(TCachedFont) - private - procedure ResetIntern(); - - protected - fFilename: string; ///< filename of the font-file - fSize: integer; ///< Font base size (in pixels) - fOutset: single; ///< size of outset extrusion (in pixels) - fFace: FT_Face; ///< Holds the height of the font - fLoadFlags: FT_Int32; ///< FT glpyh load-flags - fFontUnitScale: TPositionDbl; ///< FT font-units to pixel ratio - fUseDisplayLists: boolean; ///< true: use display-lists, false: direct drawing - - {** @see TCachedFont.LoadGlyph *} - function LoadGlyph(ch: WideChar): TGlyph; override; - - procedure Render(const Text: WideString); override; - function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; - - function GetHeight(): single; override; - function GetAscender(): single; override; - function GetDescender(): single; override; - function GetUnderlinePosition(): single; override; - function GetUnderlineThickness(): single; override; - - property Face: FT_Face read fFace; - - public - {** - * Creates a font of size Size (in pixels) from the file Filename. - * If Outset (in pixels) is set to a value > 0 the glyphs will be extruded - * at their borders. Use it for e.g. a bold effect. - * @param LoadFlags: flags passed to FT_Load_Glyph() - * @raises Exception if the font-file could not be loaded - *} - constructor Create(const Filename: string; - Size: integer; Outset: single = 0.0; - LoadFlags: FT_Int32 = FT_LOAD_DEFAULT); - - {** - * Frees all resources associated with the font. - *} - destructor Destroy(); override; - - {** @see TFont.Reset *} - procedure Reset(); override; - - {** Size of the base font *} - property Size: integer read fSize; - {** Outset size *} - property Outset: single read fOutset; - end; - - TFTScalableFont = class(TScalableFont) - protected - function GetOutset(): single; virtual; - function CreateMipmap(Level: integer; Scale: single): TFont; override; - - public - {** - * Creates a scalable font of size Size (in pixels) from the file Filename. - * OutsetAmount is the ratio of the glyph extrusion. - * The extrusion in pixels is Size*OutsetAmount - * (0.0 -> no extrusion, 0.1 -> 10%). - *} - constructor Create(const Filename: string; - Size: integer; OutsetAmount: single = 0.0; - UseMipmaps: boolean = true); - - {** @see TGlyphCache.FlushCache *} - procedure FlushCache(KeepBaseSet: boolean); - - {** Outset size (in pixels) of the scaled font *} - property Outset: single read GetOutset; - end; - - - {** - * Represents a freetype font with an additional outline around its glyphs. - * The outline size is passed on creation and cannot be changed later. - *} - TFTOutlineFont = class(TFont) - private - fFilename: string; - fSize: integer; - fOutset: single; - fInnerFont, fOutlineFont: TFTFont; - fOutlineColor: TGLColor; - - procedure ResetIntern(); - - protected - procedure DrawUnderline(const Text: WideString); override; - procedure Render(const Text: WideString); override; - function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; - - function GetHeight(): single; override; - function GetAscender(): single; override; - function GetDescender(): single; override; - procedure SetLineSpacing(Spacing: single); override; - procedure SetGlyphSpacing(Spacing: single); override; - procedure SetReflectionSpacing(Spacing: single); override; - procedure SetStyle(Style: TFontStyle); override; - function GetStyle(): TFontStyle; override; - function GetUnderlinePosition(): single; override; - function GetUnderlineThickness(): single; override; - procedure SetUseKerning(Enable: boolean); override; - procedure SetReflectionPass(Enable: boolean); override; - - public - constructor Create(const Filename: string; - Size: integer; Outset: single; - LoadFlags: FT_Int32 = FT_LOAD_DEFAULT); - destructor Destroy; override; - - {** Sets the color of the outline *} - procedure SetOutlineColor(r, g, b: GLfloat; a: GLfloat = 1.0); - - {** @see TGlyphCache.FlushCache *} - procedure FlushCache(KeepBaseSet: boolean); - - {** @see TFont.Reset *} - procedure Reset(); override; - - {** Size of the base font *} - property Size: integer read fSize; - {** Outset size *} - property Outset: single read fOutset; - end; - - {** - * Wrapper around TOutlineFont to allow font resizing. - * @see TScalableFont - *} - TFTScalableOutlineFont = class(TScalableFont) - protected - function GetOutset(): single; virtual; - function CreateMipmap(Level: integer; Scale: single): TFont; override; - - public - constructor Create(const Filename: string; - Size: integer; OutsetAmount: single; - UseMipmaps: boolean = true); - - {** Sets the color of the outline *} - procedure SetOutlineColor(r, g, b: GLfloat; a: GLfloat = 1.0); - - {** @see TGlyphCache.FlushCache *} - procedure FlushCache(KeepBaseSet: boolean); - - {** Outset size *} - property Outset: single read GetOutset; - end; - -{$IFDEF BITMAP_FONT} - - {** - * A bitmapped font loads it's glyphs from a bitmap and stores them in a - * texture. Unicode characters are not supported (but could be by supporting - * multiple textures each storing a subset of unicode glyphs). - * For backward compatibility only. - *} - TBitmapFont = class(TFont) - private - fTex: TTexture; - fTexSize: integer; - fBaseline: integer; - fAscender: integer; - fDescender: integer; - fWidths: array[0..255] of byte; // half widths - fOutline: integer; - fTempColor: TGLColor; ///< colours for the reflection - - procedure ResetIntern(); - - procedure RenderChar(ch: WideChar; var AdvanceX: real); - - {** - * Load font widths from an info file. - * @param InfoFile: the name of the info (.dat) file - * @raises Exception if the file is corrupted - *} - procedure LoadFontInfo(const InfoFile: string); - - protected - procedure Render(const Text: WideString); override; - function BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; override; - - function GetHeight(): single; override; - function GetAscender(): single; override; - function GetDescender(): single; override; - function GetUnderlinePosition(): single; override; - function GetUnderlineThickness(): single; override; - - public - {** - * Creates a bitmapped font from image Filename and font width info - * loaded from the corresponding file with ending .dat. - * @param Baseline: y-coord of the baseline given in cartesian coords - * (y-axis up) and from the lower edge of the glyphs bounding box - * @param Ascender: pixels from baseline to top of highest glyph - *} - constructor Create(const Filename: string; Outline: integer; - Baseline, Ascender, Descender: integer); - destructor Destroy(); override; - - {** - * Corrects font widths provided by the info file. - * NewWidth := Width * WidthMult + WidthAdd - *} - procedure CorrectWidths(WidthMult: real; WidthAdd: integer); - - {** @see TFont.Reset *} - procedure Reset(); override; - end; - -{$ENDIF BITMAP_FONT} - - TFreeType = class - public - {** - * Returns a pointer to the freetype library singleton. - * If non exists, freetype will be initialized. - * @raises Exception if initialization failed - *} - class function GetLibrary(): FT_Library; - class procedure FreeLibrary(); - end; - - -implementation - -uses Types; - -const - // shear factor used for the italic effect (bigger value -> more bending) - cShearFactor = 0.25; - cShearMatrix: array[0..15] of GLfloat = ( - 1, 0, 0, 0, - cShearFactor, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ); - cShearMatrixInv: array[0..15] of GLfloat = ( - 1, 0, 0, 0, - -cShearFactor, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ); - -var - LibraryInst: FT_Library; - -function NewGLColor(r, g, b, a: GLfloat): TGLColor; -begin - Result.r := r; - Result.g := g; - Result.b := b; - Result.a := a; -end; - -{** - * Returns the first power of 2 >= Value. - *} -function NextPowerOf2(Value: integer): integer; {$IFDEF HasInline}inline;{$ENDIF} -begin - Result := 1; - while (Result < Value) do - Result := Result shl 1; -end; - - -{* - * TFont - *} - -constructor TFont.Create(); -begin - inherited; - ResetIntern(); -end; - -destructor TFont.Destroy(); -begin - inherited; -end; - -procedure TFont.ResetIntern(); -begin - fStyle := []; - fUseKerning := true; - fGlyphSpacing := 0.0; - fReflectionPass := false; - - // must be set by subclasses - fLineSpacing := 0.0; - fReflectionSpacing := 0.0; -end; - -procedure TFont.Reset(); -begin - ResetIntern(); -end; - -procedure TFont.SplitLines(const Text: UTF8String; var Lines: TWideStringArray); -var - LineList: TStringList; - LineIndex: integer; -begin - // split lines on newline (there is no WideString version of ExtractStrings) - LineList := TStringList.Create(); - ExtractStrings([#13], [], PChar(Text), LineList); - - // create an array of WideStrins from the UTF-8 string-list - SetLength(Lines, LineList.Count); - for LineIndex := 0 to LineList.Count-1 do - Lines[LineIndex] := UTF8Decode(LineList[LineIndex]); - LineList.Free(); -end; - -function TFont.BBox(const Text: UTF8String; Advance: boolean): TBoundsDbl; -var - LineArray: TWideStringArray; -begin - SplitLines(Text, LineArray); - Result := BBox(LineArray, Advance); - SetLength(LineArray, 0); -end; - -function TFont.BBox(const Text: WideString; Advance: boolean): TBoundsDbl; -begin - Result := BBox(UTF8Encode(Text), Advance); -end; - -procedure TFont.Print(const Text: TWideStringArray); -var - LineIndex: integer; -begin - // recursively call this function to draw reflected text - if ((Reflect in Style) and not ReflectionPass) then - begin - ReflectionPass := true; - Print(Text); - ReflectionPass := false; - end; - - // store current color, enable-flags, matrix-mode - glPushAttrib(GL_CURRENT_BIT or GL_ENABLE_BIT or GL_TRANSFORM_BIT); - - // set OpenGL state - glMatrixMode(GL_MODELVIEW); - glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glEnable(GL_TEXTURE_2D); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - { - // TODO: just draw texels with alpha > 0 to avoid setting z-buffer for them? - glAlphaFunc(GL_GREATER, 0); - glEnable(GL_ALPHA_TEST); - - //TODO: Do we need depth-testing? - if (ReflectionPass) then - begin - glDepthMask(0); - glEnable(GL_DEPTH_TEST); - end; - } - - {$IFDEF FLIP_YAXIS} - glPushMatrix(); - glScalef(1, -1, 1); - {$ENDIF} - - // display text - for LineIndex := 0 to High(Text) do - begin - glPushMatrix(); - - // move to baseline - glTranslatef(0, -LineSpacing*LineIndex, 0); - - if ((Underline in Style) and not ReflectionPass) then - begin - glDisable(GL_TEXTURE_2D); - DrawUnderline(Text[LineIndex]); - glEnable(GL_TEXTURE_2D); - end; - - // draw reflection - if (ReflectionPass) then - begin - // set reflection spacing - glTranslatef(0, -ReflectionSpacing, 0); - // flip y-axis - glScalef(1, -1, 1); - end; - - // shear for italic effect - if (Italic in Style) then - glMultMatrixf(@cShearMatrix); - - // render text line - Render(Text[LineIndex]); - - glPopMatrix(); - end; - - // restore settings - {$IFDEF FLIP_YAXIS} - glPopMatrix(); - {$ENDIF} - glPopAttrib(); -end; - -procedure TFont.Print(const Text: string); -var - LineArray: TWideStringArray; -begin - SplitLines(Text, LineArray); - Print(LineArray); - SetLength(LineArray, 0); -end; - -procedure TFont.Print(const Text: WideString); -begin - Print(UTF8Encode(Text)); -end; - -procedure TFont.DrawUnderline(const Text: WideString); -var - UnderlineY1, UnderlineY2: single; - Bounds: TBoundsDbl; -begin - UnderlineY1 := GetUnderlinePosition(); - UnderlineY2 := UnderlineY1 + GetUnderlineThickness(); - Bounds := BBox(Text); - glRectf(Bounds.Left, UnderlineY1, Bounds.Right, UnderlineY2); -end; - -procedure TFont.SetStyle(Style: TFontStyle); -begin - fStyle := Style; -end; - -function TFont.GetStyle(): TFontStyle; -begin - Result := fStyle; -end; - -procedure TFont.SetLineSpacing(Spacing: single); -begin - fLineSpacing := Spacing; -end; - -function TFont.GetLineSpacing(): single; -begin - Result := fLineSpacing; -end; - -procedure TFont.SetGlyphSpacing(Spacing: single); -begin - fGlyphSpacing := Spacing; -end; - -function TFont.GetGlyphSpacing(): single; -begin - Result := fGlyphSpacing; -end; - -procedure TFont.SetReflectionSpacing(Spacing: single); -begin - fReflectionSpacing := Spacing; -end; - -function TFont.GetReflectionSpacing(): single; -begin - Result := fReflectionSpacing; -end; - -procedure TFont.SetUseKerning(Enable: boolean); -begin - fUseKerning := Enable; -end; - -function TFont.GetUseKerning(): boolean; -begin - Result := fUseKerning; -end; - -procedure TFont.SetReflectionPass(Enable: boolean); -begin - fReflectionPass := Enable; -end; - - -{* - * TScalableFont - *} - -constructor TScalableFont.Create(Font: TFont; UseMipmaps: boolean); -var - MipmapLevel: integer; -begin - inherited Create(); - - fBaseFont := Font; - fMipmapFonts[0] := Font; - fUseMipmaps := UseMipmaps; - ResetIntern(); - - // create mipmap fonts if requested - if (UseMipmaps) then - begin - for MipmapLevel := 1 to cMaxMipmapLevel do - begin - fMipmapFonts[MipmapLevel] := CreateMipmap(MipmapLevel, 1/(1 shl MipmapLevel)); - // stop if no smaller mipmap font is returned - if (fMipmapFonts[MipmapLevel] = nil) then - Break; - end; - end; -end; - -destructor TScalableFont.Destroy(); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - fMipmapFonts[Level].Free; - inherited; -end; - -procedure TScalableFont.ResetIntern(); -begin - fScale := 1.0; - fAspect := 1.0; -end; - -procedure TScalableFont.Reset(); -var - Level: integer; -begin - inherited; - ResetIntern(); - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - fMipmapFonts[Level].Reset(); -end; - -{** - * Returns the mipmap level to use with regard to the current projection - * and modelview matrix, font scale and aspect. - * - * Note: - * - for Freetype fonts, hinting and grid-fitting must be disabled, otherwise - * the glyph widths/heights ratios and advance widths of the mipmap fonts - * do not match as they are adjusted sligthly (e.g. an 'a' at size 12px has - * width 12px, but at size 6px width 8px). - * - returned mipmap-level is used for all glyphs of the current text to print. - * This is faster, much easier to handle, since we just need to create - * multiple sized fonts and select the one we need for the mipmap-level and - * it avoids that neighbored glyphs use different mipmap-level which might - * look odd because one glyph might look blurry and the other sharp. - * - * Motivation: - * We do not use OpenGL for mipmapping as the results are very bad. At least - * with automatic mipmap generation (gluBuildMipmaps) the fonts look rather - * blurry. - * Defining our own mipmaps by creating multiple textures with - * for different mimap levels is a pain, as the font size passed to freetype - * is not the size of the bitmaps created and it does not guarantee that a - * glyph bitmap of a font with font-size s/2 is half the size of the font with - * font-size s. If the bitmap size is just a single pixel bigger than the half - * we might need a texture of the next power-of-2 and the texture would not be - * half of the size of the next bigger mipmap. In addition we use a fixed one - * pixel sized border to smooth the texture (see cTexSmoothBorder) and maybe - * an outset that is added to the font, so creating a glyph mipmap that is - * exactly half the size of the next bigger one is a very difficult task. - * - * Solution: - * Use mipmap textures that are not exactly half the size of the next mipmap - * level. OpenGL does not support this (at least not without extensions). - * The trickiest task is to determine the mipmap to use by calculating the - * amount of minification that is performed in this function. - *} -function TScalableFont.GetMipmapLevel(): integer; -var - ModelMatrix, ProjMatrix: T16dArray; - WinCoords: array[0..2, 0..2] of GLdouble; - ViewPortArray: TViewPortArray; - Dist, Dist2: double; - WidthScale, HeightScale: double; -const - // width/height of square used for determining the scale - cTestSize = 10.0; - // an offset to the mipmap-level to adjust the change-over of two consecutive - // mipmap levels. If for example the bias is 0.1 and unbiased level is 1.9 - // the result level will be 2. A bias of 0.5 is equal to rounding. - // With bias=0.1 we prefer larger mipmaps over smaller ones. - cBias = 0.2; -begin - // 1. retrieve current transformation matrices for gluProject - glGetDoublev(GL_MODELVIEW_MATRIX, @ModelMatrix); - glGetDoublev(GL_PROJECTION_MATRIX, @ProjMatrix); - glGetIntegerv(GL_VIEWPORT, @ViewPortArray); - - // 2. project three of the corner points of a square with size cTestSize - // to window coordinates (the square is just a dummy for a glyph) - - // project point (x1, y1) to window corrdinates - gluProject(0, 0, 0, - ModelMatrix, ProjMatrix, ViewPortArray, - @WinCoords[0][0], @WinCoords[0][1], @WinCoords[0][2]); - // project point (x2, y1) to window corrdinates - gluProject(cTestSize, 0, 0, - ModelMatrix, ProjMatrix, ViewPortArray, - @WinCoords[1][0], @WinCoords[1][1], @WinCoords[1][2]); - // project point (x1, y2) to window corrdinates - gluProject(0, cTestSize, 0, - ModelMatrix, ProjMatrix, ViewPortArray, - @WinCoords[2][0], @WinCoords[2][1], @WinCoords[2][2]); - - // 3. Lets see how much the width and height of the square changed. - // Calculate the width and height as displayed on the screen in window - // coordinates and calculate the ratio to the original coordinates in - // modelview space so the ratio gives us the scale (minification here). - - // projected width ||(x1, y1) - (x2, y1)|| - Dist := (WinCoords[0][0] - WinCoords[1][0]); - Dist2 := (WinCoords[0][1] - WinCoords[1][1]); - WidthScale := cTestSize / Sqrt(Dist*Dist + Dist2*Dist2); - - // projected height ||(x1, y1) - (x1, y2)|| - Dist := (WinCoords[0][0] - WinCoords[2][0]); - Dist2 := (WinCoords[0][1] - WinCoords[2][1]); - HeightScale := cTestSize / Sqrt(Dist*Dist + Dist2*Dist2); - - //writeln(Format('Scale %f, %f', [WidthScale, HeightScale])); - - // 4. Now that we have got the scale, take the bigger minification scale - // and get it to a logarithmic scale as each mipmap is 1/2 the size of its - // predecessor (Mipmap_size[i] = Mipmap_size[i-1]/2). - // The result is our mipmap-level = the index of the mipmap to use. - - // Level > 0: Minification; < 0: Magnification - Result := Trunc(Log2(Max(WidthScale, HeightScale)) + cBias); - - // clamp to valid range - if (Result < 0) then - Result := 0; - if (Result > High(fMipmapFonts)) then - Result := High(fMipmapFonts); -end; - -function TScalableFont.GetMipmapScale(Level: integer): single; -begin - if (fMipmapFonts[Level] = nil) then - begin - Result := -1; - Exit; - end; - - Result := fScale * fMipmapFonts[0].Height / fMipmapFonts[Level].Height; -end; - -{** - * Returns the correct mipmap font for the current scale and projection - * matrix. The modelview scale is adjusted to the mipmap level, so - * Result.Print() will display the font in the correct size. - *} -function TScalableFont.ChooseMipmapFont(): TFont; -var - DesiredLevel: integer; - Level: integer; - MipmapScale: single; -begin - Result := nil; - DesiredLevel := GetMipmapLevel(); - - // get the smallest mipmap available for the desired level - // as not all levels must be assigned to a font. - for Level := DesiredLevel downto 0 do - begin - if (fMipmapFonts[Level] <> nil) then - begin - Result := fMipmapFonts[Level]; - Break; - end; - end; - - // since the mipmap font (if level > 0) is smaller than the base-font - // we have to scale to get its size right. - MipmapScale := fMipmapFonts[0].Height/Result.Height; - glScalef(MipmapScale, MipmapScale, 0); -end; - -procedure TScalableFont.Print(const Text: TWideStringArray); -begin - glPushMatrix(); - glScalef(fScale * fAspect, fScale, 0); - if (fUseMipmaps) then - ChooseMipmapFont().Print(Text) - else - fBaseFont.Print(Text); - glPopMatrix(); -end; - -procedure TScalableFont.Render(const Text: WideString); -begin - Assert(false, 'Unused TScalableFont.Render() was called'); -end; - -function TScalableFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; -begin - Result := fBaseFont.BBox(Text, Advance); - Result.Left := Result.Left * fScale; - Result.Right := Result.Right * fScale; - Result.Top := Result.Top * fScale; - Result.Bottom := Result.Bottom * fScale; -end; - -procedure TScalableFont.SetHeight(Height: single); -begin - fScale := Height / fBaseFont.GetHeight(); -end; - -function TScalableFont.GetHeight(): single; -begin - Result := fBaseFont.GetHeight() * fScale; -end; - -procedure TScalableFont.SetAspect(Aspect: single); -begin - fAspect := Aspect; -end; - -function TScalableFont.GetAspect(): single; -begin - Result := fAspect; -end; - -function TScalableFont.GetAscender(): single; -begin - Result := fBaseFont.GetAscender() * fScale; -end; - -function TScalableFont.GetDescender(): single; -begin - Result := fBaseFont.GetDescender() * fScale; -end; - -procedure TScalableFont.SetLineSpacing(Spacing: single); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - fMipmapFonts[Level].SetLineSpacing(Spacing / GetMipmapScale(Level)); -end; - -function TScalableFont.GetLineSpacing(): single; -begin - Result := fBaseFont.GetLineSpacing() * fScale; -end; - -procedure TScalableFont.SetGlyphSpacing(Spacing: single); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - fMipmapFonts[Level].SetGlyphSpacing(Spacing / GetMipmapScale(Level)); -end; - -function TScalableFont.GetGlyphSpacing(): single; -begin - Result := fBaseFont.GetGlyphSpacing() * fScale; -end; - -procedure TScalableFont.SetReflectionSpacing(Spacing: single); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - fMipmapFonts[Level].SetReflectionSpacing(Spacing / GetMipmapScale(Level)); -end; - -function TScalableFont.GetReflectionSpacing(): single; -begin - Result := fBaseFont.GetLineSpacing() * fScale; -end; - -procedure TScalableFont.SetStyle(Style: TFontStyle); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - fMipmapFonts[Level].SetStyle(Style); -end; - -function TScalableFont.GetStyle(): TFontStyle; -begin - Result := fBaseFont.GetStyle(); -end; - -function TScalableFont.GetUnderlinePosition(): single; -begin - Result := fBaseFont.GetUnderlinePosition(); -end; - -function TScalableFont.GetUnderlineThickness(): single; -begin - Result := fBaseFont.GetUnderlinePosition(); -end; - -procedure TScalableFont.SetUseKerning(Enable: boolean); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - fMipmapFonts[Level].SetUseKerning(Enable); -end; - - -{* - * TCachedFont - *} - -constructor TCachedFont.Create(); -begin - inherited; - fCache := TGlyphCache.Create(); -end; - -destructor TCachedFont.Destroy(); -begin - fCache.Free; - inherited; -end; - -function TCachedFont.GetGlyph(ch: WideChar): TGlyph; -begin - Result := fCache.GetGlyph(ch); - if (Result = nil) then - begin - Result := LoadGlyph(ch); - if (not fCache.AddGlyph(ch, Result)) then - Result.Free; - end; -end; - -procedure TCachedFont.FlushCache(KeepBaseSet: boolean); -begin - fCache.FlushCache(KeepBaseSet); -end; - - -{* - * TFTFont - *} - -constructor TFTFont.Create( - const Filename: string; - Size: integer; Outset: single; - LoadFlags: FT_Int32); -var - i: WideChar; -begin - inherited Create(); - - fFilename := Filename; - fSize := Size; - fOutset := Outset; - fLoadFlags := LoadFlags; - fUseDisplayLists := true; - - // load font information - if (FT_New_Face(TFreeType.GetLibrary(), PChar(Filename), 0, fFace) <> 0) then - raise Exception.Create('FT_New_Face: Could not load font ''' + Filename + ''''); - - // support scalable fonts only - if (not FT_IS_SCALABLE(fFace)) then - raise Exception.Create('Font is not scalable'); - - if (FT_Set_Pixel_Sizes(fFace, 0, Size) <> 0) then - raise Exception.Create('FT_Set_Pixel_Sizes failes'); - - // get scale factor for font-unit to pixel-size transformation - fFontUnitScale.X := fFace.size.metrics.x_ppem / fFace.units_per_EM; - fFontUnitScale.Y := fFace.size.metrics.y_ppem / fFace.units_per_EM; - - ResetIntern(); - - // pre-cache some commonly used glyphs (' ' - '~') - for i := #32 to #126 do - fCache.AddGlyph(i, TFTGlyph.Create(Self, i, Outset, LoadFlags)); -end; - -destructor TFTFont.Destroy(); -begin - // free face - FT_Done_Face(fFace); - inherited; -end; - -procedure TFTFont.ResetIntern(); -begin - // Note: outset and non outset fonts use same spacing - fLineSpacing := fFace.height * fFontUnitScale.Y; - fReflectionSpacing := -2*fFace.descender * fFontUnitScale.Y; -end; - -procedure TFTFont.Reset(); -begin - inherited; - ResetIntern(); -end; - -function TFTFont.LoadGlyph(ch: WideChar): TGlyph; -begin - Result := TFTGlyph.Create(Self, ch, Outset, fLoadFlags); -end; - -function TFTFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; -var - Glyph, PrevGlyph: TFTGlyph; - TextLine: WideString; - LineYOffset: single; - LineIndex, CharIndex: integer; - LineBounds: TBoundsDbl; - KernDelta: FT_Vector; - UnderlinePos: double; -begin - // Reset global bounds - Result.Left := Infinity; - Result.Right := 0; - Result.Bottom := Infinity; - Result.Top := 0; - - // reset last glyph - PrevGlyph := nil; - - // display text - for LineIndex := 0 to High(Text) do - begin - // get next text line - TextLine := Text[LineIndex]; - LineYOffset := -LineSpacing * LineIndex; - - // reset line bounds - LineBounds.Left := Infinity; - LineBounds.Right := 0; - LineBounds.Bottom := Infinity; - LineBounds.Top := 0; - - // for each glyph image, compute its bounding box - for CharIndex := 1 to Length(TextLine) do - begin - Glyph := TFTGlyph(GetGlyph(TextLine[CharIndex])); - if (Glyph <> nil) then - begin - // get kerning - if (fUseKerning and FT_HAS_KERNING(fFace) and (PrevGlyph <> nil)) then - begin - FT_Get_Kerning(fFace, PrevGlyph.CharIndex, Glyph.CharIndex, - FT_KERNING_UNSCALED, KernDelta); - LineBounds.Right := LineBounds.Right + KernDelta.x * fFontUnitScale.X; - end; - - // update left bound (must be done before right bound is updated) - if (LineBounds.Right + Glyph.Bounds.Left < LineBounds.Left) then - LineBounds.Left := LineBounds.Right + Glyph.Bounds.Left; - - // update right bound - if (CharIndex < Length(TextLine)) or // not the last character - (TextLine[CharIndex] = ' ') or // on space char (Bounds.Right = 0) - Advance then // or in advance mode - begin - // add advance and glyph spacing - LineBounds.Right := LineBounds.Right + Glyph.Advance.x + GlyphSpacing - end - else - begin - // add glyph's right bound - LineBounds.Right := LineBounds.Right + Glyph.Bounds.Right; - end; - - // update bottom and top bounds - if (Glyph.Bounds.Bottom < LineBounds.Bottom) then - LineBounds.Bottom := Glyph.Bounds.Bottom; - if (Glyph.Bounds.Top > LineBounds.Top) then - LineBounds.Top := Glyph.Bounds.Top; - end; - - PrevGlyph := Glyph; - end; - - // handle italic font style - if (Italic in Style) then - begin - LineBounds.Left := LineBounds.Left + LineBounds.Bottom * cShearFactor; - LineBounds.Right := LineBounds.Right + LineBounds.Top * cShearFactor; - end; - - // handle underlined font style - if (Underline in Style) then - begin - UnderlinePos := GetUnderlinePosition(); - if (UnderlinePos < LineBounds.Bottom) then - LineBounds.Bottom := UnderlinePos; - end; - - // add line offset - LineBounds.Bottom := LineBounds.Bottom + LineYOffset; - LineBounds.Top := LineBounds.Top + LineYOffset; - - // adjust global bounds - if (Result.Left > LineBounds.Left) then - Result.Left := LineBounds.Left; - if (Result.Right < LineBounds.Right) then - Result.Right := LineBounds.Right; - if (Result.Bottom > LineBounds.Bottom) then - Result.Bottom := LineBounds.Bottom; - if (Result.Top < LineBounds.Top) then - Result.Top := LineBounds.Top; - end; - - // if left or bottom bound was not set, set them to 0 - if (Result.Left = Infinity) then - Result.Left := 0.0; - if (Result.Bottom = Infinity) then - Result.Bottom := 0.0; -end; - -procedure TFTFont.Render(const Text: WideString); -var - CharIndex: integer; - Glyph, PrevGlyph: TFTGlyph; - KernDelta: FT_Vector; -begin - // reset last glyph - PrevGlyph := nil; - - // draw current line - for CharIndex := 1 to Length(Text) do - begin - Glyph := TFTGlyph(GetGlyph(Text[CharIndex])); - if (Assigned(Glyph)) then - begin - // get kerning - if (fUseKerning and FT_HAS_KERNING(fFace) and (PrevGlyph <> nil)) then - begin - FT_Get_Kerning(fFace, PrevGlyph.CharIndex, Glyph.CharIndex, - FT_KERNING_UNSCALED, KernDelta); - glTranslatef(KernDelta.x * fFontUnitScale.X, 0, 0); - end; - - if (ReflectionPass) then - Glyph.RenderReflection() - else - Glyph.Render(fUseDisplayLists); - - glTranslatef(Glyph.Advance.x + fGlyphSpacing, 0, 0); - end; - - PrevGlyph := Glyph; - end; -end; - -function TFTFont.GetHeight(): single; -begin - Result := Ascender - Descender; -end; - -function TFTFont.GetAscender(): single; -begin - Result := fFace.ascender * fFontUnitScale.Y + Outset*2; -end; - -function TFTFont.GetDescender(): single; -begin - // Note: outset is not part of the descender as the baseline is lifted - Result := fFace.descender * fFontUnitScale.Y; -end; - -function TFTFont.GetUnderlinePosition(): single; -begin - Result := fFace.underline_position * fFontUnitScale.Y - Outset; -end; - -function TFTFont.GetUnderlineThickness(): single; -begin - Result := fFace.underline_thickness * fFontUnitScale.Y + Outset*2; -end; - - -{* - * TFTScalableFont - *} - -constructor TFTScalableFont.Create(const Filename: string; - Size: integer; OutsetAmount: single; - UseMipmaps: boolean); -var - LoadFlags: FT_Int32; -begin - LoadFlags := FT_LOAD_DEFAULT; - // Disable hinting and grid-fitting to preserve font outlines at each font - // size, otherwise the font widths/heights do not match resulting in ugly - // text size changes during zooming. - // A drawback is a reduced quality with smaller font sizes but it is not that - // bad with gray-scaled rendering (at least it looks better than OpenGL's - // linear downscaling on minification). - if (UseMipmaps) then - LoadFlags := LoadFlags or FT_LOAD_NO_HINTING; - inherited Create( - TFTFont.Create(Filename, Size, Size * OutsetAmount, LoadFlags), - UseMipmaps); -end; - -function TFTScalableFont.CreateMipmap(Level: integer; Scale: single): TFont; -var - ScaledSize: integer; - BaseFont: TFTFont; -begin - Result := nil; - BaseFont := TFTFont(fBaseFont); - ScaledSize := Round(BaseFont.Size * Scale); - // do not create mipmap fonts < 8 pixels - if (ScaledSize < 8) then - Exit; - Result := TFTFont.Create(BaseFont.fFilename, - ScaledSize, BaseFont.fOutset * Scale, - FT_LOAD_DEFAULT or FT_LOAD_NO_HINTING); -end; - -function TFTScalableFont.GetOutset(): single; -begin - Result := TFTFont(fBaseFont).Outset * fScale; -end; - -procedure TFTScalableFont.FlushCache(KeepBaseSet: boolean); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - TFTFont(fMipmapFonts[Level]).FlushCache(KeepBaseSet); -end; - - -{* - * TOutlineFont - *} - -constructor TFTOutlineFont.Create( - const Filename: string; - Size: integer; Outset: single; - LoadFlags: FT_Int32); -begin - inherited Create(); - - fFilename := Filename; - fSize := Size; - fOutset := Outset; - - fInnerFont := TFTFont.Create(Filename, Size, 0.0, LoadFlags); - fOutlineFont := TFTFont.Create(Filename, Size, Outset, LoadFlags); - - ResetIntern(); -end; - -destructor TFTOutlineFont.Destroy; -begin - fOutlineFont.Free; - fInnerFont.Free; - inherited; -end; - -procedure TFTOutlineFont.ResetIntern(); -begin - // TODO: maybe swap fInnerFont/fOutlineFont.GlyphSpacing to use the spacing - // of the outline font? - //fInnerFont.GlyphSpacing := fOutset*2; - fOutlineFont.GlyphSpacing := -fOutset*2; - - fLineSpacing := fOutlineFont.LineSpacing; - fReflectionSpacing := fOutlineFont.ReflectionSpacing; - fOutlineColor := NewGLColor(0, 0, 0, 1); -end; - -procedure TFTOutlineFont.Reset(); -begin - inherited; - fInnerFont.Reset(); - fOutlineFont.Reset(); - ResetIntern(); -end; - -procedure TFTOutlineFont.DrawUnderline(const Text: WideString); -begin - glPushAttrib(GL_CURRENT_BIT); - glColor4fv(@fOutlineColor.vals); - fOutlineFont.DrawUnderline(Text); - glPopAttrib(); - - glPushMatrix(); - glTranslatef(fOutset, 0, 0); - fInnerFont.DrawUnderline(Text); - glPopMatrix(); -end; - -procedure TFTOutlineFont.Render(const Text: WideString); -begin - { setup and render outline font } - - // save old color - glPushAttrib(GL_CURRENT_BIT); - glColor4fv(@fOutlineColor.vals); - glPushMatrix(); - fOutlineFont.Render(Text); - glPopMatrix(); - glPopAttrib(); - - { setup and render inner font } - - glPushMatrix(); - glTranslatef(fOutset, fOutset, 0); - fInnerFont.Render(Text); - glPopMatrix(); -end; - -procedure TFTOutlineFont.SetOutlineColor(r, g, b: GLfloat; a: GLfloat); -begin - fOutlineColor := NewGLColor(r, g, b, a); -end; - -procedure TFTOutlineFont.FlushCache(KeepBaseSet: boolean); -begin - fOutlineFont.FlushCache(KeepBaseSet); - fInnerFont.FlushCache(KeepBaseSet); -end; - -function TFTOutlineFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; -begin - Result := fOutlineFont.BBox(Text, Advance); -end; - -function TFTOutlineFont.GetHeight(): single; -begin - Result := fOutlineFont.Height; -end; - -function TFTOutlineFont.GetAscender(): single; -begin - Result := fOutlineFont.Ascender; -end; - -function TFTOutlineFont.GetDescender(): single; -begin - Result := fOutlineFont.Descender; -end; - -procedure TFTOutlineFont.SetLineSpacing(Spacing: single); -begin - inherited SetLineSpacing(Spacing); - fInnerFont.LineSpacing := Spacing; - fOutlineFont.LineSpacing := Spacing; -end; - -procedure TFTOutlineFont.SetGlyphSpacing(Spacing: single); -begin - inherited SetGlyphSpacing(Spacing); - fInnerFont.GlyphSpacing := Spacing; - fOutlineFont.GlyphSpacing := Spacing - Outset*2; -end; - -procedure TFTOutlineFont.SetReflectionSpacing(Spacing: single); -begin - inherited SetReflectionSpacing(Spacing); - fInnerFont.ReflectionSpacing := Spacing; - fOutlineFont.ReflectionSpacing := Spacing; -end; - -procedure TFTOutlineFont.SetStyle(Style: TFontStyle); -begin - inherited SetStyle(Style); - fInnerFont.Style := Style; - fOutlineFont.Style := Style; -end; - -function TFTOutlineFont.GetStyle(): TFontStyle; -begin - Result := inherited GetStyle(); -end; - -function TFTOutlineFont.GetUnderlinePosition(): single; -begin - Result := fOutlineFont.GetUnderlinePosition(); -end; - -function TFTOutlineFont.GetUnderlineThickness(): single; -begin - Result := fOutlineFont.GetUnderlinePosition(); -end; - -procedure TFTOutlineFont.SetUseKerning(Enable: boolean); -begin - inherited SetUseKerning(Enable); - fInnerFont.fUseKerning := Enable; - fOutlineFont.fUseKerning := Enable; -end; - -procedure TFTOutlineFont.SetReflectionPass(Enable: boolean); -begin - inherited SetReflectionPass(Enable); - fInnerFont.fReflectionPass := Enable; - fOutlineFont.fReflectionPass := Enable; -end; - -{** - * TScalableOutlineFont - *} - -constructor TFTScalableOutlineFont.Create( - const Filename: string; - Size: integer; OutsetAmount: single; - UseMipmaps: boolean); -var - LoadFlags: FT_Int32; -begin - LoadFlags := FT_LOAD_DEFAULT; - // Disable hinting and grid-fitting (see TFTScalableFont.Create) - if (UseMipmaps) then - LoadFlags := LoadFlags or FT_LOAD_NO_HINTING; - inherited Create( - TFTOutlineFont.Create(Filename, Size, Size*OutsetAmount, LoadFlags), - UseMipmaps); -end; - -function TFTScalableOutlineFont.CreateMipmap(Level: integer; Scale: single): TFont; -var - ScaledSize: integer; - BaseFont: TFTOutlineFont; -begin - Result := nil; - BaseFont := TFTOutlineFont(fBaseFont); - ScaledSize := Round(BaseFont.Size*Scale); - // do not create mipmap fonts < 8 pixels - if (ScaledSize < 8) then - Exit; - Result := TFTOutlineFont.Create(BaseFont.fFilename, - ScaledSize, BaseFont.fOutset*Scale, - FT_LOAD_DEFAULT or FT_LOAD_NO_HINTING); -end; - -function TFTScalableOutlineFont.GetOutset(): single; -begin - Result := TFTOutlineFont(fBaseFont).Outset * fScale; -end; - -procedure TFTScalableOutlineFont.SetOutlineColor(r, g, b: GLfloat; a: GLfloat); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - TFTOutlineFont(fMipmapFonts[Level]).SetOutlineColor(r, g, b, a); -end; - -procedure TFTScalableOutlineFont.FlushCache(KeepBaseSet: boolean); -var - Level: integer; -begin - for Level := 0 to High(fMipmapFonts) do - if (fMipmapFonts[Level] <> nil) then - TFTOutlineFont(fMipmapFonts[Level]).FlushCache(KeepBaseSet); -end; - - -{* - * TFTGlyph - *} - -const - {** - * Size of the transparent border surrounding the glyph image in the texture. - * The border is necessary because OpenGL does not smooth texels at the - * border of a texture with the GL_CLAMP or GL_CLAMP_TO_EDGE styles. - * Without the border, magnified glyph textures look very ugly at their edges. - * It looks edgy, as if some pixels are missing especially on the left edge - * (just set cTexSmoothBorder to 0 to see what is meant by this). - * With the border even the glyphs edges are blended to the border (transparent) - * color and everything looks nice. - * - * Note: - * OpenGL already supports texture border by setting the border parameter - * of glTexImage*D() to 1 and using a texture size of 2^m+2b and setting the - * border pixels to the border color. In some forums it is discouraged to use - * the border parameter as only a few of the more modern graphics cards support - * this feature. On an ATI Radeon 9700 card, the slowed down to 0.5 fps and - * the glyph's background got black. So instead of using this feature we - * handle it on our own. The only drawback is that textures might get bigger - * because the border might require a higher power of 2 size instead of just - * two additional pixels. - *} - cTexSmoothBorder = 1; - -procedure TFTGlyph.Extrude(var TexBuffer: TGLubyteDynArray; Outset: single); - - procedure SetToMax(var Val1: GLubyte; Val2: GLubyte); {$IFDEF HasInline}inline;{$ENDIF} - begin - if (Val1 < Val2) then - Val1 := Val2; - end; - -var - I, X, Y: integer; - SrcBuffer,TmpBuffer: TGLubyteDynArray; - TexLine, TexLinePrev, TexLineNext: PGLubyteArray; - SrcLine: PGLubyteArray; - AlphaScale: single; - Value, ValueNeigh, ValueDiag: GLubyte; -const - // square-root of 2 used for diagonal neighbor pixels - cSqrt2 = 1.4142; - // number of ignored pixels on each edge of the bitmap. Consists of: - // - border used for font smoothing and - // - outer (extruded) bitmap pixel (because it is just written but never read) - cBorder = cTexSmoothBorder + 1; -begin - // allocate memory for temporary buffer - SetLength(SrcBuffer, Length(TexBuffer)); - FillChar(SrcBuffer[0], Length(TexBuffer), 0); - - // extrude pixel by pixel - for I := 1 to Ceil(Outset) do - begin - // swap arrays - TmpBuffer := TexBuffer; - TexBuffer := SrcBuffer; - SrcBuffer := TmpBuffer; - - // as long as we add an entire pixel of outset, use a solid color. - // If the fractional part is reached blend, e.g. outline=3.2 -> 3 solid - // pixels and one blended with alpha=0.2. - // For the fractional part I = Ceil(Outset) is always true. - if (I <= Outset) then - AlphaScale := 1 - else - AlphaScale := Outset - Trunc(Outset); - - // copy data to the expanded bitmap. - for Y := cBorder to fTexSize.Height - 2*cBorder do - begin - TexLine := @TexBuffer[Y*fTexSize.Width]; - TexLinePrev := @TexBuffer[(Y-1)*fTexSize.Width]; - TexLineNext := @TexBuffer[(Y+1)*fTexSize.Width]; - SrcLine := @SrcBuffer[Y*fTexSize.Width]; - - // expand current line's pixels - for X := cBorder to fTexSize.Width - 2*cBorder do - begin - Value := SrcLine[X]; - ValueNeigh := Round(Value * AlphaScale); - ValueDiag := Round(ValueNeigh / cSqrt2); - - SetToMax(TexLine[X], Value); - SetToMax(TexLine[X-1], ValueNeigh); - SetToMax(TexLine[X+1], ValueNeigh); - - SetToMax(TexLinePrev[X], ValueNeigh); - SetToMax(TexLinePrev[X-1], ValueDiag); - SetToMax(TexLinePrev[X+1], ValueDiag); - - SetToMax(TexLineNext[X], ValueNeigh); - SetToMax(TexLineNext[X-1], ValueDiag); - SetToMax(TexLineNext[X+1], ValueDiag); - end; - end; - end; - - TmpBuffer := nil; - SetLength(SrcBuffer, 0); -end; - -procedure TFTGlyph.CreateTexture(LoadFlags: FT_Int32); -var - X, Y: integer; - Glyph: FT_Glyph; - BitmapGlyph: FT_BitmapGlyph; - Bitmap: PFT_Bitmap; - BitmapLine: PChar; - BitmapBuffer: PChar; - TexBuffer: TGLubyteDynArray; - TexLine: PGLubyteArray; - CBox: FT_BBox; -begin - // load the Glyph for our character - if (FT_Load_Glyph(fFont.Face, fCharIndex, LoadFlags) <> 0) then - raise Exception.Create('FT_Load_Glyph failed'); - - // move the face's glyph into a Glyph object - if (FT_Get_Glyph(fFont.Face^.glyph, Glyph) <> 0) then - raise Exception.Create('FT_Get_Glyph failed'); - - // store scaled advance width/height in glyph-object - fAdvance.X := fFont.Face^.glyph^.advance.x / 64 + fOutset*2; - fAdvance.Y := fFont.Face^.glyph^.advance.y / 64 + fOutset*2; - - // get the contour's bounding box (in 1/64th pixels, not font-units) - FT_Glyph_Get_CBox(Glyph, FT_GLYPH_BBOX_UNSCALED, CBox); - // convert 1/64th values to double values - fBounds.Left := CBox.xMin / 64; - fBounds.Right := CBox.xMax / 64 + fOutset*2; - fBounds.Bottom := CBox.yMin / 64; - fBounds.Top := CBox.yMax / 64 + fOutset*2; - - // convert the glyph to a bitmap (and destroy original glyph image) - FT_Glyph_To_Bitmap(Glyph, ft_render_mode_normal, nil, 1); - BitmapGlyph := FT_BitmapGlyph(Glyph); - - // get bitmap offsets - fBitmapCoords.Left := BitmapGlyph^.left - cTexSmoothBorder; - // Note: add 1*fOutset for lifting the baseline so outset fonts to not intersect - // with the baseline; Ceil(fOutset) for the outset pixels added to the bitmap. - fBitmapCoords.Top := BitmapGlyph^.top + fOutset+Ceil(fOutset) + cTexSmoothBorder; - - // make accessing the bitmap easier - Bitmap := @BitmapGlyph^.bitmap; - // get bitmap dimensions - fBitmapCoords.Width := Bitmap.width + (Ceil(fOutset) + cTexSmoothBorder)*2; - fBitmapCoords.Height := Bitmap.rows + (Ceil(fOutset) + cTexSmoothBorder)*2; - - // get power-of-2 bitmap widths - fTexSize.Width := - NextPowerOf2(Bitmap.width + (Ceil(fOutset) + cTexSmoothBorder)*2); - fTexSize.Height := - NextPowerOf2(Bitmap.rows + (Ceil(fOutset) + cTexSmoothBorder)*2); - - // texture-widths ignoring empty (power-of-2) padding space - fTexOffset.X := fBitmapCoords.Width / fTexSize.Width; - fTexOffset.Y := fBitmapCoords.Height / fTexSize.Height; - - // allocate memory for texture data - SetLength(TexBuffer, fTexSize.Width * fTexSize.Height); - FillChar(TexBuffer[0], Length(TexBuffer), 0); - - // Freetype stores the bitmap with either upper (pitch is > 0) or lower - // (pitch < 0) glyphs line first. Set the buffer to the upper line. - // See http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-7.html - if (Bitmap.pitch > 0) then - BitmapBuffer := @Bitmap.buffer[0] - else - BitmapBuffer := @Bitmap.buffer[(Bitmap.rows-1) * Abs(Bitmap.pitch)]; - - // copy data to texture bitmap (upper line first). - for Y := 0 to Bitmap.rows-1 do - begin - // set pointer to first pixel in line that holds bitmap data. - // Each line starts with a cTexSmoothBorder pixel and multiple outset pixels - // that are added by Extrude() later. - TexLine := @TexBuffer[(Y + cTexSmoothBorder + Ceil(fOutset)) * fTexSize.Width + - cTexSmoothBorder + Ceil(fOutset)]; - // get next lower line offset, use pitch instead of width as it tells - // us the storage direction of the lines. In addition a line might be padded. - BitmapLine := @BitmapBuffer[Y * Bitmap.pitch]; - for X := 0 to Bitmap.width-1 do - TexLine[X] := GLubyte(BitmapLine[X]); - end; - - if (fOutset > 0) then - Extrude(TexBuffer, fOutset); - - // allocate resources for textures and display lists - glGenTextures(1, @fTexture); - - // setup texture paramaters - glBindTexture(GL_TEXTURE_2D, fTexture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - // create alpha-map (GL_ALPHA component only). - // TexCoord (0,0) corresponds to the top left pixel of the glyph, - // (1,1) to the bottom right pixel. So the glyph is flipped as OpenGL uses - // a cartesian (y-axis up) coordinate system for textures. - // See the cTexSmoothBorder comment for info on texture borders. - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, fTexSize.Width, fTexSize.Height, - 0, GL_ALPHA, GL_UNSIGNED_BYTE, @TexBuffer[0]); - - // free expanded data - SetLength(TexBuffer, 0); - - // create the display list - fDisplayList := glGenLists(1); - - // render to display-list - glNewList(fDisplayList, GL_COMPILE); - Render(false); - glEndList(); - - // free glyph data (bitmap, etc.) - FT_Done_Glyph(Glyph); -end; - -constructor TFTGlyph.Create(Font: TFTFont; ch: WideChar; Outset: single; - LoadFlags: FT_Int32); -begin - inherited Create(); - - fFont := Font; - fOutset := Outset; - - // get the Freetype char-index (use default UNICODE charmap) - fCharIndex := FT_Get_Char_Index(Font.fFace, FT_ULONG(ch)); - - CreateTexture(LoadFlags); -end; - -destructor TFTGlyph.Destroy; -begin - if (fDisplayList <> 0) then - glDeleteLists(fDisplayList, 1); - if (fTexture <> 0) then - glDeleteTextures(1, @fTexture); - inherited; -end; - -procedure TFTGlyph.Render(UseDisplayLists: boolean); -begin - // use display-lists if enabled and exit - if (UseDisplayLists) then - begin - glCallList(fDisplayList); - Exit; - end; - - glBindTexture(GL_TEXTURE_2D, fTexture); - glPushMatrix(); - - // move to top left glyph position - glTranslatef(fBitmapCoords.Left, fBitmapCoords.Top, 0); - - // draw glyph texture - glBegin(GL_QUADS); - // top right - glTexCoord2f(fTexOffset.X, 0); - glVertex2f(fBitmapCoords.Width, 0); - - // top left - glTexCoord2f(0, 0); - glVertex2f(0, 0); - - // bottom left - glTexCoord2f(0, fTexOffset.Y); - glVertex2f(0, -fBitmapCoords.Height); - - // bottom right - glTexCoord2f(fTexOffset.X, fTexOffset.Y); - glVertex2f(fBitmapCoords.Width, -fBitmapCoords.Height); - glEnd(); - - glPopMatrix(); -end; - -procedure TFTGlyph.RenderReflection(); -var - Color: TGLColor; - TexUpperPos: single; - TexLowerPos: single; - UpperPos: single; -const - CutOff = 0.6; -begin - glPushMatrix(); - glBindTexture(GL_TEXTURE_2D, fTexture); - glGetFloatv(GL_CURRENT_COLOR, @Color.vals); - - // add extra space to the left of the glyph - glTranslatef(fBitmapCoords.Left, 0, 0); - - // The upper position of the glyph, if CutOff is 1.0, it is fFont.Ascender. - // If CutOff is set to 0.5 only half of the glyph height is displayed. - UpperPos := fFont.Descender + fFont.Height * CutOff; - - // the glyph texture's height is just the height of the glyph but not the font - // height. Setting a color for the upper and lower bounds of the glyph results - // in different color gradients. So we have to set the color values for the - // descender and ascender (as we have a cutoff, for the upper-pos here) as - // these positions are font but not glyph specific. - - // To get the texture positions we have to enhance the texture at the top and - // bottom by the amount from the top to ascender (rather upper-pos here) and - // from the bottom (Height-Top) to descender. Then we have to convert those - // heights to texture coordinates by dividing by the bitmap Height and - // removing the power-of-2 padding space by multiplying with fTexOffset.Y - // (as fBitmapCoords.Height corresponds to fTexOffset.Y and not 1.0). - TexUpperPos := -(UpperPos - fBitmapCoords.Top) / fBitmapCoords.Height * fTexOffset.Y; - TexLowerPos := (-(fFont.Descender + fBitmapCoords.Height - fBitmapCoords.Top) / - fBitmapCoords.Height + 1) * fTexOffset.Y; - - // draw glyph texture - glBegin(GL_QUADS); - // top right - glColor4f(Color.r, Color.g, Color.b, 0); - glTexCoord2f(fTexOffset.X, TexUpperPos); - glVertex2f(fBitmapCoords.Width, UpperPos); - - // top left - glTexCoord2f(0, TexUpperPos); - glVertex2f(0, UpperPos); - - // bottom left - glColor4f(Color.r, Color.g, Color.b, Color.a-0.3); - glTexCoord2f(0, TexLowerPos); - glVertex2f(0, fFont.Descender); - - // bottom right - glTexCoord2f(fTexOffset.X, TexLowerPos); - glVertex2f(fBitmapCoords.Width, fFont.Descender); - glEnd(); - - glPopMatrix(); - - // restore old color - // Note: glPopAttrib(GL_CURRENT_BIT)/glPopAttrib() is much slower then - // glGetFloatv(GL_CURRENT_COLOR, ...)/glColor4fv(...) - glColor4fv(@Color.vals); -end; - -function TFTGlyph.GetAdvance(): TPositionDbl; -begin - Result := fAdvance; -end; - -function TFTGlyph.GetBounds(): TBoundsDbl; -begin - Result := fBounds; -end; - - -{* - * TGlyphCache - *} - -constructor TGlyphCache.Create(); -begin - inherited; - fHash := TList.Create(); -end; - -destructor TGlyphCache.Destroy(); -begin - // free cached glyphs - FlushCache(false); - - // destroy TList - fHash.Free; - - inherited; -end; - -function TGlyphCache.FindGlyphTable(BaseCode: cardinal; out InsertPos: integer): PGlyphTable; -var - I: integer; - Entry: TGlyphCacheHashEntry; -begin - Result := nil; - - for I := 0 to fHash.Count-1 do - begin - Entry := TGlyphCacheHashEntry(fHash[I]); - - if (Entry.BaseCode > BaseCode) then - begin - InsertPos := I; - Exit; - end; - - if (Entry.BaseCode = BaseCode) then - begin - InsertPos := I; - Result := @Entry.GlyphTable; - Exit; - end; - end; - - InsertPos := fHash.Count; -end; - -function TGlyphCache.AddGlyph(ch: WideChar; const Glyph: TGlyph): boolean; -var - BaseCode: cardinal; - GlyphCode: integer; - InsertPos: integer; - GlyphTable: PGlyphTable; - Entry: TGlyphCacheHashEntry; -begin - Result := false; - - BaseCode := cardinal(ch) shr 8; - GlyphTable := FindGlyphTable(BaseCode, InsertPos); - if (GlyphTable = nil) then - begin - Entry := TGlyphCacheHashEntry.Create(BaseCode); - GlyphTable := @Entry.GlyphTable; - fHash.Insert(InsertPos, Entry); - end; - - // get glyph table offset - GlyphCode := cardinal(ch) and $FF; - // insert glyph into table if not present - if (GlyphTable[GlyphCode] = nil) then - begin - GlyphTable[GlyphCode] := Glyph; - Result := true; - end; -end; - -procedure TGlyphCache.DeleteGlyph(ch: WideChar); -var - Table: PGlyphTable; - TableIndex, GlyphIndex: integer; - TableEmpty: boolean; -begin - // find table - Table := FindGlyphTable(cardinal(ch) shr 8, TableIndex); - if (Table = nil) then - Exit; - - // find glyph - GlyphIndex := cardinal(ch) and $FF; - if (Table[GlyphIndex] <> nil) then - begin - // destroy glyph - FreeAndNil(Table[GlyphIndex]); - - // check if table is empty - TableEmpty := true; - for GlyphIndex := 0 to High(Table^) do - begin - if (Table[GlyphIndex] <> nil) then - begin - TableEmpty := false; - Break; - end; - end; - - // free empty table - if (TableEmpty) then - begin - fHash.Delete(TableIndex); - end; - end; -end; - -function TGlyphCache.GetGlyph(ch: WideChar): TGlyph; -var - InsertPos: integer; - Table: PGlyphTable; -begin - Table := FindGlyphTable(cardinal(ch) shr 8, InsertPos); - if (Table = nil) then - Result := nil - else - Result := Table[cardinal(ch) and $FF]; -end; - -function TGlyphCache.HasGlyph(ch: WideChar): boolean; -begin - Result := (GetGlyph(ch) <> nil); -end; - -procedure TGlyphCache.FlushCache(KeepBaseSet: boolean); -var - EntryIndex, TableIndex: integer; - Entry: TGlyphCacheHashEntry; -begin - // destroy cached glyphs - for EntryIndex := 0 to fHash.Count-1 do - begin - Entry := TGlyphCacheHashEntry(fHash[EntryIndex]); - - // the base set (0-255) has BaseCode 0 as the upper bytes are 0. - if KeepBaseSet and (Entry.fBaseCode = 0) then - Continue; - - for TableIndex := 0 to High(Entry.GlyphTable) do - begin - if (Entry.GlyphTable[TableIndex] <> nil) then - FreeAndNil(Entry.GlyphTable[TableIndex]); - end; - FreeAndNil(Entry); - end; -end; - - -{* - * TGlyphCacheEntry - *} - -constructor TGlyphCacheHashEntry.Create(BaseCode: cardinal); -begin - inherited Create(); - fBaseCode := BaseCode; -end; - - -{* - * TFreeType - *} - -class function TFreeType.GetLibrary(): FT_Library; -begin - if (LibraryInst = nil) then - begin - // initialize freetype - if (FT_Init_FreeType(LibraryInst) <> 0) then - raise Exception.Create('FT_Init_FreeType failed'); - end; - Result := LibraryInst; -end; - -class procedure TFreeType.FreeLibrary(); -begin - if (LibraryInst <> nil) then - FT_Done_FreeType(LibraryInst); - LibraryInst := nil; -end; - - -{$IFDEF BITMAP_FONT} -{* - * TBitmapFont - *} - -constructor TBitmapFont.Create(const Filename: string; Outline: integer; - Baseline, Ascender, Descender: integer); -begin - inherited Create(); - - fTex := Texture.LoadTexture(true, Filename, TEXTURE_TYPE_TRANSPARENT, 0); - fTexSize := 1024; - fOutline := Outline; - fBaseline := Baseline; - fAscender := Ascender; - fDescender := Descender; - - LoadFontInfo(ChangeFileExt(Filename, '.dat')); - - ResetIntern(); -end; - -destructor TBitmapFont.Destroy(); -begin - glDeleteTextures(1, @fTex.TexNum); - inherited; -end; - -procedure TBitmapFont.ResetIntern(); -begin - fLineSpacing := Height; -end; - -procedure TBitmapFont.Reset(); -begin - inherited; - ResetIntern(); -end; - -procedure TBitmapFont.CorrectWidths(WidthMult: real; WidthAdd: integer); -var - Count: integer; -begin - for Count := 0 to 255 do - fWidths[Count] := Round(fWidths[Count] * WidthMult) + WidthAdd; -end; - -procedure TBitmapFont.LoadFontInfo(const InfoFile: string); -var - Stream: TFileStream; -begin - FillChar(fWidths[0], Length(fWidths), 0); - - Stream := nil; - try - Stream := TFileStream.Create(InfoFile, fmOpenRead); - Stream.Read(fWidths, 256); - except - raise Exception.Create('Could not read font info file ''' + InfoFile + ''''); - end; - Stream.Free; -end; - -function TBitmapFont.BBox(const Text: TWideStringArray; Advance: boolean): TBoundsDbl; -var - LineIndex, CharIndex: integer; - CharCode: cardinal; - Line: WideString; - LineWidth: double; -begin - Result.Left := 0; - Result.Right := 0; - Result.Top := Height; - Result.Bottom := 0; - - for LineIndex := 0 to High(Text) do - begin - Line := Text[LineIndex]; - LineWidth := 0; - for CharIndex := 1 to Length(Line) do - begin - CharCode := Ord(Line[CharIndex]); - if (CharCode < Length(fWidths)) then - LineWidth := LineWidth + fWidths[CharCode]; - end; - if (LineWidth > Result.Right) then - Result.Right := LineWidth; - end; -end; - -procedure TBitmapFont.RenderChar(ch: WideChar; var AdvanceX: real); -var - TexX, TexY: real; - TexR, TexB: real; - GlyphWidth: real; - PL, PT: real; - PR, PB: real; - CharCode: cardinal; -begin - CharCode := Ord(ch); - if (CharCode > High(fWidths)) then - CharCode := 0; - - GlyphWidth := fWidths[CharCode]; - - // set texture positions - TexX := (CharCode mod 16) * 1/16 + 1/32 - (GlyphWidth/2 - fOutline)/fTexSize; - TexY := (CharCode div 16) * 1/16 + {2 texels} 2/fTexSize; - TexR := (CharCode mod 16) * 1/16 + 1/32 + (GlyphWidth/2 + fOutline)/fTexSize; - TexB := (1 + CharCode div 16) * 1/16 - {2 texels} 2/fTexSize; - - // set vector positions - PL := AdvanceX - fOutline; - PR := PL + GlyphWidth + fOutline*2; - PB := -fBaseline; - PT := PB + fTexSize div 16; - - (* - if (Font.Blend) then - begin - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - end; - *) - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, fTex.TexNum); - - if (not ReflectionPass) then - begin - glBegin(GL_QUADS); - glTexCoord2f(TexX, TexY); glVertex2f(PL, PT); - glTexCoord2f(TexX, TexB); glVertex2f(PL, PB); - glTexCoord2f(TexR, TexB); glVertex2f(PR, PB); - glTexCoord2f(TexR, TexY); glVertex2f(PR, PT); - glEnd; - end - else - begin - glDepthRange(0, 10); - glDepthFunc(GL_LEQUAL); - glEnable(GL_DEPTH_TEST); - - glBegin(GL_QUADS); - glTexCoord2f(TexX, TexY); glVertex2f(PL, PT); - glTexCoord2f(TexX, TexB); glVertex2f(PL, PB); - glTexCoord2f(TexR, TexB); glVertex2f(PR, PB); - glTexCoord2f(TexR, TexY); glVertex2f(PR, PT); - glEnd; - - glBegin(GL_QUADS); - glTexCoord2f(TexX, TexY); glVertex2f(PL, PT); - glTexCoord2f(TexX, TexB); glVertex2f(PL, PB); - glTexCoord2f(TexR, TexB); glVertex2f(PR, PB); - glTexCoord2f(TexR, TexY); glVertex2f(PR, PT); - -(* - glColor4f(fTempColor.r, fTempColor.g, fTempColor.b, 0.7); - glTexCoord2f(TexX, TexB); glVertex3f(PL, PB, 0); - glTexCoord2f(TexR, TexB); glVertex3f(PR, PB, 0); - - glColor4f(fTempColor.r, fTempColor.g, fTempColor.b, 0); - glTexCoord2f(TexR, (TexY + TexB)/2); glVertex3f(PR, (PT + PB)/2, 0); - glTexCoord2f(TexX, (TexY + TexB)/2); glVertex3f(PL, (PT + PB)/2, 0); -*) - glEnd; - - //write the colour back - glColor4fv(@fTempColor); - - glDisable(GL_DEPTH_TEST); - end; // reflection - - glDisable(GL_TEXTURE_2D); - (* - if (Font.Blend) then - glDisable(GL_BLEND); - *) - - AdvanceX := AdvanceX + GlyphWidth; -end; - -procedure TBitmapFont.Render(const Text: WideString); -var - CharIndex: integer; - AdvanceX: real; -begin - // if there is no text do nothing - if (Text = '') then - Exit; - - //Save the current color and alpha (for reflection) - glGetFloatv(GL_CURRENT_COLOR, @fTempColor); - - AdvanceX := 0; - for CharIndex := 1 to Length(Text) do - begin - RenderChar(Text[CharIndex], AdvanceX); - end; -end; - -function TBitmapFont.GetHeight(): single; -begin - Result := fAscender - fDescender; -end; - -function TBitmapFont.GetAscender(): single; -begin - Result := fAscender; -end; - -function TBitmapFont.GetDescender(): single; -begin - Result := fDescender; -end; - -function TBitmapFont.GetUnderlinePosition(): single; -begin - Result := -2.0; -end; - -function TBitmapFont.GetUnderlineThickness(): single; -begin - Result := 1.0; -end; - -{$ENDIF BITMAP_FONT} - - -initialization - -finalization - TFreeType.FreeLibrary(); - -end. diff --git a/src/lib/freetype/demo/engine-test.bdsproj b/src/lib/freetype/demo/engine-test.bdsproj new file mode 100644 index 00000000..9547f18f --- /dev/null +++ b/src/lib/freetype/demo/engine-test.bdsproj @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="utf-8"?> +<BorlandProject> + <PersonalityInfo> + <Option> + <Option Name="Personality">Delphi.Personality</Option> + <Option Name="ProjectType">VCLApplication</Option> + <Option Name="Version">1.0</Option> + <Option Name="GUID">{41656F26-D552-4948-B9DB-E184B77C3993}</Option> + </Option> + </PersonalityInfo> + <Delphi.Personality> + <Source> + <Source Name="MainSource">engine-test.dpr</Source> + </Source> + <FileVersion> + <FileVersion Name="Version">7.0</FileVersion> + </FileVersion> + <Compiler> + <Compiler Name="A">8</Compiler> + <Compiler Name="B">0</Compiler> + <Compiler Name="C">1</Compiler> + <Compiler Name="D">1</Compiler> + <Compiler Name="E">0</Compiler> + <Compiler Name="F">0</Compiler> + <Compiler Name="G">1</Compiler> + <Compiler Name="H">1</Compiler> + <Compiler Name="I">1</Compiler> + <Compiler Name="J">0</Compiler> + <Compiler Name="K">0</Compiler> + <Compiler Name="L">1</Compiler> + <Compiler Name="M">0</Compiler> + <Compiler Name="N">1</Compiler> + <Compiler Name="O">0</Compiler> + <Compiler Name="P">1</Compiler> + <Compiler Name="Q">0</Compiler> + <Compiler Name="R">0</Compiler> + <Compiler Name="S">0</Compiler> + <Compiler Name="T">0</Compiler> + <Compiler Name="U">0</Compiler> + <Compiler Name="V">1</Compiler> + <Compiler Name="W">0</Compiler> + <Compiler Name="X">1</Compiler> + <Compiler Name="Y">1</Compiler> + <Compiler Name="Z">1</Compiler> + <Compiler Name="ShowHints">True</Compiler> + <Compiler Name="ShowWarnings">True</Compiler> + <Compiler Name="UnitAliases">WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;</Compiler> + <Compiler Name="NamespacePrefix"></Compiler> + <Compiler Name="GenerateDocumentation">False</Compiler> + <Compiler Name="DefaultNamespace"></Compiler> + <Compiler Name="SymbolDeprecated">True</Compiler> + <Compiler Name="SymbolLibrary">True</Compiler> + <Compiler Name="SymbolPlatform">True</Compiler> + <Compiler Name="SymbolExperimental">True</Compiler> + <Compiler Name="UnitLibrary">True</Compiler> + <Compiler Name="UnitPlatform">True</Compiler> + <Compiler Name="UnitDeprecated">True</Compiler> + <Compiler Name="UnitExperimental">True</Compiler> + <Compiler Name="HResultCompat">True</Compiler> + <Compiler Name="HidingMember">True</Compiler> + <Compiler Name="HiddenVirtual">True</Compiler> + <Compiler Name="Garbage">True</Compiler> + <Compiler Name="BoundsError">True</Compiler> + <Compiler Name="ZeroNilCompat">True</Compiler> + <Compiler Name="StringConstTruncated">True</Compiler> + <Compiler Name="ForLoopVarVarPar">True</Compiler> + <Compiler Name="TypedConstVarPar">True</Compiler> + <Compiler Name="AsgToTypedConst">True</Compiler> + <Compiler Name="CaseLabelRange">True</Compiler> + <Compiler Name="ForVariable">True</Compiler> + <Compiler Name="ConstructingAbstract">True</Compiler> + <Compiler Name="ComparisonFalse">True</Compiler> + <Compiler Name="ComparisonTrue">True</Compiler> + <Compiler Name="ComparingSignedUnsigned">True</Compiler> + <Compiler Name="CombiningSignedUnsigned">True</Compiler> + <Compiler Name="UnsupportedConstruct">True</Compiler> + <Compiler Name="FileOpen">True</Compiler> + <Compiler Name="FileOpenUnitSrc">True</Compiler> + <Compiler Name="BadGlobalSymbol">True</Compiler> + <Compiler Name="DuplicateConstructorDestructor">True</Compiler> + <Compiler Name="InvalidDirective">True</Compiler> + <Compiler Name="PackageNoLink">True</Compiler> + <Compiler Name="PackageThreadVar">True</Compiler> + <Compiler Name="ImplicitImport">True</Compiler> + <Compiler Name="HPPEMITIgnored">True</Compiler> + <Compiler Name="NoRetVal">True</Compiler> + <Compiler Name="UseBeforeDef">True</Compiler> + <Compiler Name="ForLoopVarUndef">True</Compiler> + <Compiler Name="UnitNameMismatch">True</Compiler> + <Compiler Name="NoCFGFileFound">True</Compiler> + <Compiler Name="ImplicitVariants">True</Compiler> + <Compiler Name="UnicodeToLocale">True</Compiler> + <Compiler Name="LocaleToUnicode">True</Compiler> + <Compiler Name="ImagebaseMultiple">True</Compiler> + <Compiler Name="SuspiciousTypecast">True</Compiler> + <Compiler Name="PrivatePropAccessor">True</Compiler> + <Compiler Name="UnsafeType">False</Compiler> + <Compiler Name="UnsafeCode">False</Compiler> + <Compiler Name="UnsafeCast">False</Compiler> + <Compiler Name="OptionTruncated">True</Compiler> + <Compiler Name="WideCharReduced">True</Compiler> + <Compiler Name="DuplicatesIgnored">True</Compiler> + <Compiler Name="UnitInitSeq">True</Compiler> + <Compiler Name="LocalPInvoke">True</Compiler> + <Compiler Name="MessageDirective">True</Compiler> + <Compiler Name="CodePage"></Compiler> + </Compiler> + <Linker> + <Linker Name="MapFile">0</Linker> + <Linker Name="OutputObjs">0</Linker> + <Linker Name="GenerateHpps">False</Linker> + <Linker Name="ConsoleApp">1</Linker> + <Linker Name="DebugInfo">False</Linker> + <Linker Name="RemoteSymbols">False</Linker> + <Linker Name="GenerateDRC">False</Linker> + <Linker Name="MinStackSize">16384</Linker> + <Linker Name="MaxStackSize">1048576</Linker> + <Linker Name="ImageBase">4194304</Linker> + <Linker Name="ExeDescription"></Linker> + </Linker> + <Directories> + <Directories Name="OutputDir"></Directories> + <Directories Name="UnitOutputDir"></Directories> + <Directories Name="PackageDLLOutputDir"></Directories> + <Directories Name="PackageDCPOutputDir"></Directories> + <Directories Name="SearchPath">..\..\JEDI-SDL\SDL\Pas</Directories> + <Directories Name="Packages">vclx;vcl;rtl;vclactnband</Directories> + <Directories Name="Conditionals"></Directories> + <Directories Name="DebugSourceDirs"></Directories> + <Directories Name="UsePackages">False</Directories> + </Directories> + <Parameters> + <Parameters Name="RunParams"></Parameters> + <Parameters Name="HostApplication"></Parameters> + <Parameters Name="Launcher"></Parameters> + <Parameters Name="UseLauncher">False</Parameters> + <Parameters Name="DebugCWD"></Parameters> + <Parameters Name="Debug Symbols Search Path"></Parameters> + <Parameters Name="LoadAllSymbols">True</Parameters> + <Parameters Name="LoadUnspecifiedSymbols">False</Parameters> + </Parameters> + <Language> + <Language Name="ActiveLang"></Language> + <Language Name="ProjectLang">$00000000</Language> + <Language Name="RootDir"></Language> + </Language> + <VersionInfo> + <VersionInfo Name="IncludeVerInfo">False</VersionInfo> + <VersionInfo Name="AutoIncBuild">False</VersionInfo> + <VersionInfo Name="MajorVer">1</VersionInfo> + <VersionInfo Name="MinorVer">0</VersionInfo> + <VersionInfo Name="Release">0</VersionInfo> + <VersionInfo Name="Build">0</VersionInfo> + <VersionInfo Name="Debug">False</VersionInfo> + <VersionInfo Name="PreRelease">False</VersionInfo> + <VersionInfo Name="Special">False</VersionInfo> + <VersionInfo Name="Private">False</VersionInfo> + <VersionInfo Name="DLL">False</VersionInfo> + <VersionInfo Name="Locale">1031</VersionInfo> + <VersionInfo Name="CodePage">1252</VersionInfo> + </VersionInfo> + <VersionInfoKeys> + <VersionInfoKeys Name="CompanyName"></VersionInfoKeys> + <VersionInfoKeys Name="FileDescription"></VersionInfoKeys> + <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys> + <VersionInfoKeys Name="InternalName"></VersionInfoKeys> + <VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys> + <VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys> + <VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys> + <VersionInfoKeys Name="ProductName"></VersionInfoKeys> + <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys> + <VersionInfoKeys Name="Comments"></VersionInfoKeys> + </VersionInfoKeys> + </Delphi.Personality> +</BorlandProject> diff --git a/src/lib/freetype/demo/engine-test.dpr b/src/lib/freetype/demo/engine-test.dpr new file mode 100644 index 00000000..80177735 --- /dev/null +++ b/src/lib/freetype/demo/engine-test.dpr @@ -0,0 +1,336 @@ +program engine_test; +(* + * This code was created by Jeff Molofee '99 + * (ported to Linux/SDL by Ti Leggett '01) + * + * If you've found this code useful, please let me know. + * + * Visit Jeff at http://nehe.gamedev.net/ + * + * or for port-specific comments, questions, bugreports etc. + * email to leggett@eecs.tulane.edu + *) + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +{$APPTYPE Console} + +uses + moduleloader in '../../JEDI-SDL/SDL/Pas/moduleloader.pas', + SDL in '../../JEDI-SDL/SDL/Pas/sdl.pas', + gl in '../../JEDI-SDL/OpenGL/Pas/gl.pas', + glext in '../../JEDI-SDL/OpenGL/Pas/glext.pas', + glu in '../../JEDI-SDL/OpenGL/Pas/glu.pas', + {$IFNDEF FPC} + ctypes in '../../ctypes/ctypes.pas', + {$ENDIF} + FreeType in '../freetype.pas', + UFont in '../../../base/UFont.pas', + math, + sysutils; + +const + // screen width, height, and bit depth + SCREEN_WIDTH = 640; + SCREEN_HEIGHT = 480; + SCREEN_BPP = 16; + + //FONT_FILE = 'Test.ttf'; + //FONT_FILE = 'C:/Windows/Fonts/Arial.ttf'; + //FONT_FILE = 'C:/Windows/Fonts/SimSun.ttf'; + //FONT_FILE = 'eurostarregularextended.ttf'; + FONT_FILE = 'FreeSans.ttf'; + +var + OurFont: TScalableFont; + // This is our SDL surface + surface: PSDL_Surface; + cnt1, cnt2: GLfloat; + +(* function to release/destroy our resources and restoring the old desktop *) +procedure Quit(returnCode: integer); +begin + OurFont.Free; + + // clean up the window + SDL_Quit( ); + + // and exit appropriately + Halt( returnCode ); +end; + +(* function to reset our viewport after a window resize *) +function resizeWindow(width: integer; height: integer): boolean; +begin + // Protect against a divide by zero + if ( height = 0 ) then + height := 1; + + // Setup our viewport. + glViewport( 0, 0, GLsizei(width), GLsizei(height) ); + + // change to the projection matrix and set our viewing volume. + glMatrixMode( GL_PROJECTION ); + glLoadIdentity( ); + + // Set our perspective + //gluOrtho2D(0, width, 0, height); + gluOrtho2D(0, 800, 0, 600); + + // Make sure we're chaning the model view and not the projection + glMatrixMode( GL_MODELVIEW ); + + // Reset The View + glLoadIdentity( ); + + Result := true; +end; + +(* function to handle key press events *) +procedure handleKeyPress(keysym: PSDL_keysym); +begin + case ( keysym^.sym ) of + SDLK_ESCAPE: + begin + // ESC key was pressed + Quit( 0 ); + end; + SDLK_F1: + begin + // F1 key was pressed + // this toggles fullscreen mode + SDL_WM_ToggleFullScreen( surface ); + end; + end; +end; + +(* general OpenGL initialization function *) +function initGL(): boolean; +begin + // Enable smooth shading + glShadeModel( GL_SMOOTH ); + + // Set the background black + //glClearColor( 1, 1, 1.0, 1.0 ); + //glClearColor( 0.3, 0.7, 1.0, 1.0 ); + glClearColor( 0.0, 0.0, 0.0, 1.0 ); + + // Depth buffer setup + glClearDepth( 1.0 ); + + // Enables Depth Testing + glEnable( GL_DEPTH_TEST ); + + // The Type Of Depth Test To Do + glDepthFunc( GL_LEQUAL ); + + // Really Nice Perspective Calculations + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + + //OurFont := TFTScalableFont.Create(FONT_FILE, 64); + //OurFont := TFTFont.Create(FONT_FILE, 128); + OurFont := TFTScalableOutlineFont.Create(FONT_FILE, 64, 0.05); + //OurFont.UseKerning := false; + TFTScalableOutlineFont(OurFont).SetOutlineColor(1, 0, 0); + //OurFont := TOutlineFont.Create(FONT_FILE, 32, 2); + //OurFont.LineSpacing := OurFont.LineSpacing * 0.5; + + Result := true; +end; + +var + NextTime: cardinal; + Counter: integer; + +type + TVector4d = array[0..3] of GLdouble; + +function NewVector4d(a, b, c, d: GLdouble): TVector4d; +begin + Result[0] := a; + Result[1] := b; + Result[2] := c; + Result[3] := d; +end; + +(* Here goes our drawing code *) +function drawGLScene(): boolean; +var + msg: WideString; + bounds: TBoundsDbl; +begin + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + + //msg := 'Here'#13'there'#13'be'#13#13'newlines'#13'.'; + //msg := 'Here'#13'newlines'; + msg := 'Active FreeType Text - ' + FloatToStr(cnt1); + //msg := 'Hören'#13'其自诞生至今'#13'спецификация'; + + // Red text + glLoadIdentity(); + glTranslatef(cnt2, 240, 0); + if (cnt2 > 800) then + cnt2 := 0; + glTranslatef(30, 40, 0); + //glTranslatef(320, 240, 0); + //glRotatef(cnt1, 0, 0, 1); + //glScalef(1, 0.8 + 0.3*cos(cnt1/5), 1); + + OurFont.Style := [Italic, {Underline,} Reflect]; + //OurFont.GlyphSpacing := 10; + //OurFont.SetOutlineColor(0.5, 0.5, 0.5); + //OurFont.ReflectionSpacing := -4; + //OurFont.UseKerning := false; + OurFont.Height := 64;//cnt2; + //OurFont.Reset; + //OurFont.Aspect := 2; + + glColor3f(1, 1, 0); + bounds := OurFont.BBox(msg); + //glRectf(bounds.Left, OurFont.Ascender, bounds.Right, OurFont.Ascender-OurFont.Height); + + glColor3f(1, 1, 1); + //OurFont.ReflectionSpacing := 0; + OurFont.Print(msg); + + cnt1 := cnt1 + 0.051; // Increase The First Counter + cnt2 := cnt2 + 0.005; // Increase The First Counter + + SDL_GL_SwapBuffers( ); + + Inc(Counter); + + if (NextTime < SDL_GetTicks()) then + begin + NextTime := SDL_GetTicks() + 2000; + writeln('FPS: ' + floattostr(Counter / 2.0)); + Counter := 0; + end; + + Result := true; +end; + +var + // Flags to pass to SDL_SetVideoMode + videoFlags: integer; + // main loop variable + done: boolean = false; + // used to collect events + event: TSDL_Event; + // this holds some info about our display + videoInfo: PSDL_VideoInfo; + // whether or not the window is active + isActive: boolean = true; + +begin + // initialize SDL + if ( SDL_Init( SDL_INIT_VIDEO or SDL_INIT_TIMER ) < 0 ) then + begin + writeln( ErrOutput, 'Video initialization failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // Fetch the video info + videoInfo := SDL_GetVideoInfo( ); + + if ( videoInfo = nil ) then + begin + writeln( ErrOutput, 'Video query failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Enable double buffering + + // the flags to pass to SDL_SetVideoMode + videoFlags := SDL_OPENGL; // Enable OpenGL in SDL + videoFlags := videoFlags or SDL_HWPALETTE; // Store the palette in hardware + videoFlags := videoFlags or SDL_RESIZABLE; // Enable window resizing + + // This checks to see if surfaces can be stored in memory + if ( videoInfo^.hw_available <> 0 ) then + videoFlags := videoFlags or SDL_HWSURFACE + else + videoFlags := videoFlags or SDL_SWSURFACE; + + // This checks if hardware blits can be done + if ( videoInfo^.blit_hw <> 0 ) then + videoFlags := videoFlags or SDL_HWACCEL; + + // Sets up OpenGL double buffering + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + // get a SDL surface + surface := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, + videoFlags ); + + // Verify there is a surface + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Video mode set failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // initialize OpenGL + initGL(); + + // resize the initial window + resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); + + // wait for events + while ( not done ) do + begin + { handle the events in the queue } + + while ( SDL_PollEvent( @event ) <> 0 ) do + begin + case( event.type_ ) of + SDL_ACTIVEEVENT: + begin + // Something's happend with our focus + // If we are iconified, we shouldn't draw the screen + if ( (event.active.state and SDL_APPACTIVE) <> 0 ) then + begin + if ( event.active.gain = 0 ) then + isActive := false + else + isActive := true; + end; + end; + SDL_VIDEORESIZE: + begin + // handle resize event + {$IFDEF UNIX} + surface := SDL_SetVideoMode( event.resize.w, + event.resize.h, + 16, videoFlags ); + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Could not get a surface after resize: ' + SDL_GetError( ) ); + Quit( 1 ); + end; + {$ENDIF} + resizeWindow( event.resize.w, event.resize.h ); + end; + SDL_KEYDOWN: + begin + // handle key presses + handleKeyPress( @event.key.keysym ); + end; + SDL_QUITEV: + begin + // handle quit requests + done := true; + end; + end; + end; + + // draw the scene + if ( isActive ) then + drawGLScene( ); + end; + + // clean ourselves up and exit + Quit( 0 ); +end. diff --git a/src/lib/freetype/demo/engine-test.lpi b/src/lib/freetype/demo/engine-test.lpi new file mode 100644 index 00000000..6cbfe1eb --- /dev/null +++ b/src/lib/freetype/demo/engine-test.lpi @@ -0,0 +1,173 @@ +<?xml version="1.0"?> +<CONFIG> + <ProjectOptions> + <PathDelim Value="\"/> + <Version Value="6"/> + <General> + <MainUnit Value="0"/> + <IconPath Value=".\"/> + <TargetFileExt Value=""/> + <ActiveEditorIndexAtStart Value="0"/> + </General> + <VersionInfo> + <ProjectVersion Value=""/> + <Language Value=""/> + <CharSet Value=""/> + </VersionInfo> + <PublishOptions> + <Version Value="2"/> + <DestinationDirectory Value="$(TestDir)\publishedproject\"/> + <IgnoreBinaries Value="False"/> + <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> + <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> + </local> + </RunParams> + <Units Count="16"> + <Unit0> + <Filename Value="engine-test.dpr"/> + <IsPartOfProject Value="True"/> + <CursorPos X="25" Y="135"/> + <TopLine Value="118"/> + <EditorIndex Value="0"/> + <UsageCount Value="72"/> + <Loaded Value="True"/> + </Unit0> + <Unit1> + <Filename Value="JEDI-SDL\OpenGL\Pas\opengl12.pas"/> + <UnitName Value="opengl12"/> + <CursorPos X="20" Y="9922"/> + <TopLine Value="9889"/> + <UsageCount Value="5"/> + </Unit1> + <Unit2> + <Filename Value="JEDI-SDL\SDL\Pas\sdl.pas"/> + <UnitName Value="sdl"/> + <CursorPos X="29" Y="3569"/> + <TopLine Value="3547"/> + <UsageCount Value="5"/> + </Unit2> + <Unit3> + <Filename Value="FreeType.pas"/> + <UnitName Value="FreeType"/> + <CursorPos X="6" Y="1"/> + <TopLine Value="1"/> + <UsageCount Value="5"/> + </Unit3> + <Unit4> + <Filename Value="UFreeType.pas"/> + <UnitName Value="UFreeType"/> + <CursorPos X="47" Y="111"/> + <TopLine Value="76"/> + <UsageCount Value="35"/> + </Unit4> + <Unit5> + <Filename Value="freetype"/> + <CursorPos X="1" Y="1"/> + <TopLine Value="1"/> + <UsageCount Value="8"/> + <SyntaxHighlighter Value="None"/> + </Unit5> + <Unit6> + <Filename Value="freetype\freetype.pas"/> + <UnitName Value="freetype"/> + <CursorPos X="31" Y="807"/> + <TopLine Value="14"/> + <UsageCount Value="15"/> + </Unit6> + <Unit7> + <Filename Value="..\..\daten\Projekte\UltraStarDX\trunk\Game\Code\lib\ffmpeg\avcodec.pas"/> + <UnitName Value="avcodec"/> + <CursorPos X="1" Y="38"/> + <TopLine Value="1"/> + <UsageCount Value="6"/> + </Unit7> + <Unit8> + <Filename Value="..\..\JEDI-SDL\OpenGL\Pas\gl.pas"/> + <UnitName Value="gl"/> + <CursorPos X="2" Y="89"/> + <TopLine Value="69"/> + <UsageCount Value="9"/> + </Unit8> + <Unit9> + <Filename Value="..\..\ctypes\ctypes.pas"/> + <UnitName Value="ctypes"/> + <CursorPos X="8" Y="25"/> + <TopLine Value="51"/> + <UsageCount Value="9"/> + </Unit9> + <Unit10> + <Filename Value="..\..\JEDI-SDL\OpenGL\Pas\glu.pas"/> + <UnitName Value="glu"/> + <CursorPos X="14" Y="155"/> + <TopLine Value="135"/> + <UsageCount Value="9"/> + </Unit10> + <Unit11> + <Filename Value="..\..\JEDI-SDL\SDL\Pas\sdl.pas"/> + <UnitName Value="sdl"/> + <CursorPos X="12" Y="1418"/> + <TopLine Value="1398"/> + <UsageCount Value="9"/> + </Unit11> + <Unit12> + <Filename Value="..\freetype.pas"/> + <UnitName Value="freetype"/> + <CursorPos X="3" Y="1985"/> + <TopLine Value="1965"/> + <UsageCount Value="10"/> + </Unit12> + <Unit13> + <Filename Value="C:\Programme\lazarus\fpc\2.2.0\source\rtl\objpas\classes\classesh.inc"/> + <CursorPos X="13" Y="26"/> + <TopLine Value="6"/> + <UsageCount Value="13"/> + </Unit13> + <Unit14> + <Filename Value="C:\Programme\lazarus\fpc\2.2.0\source\rtl\objpas\types.pp"/> + <UnitName Value="types"/> + <CursorPos X="7" Y="105"/> + <TopLine Value="73"/> + <UsageCount Value="12"/> + </Unit14> + <Unit15> + <Filename Value="UFont.pas"/> + <UnitName Value="UFont"/> + <CursorPos X="15" Y="1752"/> + <TopLine Value="1734"/> + <UsageCount Value="10"/> + </Unit15> + </Units> + <JumpHistory Count="0" HistoryIndex="-1"/> + </ProjectOptions> + <CompilerOptions> + <Version Value="8"/> + <PathDelim Value="\"/> + <SearchPaths> + <IncludeFiles Value="..\..\JEDI-SDL\SDL\Pas\"/> + </SearchPaths> + <Other> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> + <Debugging> + <BreakPoints Count="1"> + <Item1> + <Source Value="lesson43.dpr"/> + <Line Value="138"/> + </Item1> + </BreakPoints> + <Exceptions Count="2"> + <Item1> + <Name Value="ECodetoolError"/> + </Item1> + <Item2> + <Name Value="EFOpenError"/> + </Item2> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/src/lib/freetype/demo/lesson43.bdsproj b/src/lib/freetype/demo/lesson43.bdsproj deleted file mode 100644 index 30f88ab3..00000000 --- a/src/lib/freetype/demo/lesson43.bdsproj +++ /dev/null @@ -1,175 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<BorlandProject> - <PersonalityInfo> - <Option> - <Option Name="Personality">Delphi.Personality</Option> - <Option Name="ProjectType">VCLApplication</Option> - <Option Name="Version">1.0</Option> - <Option Name="GUID">{41656F26-D552-4948-B9DB-E184B77C3993}</Option> - </Option> - </PersonalityInfo> - <Delphi.Personality> - <Source> - <Source Name="MainSource">lesson43.dpr</Source> - </Source> - <FileVersion> - <FileVersion Name="Version">7.0</FileVersion> - </FileVersion> - <Compiler> - <Compiler Name="A">8</Compiler> - <Compiler Name="B">0</Compiler> - <Compiler Name="C">1</Compiler> - <Compiler Name="D">1</Compiler> - <Compiler Name="E">0</Compiler> - <Compiler Name="F">0</Compiler> - <Compiler Name="G">1</Compiler> - <Compiler Name="H">1</Compiler> - <Compiler Name="I">1</Compiler> - <Compiler Name="J">0</Compiler> - <Compiler Name="K">0</Compiler> - <Compiler Name="L">1</Compiler> - <Compiler Name="M">0</Compiler> - <Compiler Name="N">1</Compiler> - <Compiler Name="O">0</Compiler> - <Compiler Name="P">1</Compiler> - <Compiler Name="Q">0</Compiler> - <Compiler Name="R">0</Compiler> - <Compiler Name="S">0</Compiler> - <Compiler Name="T">0</Compiler> - <Compiler Name="U">0</Compiler> - <Compiler Name="V">1</Compiler> - <Compiler Name="W">0</Compiler> - <Compiler Name="X">1</Compiler> - <Compiler Name="Y">1</Compiler> - <Compiler Name="Z">1</Compiler> - <Compiler Name="ShowHints">True</Compiler> - <Compiler Name="ShowWarnings">True</Compiler> - <Compiler Name="UnitAliases">WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;</Compiler> - <Compiler Name="NamespacePrefix"></Compiler> - <Compiler Name="GenerateDocumentation">False</Compiler> - <Compiler Name="DefaultNamespace"></Compiler> - <Compiler Name="SymbolDeprecated">True</Compiler> - <Compiler Name="SymbolLibrary">True</Compiler> - <Compiler Name="SymbolPlatform">True</Compiler> - <Compiler Name="SymbolExperimental">True</Compiler> - <Compiler Name="UnitLibrary">True</Compiler> - <Compiler Name="UnitPlatform">True</Compiler> - <Compiler Name="UnitDeprecated">True</Compiler> - <Compiler Name="UnitExperimental">True</Compiler> - <Compiler Name="HResultCompat">True</Compiler> - <Compiler Name="HidingMember">True</Compiler> - <Compiler Name="HiddenVirtual">True</Compiler> - <Compiler Name="Garbage">True</Compiler> - <Compiler Name="BoundsError">True</Compiler> - <Compiler Name="ZeroNilCompat">True</Compiler> - <Compiler Name="StringConstTruncated">True</Compiler> - <Compiler Name="ForLoopVarVarPar">True</Compiler> - <Compiler Name="TypedConstVarPar">True</Compiler> - <Compiler Name="AsgToTypedConst">True</Compiler> - <Compiler Name="CaseLabelRange">True</Compiler> - <Compiler Name="ForVariable">True</Compiler> - <Compiler Name="ConstructingAbstract">True</Compiler> - <Compiler Name="ComparisonFalse">True</Compiler> - <Compiler Name="ComparisonTrue">True</Compiler> - <Compiler Name="ComparingSignedUnsigned">True</Compiler> - <Compiler Name="CombiningSignedUnsigned">True</Compiler> - <Compiler Name="UnsupportedConstruct">True</Compiler> - <Compiler Name="FileOpen">True</Compiler> - <Compiler Name="FileOpenUnitSrc">True</Compiler> - <Compiler Name="BadGlobalSymbol">True</Compiler> - <Compiler Name="DuplicateConstructorDestructor">True</Compiler> - <Compiler Name="InvalidDirective">True</Compiler> - <Compiler Name="PackageNoLink">True</Compiler> - <Compiler Name="PackageThreadVar">True</Compiler> - <Compiler Name="ImplicitImport">True</Compiler> - <Compiler Name="HPPEMITIgnored">True</Compiler> - <Compiler Name="NoRetVal">True</Compiler> - <Compiler Name="UseBeforeDef">True</Compiler> - <Compiler Name="ForLoopVarUndef">True</Compiler> - <Compiler Name="UnitNameMismatch">True</Compiler> - <Compiler Name="NoCFGFileFound">True</Compiler> - <Compiler Name="ImplicitVariants">True</Compiler> - <Compiler Name="UnicodeToLocale">True</Compiler> - <Compiler Name="LocaleToUnicode">True</Compiler> - <Compiler Name="ImagebaseMultiple">True</Compiler> - <Compiler Name="SuspiciousTypecast">True</Compiler> - <Compiler Name="PrivatePropAccessor">True</Compiler> - <Compiler Name="UnsafeType">False</Compiler> - <Compiler Name="UnsafeCode">False</Compiler> - <Compiler Name="UnsafeCast">False</Compiler> - <Compiler Name="OptionTruncated">True</Compiler> - <Compiler Name="WideCharReduced">True</Compiler> - <Compiler Name="DuplicatesIgnored">True</Compiler> - <Compiler Name="UnitInitSeq">True</Compiler> - <Compiler Name="LocalPInvoke">True</Compiler> - <Compiler Name="MessageDirective">True</Compiler> - <Compiler Name="CodePage"></Compiler> - </Compiler> - <Linker> - <Linker Name="MapFile">0</Linker> - <Linker Name="OutputObjs">0</Linker> - <Linker Name="GenerateHpps">False</Linker> - <Linker Name="ConsoleApp">1</Linker> - <Linker Name="DebugInfo">False</Linker> - <Linker Name="RemoteSymbols">False</Linker> - <Linker Name="GenerateDRC">False</Linker> - <Linker Name="MinStackSize">16384</Linker> - <Linker Name="MaxStackSize">1048576</Linker> - <Linker Name="ImageBase">4194304</Linker> - <Linker Name="ExeDescription"></Linker> - </Linker> - <Directories> - <Directories Name="OutputDir"></Directories> - <Directories Name="UnitOutputDir"></Directories> - <Directories Name="PackageDLLOutputDir"></Directories> - <Directories Name="PackageDCPOutputDir"></Directories> - <Directories Name="SearchPath">..\..\JEDI-SDL\SDL\Pas</Directories> - <Directories Name="Packages">vclx;vcl;rtl;vclactnband</Directories> - <Directories Name="Conditionals"></Directories> - <Directories Name="DebugSourceDirs"></Directories> - <Directories Name="UsePackages">False</Directories> - </Directories> - <Parameters> - <Parameters Name="RunParams"></Parameters> - <Parameters Name="HostApplication"></Parameters> - <Parameters Name="Launcher"></Parameters> - <Parameters Name="UseLauncher">False</Parameters> - <Parameters Name="DebugCWD"></Parameters> - <Parameters Name="Debug Symbols Search Path"></Parameters> - <Parameters Name="LoadAllSymbols">True</Parameters> - <Parameters Name="LoadUnspecifiedSymbols">False</Parameters> - </Parameters> - <Language> - <Language Name="ActiveLang"></Language> - <Language Name="ProjectLang">$00000000</Language> - <Language Name="RootDir"></Language> - </Language> - <VersionInfo> - <VersionInfo Name="IncludeVerInfo">False</VersionInfo> - <VersionInfo Name="AutoIncBuild">False</VersionInfo> - <VersionInfo Name="MajorVer">1</VersionInfo> - <VersionInfo Name="MinorVer">0</VersionInfo> - <VersionInfo Name="Release">0</VersionInfo> - <VersionInfo Name="Build">0</VersionInfo> - <VersionInfo Name="Debug">False</VersionInfo> - <VersionInfo Name="PreRelease">False</VersionInfo> - <VersionInfo Name="Special">False</VersionInfo> - <VersionInfo Name="Private">False</VersionInfo> - <VersionInfo Name="DLL">False</VersionInfo> - <VersionInfo Name="Locale">1031</VersionInfo> - <VersionInfo Name="CodePage">1252</VersionInfo> - </VersionInfo> - <VersionInfoKeys> - <VersionInfoKeys Name="CompanyName"></VersionInfoKeys> - <VersionInfoKeys Name="FileDescription"></VersionInfoKeys> - <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys> - <VersionInfoKeys Name="InternalName"></VersionInfoKeys> - <VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys> - <VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys> - <VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys> - <VersionInfoKeys Name="ProductName"></VersionInfoKeys> - <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys> - <VersionInfoKeys Name="Comments"></VersionInfoKeys> - </VersionInfoKeys> - </Delphi.Personality> -</BorlandProject> diff --git a/src/lib/freetype/demo/lesson43.dpr b/src/lib/freetype/demo/lesson43.dpr deleted file mode 100644 index 8a470a2e..00000000 --- a/src/lib/freetype/demo/lesson43.dpr +++ /dev/null @@ -1,366 +0,0 @@ -program lesson43; -(* - * This code was created by Jeff Molofee '99 - * (ported to Linux/SDL by Ti Leggett '01) - * - * If you've found this code useful, please let me know. - * - * Visit Jeff at http://nehe.gamedev.net/ - * - * or for port-specific comments, questions, bugreports etc. - * email to leggett@eecs.tulane.edu - *) - -{$IFDEF FPC} - {$mode delphi}{$H+} -{$ENDIF} - -{$APPTYPE Console} - -{.$DEFINE FONT2} - -uses - moduleloader in '../../JEDI-SDL/SDL/Pas/moduleloader.pas', - SDL in '../../JEDI-SDL/SDL/Pas/sdl.pas', - gl in '../../JEDI-SDL/OpenGL/Pas/gl.pas', - glext in '../../JEDI-SDL/OpenGL/Pas/glext.pas', - glu in '../../JEDI-SDL/OpenGL/Pas/glu.pas', - ctypes in '../../ctypes/ctypes.pas', - FreeType in '../freetype.pas', - {$IFNDEF FONT2} - UFont in 'UFont.pas', - {$ELSE} - UFont2 in 'UFont2.pas', - {$ENDIF} - math, - sysutils; - -const - // screen width, height, and bit depth - SCREEN_WIDTH = 640; - SCREEN_HEIGHT = 480; - SCREEN_BPP = 16; - - //FONT_FILE = 'Test.ttf'; - //FONT_FILE = 'C:/Windows/Fonts/Arial.ttf'; - //FONT_FILE = 'C:/Windows/Fonts/SimSun.ttf'; - //FONT_FILE = 'C:/Windows/Fonts/SimSun.ttf'; - FONT_FILE = 'eurostarregularextended.ttf'; - -var - OurFont: TScalableFont; - // This is our SDL surface - surface: PSDL_Surface; - cnt1, cnt2: GLfloat; - -(* function to release/destroy our resources and restoring the old desktop *) -procedure Quit(returnCode: integer); -begin - OurFont.Free; - - // clean up the window - SDL_Quit( ); - - // and exit appropriately - Halt( returnCode ); -end; - -(* function to reset our viewport after a window resize *) -function resizeWindow(width: integer; height: integer): boolean; -begin - // Protect against a divide by zero - if ( height = 0 ) then - height := 1; - - // Setup our viewport. - glViewport( 0, 0, GLsizei(width), GLsizei(height) ); - - // change to the projection matrix and set our viewing volume. - glMatrixMode( GL_PROJECTION ); - glLoadIdentity( ); - - // Set our perspective - //gluOrtho2D(0, width, 0, height); - gluOrtho2D(0, 800, 0, 600); - - // Make sure we're chaning the model view and not the projection - glMatrixMode( GL_MODELVIEW ); - - // Reset The View - glLoadIdentity( ); - - Result := true; -end; - -(* function to handle key press events *) -procedure handleKeyPress(keysym: PSDL_keysym); -begin - case ( keysym^.sym ) of - SDLK_ESCAPE: - begin - // ESC key was pressed - Quit( 0 ); - end; - SDLK_F1: - begin - // F1 key was pressed - // this toggles fullscreen mode - SDL_WM_ToggleFullScreen( surface ); - end; - end; -end; - -(* general OpenGL initialization function *) -function initGL(): boolean; -begin - // Enable smooth shading - glShadeModel( GL_SMOOTH ); - - // Set the background black - //glClearColor( 1, 1, 1.0, 1.0 ); - //glClearColor( 0.3, 0.7, 1.0, 1.0 ); - glClearColor( 0.0, 0.0, 0.0, 1.0 ); - - // Depth buffer setup - glClearDepth( 1.0 ); - - // Enables Depth Testing - glEnable( GL_DEPTH_TEST ); - - // The Type Of Depth Test To Do - glDepthFunc( GL_LEQUAL ); - - // Really Nice Perspective Calculations - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); - - //OurFont := TFTScalableFont.Create(FONT_FILE, 64); - //OurFont := TFTFont.Create(FONT_FILE, 128); - OurFont := TFTScalableOutlineFont.Create(FONT_FILE, 64, 0.05); - //OurFont.UseKerning := false; - TFTScalableOutlineFont(OurFont).SetOutlineColor(1, 0, 0); - //OurFont := TOutlineFont.Create(FONT_FILE, 32, 2); - //OurFont.LineSpacing := OurFont.LineSpacing * 0.5; - - Result := true; -end; - -var - NextTime: cardinal; - Counter: integer; - -type - TVector4d = array[0..3] of GLdouble; - -function NewVector4d(a, b, c, d: GLdouble): TVector4d; -begin - Result[0] := a; - Result[1] := b; - Result[2] := c; - Result[3] := d; -end; - -(* Here goes our drawing code *) -function drawGLScene(): boolean; -var - msg: WideString; - bounds: TBoundsDbl; - ClipPlaneEq: TVector4d; -begin - glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer - - //msg := 'Here'#13'there'#13'be'#13#13'newlines'#13'.'; - //msg := 'Here'#13'newlines'; - msg := 'Hallo Du';//Active FreeType Text - ' + FloatToStr(cnt1); - //msg := 'Hören'#13'其自诞生至今'#13'спецификация'; - - // Red text - glLoadIdentity(); - glTranslatef(cnt2, 240, 0); - if (cnt2 > 800) then - cnt2 := 0; - glTranslatef(30, 40, 0); - //glTranslatef(320, 240, 0); - //glRotatef(cnt1, 0, 0, 1); - //glScalef(1, 0.8 + 0.3*cos(cnt1/5), 1); - - OurFont.Style := [Italic, Underline, Reflect]; - //OurFont.GlyphSpacing := 10; - //OurFont.SetOutlineColor(0.5, 0.5, 0.5); - //OurFont.ReflectionSpacing := -4; - //OurFont.UseKerning := false; - OurFont.Height := 32;//cnt2; - //OurFont.Reset; - //OurFont.Aspect := 2; - - { - glColor3f(1, 1, 0); - bounds := OurFont.BBox(msg); - glRectf(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); - } - - { - glEnable(GL_CLIP_PLANE0); - ClipPlaneEq := NewVector4d(-1, 0, 0, bounds.Right/5); - glClipPlane(GL_CLIP_PLANE0, @ClipPlaneEq); - } - //glColor3f(1, 0, 0); - glColor3f(1, 1, 1); - //OurFont.ReflectionSpacing := 0; - OurFont.Print(msg); - - glTranslatef(0, 50, 0); - glColor3f(1, 1, 0); - bounds := OurFont.BBox('Hallo '); - glRectf(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); - OurFont.Print('Hallo '); - - { - ClipPlaneEq := NewVector4d(1, 0, 0, -bounds.Right/5); - glClipPlane(GL_CLIP_PLANE0, @ClipPlaneEq); - glColor3f(0, 0, 1); - OurFont.Print(msg); - glDisable(GL_CLIP_PLANE0); - //glColor3f(0, 1, 0); - //OurFont.Style := OurFont.Style - [Italic]; - //OurFont.Print(msg); - } - - cnt1 := cnt1 + 0.051; // Increase The First Counter - cnt2 := cnt2 + 0.005; // Increase The First Counter - - SDL_GL_SwapBuffers( ); - - Inc(Counter); - - if (NextTime < SDL_GetTicks()) then - begin - NextTime := SDL_GetTicks() + 2000; - writeln('FPS: ' + floattostr(Counter / 2.0)); - Counter := 0; - end; - - Result := true; -end; - -var - // Flags to pass to SDL_SetVideoMode - videoFlags: integer; - // main loop variable - done: boolean = false; - // used to collect events - event: TSDL_Event; - // this holds some info about our display - videoInfo: PSDL_VideoInfo; - // whether or not the window is active - isActive: boolean = true; - -begin - // initialize SDL - if ( SDL_Init( SDL_INIT_VIDEO or SDL_INIT_TIMER ) < 0 ) then - begin - writeln( ErrOutput, 'Video initialization failed: ' + SDL_GetError() ); - Quit( 1 ); - end; - - // Fetch the video info - videoInfo := SDL_GetVideoInfo( ); - - if ( videoInfo = nil ) then - begin - writeln( ErrOutput, 'Video query failed: ' + SDL_GetError() ); - Quit( 1 ); - end; - - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Enable double buffering - - // the flags to pass to SDL_SetVideoMode - videoFlags := SDL_OPENGL; // Enable OpenGL in SDL - videoFlags := videoFlags or SDL_HWPALETTE; // Store the palette in hardware - videoFlags := videoFlags or SDL_RESIZABLE; // Enable window resizing - - // This checks to see if surfaces can be stored in memory - if ( videoInfo^.hw_available <> 0 ) then - videoFlags := videoFlags or SDL_HWSURFACE - else - videoFlags := videoFlags or SDL_SWSURFACE; - - // This checks if hardware blits can be done - if ( videoInfo^.blit_hw <> 0 ) then - videoFlags := videoFlags or SDL_HWACCEL; - - // Sets up OpenGL double buffering - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - - // get a SDL surface - surface := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, - videoFlags ); - - // Verify there is a surface - if ( surface = nil ) then - begin - writeln( ErrOutput, 'Video mode set failed: ' + SDL_GetError() ); - Quit( 1 ); - end; - - // initialize OpenGL - initGL(); - - // resize the initial window - resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); - - // wait for events - while ( not done ) do - begin - { handle the events in the queue } - - while ( SDL_PollEvent( @event ) <> 0 ) do - begin - case( event.type_ ) of - SDL_ACTIVEEVENT: - begin - // Something's happend with our focus - // If we are iconified, we shouldn't draw the screen - if ( (event.active.state and SDL_APPACTIVE) <> 0 ) then - begin - if ( event.active.gain = 0 ) then - isActive := false - else - isActive := true; - end; - end; - SDL_VIDEORESIZE: - begin - // handle resize event - {$IFDEF UNIX} - surface := SDL_SetVideoMode( event.resize.w, - event.resize.h, - 16, videoFlags ); - if ( surface = nil ) then - begin - writeln( ErrOutput, 'Could not get a surface after resize: ' + SDL_GetError( ) ); - Quit( 1 ); - end; - {$ENDIF} - resizeWindow( event.resize.w, event.resize.h ); - end; - SDL_KEYDOWN: - begin - // handle key presses - handleKeyPress( @event.key.keysym ); - end; - SDL_QUITEV: - begin - // handle quit requests - done := true; - end; - end; - end; - - // draw the scene - if ( isActive ) then - drawGLScene( ); - end; - - // clean ourselves up and exit - Quit( 0 ); -end. diff --git a/src/lib/freetype/demo/lesson43.lpi b/src/lib/freetype/demo/lesson43.lpi deleted file mode 100644 index b6791f18..00000000 --- a/src/lib/freetype/demo/lesson43.lpi +++ /dev/null @@ -1,272 +0,0 @@ -<?xml version="1.0"?> -<CONFIG> - <ProjectOptions> - <PathDelim Value="\"/> - <Version Value="6"/> - <General> - <MainUnit Value="0"/> - <IconPath Value=".\"/> - <TargetFileExt Value=""/> - <ActiveEditorIndexAtStart Value="1"/> - </General> - <VersionInfo> - <ProjectVersion Value=""/> - <Language Value=""/> - <CharSet Value=""/> - </VersionInfo> - <PublishOptions> - <Version Value="2"/> - <DestinationDirectory Value="$(TestDir)\publishedproject\"/> - <IgnoreBinaries Value="False"/> - <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> - <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> - </PublishOptions> - <RunParams> - <local> - <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> - </local> - </RunParams> - <Units Count="16"> - <Unit0> - <Filename Value="lesson43.dpr"/> - <IsPartOfProject Value="True"/> - <UnitName Value="lesson43"/> - <CursorPos X="1" Y="138"/> - <TopLine Value="118"/> - <EditorIndex Value="0"/> - <UsageCount Value="72"/> - <Loaded Value="True"/> - </Unit0> - <Unit1> - <Filename Value="JEDI-SDL\OpenGL\Pas\opengl12.pas"/> - <UnitName Value="opengl12"/> - <CursorPos X="20" Y="9922"/> - <TopLine Value="9889"/> - <UsageCount Value="5"/> - </Unit1> - <Unit2> - <Filename Value="JEDI-SDL\SDL\Pas\sdl.pas"/> - <UnitName Value="sdl"/> - <CursorPos X="29" Y="3569"/> - <TopLine Value="3547"/> - <UsageCount Value="5"/> - </Unit2> - <Unit3> - <Filename Value="FreeType.pas"/> - <UnitName Value="FreeType"/> - <CursorPos X="6" Y="1"/> - <TopLine Value="1"/> - <UsageCount Value="5"/> - </Unit3> - <Unit4> - <Filename Value="UFreeType.pas"/> - <UnitName Value="UFreeType"/> - <CursorPos X="47" Y="111"/> - <TopLine Value="76"/> - <UsageCount Value="35"/> - </Unit4> - <Unit5> - <Filename Value="freetype"/> - <CursorPos X="1" Y="1"/> - <TopLine Value="1"/> - <UsageCount Value="8"/> - <SyntaxHighlighter Value="None"/> - </Unit5> - <Unit6> - <Filename Value="freetype\freetype.pas"/> - <UnitName Value="freetype"/> - <CursorPos X="31" Y="807"/> - <TopLine Value="14"/> - <UsageCount Value="15"/> - </Unit6> - <Unit7> - <Filename Value="..\..\daten\Projekte\UltraStarDX\trunk\Game\Code\lib\ffmpeg\avcodec.pas"/> - <UnitName Value="avcodec"/> - <CursorPos X="1" Y="38"/> - <TopLine Value="1"/> - <UsageCount Value="6"/> - </Unit7> - <Unit8> - <Filename Value="..\..\JEDI-SDL\OpenGL\Pas\gl.pas"/> - <UnitName Value="gl"/> - <CursorPos X="2" Y="89"/> - <TopLine Value="69"/> - <UsageCount Value="9"/> - </Unit8> - <Unit9> - <Filename Value="..\..\ctypes\ctypes.pas"/> - <UnitName Value="ctypes"/> - <CursorPos X="8" Y="25"/> - <TopLine Value="51"/> - <UsageCount Value="9"/> - </Unit9> - <Unit10> - <Filename Value="..\..\JEDI-SDL\OpenGL\Pas\glu.pas"/> - <UnitName Value="glu"/> - <CursorPos X="14" Y="155"/> - <TopLine Value="135"/> - <UsageCount Value="9"/> - </Unit10> - <Unit11> - <Filename Value="..\..\JEDI-SDL\SDL\Pas\sdl.pas"/> - <UnitName Value="sdl"/> - <CursorPos X="12" Y="1418"/> - <TopLine Value="1398"/> - <UsageCount Value="9"/> - </Unit11> - <Unit12> - <Filename Value="..\freetype.pas"/> - <UnitName Value="freetype"/> - <CursorPos X="3" Y="1985"/> - <TopLine Value="1965"/> - <UsageCount Value="10"/> - </Unit12> - <Unit13> - <Filename Value="C:\Programme\lazarus\fpc\2.2.0\source\rtl\objpas\classes\classesh.inc"/> - <CursorPos X="13" Y="26"/> - <TopLine Value="6"/> - <UsageCount Value="13"/> - </Unit13> - <Unit14> - <Filename Value="C:\Programme\lazarus\fpc\2.2.0\source\rtl\objpas\types.pp"/> - <UnitName Value="types"/> - <CursorPos X="7" Y="105"/> - <TopLine Value="73"/> - <UsageCount Value="12"/> - </Unit14> - <Unit15> - <Filename Value="UFont.pas"/> - <UnitName Value="UFont"/> - <CursorPos X="1" Y="1751"/> - <TopLine Value="1734"/> - <EditorIndex Value="1"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit15> - </Units> - <JumpHistory Count="22" HistoryIndex="21"> - <Position1> - <Filename Value="lesson43.dpr"/> - <Caret Line="1" Column="1" TopLine="1"/> - </Position1> - <Position2> - <Filename Value="lesson43.dpr"/> - <Caret Line="138" Column="1" TopLine="118"/> - </Position2> - <Position3> - <Filename Value="UFont.pas"/> - <Caret Line="1746" Column="1" TopLine="1726"/> - </Position3> - <Position4> - <Filename Value="UFont.pas"/> - <Caret Line="1747" Column="1" TopLine="1727"/> - </Position4> - <Position5> - <Filename Value="UFont.pas"/> - <Caret Line="1749" Column="1" TopLine="1729"/> - </Position5> - <Position6> - <Filename Value="UFont.pas"/> - <Caret Line="1750" Column="1" TopLine="1730"/> - </Position6> - <Position7> - <Filename Value="UFont.pas"/> - <Caret Line="1751" Column="1" TopLine="1731"/> - </Position7> - <Position8> - <Filename Value="UFont.pas"/> - <Caret Line="1752" Column="1" TopLine="1732"/> - </Position8> - <Position9> - <Filename Value="UFont.pas"/> - <Caret Line="1575" Column="1" TopLine="1555"/> - </Position9> - <Position10> - <Filename Value="UFont.pas"/> - <Caret Line="1576" Column="1" TopLine="1556"/> - </Position10> - <Position11> - <Filename Value="UFont.pas"/> - <Caret Line="1578" Column="1" TopLine="1558"/> - </Position11> - <Position12> - <Filename Value="UFont.pas"/> - <Caret Line="1579" Column="1" TopLine="1559"/> - </Position12> - <Position13> - <Filename Value="UFont.pas"/> - <Caret Line="1580" Column="1" TopLine="1560"/> - </Position13> - <Position14> - <Filename Value="UFont.pas"/> - <Caret Line="1582" Column="1" TopLine="1562"/> - </Position14> - <Position15> - <Filename Value="UFont.pas"/> - <Caret Line="1583" Column="1" TopLine="1563"/> - </Position15> - <Position16> - <Filename Value="UFont.pas"/> - <Caret Line="1585" Column="1" TopLine="1565"/> - </Position16> - <Position17> - <Filename Value="UFont.pas"/> - <Caret Line="1600" Column="1" TopLine="1580"/> - </Position17> - <Position18> - <Filename Value="UFont.pas"/> - <Caret Line="1602" Column="1" TopLine="1582"/> - </Position18> - <Position19> - <Filename Value="UFont.pas"/> - <Caret Line="1603" Column="1" TopLine="1583"/> - </Position19> - <Position20> - <Filename Value="UFont.pas"/> - <Caret Line="1604" Column="1" TopLine="1584"/> - </Position20> - <Position21> - <Filename Value="UFont.pas"/> - <Caret Line="1605" Column="1" TopLine="1585"/> - </Position21> - <Position22> - <Filename Value="UFont.pas"/> - <Caret Line="1586" Column="1" TopLine="1566"/> - </Position22> - </JumpHistory> - </ProjectOptions> - <CompilerOptions> - <Version Value="5"/> - <PathDelim Value="\"/> - <SearchPaths> - <IncludeFiles Value="..\..\JEDI-SDL\SDL\Pas\"/> - </SearchPaths> - <CodeGeneration> - <Generate Value="Faster"/> - </CodeGeneration> - <Other> - <CompilerPath Value="$(CompPath)"/> - </Other> - </CompilerOptions> - <Debugging> - <BreakPoints Count="2"> - <Item1> - <Source Value="lesson43.dpr"/> - <Line Value="138"/> - </Item1> - <Item2> - <Source Value="UFont.pas"/> - <Line Value="1751"/> - </Item2> - </BreakPoints> - <Exceptions Count="2"> - <Item1> - <Name Value="ECodetoolError"/> - </Item1> - <Item2> - <Name Value="EFOpenError"/> - </Item2> - </Exceptions> - </Debugging> -</CONFIG> diff --git a/src/lib/freetype/demo/nehe/UFreeType.pas b/src/lib/freetype/demo/nehe/UFreeType.pas new file mode 100644 index 00000000..c1243aae --- /dev/null +++ b/src/lib/freetype/demo/nehe/UFreeType.pas @@ -0,0 +1,326 @@ +unit UFreeType; + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +interface + +uses + FreeType, + gl, + glu, + classes, + sysutils; + +type + // This holds all of the information related to any + // freetype font that we want to create. + TFontData = class + h: single; ///< Holds the height of the font. + textures: array of GLuint; ///< Holds the texture id's + list_base: GLuint; ///< Holds the first display list id + + // The init function will create a font of + // of the height h from the file fname. + constructor Create(const fname: string; h: cardinal); + + // Free all the resources assosiated with the font. + destructor Destroy(); override; + end; + + TFreeType = class + public + // The flagship function of the library - this thing will print + // out text at window coordinates x,y, using the font ft_font. + // The current modelview matrix will also be applied to the text. + class procedure print(ft_font: TFontData; x, y: single; const str: string); + end; + + +implementation + + +// This function gets the first power of 2 >= the +// int that we pass it. +function next_p2 ( a: integer ): integer; inline; +begin + Result := 1; + while (Result < a) do + Result := Result shl 1; +end; + +type + PAGLuint = ^AGLuint; + AGLuint = array[0..High(Word)] of GLuint; + +// Create a display list coresponding to the given character. +procedure make_dlist ( face: FT_Face; ch: byte; list_base: GLuint; tex_base: PAGLuint ); +var + i, j: integer; + width, height: integer; + glyph: FT_Glyph; + bitmap_glyph: FT_BitmapGlyph; + bitmap: PFT_Bitmap; + expanded_data: array of GLubyte; + x, y: single; +begin + // The first thing we do is get FreeType to render our character + // into a bitmap. This actually requires a couple of FreeType commands: + + // Load the Glyph for our character. + if (FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ) <> 0) then + raise Exception.create('FT_Load_Glyph failed'); + + // Move the face's glyph into a Glyph object. + if (FT_Get_Glyph( face^.glyph, glyph ) <> 0) then + raise Exception.create('FT_Get_Glyph failed'); + + // Convert the glyph to a bitmap. + FT_Glyph_To_Bitmap( glyph, ft_render_mode_normal, nil, 1 ); + bitmap_glyph := FT_BitmapGlyph(glyph); + + // This reference will make accessing the bitmap easier + bitmap := @bitmap_glyph^.bitmap; + + // Use our helper function to get the widths of + // the bitmap data that we will need in order to create + // our texture. + width := next_p2( bitmap.width ); + height := next_p2( bitmap.rows ); + + // Allocate memory for the texture data. + SetLength(expanded_data, 2 * width * height); + + // Here we fill in the data for the expanded bitmap. + // Notice that we are using two channel bitmap (one for + // luminocity and one for alpha), but we assign + // both luminocity and alpha to the value that we + // find in the FreeType bitmap. + // We use the ?: operator so that value which we use + // will be 0 if we are in the padding zone, and whatever + // is the the Freetype bitmap otherwise. + for j := 0 to height-1 do + begin + for i := 0 to width-1 do + begin + if ((i >= bitmap.width) or (j >= bitmap.rows)) then + expanded_data[2*(i+j*width)] := 0 + else + expanded_data[2*(i+j*width)] := byte(bitmap.buffer[i + bitmap.width*j]); + expanded_data[2*(i+j*width)+1] := expanded_data[2*(i+j*width)]; + end; + end; + + + // Now we just setup some texture paramaters. + glBindTexture( GL_TEXTURE_2D, tex_base[integer(ch)]); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + + // Here we actually create the texture itself, notice + // that we are using GL_LUMINANCE_ALPHA to indicate that + // we are using 2 channel data. + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, + 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, @expanded_data[0] ); + + //With the texture created, we don't need to expanded data anymore + SetLength(expanded_data, 0); + + //So now we can create the display list + glNewList(list_base+ch, GL_COMPILE); + + glBindTexture(GL_TEXTURE_2D, tex_base[ch]); + + glPushMatrix(); + + //first we need to move over a little so that + //the character has the right amount of space + //between it and the one before it. + glTranslatef(bitmap_glyph^.left, 0, 0); + + //Now we move down a little in the case that the + //bitmap extends past the bottom of the line + //(this is only true for characters like 'g' or 'y'. + glTranslatef(0, bitmap_glyph^.top - bitmap.rows, 0); + + //Now we need to account for the fact that many of + //our textures are filled with empty padding space. + //We figure what portion of the texture is used by + //the actual character and store that information in + //the x and y variables, then when we draw the + //quad, we will only reference the parts of the texture + //that we contain the character itself. + x := bitmap.width / width; + y := bitmap.rows / height; + + //Here we draw the texturemaped quads. + //The bitmap that we got from FreeType was not + //oriented quite like we would like it to be, + //so we need to link the texture to the quad + //so that the result will be properly aligned. + glBegin(GL_QUADS); + glTexCoord2d(0, 0); glVertex2f(0, bitmap.rows); + glTexCoord2d(0, y); glVertex2f(0, 0); + glTexCoord2d(x, y); glVertex2f(bitmap.width, 0); + glTexCoord2d(x, 0); glVertex2f(bitmap.width, bitmap.rows); + glEnd(); + + glPopMatrix(); + glTranslatef(face^.glyph^.advance.x shr 6, 0, 0); + + //increment the raster position as if we were a bitmap font. + //(only needed if you want to calculate text length) + //glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL); + + //Finnish the display list + glEndList(); +end; + + +constructor TFontData.Create(const fname: string; h: cardinal); +var + library_: FT_Library; + //The object in which Freetype holds information on a given + //font is called a "face". + face: FT_Face; + i: byte; +begin + //Allocate some memory to store the texture ids. + SetLength(textures, 128); + + Self.h := h; + + //Create and initilize a freetype font library. + if (FT_Init_FreeType( library_ ) <> 0) then + raise Exception.create('FT_Init_FreeType failed'); + + //This is where we load in the font information from the file. + //Of all the places where the code might die, this is the most likely, + //as FT_New_Face will die if the font file does not exist or is somehow broken. + if (FT_New_Face( library_, PChar(fname), 0, face ) <> 0) then + raise Exception.create('FT_New_Face failed (there is probably a problem with your font file)'); + + //For some twisted reason, Freetype measures font size + //in terms of 1/64ths of pixels. Thus, to make a font + //h pixels high, we need to request a size of h*64. + //(h shl 6 is just a prettier way of writting h*64) + FT_Set_Char_Size( face, h shl 6, h shl 6, 96, 96); + + //Here we ask opengl to allocate resources for + //all the textures and displays lists which we + //are about to create. + list_base := glGenLists(128); + glGenTextures( 128, @textures[0] ); + + //This is where we actually create each of the fonts display lists. + for i := 0 to 127 do + make_dlist(face, i, list_base, @textures[0]); + + //We don't need the face information now that the display + //lists have been created, so we free the assosiated resources. + FT_Done_Face(face); + + //Ditto for the library. + FT_Done_FreeType(library_); +end; + +destructor TFontData.Destroy(); +begin + glDeleteLists(list_base, 128); + glDeleteTextures(128, @textures[0]); + SetLength(textures, 0); +end; + +/// A fairly straight forward function that pushes +/// a projection matrix that will make object world +/// coordinates identical to window coordinates. +procedure pushScreenCoordinateMatrix(); inline; +var + viewport: array [0..3] of GLint; +begin + glPushAttrib(GL_TRANSFORM_BIT); + glGetIntegerv(GL_VIEWPORT, @viewport); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(viewport[0], viewport[2], viewport[1], viewport[3]); + glPopAttrib(); +end; + +/// Pops the projection matrix without changing the current +/// MatrixMode. +procedure pop_projection_matrix(); inline; +begin + glPushAttrib(GL_TRANSFORM_BIT); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); +end; + +///Much like Nehe's glPrint function, but modified to work +///with freetype fonts. +class procedure TFreeType.print(ft_font: TFontData; x, y: single; const str: string); +var + font: GLuint; + h: single; + i: cardinal; + lines: TStringList; + modelview_matrix: array[0..15] of single; +begin + // We want a coordinate system where things coresponding to window pixels. + pushScreenCoordinateMatrix(); + + font := ft_font.list_base; + h := ft_font.h / 0.63; //We make the height about 1.5* that of + + lines := TStringList.Create(); + ExtractStrings([#13], [], PChar(str), lines); + + glPushAttrib(GL_LIST_BIT or GL_CURRENT_BIT or GL_ENABLE_BIT or GL_TRANSFORM_BIT); + glMatrixMode(GL_MODELVIEW); + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glListBase(font); + + glGetFloatv(GL_MODELVIEW_MATRIX, @modelview_matrix); + + //This is where the text display actually happens. + //For each line of text we reset the modelview matrix + //so that the line's text will start in the correct position. + //Notice that we need to reset the matrix, rather than just translating + //down by h. This is because when each character is + //draw it modifies the current matrix so that the next character + //will be drawn immediatly after it. + for i := 0 to lines.Count-1 do + begin + glPushMatrix(); + glLoadIdentity(); + glTranslatef(x, y - h*i, 0); + glMultMatrixf(@modelview_matrix); + + // The commented out raster position stuff can be useful if you need to + // know the length of the text that you are creating. + // If you decide to use it make sure to also uncomment the glBitmap command + // in make_dlist(). + //glRasterPos2f(0,0); + glCallLists(Length(lines[i]), GL_UNSIGNED_BYTE, PChar(lines[i])); + //float rpos[4]; + //glGetFloatv(GL_CURRENT_RASTER_POSITION ,rpos); + //float len=x-rpos[0]; + + glPopMatrix(); + end; + + glPopAttrib(); + + pop_projection_matrix(); + + lines.Free(); +end; + +end. diff --git a/src/lib/freetype/demo/nehe/lesson43.bdsproj b/src/lib/freetype/demo/nehe/lesson43.bdsproj new file mode 100644 index 00000000..9d3851c4 --- /dev/null +++ b/src/lib/freetype/demo/nehe/lesson43.bdsproj @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="utf-8"?> +<BorlandProject> + <PersonalityInfo> + <Option> + <Option Name="Personality">Delphi.Personality</Option> + <Option Name="ProjectType">VCLApplication</Option> + <Option Name="Version">1.0</Option> + <Option Name="GUID">{3306FA70-362B-4647-A969-BCEA731F436C}</Option> + </Option> + </PersonalityInfo> + <Delphi.Personality> + <Source> + <Source Name="MainSource">lesson43.dpr</Source> + </Source> + <FileVersion> + <FileVersion Name="Version">7.0</FileVersion> + </FileVersion> + <Compiler> + <Compiler Name="A">8</Compiler> + <Compiler Name="B">0</Compiler> + <Compiler Name="C">1</Compiler> + <Compiler Name="D">1</Compiler> + <Compiler Name="E">0</Compiler> + <Compiler Name="F">0</Compiler> + <Compiler Name="G">1</Compiler> + <Compiler Name="H">1</Compiler> + <Compiler Name="I">1</Compiler> + <Compiler Name="J">0</Compiler> + <Compiler Name="K">0</Compiler> + <Compiler Name="L">1</Compiler> + <Compiler Name="M">0</Compiler> + <Compiler Name="N">1</Compiler> + <Compiler Name="O">1</Compiler> + <Compiler Name="P">1</Compiler> + <Compiler Name="Q">0</Compiler> + <Compiler Name="R">0</Compiler> + <Compiler Name="S">0</Compiler> + <Compiler Name="T">0</Compiler> + <Compiler Name="U">0</Compiler> + <Compiler Name="V">1</Compiler> + <Compiler Name="W">0</Compiler> + <Compiler Name="X">1</Compiler> + <Compiler Name="Y">1</Compiler> + <Compiler Name="Z">1</Compiler> + <Compiler Name="ShowHints">True</Compiler> + <Compiler Name="ShowWarnings">True</Compiler> + <Compiler Name="UnitAliases">WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;</Compiler> + <Compiler Name="NamespacePrefix"></Compiler> + <Compiler Name="GenerateDocumentation">False</Compiler> + <Compiler Name="DefaultNamespace"></Compiler> + <Compiler Name="SymbolDeprecated">True</Compiler> + <Compiler Name="SymbolLibrary">True</Compiler> + <Compiler Name="SymbolPlatform">True</Compiler> + <Compiler Name="SymbolExperimental">True</Compiler> + <Compiler Name="UnitLibrary">True</Compiler> + <Compiler Name="UnitPlatform">True</Compiler> + <Compiler Name="UnitDeprecated">True</Compiler> + <Compiler Name="UnitExperimental">True</Compiler> + <Compiler Name="HResultCompat">True</Compiler> + <Compiler Name="HidingMember">True</Compiler> + <Compiler Name="HiddenVirtual">True</Compiler> + <Compiler Name="Garbage">True</Compiler> + <Compiler Name="BoundsError">True</Compiler> + <Compiler Name="ZeroNilCompat">True</Compiler> + <Compiler Name="StringConstTruncated">True</Compiler> + <Compiler Name="ForLoopVarVarPar">True</Compiler> + <Compiler Name="TypedConstVarPar">True</Compiler> + <Compiler Name="AsgToTypedConst">True</Compiler> + <Compiler Name="CaseLabelRange">True</Compiler> + <Compiler Name="ForVariable">True</Compiler> + <Compiler Name="ConstructingAbstract">True</Compiler> + <Compiler Name="ComparisonFalse">True</Compiler> + <Compiler Name="ComparisonTrue">True</Compiler> + <Compiler Name="ComparingSignedUnsigned">True</Compiler> + <Compiler Name="CombiningSignedUnsigned">True</Compiler> + <Compiler Name="UnsupportedConstruct">True</Compiler> + <Compiler Name="FileOpen">True</Compiler> + <Compiler Name="FileOpenUnitSrc">True</Compiler> + <Compiler Name="BadGlobalSymbol">True</Compiler> + <Compiler Name="DuplicateConstructorDestructor">True</Compiler> + <Compiler Name="InvalidDirective">True</Compiler> + <Compiler Name="PackageNoLink">True</Compiler> + <Compiler Name="PackageThreadVar">True</Compiler> + <Compiler Name="ImplicitImport">True</Compiler> + <Compiler Name="HPPEMITIgnored">True</Compiler> + <Compiler Name="NoRetVal">True</Compiler> + <Compiler Name="UseBeforeDef">True</Compiler> + <Compiler Name="ForLoopVarUndef">True</Compiler> + <Compiler Name="UnitNameMismatch">True</Compiler> + <Compiler Name="NoCFGFileFound">True</Compiler> + <Compiler Name="ImplicitVariants">True</Compiler> + <Compiler Name="UnicodeToLocale">True</Compiler> + <Compiler Name="LocaleToUnicode">True</Compiler> + <Compiler Name="ImagebaseMultiple">True</Compiler> + <Compiler Name="SuspiciousTypecast">True</Compiler> + <Compiler Name="PrivatePropAccessor">True</Compiler> + <Compiler Name="UnsafeType">False</Compiler> + <Compiler Name="UnsafeCode">False</Compiler> + <Compiler Name="UnsafeCast">False</Compiler> + <Compiler Name="OptionTruncated">True</Compiler> + <Compiler Name="WideCharReduced">True</Compiler> + <Compiler Name="DuplicatesIgnored">True</Compiler> + <Compiler Name="UnitInitSeq">True</Compiler> + <Compiler Name="LocalPInvoke">True</Compiler> + <Compiler Name="MessageDirective">True</Compiler> + <Compiler Name="CodePage"></Compiler> + </Compiler> + <Linker> + <Linker Name="MapFile">0</Linker> + <Linker Name="OutputObjs">0</Linker> + <Linker Name="GenerateHpps">False</Linker> + <Linker Name="ConsoleApp">1</Linker> + <Linker Name="DebugInfo">False</Linker> + <Linker Name="RemoteSymbols">False</Linker> + <Linker Name="GenerateDRC">False</Linker> + <Linker Name="MinStackSize">16384</Linker> + <Linker Name="MaxStackSize">1048576</Linker> + <Linker Name="ImageBase">4194304</Linker> + <Linker Name="ExeDescription"></Linker> + </Linker> + <Directories> + <Directories Name="OutputDir"></Directories> + <Directories Name="UnitOutputDir"></Directories> + <Directories Name="PackageDLLOutputDir"></Directories> + <Directories Name="PackageDCPOutputDir"></Directories> + <Directories Name="SearchPath">../../../JEDI-SDL/SDL/Pas</Directories> + <Directories Name="Packages"></Directories> + <Directories Name="Conditionals"></Directories> + <Directories Name="DebugSourceDirs"></Directories> + <Directories Name="UsePackages">False</Directories> + </Directories> + <Parameters> + <Parameters Name="RunParams"></Parameters> + <Parameters Name="HostApplication"></Parameters> + <Parameters Name="Launcher"></Parameters> + <Parameters Name="UseLauncher">False</Parameters> + <Parameters Name="DebugCWD"></Parameters> + <Parameters Name="Debug Symbols Search Path"></Parameters> + <Parameters Name="LoadAllSymbols">True</Parameters> + <Parameters Name="LoadUnspecifiedSymbols">False</Parameters> + </Parameters> + <Language> + <Language Name="ActiveLang"></Language> + <Language Name="ProjectLang">$00000000</Language> + <Language Name="RootDir"></Language> + </Language> + <VersionInfo> + <VersionInfo Name="IncludeVerInfo">False</VersionInfo> + <VersionInfo Name="AutoIncBuild">False</VersionInfo> + <VersionInfo Name="MajorVer">1</VersionInfo> + <VersionInfo Name="MinorVer">0</VersionInfo> + <VersionInfo Name="Release">0</VersionInfo> + <VersionInfo Name="Build">0</VersionInfo> + <VersionInfo Name="Debug">False</VersionInfo> + <VersionInfo Name="PreRelease">False</VersionInfo> + <VersionInfo Name="Special">False</VersionInfo> + <VersionInfo Name="Private">False</VersionInfo> + <VersionInfo Name="DLL">False</VersionInfo> + <VersionInfo Name="Locale">1031</VersionInfo> + <VersionInfo Name="CodePage">1252</VersionInfo> + </VersionInfo> + <VersionInfoKeys> + <VersionInfoKeys Name="CompanyName"></VersionInfoKeys> + <VersionInfoKeys Name="FileDescription"></VersionInfoKeys> + <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys> + <VersionInfoKeys Name="InternalName"></VersionInfoKeys> + <VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys> + <VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys> + <VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys> + <VersionInfoKeys Name="ProductName"></VersionInfoKeys> + <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys> + <VersionInfoKeys Name="Comments"></VersionInfoKeys> + </VersionInfoKeys> + </Delphi.Personality> +</BorlandProject> diff --git a/src/lib/freetype/demo/nehe/lesson43.dpr b/src/lib/freetype/demo/nehe/lesson43.dpr new file mode 100644 index 00000000..fe296fb5 --- /dev/null +++ b/src/lib/freetype/demo/nehe/lesson43.dpr @@ -0,0 +1,289 @@ +program lesson43; +(* + * This code was created by Jeff Molofee '99 + * (ported to Linux/SDL by Ti Leggett '01) + * + * If you've found this code useful, please let me know. + * + * Visit Jeff at http://nehe.gamedev.net/ + * + * or for port-specific comments, questions, bugreports etc. + * email to leggett@eecs.tulane.edu + *) + +{$IFDEF FPC} + {$mode delphi}{$H+} +{$ENDIF} + +{$APPTYPE Console} + +uses + moduleloader in '../../../JEDI-SDL/SDL/Pas/moduleloader.pas', + SDL in '../../../JEDI-SDL/SDL/Pas/sdl.pas', + gl in '../../../JEDI-SDL/OpenGL/Pas/gl.pas', + glu in '../../../JEDI-SDL/OpenGL/Pas/glu.pas', + ctypes in '../../../ctypes/ctypes.pas', + FreeType in '../../freetype.pas', + UFreeType in 'UFreeType.pas', + math, + sysutils; + +const + // screen width, height, and bit depth + SCREEN_WIDTH = 640; + SCREEN_HEIGHT = 480; + SCREEN_BPP = 16; + +var + our_font: TFontData; + // This is our SDL surface + surface: PSDL_Surface; + cnt1, cnt2: GLfloat; + +(* function to release/destroy our resources and restoring the old desktop *) +procedure Quit(returnCode: integer); +begin + // clean up the window + SDL_Quit( ); + + // and exit appropriately + Halt( returnCode ); +end; + +(* function to reset our viewport after a window resize *) +function resizeWindow(width: integer; height: integer): boolean; +var + // Height / width ration + ratio: GLfloat; +begin + // Protect against a divide by zero + if ( height = 0 ) then + height := 1; + + ratio := width / height; + + // Setup our viewport. + glViewport( 0, 0, GLsizei(width), GLsizei(height) ); + + // change to the projection matrix and set our viewing volume. + glMatrixMode( GL_PROJECTION ); + glLoadIdentity( ); + + // Set our perspective + gluPerspective( 45.0, ratio, 0.1, 100.0 ); + + // Make sure we're chaning the model view and not the projection + glMatrixMode( GL_MODELVIEW ); + + // Reset The View + glLoadIdentity( ); + + Result := true; +end; + +(* function to handle key press events *) +procedure handleKeyPress(keysym: PSDL_keysym); +begin + case ( keysym^.sym ) of + SDLK_ESCAPE: + begin + // ESC key was pressed + Quit( 0 ); + end; + SDLK_F1: + begin + // F1 key was pressed + // this toggles fullscreen mode + SDL_WM_ToggleFullScreen( surface ); + end; + end; +end; + +(* general OpenGL initialization function *) +function initGL(): boolean; +begin + // Enable smooth shading + glShadeModel( GL_SMOOTH ); + + // Set the background black + glClearColor( 0.0, 0.0, 0.0, 0.0 ); + + // Depth buffer setup + glClearDepth( 1.0 ); + + // Enables Depth Testing + glEnable( GL_DEPTH_TEST ); + + // The Type Of Depth Test To Do + glDepthFunc( GL_LEQUAL ); + + // Really Nice Perspective Calculations + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); + + our_font := TFontData.Create('Test.ttf', 16); + + Result := true; +end; + +(* Here goes our drawing code *) +function drawGLScene(): boolean; +begin + glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer + glLoadIdentity(); // Reset The Current Modelview Matrix + glTranslatef(0.0, 0.0, -1.0); // Move One Unit Into The Screen + + // Blue Text + glColor3ub(0, 0, $ff); + + // Position The WGL Text On The Screen + glRasterPos2f(-0.40, 0.35); + + // Here We Print Some Text Using Our FreeType Font + // The only really important command is the actual print() call, + // but for the sake of making the results a bit more interesting + // I have put in some code to rotate and scale the text. + + // Red text + glColor3ub($ff, 0, 0); + + glPushMatrix(); + glLoadIdentity(); + glRotatef(cnt1, 0, 0,1); + glScalef(1, 0.8 + 0.3*cos(cnt1/5) ,1); + glTranslatef(-180, 0, 0); + TFreeType.print(our_font, 320, 240, 'Active FreeType Text - ' + FloatToStr(cnt1)); + glPopMatrix(); + + //Uncomment this to test out print's ability to handle newlines. + //TFreeType.print(our_font, 320, 200, 'Here'#13'there'#13'be'#13#13'newlines'#13'.'); + + cnt1 := cnt1 + 0.051; // Increase The First Counter + cnt2 := cnt2 + 0.005; // Increase The First Counter + + SDL_GL_SwapBuffers( ); + + Result := true; +end; + +var + // Flags to pass to SDL_SetVideoMode + videoFlags: integer; + // main loop variable + done: boolean = false; + // used to collect events + event: TSDL_Event; + // this holds some info about our display + videoInfo: PSDL_VideoInfo; + // whether or not the window is active + isActive: boolean = true; + +begin + // initialize SDL + if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) then + begin + writeln( ErrOutput, 'Video initialization failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // Fetch the video info + videoInfo := SDL_GetVideoInfo( ); + + if ( videoInfo = nil ) then + begin + writeln( ErrOutput, 'Video query failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Enable double buffering + + // the flags to pass to SDL_SetVideoMode + videoFlags := SDL_OPENGL; // Enable OpenGL in SDL + videoFlags := videoFlags or SDL_HWPALETTE; // Store the palette in hardware + videoFlags := videoFlags or SDL_RESIZABLE; // Enable window resizing + + // This checks to see if surfaces can be stored in memory + if ( videoInfo^.hw_available <> 0 ) then + videoFlags := videoFlags or SDL_HWSURFACE + else + videoFlags := videoFlags or SDL_SWSURFACE; + + // This checks if hardware blits can be done + if ( videoInfo^.blit_hw <> 0 ) then + videoFlags := videoFlags or SDL_HWACCEL; + + // Sets up OpenGL double buffering + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + // get a SDL surface + surface := SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, + videoFlags ); + + // Verify there is a surface + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Video mode set failed: ' + SDL_GetError() ); + Quit( 1 ); + end; + + // initialize OpenGL + initGL(); + + // resize the initial window + resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); + + // wait for events + while ( not done ) do + begin + { handle the events in the queue } + + while ( SDL_PollEvent( @event ) <> 0 ) do + begin + case( event.type_ ) of + SDL_ACTIVEEVENT: + begin + // Something's happend with our focus + // If we are iconified, we shouldn't draw the screen + if ( (event.active.state and SDL_APPACTIVE) <> 0 ) then + begin + if ( event.active.gain = 0 ) then + isActive := false + else + isActive := true; + end; + end; + SDL_VIDEORESIZE: + begin + // handle resize event + {$IFDEF UNIX} + surface := SDL_SetVideoMode( event.resize.w, + event.resize.h, + 16, videoFlags ); + if ( surface = nil ) then + begin + writeln( ErrOutput, 'Could not get a surface after resize: ' + SDL_GetError( ) ); + Quit( 1 ); + end; + {$ENDIF} + resizeWindow( event.resize.w, event.resize.h ); + end; + SDL_KEYDOWN: + begin + // handle key presses + handleKeyPress( @event.key.keysym ); + end; + SDL_QUITEV: + begin + // handle quit requests + done := true; + end; + end; + end; + + // draw the scene + if ( isActive ) then + drawGLScene( ); + end; + + // clean ourselves up and exit + Quit( 0 ); +end. diff --git a/src/lib/freetype/demo/nehe/readme.txt b/src/lib/freetype/demo/nehe/readme.txt new file mode 100644 index 00000000..1186ef0e --- /dev/null +++ b/src/lib/freetype/demo/nehe/readme.txt @@ -0,0 +1,9 @@ +Pascal conversion of the NeHe tutorial lesson 43 (Tutorial on using FreeType Fonts in OpenGL) +http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43 + +Put the following DLLs into this directory: +- libfreetype-6.dll +- SDL.dll +- zlib1.dll + +and copy a TrueType font to this directory and rename it into "Test.ttf". diff --git a/src/lib/freetype/demo/switches.inc b/src/lib/freetype/demo/switches.inc new file mode 100644 index 00000000..0a940004 --- /dev/null +++ b/src/lib/freetype/demo/switches.inc @@ -0,0 +1 @@ +{$DEFINE FREETYPE_DEMO} -- cgit v1.2.3 From e8a388e32a4563ac9ea0895ca6c7cdf83cf9d3ec Mon Sep 17 00:00:00 2001 From: tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Tue, 28 Oct 2008 18:57:02 +0000 Subject: - glPrint(Pchar) -> glPrint(string) - glPrintLetter removed - font engine handles FT_PIXEL_MODE_MONO as FT_Glyph_To_Bitmap(FT_RENDER_MODE_NORMAL) might return a 1bit/pixel black/white image instead of 8bit/pixel gray shaded one (happened with 16px japanese glyphs of simsun.ttf, latin ones were correct). git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1482 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/freetype.pas | 141 +++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 62 deletions(-) (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/freetype.pas b/src/lib/freetype/freetype.pas index 65cce749..5263bd92 100644 --- a/src/lib/freetype/freetype.pas +++ b/src/lib/freetype/freetype.pas @@ -68,6 +68,11 @@ type PFT_Short = ^FT_Short; PFT_String = ^FT_String; + + TByteArray = array [0 .. (MaxInt div SizeOf(byte))-1] of byte; + PByteArray = ^TByteArray; + + (*************************************************************************) (* *) (* <Enum> *) @@ -563,6 +568,74 @@ const (* *) type FT_Render_Mode = FT_Int; +const + FT_RENDER_MODE_NORMAL = 0; + FT_RENDER_MODE_LIGHT = FT_RENDER_MODE_NORMAL + 1; + FT_RENDER_MODE_MONO = FT_RENDER_MODE_LIGHT + 1; + FT_RENDER_MODE_LCD = FT_RENDER_MODE_MONO + 1; + FT_RENDER_MODE_LCD_V = FT_RENDER_MODE_LCD + 1; + FT_RENDER_MODE_MAX = FT_RENDER_MODE_LCD_V + 1; + + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Pixel_Mode *) + (* *) + (* <Description> *) + (* An enumeration type used to describe the format of pixels in a *) + (* given bitmap. Note that additional formats may be added in the *) + (* future. *) + (* *) + (* <Values> *) + (* FT_PIXEL_MODE_NONE :: *) + (* Value 0 is reserved. *) + (* *) + (* FT_PIXEL_MODE_MONO :: *) + (* A monochrome bitmap, using 1 bit per pixel. Note that pixels *) + (* are stored in most-significant order (MSB), which means that *) + (* the left-most pixel in a byte has value 128. *) + (* *) + (* FT_PIXEL_MODE_GRAY :: *) + (* An 8-bit bitmap, generally used to represent anti-aliased glyph *) + (* images. Each pixel is stored in one byte. Note that the number *) + (* of value `gray' levels is stored in the `num_bytes' field of *) + (* the @FT_Bitmap structure (it generally is 256). *) + (* *) + (* FT_PIXEL_MODE_GRAY2 :: *) + (* A 2-bit/pixel bitmap, used to represent embedded anti-aliased *) + (* bitmaps in font files according to the OpenType specification. *) + (* We haven't found a single font using this format, however. *) + (* *) + (* FT_PIXEL_MODE_GRAY4 :: *) + (* A 4-bit/pixel bitmap, used to represent embedded anti-aliased *) + (* bitmaps in font files according to the OpenType specification. *) + (* We haven't found a single font using this format, however. *) + (* *) + (* FT_PIXEL_MODE_LCD :: *) + (* An 8-bit bitmap, used to represent RGB or BGR decimated glyph *) + (* images used for display on LCD displays; the bitmap is three *) + (* times wider than the original glyph image. See also *) + (* @FT_RENDER_MODE_LCD. *) + (* *) + (* FT_PIXEL_MODE_LCD_V :: *) + (* An 8-bit bitmap, used to represent RGB or BGR decimated glyph *) + (* images used for display on rotated LCD displays; the bitmap *) + (* is three times taller than the original glyph image. See also *) + (* @FT_RENDER_MODE_LCD_V. *) + (* *) +type + FT_Pixel_Mode = byte; +const + FT_PIXEL_MODE_NONE = 0; + FT_PIXEL_MODE_MONO = FT_PIXEL_MODE_NONE + 1; + FT_PIXEL_MODE_GRAY = FT_PIXEL_MODE_MONO + 1; + FT_PIXEL_MODE_GRAY2 = FT_PIXEL_MODE_GRAY + 1; + FT_PIXEL_MODE_GRAY4 = FT_PIXEL_MODE_GRAY2 + 1; + FT_PIXEL_MODE_LCD = FT_PIXEL_MODE_GRAY4 + 1; + FT_PIXEL_MODE_LCD_V = FT_PIXEL_MODE_LCD + 1; + + FT_PIXEL_MODE_MAX = FT_PIXEL_MODE_LCD_V + 1; (* do not remove *) (*************************************************************************) @@ -601,6 +674,7 @@ type (* vertAdvance :: *) (* Advance height for vertical layout. *) (* *) +type FT_Glyph_Metrics = record width , height : FT_Pos; @@ -809,10 +883,10 @@ type rows , width : FT_Int; pitch : FT_Int; - buffer : PChar; + buffer : PByteArray; num_grays : FT_Short; pixel_mode , - palette_mode : char; + palette_mode : byte; palette : pointer; end; @@ -1719,7 +1793,7 @@ type (* @macro: *) (* FT_CURVE_TAG ( flag ) *) (* *) - function FT_CURVE_TAG (flag : char ) : char; + function FT_CURVE_TAG(flag: byte): byte; const FT_CURVE_TAG_ON = 1; @@ -2027,63 +2101,6 @@ const load_flags : FT_Int32 ) : FT_Error; cdecl; external ft_lib name 'FT_Load_Glyph'; - (*************************************************************************) - (* *) - (* <Enum> *) - (* FT_Render_Mode *) - (* *) - (* <Description> *) - (* An enumeration type that lists the render modes supported by *) - (* FreeType 2. Each mode corresponds to a specific type of scanline *) - (* conversion performed on the outline, as well as specific *) - (* hinting optimizations. *) - (* *) - (* For bitmap fonts the `bitmap->pixel_mode' field in the *) - (* @FT_GlyphSlotRec structure gives the format of the returned *) - (* bitmap. *) - (* *) - (* <Values> *) - (* FT_RENDER_MODE_NORMAL :: *) - (* This is the default render mode; it corresponds to 8-bit *) - (* anti-aliased bitmaps, using 256 levels of opacity. *) - (* *) - (* FT_RENDER_MODE_LIGHT :: *) - (* This is similar to @FT_RENDER_MODE_NORMAL -- you have to use *) - (* @FT_LOAD_TARGET_LIGHT in calls to @FT_Load_Glyph to get any *) - (* effect since the rendering process no longer influences the *) - (* positioning of glyph outlines. *) - (* *) - (* The resulting glyph shapes are more similar to the original, *) - (* while being a bit more fuzzy (`better shapes' instead of `better *) - (* contrast', so to say. *) - (* *) - (* FT_RENDER_MODE_MONO :: *) - (* This mode corresponds to 1-bit bitmaps. *) - (* *) - (* FT_RENDER_MODE_LCD :: *) - (* This mode corresponds to horizontal RGB/BGR sub-pixel displays, *) - (* like LCD-screens. It produces 8-bit bitmaps that are 3 times *) - (* the width of the original glyph outline in pixels, and which use *) - (* the @FT_PIXEL_MODE_LCD mode. *) - (* *) - (* FT_RENDER_MODE_LCD_V :: *) - (* This mode corresponds to vertical RGB/BGR sub-pixel displays *) - (* (like PDA screens, rotated LCD displays, etc.). It produces *) - (* 8-bit bitmaps that are 3 times the height of the original *) - (* glyph outline in pixels and use the @FT_PIXEL_MODE_LCD_V mode. *) - (* *) - (* <Note> *) - (* The LCD-optimized glyph bitmaps produced by FT_Render_Glyph are *) - (* _not filtered_ to reduce color-fringes. It is up to the caller to *) - (* perform this pass. *) - (* *) -const - FT_RENDER_MODE_NORMAL = 0; - FT_RENDER_MODE_LIGHT = FT_RENDER_MODE_NORMAL + 1; - FT_RENDER_MODE_MONO = FT_RENDER_MODE_LIGHT + 1; - FT_RENDER_MODE_LCD = FT_RENDER_MODE_MONO + 1; - FT_RENDER_MODE_LCD_V = FT_RENDER_MODE_LCD + 1; - FT_RENDER_MODE_MAX = FT_RENDER_MODE_LCD_V + 1; (*************************************************************************) (* *) @@ -2482,9 +2499,9 @@ implementation { FT_CURVE_TAG } -function FT_CURVE_TAG(flag : char ) : char; +function FT_CURVE_TAG(flag: byte): byte; begin - result := char(byte(flag) and 3); + result := flag and 3; end; { FT_IS_SCALABLE } -- cgit v1.2.3 From 54267195b2c73ef9f4b56d0657e0866b441e5b4f Mon Sep 17 00:00:00 2001 From: k-m_schindler <k-m_schindler@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Tue, 28 Oct 2008 23:09:15 +0000 Subject: linklib changed to freetype for darwin, svn:eol-style set to native git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1486 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/freetype.pas | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/freetype.pas b/src/lib/freetype/freetype.pas index 5263bd92..6a9d2062 100644 --- a/src/lib/freetype/freetype.pas +++ b/src/lib/freetype/freetype.pas @@ -36,13 +36,13 @@ uses const {$IF Defined(MSWINDOWS)} - ft_lib = 'libfreetype-6.dll'; -{$ELSEIF Defined(DARWIN)} - ft_lib = 'libfreetype.dylib'; - {$LINKLIB libftgl} -{$ELSEIF Defined(UNIX)} - ft_lib = 'freetype.so'; -{$IFEND} + ft_lib = 'libfreetype-6.dll'; +{$ELSEIF Defined(DARWIN)} + ft_lib = 'libfreetype.dylib'; + {$LINKLIB libfreetype} +{$ELSEIF Defined(UNIX)} + ft_lib = 'freetype.so'; +{$IFEND} type FT_Byte = cuchar; -- cgit v1.2.3 From 917901e8e33438c425aef50a0a7417f32d77b760 Mon Sep 17 00:00:00 2001 From: s_alexander <s_alexander@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Mon, 9 Nov 2009 00:27:55 +0000 Subject: merged unicode branch (r1931) into trunk git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1939 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/demo/engine-test.bdsproj | 14 +- src/lib/freetype/demo/engine-test.dpr | 16 +- src/lib/freetype/demo/engine-test.lpi | 39 +- src/lib/freetype/freetype.pas | 911 ++++-------------------------- src/lib/freetype/ftconfig.inc | 35 ++ src/lib/freetype/ftglyph.inc | 435 ++++++++++++++ src/lib/freetype/ftimage.inc | 803 ++++++++++++++++++++++++++ src/lib/freetype/ftoutln.inc | 497 ++++++++++++++++ src/lib/freetype/ftstroke.inc | 711 +++++++++++++++++++++++ src/lib/freetype/fttypes.inc | 311 ++++++++++ 10 files changed, 2950 insertions(+), 822 deletions(-) create mode 100644 src/lib/freetype/ftconfig.inc create mode 100644 src/lib/freetype/ftglyph.inc create mode 100644 src/lib/freetype/ftimage.inc create mode 100644 src/lib/freetype/ftoutln.inc create mode 100644 src/lib/freetype/ftstroke.inc create mode 100644 src/lib/freetype/fttypes.inc (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/demo/engine-test.bdsproj b/src/lib/freetype/demo/engine-test.bdsproj index 9547f18f..e5b3e97d 100644 --- a/src/lib/freetype/demo/engine-test.bdsproj +++ b/src/lib/freetype/demo/engine-test.bdsproj @@ -27,13 +27,13 @@ <Compiler Name="I">1</Compiler> <Compiler Name="J">0</Compiler> <Compiler Name="K">0</Compiler> - <Compiler Name="L">1</Compiler> - <Compiler Name="M">0</Compiler> - <Compiler Name="N">1</Compiler> - <Compiler Name="O">0</Compiler> - <Compiler Name="P">1</Compiler> - <Compiler Name="Q">0</Compiler> - <Compiler Name="R">0</Compiler> + <Compiler Name="L">1</Compiler> + <Compiler Name="M">0</Compiler> + <Compiler Name="N">1</Compiler> + <Compiler Name="O">1</Compiler> + <Compiler Name="P">1</Compiler> + <Compiler Name="Q">0</Compiler> + <Compiler Name="R">0</Compiler> <Compiler Name="S">0</Compiler> <Compiler Name="T">0</Compiler> <Compiler Name="U">0</Compiler> diff --git a/src/lib/freetype/demo/engine-test.dpr b/src/lib/freetype/demo/engine-test.dpr index 80177735..bbd7d890 100644 --- a/src/lib/freetype/demo/engine-test.dpr +++ b/src/lib/freetype/demo/engine-test.dpr @@ -27,7 +27,9 @@ uses ctypes in '../../ctypes/ctypes.pas', {$ENDIF} FreeType in '../freetype.pas', - UFont in '../../../base/UFont.pas', + UFont in 'UFont.pas', + //UFont in '../../../base/UFont.pas', + UUnicodeUtils in '../../../base/UUnicodeUtils.pas', math, sysutils; @@ -41,7 +43,7 @@ const //FONT_FILE = 'C:/Windows/Fonts/Arial.ttf'; //FONT_FILE = 'C:/Windows/Fonts/SimSun.ttf'; //FONT_FILE = 'eurostarregularextended.ttf'; - FONT_FILE = 'FreeSans.ttf'; + FONT_FILE = '../../../../game/fonts/FreeSans/FreeSans.ttf'; var OurFont: TScalableFont; @@ -129,11 +131,11 @@ begin // Really Nice Perspective Calculations glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); - //OurFont := TFTScalableFont.Create(FONT_FILE, 64); + OurFont := TFTScalableFont.Create(FONT_FILE, 64, 0.03); //OurFont := TFTFont.Create(FONT_FILE, 128); - OurFont := TFTScalableOutlineFont.Create(FONT_FILE, 64, 0.05); + //OurFont := TFTScalableOutlineFont.Create(FONT_FILE, 64, 0.03); //OurFont.UseKerning := false; - TFTScalableOutlineFont(OurFont).SetOutlineColor(1, 0, 0); + //TFTScalableOutlineFont(OurFont).SetOutlineColor(1, 0, 0, 1); //OurFont := TOutlineFont.Create(FONT_FILE, 32, 2); //OurFont.LineSpacing := OurFont.LineSpacing * 0.5; @@ -183,7 +185,7 @@ begin //OurFont.SetOutlineColor(0.5, 0.5, 0.5); //OurFont.ReflectionSpacing := -4; //OurFont.UseKerning := false; - OurFont.Height := 64;//cnt2; + OurFont.Height := 150;//cnt2; //OurFont.Reset; //OurFont.Aspect := 2; @@ -191,7 +193,7 @@ begin bounds := OurFont.BBox(msg); //glRectf(bounds.Left, OurFont.Ascender, bounds.Right, OurFont.Ascender-OurFont.Height); - glColor3f(1, 1, 1); + glColor4f(1, 1, 1, 1); //OurFont.ReflectionSpacing := 0; OurFont.Print(msg); diff --git a/src/lib/freetype/demo/engine-test.lpi b/src/lib/freetype/demo/engine-test.lpi index 6cbfe1eb..45483a56 100644 --- a/src/lib/freetype/demo/engine-test.lpi +++ b/src/lib/freetype/demo/engine-test.lpi @@ -28,14 +28,14 @@ </local> </RunParams> <Units Count="16"> - <Unit0> - <Filename Value="engine-test.dpr"/> - <IsPartOfProject Value="True"/> - <CursorPos X="25" Y="135"/> - <TopLine Value="118"/> - <EditorIndex Value="0"/> - <UsageCount Value="72"/> - <Loaded Value="True"/> + <Unit0> + <Filename Value="engine-test.dpr"/> + <IsPartOfProject Value="True"/> + <CursorPos X="18" Y="25"/> + <TopLine Value="1"/> + <EditorIndex Value="0"/> + <UsageCount Value="72"/> + <Loaded Value="True"/> </Unit0> <Unit1> <Filename Value="JEDI-SDL\OpenGL\Pas\opengl12.pas"/> @@ -139,13 +139,22 @@ <UnitName Value="UFont"/> <CursorPos X="15" Y="1752"/> <TopLine Value="1734"/> - <UsageCount Value="10"/> - </Unit15> - </Units> - <JumpHistory Count="0" HistoryIndex="-1"/> - </ProjectOptions> - <CompilerOptions> - <Version Value="8"/> + <UsageCount Value="10"/> + </Unit15> + </Units> + <JumpHistory Count="2" HistoryIndex="1"> + <Position1> + <Filename Value="engine-test.dpr"/> + <Caret Line="52" Column="10" TopLine="37"/> + </Position1> + <Position2> + <Filename Value="engine-test.dpr"/> + <Caret Line="1" Column="1" TopLine="1"/> + </Position2> + </JumpHistory> + </ProjectOptions> + <CompilerOptions> + <Version Value="8"/> <PathDelim Value="\"/> <SearchPaths> <IncludeFiles Value="..\..\JEDI-SDL\SDL\Pas\"/> diff --git a/src/lib/freetype/freetype.pas b/src/lib/freetype/freetype.pas index 6a9d2062..6aaa3b59 100644 --- a/src/lib/freetype/freetype.pas +++ b/src/lib/freetype/freetype.pas @@ -1,23 +1,42 @@ -//---------------------------------------------------------------------------- -// FreeType2 pascal header -//---------------------------------------------------------------------------- -// Anti-Grain Geometry - Version 2.4 (Public License) -// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) -// -// Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) -// Pascal Port By: Milan Marusinec alias Milano -// milan@marusinec.sk -// http://www.aggpas.org -// Copyright (c) 2005-2007 -// -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. -// -//---------------------------------------------------------------------------- -// Adapted by the UltraStar Deluxe Team -//---------------------------------------------------------------------------- +(***************************************************************************) +(* *) +(* freetype.h *) +(* *) +(* FreeType high-level API and common types (specification only). *) +(* *) +(* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by *) +(* David Turner, Robert Wilhelm, and Werner Lemberg. *) +(* *) +(* This file is part of the FreeType project, and may only be used, *) +(* modified, and distributed under the terms of the FreeType project *) +(* license, LICENSE.TXT. By continuing to use, modify, or distribute *) +(* this file you indicate that you have read the license and *) +(* understand and accept it fully. *) +(* *) +(***************************************************************************) + +(***************************************************************************) +(* Initial Pascal port by *) +(***************************************************************************) +(* Anti-Grain Geometry - Version 2.4 (Public License) *) +(* Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) *) +(* *) +(* Anti-Grain Geometry - Version 2.4 Release Milano 3 (AggPas 2.4 RM3) *) +(* Pascal Port By: Milan Marusinec alias Milano *) +(* milan@marusinec.sk *) +(* http://www.aggpas.org *) +(* Copyright (c) 2005-2007 *) +(* *) +(* Permission to copy, use, modify, sell and distribute this software *) +(* is granted provided this copyright notice appears in all copies. *) +(* This software is provided "as is" without express or implied *) +(* warranty, and with no claim as to its suitability for any purpose. *) +(* *) +(***************************************************************************) + +(***************************************************************************) +(* Extended by the UltraStar Deluxe Team *) +(***************************************************************************) unit freetype; @@ -36,7 +55,7 @@ uses const {$IF Defined(MSWINDOWS)} - ft_lib = 'libfreetype-6.dll'; + ft_lib = 'freetype6.dll'; {$ELSEIF Defined(DARWIN)} ft_lib = 'libfreetype.dylib'; {$LINKLIB libfreetype} @@ -45,32 +64,24 @@ const {$IFEND} type - FT_Byte = cuchar; - FT_Short = csshort; - FT_UShort = cushort; - FT_Int = csint; - FT_UInt = cuint; - FT_Int16 = cint16; - FT_UInt16 = cuint16; - FT_Int32 = cint32; - FT_UInt32 = cuint32; - FT_Long = cslong; - FT_ULong = culong; - - FT_Fixed = cslong; - FT_Pos = cslong; - FT_Error = cint; - FT_F26Dot6 = cslong; - FT_String = cchar; - FT_Bool = cuchar; - - PFT_Byte = ^FT_Byte; - PFT_Short = ^FT_Short; - PFT_String = ^FT_String; - - - TByteArray = array [0 .. (MaxInt div SizeOf(byte))-1] of byte; - PByteArray = ^TByteArray; + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Library *) + (* *) + (* <Description> *) + (* A handle to a FreeType library instance. Each `library' is *) + (* completely independent from the others; it is the `root' of a set *) + (* of objects like fonts, faces, sizes, etc. *) + (* *) + (* It also embeds a memory manager (see @FT_Memory), as well as a *) + (* scan-line converter object (see @FT_Raster). *) + (* *) + (* <Note> *) + (* Library objects are normally created by @FT_Init_FreeType, and *) + (* destroyed with @FT_Done_FreeType. *) + (* *) + FT_Library = Pointer; (*************************************************************************) @@ -290,54 +301,6 @@ const FT_ENCODING_WANSUNG: FT_Encoding = ('w', 'a', 'n', 's'); FT_ENCODING_JOHAB: FT_Encoding = ('j', 'o', 'h', 'a'); - (*************************************************************************) - (* *) - (* <Enum> *) - (* FT_Glyph_Format *) - (* *) - (* <Description> *) - (* An enumeration type used to describe the format of a given glyph *) - (* image. Note that this version of FreeType only supports two image *) - (* formats, even though future font drivers will be able to register *) - (* their own format. *) - (* *) - (* <Values> *) - (* FT_GLYPH_FORMAT_NONE :: *) - (* The value 0 is reserved and does describe a glyph format. *) - (* *) - (* FT_GLYPH_FORMAT_COMPOSITE :: *) - (* The glyph image is a composite of several other images. This *) - (* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to *) - (* report compound glyphs (like accented characters). *) - (* *) - (* FT_GLYPH_FORMAT_BITMAP :: *) - (* The glyph image is a bitmap, and can be described as an *) - (* @FT_Bitmap. You generally need to access the `bitmap' field of *) - (* the @FT_GlyphSlotRec structure to read it. *) - (* *) - (* FT_GLYPH_FORMAT_OUTLINE :: *) - (* The glyph image is a vertorial outline made of line segments *) - (* and Bezier arcs; it can be described as an @FT_Outline; you *) - (* generally want to access the `outline' field of the *) - (* @FT_GlyphSlotRec structure to read it. *) - (* *) - (* FT_GLYPH_FORMAT_PLOTTER :: *) - (* The glyph image is a vectorial path with no inside/outside *) - (* contours. Some Type 1 fonts, like those in the Hershey family, *) - (* contain glyphs in this format. These are described as *) - (* @FT_Outline, but FreeType isn't currently capable of rendering *) - (* them correctly. *) - (* *) -type - FT_Glyph_Format = array[0..3] of char; -const - FT_GLYPH_FORMAT_NONE: FT_Glyph_Format = (#0, #0, #0, #0 ); - - FT_GLYPH_FORMAT_COMPOSITE: FT_Glyph_Format = ('c', 'o', 'm', 'p' ); - FT_GLYPH_FORMAT_BITMAP: FT_Glyph_Format = ('b', 'i', 't', 's' ); - FT_GLYPH_FORMAT_OUTLINE: FT_Glyph_Format = ('o', 'u', 't', 'l' ); - FT_GLYPH_FORMAT_PLOTTER: FT_Glyph_Format = ('p', 'l', 'o', 't' ); - (*************************************************************************) (* *) @@ -358,7 +321,7 @@ const const FT_STYLE_FLAG_ITALIC = 1 shl 0; FT_STYLE_FLAG_BOLD = 1 shl 1; - + (*************************************************************************** * @@ -567,7 +530,7 @@ const (* perform this pass. *) (* *) type - FT_Render_Mode = FT_Int; + FT_Render_Mode = cint; const FT_RENDER_MODE_NORMAL = 0; FT_RENDER_MODE_LIGHT = FT_RENDER_MODE_NORMAL + 1; @@ -579,63 +542,34 @@ const (*************************************************************************) (* *) - (* <Enum> *) - (* FT_Pixel_Mode *) + (* <Type> *) + (* FT_GlyphSlot *) (* *) (* <Description> *) - (* An enumeration type used to describe the format of pixels in a *) - (* given bitmap. Note that additional formats may be added in the *) - (* future. *) + (* A handle to a given `glyph slot'. A slot is a container where it *) + (* is possible to load any one of the glyphs contained in its parent *) + (* face. *) (* *) - (* <Values> *) - (* FT_PIXEL_MODE_NONE :: *) - (* Value 0 is reserved. *) - (* *) - (* FT_PIXEL_MODE_MONO :: *) - (* A monochrome bitmap, using 1 bit per pixel. Note that pixels *) - (* are stored in most-significant order (MSB), which means that *) - (* the left-most pixel in a byte has value 128. *) - (* *) - (* FT_PIXEL_MODE_GRAY :: *) - (* An 8-bit bitmap, generally used to represent anti-aliased glyph *) - (* images. Each pixel is stored in one byte. Note that the number *) - (* of value `gray' levels is stored in the `num_bytes' field of *) - (* the @FT_Bitmap structure (it generally is 256). *) - (* *) - (* FT_PIXEL_MODE_GRAY2 :: *) - (* A 2-bit/pixel bitmap, used to represent embedded anti-aliased *) - (* bitmaps in font files according to the OpenType specification. *) - (* We haven't found a single font using this format, however. *) - (* *) - (* FT_PIXEL_MODE_GRAY4 :: *) - (* A 4-bit/pixel bitmap, used to represent embedded anti-aliased *) - (* bitmaps in font files according to the OpenType specification. *) - (* We haven't found a single font using this format, however. *) - (* *) - (* FT_PIXEL_MODE_LCD :: *) - (* An 8-bit bitmap, used to represent RGB or BGR decimated glyph *) - (* images used for display on LCD displays; the bitmap is three *) - (* times wider than the original glyph image. See also *) - (* @FT_RENDER_MODE_LCD. *) - (* *) - (* FT_PIXEL_MODE_LCD_V :: *) - (* An 8-bit bitmap, used to represent RGB or BGR decimated glyph *) - (* images used for display on rotated LCD displays; the bitmap *) - (* is three times taller than the original glyph image. See also *) - (* @FT_RENDER_MODE_LCD_V. *) + (* In other words, each time you call @FT_Load_Glyph or *) + (* @FT_Load_Char, the slot's content is erased by the new glyph data, *) + (* i.e. the glyph's metrics, its image (bitmap or outline), and *) + (* other control information. *) + (* *) + (* <Also> *) + (* @FT_GlyphSlotRec details the publicly accessible glyph fields. *) (* *) type - FT_Pixel_Mode = byte; -const - FT_PIXEL_MODE_NONE = 0; - FT_PIXEL_MODE_MONO = FT_PIXEL_MODE_NONE + 1; - FT_PIXEL_MODE_GRAY = FT_PIXEL_MODE_MONO + 1; - FT_PIXEL_MODE_GRAY2 = FT_PIXEL_MODE_GRAY + 1; - FT_PIXEL_MODE_GRAY4 = FT_PIXEL_MODE_GRAY2 + 1; - FT_PIXEL_MODE_LCD = FT_PIXEL_MODE_GRAY4 + 1; - FT_PIXEL_MODE_LCD_V = FT_PIXEL_MODE_LCD + 1; + FT_GlyphSlot = ^FT_GlyphSlotRec; - FT_PIXEL_MODE_MAX = FT_PIXEL_MODE_LCD_V + 1; (* do not remove *) + +{$DEFINE TYPE_DECL} +{$I ftconfig.inc} +{$I fttypes.inc} +{$I ftimage.inc} +{$I ftglyph.inc} +{$I ftstroke.inc} +{$I ftoutln.inc} +{$UNDEF TYPE_DECL} (*************************************************************************) @@ -674,7 +608,6 @@ const (* vertAdvance :: *) (* Advance height for vertical layout. *) (* *) -type FT_Glyph_Metrics = record width , height : FT_Pos; @@ -757,140 +690,6 @@ type AFT_Bitmap_Size = array[0..High(Word)] of FT_Bitmap_Size; - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_Vector *) - (* *) - (* <Description> *) - (* A simple structure used to store a 2D vector; coordinates are of *) - (* the FT_Pos type. *) - (* *) - (* <Fields> *) - (* x :: The horizontal coordinate. *) - (* y :: The vertical coordinate. *) - (* *) - PFT_Vector = ^FT_Vector; - FT_Vector = record - x , - y : FT_Pos; - end; - - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_Outline *) - (* *) - (* <Description> *) - (* This structure is used to describe an outline to the scan-line *) - (* converter. *) - (* *) - (* <Fields> *) - (* n_contours :: The number of contours in the outline. *) - (* *) - (* n_points :: The number of points in the outline. *) - (* *) - (* points :: A pointer to an array of `n_points' FT_Vector *) - (* elements, giving the outline's point coordinates. *) - (* *) - (* tags :: A pointer to an array of `n_points' chars, giving *) - (* each outline point's type. If bit 0 is unset, the *) - (* point is `off' the curve, i.e. a Bezier control *) - (* point, while it is `on' when set. *) - (* *) - (* Bit 1 is meaningful for `off' points only. If set, *) - (* it indicates a third-order Bezier arc control point; *) - (* and a second-order control point if unset. *) - (* *) - (* contours :: An array of `n_contours' shorts, giving the end *) - (* point of each contour within the outline. For *) - (* example, the first contour is defined by the points *) - (* `0' to `contours[0]', the second one is defined by *) - (* the points `contours[0]+1' to `contours[1]', etc. *) - (* *) - (* flags :: A set of bit flags used to characterize the outline *) - (* and give hints to the scan-converter and hinter on *) - (* how to convert/grid-fit it. See FT_Outline_Flags. *) - (* *) - PFT_Outline = ^FT_Outline; - FT_Outline = record - n_contours : FT_Short; - n_points : FT_Short; - - points : PFT_Vector; - tags : PChar; - contours : PFT_Short; - - flags : FT_Int; - end; - - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_Bitmap *) - (* *) - (* <Description> *) - (* A structure used to describe a bitmap or pixmap to the raster. *) - (* Note that we now manage pixmaps of various depths through the *) - (* `pixel_mode' field. *) - (* *) - (* <Fields> *) - (* rows :: The number of bitmap rows. *) - (* *) - (* width :: The number of pixels in bitmap row. *) - (* *) - (* pitch :: The pitch's absolute value is the number of bytes *) - (* taken by one bitmap row, including padding. *) - (* However, the pitch is positive when the bitmap has *) - (* a `down' flow, and negative when it has an `up' *) - (* flow. In all cases, the pitch is an offset to add *) - (* to a bitmap pointer in order to go down one row. *) - (* *) - (* buffer :: A typeless pointer to the bitmap buffer. This *) - (* value should be aligned on 32-bit boundaries in *) - (* most cases. *) - (* *) - (* num_grays :: This field is only used with *) - (* `FT_PIXEL_MODE_GRAY'; it gives the number of gray *) - (* levels used in the bitmap. *) - (* *) - (* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. *) - (* See @FT_Pixel_Mode for possible values. *) - (* *) - (* palette_mode :: This field is only used with paletted pixel modes; *) - (* it indicates how the palette is stored. *) - (* *) - (* palette :: A typeless pointer to the bitmap palette; only *) - (* used for paletted pixel modes. *) - (* *) - (* <Note> *) - (* For now, the only pixel mode supported by FreeType are mono and *) - (* grays. However, drivers might be added in the future to support *) - (* more `colorful' options. *) - (* *) - (* When using pixel modes pal2, pal4 and pal8 with a void `palette' *) - (* field, a gray pixmap with respectively 4, 16, and 256 levels of *) - (* gray is assumed. This, in order to be compatible with some *) - (* embedded bitmap formats defined in the TrueType specification. *) - (* *) - (* Note that no font was found presenting such embedded bitmaps, so *) - (* this is currently completely unhandled by the library. *) - (* *) - PFT_Bitmap = ^FT_Bitmap; - FT_Bitmap = record - rows , - width : FT_Int; - pitch : FT_Int; - buffer : PByteArray; - num_grays : FT_Short; - pixel_mode , - palette_mode : byte; - palette : pointer; - end; - - (*************************************************************************) (* *) (* <Type> *) @@ -950,184 +749,11 @@ type PAFT_CharMap = ^FT_CharMap; AFT_CharMap = array[0..High(Word)] of FT_CharMap; - (*************************************************************************) - (* *) - (* <Type> *) - (* FT_Library *) - (* *) - (* <Description> *) - (* A handle to a FreeType library instance. Each `library' is *) - (* completely independent from the others; it is the `root' of a set *) - (* of objects like fonts, faces, sizes, etc. *) - (* *) - (* It also embeds a memory manager (see @FT_Memory), as well as a *) - (* scan-line converter object (see @FT_Raster). *) - (* *) - (* <Note> *) - (* Library objects are normally created by @FT_Init_FreeType, and *) - (* destroyed with @FT_Done_FreeType. *) - (* *) - FT_Library = ^FT_LibraryRec; - FT_LibraryRec = record // internal - end; - (*************************************************************************) - (* *) - (* <Section> *) - (* glyph_management *) - (* *) - (* <Title> *) - (* Glyph Management *) - (* *) - (* <Abstract> *) - (* Generic interface to manage individual glyph data. *) - (* *) - (* <Description> *) - (* This section contains definitions used to manage glyph data *) - (* through generic FT_Glyph objects. Each of them can contain a *) - (* bitmap, a vector outline, or even images in other formats. *) - (* *) - (*************************************************************************) - (* forward declaration to a private type *) - PFT_Glyph_Class = ^FT_Glyph_Class; - FT_Glyph_Class = record // internal - end; - (*************************************************************************) - (* *) - (* <Type> *) - (* FT_Glyph *) - (* *) - (* <Description> *) - (* Handle to an object used to model generic glyph images. It is a *) - (* pointer to the @FT_GlyphRec structure and can contain a glyph *) - (* bitmap or pointer. *) - (* *) - (* <Note> *) - (* Glyph objects are not owned by the library. You must thus release *) - (* them manually (through @FT_Done_Glyph) _before_ calling *) - (* @FT_Done_FreeType. *) - (* *) - FT_Glyph = ^FT_GlyphRec; - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_GlyphRec *) - (* *) - (* <Description> *) - (* The root glyph structure contains a given glyph image plus its *) - (* advance width in 16.16 fixed float format. *) - (* *) - (* <Fields> *) - (* library :: A handle to the FreeType library object. *) - (* *) - (* clazz :: A pointer to the glyph's class. Private. *) - (* *) - (* format :: The format of the glyph's image. *) - (* *) - (* advance :: A 16.16 vector that gives the glyph's advance width. *) - (* *) - FT_GlyphRec = record - library_: FT_Library; - clazz: PFT_Glyph_Class; - format: FT_Glyph_Format; - advance: FT_Vector; - end; - - - (*************************************************************************) - (* *) - (* <Type> *) - (* FT_BitmapGlyph *) - (* *) - (* <Description> *) - (* A handle to an object used to model a bitmap glyph image. This is *) - (* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. *) - (* *) - FT_BitmapGlyph = ^FT_BitmapGlyphRec; - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_BitmapGlyphRec *) - (* *) - (* <Description> *) - (* A structure used for bitmap glyph images. This really is a *) - (* `sub-class' of `FT_GlyphRec'. *) - (* *) - (* <Fields> *) - (* root :: The root FT_Glyph fields. *) - (* *) - (* left :: The left-side bearing, i.e., the horizontal distance *) - (* from the current pen position to the left border of the *) - (* glyph bitmap. *) - (* *) - (* top :: The top-side bearing, i.e., the vertical distance from *) - (* the current pen position to the top border of the glyph *) - (* bitmap. This distance is positive for upwards-y! *) - (* *) - (* bitmap :: A descriptor for the bitmap. *) - (* *) - (* <Note> *) - (* You can typecast FT_Glyph to FT_BitmapGlyph if you have *) - (* glyph->format == FT_GLYPH_FORMAT_BITMAP. This lets you access *) - (* the bitmap's contents easily. *) - (* *) - (* The corresponding pixel buffer is always owned by the BitmapGlyph *) - (* and is thus created and destroyed with it. *) - (* *) - FT_BitmapGlyphRec = record - root: FT_GlyphRec; - left: FT_Int; - top: FT_Int; - bitmap: FT_Bitmap; - end; - (*************************************************************************) - (* *) - (* <Type> *) - (* FT_OutlineGlyph *) - (* *) - (* <Description> *) - (* A handle to an object used to model an outline glyph image. This *) - (* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. *) - (* *) - FT_OutlineGlyph = ^FT_OutlineGlyphRec; - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_OutlineGlyphRec *) - (* *) - (* <Description> *) - (* A structure used for outline (vectorial) glyph images. This *) - (* really is a `sub-class' of `FT_GlyphRec'. *) - (* *) - (* <Fields> *) - (* root :: The root FT_Glyph fields. *) - (* *) - (* outline :: A descriptor for the outline. *) - (* *) - (* <Note> *) - (* You can typecast FT_Glyph to FT_OutlineGlyph if you have *) - (* glyph->format == FT_GLYPH_FORMAT_OUTLINE. This lets you access *) - (* the outline's content easily. *) - (* *) - (* As the outline is extracted from a glyph slot, its coordinates are *) - (* expressed normally in 26.6 pixels, unless the flag *) - (* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). *) - (* *) - (* The outline's tables are always owned by the object and are *) - (* destroyed with it. *) - (* *) - FT_OutlineGlyphRec = record - root: FT_GlyphRec; - outline: FT_Outline; - end; - (*************************************************************************) (* *) @@ -1147,101 +773,6 @@ type end; - (*************************************************************************) - (* *) - (* <FuncType> *) - (* FT_Generic_Finalizer *) - (* *) - (* <Description> *) - (* Describes a function used to destroy the `client' data of any *) - (* FreeType object. See the description of the FT_Generic type for *) - (* details of usage. *) - (* *) - (* <Input> *) - (* The address of the FreeType object which is under finalization. *) - (* Its client data is accessed through its `generic' field. *) - (* *) - FT_Generic_Finalizer = procedure(AnObject : pointer ); cdecl; - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_Generic *) - (* *) - (* <Description> *) - (* Client applications often need to associate their own data to a *) - (* variety of FreeType core objects. For example, a text layout API *) - (* might want to associate a glyph cache to a given size object. *) - (* *) - (* Most FreeType object contains a `generic' field, of type *) - (* FT_Generic, which usage is left to client applications and font *) - (* servers. *) - (* *) - (* It can be used to store a pointer to client-specific data, as well *) - (* as the address of a `finalizer' function, which will be called by *) - (* FreeType when the object is destroyed (for example, the previous *) - (* client example would put the address of the glyph cache destructor *) - (* in the `finalizer' field). *) - (* *) - (* <Fields> *) - (* data :: A typeless pointer to any client-specified data. This *) - (* field is completely ignored by the FreeType library. *) - (* *) - (* finalizer :: A pointer to a `generic finalizer' function, which *) - (* will be called when the object is destroyed. If this *) - (* field is set to NULL, no code will be called. *) - (* *) - FT_Generic = record - data : pointer; - finalizer : FT_Generic_Finalizer; - end; - - (*************************************************************************) - (* *) - (* <Struct> *) - (* FT_BBox *) - (* *) - (* <Description> *) - (* A structure used to hold an outline's bounding box, i.e., the *) - (* coordinates of its extrema in the horizontal and vertical *) - (* directions. *) - (* *) - (* <Fields> *) - (* xMin :: The horizontal minimum (left-most). *) - (* *) - (* yMin :: The vertical minimum (bottom-most). *) - (* *) - (* xMax :: The horizontal maximum (right-most). *) - (* *) - (* yMax :: The vertical maximum (top-most). *) - (* *) - PFT_BBox = ^FT_BBox; - FT_BBox = record - xMin, yMin : FT_Pos; - xMax, yMax : FT_Pos; - end; - - - (*************************************************************************) - (* *) - (* <Type> *) - (* FT_GlyphSlot *) - (* *) - (* <Description> *) - (* A handle to a given `glyph slot'. A slot is a container where it *) - (* is possible to load any one of the glyphs contained in its parent *) - (* face. *) - (* *) - (* In other words, each time you call @FT_Load_Glyph or *) - (* @FT_Load_Char, the slot's content is erased by the new glyph data, *) - (* i.e. the glyph's metrics, its image (bitmap or outline), and *) - (* other control information. *) - (* *) - (* <Also> *) - (* @FT_GlyphSlotRec details the publicly accessible glyph fields. *) - (* *) - FT_GlyphSlot = ^FT_GlyphSlotRec; - (*************************************************************************) (* *) (* <Struct> *) @@ -1432,7 +963,7 @@ type subglyphs : FT_SubGlyph; control_data : pointer; - control_len : longint; + control_len : clong; lsb_delta: FT_Pos; rsb_delta: FT_Pos; @@ -1497,15 +1028,15 @@ type (* computations. *) (* *) FT_Size_Metrics = record - x_ppem , - y_ppem : FT_UShort; - x_scale , - y_scale : FT_Fixed; - - ascender , - descender : FT_Pos; - height : FT_Pos; - max_advance : FT_Pos; + x_ppem, (* horizontal pixels per EM *) + y_ppem: FT_UShort; (* vertical pixels per EM *) + x_scale, (* scaling values used to convert font *) + y_scale: FT_Fixed; (* units to 26.6 fractional pixels *) + + ascender, (* ascender in 26.6 frac. pixels *) + descender: FT_Pos; (* descender in 26.6 frac. pixels *) + height: FT_Pos; (* text height in 26.6 frac. pixels *) + max_advance: FT_Pos; (* max horizontal advance, in 26.6 pixels *) end; (*************************************************************************) @@ -1786,21 +1317,29 @@ type encoding_id : FT_UShort; end; + +{$I ftconfig.inc} +{$I fttypes.inc} +{$I ftimage.inc} +{$I ftglyph.inc} +{$I ftstroke.inc} +{$I ftoutln.inc} + + { GLOBAL PROCEDURES } (*************************************************************************) (* *) (* @macro: *) - (* FT_CURVE_TAG ( flag ) *) + (* FT_HAS_KERNING( face ) *) (* *) - function FT_CURVE_TAG(flag: byte): byte; - -const - FT_CURVE_TAG_ON = 1; - FT_CURVE_TAG_CONIC = 0; - FT_CURVE_TAG_CUBIC = 2; - + (* @description: *) + (* A macro that returns true whenever a face object contains kerning *) + (* data that can be accessed with @FT_Get_Kerning. *) + (* *) + function FT_HAS_KERNING(face : FT_Face ) : cbool; + (*************************************************************************) (* *) (* @macro: *) @@ -1813,16 +1352,6 @@ const (* *) function FT_IS_SCALABLE(face : FT_Face ) : cbool; - (*************************************************************************) - (* *) - (* @macro: *) - (* FT_HAS_KERNING( face ) *) - (* *) - (* @description: *) - (* A macro that returns true whenever a face object contains kerning *) - (* data that can be accessed with @FT_Get_Kerning. *) - (* *) - function FT_HAS_KERNING(face : FT_Face ) : cbool; (*************************************************************************) (* *) @@ -2284,216 +1813,12 @@ const pixel_height : FT_UInt ) : FT_Error; cdecl; external ft_lib name 'FT_Set_Pixel_Sizes'; - (*************************************************************************) - (* *) - (* <Function> *) - (* FT_Get_Glyph *) - (* *) - (* <Description> *) - (* A function used to extract a glyph image from a slot. *) - (* *) - (* <Input> *) - (* slot :: A handle to the source glyph slot. *) - (* *) - (* <Output> *) - (* aglyph :: A handle to the glyph object. *) - (* *) - (* <Return> *) - (* FreeType error code. 0 means success. *) - (* *) - function FT_Get_Glyph( - slot: FT_GlyphSlot; - out aglyph: FT_Glyph ): FT_Error; - cdecl; external ft_lib name 'FT_Get_Glyph'; - - (*************************************************************************) - (* *) - (* <Enum> *) - (* FT_Glyph_BBox_Mode *) - (* *) - (* <Description> *) - (* The mode how the values of @FT_Glyph_Get_CBox are returned. *) - (* *) - (* <Values> *) - (* FT_GLYPH_BBOX_UNSCALED :: *) - (* Return unscaled font units. *) - (* *) - (* FT_GLYPH_BBOX_SUBPIXELS :: *) - (* Return unfitted 26.6 coordinates. *) - (* *) - (* FT_GLYPH_BBOX_GRIDFIT :: *) - (* Return grid-fitted 26.6 coordinates. *) - (* *) - (* FT_GLYPH_BBOX_TRUNCATE :: *) - (* Return coordinates in integer pixels. *) - (* *) - (* FT_GLYPH_BBOX_PIXELS :: *) - (* Return grid-fitted pixel coordinates. *) - (* *) -type - FT_Glyph_BBox_Mode = FT_UInt; const - FT_GLYPH_BBOX_UNSCALED = 0; - FT_GLYPH_BBOX_SUBPIXELS = 0; - FT_GLYPH_BBOX_GRIDFIT = 1; - FT_GLYPH_BBOX_TRUNCATE = 2; - FT_GLYPH_BBOX_PIXELS = 3; - - (*************************************************************************) - (* *) - (* <Function> *) - (* FT_Glyph_Get_CBox *) - (* *) - (* <Description> *) - (* Return a glyph's `control box'. The control box encloses all the *) - (* outline's points, including Bzier control points. Though it *) - (* coincides with the exact bounding box for most glyphs, it can be *) - (* slightly larger in some situations (like when rotating an outline *) - (* which contains Bzier outside arcs). *) - (* *) - (* Computing the control box is very fast, while getting the bounding *) - (* box can take much more time as it needs to walk over all segments *) - (* and arcs in the outline. To get the latter, you can use the *) - (* `ftbbox' component which is dedicated to this single task. *) - (* *) - (* <Input> *) - (* glyph :: A handle to the source glyph object. *) - (* *) - (* mode :: The mode which indicates how to interpret the returned *) - (* bounding box values. *) - (* *) - (* <Output> *) - (* acbox :: The glyph coordinate bounding box. Coordinates are *) - (* expressed in 1/64th of pixels if it is grid-fitted. *) - (* *) - (* <Note> *) - (* Coordinates are relative to the glyph origin, using the Y-upwards *) - (* convention. *) - (* *) - (* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode' *) - (* must be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font *) - (* units in 26.6 pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS *) - (* is another name for this constant. *) - (* *) - (* Note that the maximum coordinates are exclusive, which means that *) - (* one can compute the width and height of the glyph image (be it in *) - (* integer or 26.6 pixels) as: *) - (* *) - (* { *) - (* width = bbox.xMax - bbox.xMin; *) - (* height = bbox.yMax - bbox.yMin; *) - (* } *) - (* *) - (* Note also that for 26.6 coordinates, if `bbox_mode' is set to *) - (* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, *) - (* which corresponds to: *) - (* *) - (* { *) - (* bbox.xMin = FLOOR(bbox.xMin); *) - (* bbox.yMin = FLOOR(bbox.yMin); *) - (* bbox.xMax = CEILING(bbox.xMax); *) - (* bbox.yMax = CEILING(bbox.yMax); *) - (* } *) - (* *) - (* To get the bbox in pixel coordinates, set `bbox_mode' to *) - (* @FT_GLYPH_BBOX_TRUNCATE. *) - (* *) - (* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' *) - (* to @FT_GLYPH_BBOX_PIXELS. *) - (* *) - procedure FT_Glyph_Get_CBox( glyph: FT_Glyph; - bbox_mode: FT_UInt; - out acbox: FT_BBox ); - cdecl; external ft_lib name 'FT_Glyph_Get_CBox'; - - (*************************************************************************) - (* *) - (* <Function> *) - (* FT_Glyph_To_Bitmap *) - (* *) - (* <Description> *) - (* Converts a given glyph object to a bitmap glyph object. *) - (* *) - (* <InOut> *) - (* the_glyph :: A pointer to a handle to the target glyph. *) - (* *) - (* <Input> *) - (* render_mode :: An enumeration that describe how the data is *) - (* rendered. *) - (* *) - (* origin :: A pointer to a vector used to translate the glyph *) - (* image before rendering. Can be 0 (if no *) - (* translation). The origin is expressed in *) - (* 26.6 pixels. *) - (* *) - (* destroy :: A boolean that indicates that the original glyph *) - (* image should be destroyed by this function. It is *) - (* never destroyed in case of error. *) - (* *) - (* <Return> *) - (* FreeType error code. 0 means success. *) - (* *) - (* <Note> *) - (* The glyph image is translated with the `origin' vector before *) - (* rendering. *) - (* *) - (* The first parameter is a pointer to a FT_Glyph handle, that will *) - (* be replaced by this function. Typically, you would use (omitting *) - (* error handling): *) - (* *) - (* *) - (* { *) - (* FT_Glyph glyph; *) - (* FT_BitmapGlyph glyph_bitmap; *) - (* *) - (* *) - (* // load glyph *) - (* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); *) - (* *) - (* // extract glyph image *) - (* error = FT_Get_Glyph( face->glyph, &glyph ); *) - (* *) - (* // convert to a bitmap (default render mode + destroy old) *) - (* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) *) - (* { *) - (* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_DEFAULT, *) - (* 0, 1 ); *) - (* if ( error ) // glyph unchanged *) - (* ... *) - (* } *) - (* *) - (* // access bitmap content by typecasting *) - (* glyph_bitmap = (FT_BitmapGlyph)glyph; *) - (* *) - (* // do funny stuff with it, like blitting/drawing *) - (* ... *) - (* *) - (* // discard glyph image (bitmap or not) *) - (* FT_Done_Glyph( glyph ); *) - (* } *) - (* *) - (* *) - (* This function does nothing if the glyph format isn't scalable. *) - (* *) - function FT_Glyph_To_Bitmap(var the_glyph: FT_Glyph; - render_mode: FT_Render_Mode; - origin: PFT_Vector; - destroy: FT_Bool ): FT_Error; - cdecl; external ft_lib name 'FT_Glyph_To_Bitmap'; + FT_ANGLE_PI = 180 shl 16; + FT_ANGLE_2PI = FT_ANGLE_PI * 2; + FT_ANGLE_PI2 = FT_ANGLE_PI div 2; + FT_ANGLE_PI4 = FT_ANGLE_PI div 4; - (*************************************************************************) - (* *) - (* <Function> *) - (* FT_Done_Glyph *) - (* *) - (* <Description> *) - (* Destroys a given glyph. *) - (* *) - (* <Input> *) - (* glyph :: A handle to the target glyph object. *) - (* *) - procedure FT_Done_Glyph( glyph: FT_Glyph ); - cdecl; external ft_lib name 'FT_Done_Glyph'; implementation @@ -2504,17 +1829,17 @@ begin result := flag and 3; end; -{ FT_IS_SCALABLE } -function FT_IS_SCALABLE(face : FT_Face ) : cbool; -begin - result := cbool(face.face_flags and FT_FACE_FLAG_SCALABLE ); -end; - { FT_HAS_KERNING } function FT_HAS_KERNING(face : FT_Face ) : cbool; begin result := cbool(face.face_flags and FT_FACE_FLAG_KERNING ); end; +{ FT_IS_SCALABLE } +function FT_IS_SCALABLE(face : FT_Face ) : cbool; +begin + result := cbool(face.face_flags and FT_FACE_FLAG_SCALABLE ); +end; + end. diff --git a/src/lib/freetype/ftconfig.inc b/src/lib/freetype/ftconfig.inc new file mode 100644 index 00000000..100fb2e0 --- /dev/null +++ b/src/lib/freetype/ftconfig.inc @@ -0,0 +1,35 @@ +(***************************************************************************) +(* *) +(* ftconfig.h *) +(* *) +(* ANSI-specific configuration file (specification only). *) +(* *) +(* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007 by *) +(* David Turner, Robert Wilhelm, and Werner Lemberg. *) +(* *) +(* This file is part of the FreeType project, and may only be used, *) +(* modified, and distributed under the terms of the FreeType project *) +(* license, LICENSE.TXT. By continuing to use, modify, or distribute *) +(* this file you indicate that you have read the license and *) +(* understand and accept it fully. *) +(* *) +(***************************************************************************) +(***************************************************************************) +(* Pascal port by the UltraStar Deluxe Team *) +(***************************************************************************) + +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* IntN types *) + (* *) + (* Used to guarantee the size of some specific integers. *) + (* *) + FT_Int16 = cint16; + FT_UInt16 = cuint16; + FT_Int32 = cint32; + FT_UInt32 = cuint32; + +{$ENDIF TYPE_DECL} + diff --git a/src/lib/freetype/ftglyph.inc b/src/lib/freetype/ftglyph.inc new file mode 100644 index 00000000..0d4acc99 --- /dev/null +++ b/src/lib/freetype/ftglyph.inc @@ -0,0 +1,435 @@ +(***************************************************************************) +(* *) +(* ftglyph.h *) +(* *) +(* FreeType convenience functions to handle glyphs (specification). *) +(* *) +(* Copyright 1996-2001, 2002, 2003, 2006 by *) +(* David Turner, Robert Wilhelm, and Werner Lemberg. *) +(* *) +(* This file is part of the FreeType project, and may only be used, *) +(* modified, and distributed under the terms of the FreeType project *) +(* license, LICENSE.TXT. By continuing to use, modify, or distribute *) +(* this file you indicate that you have read the license and *) +(* understand and accept it fully. *) +(* *) +(***************************************************************************) +(***************************************************************************) +(* Pascal port by the UltraStar Deluxe Team *) +(***************************************************************************) + + + (*************************************************************************) + (* *) + (* This file contains the definition of several convenience functions *) + (* that can be used by client applications to easily retrieve glyph *) + (* bitmaps and outlines from a given face. *) + (* *) + (* These functions should be optional if you are writing a font server *) + (* or text layout engine on top of FreeType. However, they are pretty *) + (* handy for many other simple uses of the library. *) + (* *) + (*************************************************************************) + + (*************************************************************************) + (* *) + (* <Section> *) + (* glyph_management *) + (* *) + (* <Title> *) + (* Glyph Management *) + (* *) + (* <Abstract> *) + (* Generic interface to manage individual glyph data. *) + (* *) + (* <Description> *) + (* This section contains definitions used to manage glyph data *) + (* through generic FT_Glyph objects. Each of them can contain a *) + (* bitmap, a vector outline, or even images in other formats. *) + (* *) + (*************************************************************************) + +{$IFDEF TYPE_DECL} + + (* forward declaration to a private type *) + PFT_Glyph_Class = Pointer; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Glyph *) + (* *) + (* <Description> *) + (* Handle to an object used to model generic glyph images. It is a *) + (* pointer to the @FT_GlyphRec structure and can contain a glyph *) + (* bitmap or pointer. *) + (* *) + (* <Note> *) + (* Glyph objects are not owned by the library. You must thus release *) + (* them manually (through @FT_Done_Glyph) _before_ calling *) + (* @FT_Done_FreeType. *) + (* *) + FT_Glyph = ^FT_GlyphRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_GlyphRec *) + (* *) + (* <Description> *) + (* The root glyph structure contains a given glyph image plus its *) + (* advance width in 16.16 fixed float format. *) + (* *) + (* <Fields> *) + (* library :: A handle to the FreeType library object. *) + (* *) + (* clazz :: A pointer to the glyph's class. Private. *) + (* *) + (* format :: The format of the glyph's image. *) + (* *) + (* advance :: A 16.16 vector that gives the glyph's advance width. *) + (* *) + FT_GlyphRec = record + library_: FT_Library; + clazz: PFT_Glyph_Class; + format: FT_Glyph_Format; + advance: FT_Vector; + end; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_BitmapGlyph *) + (* *) + (* <Description> *) + (* A handle to an object used to model a bitmap glyph image. This is *) + (* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. *) + (* *) + FT_BitmapGlyph = ^FT_BitmapGlyphRec; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_BitmapGlyphRec *) + (* *) + (* <Description> *) + (* A structure used for bitmap glyph images. This really is a *) + (* `sub-class' of `FT_GlyphRec'. *) + (* *) + (* <Fields> *) + (* root :: The root FT_Glyph fields. *) + (* *) + (* left :: The left-side bearing, i.e., the horizontal distance *) + (* from the current pen position to the left border of the *) + (* glyph bitmap. *) + (* *) + (* top :: The top-side bearing, i.e., the vertical distance from *) + (* the current pen position to the top border of the glyph *) + (* bitmap. This distance is positive for upwards-y! *) + (* *) + (* bitmap :: A descriptor for the bitmap. *) + (* *) + (* <Note> *) + (* You can typecast FT_Glyph to FT_BitmapGlyph if you have *) + (* glyph->format == FT_GLYPH_FORMAT_BITMAP. This lets you access *) + (* the bitmap's contents easily. *) + (* *) + (* The corresponding pixel buffer is always owned by the BitmapGlyph *) + (* and is thus created and destroyed with it. *) + (* *) + FT_BitmapGlyphRec = record + root: FT_GlyphRec; + left: FT_Int; + top: FT_Int; + bitmap: FT_Bitmap; + end; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_OutlineGlyph *) + (* *) + (* <Description> *) + (* A handle to an object used to model an outline glyph image. This *) + (* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. *) + (* *) + FT_OutlineGlyph = ^FT_OutlineGlyphRec; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_OutlineGlyphRec *) + (* *) + (* <Description> *) + (* A structure used for outline (vectorial) glyph images. This *) + (* really is a `sub-class' of `FT_GlyphRec'. *) + (* *) + (* <Fields> *) + (* root :: The root FT_Glyph fields. *) + (* *) + (* outline :: A descriptor for the outline. *) + (* *) + (* <Note> *) + (* You can typecast FT_Glyph to FT_OutlineGlyph if you have *) + (* glyph->format == FT_GLYPH_FORMAT_OUTLINE. This lets you access *) + (* the outline's content easily. *) + (* *) + (* As the outline is extracted from a glyph slot, its coordinates are *) + (* expressed normally in 26.6 pixels, unless the flag *) + (* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). *) + (* *) + (* The outline's tables are always owned by the object and are *) + (* destroyed with it. *) + (* *) + FT_OutlineGlyphRec = record + root: FT_GlyphRec; + outline: FT_Outline; + end; + +{$ELSE TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Get_Glyph *) + (* *) + (* <Description> *) + (* A function used to extract a glyph image from a slot. *) + (* *) + (* <Input> *) + (* slot :: A handle to the source glyph slot. *) + (* *) + (* <Output> *) + (* aglyph :: A handle to the glyph object. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Get_Glyph( + slot: FT_GlyphSlot; + out aglyph: FT_Glyph ): FT_Error; + cdecl; external ft_lib name 'FT_Get_Glyph'; + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Glyph_Copy *) + (* *) + (* <Description> *) + (* A function used to copy a glyph image. Note that the created *) + (* @FT_Glyph object must be released with @FT_Done_Glyph. *) + (* *) + (* <Input> *) + (* source :: A handle to the source glyph object. *) + (* *) + (* <Output> *) + (* target :: A handle to the target glyph object. 0~in case of *) + (* error. *) + (* *) + (* <Return> *) + (* FreeType error code. 0~means success. *) + (* *) + function FT_Glyph_Copy(source: FT_Glyph; + var target: FT_Glyph ): FT_Error; + cdecl; external ft_lib name 'FT_Glyph_Copy'; + +{$ENDIF TYPE_DECL} +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Glyph_BBox_Mode *) + (* *) + (* <Description> *) + (* The mode how the values of @FT_Glyph_Get_CBox are returned. *) + (* *) + (* <Values> *) + (* FT_GLYPH_BBOX_UNSCALED :: *) + (* Return unscaled font units. *) + (* *) + (* FT_GLYPH_BBOX_SUBPIXELS :: *) + (* Return unfitted 26.6 coordinates. *) + (* *) + (* FT_GLYPH_BBOX_GRIDFIT :: *) + (* Return grid-fitted 26.6 coordinates. *) + (* *) + (* FT_GLYPH_BBOX_TRUNCATE :: *) + (* Return coordinates in integer pixels. *) + (* *) + (* FT_GLYPH_BBOX_PIXELS :: *) + (* Return grid-fitted pixel coordinates. *) + (* *) + FT_Glyph_BBox_Mode = cint; +{$ELSE TYPE_DECL} +const + FT_GLYPH_BBOX_UNSCALED = 0; + FT_GLYPH_BBOX_SUBPIXELS = 0; + FT_GLYPH_BBOX_GRIDFIT = 1; + FT_GLYPH_BBOX_TRUNCATE = 2; + FT_GLYPH_BBOX_PIXELS = 3; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Glyph_Get_CBox *) + (* *) + (* <Description> *) + (* Return a glyph's `control box'. The control box encloses all the *) + (* outline's points, including Bzier control points. Though it *) + (* coincides with the exact bounding box for most glyphs, it can be *) + (* slightly larger in some situations (like when rotating an outline *) + (* which contains Bzier outside arcs). *) + (* *) + (* Computing the control box is very fast, while getting the bounding *) + (* box can take much more time as it needs to walk over all segments *) + (* and arcs in the outline. To get the latter, you can use the *) + (* `ftbbox' component which is dedicated to this single task. *) + (* *) + (* <Input> *) + (* glyph :: A handle to the source glyph object. *) + (* *) + (* mode :: The mode which indicates how to interpret the returned *) + (* bounding box values. *) + (* *) + (* <Output> *) + (* acbox :: The glyph coordinate bounding box. Coordinates are *) + (* expressed in 1/64th of pixels if it is grid-fitted. *) + (* *) + (* <Note> *) + (* Coordinates are relative to the glyph origin, using the Y-upwards *) + (* convention. *) + (* *) + (* If the glyph has been loaded with @FT_LOAD_NO_SCALE, `bbox_mode' *) + (* must be set to @FT_GLYPH_BBOX_UNSCALED to get unscaled font *) + (* units in 26.6 pixel format. The value @FT_GLYPH_BBOX_SUBPIXELS *) + (* is another name for this constant. *) + (* *) + (* Note that the maximum coordinates are exclusive, which means that *) + (* one can compute the width and height of the glyph image (be it in *) + (* integer or 26.6 pixels) as: *) + (* *) + (* { *) + (* width = bbox.xMax - bbox.xMin; *) + (* height = bbox.yMax - bbox.yMin; *) + (* } *) + (* *) + (* Note also that for 26.6 coordinates, if `bbox_mode' is set to *) + (* @FT_GLYPH_BBOX_GRIDFIT, the coordinates will also be grid-fitted, *) + (* which corresponds to: *) + (* *) + (* { *) + (* bbox.xMin = FLOOR(bbox.xMin); *) + (* bbox.yMin = FLOOR(bbox.yMin); *) + (* bbox.xMax = CEILING(bbox.xMax); *) + (* bbox.yMax = CEILING(bbox.yMax); *) + (* } *) + (* *) + (* To get the bbox in pixel coordinates, set `bbox_mode' to *) + (* @FT_GLYPH_BBOX_TRUNCATE. *) + (* *) + (* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' *) + (* to @FT_GLYPH_BBOX_PIXELS. *) + (* *) + procedure FT_Glyph_Get_CBox( glyph: FT_Glyph; + bbox_mode: FT_UInt; + out acbox: FT_BBox ); + cdecl; external ft_lib name 'FT_Glyph_Get_CBox'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Glyph_To_Bitmap *) + (* *) + (* <Description> *) + (* Converts a given glyph object to a bitmap glyph object. *) + (* *) + (* <InOut> *) + (* the_glyph :: A pointer to a handle to the target glyph. *) + (* *) + (* <Input> *) + (* render_mode :: An enumeration that describe how the data is *) + (* rendered. *) + (* *) + (* origin :: A pointer to a vector used to translate the glyph *) + (* image before rendering. Can be 0 (if no *) + (* translation). The origin is expressed in *) + (* 26.6 pixels. *) + (* *) + (* destroy :: A boolean that indicates that the original glyph *) + (* image should be destroyed by this function. It is *) + (* never destroyed in case of error. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* The glyph image is translated with the `origin' vector before *) + (* rendering. *) + (* *) + (* The first parameter is a pointer to a FT_Glyph handle, that will *) + (* be replaced by this function. Typically, you would use (omitting *) + (* error handling): *) + (* *) + (* *) + (* { *) + (* FT_Glyph glyph; *) + (* FT_BitmapGlyph glyph_bitmap; *) + (* *) + (* *) + (* // load glyph *) + (* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); *) + (* *) + (* // extract glyph image *) + (* error = FT_Get_Glyph( face->glyph, &glyph ); *) + (* *) + (* // convert to a bitmap (default render mode + destroy old) *) + (* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) *) + (* { *) + (* error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_DEFAULT, *) + (* 0, 1 ); *) + (* if ( error ) // glyph unchanged *) + (* ... *) + (* } *) + (* *) + (* // access bitmap content by typecasting *) + (* glyph_bitmap = (FT_BitmapGlyph)glyph; *) + (* *) + (* // do funny stuff with it, like blitting/drawing *) + (* ... *) + (* *) + (* // discard glyph image (bitmap or not) *) + (* FT_Done_Glyph( glyph ); *) + (* } *) + (* *) + (* *) + (* This function does nothing if the glyph format isn't scalable. *) + (* *) + function FT_Glyph_To_Bitmap(var the_glyph: FT_Glyph; + render_mode: FT_Render_Mode; + origin: PFT_Vector; + destroy: FT_Bool ): FT_Error; + cdecl; external ft_lib name 'FT_Glyph_To_Bitmap'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Done_Glyph *) + (* *) + (* <Description> *) + (* Destroys a given glyph. *) + (* *) + (* <Input> *) + (* glyph :: A handle to the target glyph object. *) + (* *) + procedure FT_Done_Glyph( glyph: FT_Glyph ); + cdecl; external ft_lib name 'FT_Done_Glyph'; + +{$ENDIF TYPE_DECL} diff --git a/src/lib/freetype/ftimage.inc b/src/lib/freetype/ftimage.inc new file mode 100644 index 00000000..9255c422 --- /dev/null +++ b/src/lib/freetype/ftimage.inc @@ -0,0 +1,803 @@ +(***************************************************************************) +(* *) +(* ftimage.h *) +(* *) +(* FreeType glyph image formats and default raster interface *) +(* (specification). *) +(* *) +(* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 by *) +(* David Turner, Robert Wilhelm, and Werner Lemberg. *) +(* *) +(* This file is part of the FreeType project, and may only be used, *) +(* modified, and distributed under the terms of the FreeType project *) +(* license, LICENSE.TXT. By continuing to use, modify, or distribute *) +(* this file you indicate that you have read the license and *) +(* understand and accept it fully. *) +(* *) +(***************************************************************************) +(***************************************************************************) +(* Pascal port by the UltraStar Deluxe Team *) +(***************************************************************************) + + (*************************************************************************) + (* *) + (* Note: A `raster' is simply a scan-line converter, used to render *) + (* FT_Outlines into FT_Bitmaps. *) + (* *) + (*************************************************************************) + +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Pos *) + (* *) + (* <Description> *) + (* The type FT_Pos is a 32-bit integer used to store vectorial *) + (* coordinates. Depending on the context, these can represent *) + (* distances in integer font units, or 16,16, or 26.6 fixed float *) + (* pixel coordinates. *) + (* *) + FT_Pos = cslong; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Vector *) + (* *) + (* <Description> *) + (* A simple structure used to store a 2D vector; coordinates are of *) + (* the FT_Pos type. *) + (* *) + (* <Fields> *) + (* x :: The horizontal coordinate. *) + (* y :: The vertical coordinate. *) + (* *) + PFT_Vector = ^FT_Vector; + FT_Vector = record + x , + y : FT_Pos; + end; + + PFT_VectorArray = ^FT_VectorArray; + FT_VectorArray = array[0 .. (MaxInt div SizeOf(FT_Vector))-1] of FT_Vector; + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_BBox *) + (* *) + (* <Description> *) + (* A structure used to hold an outline's bounding box, i.e., the *) + (* coordinates of its extrema in the horizontal and vertical *) + (* directions. *) + (* *) + (* <Fields> *) + (* xMin :: The horizontal minimum (left-most). *) + (* *) + (* yMin :: The vertical minimum (bottom-most). *) + (* *) + (* xMax :: The horizontal maximum (right-most). *) + (* *) + (* yMax :: The vertical maximum (top-most). *) + (* *) + PFT_BBox = ^FT_BBox; + FT_BBox = record + xMin, yMin : FT_Pos; + xMax, yMax : FT_Pos; + end; + + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Pixel_Mode *) + (* *) + (* <Description> *) + (* An enumeration type used to describe the format of pixels in a *) + (* given bitmap. Note that additional formats may be added in the *) + (* future. *) + (* *) + (* <Values> *) + (* FT_PIXEL_MODE_NONE :: *) + (* Value 0 is reserved. *) + (* *) + (* FT_PIXEL_MODE_MONO :: *) + (* A monochrome bitmap, using 1 bit per pixel. Note that pixels *) + (* are stored in most-significant order (MSB), which means that *) + (* the left-most pixel in a byte has value 128. *) + (* *) + (* FT_PIXEL_MODE_GRAY :: *) + (* An 8-bit bitmap, generally used to represent anti-aliased glyph *) + (* images. Each pixel is stored in one byte. Note that the number *) + (* of value `gray' levels is stored in the `num_bytes' field of *) + (* the @FT_Bitmap structure (it generally is 256). *) + (* *) + (* FT_PIXEL_MODE_GRAY2 :: *) + (* A 2-bit/pixel bitmap, used to represent embedded anti-aliased *) + (* bitmaps in font files according to the OpenType specification. *) + (* We haven't found a single font using this format, however. *) + (* *) + (* FT_PIXEL_MODE_GRAY4 :: *) + (* A 4-bit/pixel bitmap, used to represent embedded anti-aliased *) + (* bitmaps in font files according to the OpenType specification. *) + (* We haven't found a single font using this format, however. *) + (* *) + (* FT_PIXEL_MODE_LCD :: *) + (* An 8-bit bitmap, used to represent RGB or BGR decimated glyph *) + (* images used for display on LCD displays; the bitmap is three *) + (* times wider than the original glyph image. See also *) + (* @FT_RENDER_MODE_LCD. *) + (* *) + (* FT_PIXEL_MODE_LCD_V :: *) + (* An 8-bit bitmap, used to represent RGB or BGR decimated glyph *) + (* images used for display on rotated LCD displays; the bitmap *) + (* is three times taller than the original glyph image. See also *) + (* @FT_RENDER_MODE_LCD_V. *) + (* *) + FT_Pixel_Mode = cint; +{$ELSE TYPE_DECL} +const + FT_PIXEL_MODE_NONE = 0; + FT_PIXEL_MODE_MONO = FT_PIXEL_MODE_NONE + 1; + FT_PIXEL_MODE_GRAY = FT_PIXEL_MODE_MONO + 1; + FT_PIXEL_MODE_GRAY2 = FT_PIXEL_MODE_GRAY + 1; + FT_PIXEL_MODE_GRAY4 = FT_PIXEL_MODE_GRAY2 + 1; + FT_PIXEL_MODE_LCD = FT_PIXEL_MODE_GRAY4 + 1; + FT_PIXEL_MODE_LCD_V = FT_PIXEL_MODE_LCD + 1; + + FT_PIXEL_MODE_MAX = FT_PIXEL_MODE_LCD_V + 1; (* do not remove *) +{$ENDIF TYPE_DECL} +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Bitmap *) + (* *) + (* <Description> *) + (* A structure used to describe a bitmap or pixmap to the raster. *) + (* Note that we now manage pixmaps of various depths through the *) + (* `pixel_mode' field. *) + (* *) + (* <Fields> *) + (* rows :: The number of bitmap rows. *) + (* *) + (* width :: The number of pixels in bitmap row. *) + (* *) + (* pitch :: The pitch's absolute value is the number of bytes *) + (* taken by one bitmap row, including padding. *) + (* However, the pitch is positive when the bitmap has *) + (* a `down' flow, and negative when it has an `up' *) + (* flow. In all cases, the pitch is an offset to add *) + (* to a bitmap pointer in order to go down one row. *) + (* *) + (* buffer :: A typeless pointer to the bitmap buffer. This *) + (* value should be aligned on 32-bit boundaries in *) + (* most cases. *) + (* *) + (* num_grays :: This field is only used with *) + (* `FT_PIXEL_MODE_GRAY'; it gives the number of gray *) + (* levels used in the bitmap. *) + (* *) + (* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. *) + (* See @FT_Pixel_Mode for possible values. *) + (* *) + (* palette_mode :: This field is only used with paletted pixel modes; *) + (* it indicates how the palette is stored. *) + (* *) + (* palette :: A typeless pointer to the bitmap palette; only *) + (* used for paletted pixel modes. *) + (* *) + (* <Note> *) + (* For now, the only pixel mode supported by FreeType are mono and *) + (* grays. However, drivers might be added in the future to support *) + (* more `colorful' options. *) + (* *) + (* When using pixel modes pal2, pal4 and pal8 with a void `palette' *) + (* field, a gray pixmap with respectively 4, 16, and 256 levels of *) + (* gray is assumed. This, in order to be compatible with some *) + (* embedded bitmap formats defined in the TrueType specification. *) + (* *) + (* Note that no font was found presenting such embedded bitmaps, so *) + (* this is currently completely unhandled by the library. *) + (* *) + PFT_Bitmap = ^FT_Bitmap; + FT_Bitmap = record + rows: FT_Int; + width: FT_Int; + pitch: FT_Int; + buffer: PByteArray; + num_grays: FT_Short; + pixel_mode: byte; + palette_mode: byte; + palette: pointer; + end; + + + (*************************************************************************) + (* *) + (* <Section> *) + (* outline_processing *) + (* *) + (*************************************************************************) + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Outline *) + (* *) + (* <Description> *) + (* This structure is used to describe an outline to the scan-line *) + (* converter. *) + (* *) + (* <Fields> *) + (* n_contours :: The number of contours in the outline. *) + (* *) + (* n_points :: The number of points in the outline. *) + (* *) + (* points :: A pointer to an array of `n_points' FT_Vector *) + (* elements, giving the outline's point coordinates. *) + (* *) + (* tags :: A pointer to an array of `n_points' chars, giving *) + (* each outline point's type. If bit 0 is unset, the *) + (* point is `off' the curve, i.e. a Bezier control *) + (* point, while it is `on' when set. *) + (* *) + (* Bit 1 is meaningful for `off' points only. If set, *) + (* it indicates a third-order Bezier arc control point; *) + (* and a second-order control point if unset. *) + (* *) + (* contours :: An array of `n_contours' shorts, giving the end *) + (* point of each contour within the outline. For *) + (* example, the first contour is defined by the points *) + (* `0' to `contours[0]', the second one is defined by *) + (* the points `contours[0]+1' to `contours[1]', etc. *) + (* *) + (* flags :: A set of bit flags used to characterize the outline *) + (* and give hints to the scan-converter and hinter on *) + (* how to convert/grid-fit it. See FT_Outline_Flags. *) + (* *) + PFT_Outline = ^FT_Outline; + FT_Outline = record + n_contours: FT_Short; (* number of contours in glyph *) + n_points: FT_Short; (* number of points in the glyph *) + + points: PFT_VectorArray; (* the outline's points *) + tags: PByteArray; (* the points flags *) + contours: PFT_ShortArray; (* the contour end points *) + + flags: FT_Int; (* outline masks *) + end; + +{$ELSE TYPE_DECL} + + (*************************************************************************) + (* *) + (* @macro: *) + (* FT_CURVE_TAG ( flag ) *) + (* *) + function FT_CURVE_TAG(flag: byte): byte; + +const + FT_CURVE_TAG_ON = 1; + FT_CURVE_TAG_CONIC = 0; + FT_CURVE_TAG_CUBIC = 2; + + FT_CURVE_TAG_TOUCH_X = 8; // reserved for the TrueType hinter + FT_CURVE_TAG_TOUCH_Y = 16; // reserved for the TrueType hinter + + FT_CURVE_TAG_TOUCH_BOTH = ( FT_CURVE_TAG_TOUCH_X or + FT_CURVE_TAG_TOUCH_Y ); +{$ENDIF TYPE_DECL} +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Outline_MoveToFunc *) + (* *) + (* <Description> *) + (* A function pointer type used to describe the signature of a `move *) + (* to' function during outline walking/decomposition. *) + (* *) + (* A `move to' is emitted to start a new contour in an outline. *) + (* *) + (* <Input> *) + (* to :: A pointer to the target point of the `move to'. *) + (* *) + (* user :: A typeless pointer which is passed from the caller of the *) + (* decomposition function. *) + (* *) + (* <Return> *) + (* Error code. 0 means success. *) + (* *) + FT_Outline_MoveToFunc = function(to_: {const} PFT_Vector; + user: Pointer): cint; cdecl; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Outline_LineToFunc *) + (* *) + (* <Description> *) + (* A function pointer type used to describe the signature of a `line *) + (* to' function during outline walking/decomposition. *) + (* *) + (* A `line to' is emitted to indicate a segment in the outline. *) + (* *) + (* <Input> *) + (* to :: A pointer to the target point of the `line to'. *) + (* *) + (* user :: A typeless pointer which is passed from the caller of the *) + (* decomposition function. *) + (* *) + (* <Return> *) + (* Error code. 0 means success. *) + (* *) + FT_Outline_LineToFunc = function(to_: {const} PFT_Vector; + user: Pointer): cint; cdecl; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Outline_ConicToFunc *) + (* *) + (* <Description> *) + (* A function pointer type use to describe the signature of a `conic *) + (* to' function during outline walking/decomposition. *) + (* *) + (* A `conic to' is emitted to indicate a second-order Bzier arc in *) + (* the outline. *) + (* *) + (* <Input> *) + (* control :: An intermediate control point between the last position *) + (* and the new target in `to'. *) + (* *) + (* to :: A pointer to the target end point of the conic arc. *) + (* *) + (* user :: A typeless pointer which is passed from the caller of *) + (* the decomposition function. *) + (* *) + (* <Return> *) + (* Error code. 0 means success. *) + (* *) + FT_Outline_ConicToFunc = function(control: {const} PFT_Vector; + to_: {const} PFT_Vector; + user: Pointer): cint; cdecl; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Outline_CubicToFunc *) + (* *) + (* <Description> *) + (* A function pointer type used to describe the signature of a `cubic *) + (* to' function during outline walking/decomposition. *) + (* *) + (* A `cubic to' is emitted to indicate a third-order Bzier arc. *) + (* *) + (* <Input> *) + (* control1 :: A pointer to the first Bzier control point. *) + (* *) + (* control2 :: A pointer to the second Bzier control point. *) + (* *) + (* to :: A pointer to the target end point. *) + (* *) + (* user :: A typeless pointer which is passed from the caller of *) + (* the decomposition function. *) + (* *) + (* <Return> *) + (* Error code. 0 means success. *) + (* *) + FT_Outline_CubicToFunc = function( control1: {const} PFT_Vector; + control2: {const} PFT_Vector; + to_: {const} PFT_Vector; + user: Pointer ): cint; cdecl; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Outline_Funcs *) + (* *) + (* <Description> *) + (* A structure to hold various function pointers used during outline *) + (* decomposition in order to emit segments, conic, and cubic Bziers, *) + (* as well as `move to' and `close to' operations. *) + (* *) + (* <Fields> *) + (* move_to :: The `move to' emitter. *) + (* *) + (* line_to :: The segment emitter. *) + (* *) + (* conic_to :: The second-order Bzier arc emitter. *) + (* *) + (* cubic_to :: The third-order Bzier arc emitter. *) + (* *) + (* shift :: The shift that is applied to coordinates before they *) + (* are sent to the emitter. *) + (* *) + (* delta :: The delta that is applied to coordinates before they *) + (* are sent to the emitter, but after the shift. *) + (* *) + (* <Note> *) + (* The point coordinates sent to the emitters are the transformed *) + (* version of the original coordinates (this is important for high *) + (* accuracy during scan-conversion). The transformation is simple: *) + (* *) + (* { *) + (* x' = (x << shift) - delta *) + (* y' = (x << shift) - delta *) + (* } *) + (* *) + (* Set the value of `shift' and `delta' to 0 to get the original *) + (* point coordinates. *) + (* *) + PFT_Outline_Funcs = ^FT_Outline_Funcs; + 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: cint; + delta: FT_Pos; + end; + + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_Glyph_Format *) + (* *) + (* <Description> *) + (* An enumeration type used to describe the format of a given glyph *) + (* image. Note that this version of FreeType only supports two image *) + (* formats, even though future font drivers will be able to register *) + (* their own format. *) + (* *) + (* <Values> *) + (* FT_GLYPH_FORMAT_NONE :: *) + (* The value 0 is reserved and does describe a glyph format. *) + (* *) + (* FT_GLYPH_FORMAT_COMPOSITE :: *) + (* The glyph image is a composite of several other images. This *) + (* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to *) + (* report compound glyphs (like accented characters). *) + (* *) + (* FT_GLYPH_FORMAT_BITMAP :: *) + (* The glyph image is a bitmap, and can be described as an *) + (* @FT_Bitmap. You generally need to access the `bitmap' field of *) + (* the @FT_GlyphSlotRec structure to read it. *) + (* *) + (* FT_GLYPH_FORMAT_OUTLINE :: *) + (* The glyph image is a vertorial outline made of line segments *) + (* and Bezier arcs; it can be described as an @FT_Outline; you *) + (* generally want to access the `outline' field of the *) + (* @FT_GlyphSlotRec structure to read it. *) + (* *) + (* FT_GLYPH_FORMAT_PLOTTER :: *) + (* The glyph image is a vectorial path with no inside/outside *) + (* contours. Some Type 1 fonts, like those in the Hershey family, *) + (* contain glyphs in this format. These are described as *) + (* @FT_Outline, but FreeType isn't currently capable of rendering *) + (* them correctly. *) + (* *) + FT_Glyph_Format = array[0..3] of char; +{$ELSE TYPE_DECL} +const + FT_GLYPH_FORMAT_NONE: FT_Glyph_Format = (#0, #0, #0, #0 ); + + FT_GLYPH_FORMAT_COMPOSITE: FT_Glyph_Format = ('c', 'o', 'm', 'p' ); + FT_GLYPH_FORMAT_BITMAP: FT_Glyph_Format = ('b', 'i', 't', 's' ); + FT_GLYPH_FORMAT_OUTLINE: FT_Glyph_Format = ('o', 'u', 't', 'l' ); + FT_GLYPH_FORMAT_PLOTTER: FT_Glyph_Format = ('p', 'l', 'o', 't' ); + +{$ENDIF TYPE_DECL} + + (*************************************************************************) + (*************************************************************************) + (*************************************************************************) + (***** *****) + (***** R A S T E R D E F I N I T I O N S *****) + (***** *****) + (*************************************************************************) + (*************************************************************************) + (*************************************************************************) + + + (*************************************************************************) + (* *) + (* A raster is a scan converter, in charge of rendering an outline into *) + (* a a bitmap. This section contains the public API for rasters. *) + (* *) + (* Note that in FreeType 2, all rasters are now encapsulated within *) + (* specific modules called `renderers'. See `freetype/ftrender.h' for *) + (* more details on renderers. *) + (* *) + (*************************************************************************) + + + (*************************************************************************) + (* *) + (* <Section> *) + (* raster *) + (* *) + (* <Title> *) + (* Scanline Converter *) + (* *) + (* <Abstract> *) + (* How vectorial outlines are converted into bitmaps and pixmaps. *) + (* *) + (* <Description> *) + (* This section contains technical definitions. *) + (* *) + (*************************************************************************) + +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Raster *) + (* *) + (* <Description> *) + (* A handle (pointer) to a raster object. Each object can be used *) + (* independently to convert an outline into a bitmap or pixmap. *) + (* *) + FT_Raster = Pointer; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Span *) + (* *) + (* <Description> *) + (* A structure used to model a single span of gray (or black) pixels *) + (* when rendering a monochrome or anti-aliased bitmap. *) + (* *) + (* <Fields> *) + (* x :: The span's horizontal start position. *) + (* *) + (* len :: The span's length in pixels. *) + (* *) + (* coverage :: The span color/coverage, ranging from 0 (background) *) + (* to 255 (foreground). Only used for anti-aliased *) + (* rendering. *) + (* *) + (* <Note> *) + (* This structure is used by the span drawing callback type named *) + (* @FT_SpanFunc which takes the y-coordinate of the span as a *) + (* a parameter. *) + (* *) + (* The coverage value is always between 0 and 255. *) + (* *) + PFT_Span = ^FT_Span; + FT_Span = record + x: cshort; + len: cushort; + coverage: cuchar; + end; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_SpanFunc *) + (* *) + (* <Description> *) + (* A function used as a call-back by the anti-aliased renderer in *) + (* order to let client applications draw themselves the gray pixel *) + (* spans on each scan line. *) + (* *) + (* <Input> *) + (* y :: The scanline's y-coordinate. *) + (* *) + (* count :: The number of spans to draw on this scanline. *) + (* *) + (* spans :: A table of `count' spans to draw on the scanline. *) + (* *) + (* user :: User-supplied data that is passed to the callback. *) + (* *) + (* <Note> *) + (* This callback allows client applications to directly render the *) + (* gray spans of the anti-aliased bitmap to any kind of surfaces. *) + (* *) + (* This can be used to write anti-aliased outlines directly to a *) + (* given background bitmap, and even perform translucency. *) + (* *) + (* Note that the `count' field cannot be greater than a fixed value *) + (* defined by the `FT_MAX_GRAY_SPANS' configuration macro in *) + (* `ftoption.h'. By default, this value is set to 32, which means *) + (* that if there are more than 32 spans on a given scanline, the *) + (* callback is called several times with the same `y' parameter in *) + (* order to draw all callbacks. *) + (* *) + (* Otherwise, the callback is only called once per scan-line, and *) + (* only for those scanlines that do have `gray' pixels on them. *) + (* *) + FT_SpanFunc = procedure(y: cint; + count: cint; + spans: {const} PFT_Span; + user: Pointer ); cdecl; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Raster_BitTest_Func *) + (* *) + (* <Description> *) + (* THIS TYPE IS DEPRECATED. DO NOT USE IT. *) + (* *) + (* A function used as a call-back by the monochrome scan-converter *) + (* to test whether a given target pixel is already set to the drawing *) + (* `color'. These tests are crucial to implement drop-out control *) + (* per-se the TrueType spec. *) + (* *) + (* <Input> *) + (* y :: The pixel's y-coordinate. *) + (* *) + (* x :: The pixel's x-coordinate. *) + (* *) + (* user :: User-supplied data that is passed to the callback. *) + (* *) + (* <Return> *) + (* 1 if the pixel is `set', 0 otherwise. *) + (* *) + FT_Raster_BitTest_Func = function(y: cint; + x: cint; + user: Pointer): cint; cdecl; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Raster_BitSet_Func *) + (* *) + (* <Description> *) + (* THIS TYPE IS DEPRECATED. DO NOT USE IT. *) + (* *) + (* A function used as a call-back by the monochrome scan-converter *) + (* to set an individual target pixel. This is crucial to implement *) + (* drop-out control according to the TrueType specification. *) + (* *) + (* <Input> *) + (* y :: The pixel's y-coordinate. *) + (* *) + (* x :: The pixel's x-coordinate. *) + (* *) + (* user :: User-supplied data that is passed to the callback. *) + (* *) + (* <Return> *) + (* 1 if the pixel is `set', 0 otherwise. *) + (* *) + FT_Raster_BitSet_Func = procedure(y: cint; + x: cint; + user: Pointer ); cdecl; + + + (*************************************************************************) + (* *) + (* <Enum> *) + (* FT_RASTER_FLAG_XXX *) + (* *) + (* <Description> *) + (* A list of bit flag constants as used in the `flags' field of a *) + (* @FT_Raster_Params structure. *) + (* *) + (* <Values> *) + (* FT_RASTER_FLAG_DEFAULT :: This value is 0. *) + (* *) + (* FT_RASTER_FLAG_AA :: This flag is set to indicate that an *) + (* anti-aliased glyph image should be *) + (* generated. Otherwise, it will be *) + (* monochrome (1-bit). *) + (* *) + (* FT_RASTER_FLAG_DIRECT :: This flag is set to indicate direct *) + (* rendering. In this mode, client *) + (* applications must provide their own span *) + (* callback. This lets them directly *) + (* draw or compose over an existing bitmap. *) + (* If this bit is not set, the target *) + (* pixmap's buffer _must_ be zeroed before *) + (* rendering. *) + (* *) + (* Note that for now, direct rendering is *) + (* only possible with anti-aliased glyphs. *) + (* *) + (* FT_RASTER_FLAG_CLIP :: This flag is only used in direct *) + (* rendering mode. If set, the output will *) + (* be clipped to a box specified in the *) + (* `clip_box' field of the *) + (* @FT_Raster_Params structure. *) + (* *) + (* Note that by default, the glyph bitmap *) + (* is clipped to the target pixmap, except *) + (* in direct rendering mode where all spans *) + (* are generated if no clipping box is set. *) + (* *) +{$ELSE TYPE_DECL} +const + FT_RASTER_FLAG_DEFAULT = $0; + FT_RASTER_FLAG_AA = $1; + FT_RASTER_FLAG_DIRECT = $2; + FT_RASTER_FLAG_CLIP = $4; + +{$ENDIF TYPE_DECL} +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Raster_Params *) + (* *) + (* <Description> *) + (* A structure to hold the arguments used by a raster's render *) + (* function. *) + (* *) + (* <Fields> *) + (* target :: The target bitmap. *) + (* *) + (* source :: A pointer to the source glyph image (e.g., an *) + (* @FT_Outline). *) + (* *) + (* flags :: The rendering flags. *) + (* *) + (* gray_spans :: The gray span drawing callback. *) + (* *) + (* black_spans :: The black span drawing callback. *) + (* *) + (* bit_test :: The bit test callback. UNIMPLEMENTED! *) + (* *) + (* bit_set :: The bit set callback. UNIMPLEMENTED! *) + (* *) + (* user :: User-supplied data that is passed to each drawing *) + (* callback. *) + (* *) + (* clip_box :: An optional clipping box. It is only used in *) + (* direct rendering mode. Note that coordinates here *) + (* should be expressed in _integer_ pixels (and not in *) + (* 26.6 fixed-point units). *) + (* *) + (* <Note> *) + (* An anti-aliased glyph bitmap is drawn if the @FT_RASTER_FLAG_AA *) + (* bit flag is set in the `flags' field, otherwise a monochrome *) + (* bitmap is generated. *) + (* *) + (* If the @FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the *) + (* raster will call the `gray_spans' callback to draw gray pixel *) + (* spans, in the case of an aa glyph bitmap, it will call *) + (* `black_spans', and `bit_test' and `bit_set' in the case of a *) + (* monochrome bitmap. This allows direct composition over a *) + (* pre-existing bitmap through user-provided callbacks to perform the *) + (* span drawing/composition. *) + (* *) + (* Note that the `bit_test' and `bit_set' callbacks are required when *) + (* rendering a monochrome bitmap, as they are crucial to implement *) + (* correct drop-out control as defined in the TrueType specification. *) + (* *) + PFT_Raster_Params = ^FT_Raster_Params; + FT_Raster_Params = record + target: {const} PFT_Bitmap; + source: {const} Pointer; + flags: cint; + gray_spans: FT_SpanFunc; + black_spans: FT_SpanFunc; + bit_test: FT_Raster_BitTest_Func; (* doesn't work! *) + bit_set: FT_Raster_BitSet_Func; (* doesn't work! *) + user: Pointer; + clip_box: FT_BBox; + end; + +{$ENDIF TYPE_DECL} + + diff --git a/src/lib/freetype/ftoutln.inc b/src/lib/freetype/ftoutln.inc new file mode 100644 index 00000000..997c6cb3 --- /dev/null +++ b/src/lib/freetype/ftoutln.inc @@ -0,0 +1,497 @@ +(***************************************************************************) +(* *) +(* ftoutln.h *) +(* *) +(* Support for the FT_Outline type used to store glyph shapes of *) +(* most scalable font formats (specification). *) +(* *) +(* Copyright 1996-2001, 2002, 2003, 2005, 2006, 2007 by *) +(* David Turner, Robert Wilhelm, and Werner Lemberg. *) +(* *) +(* This file is part of the FreeType project, and may only be used, *) +(* modified, and distributed under the terms of the FreeType project *) +(* license, LICENSE.TXT. By continuing to use, modify, or distribute *) +(* this file you indicate that you have read the license and *) +(* understand and accept it fully. *) +(* *) +(***************************************************************************) +(***************************************************************************) +(* Pascal port by the UltraStar Deluxe Team *) +(***************************************************************************) + + + (*************************************************************************) + (* *) + (* <Section> *) + (* outline_processing *) + (* *) + (* <Title> *) + (* Outline Processing *) + (* *) + (* <Abstract> *) + (* Functions to create, transform, and render vectorial glyph images. *) + (* *) + (* <Description> *) + (* This section contains routines used to create and destroy scalable *) + (* glyph images known as `outlines'. These can also be measured, *) + (* transformed, and converted into bitmaps and pixmaps. *) + (* *) + (* <Order> *) + (* FT_Outline *) + (* FT_OUTLINE_FLAGS *) + (* FT_Outline_New *) + (* FT_Outline_Done *) + (* FT_Outline_Copy *) + (* FT_Outline_Translate *) + (* FT_Outline_Transform *) + (* FT_Outline_Embolden *) + (* FT_Outline_Reverse *) + (* FT_Outline_Check *) + (* *) + (* FT_Outline_Get_CBox *) + (* FT_Outline_Get_BBox *) + (* *) + (* FT_Outline_Get_Bitmap *) + (* FT_Outline_Render *) + (* *) + (* FT_Outline_Decompose *) + (* FT_Outline_Funcs *) + (* FT_Outline_MoveTo_Func *) + (* FT_Outline_LineTo_Func *) + (* FT_Outline_ConicTo_Func *) + (* FT_Outline_CubicTo_Func *) + (* *) + (*************************************************************************) + +{$IFNDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Decompose *) + (* *) + (* <Description> *) + (* Walks over an outline's structure to decompose it into individual *) + (* segments and Bézier arcs. This function is also able to emit *) + (* `move to' and `close to' operations to indicate the start and end *) + (* of new contours in the outline. *) + (* *) + (* <Input> *) + (* outline :: A pointer to the source target. *) + (* *) + (* func_interface :: A table of `emitters', i.e,. function pointers *) + (* called during decomposition to indicate path *) + (* operations. *) + (* *) + (* <InOut> *) + (* user :: A typeless pointer which is passed to each *) + (* emitter during the decomposition. It can be *) + (* used to store the state during the *) + (* decomposition. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Outline_Decompose( + outline: PFT_Outline; + func_interface: {const} PFT_Outline_Funcs; + user: Pointer): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Decompose'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_New *) + (* *) + (* <Description> *) + (* Creates a new outline of a given size. *) + (* *) + (* <Input> *) + (* library :: A handle to the library object from where the *) + (* outline is allocated. Note however that the new *) + (* outline will *not* necessarily be *freed*, when *) + (* destroying the library, by @FT_Done_FreeType. *) + (* *) + (* numPoints :: The maximal number of points within the outline. *) + (* *) + (* numContours :: The maximal number of contours within the outline. *) + (* *) + (* <Output> *) + (* anoutline :: A handle to the new outline. NULL in case of *) + (* error. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* The reason why this function takes a `library' parameter is simply *) + (* to use the library's memory allocator. *) + (* *) + function FT_Outline_New( + library_: FT_Library; + numPoints: FT_UInt; + numContours: FT_Int; + anoutline: PFT_Outline): FT_Error; + cdecl; external ft_lib name 'FT_Outline_New'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Done *) + (* *) + (* <Description> *) + (* Destroys an outline created with @FT_Outline_New. *) + (* *) + (* <Input> *) + (* library :: A handle of the library object used to allocate the *) + (* outline. *) + (* *) + (* outline :: A pointer to the outline object to be discarded. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* If the outline's `owner' field is not set, only the outline *) + (* descriptor will be released. *) + (* *) + (* The reason why this function takes an `library' parameter is *) + (* simply to use ft_mem_free(). *) + (* *) + function FT_Outline_Done(library_: FT_Library; + outline: PFT_Outline): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Done'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Check *) + (* *) + (* <Description> *) + (* Check the contents of an outline descriptor. *) + (* *) + (* <Input> *) + (* outline :: A handle to a source outline. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Outline_Check( outline: PFT_Outline ): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Check'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Get_CBox *) + (* *) + (* <Description> *) + (* Returns an outline's `control box'. The control box encloses all *) + (* the outline's points, including Bézier control points. Though it *) + (* coincides with the exact bounding box for most glyphs, it can be *) + (* slightly larger in some situations (like when rotating an outline *) + (* which contains Bézier outside arcs). *) + (* *) + (* Computing the control box is very fast, while getting the bounding *) + (* box can take much more time as it needs to walk over all segments *) + (* and arcs in the outline. To get the latter, you can use the *) + (* `ftbbox' component which is dedicated to this single task. *) + (* *) + (* <Input> *) + (* outline :: A pointer to the source outline descriptor. *) + (* *) + (* <Output> *) + (* acbox :: The outline's control box. *) + (* *) + procedure FT_Outline_Get_CBox( + outline: {const} PFT_Outline; + acbox: PFT_BBox); + cdecl; external ft_lib name 'FT_Outline_Get_CBox'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Translate *) + (* *) + (* <Description> *) + (* Applies a simple translation to the points of an outline. *) + (* *) + (* <InOut> *) + (* outline :: A pointer to the target outline descriptor. *) + (* *) + (* <Input> *) + (* xOffset :: The horizontal offset. *) + (* *) + (* yOffset :: The vertical offset. *) + (* *) + procedure FT_Outline_Translate( + outline: {const} PFT_Outline; + xOffset: FT_Pos; + yOffset: FT_Pos); + cdecl; external ft_lib name 'FT_Outline_Translate'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Copy *) + (* *) + (* <Description> *) + (* Copies an outline into another one. Both objects must have the *) + (* same sizes (number of points & number of contours) when this *) + (* function is called. *) + (* *) + (* <Input> *) + (* source :: A handle to the source outline. *) + (* *) + (* <Output> *) + (* target :: A handle to the target outline. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + function FT_Outline_Copy( + source: {const} PFT_Outline; + target: PFT_Outline): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Copy'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Transform *) + (* *) + (* <Description> *) + (* Applies a simple 2x2 matrix to all of an outline's points. Useful *) + (* for applying rotations, slanting, flipping, etc. *) + (* *) + (* <InOut> *) + (* outline :: A pointer to the target outline descriptor. *) + (* *) + (* <Input> *) + (* matrix :: A pointer to the transformation matrix. *) + (* *) + (* <Note> *) + (* You can use @FT_Outline_Translate if you need to translate the *) + (* outline's points. *) + (* *) + procedure FT_Outline_Transform( + outline: {const} PFT_Outline; + matrix: {const} PFT_Matrix); + cdecl; external ft_lib name 'FT_Outline_Transform'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Embolden *) + (* *) + (* <Description> *) + (* Emboldens an outline. The new outline will be at most 4 times *) + (* `strength' pixels wider and higher. You may think of the left and *) + (* bottom borders as unchanged. *) + (* *) + (* Negative `strength' values to reduce the outline thickness are *) + (* possible also. *) + (* *) + (* <InOut> *) + (* outline :: A handle to the target outline. *) + (* *) + (* <Input> *) + (* strength :: How strong the glyph is emboldened. Expressed in *) + (* 26.6 pixel format. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* The used algorithm to increase or decrease the thickness of the *) + (* glyph doesn't change the number of points; this means that certain *) + (* situations like acute angles or intersections are sometimes *) + (* handled incorrectly. *) + (* *) + (* Example call: *) + (* *) + (* { *) + (* FT_Load_Glyph( face, index, FT_LOAD_DEFAULT ); *) + (* if ( face->slot->format == FT_GLYPH_FORMAT_OUTLINE ) *) + (* FT_Outline_Embolden( &face->slot->outline, strength ); *) + (* } *) + (* *) + function FT_Outline_Embolden( + outline: PFT_Outline; + strength: FT_Pos): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Embolden'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Reverse *) + (* *) + (* <Description> *) + (* Reverses the drawing direction of an outline. This is used to *) + (* ensure consistent fill conventions for mirrored glyphs. *) + (* *) + (* <InOut> *) + (* outline :: A pointer to the target outline descriptor. *) + (* *) + (* <Note> *) + (* This functions toggles the bit flag @FT_OUTLINE_REVERSE_FILL in *) + (* the outline's `flags' field. *) + (* *) + (* It shouldn't be used by a normal client application, unless it *) + (* knows what it is doing. *) + (* *) + procedure FT_Outline_Reverse( outline: PFT_Outline ); + cdecl; external ft_lib name 'FT_Outline_Reverse'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Get_Bitmap *) + (* *) + (* <Description> *) + (* Renders an outline within a bitmap. The outline's image is simply *) + (* OR-ed to the target bitmap. *) + (* *) + (* <Input> *) + (* library :: A handle to a FreeType library object. *) + (* *) + (* outline :: A pointer to the source outline descriptor. *) + (* *) + (* <InOut> *) + (* abitmap :: A pointer to the target bitmap descriptor. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* This function does NOT CREATE the bitmap, it only renders an *) + (* outline image within the one you pass to it! *) + (* *) + (* It will use the raster corresponding to the default glyph format. *) + (* *) + function FT_Outline_Get_Bitmap( + library_: FT_Library; + outline: PFT_Outline; + abitmap: {const} PFT_Bitmap): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Get_Bitmap'; + + + (*************************************************************************) + (* *) + (* <Function> *) + (* FT_Outline_Render *) + (* *) + (* <Description> *) + (* Renders an outline within a bitmap using the current scan-convert. *) + (* This functions uses an @FT_Raster_Params structure as an argument, *) + (* allowing advanced features like direct composition, translucency, *) + (* etc. *) + (* *) + (* <Input> *) + (* library :: A handle to a FreeType library object. *) + (* *) + (* outline :: A pointer to the source outline descriptor. *) + (* *) + (* <InOut> *) + (* params :: A pointer to an @FT_Raster_Params structure used to *) + (* describe the rendering operation. *) + (* *) + (* <Return> *) + (* FreeType error code. 0 means success. *) + (* *) + (* <Note> *) + (* You should know what you are doing and how @FT_Raster_Params works *) + (* to use this function. *) + (* *) + (* The field `params.source' will be set to `outline' before the scan *) + (* converter is called, which means that the value you give to it is *) + (* actually ignored. *) + (* *) + function FT_Outline_Render( + library_: FT_Library; + outline: PFT_Outline; + params: PFT_Raster_Params): FT_Error; + cdecl; external ft_lib name 'FT_Outline_Render'; + +{$ENDIF TYPE_DECL} + + (************************************************************************** + * + * @enum: + * FT_Orientation + * + * @description: + * A list of values used to describe an outline's contour orientation. + * + * The TrueType and Postscript specifications use different conventions + * to determine whether outline contours should be filled or unfilled. + * + * @values: + * FT_ORIENTATION_TRUETYPE :: + * According to the TrueType specification, clockwise contours must + * be filled, and counter-clockwise ones must be unfilled. + * + * FT_ORIENTATION_POSTSCRIPT :: + * According to the Postscript specification, counter-clockwise contours + * must be filled, and clockwise ones must be unfilled. + * + * FT_ORIENTATION_FILL_RIGHT :: + * This is identical to @FT_ORIENTATION_TRUETYPE, but is used to + * remember that in TrueType, everything that is to the right of + * the drawing direction of a contour must be filled. + * + * FT_ORIENTATION_FILL_LEFT :: + * This is identical to @FT_ORIENTATION_POSTSCRIPT, but is used to + * remember that in Postscript, everything that is to the left of + * the drawing direction of a contour must be filled. + * + * FT_ORIENTATION_NONE :: + * The orientation cannot be determined. That is, different parts of + * the glyph have different orientation. + * + *) +{$IFDEF TYPE_DECL} + FT_Orientation = cint; +{$ELSE TYPE_DECL} +const + FT_ORIENTATION_TRUETYPE = 0; + FT_ORIENTATION_POSTSCRIPT = 1; + FT_ORIENTATION_FILL_RIGHT = FT_ORIENTATION_TRUETYPE; + FT_ORIENTATION_FILL_LEFT = FT_ORIENTATION_POSTSCRIPT; + FT_ORIENTATION_NONE = FT_ORIENTATION_FILL_LEFT+1; + + (************************************************************************** + * + * @function: + * FT_Outline_Get_Orientation + * + * @description: + * This function analyzes a glyph outline and tries to compute its + * fill orientation (see @FT_Orientation). This is done by computing + * the direction of each global horizontal and/or vertical extrema + * within the outline. + * + * Note that this will return @FT_ORIENTATION_TRUETYPE for empty + * outlines. + * + * @input: + * outline :: + * A handle to the source outline. + * + * @return: + * The orientation. + * + *) + function FT_Outline_Get_Orientation( outline: PFT_Outline ): FT_Orientation; + cdecl; external ft_lib name 'FT_Outline_Get_Orientation'; + +{$ENDIF TYPE_DECL} + diff --git a/src/lib/freetype/ftstroke.inc b/src/lib/freetype/ftstroke.inc new file mode 100644 index 00000000..bf8a00ae --- /dev/null +++ b/src/lib/freetype/ftstroke.inc @@ -0,0 +1,711 @@ +{***************************************************************************} +{* *} +{* ftstroke.h *} +{* *} +{* FreeType path stroker (specification). *} +{* *} +{* Copyright 2002, 2003, 2004, 2005, 2006 by *} +{* David Turner, Robert Wilhelm, and Werner Lemberg. *} +{* *} +{* This file is part of the FreeType project, and may only be used, *} +{* modified, and distributed under the terms of the FreeType project *} +{* license, LICENSE.TXT. By continuing to use, modify, or distribute *} +{* this file you indicate that you have read the license and *} +{* understand and accept it fully. *} +{* *} +{***************************************************************************} +(***************************************************************************) +(* Pascal port by the UltraStar Deluxe Team *) +(***************************************************************************) + + {************************************************************************ + * + * @section: + * glyph_stroker + * + * @title: + * Glyph Stroker + * + * @abstract: + * Generating bordered and stroked glyphs. + * + * @description: + * This component generates stroked outlines of a given vectorial + * glyph. It also allows you to retrieve the `outside' and/or the + * `inside' borders of the stroke. + * + * This can be useful to generate `bordered' glyph, i.e., glyphs + * displayed with a coloured (and anti-aliased) border around their + * shape. + *} + +{$IFDEF TYPE_DECL} + + {************************************************************** + * + * @type: + * FT_Stroker + * + * @description: + * Opaque handler to a path stroker object. + *} + FT_Stroker = Pointer; + + + {************************************************************** + * + * @enum: + * FT_Stroker_LineJoin + * + * @description: + * These values determine how two joining lines are rendered + * in a stroker. + * + * @values: + * FT_STROKER_LINEJOIN_ROUND :: + * Used to render rounded line joins. Circular arcs are used + * to join two lines smoothly. + * + * FT_STROKER_LINEJOIN_BEVEL :: + * Used to render beveled line joins; i.e., the two joining lines + * are extended until they intersect. + * + * FT_STROKER_LINEJOIN_MITER :: + * Same as beveled rendering, except that an additional line + * break is added if the angle between the two joining lines + * is too closed (this is useful to avoid unpleasant spikes + * in beveled rendering). + *} + FT_Stroker_LineJoin = cint; +{$ELSE TYPE_DECL} +const + FT_STROKER_LINEJOIN_ROUND = 0; + FT_STROKER_LINEJOIN_BEVEL = 1; + FT_STROKER_LINEJOIN_MITER = 2; + +{$ENDIF TYPE_DECL} +{$IFDEF TYPE_DECL} + + {************************************************************** + * + * @enum: + * FT_Stroker_LineCap + * + * @description: + * These values determine how the end of opened sub-paths are + * rendered in a stroke. + * + * @values: + * FT_STROKER_LINECAP_BUTT :: + * The end of lines is rendered as a full stop on the last + * point itself. + * + * FT_STROKER_LINECAP_ROUND :: + * The end of lines is rendered as a half-circle around the + * last point. + * + * FT_STROKER_LINECAP_SQUARE :: + * The end of lines is rendered as a square around the + * last point. + *} + FT_Stroker_LineCap = cint; +{$ELSE TYPE_DECL} +const + FT_STROKER_LINECAP_BUTT = 0; + FT_STROKER_LINECAP_ROUND = 1; + FT_STROKER_LINECAP_SQUARE = 2; + +{$ENDIF TYPE_DECL} +{$IFDEF TYPE_DECL} + + {************************************************************** + * + * @enum: + * FT_StrokerBorder + * + * @description: + * These values are used to select a given stroke border + * in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder. + * + * @values: + * FT_STROKER_BORDER_LEFT :: + * Select the left border, relative to the drawing direction. + * + * FT_STROKER_BORDER_RIGHT :: + * Select the right border, relative to the drawing direction. + * + * @note: + * Applications are generally interested in the `inside' and `outside' + * borders. However, there is no direct mapping between these and the + * `left' and `right' ones, since this really depends on the glyph's + * drawing orientation, which varies between font formats. + * + * You can however use @FT_Outline_GetInsideBorder and + * @FT_Outline_GetOutsideBorder to get these. + *} + FT_StrokerBorder = cint; +{$ELSE TYPE_DECL} +const + FT_STROKER_BORDER_LEFT = 0; + FT_STROKER_BORDER_RIGHT = 1; + + + {************************************************************** + * + * @function: + * FT_Outline_GetInsideBorder + * + * @description: + * Retrieve the @FT_StrokerBorder value corresponding to the + * `inside' borders of a given outline. + * + * @input: + * outline :: + * The source outline handle. + * + * @return: + * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid + * outlines. + *} + function FT_Outline_GetInsideBorder( outline: PFT_Outline ): FT_StrokerBorder; + cdecl; external ft_lib name 'FT_Outline_GetInsideBorder'; + + + {************************************************************** + * + * @function: + * FT_Outline_GetOutsideBorder + * + * @description: + * Retrieve the @FT_StrokerBorder value corresponding to the + * `outside' borders of a given outline. + * + * @input: + * outline :: + * The source outline handle. + * + * @return: + * The border index. @FT_STROKER_BORDER_LEFT for empty or invalid + * outlines. + *} + function FT_Outline_GetOutsideBorder( outline: PFT_Outline ): FT_StrokerBorder; + cdecl; external ft_lib name 'FT_Outline_GetOutsideBorder'; + + + {************************************************************** + * + * @function: + * FT_Stroker_New + * + * @description: + * Create a new stroker object. + * + * @input: + * library :: + * FreeType library handle. + * + * @output: + * astroker :: + * A new stroker object handle. NULL in case of error. + * + * @return: + * FreeType error code. 0 means success. + *} + function FT_Stroker_New( + library_: FT_Library; + out astroker: FT_Stroker ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_New'; + + + {************************************************************** + * + * @function: + * FT_Stroker_Set + * + * @description: + * Reset a stroker object's attributes. + * + * @input: + * stroker :: + * The target stroker handle. + * + * radius :: + * The border radius. + * + * line_cap :: + * The line cap style. + * + * line_join :: + * The line join style. + * + * miter_limit :: + * The miter limit for the FT_STROKER_LINEJOIN_MITER style, + * expressed as 16.16 fixed point value. + * + * @note: + * The radius is expressed in the same units that the outline + * coordinates. + *} + procedure FT_Stroker_Set( + stroker: FT_Stroker; + radius: FT_Fixed; + line_cap: FT_Stroker_LineCap; + line_join: FT_Stroker_LineJoin; + miter_limit: FT_Fixed ); + cdecl; external ft_lib name 'FT_Stroker_Set'; + + + {************************************************************** + * + * @function: + * FT_Stroker_Rewind + * + * @description: + * Reset a stroker object without changing its attributes. + * You should call this function before beginning a new + * series of calls to @FT_Stroker_BeginSubPath or + * @FT_Stroker_EndSubPath. + * + * @input: + * stroker :: + * The target stroker handle. + *} + procedure FT_Stroker_Rewind( stroker: FT_Stroker ); + cdecl; external ft_lib name 'FT_Stroker_Rewind'; + + + {************************************************************** + * + * @function: + * FT_Stroker_ParseOutline + * + * @description: + * A convenience function used to parse a whole outline with + * the stroker. The resulting outline(s) can be retrieved + * later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export. + * + * @input: + * stroker :: + * The target stroker handle. + * + * outline :: + * The source outline. + * + * opened :: + * A boolean. If 1, the outline is treated as an open path instead + * of a closed one. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * If `opened' is 0 (the default), the outline is treated as a closed + * path, and the stroker will generate two distinct `border' outlines. + * + * If `opened' is 1, the outline is processed as an open path, and the + * stroker will generate a single `stroke' outline. + * + * This function calls @FT_Stroker_Rewind automatically. + *} + function FT_Stroker_ParseOutline( + stroker: FT_Stroker; + outline: PFT_Outline; + opened: FT_Bool): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_ParseOutline'; + + + {************************************************************** + * + * @function: + * FT_Stroker_BeginSubPath + * + * @description: + * Start a new sub-path in the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * to :: + * A pointer to the start vector. + * + * open :: + * A boolean. If 1, the sub-path is treated as an open one. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * This function is useful when you need to stroke a path that is + * not stored as an @FT_Outline object. + *} + function FT_Stroker_BeginSubPath( + stroker: FT_Stroker; + to_: PFT_Vector; + open: FT_Bool ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_BeginSubPath'; + + + {************************************************************** + * + * @function: + * FT_Stroker_EndSubPath + * + * @description: + * Close the current sub-path in the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * You should call this function after @FT_Stroker_BeginSubPath. + * If the subpath was not `opened', this function will `draw' a + * single line segment to the start position when needed. + *} + function FT_Stroker_EndSubPath( stroker: FT_Stroker ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_EndSubPath'; + + + {************************************************************** + * + * @function: + * FT_Stroker_LineTo + * + * @description: + * `Draw' a single line segment in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + *} + function FT_Stroker_LineTo( + stroker: FT_Stroker; + to_: PFT_Vector ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_LineTo'; + + + {************************************************************** + * + * @function: + * FT_Stroker_ConicTo + * + * @description: + * `Draw' a single quadratic Bézier in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * control :: + * A pointer to a Bézier control point. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + *} + function FT_Stroker_ConicTo( + stroker: FT_Stroker; + control: PFT_Vector; + to_: PFT_Vector ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_ConicTo'; + + + {************************************************************** + * + * @function: + * FT_Stroker_CubicTo + * + * @description: + * `Draw' a single cubic Bézier in the stroker's current sub-path, + * from the last position. + * + * @input: + * stroker :: + * The target stroker handle. + * + * control1 :: + * A pointer to the first Bézier control point. + * + * control2 :: + * A pointer to second Bézier control point. + * + * to :: + * A pointer to the destination point. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * You should call this function between @FT_Stroker_BeginSubPath and + * @FT_Stroker_EndSubPath. + *} + function FT_Stroker_CubicTo( + stroker: FT_Stroker; + control1: PFT_Vector; + control2: PFT_Vector; + to_: PFT_Vector ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_CubicTo'; + + + {************************************************************** + * + * @function: + * FT_Stroker_GetBorderCounts + * + * @description: + * Call this function once you have finished parsing your paths + * with the stroker. It will return the number of points and + * contours necessary to export one of the `border' or `stroke' + * outlines generated by the stroker. + * + * @input: + * stroker :: + * The target stroker handle. + * + * border :: + * The border index. + * + * @output: + * anum_points :: + * The number of points. + * + * anum_contours :: + * The number of contours. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * When an outline, or a sub-path, is `closed', the stroker generates + * two independent `border' outlines, named `left' and `right'. + * + * When the outline, or a sub-path, is `opened', the stroker merges + * the `border' outlines with caps. The `left' border receives all + * points, while the `right' border becomes empty. + * + * Use the function @FT_Stroker_GetCounts instead if you want to + * retrieve the counts associated to both borders. + *} + function FT_Stroker_GetBorderCounts( + stroker: FT_Stroker; + border: FT_StrokerBorder; + out anum_points: FT_UInt; + out anum_contours: FT_UInt ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_GetBorderCounts'; + + + {************************************************************** + * + * @function: + * FT_Stroker_ExportBorder + * + * @description: + * Call this function after @FT_Stroker_GetBorderCounts to + * export the corresponding border to your own @FT_Outline + * structure. + * + * Note that this function will append the border points and + * contours to your outline, but will not try to resize its + * arrays. + * + * @input: + * stroker :: + * The target stroker handle. + * + * border :: + * The border index. + * + * outline :: + * The target outline handle. + * + * @note: + * Always call this function after @FT_Stroker_GetBorderCounts to + * get sure that there is enough room in your @FT_Outline object to + * receive all new data. + * + * When an outline, or a sub-path, is `closed', the stroker generates + * two independent `border' outlines, named `left' and `right' + * + * When the outline, or a sub-path, is `opened', the stroker merges + * the `border' outlines with caps. The `left' border receives all + * points, while the `right' border becomes empty. + * + * Use the function @FT_Stroker_Export instead if you want to + * retrieve all borders at once. + *} + procedure FT_Stroker_ExportBorder( + stroker: FT_Stroker; + border: FT_StrokerBorder; + outline: PFT_Outline ); + cdecl; external ft_lib name 'FT_Stroker_ExportBorder'; + + + {************************************************************** + * + * @function: + * FT_Stroker_GetCounts + * + * @description: + * Call this function once you have finished parsing your paths + * with the stroker. It returns the number of points and + * contours necessary to export all points/borders from the stroked + * outline/path. + * + * @input: + * stroker :: + * The target stroker handle. + * + * @output: + * anum_points :: + * The number of points. + * + * anum_contours :: + * The number of contours. + * + * @return: + * FreeType error code. 0 means success. + *} + function FT_Stroker_GetCounts( + stroker: FT_Stroker; + out anum_points: FT_UInt; + out anum_contours: FT_UInt ): FT_Error; + cdecl; external ft_lib name 'FT_Stroker_GetCounts'; + + + {************************************************************** + * + * @function: + * FT_Stroker_Export + * + * @description: + * Call this function after @FT_Stroker_GetBorderCounts to + * export the all borders to your own @FT_Outline structure. + * + * Note that this function will append the border points and + * contours to your outline, but will not try to resize its + * arrays. + * + * @input: + * stroker :: + * The target stroker handle. + * + * outline :: + * The target outline handle. + *} + procedure FT_Stroker_Export( + stroker: FT_Stroker; + outline: PFT_Outline ); + cdecl; external ft_lib name 'FT_Stroker_Export'; + + + {************************************************************** + * + * @function: + * FT_Stroker_Done + * + * @description: + * Destroy a stroker object. + * + * @input: + * stroker :: + * A stroker handle. Can be NULL. + *} + procedure FT_Stroker_Done( stroker: FT_Stroker ); + cdecl; external ft_lib name 'FT_Stroker_Done'; + + + {************************************************************** + * + * @function: + * FT_Glyph_Stroke + * + * @description: + * Stroke a given outline glyph object with a given stroker. + * + * @inout: + * pglyph :: + * Source glyph handle on input, new glyph handle on output. + * + * @input: + * stroker :: + * A stroker handle. + * + * destroy :: + * A Boolean. If 1, the source glyph object is destroyed + * on success. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * The source glyph is untouched in case of error. + *} + function FT_Glyph_Stroke( + var glyph: FT_Glyph; + stroker: FT_Stroker; + destroy: FT_Bool ): FT_Error; + cdecl; external ft_lib name 'FT_Glyph_Stroke'; + + + {************************************************************** + * + * @function: + * FT_Glyph_StrokeBorder + * + * @description: + * Stroke a given outline glyph object with a given stroker, but + * only return either its inside or outside border. + * + * @inout: + * pglyph :: + * Source glyph handle on input, new glyph handle on output. + * + * @input: + * stroker :: + * A stroker handle. + * + * inside :: + * A Boolean. If 1, return the inside border, otherwise + * the outside border. + * + * destroy :: + * A Boolean. If 1, the source glyph object is destroyed + * on success. + * + * @return: + * FreeType error code. 0 means success. + * + * @note: + * The source glyph is untouched in case of error. + *} + function FT_Glyph_StrokeBorder( + var glyph: FT_Glyph; + stroker: FT_Stroker; + inside: FT_Bool; + destroy: FT_Bool ): FT_Error; + cdecl; external ft_lib name 'FT_Glyph_StrokeBorder'; + +{$ENDIF TYPE_DECL} + diff --git a/src/lib/freetype/fttypes.inc b/src/lib/freetype/fttypes.inc new file mode 100644 index 00000000..a64432e6 --- /dev/null +++ b/src/lib/freetype/fttypes.inc @@ -0,0 +1,311 @@ +(***************************************************************************) +(* *) +(* fttypes.h *) +(* *) +(* FreeType simple types definitions (specification only). *) +(* *) +(* Copyright 1996-2001, 2002, 2004, 2006, 2007 by *) +(* David Turner, Robert Wilhelm, and Werner Lemberg. *) +(* *) +(* This file is part of the FreeType project, and may only be used, *) +(* modified, and distributed under the terms of the FreeType project *) +(* license, LICENSE.TXT. By continuing to use, modify, or distribute *) +(* this file you indicate that you have read the license and *) +(* understand and accept it fully. *) +(* *) +(***************************************************************************) +(***************************************************************************) +(* Pascal port by the UltraStar Deluxe Team *) +(***************************************************************************) + + (*************************************************************************) + (* *) + (* <Section> *) + (* basic_types *) + (* *) + (* <Title> *) + (* Basic Data Types *) + (* *) + (* <Abstract> *) + (* The basic data types defined by the library. *) + (* *) + (* <Description> *) + (* This section contains the basic data types defined by FreeType 2, *) + (* ranging from simple scalar types to bitmap descriptors. More *) + (* font-specific structures are defined in a different section. *) + (* *) + (* <Order> *) + (* FT_Byte *) + (* FT_Bytes *) + (* FT_Char *) + (* FT_Int *) + (* FT_UInt *) + (* FT_Short *) + (* FT_UShort *) + (* FT_Long *) + (* FT_ULong *) + (* FT_Bool *) + (* FT_Offset *) + (* FT_PtrDist *) + (* FT_String *) + (* FT_Tag *) + (* FT_Error *) + (* FT_Fixed *) + (* FT_Pointer *) + (* FT_Pos *) + (* FT_Vector *) + (* FT_BBox *) + (* FT_Matrix *) + (* FT_FWord *) + (* FT_UFWord *) + (* FT_F2Dot14 *) + (* FT_UnitVector *) + (* FT_F26Dot6 *) + (* *) + (* *) + (* FT_Generic *) + (* FT_Generic_Finalizer *) + (* *) + (* FT_Bitmap *) + (* FT_Pixel_Mode *) + (* FT_Palette_Mode *) + (* FT_Glyph_Format *) + (* FT_IMAGE_TAG *) + (* *) + (*************************************************************************) + +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Bool *) + (* *) + (* <Description> *) + (* A typedef of unsigned char, used for simple booleans. As usual, *) + (* values 1 and 0 represent true and false, respectively. *) + (* *) + FT_Bool = cuchar; +{$ENDIF TYPE_DECL} +{$IFNDEF TYPE_DECL} +const + FT_FALSE = 0; + FT_TRUE = 1; +{$ENDIF !TYPE_DECL} +{$IFDEF TYPE_DECL} + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Byte *) + (* *) + (* <Description> *) + (* A simple typedef for the _unsigned_ char type. *) + (* *) + FT_Byte = cuchar; + PFT_Byte = ^FT_Byte; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_String *) + (* *) + (* <Description> *) + (* A simple typedef for the char type, usually used for strings. *) + (* *) + FT_String = cchar; + PFT_String = ^FT_String; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Short *) + (* *) + (* <Description> *) + (* A typedef for signed short. *) + (* *) + FT_Short = csshort; + PFT_Short = ^FT_Short; + + PFT_ShortArray = ^FT_ShortArray; + FT_ShortArray = array[0 .. (MaxInt div SizeOf(FT_Short))-1] of FT_Short; + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_UShort *) + (* *) + (* <Description> *) + (* A typedef for unsigned short. *) + (* *) + FT_UShort = cushort; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Int *) + (* *) + (* <Description> *) + (* A typedef for the int type. *) + (* *) + FT_Int = csint; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_UInt *) + (* *) + (* <Description> *) + (* A typedef for the unsigned int type. *) + (* *) + FT_UInt = cuint; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Long *) + (* *) + (* <Description> *) + (* A typedef for signed long. *) + (* *) + FT_Long = cslong; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_ULong *) + (* *) + (* <Description> *) + (* A typedef for unsigned long. *) + (* *) + FT_ULong = culong; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_F26Dot6 *) + (* *) + (* <Description> *) + (* A signed 26.6 fixed float type used for vectorial pixel *) + (* coordinates. *) + (* *) + FT_F26Dot6 = cslong; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Fixed *) + (* *) + (* <Description> *) + (* This type is used to store 16.16 fixed float values, like scaling *) + (* values or matrix coefficients. *) + (* *) + FT_Fixed = cslong; + + + (*************************************************************************) + (* *) + (* <Type> *) + (* FT_Error *) + (* *) + (* <Description> *) + (* The FreeType error code type. A value of 0 is always interpreted *) + (* as a successful operation. *) + (* *) + FT_Error = cint; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Matrix *) + (* *) + (* <Description> *) + (* A simple structure used to store a 2x2 matrix. Coefficients are *) + (* in 16.16 fixed float format. The computation performed is: *) + (* *) + (* { *) + (* x' = x*xx + y*xy *) + (* y' = x*yx + y*yy *) + (* } *) + (* *) + (* <Fields> *) + (* xx :: Matrix coefficient. *) + (* *) + (* xy :: Matrix coefficient. *) + (* *) + (* yx :: Matrix coefficient. *) + (* *) + (* yy :: Matrix coefficient. *) + (* *) + PFT_Matrix = ^FT_Matrix; + FT_Matrix = record + xx, xy: FT_Fixed; + yx, yy: FT_Fixed; + end; + + + (*************************************************************************) + (* *) + (* <FuncType> *) + (* FT_Generic_Finalizer *) + (* *) + (* <Description> *) + (* Describes a function used to destroy the `client' data of any *) + (* FreeType object. See the description of the FT_Generic type for *) + (* details of usage. *) + (* *) + (* <Input> *) + (* The address of the FreeType object which is under finalization. *) + (* Its client data is accessed through its `generic' field. *) + (* *) + FT_Generic_Finalizer = procedure(AnObject : pointer ); cdecl; + + + (*************************************************************************) + (* *) + (* <Struct> *) + (* FT_Generic *) + (* *) + (* <Description> *) + (* Client applications often need to associate their own data to a *) + (* variety of FreeType core objects. For example, a text layout API *) + (* might want to associate a glyph cache to a given size object. *) + (* *) + (* Most FreeType object contains a `generic' field, of type *) + (* FT_Generic, which usage is left to client applications and font *) + (* servers. *) + (* *) + (* It can be used to store a pointer to client-specific data, as well *) + (* as the address of a `finalizer' function, which will be called by *) + (* FreeType when the object is destroyed (for example, the previous *) + (* client example would put the address of the glyph cache destructor *) + (* in the `finalizer' field). *) + (* *) + (* <Fields> *) + (* data :: A typeless pointer to any client-specified data. This *) + (* field is completely ignored by the FreeType library. *) + (* *) + (* finalizer :: A pointer to a `generic finalizer' function, which *) + (* will be called when the object is destroyed. If this *) + (* field is set to NULL, no code will be called. *) + (* *) + FT_Generic = record + data: pointer; + finalizer: FT_Generic_Finalizer; + end; + + + TByteArray = array [0 .. (MaxInt div SizeOf(byte))-1] of byte; + PByteArray = ^TByteArray; + +{$ENDIF TYPE_DECL} + -- cgit v1.2.3 From e207d2671c3db087f0ec1b9f6594f1746ca16fa7 Mon Sep 17 00:00:00 2001 From: tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Fri, 23 Apr 2010 21:06:38 +0000 Subject: byte order of some C enums was incorrect git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2286 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/freetype.pas | 78 +++++++++++++++++++++++++++++++++++++------ src/lib/freetype/ftimage.inc | 60 +++++++++++++++++++++++++++++---- 2 files changed, 121 insertions(+), 17 deletions(-) (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/freetype.pas b/src/lib/freetype/freetype.pas index 6aaa3b59..01f507bc 100644 --- a/src/lib/freetype/freetype.pas +++ b/src/lib/freetype/freetype.pas @@ -150,6 +150,34 @@ const FT_FACE_FLAG_SCALABLE = 1 shl 0; FT_FACE_FLAG_KERNING = 1 shl 6; + (*************************************************************************) + (* *) + (* <Macro> *) + (* FT_ENC_TAG *) + (* *) + (* <Description> *) + (* This macro converts four-letter tags into an unsigned long. It is *) + (* used to define `encoding' identifiers (see @FT_Encoding). *) + (* *) + (* <Note> *) + (* Since many 16-bit compilers don't like 32-bit enumerations, you *) + (* should redefine this macro in case of problems to something like *) + (* this: *) + (* *) + (* { *) + (* #define FT_ENC_TAG( value, a, b, c, d ) value *) + (* } *) + (* *) + (* to get a simple enumeration without assigning special numbers. *) + (* *) + { + #define FT_ENC_TAG( value, a, b, c, d ) \ + value = ( ( (FT_UInt32)(a) << 24 ) | \ + ( (FT_UInt32)(b) << 16 ) | \ + ( (FT_UInt32)(c) << 8 ) | \ + (FT_UInt32)(d) ) + } + (*************************************************************************) (* *) (* <Enum> *) @@ -289,17 +317,47 @@ const (* *) type PFT_Encoding = ^FT_Encoding; - FT_Encoding = array[0..3] of char; + FT_Encoding = cint32; // 32 bit enum of FT_ENC_TAG const - FT_ENCODING_NONE: FT_Encoding = (#0 ,#0 ,#0 ,#0 ); - FT_ENCODING_MS_SYMBOL: FT_Encoding = ('s', 'y', 'm', 'b' ); - FT_ENCODING_UNICODE: FT_Encoding = ('u', 'n', 'i', 'c' ); - - FT_ENCODING_SJIS: FT_Encoding = ('s', 'j', 'i', 's'); - FT_ENCODING_GB2312: FT_Encoding = ('g', 'b', ' ', ' '); - FT_ENCODING_BIG5: FT_Encoding = ('b', 'i', 'g', '5'); - FT_ENCODING_WANSUNG: FT_Encoding = ('w', 'a', 'n', 's'); - FT_ENCODING_JOHAB: FT_Encoding = ('j', 'o', 'h', 'a'); + FT_ENCODING_NONE = (Ord(#0) shl 24) or + (Ord(#0) shl 16) or + (Ord(#0) shl 8) or + (Ord(#0) shl 0); + + FT_ENCODING_MS_SYMBOL = (Ord('s') shl 24) or + (Ord('y') shl 16) or + (Ord('m') shl 8) or + (Ord('b') shl 0); + + FT_ENCODING_UNICODE = (Ord('u') shl 24) or + (Ord('n') shl 16) or + (Ord('i') shl 8) or + (Ord('c') shl 0); + + FT_ENCODING_SJIS = (Ord('s') shl 24) or + (Ord('j') shl 16) or + (Ord('i') shl 8) or + (Ord('s') shl 0); + + FT_ENCODING_GB2312 = (Ord('g') shl 24) or + (Ord('b') shl 16) or + (Ord(' ') shl 8) or + (Ord(' ') shl 0); + + FT_ENCODING_BIG5 = (Ord('b') shl 24) or + (Ord('i') shl 16) or + (Ord('g') shl 8) or + (Ord('5') shl 0); + + FT_ENCODING_WANSUNG = (Ord('w') shl 24) or + (Ord('a') shl 16) or + (Ord('n') shl 8) or + (Ord('s') shl 0); + + FT_ENCODING_JOHAB = (Ord('j') shl 24) or + (Ord('o') shl 16) or + (Ord('h') shl 8) or + (Ord('a') shl 0); (*************************************************************************) diff --git a/src/lib/freetype/ftimage.inc b/src/lib/freetype/ftimage.inc index 9255c422..d16d52a2 100644 --- a/src/lib/freetype/ftimage.inc +++ b/src/lib/freetype/ftimage.inc @@ -452,6 +452,33 @@ const end; + (*************************************************************************) + (* *) + (* <Macro> *) + (* FT_IMAGE_TAG *) + (* *) + (* <Description> *) + (* This macro converts four-letter tags to an unsigned long type. *) + (* *) + (* <Note> *) + (* Since many 16-bit compilers don't like 32-bit enumerations, you *) + (* should redefine this macro in case of problems to something like *) + (* this: *) + (* *) + (* { *) + (* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value *) + (* } *) + (* *) + (* to get a simple enumeration without assigning special numbers. *) + (* *) + { + #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ + value = ( ( (unsigned long)_x1 << 24 ) | \ + ( (unsigned long)_x2 << 16 ) | \ + ( (unsigned long)_x3 << 8 ) | \ + (unsigned long)_x4 ) + } + (*************************************************************************) (* *) (* <Enum> *) @@ -490,15 +517,34 @@ const (* @FT_Outline, but FreeType isn't currently capable of rendering *) (* them correctly. *) (* *) - FT_Glyph_Format = array[0..3] of char; + // Note: enums are 32 bit on x86 AND x86_64 + FT_Glyph_Format = cuint32; // 32 bit enum of FT_IMAGE_TAG {$ELSE TYPE_DECL} const - FT_GLYPH_FORMAT_NONE: FT_Glyph_Format = (#0, #0, #0, #0 ); - - FT_GLYPH_FORMAT_COMPOSITE: FT_Glyph_Format = ('c', 'o', 'm', 'p' ); - FT_GLYPH_FORMAT_BITMAP: FT_Glyph_Format = ('b', 'i', 't', 's' ); - FT_GLYPH_FORMAT_OUTLINE: FT_Glyph_Format = ('o', 'u', 't', 'l' ); - FT_GLYPH_FORMAT_PLOTTER: FT_Glyph_Format = ('p', 'l', 'o', 't' ); + FT_GLYPH_FORMAT_NONE = (Ord(#0) shl 24) or + (Ord(#0) shl 16) or + (Ord(#0) shl 8) or + (Ord(#0) shl 0); + + FT_GLYPH_FORMAT_COMPOSITE = (Ord('c') shl 24) or + (Ord('o') shl 16) or + (Ord('m') shl 8) or + (Ord('p') shl 0); + + FT_GLYPH_FORMAT_BITMAP = (Ord('b') shl 24) or + (Ord('i') shl 16) or + (Ord('t') shl 8) or + (Ord('s') shl 0); + + FT_GLYPH_FORMAT_OUTLINE = (Ord('o') shl 24) or + (Ord('u') shl 16) or + (Ord('t') shl 8) or + (Ord('l') shl 0); + + FT_GLYPH_FORMAT_PLOTTER = (Ord('p') shl 24) or + (Ord('l') shl 16) or + (Ord('o') shl 8) or + (Ord('t') shl 0); {$ENDIF TYPE_DECL} -- cgit v1.2.3 From 2c618ba87578a7ca4acff5960284d22f472ae29c Mon Sep 17 00:00:00 2001 From: k-m_schindler <k-m_schindler@b956fd51-792f-4845-bead-9b4dfca2ff2c> Date: Thu, 19 Aug 2010 14:04:35 +0000 Subject: fix line endings. no code change git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2613 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/freetype/ftimage.inc | 72 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'src/lib/freetype') diff --git a/src/lib/freetype/ftimage.inc b/src/lib/freetype/ftimage.inc index d16d52a2..63eee534 100644 --- a/src/lib/freetype/ftimage.inc +++ b/src/lib/freetype/ftimage.inc @@ -453,32 +453,32 @@ const (*************************************************************************) - (* *) - (* <Macro> *) - (* FT_IMAGE_TAG *) - (* *) - (* <Description> *) - (* This macro converts four-letter tags to an unsigned long type. *) - (* *) - (* <Note> *) - (* Since many 16-bit compilers don't like 32-bit enumerations, you *) - (* should redefine this macro in case of problems to something like *) - (* this: *) - (* *) - (* { *) - (* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value *) - (* } *) - (* *) - (* to get a simple enumeration without assigning special numbers. *) - (* *) - { - #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ - value = ( ( (unsigned long)_x1 << 24 ) | \ - ( (unsigned long)_x2 << 16 ) | \ - ( (unsigned long)_x3 << 8 ) | \ - (unsigned long)_x4 ) - } - + (* *) + (* <Macro> *) + (* FT_IMAGE_TAG *) + (* *) + (* <Description> *) + (* This macro converts four-letter tags to an unsigned long type. *) + (* *) + (* <Note> *) + (* Since many 16-bit compilers don't like 32-bit enumerations, you *) + (* should redefine this macro in case of problems to something like *) + (* this: *) + (* *) + (* { *) + (* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value *) + (* } *) + (* *) + (* to get a simple enumeration without assigning special numbers. *) + (* *) + { + #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ + value = ( ( (unsigned long)_x1 << 24 ) | \ + ( (unsigned long)_x2 << 16 ) | \ + ( (unsigned long)_x3 << 8 ) | \ + (unsigned long)_x4 ) + } + (*************************************************************************) (* *) (* <Enum> *) @@ -522,28 +522,28 @@ const {$ELSE TYPE_DECL} const FT_GLYPH_FORMAT_NONE = (Ord(#0) shl 24) or - (Ord(#0) shl 16) or - (Ord(#0) shl 8) or + (Ord(#0) shl 16) or + (Ord(#0) shl 8) or (Ord(#0) shl 0); FT_GLYPH_FORMAT_COMPOSITE = (Ord('c') shl 24) or - (Ord('o') shl 16) or - (Ord('m') shl 8) or + (Ord('o') shl 16) or + (Ord('m') shl 8) or (Ord('p') shl 0); FT_GLYPH_FORMAT_BITMAP = (Ord('b') shl 24) or - (Ord('i') shl 16) or - (Ord('t') shl 8) or + (Ord('i') shl 16) or + (Ord('t') shl 8) or (Ord('s') shl 0); FT_GLYPH_FORMAT_OUTLINE = (Ord('o') shl 24) or - (Ord('u') shl 16) or - (Ord('t') shl 8) or + (Ord('u') shl 16) or + (Ord('t') shl 8) or (Ord('l') shl 0); FT_GLYPH_FORMAT_PLOTTER = (Ord('p') shl 24) or - (Ord('l') shl 16) or - (Ord('o') shl 8) or + (Ord('l') shl 16) or + (Ord('o') shl 8) or (Ord('t') shl 0); {$ENDIF TYPE_DECL} -- cgit v1.2.3