1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2001-2010, AdaCore                   -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- -- -- -- -- -- -- -- -- -- -- --
  22. ----------------------------------------------------------------------- 
  23.  
  24. --  <description> 
  25. -- 
  26. --  This package provides high-level, system-independent handling of fonts. It 
  27. --  supercedes the old Gdk.Font package, which should no longer be used. 
  28. -- 
  29. --  Fonts are defined through several attributes, like their family, weight, 
  30. --  size, style, ... 
  31. -- 
  32. --  The Pango_Font_Description objects created by this package can either be 
  33. --  used directly to draw text through Pango.Layout.Pango_Layout objects (and 
  34. --  the associated Gdk.Drawable.Draw_Layout procedure), or by converting them 
  35. --  to a Gdk_Font. The first method is the preferred one, and provides 
  36. --  high-level handling of multi-line texts or tabs, when you have to handle 
  37. --  this yourself in the second case. 
  38. -- 
  39. --  </description> 
  40. --  <group>Pango, font handling</group> 
  41.  
  42. with Glib; use Glib; 
  43. with Glib.Object; 
  44. with Glib.Generic_Properties; use Glib.Generic_Properties; 
  45. pragma Elaborate_All (Glib.Generic_Properties); 
  46. with Pango.Enums; 
  47. with System; 
  48.  
  49. package Pango.Font is 
  50.  
  51.    type Pango_Font_Description is new Glib.C_Proxy; 
  52.  
  53.    function Get_Type return Glib.GType; 
  54.    --  Return the internal gtk+ type associated with font descriptions. 
  55.  
  56.    function Copy (Desc : Pango_Font_Description) return Pango_Font_Description; 
  57.    --  Return a newly allocated font description. 
  58.    --  This Pango_Font_Description needs to be free'ed after use. 
  59.  
  60.    function Equal 
  61.      (Desc1 : Pango_Font_Description; 
  62.       Desc2 : Pango_Font_Description) return Boolean; 
  63.    --  Return True if the two font descriptions are identical. 
  64.    --  Note that two font description may result in identical fonts being 
  65.    --  loaded, but still compare False. 
  66.  
  67.    procedure Free (Desc : in out Pango_Font_Description); 
  68.    --  Deallocate the given font description. 
  69.  
  70.    function From_String (Str : String) return Pango_Font_Description; 
  71.    --  Create a new font description from the given string representation 
  72.    --  of the given form: "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]". Any one 
  73.    --  of the options may be omitted. 
  74.    --    - FAMILY-LIST is a comma separated list (spaces are not allowed) 
  75.    --      of font families optionally terminated by a comma. If absent, 
  76.    --      the font family of the font that will be used is unspecified. 
  77.    --    - STYLE_OPTIONS is a whitespace separated list of words where each 
  78.    --      word describes either style, variant, weight, or stretch. Any 
  79.    --      unspecified style option is defaulted to "Normal", which 
  80.    --      respectively corresponds to Pango_Style_Normal, Pango_Weight_Normal, 
  81.    --      Pango_Variant_Normal, and Pango_Stretch_Normal. 
  82.    --    - SIZE is a decimal number describing the size of the font in points. 
  83.    --      If unspecified, a size of 0 will be used. 
  84.  
  85.    function To_Font_Description 
  86.      (Family_Name : String := ""; 
  87.       Style       : Pango.Enums.Style := Pango.Enums.Pango_Style_Normal; 
  88.       Variant     : Pango.Enums.Variant := Pango.Enums.Pango_Variant_Normal; 
  89.       Weight      : Pango.Enums.Weight := Pango.Enums.Pango_Weight_Normal; 
  90.       Stretch     : Pango.Enums.Stretch := Pango.Enums.Pango_Stretch_Normal; 
  91.       Size        : Gint := 0) return Pango_Font_Description; 
  92.    --  Create a new font decription from the given parameters. 
  93.  
  94.    function To_String (Desc : Pango_Font_Description) return String; 
  95.    --  Create a string representation of a font description. The format 
  96.    --  of the string produced follows the syntax used by From_String. 
  97.    --  The family-list in the string description will have a terminating 
  98.    --  comma only if the last word of the list is a valid style option. 
  99.  
  100.    function To_Filename (Desc : Pango_Font_Description) return String; 
  101.    --  Create a filename representation of a font description. The filename 
  102.    --  is identical to the result from calling To_String, but with underscores 
  103.    --  instead of characters that are untypical in filenames, and in lower 
  104.    --  case only. 
  105.  
  106.    function Get_Family (Desc : Pango_Font_Description) return String; 
  107.    --  Return the Family_Name of the given Pango_Font_Description. 
  108.  
  109.    procedure Set_Family (Desc : Pango_Font_Description; Name : String); 
  110.    --  Set the Family_Name of the given Pango_Font_Description. 
  111.  
  112.    function Get_Style (Desc : Pango_Font_Description) return Pango.Enums.Style; 
  113.    --  Return the Style of the given Pango_Font_Description. 
  114.  
  115.    procedure Set_Style 
  116.      (Desc : Pango_Font_Description; Style : Pango.Enums.Style); 
  117.    --  Set the Style of the given Pango_Font_Description. 
  118.  
  119.    function Get_Variant 
  120.      (Desc : Pango_Font_Description) return Pango.Enums.Variant; 
  121.    --  Return the Variant of the given Pango_Font_Description. 
  122.  
  123.    procedure Set_Variant 
  124.      (Desc : Pango_Font_Description; Variant : Pango.Enums.Variant); 
  125.    --  Set the Variant of the given Pango_Font_Description. 
  126.  
  127.    function Get_Weight 
  128.      (Desc : Pango_Font_Description) return Pango.Enums.Weight; 
  129.    --  Return the Weight of the given Pango_Font_Description. 
  130.  
  131.    procedure Set_Weight 
  132.      (Desc : Pango_Font_Description; Weight : Pango.Enums.Weight); 
  133.    --  Set the Weight of the given Pango_Font_Description. 
  134.  
  135.    function Get_Stretch 
  136.      (Desc : Pango_Font_Description) return Pango.Enums.Stretch; 
  137.    --  Return the Stretch of the given Pango_Font_Description. 
  138.  
  139.    procedure Set_Stretch 
  140.      (Desc : Pango_Font_Description; Stretch : Pango.Enums.Stretch); 
  141.    --  Set the Stretch of the given Pango_Font_Description. 
  142.  
  143.    function Get_Size (Desc : Pango_Font_Description) return Gint; 
  144.    --  Return value: the size for the font description in pango units. 
  145.    --  (PANGO_SCALE pango units equals one point). Returns 0 if Desc hasn't 
  146.    --  been initialized. 
  147.  
  148.    procedure Set_Size (Desc : Pango_Font_Description; Size : Gint); 
  149.    --  Set the size for the font description in pango units.  (PANGO_SCALE 
  150.    --  pango units equals one point) 
  151.  
  152.    --------------- 
  153.    -- Languages -- 
  154.    --------------- 
  155.    --  The following section provides types and subprograms to identify a 
  156.    --  specific script and language inside a font (Not all characters of a font 
  157.    --  are used for all languages) 
  158.  
  159.    type Pango_Language is new Glib.C_Proxy; 
  160.  
  161.    function Pango_Language_Get_Type return Glib.GType; 
  162.    --  Return the internal value used to identify a Pango_Language 
  163.  
  164.    function From_String (Language : String) return Pango_Language; 
  165.    --  Take a RFC-3066 format language tag as a string and convert it to a 
  166.    --  Pango_Language pointer that can be efficiently copied (copy the pointer) 
  167.    --  and compared with other language tags (compare the pointer). Language is 
  168.    --  something like "fr" (french), "ar" (arabic), "en" (english), "ru" 
  169.    --  (russian), ... 
  170.    -- 
  171.    --  This function first canonicalizes the string by converting it to 
  172.    --  lowercase, mapping '_' to '-', and stripping all characters other than 
  173.    --  letters and '-'. 
  174.    -- 
  175.    --  The returned value need not be freed, it is stored internally by gtk+ in 
  176.    --  a hash-table. 
  177.  
  178.    ------------- 
  179.    -- Metrics -- 
  180.    ------------- 
  181.    --  The following subprograms can be used to retrieve the metrics associated 
  182.    --  with the font. Note that such metrics might depend on the specific 
  183.    --  script/language in use. 
  184.  
  185.    type Pango_Font_Metrics is new Glib.C_Proxy; 
  186.  
  187.    type Pango_Font_Record is new Glib.Object.GObject_Record with null record; 
  188.    type Pango_Font is access all Pango_Font_Record'Class; 
  189.    --  Created through Pango.Context.Load_Font 
  190.  
  191.    function Get_Metrics 
  192.      (Font : access Pango_Font_Record'Class; 
  193.       Language : Pango_Language := null) return Pango_Font_Metrics; 
  194.    --  Gets overall metric information for a font. Since the metrics may be 
  195.    --  substantially different for different scripts, a language tag can be 
  196.    --  provided to indicate that the metrics should be retrieved that 
  197.    --  correspond to the script(s) used by that language. 
  198.    -- 
  199.    --  The returned value must be Unref'ed by the caller. 
  200.    -- 
  201.    --  Language determines which script to get the metrics for, or null to 
  202.    --  indicate the metrics for the entire font. 
  203.  
  204.    procedure Ref (Metrics : Pango_Font_Metrics); 
  205.    procedure Unref (Metrics : Pango_Font_Metrics); 
  206.    --  Ref or unref Metrics When the reference counter reaches 0, the memory is 
  207.    --  deallocated. 
  208.  
  209.    function Get_Ascent (Metrics : Pango_Font_Metrics) return Gint; 
  210.    --  Gets the ascent from a font metrics structure. The ascent is the 
  211.    --  distance from the baseline to the logical top of a line of text. (The 
  212.    --  logical top may be above or below the top of the actual drawn ink. It is 
  213.    --  necessary to lay out the text to figure where the ink will be). 
  214.    -- 
  215.    --  The returned value is expressed in pango units, and must be divided by 
  216.    --  Pango_Scale to get the value in pixels. 
  217.  
  218.    function Get_Descent (Metrics : Pango_Font_Metrics) return Gint; 
  219.    --  Gets the descent from a font metrics structure. The descent is the 
  220.    --  distance from the baseline to the logical bottom of a line of text. (The 
  221.    --  logical bottom may be above or below the bottom of the actual drawn 
  222.    --  ink. It is necessary to lay out the text to figure where the ink will 
  223.    --  be.) 
  224.    -- 
  225.    --  The returned value is expressed in pango units, and must be divided by 
  226.    --  Pango_Scale to get the value in pixels. 
  227.  
  228.    function Get_Approximate_Char_Width (Metrics : Pango_Font_Metrics) 
  229.       return Gint; 
  230.    --  Gets the approximate character width for a font metrics structure.  This 
  231.    --  is merely a representative value useful, for example, for determining 
  232.    --  the initial size for a window. Actual characters in text will be wider 
  233.    --  and narrower than this. 
  234.    -- 
  235.    --  The returned value is expressed in pango units, and must be divided by 
  236.    --  Pango_Scale to get the value in pixels. 
  237.  
  238.    function Get_Approximate_Digit_Width (Metrics : Pango_Font_Metrics) 
  239.       return Gint; 
  240.    --  Gets the approximate digit width for a font metrics structure.  This is 
  241.    --  merely a representative value useful, for example, for determining the 
  242.    --  initial size for a window. Actual digits in text can be wider and 
  243.    --  narrower than this, though this value is generally somewhat more 
  244.    --  accurate than the result of Get_Approximate_Char_Width. 
  245.    -- 
  246.    --  The returned value is expressed in pango units, and must be divided by 
  247.    --  Pango_Scale to get the value in pixels. 
  248.  
  249.    function Font_Metrics_Get_Type return Glib.GType; 
  250.    --  Return the internal value associated with a Pango_Font_Metrics 
  251.  
  252.    ---------------- 
  253.    -- Properties -- 
  254.    ---------------- 
  255.    --  See the package Glib.Properties for more information on how to 
  256.    --  use properties 
  257.  
  258.    pragma Import (C, Get_Type, "pango_font_description_get_type"); 
  259.  
  260.    function To_Address 
  261.      (F : Pango_Font_Description; Add : System.Address) return System.Address; 
  262.  
  263.    package Desc_Properties is new Generic_Internal_Boxed_Property 
  264.      (Pango_Font_Description, Get_Type, To_Address); 
  265.  
  266.    type Property_Font_Description is new Desc_Properties.Property; 
  267.  
  268. private 
  269.    pragma Import (C, Copy, "pango_font_description_copy"); 
  270.    pragma Import (C, Get_Size, "pango_font_description_get_size"); 
  271.    pragma Import (C, Set_Size, "pango_font_description_set_size"); 
  272.    pragma Import (C, Pango_Language_Get_Type, "pango_language_get_type"); 
  273.    pragma Import 
  274.      (C, Font_Metrics_Get_Type, "pango_font_metrics_get_type"); 
  275.    pragma Import (C, Ref, "pango_font_metrics_ref"); 
  276.    pragma Import (C, Unref, "pango_font_metrics_unref"); 
  277.    pragma Import (C, Get_Ascent, "pango_font_metrics_get_ascent"); 
  278.    pragma Import (C, Get_Descent, "pango_font_metrics_get_descent"); 
  279.    pragma Import (C, Get_Approximate_Char_Width, 
  280.                   "pango_font_metrics_get_approximate_char_width"); 
  281.    pragma Import (C, Get_Approximate_Digit_Width, 
  282.                   "pango_font_metrics_get_approximate_digit_width"); 
  283.  
  284.    pragma Import (C, Get_Style, "pango_font_description_get_style"); 
  285.    pragma Import (C, Set_Style, "pango_font_description_set_style"); 
  286.    pragma Import (C, Get_Variant, "pango_font_description_get_variant"); 
  287.    pragma Import (C, Set_Variant, "pango_font_description_set_variant"); 
  288.    pragma Import (C, Get_Weight, "pango_font_description_get_weight"); 
  289.    pragma Import (C, Set_Weight, "pango_font_description_set_weight"); 
  290.    pragma Import (C, Get_Stretch, "pango_font_description_get_stretch"); 
  291.    pragma Import (C, Set_Stretch, "pango_font_description_set_stretch"); 
  292. end Pango.Font; 
  293.  
  294. --  Missing: 
  295. --  pango_language_matches