1
-----------------------------------------------------------------------
4
-- Copyright (C) 2010, AdaCore --
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. --
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. --
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. --
21
-----------------------------------------------------------------------
23
-- This software was originally contributed by William A. Duff
25
with GNATCOLL.Paragraph_Filling.Words; use GNATCOLL.Paragraph_Filling.Words;
27
private package GNATCOLL.Paragraph_Filling.Badnesses is
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
37
function "+" (X, Y : Badness_Value) return Badness_Value;
38
-- Adds two Badnesses. If the result is greater than infinity, it returns
41
function "<" (X, Y : Badness_Value) return Boolean;
42
-- Returns true if X is less than Y. Else returns False
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.
48
function Image (Badness : Badness_Value) return String;
51
(W : Paragraph_Filling.Words.Words;
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.
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.
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.
75
type Badness_Value is new Natural;
76
Zero : constant Badness_Value := 0;
77
Infinity : constant Badness_Value := Badness_Value'Last;
79
end GNATCOLL.Paragraph_Filling.Badnesses;