with Allegro.Bitmaps; use Allegro.Bitmaps;
with Allegro.Truecolor; use Allegro.Truecolor;
with System; use System;
package Alfont is
-- An AlFont instance represents a font loaded by the AlFont API and able to
-- be used to render strings to bitmaps.
type Alfont_Font is private;
type A_Alfont_Font is access all Alfont_Font;
type Size_Array is array (Natural range <>) of Integer;
pragma Convention( C, Size_Array );
type A_Size_Array is access all Size_Array;
STYLE_STANDARD : constant := 0; -- Standard style font
STYLE_ITALIC : constant := 1; -- Italic style font
STYLE_BOLD : constant := 2; -- Bold style font
STYLE_BOLDITALIC : constant := 3; -- BoldItalic style font
ALFONT_OK : constant := 0;
ALFONT_ERROR : constant := -1;
----------------------------------------------------------------------------
-- Returns the copyright tag for AllegroFont.
function Alfont_Copyright return String;
-- Returns a string describing the library version in the form
-- "LibraryName dotted.version"
function Alfont_Version return String;
-- Initializes AllegroFont. Remember to call alfont_exit() when you
-- are done with it! Nobody will do it automatically for you.
--
-- return values:
-- ALFONT_OK on success.
-- Other value ( != 0 ) on error.
function Alfont_Init return Integer;
-- Deinitializes AllegroFont and its resources (fonts included).
-- It is important to call it before you exit.
procedure Alfont_Exit;
-- Loads a font from a the following formats (thanks to FreeType 2):
-- TrueType fonts (and collections)
-- Type 1 fonts
-- CID-keyed Type 1 fonts
-- CFF fonts
-- OpenType fonts (both TrueType and CFF variants)
-- SFNT-based bitmap fonts
-- X11 PCF fonts
-- Windows FNT fonts
-- Note the scalable fonts by default get loaded with a size of 8 pixels
-- height.
-- Use alfont_set_font_size() to change the font size.
--
-- return values:
-- NULL if there ocurred an error.
-- Other value ( != NULL ) otherwise.
function Load_Font( filepathname : String ) return A_Alfont_Font;
pragma Precondition( filepathname'Length > 0 );
-- Same as alfont_load_font only that instead of loading it from a file
-- it loads it directly from memory. The lib will create its own copy
-- of this buffer, so you are free to deallocate it once this function
-- has been called.
function Load_Font_From_Mem( data : Address; data_len : Natural ) return A_Alfont_Font;
pragma Precondition( data /= Null_Address );
-- Destroys the font. Note this function check if the 'f' pointer is
-- pointing to NULL, so for example this:
-- ALFONT_FONT *f = NULL;
-- alfont_destroy_font(f);
-- won't crash the program.
procedure Destroy_Font( f : in out A_Alfont_Font );
pragma Postcondition( f = null );
-- Since AllegroFont can use scalable fonts (for example TrueType)
-- this sets the size of the font. This should also work with multiple
-- fixed sized fonts.
-- Note changing the size of a font makes it to "reload" the internal
-- glyphs of it, which is *slow*, so if you want to use many sizes
-- of the same font very regularly, better create several instances
-- of it.
--
-- return values:
-- ALFONT_ERROR if there ocurred an error (for example if the font is not scalable).
-- ALFONT_OK otherwise.
function Set_Font_Size( f : not null A_Alfont_Font; h : Positive ) return Integer;
-- Returns the selected font height.
function Get_Font_Height( f : not null A_Alfont_Font ) return Positive;
-- Return TRUE or FALSE, dependant on if the font is fixed (there is
-- a range of sizes where to choose from) or scalable (any size can be
-- used, well, or almost)
function Is_Scalable_Font( f : not null A_Alfont_Font ) return Boolean;
function Is_Fixed_Font( f : not null A_Alfont_Font ) return Boolean;
-- Sets the selected font as fixed width.
procedure Set_Font_Fixed_Width( f : not null A_Alfont_Font; fixed_width : Boolean );
-- Returns an array with the available fixed heights, being the last item
-- this array -1.
-- In case of calling this function for a scalable font you will get an
-- array of just one element, being it -1
-- If you have doubts on how to access the information because pointers
-- scare you, you just have to do:
--
-- const int *my_font_sizes;
-- my_font_sizes = alfont_get_available_fixed_sizes(my_font);
-- /* first size */
-- int first_h = my_font_sizes[0];
-- /* second */
-- int second_h = my_font_sizes[1];
--
-- and so until my_font_sizes[x] is -1
--
-- Regarding the Ada interface, the array returned from this function must
-- be deleted by the caller. In the case of a scalable font, null will be
-- returned.
function Get_Available_Fixed_Sizes( f : not null A_Alfont_Font ) return A_Size_Array;
-- Returns the number of available fixed sizes, or -1 if a scalable font
-- is passed.
function Get_Nof_Available_Fixed_Sizes( f : not null A_Alfont_Font ) return Integer;
-- Returns the character extra spacing, this is, an int number
-- that will be added to the space between characters, being the
-- min of it '0'.
function Get_Char_Extra_Spacing( f : not null A_Alfont_Font ) return Natural;
-- Sets the character extra spacing, this is, an int number
-- that will be added to the space between characters, being the
-- min of it '0'.
procedure Set_Char_Extra_Spacing( f : not null A_Alfont_Font; spacing : Natural );
-- Sets the language for the selected font.
-- You can visit the language string in the header "alfont.h" or see
-- "language_strings.txt"
procedure Set_Language( f : not null A_Alfont_Font; language : String );
pragma Precondition( language'Length > 0 );
-- Returns the language of the selected font.
function Get_Language( f : not null A_Alfont_Font ) return String;
-- Sets the convert type for the selected font.
-- You can set the type as "No Switch",AlFont won't convert the string.
-- Or you can set the type as "TYPE_MULTIBYTE",AlFont will convert the
-- string as multibyte string(Local Code).
-- Or you can set the type as "TYPE_WIDECHAR",AlFont will convert the
-- string as widechar string(Unicode Code).
procedure Set_Convert( f : not null A_Alfont_Font; typ : Integer );
-- Returns the convert type of the selected font.
function Get_Convert( f : not null A_Alfont_Font ) return Integer;
-- Sets the selected font style as Standard,Italic,Bold or BoldItalic style font.
procedure Set_Font_Style( f : not null A_Alfont_Font; style : Integer );
-- Returns the style of the selected font.
function Get_Font_Style( f : not null A_Alfont_Font ) return Integer;
-- Sets the selected font with underline.
procedure Set_Font_Underline( f : not null A_Alfont_Font; underline : Boolean );
-- Returns if the selected font have been set as underline.
function Get_Font_Underline( f : not null A_Alfont_Font ) return Boolean;
-- Extends the right underline for the selected font.
procedure Set_Font_Underline_Right( f : not null A_Alfont_Font; underline_right : Boolean );
-- Returns if the selected font have been set as extend right underline.
function Get_Font_Underline_Right( f : not null A_Alfont_Font ) return Boolean;
-- Extends the left underline for the selected font.
procedure Set_Font_Underline_Left( f : not null A_Alfont_Font; underline_left : Boolean );
-- Returns if the selected font have been set as extend left underline.
function Get_Font_Underline_Left( f : not null A_Alfont_Font ) return Boolean;
-- Sets the background for the selected font.(TRUE/FALSE)
procedure Set_Font_Background( f : not null A_Alfont_Font; background : Boolean );
-- Returns if the selected font have been set to show the background color.
function Get_Font_Background( f : not null A_Alfont_Font ) return Boolean;
-- Sets the transparency for the selected font.(0-255)
procedure Set_Font_Transparency( f : not null A_Alfont_Font; transparency : Integer );
pragma Precondition( transparency >= 0 );
pragma Precondition( transparency <= 255 );
-- Returns the transparency of the selected font.
function Get_Font_Transparency( f : not null A_Alfont_Font ) return Integer;
-- Autofix the shortcutted character while trying to convert ASCII encoding
-- format to Unicode encoding format. The shortcutted character will be
-- appended to the next string. After the shortcutted character showed with
-- the next string, the shortcutted character value will be set as 0.
-- The function will be useful for double-byte characters.
procedure Set_Autofix( f : not null A_Alfont_Font; autofix : Boolean );
-- Returns if the selected font have been set as autofix.
function Get_Autofix( f : not null A_Alfont_Font ) return Boolean;
-- Sets the shortcutted character value.
-- The shortcutted character will be showed in the front of the next string.
procedure Set_Precedingchar( f : not null A_Alfont_Font; precedingchar : Integer );
-- Returns the shortcutted character value that will be appended to the next string.
-- If there are not the shortcutted character that will be appended to the next string,
-- the return value of the alfont_get_precedingchar function will be 0.
function Get_Precedingchar( f : not null A_Alfont_Font ) return Integer;
-- Returns the character pointed to by `s' in the current encoding format.
-- int alfont_ugetc(ALFONT_FONT *f, const char *s);
-- Returns the character pointered by `s' in the current encoding format,
-- and advances the pointer to the next character after the one just returned.
-- int alfont_ugetx(ALFONT_FONT *f, char **s);
-- Returns the character pointered by `s' in the current encoding format,
-- and advances the pointer to the next character after the one just returned.
-- int alfont_ugetxc(ALFONT_FONT *f, const char **s);
-- Gets the converted string pointered by `s' in the current encoding format.
-- void alfont_get_string(ALFONT_FONT *f, const char *s , char **out);
-- Adds the outline width of the top for the selected font.
-- The height of the selected font is the max restriction.
procedure Set_Font_Outline_Top( f : not null A_Alfont_Font; w : Natural );
-- Returns the top outline width of the selected font.
function Get_Font_Outline_Top( f : not null A_Alfont_Font ) return Natural;
-- Adds the outline width of the bottom for the selected font.
-- The height of the selected font is the max restriction.
procedure Set_Font_Outline_Bottom( f : not null A_Alfont_Font; w : Natural );
-- Returns the bottom outline width of the selected font.
function Get_Font_Outline_Bottom( f : not null A_Alfont_Font ) return Natural;
-- Adds the outline width of the left for the selected font.
-- The width of the selected font is the max restriction.
procedure Set_Font_Outline_Left( f : not null A_Alfont_Font; w : Natural );
-- Returns the left outline width of the selected font.
function Get_Font_Outline_Left( f : not null A_Alfont_Font ) return Natural;
-- Adds the outline width of the right for the selected font.
-- The width of the selected font is the max restriction.
procedure Set_Font_Outline_Right( f : not null A_Alfont_Font; w : Natural );
-- Returns the right outline width of the selected font.
function Get_Font_Outline_Right( f : not null A_Alfont_Font ) return Natural;
-- Sets the outline color for the selected font.
procedure Set_Font_Outline_Color( f : not null A_Alfont_Font; c : Integer );
-- Returns the outline color of the selected font.
function Get_Font_Outline_Color( f : not null A_Alfont_Font ) return Integer;
-- Sets the selected font as hollow.(TRUE/FALSE)
procedure Set_Font_Outline_Hollow( f : not null A_Alfont_Font; hollow : Boolean );
-- Returns if the selected font have been set as hollow.
function Get_Font_Outline_Hollow( f : not null A_Alfont_Font ) return Boolean;
-- Returns the length of the string.
function Text_Count( f : not null A_Alfont_Font; str : String ) return Natural;
-- Returns TRUE if unicode conversion is required or FALSE otherwise,
-- that is the string contains only character values less than 128.
function Need_Uconvert( f : not null A_Alfont_Font; str : String ) return Boolean;
-- For the following procedures...
--
-- See allegro ones. The only difference is the suffix "_aa" that means
-- antialiased. Bear in mind antialiased operations are a lot slower than
-- monochrome ones. Also some old font formats, like PCF do not support
-- antialiasing.
-- Notice also the "_ex" suffix that adds a 'backg' parameter, which is the
-- background color, avoiding that way the use of alfont_textmode().
-- In fact, the speed from faster to slower are (being 100% the speed
-- of the fastest one):
-- Bliting over screen:
-- Monochrome, transparent textmode (100%)
-- Monochrome, opaque textmode (63%)
-- Antialiased, opaque textmode (53%)
-- Antialiased, transparent textmode (6%)
-- Blitting over memory bitmap:
-- Monochrome, transparent textmode (91%)
-- Monochrome, opaque textmode (50%)
-- Antialiased, opaque textmode (47%)
-- Antialiased, transparent textmode (20%)
-- being the Antialiased opaque mode a lot faster than the Antialiased
-- transparent mode (since this last one uses allegro blenders). That's
-- also the reason of why this last one works A LOT better over memory
-- bitmaps (implies read operations).
-- Sets text drawing mode. The previous mode is returned.
function Text_Mode( mode : Integer ) return Integer;
procedure Textout_aa( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type );
procedure Textout( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type );
procedure Textout_aa_ex( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type; backg : Integer );
procedure Textout_ex( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type; backg : Integer );
procedure Textout_Centre_aa( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type );
procedure Textout_Centre( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type );
procedure Textout_Centre_aa_ex( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type; backg : Integer );
procedure Textout_Centre_ex( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type; backg : Integer );
procedure Textout_Right_aa( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type );
procedure Textout_Right( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type );
procedure Textout_Right_aa_ex( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type; backg : Integer );
procedure Textout_Right_ex( bmp : not null A_Bitmap; f : not null A_Alfont_Font; s : String; x, y : Integer; color : Color_Type; backg : Integer );
function Text_Height( f : not null A_Alfont_Font ) return Natural;
function Text_Length( f : not null A_Alfont_Font; str : String ) return Natural;
private
type Alfont_Font is null record;
pragma Convention( C, Alfont_Font );
----------------------------------------------------------------------------
pragma Import( C, Alfont_Init, "alfont_init" );
pragma Import( C, Alfont_Exit, "alfont_exit" );
pragma Import( C, Load_Font_From_Mem, "alfont_load_font_from_mem" );
pragma Import( C, Set_Font_Size, "alfont_set_font_size" );
pragma Import( C, Get_Font_Height, "alfont_get_font_height" );
pragma Import( C, Get_Nof_Available_Fixed_Sizes, "alfont_get_nof_available_fixed_sizes" );
pragma Import( C, Get_Char_Extra_Spacing, "alfont_get_char_extra_spacing" );
pragma Import( C, Set_Char_Extra_Spacing, "alfont_set_char_extra_spacing" );
pragma Import( C, Set_Convert, "alfont_set_convert" );
pragma Import( C, Get_Convert, "alfont_get_convert" );
pragma Import( C, Set_Font_Style, "alfont_set_font_style" );
pragma Import( C, Get_Font_Style, "alfont_get_font_style" );
pragma Import( C, Set_Font_Transparency, "alfont_set_font_transparency" );
pragma Import( C, Get_Font_Transparency, "alfont_get_font_transparency" );
pragma Import( C, Set_Precedingchar, "alfont_set_precedingchar" );
pragma Import( C, Get_Precedingchar, "alfont_get_precedingchar" );
pragma Import( C, Set_Font_Outline_Top, "alfont_set_font_outline_top" );
pragma Import( C, Get_Font_Outline_Top, "alfont_get_font_outline_top" );
pragma Import( C, Set_Font_Outline_Bottom, "alfont_set_font_outline_bottom" );
pragma Import( C, Get_Font_Outline_Bottom, "alfont_get_font_outline_bottom" );
pragma Import( C, Set_Font_Outline_Left, "alfont_set_font_outline_left" );
pragma Import( C, Get_Font_Outline_Left, "alfont_get_font_outline_left" );
pragma Import( C, Set_Font_Outline_Right, "alfont_set_font_outline_right" );
pragma Import( C, Get_Font_Outline_Right, "alfont_get_font_outline_right" );
pragma Import( C, Set_Font_Outline_Color, "alfont_set_font_outline_color" );
pragma Import( C, Get_Font_Outline_Color, "alfont_get_font_outline_color" );
pragma Import( C, Text_Mode, "alfont_text_mode" );
pragma Import( C, Text_Height, "alfont_text_height" );
end Alfont;