~ubuntu-branches/ubuntu/precise/gnat-gps/precise

« back to all changes in this revision

Viewing changes to gnatlib/src/paragraph_filling/gnatcoll-paragraph_filling-badnesses.ads

  • Committer: Package Import Robot
  • Author(s): Ludovic Brenta
  • Date: 2012-01-15 15:42:21 UTC
  • mfrom: (10.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120115154221-ccysuzvh02pkhuwq
Tags: 5.0-6
Rebuild against libgtkada 2.24.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-----------------------------------------------------------------------
 
2
--                          G N A T C O L L                          --
 
3
--                                                                   --
 
4
--                    Copyright (C) 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
--  This software was originally contributed by William A. Duff
 
24
 
 
25
with GNATCOLL.Paragraph_Filling.Words; use GNATCOLL.Paragraph_Filling.Words;
 
26
 
 
27
private package GNATCOLL.Paragraph_Filling.Badnesses is
 
28
 
 
29
   type Badness_Value is private;
 
30
   Zero     : constant Badness_Value;
 
31
   Infinity : constant Badness_Value;
 
32
   --  It's a non-negative number that represents how bad the formatting of a
 
33
   --  line or paragraph is, with Zero meaning perfectly good, and Infinity
 
34
   --  representing "too long to fit on a line". The term 'badness' comes from
 
35
   --  Knuth's TeX.
 
36
 
 
37
   function "+" (X, Y : Badness_Value) return Badness_Value;
 
38
   --  Adds two Badnesses. If the result is greater than infinity, it returns
 
39
   --  infinity.
 
40
 
 
41
   function "<" (X, Y : Badness_Value) return Boolean;
 
42
   --  Returns true if X is less than Y. Else returns False
 
43
 
 
44
   function "**" (X : Natural; Y : Positive) return Badness_Value;
 
45
   --  Raise X to the Y power and returns the result as a Badness_Value. If the
 
46
   --  result is greater that infinity, returns infinity.
 
47
 
 
48
   function Image (Badness : Badness_Value) return String;
 
49
 
 
50
   function Line_Badness
 
51
     (W                : Paragraph_Filling.Words.Words;
 
52
      X, Y             : Word_Index;
 
53
      Max_Line_Length  : Positive;
 
54
      Format_Last_Line : Boolean := False) return Badness_Value;
 
55
   --  Returns badness as determined by a formula invented by Knuth. This
 
56
   --  formula calculates the square of the difference between the Line_Length
 
57
   --  (calculated by the Line_Length function in Paragraph_Filling.Words) and
 
58
   --  the Max_Line_Length. If the line length is greater than the
 
59
   --  Max_Line_Length then the function returns Infinity.
 
60
   --
 
61
   --  ??? Currently, Format_Last_Line is always defaulted to false. However,
 
62
   --  the calls could be changes to allow a user option of whether to include
 
63
   --  the last line in badness calculations.
 
64
 
 
65
   function Line_Badness
 
66
     (Line_Length     : Positive;
 
67
      Max_Line_Length : Positive) return Badness_Value;
 
68
   --  Returns badness as determined by a formula invented by Knuth.
 
69
   --  This formula calculates the square of the difference between the
 
70
   --  Line_Length and the Max_Line_Length. If the line length is greater
 
71
   --  than the Max_Line_Length then the function returns Infinity.
 
72
 
 
73
private
 
74
 
 
75
   type Badness_Value is new Natural;
 
76
   Zero     : constant Badness_Value := 0;
 
77
   Infinity : constant Badness_Value := Badness_Value'Last;
 
78
 
 
79
end GNATCOLL.Paragraph_Filling.Badnesses;