Back to index

texmacs  1.0.7.15
vpenalty.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : vpenalty.cpp
00004 * DESCRIPTION: Vertical penalties
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 *******************************************************************************
00011 *   The main 'pen' parameter is (mainly) determined at the typesetting process
00012 * It is 0 on paragraph borders, 1 inside paragraphs, 10 when two lines near
00013 * a paragraph border, 100 when one line from a paragraph border and
00014 * HYPH_INVALID if a page break is prohibited.
00015 *   The main penalty is adjusted when a given break is really not good
00016 * enough for a given page: if the page length is flexible and we can make
00017 * material between two breaks fit on a page of extended (or reduced) length,
00018 * then we add EXTEND_PAGE_PENALTY resp. REDUCE_PAGE_PENALTY to
00019 * the main penalty.
00020 *   At equal main penalties, we look at the excentricity parameter 'exc',
00021 * which is determined as the square of the difference between the default
00022 * length of the material between two breaks and the default required
00023 * page height.
00024 ******************************************************************************/
00025 
00026 #ifndef VPENALTY_H
00027 #define VPENALTY_H
00028 #include "basic.hpp"
00029 
00030 #define EXTEND_PAGE_PENALTY   33
00031 #define REDUCE_PAGE_PENALTY   33
00032 #define TOO_SHORT_PENALTY     10000
00033 #define TOO_LONG_PENALTY      100000
00034 #define UNBALANCED_COLUMNS    1000
00035 #define LONGER_LATTER_COLUMN  1000
00036 
00037 struct vpenalty_rep: concrete_struct {
00038   int pen;   // main penalty
00039   int exc;   // excentricity: square of shift with respect to ideal position
00040   inline vpenalty_rep (): pen (0), exc (0) {}
00041   inline vpenalty_rep (int pen2): pen (pen2), exc (0) {}
00042   inline vpenalty_rep (int pen2, int exc2): pen (pen2), exc (exc2) {}
00043 };
00044 
00045 class vpenalty {
00046   CONCRETE(vpenalty);
00047   inline vpenalty (): rep (tm_new<vpenalty_rep> ()) {}
00048   inline vpenalty (int pen): rep (tm_new<vpenalty_rep> (pen)) {}
00049   inline vpenalty (int pen, int exc): rep (tm_new<vpenalty_rep> (pen, exc)) {}
00050   inline bool operator == (vpenalty pen) {
00051     return (rep->pen == pen->pen) && (rep->exc == pen->exc); }
00052   inline bool operator != (vpenalty pen) {
00053     return (rep->pen != pen->pen) || (rep->exc != pen->exc); }
00054   inline bool operator < (vpenalty pen) {
00055     return
00056       (rep->pen < pen->pen) ||
00057       ((rep->pen == pen->pen) && (rep->exc < pen->exc)); }
00058   inline void operator += (vpenalty pen) {
00059     rep->pen += pen->pen; rep->exc += pen->exc; }
00060   inline vpenalty operator + (vpenalty pen) {
00061     return vpenalty (rep->pen + pen->pen, rep->exc + pen->exc); }
00062 };
00063 CONCRETE_CODE(vpenalty);
00064 
00065 tm_ostream& operator << (tm_ostream& out, vpenalty pen);
00066 
00067 #endif // defined VPENALTY_H