------------------------------------------------------------------------------ -- AGAR GUI LIBRARY -- -- A G A R . T E X T -- -- S p e c -- ------------------------------------------------------------------------------ with Ada.Containers.Indefinite_Vectors; with Interfaces; use Interfaces; with Interfaces.C; with Interfaces.C.Pointers; with Interfaces.C.Strings; with Agar.Types; use Agar.Types; with Agar.Object; with Agar.Surface; with Agar.Widget; with System; package Agar.Text is package C renames Interfaces.C; package CS renames Interfaces.C.Strings; package SU renames Agar.Surface; package WID renames Agar.Widget; use type C.int; use type C.unsigned; -- Limits -- FONT_NAME_MAX : constant Natural := $AG_FONT_NAME_MAX; TEXT_STATES_MAX : constant C.unsigned := $AG_TEXT_STATES_MAX; -- Agar Font style flags -- FONT_THIN : constant C.unsigned := 16#00_01#; FONT_EXTRALIGHT : constant C.unsigned := 16#00_02#; FONT_LIGHT : constant C.unsigned := 16#00_04#; FONT_SEMIBOLD : constant C.unsigned := 16#00_08#; FONT_BOLD : constant C.unsigned := 16#00_10#; FONT_EXTRABOLD : constant C.unsigned := 16#00_20#; FONT_BLACK : constant C.unsigned := 16#00_40#; FONT_OBLIQUE : constant C.unsigned := 16#00_80#; FONT_ITALIC : constant C.unsigned := 16#01_00#; FONT_ULTRACONDENSED : constant C.unsigned := 16#04_00#; FONT_CONDENSED : constant C.unsigned := 16#08_00#; FONT_SEMICONDENSED : constant C.unsigned := 16#10_00#; FONT_SEMIEXPANDED : constant C.unsigned := 16#20_00#; FONT_EXPANDED : constant C.unsigned := 16#40_00#; FONT_ULTRAEXPANDED : constant C.unsigned := 16#80_00#; FONT_WEIGHTS : constant C.unsigned := 16#00_7f#; -- All weights FONT_STYLES : constant C.unsigned := 16#01_80#; -- All styles FONT_WIDTH_VARIANTS : constant C.unsigned := 16#fc_00#; -- All wd. variants -- Agar Font state flags -- FONT_FONTCONFIGED : constant C.unsigned := 16#01#; -- Discovered via fontconfig FONT_FAMILY_FLAGS : constant C.unsigned := 16#02#; -- Family flags are specified ----------------------------- -- Text Justification Mode -- ----------------------------- type Text_Justify is (LEFT, CENTER, RIGHT); for Text_Justify use (LEFT => 0, CENTER => 1, RIGHT => 2); for Text_Justify'Size use C.int'Size; ---------------------------------- -- Vertical Text Alignment Mode -- ---------------------------------- type Text_Valign is (TOP, MIDDLE, BOTTOM); for Text_Valign use (TOP => 0, MIDDLE => 1, BOTTOM => 2); for Text_Valign'Size use C.int'Size; -------------------------------- -- Type of message to display -- -------------------------------- type Text_Message_Title is (ERROR, -- Error message alert WARNING, -- Warning (ignorable) INFO); -- Informational message (ignorable) for Text_Message_Title use (ERROR => 0, WARNING => 1, INFO => 2); for Text_Message_Title'Size use C.int'Size; ------------------ -- Type of font -- ------------------ type Font_Engine_Type is (FREETYPE, -- FreeType vector font engine BITMAP, -- Agar bitmap font engine DUMMY); -- A "no-op" font engine for Font_Engine_Type use (FREETYPE => 0, BITMAP => 1, DUMMY => 2); for Font_Engine_Type'Size use C.int'Size; ------------------------------------------- -- Type of data source to load font from -- ------------------------------------------- type Font_Spec_Source is (FONT_FILE, -- Load font from file FONT_IN_MEMORY); -- Deserialize in-memory font data for Font_Spec_Source use (FONT_FILE => 0, FONT_IN_MEMORY => 1); for Font_Spec_Source'Size use C.int'Size; ---------------------------- -- Size of font in points -- ---------------------------- subtype Font_Points is C.C_float; type Font_Points_Access is access all Font_Points with Convention => C; ----------------------------- -- Agar font specification -- ----------------------------- type Font_Spec (Spec_Source : Font_Spec_Source := FONT_FILE) is record Size : Font_Points; -- Font size in points Index : C.int; -- Font index (FC_INDEX) Font_Type : Font_Engine_Type; -- Font engine type Font_Source : Font_Spec_Source; -- Source type Matrix_XX : C.double; -- 1 -- -- Transformation matrix Matrix_XY : C.double; -- 0 -- Matrix_YX : C.double; -- 0 -- Matrix_YY : C.double; -- 1 -- case Spec_Source is when FONT_FILE => null; when FONT_IN_MEMORY => Memory_Source : access Unsigned_8; -- Source memory region Memory_Size : AG_Size; -- Size in bytes #if AG_MODEL = AG_MEDIUM C_Pad1 : Interfaces.Unsigned_32; #end if; end case; end record with Convention => C; pragma Unchecked_Union (Font_Spec); type Font_Spec_Access is access all Font_Spec with Convention => C; subtype Font_Spec_not_null_Access is not null Font_Spec_Access; ------------------ -- An Agar Font -- ------------------ type Font; type Font_Access is access all Font with Convention => C; subtype Font_not_null_Access is not null Font_Access; type Font_Entry is limited record Next : Font_Access; Prev : access Font_Access; end record with Convention => C; type Font_Name is array (1 .. FONT_NAME_MAX) of aliased c.char with Convention => C; type Font_Family_Style_Access is access all C.unsigned with Convention => C; subtype Font_Family_Style_not_null_Access is not null Font_Family_Style_Access; type Font is limited record Super : aliased Agar.Object.Object; -- ( Object -> Font ) Name : aliased Font_Name; -- Font family Spec : aliased Font_Spec; -- Font specification Flags : C.unsigned; -- Style/Weight/Wd.Variant -- Unicode coverage (OS/2 Charsets) Unicode_Ranges1 : Interfaces.Unsigned_32; -- Bits 0-31 Unicode_Ranges2 : Interfaces.Unsigned_32; -- Bits 32-63 Unicode_Ranges3 : Interfaces.Unsigned_32; -- Bits 64-95 Unicode_Ranges4 : Interfaces.Unsigned_32; -- Bits 96-127 Family_Style_Count : C.unsigned; -- No of styles in family Family_Styles : Font_Family_Style_Access; -- Styles in font's family State_Flags : C.unsigned; -- State flags Height : C.int; -- Height (px) Ascent : C.int; -- Ascent (px) Descent : C.int; -- Descent (px) Line_Skip : C.int; -- Multiline y-increment (px) Underline_Pos : C.int; -- Underline position Underline_Thick : C.int; -- Underline thickness Typo_Ascender : C.int; -- Ascent from OS/2 header Typo_Descender : C.int; -- Descent from OS/2 header Typo_Line_Gap : C.int; -- Line Gap from OS/2 header Win_Ascent : C.int; -- usWinAscent from OS/2 header Win_Descent : C.int; -- usWinDescent from OS/2 header Access_Time : C.unsigned; -- Access time (debug mode only) Entry_in_Fonts : Font_Entry; -- Entry in global fonts list end record with Convention => C; ---------------------------------- -- A rendered (in-memory) glyph -- ---------------------------------- type Glyph; type Glyph_Access is access all Glyph with Convention => C; subtype Glyph_not_null_Access is not null Glyph_Access; type Glyph_Entry is limited record Next : Glyph_Access; end record with Convention => C; type Glyph is limited record Font : Font_not_null_Access; -- Font face Color_BG : SU.AG_Color; -- Background color Color : SU.AG_Color; -- Foreground color Surface : SU.Surface_not_null_Access; -- Rendered surface Char : AG_Char; -- Native character Advance : C.int; -- Advance in pixels Texture : C.unsigned; -- Mapped texture (by driver) Texcoords : SU.AG_Texcoord; -- Texture coordinates C_Pad1 : Interfaces.Unsigned_32; Entry_in_Cache : Glyph_Entry; -- Entry in cache end record with Convention => C; --------------------------------------- -- Pushable/poppable state variables -- --------------------------------------- #if AG_DEBUG type Text_State_Tag is array (1 .. 8) of aliased C.char with Convention => C; #end if; type Text_State_Rec is record Font : Font_not_null_Access; -- Font face Color : aliased SU.AG_Color; -- Foreground text color Color_BG : aliased SU.AG_Color; -- Background color Color_ANSI : SU.Color_Access; -- ANSI color palette (3/4-bit) Justify : Text_Justify; -- Justification mode Valign : Text_Valign; -- Vertical alignment Tab_Width : C.int; -- Width of tabs in pixels C_Pad1 : Unsigned_32; end record with Convention => C; type Text_State_Access is access all Text_State_Rec with Convention => C; subtype Text_State_not_null_Access is not null Text_State_Access; ------------------------------------------ -- Statically-compiled font description -- ------------------------------------------ type Static_Font is array (1 .. $SIZEOF_AG_StaticFont) of aliased Unsigned_8 with Convention => C; for Static_Font'Size use $SIZEOF_AG_StaticFont * System.Storage_Unit; ------------------------------ -- Measure of rendered text -- ------------------------------ type Text_Metrics is record W,H : C.int; -- Dimensions in pixels Line_Widths : access C.unsigned; -- Width of each line Line_Count : C.unsigned; -- Total line count C_Pad1 : Unsigned_32; end record with Convention => C; type Text_Metrics_Access is access all Text_Metrics with Convention => C; subtype Text_Metrics_not_null_Access is not null Text_Metrics_Access; package Text_Line_Widths_Packages is new Ada.Containers.Indefinite_Vectors (Index_Type => Positive, Element_Type => Natural); subtype Text_Line_Widths is Text_Line_Widths_Packages.Vector; -------------------------- -- Internal glyph cache -- -------------------------- type Glyph_Cache is array (1 .. $SIZEOF_AG_GlyphCache) of aliased Unsigned_8 with Convention => C; for Glyph_Cache'Size use $SIZEOF_AG_GlyphCache * System.Storage_Unit; -- -- Initialize the font engine. -- function Init_Text_Subsystem return Boolean; -- -- Release all resources allocated by the font engine. -- procedure Destroy_Text_Subsystem; -- -- Set the default Agar font (by access to a Font object). -- Return a pointer to the previous default font. -- Updates the default font settings in AG_Config(3). -- function Set_Default_Font (Font : in Font_not_null_Access) return Font_Access with Import, Convention => C, Link_Name => "AG_SetDefaultFont"; -- -- Set the default font from a string of the form ",,